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