diff options
4 files changed, 29 insertions, 38 deletions
diff --git a/chrome/browser/views/tab_contents_container_view.cc b/chrome/browser/views/tab_contents_container_view.cc index 04c9354..c0089a7 100644 --- a/chrome/browser/views/tab_contents_container_view.cc +++ b/chrome/browser/views/tab_contents_container_view.cc @@ -174,33 +174,20 @@ void TabContentsContainerView::Observe(NotificationType type, } void TabContentsContainerView::AddObservers() { - DCHECK(tab_contents_); - if (tab_contents_->AsWebContents()) { - // WebContents can change their RenderViewHost and hence the HWND that is - // shown and getting focused. We need to keep track of that so we install - // the focus subclass on the shown HWND so we intercept focus change events. - 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_)); + // WebContents can change their RenderViewHost and hence the HWND that is + // shown and getting focused. We need to keep track of that so we install + // the focus subclass on the shown HWND so we intercept focus change events. + registrar_.Add(this, + NotificationType::RENDER_VIEW_HOST_CHANGED, + Source<NavigationController>(&tab_contents_->controller())); + + registrar_.Add(this, + NotificationType::TAB_CONTENTS_DESTROYED, + Source<TabContents>(tab_contents_)); } void TabContentsContainerView::RemoveObservers() { - DCHECK(tab_contents_); - if (tab_contents_->AsWebContents()) { - 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_)); + registrar_.RemoveAll(); } void TabContentsContainerView::RenderViewHostChanged(RenderViewHost* old_host, diff --git a/chrome/browser/views/tab_contents_container_view.h b/chrome/browser/views/tab_contents_container_view.h index 7a7ec9d..8bda8bb 100644 --- a/chrome/browser/views/tab_contents_container_view.h +++ b/chrome/browser/views/tab_contents_container_view.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_VIEWS_TAB_CONTENTS_CONTAINER_VIEW_H__ -#define CHROME_BROWSER_VIEWS_TAB_CONTENTS_CONTAINER_VIEW_H__ +#ifndef CHROME_BROWSER_VIEWS_TAB_CONTENTS_CONTAINER_VIEW_H_ +#define CHROME_BROWSER_VIEWS_TAB_CONTENTS_CONTAINER_VIEW_H_ namespace ChromeView { class KeyEvent; @@ -12,7 +12,7 @@ class View; class RenderViewHost; class TabContents; -#include "chrome/common/notification_observer.h" +#include "chrome/common/notification_registrar.h" #include "chrome/views/controls/hwnd_view.h" #include "chrome/views/focus/focus_manager.h" @@ -71,10 +71,13 @@ class TabContentsContainerView : public views::HWNDView, // get notified. void TabContentsDestroyed(TabContents* contents); + // Handles registering for our notifications. + NotificationRegistrar registrar_; + // The current TabContents shown. TabContents* tab_contents_; - DISALLOW_EVIL_CONSTRUCTORS(TabContentsContainerView); + DISALLOW_COPY_AND_ASSIGN(TabContentsContainerView); }; -#endif // #ifndef CHROME_BROWSER_VIEWS_TAB_CONTENTS_CONTAINER_VIEW_H__ +#endif // CHROME_BROWSER_VIEWS_TAB_CONTENTS_CONTAINER_VIEW_H_ diff --git a/chrome/browser/views/tabs/dragged_tab_controller.cc b/chrome/browser/views/tabs/dragged_tab_controller.cc index 95e2022..33a01c4 100644 --- a/chrome/browser/views/tabs/dragged_tab_controller.cc +++ b/chrome/browser/views/tabs/dragged_tab_controller.cc @@ -474,20 +474,18 @@ void DraggedTabController::UpdateDockInfo(const gfx::Point& screen_point) { void DraggedTabController::SetDraggedContents(TabContents* new_contents) { if (dragged_contents_) { - NotificationService::current()->RemoveObserver( - this, - NotificationType::TAB_CONTENTS_DESTROYED, - Source<TabContents>(dragged_contents_)); + registrar_.Remove(this, + NotificationType::TAB_CONTENTS_DESTROYED, + Source<TabContents>(dragged_contents_)); if (original_delegate_) dragged_contents_->set_delegate(original_delegate_); } original_delegate_ = NULL; dragged_contents_ = new_contents; if (dragged_contents_) { - NotificationService::current()->AddObserver( - this, - NotificationType::TAB_CONTENTS_DESTROYED, - Source<TabContents>(dragged_contents_)); + registrar_.Add(this, + NotificationType::TAB_CONTENTS_DESTROYED, + Source<TabContents>(dragged_contents_)); // We need to be the delegate so we receive messages about stuff, // otherwise our dragged_contents() may be replaced and subsequently diff --git a/chrome/browser/views/tabs/dragged_tab_controller.h b/chrome/browser/views/tabs/dragged_tab_controller.h index 00b715b..1989031 100644 --- a/chrome/browser/views/tabs/dragged_tab_controller.h +++ b/chrome/browser/views/tabs/dragged_tab_controller.h @@ -12,7 +12,7 @@ #include "chrome/browser/tab_contents/tab_contents_delegate.h" #include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/browser/views/tabs/tab_renderer.h" -#include "chrome/common/notification_observer.h" +#include "chrome/common/notification_registrar.h" namespace views { class MouseEvent; @@ -223,6 +223,9 @@ class DraggedTabController : public TabContentsDelegate, void BringWindowUnderMouseToFront(); + // Handles registering for notifications. + NotificationRegistrar registrar_; + // The TabContents being dragged. TabContents* dragged_contents_; |