Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: chrome/browser/ui/views/infobars/extension_infobar.cc

Issue 22694006: Infobar system refactor. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_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/extensions/image_loader.h" 10 #include "chrome/browser/extensions/image_loader.h"
(...skipping 11 matching lines...) Expand all
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
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_host()->view()->SetBounds( 107 GetDelegate()->extension_host()->view()->SetBounds(
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 gfx::Size(image_size, image_size), 156 gfx::Size(image_size, image_size),
159 base::Bind(&ExtensionInfoBar::OnImageLoaded, 157 base::Bind(&ExtensionInfoBar::OnImageLoaded,
160 weak_ptr_factory_.GetWeakPtr())); 158 weak_ptr_factory_.GetWeakPtr()));
161 } 159 }
162 160
163 int ExtensionInfoBar::ContentMinimumWidth() const { 161 int ExtensionInfoBar::ContentMinimumWidth() const {
164 return infobar_icon_->GetPreferredSize().width() + kIconHorizontalMargin; 162 return infobar_icon_->GetPreferredSize().width() + kIconHorizontalMargin;
165 163
166 } 164 }
167 165
168 void ExtensionInfoBar::OnDelegateDeleted() {
169 delegate_ = NULL;
170 }
171
172 void ExtensionInfoBar::OnMenuButtonClicked(views::View* source, 166 void ExtensionInfoBar::OnMenuButtonClicked(views::View* source,
173 const gfx::Point& point) { 167 const gfx::Point& point) {
174 if (!owner()) 168 if (!owner())
175 return; // We're closing; don't call anything, it might access the owner. 169 return; // We're closing; don't call anything, it might access the owner.
176 const extensions::Extension* extension = 170 const extensions::Extension* extension =
177 GetDelegate()->extension_host()->extension(); 171 GetDelegate()->extension_host()->extension();
178 DCHECK(icon_as_menu_); 172 DCHECK(icon_as_menu_);
179 173
180 scoped_refptr<ExtensionContextMenuModel> options_menu_contents = 174 scoped_refptr<ExtensionContextMenuModel> options_menu_contents =
181 new ExtensionContextMenuModel(extension, browser_); 175 new ExtensionContextMenuModel(extension, browser_);
(...skipping 25 matching lines...) Expand all
207 } else { 201 } else {
208 icon_as_image_->SetImage(*icon); 202 icon_as_image_->SetImage(*icon);
209 } 203 }
210 204
211 infobar_icon_->SetVisible(true); 205 infobar_icon_->SetVisible(true);
212 206
213 Layout(); 207 Layout();
214 } 208 }
215 209
216 ExtensionInfoBarDelegate* ExtensionInfoBar::GetDelegate() { 210 ExtensionInfoBarDelegate* ExtensionInfoBar::GetDelegate() {
217 return delegate_ ? delegate_->AsExtensionInfoBarDelegate() : NULL; 211 return delegate()->AsExtensionInfoBarDelegate();
218 } 212 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698