| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/ui/views/infobars/extension_infobar.h" | 5 #include "chrome/browser/ui/views/infobars/extension_infobar.h" |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/extension_context_menu_model.h" | 7 #include "chrome/browser/extensions/extension_context_menu_model.h" |
| 8 #include "chrome/browser/extensions/extension_host.h" | 8 #include "chrome/browser/extensions/extension_host.h" |
| 9 #include "chrome/browser/extensions/extension_infobar_delegate.h" | 9 #include "chrome/browser/extensions/extension_infobar_delegate.h" |
| 10 #include "chrome/browser/platform_util.h" | 10 #include "chrome/browser/platform_util.h" |
| 11 #include "chrome/browser/ui/views/frame/browser_view.h" | 11 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 12 #include "chrome/common/extensions/extension.h" | 12 #include "chrome/common/extensions/extension.h" |
| 13 #include "chrome/common/extensions/extension_icon_set.h" | 13 #include "chrome/common/extensions/extension_icon_set.h" |
| 14 #include "chrome/common/extensions/extension_resource.h" | 14 #include "chrome/common/extensions/extension_resource.h" |
| 15 #include "grit/theme_resources.h" | 15 #include "grit/theme_resources.h" |
| 16 #include "ui/base/animation/slide_animation.h" | 16 #include "ui/base/animation/slide_animation.h" |
| 17 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
| 18 #include "ui/gfx/canvas_skia.h" | 18 #include "ui/gfx/canvas_skia.h" |
| 19 #include "ui/gfx/image/image.h" |
| 19 #include "ui/views/controls/button/menu_button.h" | 20 #include "ui/views/controls/button/menu_button.h" |
| 20 #include "ui/views/controls/menu/menu_item_view.h" | 21 #include "ui/views/controls/menu/menu_item_view.h" |
| 21 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
| 22 | 23 |
| 23 // ExtensionInfoBarDelegate ---------------------------------------------------- | 24 // ExtensionInfoBarDelegate ---------------------------------------------------- |
| 24 | 25 |
| 25 InfoBar* ExtensionInfoBarDelegate::CreateInfoBar(InfoBarTabHelper* owner) { | 26 InfoBar* ExtensionInfoBarDelegate::CreateInfoBar(InfoBarTabHelper* owner) { |
| 26 return new ExtensionInfoBar(browser_, owner, this); | 27 return new ExtensionInfoBar(browser_, owner, this); |
| 27 } | 28 } |
| 28 | 29 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 // which assumes that particular children (e.g. the close button) have already | 91 // which assumes that particular children (e.g. the close button) have already |
| 91 // been added. | 92 // been added. |
| 92 const Extension* extension = extension_host->extension(); | 93 const Extension* extension = extension_host->extension(); |
| 93 int image_size = Extension::EXTENSION_ICON_BITTY; | 94 int image_size = Extension::EXTENSION_ICON_BITTY; |
| 94 ExtensionResource icon_resource = extension->GetIconResource( | 95 ExtensionResource icon_resource = extension->GetIconResource( |
| 95 image_size, ExtensionIconSet::MATCH_EXACTLY); | 96 image_size, ExtensionIconSet::MATCH_EXACTLY); |
| 96 if (!icon_resource.relative_path().empty()) { | 97 if (!icon_resource.relative_path().empty()) { |
| 97 tracker_.LoadImage(extension, icon_resource, | 98 tracker_.LoadImage(extension, icon_resource, |
| 98 gfx::Size(image_size, image_size), ImageLoadingTracker::DONT_CACHE); | 99 gfx::Size(image_size, image_size), ImageLoadingTracker::DONT_CACHE); |
| 99 } else { | 100 } else { |
| 100 OnImageLoaded(NULL, icon_resource, 0); | 101 OnImageLoaded(NULL, std::string(), 0); |
| 101 } | 102 } |
| 102 } | 103 } |
| 103 | 104 |
| 104 int ExtensionInfoBar::ContentMinimumWidth() const { | 105 int ExtensionInfoBar::ContentMinimumWidth() const { |
| 105 return menu_->GetPreferredSize().width() + kMenuHorizontalMargin; | 106 return menu_->GetPreferredSize().width() + kMenuHorizontalMargin; |
| 106 } | 107 } |
| 107 | 108 |
| 108 void ExtensionInfoBar::OnImageLoaded(SkBitmap* image, | 109 void ExtensionInfoBar::OnImageLoaded(const gfx::Image* image, |
| 109 const ExtensionResource& resource, | 110 const std::string& extension_id, |
| 110 int index) { | 111 int index) { |
| 111 if (!GetDelegate()) | 112 if (!GetDelegate()) |
| 112 return; // The delegate can go away while we asynchronously load images. | 113 return; // The delegate can go away while we asynchronously load images. |
| 113 | 114 |
| 114 SkBitmap* icon = image; | 115 const SkBitmap* icon = NULL; |
| 115 // Fall back on the default extension icon on failure. | 116 // Fall back on the default extension icon on failure. |
| 116 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 117 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 117 if (!image || image->empty()) | 118 if (!image || image->IsEmpty()) |
| 118 icon = rb.GetBitmapNamed(IDR_EXTENSIONS_SECTION); | 119 icon = rb.GetBitmapNamed(IDR_EXTENSIONS_SECTION); |
| 120 else |
| 121 icon = image->AsSkBitmap(); |
| 119 | 122 |
| 120 SkBitmap* drop_image = rb.GetBitmapNamed(IDR_APP_DROPARROW); | 123 SkBitmap* drop_image = rb.GetBitmapNamed(IDR_APP_DROPARROW); |
| 121 | 124 |
| 122 int image_size = Extension::EXTENSION_ICON_BITTY; | 125 int image_size = Extension::EXTENSION_ICON_BITTY; |
| 123 // The margin between the extension icon and the drop-down arrow bitmap. | 126 // The margin between the extension icon and the drop-down arrow bitmap. |
| 124 static const int kDropArrowLeftMargin = 3; | 127 static const int kDropArrowLeftMargin = 3; |
| 125 scoped_ptr<gfx::CanvasSkia> canvas(new gfx::CanvasSkia( | 128 scoped_ptr<gfx::CanvasSkia> canvas(new gfx::CanvasSkia( |
| 126 gfx::Size(image_size + kDropArrowLeftMargin + drop_image->width(), | 129 gfx::Size(image_size + kDropArrowLeftMargin + drop_image->width(), |
| 127 image_size), | 130 image_size), |
| 128 false)); | 131 false)); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 149 | 152 |
| 150 scoped_refptr<ExtensionContextMenuModel> options_menu_contents = | 153 scoped_refptr<ExtensionContextMenuModel> options_menu_contents = |
| 151 new ExtensionContextMenuModel(extension, browser_, NULL); | 154 new ExtensionContextMenuModel(extension, browser_, NULL); |
| 152 DCHECK_EQ(source, menu_); | 155 DCHECK_EQ(source, menu_); |
| 153 RunMenuAt(options_menu_contents.get(), menu_, views::MenuItemView::TOPLEFT); | 156 RunMenuAt(options_menu_contents.get(), menu_, views::MenuItemView::TOPLEFT); |
| 154 } | 157 } |
| 155 | 158 |
| 156 ExtensionInfoBarDelegate* ExtensionInfoBar::GetDelegate() { | 159 ExtensionInfoBarDelegate* ExtensionInfoBar::GetDelegate() { |
| 157 return delegate_ ? delegate_->AsExtensionInfoBarDelegate() : NULL; | 160 return delegate_ ? delegate_->AsExtensionInfoBarDelegate() : NULL; |
| 158 } | 161 } |
| OLD | NEW |