Chromium Code Reviews| 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 if (!icon_resource.relative_path().empty()) { |
|
Mihai Parparita -not on Chrome
2012/02/23 00:19:41
Seems like you could remove this check, since Imag
sail
2012/02/23 02:54:27
Done.
| |
| 75 tracker_.LoadImage(extension, icon_resource, | 76 tracker_.LoadImage(extension, icon_resource, |
| 76 gfx::Size(Extension::EXTENSION_ICON_BITTY, | 77 gfx::Size(Extension::EXTENSION_ICON_BITTY, |
| 77 Extension::EXTENSION_ICON_BITTY), | 78 Extension::EXTENSION_ICON_BITTY), |
| 78 ImageLoadingTracker::DONT_CACHE); | 79 ImageLoadingTracker::DONT_CACHE); |
| 79 } else { | 80 } else { |
| 80 OnImageLoaded(NULL, icon_resource, 0); | 81 OnImageLoaded(NULL, std::string(), 0); |
| 81 } | 82 } |
| 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( | 88 virtual void OnImageLoaded(const gfx::Image* image, |
| 88 SkBitmap* image, const ExtensionResource& resource, int index) { | 89 const std::string& extension_id, |
| 90 int index) OVERRIDE { | |
| 89 if (!delegate_) | 91 if (!delegate_) |
| 90 return; // The delegate can go away while the image asynchronously loads. | 92 return; // The delegate can go away while the image asynchronously loads. |
| 91 | 93 |
| 92 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 94 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 93 | 95 |
| 94 // Fall back on the default extension icon on failure. | 96 // Fall back on the default extension icon on failure. |
| 95 SkBitmap* icon; | 97 const SkBitmap* icon; |
| 96 if (!image || image->empty()) | 98 if (!image || image->IsEmpty()) |
| 97 icon = rb.GetBitmapNamed(IDR_EXTENSIONS_SECTION); | 99 icon = rb.GetBitmapNamed(IDR_EXTENSIONS_SECTION); |
| 98 else | 100 else |
| 99 icon = image; | 101 icon = image->ToSkBitmap(); |
| 100 | 102 |
| 101 SkBitmap* drop_image = rb.GetBitmapNamed(IDR_APP_DROPARROW); | 103 SkBitmap* drop_image = rb.GetBitmapNamed(IDR_APP_DROPARROW); |
| 102 | 104 |
| 103 const int image_size = Extension::EXTENSION_ICON_BITTY; | 105 const int image_size = Extension::EXTENSION_ICON_BITTY; |
| 104 scoped_ptr<gfx::CanvasSkia> canvas( | 106 scoped_ptr<gfx::CanvasSkia> canvas( |
| 105 new gfx::CanvasSkia( | 107 new gfx::CanvasSkia( |
| 106 gfx::Size(image_size + kDropArrowLeftMarginPx + drop_image->width(), | 108 gfx::Size(image_size + kDropArrowLeftMarginPx + drop_image->width(), |
| 107 image_size), false)); | 109 image_size), false)); |
| 108 canvas->DrawBitmapInt(*icon, | 110 canvas->DrawBitmapInt(*icon, |
| 109 0, 0, icon->width(), icon->height(), | 111 0, 0, icon->width(), icon->height(), |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 269 | 271 |
| 270 InfoBar* ExtensionInfoBarDelegate::CreateInfoBar(InfoBarTabHelper* owner) { | 272 InfoBar* ExtensionInfoBarDelegate::CreateInfoBar(InfoBarTabHelper* owner) { |
| 271 NSWindow* window = | 273 NSWindow* window = |
| 272 [(NSView*)owner->web_contents()->GetContentNativeView() window]; | 274 [(NSView*)owner->web_contents()->GetContentNativeView() window]; |
| 273 ExtensionInfoBarController* controller = | 275 ExtensionInfoBarController* controller = |
| 274 [[ExtensionInfoBarController alloc] initWithDelegate:this | 276 [[ExtensionInfoBarController alloc] initWithDelegate:this |
| 275 owner:owner | 277 owner:owner |
| 276 window:window]; | 278 window:window]; |
| 277 return new InfoBar(controller, this); | 279 return new InfoBar(controller, this); |
| 278 } | 280 } |
| OLD | NEW |