diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-22 22:57:48 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-22 22:57:48 +0000 |
commit | 1f3157f5c807cae9cddd92fb8b6e4908da9adefb (patch) | |
tree | 47aad89aebb339ac6f1723af13da3795200a62a6 /chrome/browser/gtk/tab_contents_container_gtk.cc | |
parent | 65f77adcaf52868c720a73ba3ca08dee7899d707 (diff) | |
download | chromium_src-1f3157f5c807cae9cddd92fb8b6e4908da9adefb.zip chromium_src-1f3157f5c807cae9cddd92fb8b6e4908da9adefb.tar.gz chromium_src-1f3157f5c807cae9cddd92fb8b6e4908da9adefb.tar.bz2 |
Use a NotificationRegistrar to listen for notifications.
BUG=2381
Review URL: http://codereview.chromium.org/113792
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16806 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk/tab_contents_container_gtk.cc')
-rw-r--r-- | chrome/browser/gtk/tab_contents_container_gtk.cc | 47 |
1 files changed, 12 insertions, 35 deletions
diff --git a/chrome/browser/gtk/tab_contents_container_gtk.cc b/chrome/browser/gtk/tab_contents_container_gtk.cc index 4305519..7b4e6b4 100644 --- a/chrome/browser/gtk/tab_contents_container_gtk.cc +++ b/chrome/browser/gtk/tab_contents_container_gtk.cc @@ -41,8 +41,6 @@ TabContentsContainerGtk::TabContentsContainerGtk(StatusBubbleGtk* status_bubble) } TabContentsContainerGtk::~TabContentsContainerGtk() { - if (tab_contents_) - RemoveObservers(); } void TabContentsContainerGtk::AddContainerToBox(GtkWidget* box) { @@ -57,7 +55,10 @@ void TabContentsContainerGtk::SetTabContents(TabContents* tab_contents) { tab_contents_->WasHidden(); - RemoveObservers(); + registrar_.Remove(this, NotificationType::RENDER_VIEW_HOST_CHANGED, + Source<NavigationController>(&tab_contents_->controller())); + registrar_.Remove(this, NotificationType::TAB_CONTENTS_DESTROYED, + Source<TabContents>(tab_contents_)); } tab_contents_ = tab_contents; @@ -65,7 +66,14 @@ void TabContentsContainerGtk::SetTabContents(TabContents* tab_contents) { // When detaching the last tab of the browser SetTabContents is invoked // with NULL. Don't attempt to do anything in that case. if (tab_contents_) { - AddObservers(); + // TabContents can change their RenderViewHost and hence the GtkWidget that + // is shown. I'm not entirely sure that we need to observe this event under + // GTK, but am putting a stub implementation and a comment saying that if + // we crash after that NOTIMPLEMENTED(), we'll need it. + registrar_.Add(this, NotificationType::RENDER_VIEW_HOST_CHANGED, + Source<NavigationController>(&tab_contents_->controller())); + registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED, + Source<TabContents>(tab_contents_)); gfx::NativeView widget = tab_contents_->GetNativeView(); if (widget) { @@ -111,37 +119,6 @@ void TabContentsContainerGtk::Observe(NotificationType type, } } -void TabContentsContainerGtk::AddObservers() { - DCHECK(tab_contents_); - - // TabContents can change their RenderViewHost and hence the GtkWidget that - // is shown. I'm not entirely sure that we need to observe this event under - // GTK, but am putting a stub implementation and a comment saying that if - // we crash after that NOTIMPLEMENTED(), we'll need it. - NotificationService::current()->AddObserver( - this, NotificationType::RENDER_VIEW_HOST_CHANGED, - Source<NavigationController>(&tab_contents_->controller())); - - NotificationService::current()->AddObserver( - this, - NotificationType::TAB_CONTENTS_DESTROYED, - Source<TabContents>(tab_contents_)); -} - -void TabContentsContainerGtk::RemoveObservers() { - DCHECK(tab_contents_); - - NotificationService::current()->RemoveObserver( - this, - NotificationType::RENDER_VIEW_HOST_CHANGED, - Source<NavigationController>(&tab_contents_->controller())); - - NotificationService::current()->RemoveObserver( - this, - NotificationType::TAB_CONTENTS_DESTROYED, - Source<TabContents>(tab_contents_)); -} - void TabContentsContainerGtk::RenderViewHostChanged(RenderViewHost* old_host, RenderViewHost* new_host) { // TODO(port): Remove this method and the logic where we subscribe to the |