OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "chrome/browser/ui/cocoa/infobars/extension_infobar_controller.h" | 5 #import "chrome/browser/ui/cocoa/infobars/extension_infobar_controller.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "chrome/browser/extensions/extension_host.h" | 9 #include "chrome/browser/extensions/extension_host.h" |
10 #include "chrome/browser/extensions/extension_infobar_delegate.h" | 10 #include "chrome/browser/extensions/extension_infobar_delegate.h" |
11 #include "chrome/browser/extensions/image_loading_tracker.h" | 11 #include "chrome/browser/extensions/image_loading_tracker.h" |
12 #include "chrome/browser/infobars/infobar_tab_helper.h" | 12 #include "chrome/browser/infobars/infobar_tab_helper.h" |
13 #include "chrome/browser/ui/browser_finder.h" | 13 #include "chrome/browser/ui/browser_finder.h" |
14 #import "chrome/browser/ui/cocoa/animatable_view.h" | 14 #import "chrome/browser/ui/cocoa/animatable_view.h" |
15 #import "chrome/browser/ui/cocoa/extensions/extension_action_context_menu.h" | 15 #import "chrome/browser/ui/cocoa/extensions/extension_action_context_menu.h" |
16 #include "chrome/browser/ui/cocoa/infobars/infobar.h" | 16 #include "chrome/browser/ui/cocoa/infobars/infobar.h" |
17 #import "chrome/browser/ui/cocoa/menu_button.h" | 17 #import "chrome/browser/ui/cocoa/menu_button.h" |
18 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 18 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
19 #include "chrome/common/extensions/extension.h" | 19 #include "chrome/common/extensions/extension.h" |
| 20 #include "chrome/common/extensions/extension_constants.h" |
20 #include "chrome/common/extensions/extension_icon_set.h" | 21 #include "chrome/common/extensions/extension_icon_set.h" |
21 #include "chrome/common/extensions/extension_resource.h" | 22 #include "chrome/common/extensions/extension_resource.h" |
22 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
23 #include "grit/theme_resources.h" | 24 #include "grit/theme_resources.h" |
24 #include "skia/ext/skia_utils_mac.h" | 25 #include "skia/ext/skia_utils_mac.h" |
25 #include "ui/base/resource/resource_bundle.h" | 26 #include "ui/base/resource/resource_bundle.h" |
26 #include "ui/gfx/canvas.h" | 27 #include "ui/gfx/canvas.h" |
27 #include "ui/gfx/image/image.h" | 28 #include "ui/gfx/image/image.h" |
28 | 29 |
29 namespace { | 30 namespace { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 virtual ~InfobarBridge() { | 67 virtual ~InfobarBridge() { |
67 if (delegate_) | 68 if (delegate_) |
68 delegate_->set_observer(NULL); | 69 delegate_->set_observer(NULL); |
69 } | 70 } |
70 | 71 |
71 // Load the Extension's icon image. | 72 // Load the Extension's icon image. |
72 void LoadIcon() { | 73 void LoadIcon() { |
73 const extensions::Extension* extension = delegate_->extension_host()-> | 74 const extensions::Extension* extension = delegate_->extension_host()-> |
74 extension(); | 75 extension(); |
75 ExtensionResource icon_resource = | 76 ExtensionResource icon_resource = |
76 extension->GetIconResource(ExtensionIconSet::EXTENSION_ICON_BITTY, | 77 extension->GetIconResource(extension_misc::EXTENSION_ICON_BITTY, |
77 ExtensionIconSet::MATCH_EXACTLY); | 78 ExtensionIconSet::MATCH_EXACTLY); |
78 tracker_.LoadImage(extension, icon_resource, | 79 tracker_.LoadImage(extension, icon_resource, |
79 gfx::Size(ExtensionIconSet::EXTENSION_ICON_BITTY, | 80 gfx::Size(extension_misc::EXTENSION_ICON_BITTY, |
80 ExtensionIconSet::EXTENSION_ICON_BITTY), | 81 extension_misc::EXTENSION_ICON_BITTY), |
81 ImageLoadingTracker::DONT_CACHE); | 82 ImageLoadingTracker::DONT_CACHE); |
82 } | 83 } |
83 | 84 |
84 // ImageLoadingTracker::Observer implementation. | 85 // ImageLoadingTracker::Observer implementation. |
85 // TODO(andybons): The infobar view implementations share a lot of the same | 86 // TODO(andybons): The infobar view implementations share a lot of the same |
86 // code. Come up with a strategy to share amongst them. | 87 // code. Come up with a strategy to share amongst them. |
87 virtual void OnImageLoaded(const gfx::Image& image, | 88 virtual void OnImageLoaded(const gfx::Image& image, |
88 const std::string& extension_id, | 89 const std::string& extension_id, |
89 int index) OVERRIDE { | 90 int index) OVERRIDE { |
90 if (!delegate_) | 91 if (!delegate_) |
91 return; // The delegate can go away while the image asynchronously loads. | 92 return; // The delegate can go away while the image asynchronously loads. |
92 | 93 |
93 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 94 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
94 | 95 |
95 // Fall back on the default extension icon on failure. | 96 // Fall back on the default extension icon on failure. |
96 const SkBitmap* icon; | 97 const SkBitmap* icon; |
97 if (image.IsEmpty()) | 98 if (image.IsEmpty()) |
98 icon = rb.GetBitmapNamed(IDR_EXTENSIONS_SECTION); | 99 icon = rb.GetBitmapNamed(IDR_EXTENSIONS_SECTION); |
99 else | 100 else |
100 icon = image.ToSkBitmap(); | 101 icon = image.ToSkBitmap(); |
101 | 102 |
102 SkBitmap* drop_image = rb.GetBitmapNamed(IDR_APP_DROPARROW); | 103 SkBitmap* drop_image = rb.GetBitmapNamed(IDR_APP_DROPARROW); |
103 | 104 |
104 const int image_size = ExtensionIconSet::EXTENSION_ICON_BITTY; | 105 const int image_size = extension_misc::EXTENSION_ICON_BITTY; |
105 scoped_ptr<gfx::Canvas> canvas( | 106 scoped_ptr<gfx::Canvas> canvas( |
106 new gfx::Canvas( | 107 new gfx::Canvas( |
107 gfx::Size(image_size + kDropArrowLeftMarginPx + drop_image->width(), | 108 gfx::Size(image_size + kDropArrowLeftMarginPx + drop_image->width(), |
108 image_size), ui::SCALE_FACTOR_100P, false)); | 109 image_size), ui::SCALE_FACTOR_100P, false)); |
109 canvas->DrawImageInt(*icon, | 110 canvas->DrawImageInt(*icon, |
110 0, 0, icon->width(), icon->height(), | 111 0, 0, icon->width(), icon->height(), |
111 0, 0, image_size, image_size, | 112 0, 0, image_size, image_size, |
112 false); | 113 false); |
113 canvas->DrawImageInt(*drop_image, | 114 canvas->DrawImageInt(*drop_image, |
114 image_size + kDropArrowLeftMarginPx, | 115 image_size + kDropArrowLeftMarginPx, |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 | 274 |
274 InfoBar* ExtensionInfoBarDelegate::CreateInfoBar(InfoBarTabHelper* owner) { | 275 InfoBar* ExtensionInfoBarDelegate::CreateInfoBar(InfoBarTabHelper* owner) { |
275 NSWindow* window = | 276 NSWindow* window = |
276 [(NSView*)owner->web_contents()->GetContentNativeView() window]; | 277 [(NSView*)owner->web_contents()->GetContentNativeView() window]; |
277 ExtensionInfoBarController* controller = | 278 ExtensionInfoBarController* controller = |
278 [[ExtensionInfoBarController alloc] initWithDelegate:this | 279 [[ExtensionInfoBarController alloc] initWithDelegate:this |
279 owner:owner | 280 owner:owner |
280 window:window]; | 281 window:window]; |
281 return new InfoBar(controller, this); | 282 return new InfoBar(controller, this); |
282 } | 283 } |
OLD | NEW |