Chromium Code Reviews| 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 "views/controls/button/menu_button.h" | 19 #include "views/controls/button/menu_button.h" |
| 20 #include "views/controls/menu/menu_item_view.h" | 20 #include "views/controls/menu/menu_item_view.h" |
| 21 #include "views/widget/widget.h" | 21 #include "views/widget/widget.h" |
| 22 | 22 |
| 23 // ExtensionInfoBarDelegate ---------------------------------------------------- | 23 // ExtensionInfoBarDelegate ---------------------------------------------------- |
| 24 | 24 |
| 25 InfoBar* ExtensionInfoBarDelegate::CreateInfoBar(TabContentsWrapper* owner) { | 25 InfoBar* ExtensionInfoBarDelegate::CreateInfoBar(TabContentsWrapper* owner) { |
| 26 return new ExtensionInfoBar(owner, this); | 26 return new ExtensionInfoBar(browser(), owner, this); |
| 27 } | 27 } |
| 28 | 28 |
| 29 // ExtensionInfoBar ------------------------------------------------------------ | 29 // ExtensionInfoBar ------------------------------------------------------------ |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| 32 // The horizontal margin between the menu and the Extension (HTML) view. | 32 // The horizontal margin between the menu and the Extension (HTML) view. |
| 33 const int kMenuHorizontalMargin = 1; | 33 const int kMenuHorizontalMargin = 1; |
| 34 } // namespace | 34 } // namespace |
| 35 | 35 |
| 36 ExtensionInfoBar::ExtensionInfoBar(TabContentsWrapper* owner, | 36 ExtensionInfoBar::ExtensionInfoBar(Browser* browser, |
|
Peter Kasting
2011/09/29 17:39:20
Nit: This should probably go at the end of the lis
| |
| 37 TabContentsWrapper* owner, | |
| 37 ExtensionInfoBarDelegate* delegate) | 38 ExtensionInfoBarDelegate* delegate) |
| 38 : InfoBarView(owner, delegate), | 39 : InfoBarView(owner, delegate), |
| 40 browser_(browser), | |
| 39 delegate_(delegate), | 41 delegate_(delegate), |
| 40 menu_(NULL), | 42 menu_(NULL), |
| 41 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) { | 43 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) { |
| 42 delegate->set_observer(this); | 44 delegate->set_observer(this); |
| 43 | 45 |
| 44 int height = delegate->height(); | 46 int height = delegate->height(); |
| 45 SetBarTargetHeight((height > 0) ? (height + kSeparatorLineHeight) : 0); | 47 SetBarTargetHeight((height > 0) ? (height + kSeparatorLineHeight) : 0); |
| 46 } | 48 } |
| 47 | 49 |
| 48 ExtensionInfoBar::~ExtensionInfoBar() { | 50 ExtensionInfoBar::~ExtensionInfoBar() { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 | 136 |
| 135 void ExtensionInfoBar::OnDelegateDeleted() { | 137 void ExtensionInfoBar::OnDelegateDeleted() { |
| 136 delegate_ = NULL; | 138 delegate_ = NULL; |
| 137 } | 139 } |
| 138 | 140 |
| 139 void ExtensionInfoBar::RunMenu(View* source, const gfx::Point& pt) { | 141 void ExtensionInfoBar::RunMenu(View* source, const gfx::Point& pt) { |
| 140 const Extension* extension = GetDelegate()->extension_host()->extension(); | 142 const Extension* extension = GetDelegate()->extension_host()->extension(); |
| 141 if (!extension->ShowConfigureContextMenus()) | 143 if (!extension->ShowConfigureContextMenus()) |
| 142 return; | 144 return; |
| 143 | 145 |
| 144 Browser* browser = BrowserView::GetBrowserViewForNativeWindow( | |
| 145 platform_util::GetTopLevel(source->GetWidget()->GetNativeView()))-> | |
| 146 browser(); | |
| 147 scoped_refptr<ExtensionContextMenuModel> options_menu_contents = | 146 scoped_refptr<ExtensionContextMenuModel> options_menu_contents = |
| 148 new ExtensionContextMenuModel(extension, browser, NULL); | 147 new ExtensionContextMenuModel(extension, browser_, NULL); |
| 149 DCHECK_EQ(source, menu_); | 148 DCHECK_EQ(source, menu_); |
| 150 RunMenuAt(options_menu_contents.get(), menu_, views::MenuItemView::TOPLEFT); | 149 RunMenuAt(options_menu_contents.get(), menu_, views::MenuItemView::TOPLEFT); |
| 151 // TODO(pkasting): this may be deleted after rewrite. | 150 // TODO(pkasting): this may be deleted after rewrite. |
| 152 } | 151 } |
| 153 | 152 |
| 154 ExtensionInfoBarDelegate* ExtensionInfoBar::GetDelegate() { | 153 ExtensionInfoBarDelegate* ExtensionInfoBar::GetDelegate() { |
| 155 return delegate_ ? delegate_->AsExtensionInfoBarDelegate() : NULL; | 154 return delegate_ ? delegate_->AsExtensionInfoBarDelegate() : NULL; |
| 156 } | 155 } |
| OLD | NEW |