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 #import "chrome/browser/ui/cocoa/animatable_view.h" | 13 #import "chrome/browser/ui/cocoa/animatable_view.h" |
14 #import "chrome/browser/ui/cocoa/extensions/extension_action_context_menu.h" | 14 #import "chrome/browser/ui/cocoa/extensions/extension_action_context_menu.h" |
15 #import "chrome/browser/ui/cocoa/menu_button.h" | 15 #import "chrome/browser/ui/cocoa/menu_button.h" |
16 #include "chrome/browser/ui/cocoa/infobars/infobar.h" | 16 #include "chrome/browser/ui/cocoa/infobars/infobar.h" |
17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
18 #include "chrome/common/extensions/extension.h" | 18 #include "chrome/common/extensions/extension.h" |
19 #include "chrome/common/extensions/extension_icon_set.h" | 19 #include "chrome/common/extensions/extension_icon_set.h" |
20 #include "chrome/common/extensions/extension_resource.h" | 20 #include "chrome/common/extensions/extension_resource.h" |
21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
22 #include "grit/theme_resources.h" | 22 #include "grit/theme_resources.h" |
23 #include "skia/ext/skia_utils_mac.h" | 23 #include "skia/ext/skia_utils_mac.h" |
24 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
25 #include "ui/gfx/canvas_skia.h" | 25 #include "ui/gfx/canvas_skia.h" |
| 26 #include "ui/gfx/image/image.h" |
26 | 27 |
27 namespace { | 28 namespace { |
28 const CGFloat kAnimationDuration = 0.12; | 29 const CGFloat kAnimationDuration = 0.12; |
29 const CGFloat kBottomBorderHeightPx = 1.0; | 30 const CGFloat kBottomBorderHeightPx = 1.0; |
30 const CGFloat kButtonHeightPx = 26.0; | 31 const CGFloat kButtonHeightPx = 26.0; |
31 const CGFloat kButtonLeftMarginPx = 2.0; | 32 const CGFloat kButtonLeftMarginPx = 2.0; |
32 const CGFloat kButtonWidthPx = 34.0; | 33 const CGFloat kButtonWidthPx = 34.0; |
33 const CGFloat kDropArrowLeftMarginPx = 3.0; | 34 const CGFloat kDropArrowLeftMarginPx = 3.0; |
34 const CGFloat kToolbarMinHeightPx = 36.0; | 35 const CGFloat kToolbarMinHeightPx = 36.0; |
35 const CGFloat kToolbarMaxHeightPx = 72.0; | 36 const CGFloat kToolbarMaxHeightPx = 72.0; |
(...skipping 29 matching lines...) Expand all Loading... |
65 if (delegate_) | 66 if (delegate_) |
66 delegate_->set_observer(NULL); | 67 delegate_->set_observer(NULL); |
67 } | 68 } |
68 | 69 |
69 // Load the Extension's icon image. | 70 // Load the Extension's icon image. |
70 void LoadIcon() { | 71 void LoadIcon() { |
71 const Extension* extension = delegate_->extension_host()->extension(); | 72 const Extension* extension = delegate_->extension_host()->extension(); |
72 ExtensionResource icon_resource = | 73 ExtensionResource icon_resource = |
73 extension->GetIconResource(ExtensionIconSet::EXTENSION_ICON_BITTY, | 74 extension->GetIconResource(ExtensionIconSet::EXTENSION_ICON_BITTY, |
74 ExtensionIconSet::MATCH_EXACTLY); | 75 ExtensionIconSet::MATCH_EXACTLY); |
75 if (!icon_resource.relative_path().empty()) { | 76 tracker_.LoadImage(extension, icon_resource, |
76 tracker_.LoadImage(extension, icon_resource, | 77 gfx::Size(ExtensionIconSet::EXTENSION_ICON_BITTY, |
77 gfx::Size(ExtensionIconSet::EXTENSION_ICON_BITTY, | 78 ExtensionIconSet::EXTENSION_ICON_BITTY), |
78 ExtensionIconSet::EXTENSION_ICON_BITTY), | 79 ImageLoadingTracker::DONT_CACHE); |
79 ImageLoadingTracker::DONT_CACHE); | |
80 } else { | |
81 OnImageLoaded(NULL, icon_resource, 0); | |
82 } | |
83 } | 80 } |
84 | 81 |
85 // ImageLoadingTracker::Observer implementation. | 82 // ImageLoadingTracker::Observer implementation. |
86 // TODO(andybons): The infobar view implementations share a lot of the same | 83 // TODO(andybons): The infobar view implementations share a lot of the same |
87 // code. Come up with a strategy to share amongst them. | 84 // code. Come up with a strategy to share amongst them. |
88 virtual void OnImageLoaded( | 85 virtual void OnImageLoaded(const gfx::Image& image, |
89 SkBitmap* image, const ExtensionResource& resource, int index) { | 86 const std::string& extension_id, |
| 87 int index) OVERRIDE { |
90 if (!delegate_) | 88 if (!delegate_) |
91 return; // The delegate can go away while the image asynchronously loads. | 89 return; // The delegate can go away while the image asynchronously loads. |
92 | 90 |
93 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 91 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
94 | 92 |
95 // Fall back on the default extension icon on failure. | 93 // Fall back on the default extension icon on failure. |
96 SkBitmap* icon; | 94 const SkBitmap* icon; |
97 if (!image || image->empty()) | 95 if (image.IsEmpty()) |
98 icon = rb.GetBitmapNamed(IDR_EXTENSIONS_SECTION); | 96 icon = rb.GetBitmapNamed(IDR_EXTENSIONS_SECTION); |
99 else | 97 else |
100 icon = image; | 98 icon = image.ToSkBitmap(); |
101 | 99 |
102 SkBitmap* drop_image = rb.GetBitmapNamed(IDR_APP_DROPARROW); | 100 SkBitmap* drop_image = rb.GetBitmapNamed(IDR_APP_DROPARROW); |
103 | 101 |
104 const int image_size = ExtensionIconSet::EXTENSION_ICON_BITTY; | 102 const int image_size = ExtensionIconSet::EXTENSION_ICON_BITTY; |
105 scoped_ptr<gfx::CanvasSkia> canvas( | 103 scoped_ptr<gfx::CanvasSkia> canvas( |
106 new gfx::CanvasSkia( | 104 new gfx::CanvasSkia( |
107 gfx::Size(image_size + kDropArrowLeftMarginPx + drop_image->width(), | 105 gfx::Size(image_size + kDropArrowLeftMarginPx + drop_image->width(), |
108 image_size), false)); | 106 image_size), false)); |
109 canvas->DrawBitmapInt(*icon, | 107 canvas->DrawBitmapInt(*icon, |
110 0, 0, icon->width(), icon->height(), | 108 0, 0, icon->width(), icon->height(), |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 | 268 |
271 InfoBar* ExtensionInfoBarDelegate::CreateInfoBar(InfoBarTabHelper* owner) { | 269 InfoBar* ExtensionInfoBarDelegate::CreateInfoBar(InfoBarTabHelper* owner) { |
272 NSWindow* window = | 270 NSWindow* window = |
273 [(NSView*)owner->web_contents()->GetContentNativeView() window]; | 271 [(NSView*)owner->web_contents()->GetContentNativeView() window]; |
274 ExtensionInfoBarController* controller = | 272 ExtensionInfoBarController* controller = |
275 [[ExtensionInfoBarController alloc] initWithDelegate:this | 273 [[ExtensionInfoBarController alloc] initWithDelegate:this |
276 owner:owner | 274 owner:owner |
277 window:window]; | 275 window:window]; |
278 return new InfoBar(controller, this); | 276 return new InfoBar(controller, this); |
279 } | 277 } |
OLD | NEW |