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

Unified Diff: chrome/browser/ui/views/infobars/extension_infobar.cc

Issue 4767001: Make TabContents own its infobar delegates.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/infobars/extension_infobar.cc
===================================================================
--- chrome/browser/ui/views/infobars/extension_infobar.cc (revision 65711)
+++ chrome/browser/ui/views/infobars/extension_infobar.cc (working copy)
@@ -32,61 +32,51 @@
ExtensionInfoBar::ExtensionInfoBar(ExtensionInfoBarDelegate* delegate)
: InfoBar(delegate),
- delegate_(delegate),
ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) {
- delegate_->set_observer(this);
-
- ExtensionHost* extension_host = delegate_->extension_host();
-
// We set the target height for the InfoBar to be the height of the
// ExtensionView it contains (plus 1 because the view should not overlap the
// separator line at the bottom). When the InfoBar is first created, however,
// this value is 0 but becomes positive after the InfoBar has been shown. See
// function: OnExtensionPreferredSizeChanged.
- gfx::Size sz = extension_host->view()->GetPreferredSize();
- if (sz.height() > 0)
- sz.set_height(sz.height() + 1);
- set_target_height(sz.height());
+ ExtensionView* extension_view = delegate->extension_host()->view();
+ gfx::Size sz = extension_view->GetPreferredSize();
+ set_target_height((sz.height() > 0) ? (sz.height() + 1) : sz.height());
// Setup the extension icon and its associated drop down menu.
SetupIconAndMenu();
// Get notified of resize events for the ExtensionView.
- extension_host->view()->SetContainer(this);
+ extension_view->SetContainer(this);
// We show the ExtensionView, but we don't want it deleted when we get
// destroyed, which happens on tab switching (for example).
- extension_host->view()->set_parent_owned(false);
- AddChildView(extension_host->view());
+ extension_view->set_parent_owned(false);
+ AddChildView(extension_view);
}
ExtensionInfoBar::~ExtensionInfoBar() {
- if (delegate_) {
- delegate_->extension_host()->view()->SetContainer(NULL);
- delegate_->set_observer(NULL);
+ if (delegate()) {
+ delegate()->AsExtensionInfoBarDelegate()->extension_host()->view()->
+ SetContainer(NULL);
}
}
void ExtensionInfoBar::OnExtensionPreferredSizeChanged(ExtensionView* view) {
- DCHECK(view == delegate_->extension_host()->view());
+ DCHECK(delegate());
Finnur 2010/11/15 23:08:41 nit: This is redundant and just adds cruft to the
+ ExtensionView* extension_view =
+ delegate()->AsExtensionInfoBarDelegate()->extension_host()->view();
+ DCHECK_EQ(extension_view, view);
- // When the infobar is closed, it animates to 0 vertical height. We'll
- // continue to get size changed notifications from the ExtensionView, but we
- // need to ignore them otherwise we'll try to re-animate open (and leak the
- // infobar view).
- if (delegate_->closing())
- return;
Finnur 2010/11/15 23:08:41 So, given the new model, there is no chance of it
+ extension_view->SetVisible(true);
- delegate_->extension_host()->view()->SetVisible(true);
+ if (height() == 0)
+ animation()->Reset(0.0);
- gfx::Size sz = view->GetPreferredSize();
// Clamp height to a min and a max size of between 1 and 2 InfoBars.
+ gfx::Size sz = view->GetPreferredSize();
int default_height = static_cast<int>(InfoBar::kDefaultTargetHeight);
- sz.set_height(std::max(default_height, sz.height()));
- sz.set_height(std::min(2 * default_height, sz.height()));
+ set_target_height(
+ std::min(2 * default_height, std::max(default_height, sz.height())));
- if (height() == 0)
- animation()->Reset(0.0);
- set_target_height(sz.height());
animation()->Show();
}
@@ -97,21 +87,21 @@
// Layout the extension icon + drop down menu.
int x = 0;
gfx::Size sz = menu_->GetPreferredSize();
- menu_->SetBounds(x,
- (height() - sz.height()) / 2,
- sz.width(), sz.height());
+ menu_->SetBounds(x, (height() - sz.height()) / 2, sz.width(), sz.height());
x += sz.width() + kMenuHorizontalMargin;
- // Layout the ExtensionView, showing the HTML InfoBar.
- ExtensionView* view = delegate_->extension_host()->view();
- view->SetBounds(x, 0, width() - x - kFarRightMargin - 1, height() - 1);
+ // Layout the ExtensionView, showing the HTML InfoBar. The delegate owns the
+ // view, so if the delegate is destroyed, the view will have been destroyed as
+ // well (which also removes it as a child view).
+ if (delegate()) {
+ delegate()->AsExtensionInfoBarDelegate()->extension_host()->view()->
+ SetBounds(x, 0, width() - x - kFarRightMargin - 1, height() - 1);
+ }
}
-void ExtensionInfoBar::OnImageLoaded(
- SkBitmap* image, ExtensionResource resource, int index) {
- if (!delegate_)
- return; // The delegate can go away while we asynchronously load images.
Finnur 2010/11/15 23:08:41 This should be OK I guess given that it is guarant
-
+void ExtensionInfoBar::OnImageLoaded(SkBitmap* image,
+ ExtensionResource resource,
+ int index) {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
// We fall back on the default extension icon on failure.
@@ -141,18 +131,15 @@
Layout();
}
-void ExtensionInfoBar::OnDelegateDeleted() {
- delegate_->extension_host()->view()->SetContainer(NULL);
- delegate_ = NULL;
-}
-
void ExtensionInfoBar::RunMenu(View* source, const gfx::Point& pt) {
+ DCHECK(delegate());
if (!options_menu_contents_.get()) {
Browser* browser = BrowserView::GetBrowserViewForNativeWindow(
platform_util::GetTopLevel(source->GetWidget()->GetNativeView()))->
browser();
options_menu_contents_ = new ExtensionContextMenuModel(
- delegate_->extension_host()->extension(), browser, NULL);
+ delegate()->AsExtensionInfoBarDelegate()->extension_host()->extension(),
+ browser, NULL);
}
options_menu_menu_.reset(new views::Menu2(options_menu_contents_.get()));
@@ -160,11 +147,13 @@
}
void ExtensionInfoBar::SetupIconAndMenu() {
+ DCHECK(delegate());
Finnur 2010/11/15 23:08:41 Same here, redundant.
menu_ = new views::MenuButton(NULL, std::wstring(), this, false);
menu_->SetVisible(false);
AddChildView(menu_);
- const Extension* extension = delegate_->extension_host()->extension();
+ const Extension* extension =
+ delegate()->AsExtensionInfoBarDelegate()->extension_host()->extension();
ExtensionResource icon_resource = extension->GetIconResource(
Extension::EXTENSION_ICON_BITTY, ExtensionIconSet::MATCH_EXACTLY);
if (!icon_resource.relative_path().empty()) {
« no previous file with comments | « chrome/browser/ui/views/infobars/extension_infobar.h ('k') | chrome/browser/ui/views/infobars/infobar_container.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698