summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-20 09:32:47 +0000
committerjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-20 09:32:47 +0000
commit7bb761897cda2caf6d4d8b334709a3761f2a07ab (patch)
tree7f50a6f243ae7cb4dfe886741620379e6e398604 /chrome
parent526b34fa1a9a9b32041f31d23f927a0a04c06e7a (diff)
downloadchromium_src-7bb761897cda2caf6d4d8b334709a3761f2a07ab.zip
chromium_src-7bb761897cda2caf6d4d8b334709a3761f2a07ab.tar.gz
chromium_src-7bb761897cda2caf6d4d8b334709a3761f2a07ab.tar.bz2
Pass the RVH to RVHD::OnMessageReceived and make WCImpl forward it for load signals to its observers.
Also add a WebContentsObserver::AboutToNavigateRenderView that notifies the observer when a WC is about to navigate a RenderView Suppress navigation events in the webNavigation API for all but the currently committed and the currently navigating render view. BUG=116643 TEST=none Review URL: https://chromiumcodereview.appspot.com/10807035 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@147632 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/extensions/api/web_navigation/web_navigation_api.cc54
-rw-r--r--chrome/browser/extensions/api/web_navigation/web_navigation_api.h29
-rw-r--r--chrome/browser/page_cycler/page_cycler.cc3
-rw-r--r--chrome/browser/page_cycler/page_cycler.h8
-rw-r--r--chrome/browser/page_cycler/page_cycler_unittest.cc24
-rw-r--r--chrome/browser/prerender/prerender_contents.cc3
-rw-r--r--chrome/browser/prerender/prerender_contents.h8
7 files changed, 99 insertions, 30 deletions
diff --git a/chrome/browser/extensions/api/web_navigation/web_navigation_api.cc b/chrome/browser/extensions/api/web_navigation/web_navigation_api.cc
index d26b7f9..7dada01 100644
--- a/chrome/browser/extensions/api/web_navigation/web_navigation_api.cc
+++ b/chrome/browser/extensions/api/web_navigation/web_navigation_api.cc
@@ -236,7 +236,9 @@ void WebNavigationEventRouter::TabDestroyed(content::WebContents* tab) {
WebNavigationTabObserver::WebNavigationTabObserver(
content::WebContents* web_contents)
- : WebContentsObserver(web_contents) {
+ : WebContentsObserver(web_contents),
+ render_view_host_(NULL),
+ pending_render_view_host_(NULL) {
g_tab_observer.Get().insert(TabObserverMap::value_type(web_contents, this));
registrar_.Add(this,
content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
@@ -277,12 +279,31 @@ void WebNavigationTabObserver::Observe(
}
}
+void WebNavigationTabObserver::AboutToNavigateRenderView(
+ content::RenderViewHost* render_view_host) {
+ if (!render_view_host_) {
+ render_view_host_ = render_view_host;
+ } else if (render_view_host != render_view_host_) {
+ // TODO(jochen): If pending_render_view_host_ is non-NULL, send error events
+ // for all ongoing navigations in that RVH.
+ pending_render_view_host_ = render_view_host;
+ }
+}
+
void WebNavigationTabObserver::DidStartProvisionalLoadForFrame(
int64 frame_id,
bool is_main_frame,
const GURL& validated_url,
bool is_error_page,
content::RenderViewHost* render_view_host) {
+ if (!render_view_host_)
+ render_view_host_ = render_view_host;
+ if (render_view_host != render_view_host_ &&
+ render_view_host != pending_render_view_host_)
+ return;
+
+ // TODO(jochen): Remove this hack once we properly include the process ID in
+ // the events.
// Ignore navigations of sub frames, if the main frame isn't committed yet.
// This might happen if a sub frame triggers a navigation for both the main
// frame and itself. Since the sub frame is about to be deleted, and there's
@@ -300,6 +321,7 @@ void WebNavigationTabObserver::DidStartProvisionalLoadForFrame(
is_error_page);
if (!navigation_state_.CanSendEvents(frame_id))
return;
+
helpers::DispatchOnBeforeNavigate(
web_contents(), frame_id, is_main_frame, validated_url);
}
@@ -310,6 +332,14 @@ void WebNavigationTabObserver::DidCommitProvisionalLoadForFrame(
const GURL& url,
content::PageTransition transition_type,
content::RenderViewHost* render_view_host) {
+ if (render_view_host != render_view_host_ &&
+ render_view_host != pending_render_view_host_)
+ return;
+ // TODO(jochen): If we switched the RVH, send error events for all ongoing
+ // navigations in the old RVH.
+ render_view_host_ = render_view_host;
+ pending_render_view_host_ = NULL;
+
if (!navigation_state_.CanSendEvents(frame_id))
return;
@@ -365,15 +395,25 @@ void WebNavigationTabObserver::DidFailProvisionalLoad(
int error_code,
const string16& error_description,
content::RenderViewHost* render_view_host) {
+ if (render_view_host != render_view_host_ &&
+ render_view_host != pending_render_view_host_)
+ return;
+ if (render_view_host == pending_render_view_host_)
+ pending_render_view_host_ = NULL;
+
if (!navigation_state_.CanSendEvents(frame_id))
return;
+
navigation_state_.SetErrorOccurredInFrame(frame_id);
helpers::DispatchOnErrorOccurred(
web_contents(), validated_url, frame_id, is_main_frame, error_code);
}
void WebNavigationTabObserver::DocumentLoadedInFrame(
- int64 frame_id) {
+ int64 frame_id,
+ content::RenderViewHost* render_view_host) {
+ if (render_view_host != render_view_host_)
+ return;
if (!navigation_state_.CanSendEvents(frame_id))
return;
helpers::DispatchOnDOMContentLoaded(web_contents(),
@@ -385,7 +425,10 @@ void WebNavigationTabObserver::DocumentLoadedInFrame(
void WebNavigationTabObserver::DidFinishLoad(
int64 frame_id,
const GURL& validated_url,
- bool is_main_frame) {
+ bool is_main_frame,
+ content::RenderViewHost* render_view_host) {
+ if (render_view_host != render_view_host_)
+ return;
if (!navigation_state_.CanSendEvents(frame_id))
return;
navigation_state_.SetNavigationCompleted(frame_id);
@@ -402,7 +445,10 @@ void WebNavigationTabObserver::DidFailLoad(
const GURL& validated_url,
bool is_main_frame,
int error_code,
- const string16& error_description) {
+ const string16& error_description,
+ content::RenderViewHost* render_view_host) {
+ if (render_view_host != render_view_host_)
+ return;
if (!navigation_state_.CanSendEvents(frame_id))
return;
navigation_state_.SetErrorOccurredInFrame(frame_id);
diff --git a/chrome/browser/extensions/api/web_navigation/web_navigation_api.h b/chrome/browser/extensions/api/web_navigation/web_navigation_api.h
index 556dd057..e4a3c69 100644
--- a/chrome/browser/extensions/api/web_navigation/web_navigation_api.h
+++ b/chrome/browser/extensions/api/web_navigation/web_navigation_api.h
@@ -47,6 +47,8 @@ class WebNavigationTabObserver : public content::NotificationObserver,
// content::WebContentsObserver implementation.
+ virtual void AboutToNavigateRenderView(
+ content::RenderViewHost* render_view_host) OVERRIDE;
virtual void DidStartProvisionalLoadForFrame(
int64 frame_id,
bool is_main_frame,
@@ -66,15 +68,21 @@ class WebNavigationTabObserver : public content::NotificationObserver,
int error_code,
const string16& error_description,
content::RenderViewHost* render_view_host) OVERRIDE;
- virtual void DocumentLoadedInFrame(int64 frame_id) OVERRIDE;
- virtual void DidFinishLoad(int64 frame_id,
- const GURL& validated_url,
- bool is_main_frame) OVERRIDE;
- virtual void DidFailLoad(int64 frame_id,
- const GURL& validated_url,
- bool is_main_frame,
- int error_code,
- const string16& error_description) OVERRIDE;
+ virtual void DocumentLoadedInFrame(
+ int64 frame_id,
+ content::RenderViewHost* render_view_host) OVERRIDE;
+ virtual void DidFinishLoad(
+ int64 frame_id,
+ const GURL& validated_url,
+ bool is_main_frame,
+ content::RenderViewHost* render_view_host) OVERRIDE;
+ virtual void DidFailLoad(
+ int64 frame_id,
+ const GURL& validated_url,
+ bool is_main_frame,
+ int error_code,
+ const string16& error_description,
+ content::RenderViewHost* render_view_host) OVERRIDE;
virtual void DidOpenRequestedURL(content::WebContents* new_contents,
const GURL& url,
const content::Referrer& referrer,
@@ -94,6 +102,9 @@ class WebNavigationTabObserver : public content::NotificationObserver,
// Used for tracking registrations to redirect notifications.
content::NotificationRegistrar registrar_;
+ content::RenderViewHost* render_view_host_;
+ content::RenderViewHost* pending_render_view_host_;
+
DISALLOW_COPY_AND_ASSIGN(WebNavigationTabObserver);
};
diff --git a/chrome/browser/page_cycler/page_cycler.cc b/chrome/browser/page_cycler/page_cycler.cc
index 5647d6d..ef66161 100644
--- a/chrome/browser/page_cycler/page_cycler.cc
+++ b/chrome/browser/page_cycler/page_cycler.cc
@@ -61,7 +61,8 @@ bool PageCycler::IsLoadCallbackValid(const GURL& validated_url,
void PageCycler::DidFinishLoad(int64 frame_id,
const GURL& validated_url,
- bool is_main_frame) {
+ bool is_main_frame,
+ content::RenderViewHost* render_view_host) {
if (IsLoadCallbackValid(validated_url, is_main_frame))
LoadSucceeded();
}
diff --git a/chrome/browser/page_cycler/page_cycler.h b/chrome/browser/page_cycler/page_cycler.h
index 7304be4..65eb204 100644
--- a/chrome/browser/page_cycler/page_cycler.h
+++ b/chrome/browser/page_cycler/page_cycler.h
@@ -35,9 +35,11 @@ class PageCycler : public base::RefCountedThreadSafe<PageCycler>,
void Run();
// content::WebContentsObserver
- virtual void DidFinishLoad(int64 frame_id,
- const GURL& validated_url,
- bool is_main_frame) OVERRIDE;
+ virtual void DidFinishLoad(
+ int64 frame_id,
+ const GURL& validated_url,
+ bool is_main_frame,
+ content::RenderViewHost* render_view_host) OVERRIDE;
virtual void DidFailProvisionalLoad(
int64 frame_id,
bool is_main_frame,
diff --git a/chrome/browser/page_cycler/page_cycler_unittest.cc b/chrome/browser/page_cycler/page_cycler_unittest.cc
index df99e39..8751407 100644
--- a/chrome/browser/page_cycler/page_cycler_unittest.cc
+++ b/chrome/browser/page_cycler/page_cycler_unittest.cc
@@ -53,9 +53,10 @@ class MockPageCycler : public PageCycler {
set_errors_file(errors_file);
}
- MOCK_METHOD3(DidFinishLoad, void(int64 frame_id,
+ MOCK_METHOD4(DidFinishLoad, void(int64 frame_id,
const GURL& validated_url,
- bool is_main_frame));
+ bool is_main_frame,
+ RenderViewHost* render_view_host));
MOCK_METHOD6(DidFailProvisionalLoad, void(int64 frame_id,
bool is_main_frame,
const GURL& validated_url,
@@ -79,8 +80,10 @@ class MockPageCycler : public PageCycler {
void PageCyclerDidFinishLoad(int64 frame_id,
const GURL& validated_url,
- bool is_main_frame) {
- PageCycler::DidFinishLoad(frame_id, validated_url, is_main_frame);
+ bool is_main_frame,
+ RenderViewHost* render_view_host) {
+ PageCycler::DidFinishLoad(
+ frame_id, validated_url, is_main_frame, render_view_host);
}
private:
@@ -134,7 +137,7 @@ class PageCyclerTest : public BrowserWithTestWindowTest {
FOR_EACH_OBSERVER(
WebContentsObserver,
observers_,
- DidFinishLoad(kFrameID, kAboutURL, kIsMainFrame));
+ DidFinishLoad(kFrameID, kAboutURL, kIsMainFrame, NULL));
PumpLoop();
}
@@ -208,7 +211,8 @@ TEST_F(PageCyclerTest, FailProvisionalLoads) {
RunPageCycler();
// Page cycler expects browser to automatically start loading the first page.
- EXPECT_CALL(*page_cycler(), DidFinishLoad(kFrameID, kAboutURL, kIsMainFrame))
+ EXPECT_CALL(*page_cycler(),
+ DidFinishLoad(kFrameID, kAboutURL, kIsMainFrame, _))
.WillOnce(Invoke(page_cycler(),
&MockPageCycler::PageCyclerDidFinishLoad));
FinishLoad();
@@ -273,7 +277,7 @@ TEST_F(PageCyclerTest, StatsFile) {
for (int i = 0; i < kNumLoads; ++i) {
EXPECT_CALL(*page_cycler(), DidFinishLoad(
- kFrameID, kAboutURL, kIsMainFrame))
+ kFrameID, kAboutURL, kIsMainFrame, _))
.WillOnce(Invoke(page_cycler(),
&MockPageCycler::PageCyclerDidFinishLoad));
FinishLoad();
@@ -300,7 +304,8 @@ TEST_F(PageCyclerTest, KillBrowserAndAbort) {
errors_file()));
RunPageCycler();
- EXPECT_CALL(*page_cycler(), DidFinishLoad(kFrameID, kAboutURL, kIsMainFrame))
+ EXPECT_CALL(*page_cycler(),
+ DidFinishLoad(kFrameID, kAboutURL, kIsMainFrame, _))
.WillOnce(Invoke(page_cycler(),
&MockPageCycler::PageCyclerDidFinishLoad));
message_loop()->RunAllPending();
@@ -334,7 +339,8 @@ TEST_F(PageCyclerTest, MultipleIterations) {
page_cycler()->set_stats_file(stats_file());
RunPageCycler();
- EXPECT_CALL(*page_cycler(), DidFinishLoad(kFrameID, kAboutURL, kIsMainFrame))
+ EXPECT_CALL(*page_cycler(),
+ DidFinishLoad(kFrameID, kAboutURL, kIsMainFrame, _))
.WillRepeatedly(Invoke(page_cycler(),
&MockPageCycler::PageCyclerDidFinishLoad));
diff --git a/chrome/browser/prerender/prerender_contents.cc b/chrome/browser/prerender/prerender_contents.cc
index d77be83..7e504d0 100644
--- a/chrome/browser/prerender/prerender_contents.cc
+++ b/chrome/browser/prerender/prerender_contents.cc
@@ -592,7 +592,8 @@ void PrerenderContents::DidStartProvisionalLoadForFrame(
void PrerenderContents::DidFinishLoad(int64 frame_id,
const GURL& validated_url,
- bool is_main_frame) {
+ bool is_main_frame,
+ RenderViewHost* render_view_host) {
if (is_main_frame)
has_finished_loading_ = true;
}
diff --git a/chrome/browser/prerender/prerender_contents.h b/chrome/browser/prerender/prerender_contents.h
index 7b0a914..9d1be4e 100644
--- a/chrome/browser/prerender/prerender_contents.h
+++ b/chrome/browser/prerender/prerender_contents.h
@@ -171,9 +171,11 @@ class PrerenderContents : public content::NotificationObserver,
const GURL& validated_url,
bool is_error_page,
content::RenderViewHost* render_view_host) OVERRIDE;
- virtual void DidFinishLoad(int64 frame_id,
- const GURL& validated_url,
- bool is_main_frame) OVERRIDE;
+ virtual void DidFinishLoad(
+ int64 frame_id,
+ const GURL& validated_url,
+ bool is_main_frame,
+ content::RenderViewHost* render_view_host) OVERRIDE;
virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE;