diff options
14 files changed, 91 insertions, 59 deletions
diff --git a/chrome/browser/extensions/execute_code_in_tab_function.h b/chrome/browser/extensions/execute_code_in_tab_function.h index 9d06ce8..e4c1e1a 100644 --- a/chrome/browser/extensions/execute_code_in_tab_function.h +++ b/chrome/browser/extensions/execute_code_in_tab_function.h @@ -11,6 +11,7 @@ #include "chrome/browser/extensions/extension_function.h" #include "chrome/common/extensions/extension_resource.h" #include "content/browser/tab_contents/tab_contents_observer.h" +#include "content/browser/tab_contents/tab_contents_observer_registrar.h" // Implement API call tabs.executeScript and tabs.insertCSS. class ExecuteCodeInTabFunction : public AsyncExtensionFunction, @@ -37,7 +38,7 @@ class ExecuteCodeInTabFunction : public AsyncExtensionFunction, // true on success. If true is returned, this does an AddRef. bool Execute(const std::string& code_string); - TabContentsObserver::Registrar registrar_; + TabContentsObserverRegistrar registrar_; // Id of tab which executes code. int execute_tab_id_; diff --git a/chrome/browser/extensions/extension_tabs_module.h b/chrome/browser/extensions/extension_tabs_module.h index f110c6e..6e39ced 100644 --- a/chrome/browser/extensions/extension_tabs_module.h +++ b/chrome/browser/extensions/extension_tabs_module.h @@ -10,6 +10,7 @@ #include "chrome/browser/extensions/extension_function.h" #include "content/browser/tab_contents/tab_contents_observer.h" +#include "content/browser/tab_contents/tab_contents_observer_registrar.h" #include "content/common/notification_observer.h" #include "content/common/notification_registrar.h" @@ -122,7 +123,7 @@ class UpdateTabFunction : public AsyncExtensionFunction, virtual bool OnMessageReceived(const IPC::Message& message); void OnExecuteCodeFinished(int request_id, bool success, const std::string& error); - TabContentsObserver::Registrar registrar_; + TabContentsObserverRegistrar registrar_; DECLARE_EXTENSION_FUNCTION_NAME("tabs.update") }; class MoveTabFunction : public SyncExtensionFunction { diff --git a/chrome/browser/external_tab_container_win.h b/chrome/browser/external_tab_container_win.h index 55de8cb..d8ac9d3 100644 --- a/chrome/browser/external_tab_container_win.h +++ b/chrome/browser/external_tab_container_win.h @@ -20,6 +20,7 @@ #include "chrome/browser/ui/views/unhandled_keyboard_event_handler.h" #include "content/browser/tab_contents/tab_contents_delegate.h" #include "content/browser/tab_contents/tab_contents_observer.h" +#include "content/browser/tab_contents/tab_contents_observer_registrar.h" #include "content/common/navigation_types.h" #include "content/common/notification_observer.h" #include "content/common/notification_registrar.h" @@ -275,7 +276,7 @@ class ExternalTabContainer : public TabContentsDelegate, NotificationRegistrar registrar_; - TabContentsObserver::Registrar tab_contents_registrar_; + TabContentsObserverRegistrar tab_contents_registrar_; // A view to handle focus cycling TabContentsContainer* tab_contents_container_; diff --git a/chrome/browser/prerender/prerender_contents.h b/chrome/browser/prerender/prerender_contents.h index 62fd5f6..c636765 100644 --- a/chrome/browser/prerender/prerender_contents.h +++ b/chrome/browser/prerender/prerender_contents.h @@ -16,6 +16,7 @@ #include "chrome/browser/tab_contents/render_view_host_delegate_helper.h" #include "chrome/browser/ui/download/download_tab_helper_delegate.h" #include "content/browser/tab_contents/tab_contents_observer.h" +#include "content/browser/tab_contents/tab_contents_observer_registrar.h" #include "content/common/notification_registrar.h" #include "content/common/window_container_type.h" #include "webkit/glue/window_open_disposition.h" @@ -231,7 +232,7 @@ class PrerenderContents : public NotificationObserver, GURL url_; GURL icon_url_; NotificationRegistrar notification_registrar_; - TabContentsObserver::Registrar tab_contents_observer_registrar_; + TabContentsObserverRegistrar tab_contents_observer_registrar_; // A vector of URLs that this prerendered page matches against. // This array can contain more than element as a result of redirects, diff --git a/chrome/browser/tab_contents/thumbnail_generator.cc b/chrome/browser/tab_contents/thumbnail_generator.cc index b72e1e03..105e5142 100644 --- a/chrome/browser/tab_contents/thumbnail_generator.cc +++ b/chrome/browser/tab_contents/thumbnail_generator.cc @@ -491,9 +491,3 @@ void ThumbnailGenerator::StopNavigation() { // stop button. load_interrupted_ = true; } - -void ThumbnailGenerator::TabContentsDestroyed(TabContents* tab) { - // Tell the registrar the tab contents, that we started observing in - // StartThumbnailing(), is now destroyed. - tab_contents_observer_registrar_.Observe(NULL); -} diff --git a/chrome/browser/tab_contents/thumbnail_generator.h b/chrome/browser/tab_contents/thumbnail_generator.h index 755951a..a57ee66 100644 --- a/chrome/browser/tab_contents/thumbnail_generator.h +++ b/chrome/browser/tab_contents/thumbnail_generator.h @@ -16,6 +16,7 @@ #include "base/timer.h" #include "content/browser/renderer_host/backing_store.h" #include "content/browser/tab_contents/tab_contents_observer.h" +#include "content/browser/tab_contents/tab_contents_observer_registrar.h" #include "content/common/notification_observer.h" #include "content/common/notification_registrar.h" @@ -126,7 +127,6 @@ class ThumbnailGenerator : public NotificationObserver, // TabContentsObserver overrides. virtual void DidStartLoading(); virtual void StopNavigation(); - virtual void TabContentsDestroyed(TabContents* tab); private: virtual void WidgetDidReceivePaintAtSizeAck( @@ -154,7 +154,7 @@ class ThumbnailGenerator : public NotificationObserver, linked_ptr<AsyncRequestInfo> > ThumbnailCallbackMap; ThumbnailCallbackMap callback_map_; - TabContentsObserver::Registrar tab_contents_observer_registrar_; + TabContentsObserverRegistrar tab_contents_observer_registrar_; bool load_interrupted_; diff --git a/chrome/browser/ui/touch/frame/keyboard_container_view.cc b/chrome/browser/ui/touch/frame/keyboard_container_view.cc index 590ad96..13b7725 100644 --- a/chrome/browser/ui/touch/frame/keyboard_container_view.cc +++ b/chrome/browser/ui/touch/frame/keyboard_container_view.cc @@ -9,6 +9,7 @@ #include "chrome/browser/ui/views/dom_view.h" #include "chrome/common/url_constants.h" #include "content/browser/site_instance.h" +#include "content/browser/tab_contents/tab_contents.h" namespace { diff --git a/chrome/browser/ui/touch/frame/keyboard_container_view.h b/chrome/browser/ui/touch/frame/keyboard_container_view.h index 7fa2b82..c1c6ab8 100644 --- a/chrome/browser/ui/touch/frame/keyboard_container_view.h +++ b/chrome/browser/ui/touch/frame/keyboard_container_view.h @@ -8,8 +8,8 @@ #include "chrome/browser/extensions/extension_function_dispatcher.h" #include "chrome/common/extensions/extension_messages.h" -#include "content/browser/tab_contents/tab_contents.h" #include "content/browser/tab_contents/tab_contents_observer.h" +#include "content/browser/tab_contents/tab_contents_observer_registrar.h" #include "views/view.h" namespace IPC { @@ -55,7 +55,7 @@ class KeyboardContainerView : public views::View, DOMView* dom_view_; ExtensionFunctionDispatcher extension_function_dispatcher_; - TabContentsObserver::Registrar tab_contents_registrar_; + TabContentsObserverRegistrar tab_contents_registrar_; Browser* browser_; DISALLOW_COPY_AND_ASSIGN(KeyboardContainerView); diff --git a/content/browser/tab_contents/tab_contents.h b/content/browser/tab_contents/tab_contents.h index 4220e20..8d07b29 100644 --- a/content/browser/tab_contents/tab_contents.h +++ b/content/browser/tab_contents/tab_contents.h @@ -492,7 +492,7 @@ class TabContents : public PageNavigator, protected: friend class TabContentsObserver; - friend class TabContentsObserver::Registrar; + friend class TabContentsObserverRegistrar; // Add and remove observers for page navigation notifications. Adding or // removing multiple times has no effect. The order in which notifications diff --git a/content/browser/tab_contents/tab_contents_observer.cc b/content/browser/tab_contents/tab_contents_observer.cc index e3f7027..44a4d45 100644 --- a/content/browser/tab_contents/tab_contents_observer.cc +++ b/content/browser/tab_contents/tab_contents_observer.cc @@ -8,24 +8,6 @@ #include "content/browser/tab_contents/navigation_details.h" #include "content/browser/tab_contents/tab_contents.h" -TabContentsObserver::Registrar::Registrar(TabContentsObserver* observer) - : observer_(observer), tab_(NULL) { -} - -TabContentsObserver::Registrar::~Registrar() { - if (tab_) - tab_->RemoveObserver(observer_); -} - -void TabContentsObserver::Registrar::Observe(TabContents* tab) { - observer_->SetTabContents(tab); - if (tab_) - tab_->RemoveObserver(observer_); - tab_ = tab; - if (tab_) - tab_->AddObserver(observer_); -} - void TabContentsObserver::RenderViewCreated(RenderViewHost* render_view_host) { } diff --git a/content/browser/tab_contents/tab_contents_observer.h b/content/browser/tab_contents/tab_contents_observer.h index 3456895..f085062 100644 --- a/content/browser/tab_contents/tab_contents_observer.h +++ b/content/browser/tab_contents/tab_contents_observer.h @@ -11,6 +11,7 @@ #include "webkit/glue/window_open_disposition.h" class RenderViewHost; +class TabContentsObserverRegistrar; struct ViewHostMsg_FrameNavigate_Params; // An observer API implemented by classes which are interested in various page @@ -18,28 +19,6 @@ struct ViewHostMsg_FrameNavigate_Params; class TabContentsObserver : public IPC::Channel::Listener, public IPC::Message::Sender { public: - // Use this as a member variable in a class that uses the empty constructor - // version of this interface. On destruction of TabContents being observed, - // the registrar must either be destroyed or explicitly set to observe - // another TabContents. - class Registrar { - public: - explicit Registrar(TabContentsObserver* observer); - ~Registrar(); - - // Call this to start observing a tab. Passing in NULL resets it. - // This can only be used to watch one tab at a time. If you call this and - // you're already observing another tab, the old tab won't be observed - // afterwards. - void Observe(TabContents* tab); - - private: - TabContentsObserver* observer_; - TabContents* tab_; - - DISALLOW_COPY_AND_ASSIGN(Registrar); - }; - virtual void RenderViewCreated(RenderViewHost* render_view_host); virtual void NavigateToPendingEntry( const GURL& url, @@ -105,8 +84,8 @@ class TabContentsObserver : public IPC::Channel::Listener, explicit TabContentsObserver(TabContents* tab_contents); // Use this constructor when the object wants to observe a TabContents for - // part of its lifetime. It can use a TabContentsRegistrar member variable - // to start and stop observing. + // part of its lifetime. It can use a TabContentsObserverRegistrar member + // variable to start and stop observing. TabContentsObserver(); virtual ~TabContentsObserver(); @@ -125,8 +104,7 @@ class TabContentsObserver : public IPC::Channel::Listener, TabContents* tab_contents() const { return tab_contents_; } int routing_id() const; - protected: - friend class Registrar; + friend class TabContentsObserverRegistrar; // Called from TabContents in response to having |this| added as an observer. void SetTabContents(TabContents* tab_contents); diff --git a/content/browser/tab_contents/tab_contents_observer_registrar.cc b/content/browser/tab_contents/tab_contents_observer_registrar.cc new file mode 100644 index 0000000..352525f --- /dev/null +++ b/content/browser/tab_contents/tab_contents_observer_registrar.cc @@ -0,0 +1,37 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/browser/tab_contents/tab_contents_observer_registrar.h" + +#include "content/browser/tab_contents/tab_contents.h" + +TabContentsObserverRegistrar::TabContentsObserverRegistrar( + TabContentsObserver* observer) + : observer_(observer), tab_(NULL) { +} + +TabContentsObserverRegistrar::~TabContentsObserverRegistrar() { + if (tab_) { + tab_->RemoveObserver(observer_); + tab_->RemoveObserver(this); + } +} + +void TabContentsObserverRegistrar::Observe(TabContents* tab) { + observer_->SetTabContents(tab); + SetTabContents(tab); + if (tab_) { + tab_->RemoveObserver(observer_); + tab_->RemoveObserver(this); + } + tab_ = tab; + if (tab_) { + tab_->AddObserver(observer_); + tab_->AddObserver(this); + } +} + +void TabContentsObserverRegistrar::TabContentsDestroyed(TabContents* tab) { + Observe(NULL); +} diff --git a/content/browser/tab_contents/tab_contents_observer_registrar.h b/content/browser/tab_contents/tab_contents_observer_registrar.h new file mode 100644 index 0000000..32be40d --- /dev/null +++ b/content/browser/tab_contents/tab_contents_observer_registrar.h @@ -0,0 +1,34 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_OBSERVER_REGISTRAR_H_ +#define CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_OBSERVER_REGISTRAR_H_ + +#include "content/browser/tab_contents/tab_contents_observer.h" + +// Use this as a member variable in a class that uses the empty constructor +// version of this interface. On destruction of TabContents being observed, +// the registrar must either be destroyed or explicitly set to observe +// another TabContents. +class TabContentsObserverRegistrar : public TabContentsObserver { + public: + explicit TabContentsObserverRegistrar(TabContentsObserver* observer); + ~TabContentsObserverRegistrar(); + + // Call this to start observing a tab. Passing in NULL resets it. + // This can only be used to watch one tab at a time. If you call this and + // you're already observing another tab, the old tab won't be observed + // afterwards. + void Observe(TabContents* tab); + + private: + virtual void TabContentsDestroyed(TabContents* tab); + + TabContentsObserver* observer_; + TabContents* tab_; + + DISALLOW_COPY_AND_ASSIGN(TabContentsObserverRegistrar); +}; + +#endif // CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_OBSERVER_REGISTRAR_H_ diff --git a/content/content_browser.gypi b/content/content_browser.gypi index 6ec29f3..fd59ec2 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -328,6 +328,8 @@ 'browser/tab_contents/tab_contents_delegate.h', 'browser/tab_contents/tab_contents_observer.cc', 'browser/tab_contents/tab_contents_observer.h', + 'browser/tab_contents/tab_contents_observer_registrar.cc', + 'browser/tab_contents/tab_contents_observer_registrar.h', 'browser/tab_contents/tab_contents_view.cc', 'browser/tab_contents/tab_contents_view.h', 'browser/tab_contents/title_updated_details.h', |