summaryrefslogtreecommitdiffstats
path: root/chrome/browser/tab_contents
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-17 03:09:42 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-17 03:09:42 +0000
commitb5a1d11cc70ab12c69e579d132204863a780eb75 (patch)
treea9300148dd2434b645ad7fe1716cce2f9e42e064 /chrome/browser/tab_contents
parentcd124097edce07ef5e0a7f80105e81c7982b81a1 (diff)
downloadchromium_src-b5a1d11cc70ab12c69e579d132204863a780eb75.zip
chromium_src-b5a1d11cc70ab12c69e579d132204863a780eb75.tar.gz
chromium_src-b5a1d11cc70ab12c69e579d132204863a780eb75.tar.bz2
Make TabContentsObserver handle registration automatically, as well as exposing getters for TC, routing_id, and sending messages.
Review URL: http://codereview.chromium.org/6537004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75226 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents')
-rw-r--r--chrome/browser/tab_contents/tab_contents.cc64
-rw-r--r--chrome/browser/tab_contents/tab_contents.h10
-rw-r--r--chrome/browser/tab_contents/tab_contents_observer.cc23
-rw-r--r--chrome/browser/tab_contents/tab_contents_observer.h27
4 files changed, 73 insertions, 51 deletions
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index 2fd6ea1..223668c 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -254,48 +254,29 @@ TabContents::TabContents(Profile* profile,
ALLOW_THIS_IN_INITIALIZER_LIST(view_(
TabContentsView::Create(this))),
ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
- property_bag_(),
- registrar_(),
- ALLOW_THIS_IN_INITIALIZER_LIST(printing_(
- new printing::PrintViewManager(*this))),
- ALLOW_THIS_IN_INITIALIZER_LIST(print_preview_(
- new printing::PrintPreviewMessageHandler(this))),
- save_package_(),
- autocomplete_history_manager_(),
- autofill_manager_(),
- prerender_plt_recorder_(),
bookmark_drag_(NULL),
- ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)),
is_loading_(false),
crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
crashed_error_code_(0),
waiting_for_response_(false),
max_page_id_(-1),
- current_load_start_(),
load_state_(net::LOAD_STATE_IDLE),
- load_state_host_(),
upload_size_(0),
upload_position_(0),
received_page_title_(false),
- contents_mime_type_(),
- encoding_(),
blocked_contents_(NULL),
all_contents_blocked_(false),
dont_notify_render_view_(false),
displayed_insecure_content_(false),
- infobar_delegates_(),
extension_app_(NULL),
capturing_contents_(false),
is_being_destroyed_(false),
notify_disconnection_(false),
- history_requests_(),
#if defined(OS_WIN)
message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
#endif
- last_javascript_message_dismissal_(),
suppress_javascript_messages_(false),
is_showing_before_unload_dialog_(false),
- renderer_preferences_(),
opener_web_ui_type_(WebUIFactory::kNoWebUI),
language_state_(&controller_),
closed_by_user_gesture_(false),
@@ -354,20 +335,10 @@ TabContents::TabContents(Profile* profile,
if (OmniboxSearchHint::IsEnabled(profile))
omnibox_search_hint_.reset(new OmniboxSearchHint(this));
- autofill_manager_.reset(new AutoFillManager(this));
- AddObserver(autofill_manager_.get());
- autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this));
- AddObserver(autocomplete_history_manager_.get());
- prerender_plt_recorder_.reset(new prerender::PrerenderPLTRecorder(this));
- AddObserver(prerender_plt_recorder_.get());
- AddObserver(&fav_icon_helper_);
- AddObserver(printing_.get());
- desktop_notification_handler_.reset(
- new DesktopNotificationHandler(this, GetRenderProcessHost()));
- AddObserver(desktop_notification_handler_.get());
- plugin_observer_.reset(new PluginObserver(this));
- AddObserver(plugin_observer_.get());
- AddObserver(print_preview_.get());
+ // Can only add observers after render_manager_.Init() is called, since that's
+ // what sets up the render_view_host which TabContentObserver's constructor
+ // uses to get the routing_id.
+ AddObservers();
}
TabContents::~TabContents() {
@@ -427,6 +398,20 @@ TabContents::~TabContents() {
UMA_HISTOGRAM_TIMES("Tab.Close",
base::TimeTicks::Now() - tab_close_start_time_);
}
+
+ FOR_EACH_OBSERVER(TabContentsObserver, observers_, set_tab_contents(NULL));
+}
+
+void TabContents::AddObservers() {
+ printing_.reset(new printing::PrintViewManager(this));
+ print_preview_.reset(new printing::PrintPreviewMessageHandler(this));
+ fav_icon_helper_.reset(new FavIconHelper(this));
+ autofill_manager_.reset(new AutoFillManager(this));
+ autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this));
+ prerender_plt_recorder_.reset(new prerender::PrerenderPLTRecorder(this));
+ desktop_notification_handler_.reset(
+ new DesktopNotificationHandlerForTC(this, GetRenderProcessHost()));
+ plugin_observer_.reset(new PluginObserver(this));
}
// static
@@ -1276,7 +1261,7 @@ void TabContents::OnSavePage() {
// Create the save package and possibly prompt the user for the name to save
// the page as. The user prompt is an asynchronous operation that runs on
// another thread.
- SetSavePackage(new SavePackage(this));
+ save_package_ = new SavePackage(this);
save_package_->GetSaveInfo();
}
@@ -1288,17 +1273,10 @@ bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
// Stop the page from navigating.
Stop();
- SetSavePackage(new SavePackage(this, save_type, main_file, dir_path));
+ save_package_ = new SavePackage(this, save_type, main_file, dir_path);
return save_package_->Init();
}
-void TabContents::SetSavePackage(SavePackage* save_package) {
- if (save_package_.get())
- RemoveObserver(save_package_.get());
- save_package_ = save_package;
- AddObserver(save_package);
-}
-
void TabContents::EmailPageLocation() {
std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false);
std::string page_url = EscapeQueryParamValue(GetURL().spec(), false);
@@ -1797,7 +1775,7 @@ void TabContents::DidNavigateMainFramePostCommit(
received_page_title_ = false;
// Get the favicon, either from history or request it from the net.
- fav_icon_helper_.FetchFavIcon(details.entry->url());
+ fav_icon_helper_->FetchFavIcon(details.entry->url());
// Clear all page actions, blocked content notifications and browser actions
// for this tab, unless this is an in-page navigation.
diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h
index 6da4023..3e6613d 100644
--- a/chrome/browser/tab_contents/tab_contents.h
+++ b/chrome/browser/tab_contents/tab_contents.h
@@ -181,7 +181,7 @@ class TabContents : public PageNavigator,
// Returns the FavIconHelper of this TabContents.
FavIconHelper& fav_icon_helper() {
- return fav_icon_helper_;
+ return *fav_icon_helper_.get();
}
// App extensions ------------------------------------------------------------
@@ -557,9 +557,6 @@ class TabContents : public PageNavigator,
bool SavePage(const FilePath& main_file, const FilePath& dir_path,
SavePackage::SavePackageType save_type);
- // Sets save_package_, taking care to register and unregister the observers.
- void SetSavePackage(SavePackage* save_package);
-
// Tells the user's email client to open a compose window containing the
// current page's URL.
void EmailPageLocation();
@@ -752,6 +749,9 @@ class TabContents : public PageNavigator,
// Used to access RVH Delegates.
friend class prerender::PrerenderManager;
+ // Add all the TabContentObservers.
+ void AddObservers();
+
// Message handlers.
void OnDidStartProvisionalLoadForFrame(int64 frame_id,
bool main_frame,
@@ -1079,7 +1079,7 @@ class TabContents : public PageNavigator,
BookmarkDrag* bookmark_drag_;
// Handles downloading favicons.
- FavIconHelper fav_icon_helper_;
+ scoped_ptr<FavIconHelper> fav_icon_helper_;
// Cached web app info data.
WebApplicationInfo web_app_info_;
diff --git a/chrome/browser/tab_contents/tab_contents_observer.cc b/chrome/browser/tab_contents/tab_contents_observer.cc
index 5ad1e1d..738539a 100644
--- a/chrome/browser/tab_contents/tab_contents_observer.cc
+++ b/chrome/browser/tab_contents/tab_contents_observer.cc
@@ -4,6 +4,29 @@
#include "chrome/browser/tab_contents/tab_contents_observer.h"
+#include "chrome/browser/renderer_host/render_view_host.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
+
+TabContentsObserver::TabContentsObserver(TabContents* tab_contents)
+ : tab_contents_(tab_contents),
+ routing_id_(tab_contents->render_view_host()->routing_id()) {
+ tab_contents_->AddObserver(this);
+}
+
+TabContentsObserver::~TabContentsObserver() {
+ if (tab_contents_)
+ tab_contents_->RemoveObserver(this);
+}
+
bool TabContentsObserver::OnMessageReceived(const IPC::Message& message) {
return false;
}
+
+bool TabContentsObserver::Send(IPC::Message* message) {
+ if (!tab_contents_->render_view_host()) {
+ delete message;
+ return false;
+ }
+
+ return tab_contents_->render_view_host()->Send(message);
+}
diff --git a/chrome/browser/tab_contents/tab_contents_observer.h b/chrome/browser/tab_contents/tab_contents_observer.h
index 7e56ed97..55a609c 100644
--- a/chrome/browser/tab_contents/tab_contents_observer.h
+++ b/chrome/browser/tab_contents/tab_contents_observer.h
@@ -26,9 +26,6 @@ class TabContentsObserver : public IPC::Channel::Listener {
virtual void DidStartLoading() { }
virtual void DidStopLoading() { }
- // IPC::Channel::Listener implementation.
- virtual bool OnMessageReceived(const IPC::Message& message);
-
#if 0
// For unifying with delegate...
@@ -43,6 +40,30 @@ class TabContentsObserver : public IPC::Channel::Listener {
virtual void NavigationStateChanged(const TabContents* source,
unsigned changed_flags) { }
#endif
+
+ protected:
+ TabContentsObserver(TabContents* tab_contents);
+ virtual ~TabContentsObserver();
+
+ // IPC::Channel::Listener implementation.
+ virtual bool OnMessageReceived(const IPC::Message& message);
+
+ // IPC::Message::Sender implementation.
+ virtual bool Send(IPC::Message* message);
+
+ TabContents* tab_contents() { return tab_contents_; }
+ int routing_id() { return routing_id_; }
+
+ private:
+ friend class TabContents;
+
+ void set_tab_contents(TabContents* tc) { tab_contents_ = tc; }
+
+ TabContents* tab_contents_;
+ // The routing ID of the associated TabContents.
+ int routing_id_;
+
+ DISALLOW_COPY_AND_ASSIGN(TabContentsObserver);
};
#endif // CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_OBSERVER_H_