| 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" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 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" | 26 #include "ui/views/controls/menu/menu_item_view.h" |
| 27 #include "ui/views/widget/widget.h" | 27 #include "ui/views/widget/widget.h" |
| 28 | 28 |
| 29 | 29 |
| 30 // ExtensionInfoBarDelegate ---------------------------------------------------- | 30 // ExtensionInfoBarDelegate ---------------------------------------------------- |
| 31 | 31 |
| 32 InfoBar* ExtensionInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { | 32 // static |
| 33 return new ExtensionInfoBar(owner, this, browser_); | 33 scoped_ptr<InfoBar> ExtensionInfoBarDelegate::CreateInfoBar( |
| 34 scoped_ptr<ExtensionInfoBarDelegate> delegate) { |
| 35 Browser* browser = delegate->browser_; |
| 36 return scoped_ptr<InfoBar>(new ExtensionInfoBar(delegate.Pass(), browser)); |
| 34 } | 37 } |
| 35 | 38 |
| 36 | 39 |
| 37 // ExtensionInfoBar ------------------------------------------------------------ | 40 // ExtensionInfoBar ------------------------------------------------------------ |
| 38 | 41 |
| 39 namespace { | 42 namespace { |
| 40 // The horizontal margin between the infobar icon and the Extension (HTML) view. | 43 // The horizontal margin between the infobar icon and the Extension (HTML) view. |
| 41 const int kIconHorizontalMargin = 1; | 44 const int kIconHorizontalMargin = 1; |
| 42 | 45 |
| 43 class MenuImageSource: public gfx::CanvasImageSource { | 46 class MenuImageSource: public gfx::CanvasImageSource { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 71 static const int kDropArrowLeftMargin = 3; | 74 static const int kDropArrowLeftMargin = 3; |
| 72 | 75 |
| 73 const gfx::ImageSkia icon_; | 76 const gfx::ImageSkia icon_; |
| 74 const gfx::ImageSkia drop_image_; | 77 const gfx::ImageSkia drop_image_; |
| 75 | 78 |
| 76 DISALLOW_COPY_AND_ASSIGN(MenuImageSource); | 79 DISALLOW_COPY_AND_ASSIGN(MenuImageSource); |
| 77 }; | 80 }; |
| 78 | 81 |
| 79 } // namespace | 82 } // namespace |
| 80 | 83 |
| 81 ExtensionInfoBar::ExtensionInfoBar(InfoBarService* owner, | 84 ExtensionInfoBar::ExtensionInfoBar( |
| 82 ExtensionInfoBarDelegate* delegate, | 85 scoped_ptr<ExtensionInfoBarDelegate> delegate, |
| 83 Browser* browser) | 86 Browser* browser) |
| 84 : InfoBarView(owner, delegate), | 87 : InfoBarView(delegate.PassAs<InfoBarDelegate>()), |
| 85 delegate_(delegate), | |
| 86 browser_(browser), | 88 browser_(browser), |
| 87 infobar_icon_(NULL), | 89 infobar_icon_(NULL), |
| 88 icon_as_menu_(NULL), | 90 icon_as_menu_(NULL), |
| 89 icon_as_image_(NULL), | 91 icon_as_image_(NULL), |
| 90 weak_ptr_factory_(this) { | 92 weak_ptr_factory_(this) { |
| 91 GetDelegate()->set_observer(this); | |
| 92 | |
| 93 int height = GetDelegate()->height(); | 93 int height = GetDelegate()->height(); |
| 94 SetBarTargetHeight((height > 0) ? (height + kSeparatorLineHeight) : 0); | 94 SetBarTargetHeight((height > 0) ? (height + kSeparatorLineHeight) : 0); |
| 95 } | 95 } |
| 96 | 96 |
| 97 ExtensionInfoBar::~ExtensionInfoBar() { | 97 ExtensionInfoBar::~ExtensionInfoBar() { |
| 98 if (GetDelegate()) | |
| 99 GetDelegate()->set_observer(NULL); | |
| 100 } | 98 } |
| 101 | 99 |
| 102 void ExtensionInfoBar::Layout() { | 100 void ExtensionInfoBar::Layout() { |
| 103 InfoBarView::Layout(); | 101 InfoBarView::Layout(); |
| 104 | 102 |
| 105 gfx::Size size = infobar_icon_->GetPreferredSize(); | 103 gfx::Size size = infobar_icon_->GetPreferredSize(); |
| 106 infobar_icon_->SetBounds(StartX(), OffsetY(size), size.width(), | 104 infobar_icon_->SetBounds(StartX(), OffsetY(size), size.width(), |
| 107 size.height()); | 105 size.height()); |
| 108 | 106 |
| 109 GetDelegate()->extension_view_host()->view()->SetBounds( | 107 GetDelegate()->extension_view_host()->view()->SetBounds( |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 gfx::Size(image_size, image_size), | 157 gfx::Size(image_size, image_size), |
| 160 base::Bind(&ExtensionInfoBar::OnImageLoaded, | 158 base::Bind(&ExtensionInfoBar::OnImageLoaded, |
| 161 weak_ptr_factory_.GetWeakPtr())); | 159 weak_ptr_factory_.GetWeakPtr())); |
| 162 } | 160 } |
| 163 | 161 |
| 164 int ExtensionInfoBar::ContentMinimumWidth() const { | 162 int ExtensionInfoBar::ContentMinimumWidth() const { |
| 165 return infobar_icon_->GetPreferredSize().width() + kIconHorizontalMargin; | 163 return infobar_icon_->GetPreferredSize().width() + kIconHorizontalMargin; |
| 166 | 164 |
| 167 } | 165 } |
| 168 | 166 |
| 169 void ExtensionInfoBar::OnDelegateDeleted() { | |
| 170 delegate_ = NULL; | |
| 171 } | |
| 172 | |
| 173 void ExtensionInfoBar::OnMenuButtonClicked(views::View* source, | 167 void ExtensionInfoBar::OnMenuButtonClicked(views::View* source, |
| 174 const gfx::Point& point) { | 168 const gfx::Point& point) { |
| 175 if (!owner()) | 169 if (!owner()) |
| 176 return; // We're closing; don't call anything, it might access the owner. | 170 return; // We're closing; don't call anything, it might access the owner. |
| 177 const extensions::Extension* extension = | 171 const extensions::Extension* extension = |
| 178 GetDelegate()->extension_view_host()->extension(); | 172 GetDelegate()->extension_view_host()->extension(); |
| 179 DCHECK(icon_as_menu_); | 173 DCHECK(icon_as_menu_); |
| 180 | 174 |
| 181 scoped_refptr<ExtensionContextMenuModel> options_menu_contents = | 175 scoped_refptr<ExtensionContextMenuModel> options_menu_contents = |
| 182 new ExtensionContextMenuModel(extension, browser_); | 176 new ExtensionContextMenuModel(extension, browser_); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 208 } else { | 202 } else { |
| 209 icon_as_image_->SetImage(*icon); | 203 icon_as_image_->SetImage(*icon); |
| 210 } | 204 } |
| 211 | 205 |
| 212 infobar_icon_->SetVisible(true); | 206 infobar_icon_->SetVisible(true); |
| 213 | 207 |
| 214 Layout(); | 208 Layout(); |
| 215 } | 209 } |
| 216 | 210 |
| 217 ExtensionInfoBarDelegate* ExtensionInfoBar::GetDelegate() { | 211 ExtensionInfoBarDelegate* ExtensionInfoBar::GetDelegate() { |
| 218 return delegate_ ? delegate_->AsExtensionInfoBarDelegate() : NULL; | 212 return delegate()->AsExtensionInfoBarDelegate(); |
| 219 } | 213 } |
| OLD | NEW |