diff options
author | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-14 12:40:10 +0000 |
---|---|---|
committer | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-14 12:40:10 +0000 |
commit | 0d60f0199b8be7f6597aae7796de8f1c4b2534bb (patch) | |
tree | c516b91b2141bed811365653898b40867dbd18aa /content/browser | |
parent | fab807ebcfcc992559b4197ba7264bed611f2eb0 (diff) | |
download | chromium_src-0d60f0199b8be7f6597aae7796de8f1c4b2534bb.zip chromium_src-0d60f0199b8be7f6597aae7796de8f1c4b2534bb.tar.gz chromium_src-0d60f0199b8be7f6597aae7796de8f1c4b2534bb.tar.bz2 |
Use TabContentsObserver to monitor web navigation events instead of notifications
BUG=none
TEST=WebNavigation* browser tests
Review URL: http://codereview.chromium.org/6822048
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81570 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser')
4 files changed, 72 insertions, 38 deletions
diff --git a/content/browser/tab_contents/provisional_load_details.h b/content/browser/tab_contents/provisional_load_details.h index 81f9ad2..0e8331f 100644 --- a/content/browser/tab_contents/provisional_load_details.h +++ b/content/browser/tab_contents/provisional_load_details.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// 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. @@ -14,8 +14,7 @@ // This class captures some of the information associated to the provisional // load of a frame. It is provided as Details with the -// NOTIFY_FRAME_PROVISIONAL_LOAD_START, NOTIFY_FRAME_PROVISIONAL_LOAD_COMMITTED -// and NOTIFY_FAIL_PROVISIONAL_LOAD_WITH_ERROR notifications +// NOTIFY_FAIL_PROVISIONAL_LOAD_WITH_ERROR notification // (see notification_types.h). // TODO(brettw) this mostly duplicates diff --git a/content/browser/tab_contents/tab_contents.cc b/content/browser/tab_contents/tab_contents.cc index 9bd9523..6ed1c38 100644 --- a/content/browser/tab_contents/tab_contents.cc +++ b/content/browser/tab_contents/tab_contents.cc @@ -1223,14 +1223,11 @@ void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id, render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(), GetRenderProcessHost()->id(), &validated_url); - ProvisionalLoadDetails details( - is_main_frame, - controller_.IsURLInPageNavigation(validated_url), - validated_url, std::string(), is_error_page, frame_id); - NotificationService::current()->Notify( - NotificationType::FRAME_PROVISIONAL_LOAD_START, - Source<NavigationController>(&controller_), - Details<ProvisionalLoadDetails>(&details)); + // Notify observers about the start of the provisional load. + FOR_EACH_OBSERVER(TabContentsObserver, observers_, + DidStartProvisionalLoadForFrame(frame_id, is_main_frame, + validated_url, is_error_page)); + if (is_main_frame) { // If we're displaying a network error page do not reset the content // settings delegate's cookies so the user has a chance to modify cookie @@ -1241,7 +1238,7 @@ void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id, // Notify observers about the provisional change in the main frame URL. FOR_EACH_OBSERVER(TabContentsObserver, observers_, - OnProvisionalChangeToMainFrameUrl(url)); + ProvisionalChangeToMainFrameUrl(url)); } } @@ -1261,7 +1258,7 @@ void TabContents::OnDidRedirectProvisionalLoad(int32 page_id, // Notify observers about the provisional change in the main frame URL. FOR_EACH_OBSERVER(TabContentsObserver, observers_, - OnProvisionalChangeToMainFrameUrl(target_url)); + ProvisionalChangeToMainFrameUrl(target_url)); } void TabContents::OnDidFailProvisionalLoadWithError( @@ -1327,6 +1324,10 @@ void TabContents::OnDidFailProvisionalLoadWithError( NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR, Source<NavigationController>(&controller_), Details<ProvisionalLoadDetails>(&details)); + + FOR_EACH_OBSERVER(TabContentsObserver, observers_, + DidFailProvisionalLoad(frame_id, is_main_frame, + validated_url, error_code)); } void TabContents::OnDidLoadResourceFromMemoryCache( @@ -1364,17 +1365,13 @@ void TabContents::OnDidRunInsecureContent( void TabContents::OnDocumentLoadedInFrame(int64 frame_id) { controller_.DocumentLoadedInFrame(); - NotificationService::current()->Notify( - NotificationType::FRAME_DOM_CONTENT_LOADED, - Source<NavigationController>(&controller_), - Details<int64>(&frame_id)); + FOR_EACH_OBSERVER(TabContentsObserver, observers_, + DocumentLoadedInFrame(frame_id)); } void TabContents::OnDidFinishLoad(int64 frame_id) { - NotificationService::current()->Notify( - NotificationType::FRAME_DID_FINISH_LOAD, - Source<NavigationController>(&controller_), - Details<int64>(&frame_id)); + FOR_EACH_OBSERVER(TabContentsObserver, observers_, + DidFinishLoad(frame_id)); } void TabContents::OnUpdateContentRestrictions(int restrictions) { @@ -1921,23 +1918,19 @@ void TabContents::DidNavigate(RenderViewHost* rvh, // tracking navigation events, we treat this event as a sub frame navigation // event. bool is_main_frame = did_navigate ? details.is_main_frame : false; - ProvisionalLoadDetails load_details( - is_main_frame, details.is_in_page, params.url, std::string(), - false, params.frame_id); - load_details.set_transition_type(params.transition); + PageTransition::Type transition_type = params.transition; // Whether or not a page transition was triggered by going backward or // forward in the history is only stored in the navigation controller's // entry list. if (did_navigate && (controller_.GetActiveEntry()->transition_type() & PageTransition::FORWARD_BACK)) { - load_details.set_transition_type( - params.transition | PageTransition::FORWARD_BACK); + transition_type = params.transition | PageTransition::FORWARD_BACK; } - NotificationService::current()->Notify( - NotificationType::FRAME_PROVISIONAL_LOAD_COMMITTED, - Source<NavigationController>(&controller_), - Details<ProvisionalLoadDetails>(&load_details)); + // Notify observers about the commit of the provisional load. + FOR_EACH_OBSERVER(TabContentsObserver, observers_, + DidCommitProvisionalLoadForFrame(params.frame_id, + is_main_frame, params.url, transition_type)); } // Update history. Note that this needs to happen after the entry is complete, diff --git a/content/browser/tab_contents/tab_contents_observer.cc b/content/browser/tab_contents/tab_contents_observer.cc index 3dfda19..d045792 100644 --- a/content/browser/tab_contents/tab_contents_observer.cc +++ b/content/browser/tab_contents/tab_contents_observer.cc @@ -38,7 +38,33 @@ void TabContentsObserver::DidNavigateAnyFramePostCommit( const ViewHostMsg_FrameNavigate_Params& params) { } -void TabContentsObserver::OnProvisionalChangeToMainFrameUrl(const GURL& url) { +void TabContentsObserver::DidStartProvisionalLoadForFrame( + int64 frame_id, + bool is_main_frame, + const GURL& validated_url, + bool is_error_page) { +} + +void TabContentsObserver::ProvisionalChangeToMainFrameUrl(const GURL& url) { +} + +void TabContentsObserver::DidCommitProvisionalLoadForFrame( + int64 frame_id, + bool is_main_frame, + const GURL& url, + PageTransition::Type transition_type) { +} + +void TabContentsObserver::DidFailProvisionalLoad(int64 frame_id, + bool is_main_frame, + const GURL& validated_url, + int error_code) { +} + +void TabContentsObserver::DocumentLoadedInFrame(int64 frame_id) { +} + +void TabContentsObserver::DidFinishLoad(int64 frame_id) { } void TabContentsObserver::DidStartLoading() { @@ -67,7 +93,7 @@ TabContentsObserver::~TabContentsObserver() { tab_contents_->RemoveObserver(this); } -void TabContentsObserver::OnTabContentsDestroyed(TabContents* tab) { +void TabContentsObserver::TabContentsDestroyed(TabContents* tab) { } bool TabContentsObserver::OnMessageReceived(const IPC::Message& message) { @@ -98,9 +124,9 @@ void TabContentsObserver::SetTabContents(TabContents* tab_contents) { void TabContentsObserver::TabContentsDestroyed() { // Do cleanup so that 'this' can safely be deleted from - // OnTabContentsDestroyed. + // TabContentsDestroyed. tab_contents_->RemoveObserver(this); TabContents* tab = tab_contents_; tab_contents_ = NULL; - OnTabContentsDestroyed(tab); + TabContentsDestroyed(tab); } diff --git a/content/browser/tab_contents/tab_contents_observer.h b/content/browser/tab_contents/tab_contents_observer.h index fab9165..87694d8 100644 --- a/content/browser/tab_contents/tab_contents_observer.h +++ b/content/browser/tab_contents/tab_contents_observer.h @@ -6,6 +6,7 @@ #define CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_OBSERVER_H_ #include "content/browser/tab_contents/navigation_controller.h" +#include "content/common/page_transition_types.h" #include "ipc/ipc_channel.h" struct ViewHostMsg_FrameNavigate_Params; @@ -43,7 +44,22 @@ class TabContentsObserver : public IPC::Channel::Listener, virtual void DidNavigateAnyFramePostCommit( const NavigationController::LoadCommittedDetails& details, const ViewHostMsg_FrameNavigate_Params& params); - virtual void OnProvisionalChangeToMainFrameUrl(const GURL& url); + virtual void DidStartProvisionalLoadForFrame(int64 frame_id, + bool is_main_frame, + const GURL& validated_url, + bool is_error_page); + virtual void ProvisionalChangeToMainFrameUrl(const GURL& url); + virtual void DidCommitProvisionalLoadForFrame( + int64 frame_id, + bool is_main_frame, + const GURL& url, + PageTransition::Type transition_type); + virtual void DidFailProvisionalLoad(int64 frame_id, + bool is_main_frame, + const GURL& validated_url, + int error_code); + virtual void DocumentLoadedInFrame(int64 frame_id); + virtual void DidFinishLoad(int64 frame_id); virtual void DidStartLoading(); virtual void DidStopLoading(); @@ -80,7 +96,7 @@ class TabContentsObserver : public IPC::Channel::Listener, // Invoked when the TabContents is being destroyed. Gives subclasses a chance // to cleanup. At the time this is invoked |tab_contents()| returns NULL. // It is safe to delete 'this' from here. - virtual void OnTabContentsDestroyed(TabContents* tab); + virtual void TabContentsDestroyed(TabContents* tab); // IPC::Channel::Listener implementation. virtual bool OnMessageReceived(const IPC::Message& message); @@ -99,7 +115,7 @@ class TabContentsObserver : public IPC::Channel::Listener, private: friend class TabContents; - // Invoked from TabContents. Invokes OnTabContentsDestroyed and NULL out + // Invoked from TabContents. Invokes TabContentsDestroyed and NULL out // |tab_contents_|. void TabContentsDestroyed(); |