| 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 #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_infobar_delegate.h" | 8 #include "chrome/browser/extensions/extension_infobar_delegate.h" |
| 9 #include "chrome/browser/extensions/extension_view_host.h" | 9 #include "chrome/browser/extensions/extension_view_host.h" |
| 10 #include "chrome/browser/extensions/image_loader.h" | 10 #include "chrome/browser/extensions/image_loader.h" |
| 11 #include "chrome/browser/platform_util.h" | 11 #include "chrome/browser/platform_util.h" |
| 12 #include "chrome/browser/ui/views/frame/browser_view.h" | 12 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 13 #include "extensions/common/constants.h" | 13 #include "extensions/common/constants.h" |
| 14 #include "extensions/common/extension.h" | 14 #include "extensions/common/extension.h" |
| 15 #include "extensions/common/extension_icon_set.h" | 15 #include "extensions/common/extension_icon_set.h" |
| 16 #include "extensions/common/extension_resource.h" | 16 #include "extensions/common/extension_resource.h" |
| 17 #include "extensions/common/manifest_handlers/icons_handler.h" | 17 #include "extensions/common/manifest_handlers/icons_handler.h" |
| 18 #include "grit/theme_resources.h" | 18 #include "grit/theme_resources.h" |
| 19 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
| 20 #include "ui/gfx/animation/slide_animation.h" | 20 #include "ui/gfx/animation/slide_animation.h" |
| 21 #include "ui/gfx/canvas.h" | 21 #include "ui/gfx/canvas.h" |
| 22 #include "ui/gfx/image/canvas_image_source.h" | 22 #include "ui/gfx/image/canvas_image_source.h" |
| 23 #include "ui/gfx/image/image.h" | 23 #include "ui/gfx/image/image.h" |
| 24 #include "ui/views/controls/button/menu_button.h" | 24 #include "ui/views/controls/button/menu_button.h" |
| 25 #include "ui/views/controls/image_view.h" | 25 #include "ui/views/controls/image_view.h" |
| 26 #include "ui/views/controls/menu/menu_item_view.h" | |
| 27 #include "ui/views/widget/widget.h" | 26 #include "ui/views/widget/widget.h" |
| 28 | 27 |
| 29 | 28 |
| 30 // ExtensionInfoBarDelegate ---------------------------------------------------- | 29 // ExtensionInfoBarDelegate ---------------------------------------------------- |
| 31 | 30 |
| 32 // static | 31 // static |
| 33 scoped_ptr<infobars::InfoBar> ExtensionInfoBarDelegate::CreateInfoBar( | 32 scoped_ptr<infobars::InfoBar> ExtensionInfoBarDelegate::CreateInfoBar( |
| 34 scoped_ptr<ExtensionInfoBarDelegate> delegate) { | 33 scoped_ptr<ExtensionInfoBarDelegate> delegate) { |
| 35 Browser* browser = delegate->browser_; | 34 Browser* browser = delegate->browser_; |
| 36 return scoped_ptr<infobars::InfoBar>( | 35 return scoped_ptr<infobars::InfoBar>( |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 const gfx::Point& point) { | 178 const gfx::Point& point) { |
| 180 if (!owner()) | 179 if (!owner()) |
| 181 return; // We're closing; don't call anything, it might access the owner. | 180 return; // We're closing; don't call anything, it might access the owner. |
| 182 const extensions::Extension* extension = | 181 const extensions::Extension* extension = |
| 183 GetDelegate()->extension_view_host()->extension(); | 182 GetDelegate()->extension_view_host()->extension(); |
| 184 DCHECK(icon_as_menu_); | 183 DCHECK(icon_as_menu_); |
| 185 | 184 |
| 186 scoped_refptr<ExtensionContextMenuModel> options_menu_contents = | 185 scoped_refptr<ExtensionContextMenuModel> options_menu_contents = |
| 187 new ExtensionContextMenuModel(extension, browser_); | 186 new ExtensionContextMenuModel(extension, browser_); |
| 188 DCHECK_EQ(icon_as_menu_, source); | 187 DCHECK_EQ(icon_as_menu_, source); |
| 189 RunMenuAt(options_menu_contents.get(), | 188 RunMenuAt( |
| 190 icon_as_menu_, | 189 options_menu_contents.get(), icon_as_menu_, ui::MENU_ANCHOR_TOPLEFT); |
| 191 views::MenuItemView::TOPLEFT); | |
| 192 } | 190 } |
| 193 | 191 |
| 194 void ExtensionInfoBar::OnImageLoaded(const gfx::Image& image) { | 192 void ExtensionInfoBar::OnImageLoaded(const gfx::Image& image) { |
| 195 if (!GetDelegate()) | 193 if (!GetDelegate()) |
| 196 return; // The delegate can go away while we asynchronously load images. | 194 return; // The delegate can go away while we asynchronously load images. |
| 197 | 195 |
| 198 const gfx::ImageSkia* icon = NULL; | 196 const gfx::ImageSkia* icon = NULL; |
| 199 // Fall back on the default extension icon on failure. | 197 // Fall back on the default extension icon on failure. |
| 200 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 198 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 201 if (image.IsEmpty()) | 199 if (image.IsEmpty()) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 220 Layout(); | 218 Layout(); |
| 221 } | 219 } |
| 222 | 220 |
| 223 ExtensionInfoBarDelegate* ExtensionInfoBar::GetDelegate() { | 221 ExtensionInfoBarDelegate* ExtensionInfoBar::GetDelegate() { |
| 224 return delegate()->AsExtensionInfoBarDelegate(); | 222 return delegate()->AsExtensionInfoBarDelegate(); |
| 225 } | 223 } |
| 226 | 224 |
| 227 int ExtensionInfoBar::NonExtensionViewWidth() const { | 225 int ExtensionInfoBar::NonExtensionViewWidth() const { |
| 228 return infobar_icon_->width() + kIconHorizontalMargin; | 226 return infobar_icon_->width() + kIconHorizontalMargin; |
| 229 } | 227 } |
| OLD | NEW |