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 28 matching lines...) Expand all Loading... | |
64 virtual ~InfobarBridge() { | 65 virtual ~InfobarBridge() { |
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 = extension->GetIconResource( | 73 ExtensionResource icon_resource = extension->GetIconResource( |
73 Extension::EXTENSION_ICON_BITTY, ExtensionIconSet::MATCH_EXACTLY); | 74 Extension::EXTENSION_ICON_BITTY, ExtensionIconSet::MATCH_EXACTLY); |
74 if (!icon_resource.relative_path().empty()) { | 75 tracker_.LoadImage(extension, icon_resource, |
Finnur
2012/02/23 12:05:42
Hmmm... are you sure about this being redundant?
Mihai Parparita -not on Chrome
2012/02/23 18:37:58
ImageLoadingTracker::LoadImage has the same resour
| |
75 tracker_.LoadImage(extension, icon_resource, | 76 gfx::Size(Extension::EXTENSION_ICON_BITTY, |
76 gfx::Size(Extension::EXTENSION_ICON_BITTY, | 77 Extension::EXTENSION_ICON_BITTY), |
77 Extension::EXTENSION_ICON_BITTY), | 78 ImageLoadingTracker::DONT_CACHE); |
78 ImageLoadingTracker::DONT_CACHE); | |
79 } else { | |
80 OnImageLoaded(NULL, icon_resource, 0); | |
81 } | |
82 } | 79 } |
83 | 80 |
84 // ImageLoadingTracker::Observer implementation. | 81 // ImageLoadingTracker::Observer implementation. |
85 // TODO(andybons): The infobar view implementations share a lot of the same | 82 // TODO(andybons): The infobar view implementations share a lot of the same |
86 // code. Come up with a strategy to share amongst them. | 83 // code. Come up with a strategy to share amongst them. |
87 virtual void OnImageLoaded( | 84 virtual void OnImageLoaded(const gfx::Image* image, |
88 SkBitmap* image, const ExtensionResource& resource, int index) { | 85 const std::string& extension_id, |
86 int index) OVERRIDE { | |
89 if (!delegate_) | 87 if (!delegate_) |
90 return; // The delegate can go away while the image asynchronously loads. | 88 return; // The delegate can go away while the image asynchronously loads. |
91 | 89 |
92 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 90 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
93 | 91 |
94 // Fall back on the default extension icon on failure. | 92 // Fall back on the default extension icon on failure. |
95 SkBitmap* icon; | 93 const SkBitmap* icon; |
96 if (!image || image->empty()) | 94 if (!image || image->IsEmpty()) |
97 icon = rb.GetBitmapNamed(IDR_EXTENSIONS_SECTION); | 95 icon = rb.GetBitmapNamed(IDR_EXTENSIONS_SECTION); |
98 else | 96 else |
99 icon = image; | 97 icon = image->ToSkBitmap(); |
100 | 98 |
101 SkBitmap* drop_image = rb.GetBitmapNamed(IDR_APP_DROPARROW); | 99 SkBitmap* drop_image = rb.GetBitmapNamed(IDR_APP_DROPARROW); |
102 | 100 |
103 const int image_size = Extension::EXTENSION_ICON_BITTY; | 101 const int image_size = Extension::EXTENSION_ICON_BITTY; |
104 scoped_ptr<gfx::CanvasSkia> canvas( | 102 scoped_ptr<gfx::CanvasSkia> canvas( |
105 new gfx::CanvasSkia( | 103 new gfx::CanvasSkia( |
106 gfx::Size(image_size + kDropArrowLeftMarginPx + drop_image->width(), | 104 gfx::Size(image_size + kDropArrowLeftMarginPx + drop_image->width(), |
107 image_size), false)); | 105 image_size), false)); |
108 canvas->DrawBitmapInt(*icon, | 106 canvas->DrawBitmapInt(*icon, |
109 0, 0, icon->width(), icon->height(), | 107 0, 0, icon->width(), icon->height(), |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 | 267 |
270 InfoBar* ExtensionInfoBarDelegate::CreateInfoBar(InfoBarTabHelper* owner) { | 268 InfoBar* ExtensionInfoBarDelegate::CreateInfoBar(InfoBarTabHelper* owner) { |
271 NSWindow* window = | 269 NSWindow* window = |
272 [(NSView*)owner->web_contents()->GetContentNativeView() window]; | 270 [(NSView*)owner->web_contents()->GetContentNativeView() window]; |
273 ExtensionInfoBarController* controller = | 271 ExtensionInfoBarController* controller = |
274 [[ExtensionInfoBarController alloc] initWithDelegate:this | 272 [[ExtensionInfoBarController alloc] initWithDelegate:this |
275 owner:owner | 273 owner:owner |
276 window:window]; | 274 window:window]; |
277 return new InfoBar(controller, this); | 275 return new InfoBar(controller, this); |
278 } | 276 } |
OLD | NEW |