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
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 600c7b1..b3e9f7c 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -600,7 +600,8 @@
return &render_manager_;
}
-bool WebContentsImpl::OnMessageReceived(const IPC::Message& message) {
+bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
+ const IPC::Message& message) {
if (GetWebUI() &&
static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
return true;
@@ -612,6 +613,9 @@
if (observer->OnMessageReceived(message))
return true;
+ // Message handlers should be aware of which RenderViewHost sent the
+ // message, which is temporarily stored in message_source_.
+ message_source_ = render_view_host;
bool handled = true;
bool message_is_ok = true;
IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
@@ -650,6 +654,7 @@
IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP_EX()
+ message_source_ = NULL;
if (!message_is_ok) {
content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
@@ -1406,6 +1411,11 @@
dest_render_view_host,
entry.GetURL());
+ // Notify observers that we will navigate in this RV.
+ FOR_EACH_OBSERVER(WebContentsObserver,
+ observers_,
+ AboutToNavigateRenderView(dest_render_view_host));
+
// Used for page load time metrics.
current_load_start_ = base::TimeTicks::Now();
@@ -1963,7 +1973,7 @@
void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
controller_.DocumentLoadedInFrame();
FOR_EACH_OBSERVER(WebContentsObserver, observers_,
- DocumentLoadedInFrame(frame_id));
+ DocumentLoadedInFrame(frame_id, message_source_));
}
void WebContentsImpl::OnDidFinishLoad(
@@ -1971,7 +1981,8 @@
const GURL& validated_url,
bool is_main_frame) {
FOR_EACH_OBSERVER(WebContentsObserver, observers_,
- DidFinishLoad(frame_id, validated_url, is_main_frame));
+ DidFinishLoad(frame_id, validated_url, is_main_frame,
+ message_source_));
}
void WebContentsImpl::OnDidFailLoadWithError(
@@ -1982,7 +1993,8 @@
const string16& error_description) {
FOR_EACH_OBSERVER(WebContentsObserver, observers_,
DidFailLoad(frame_id, validated_url, is_main_frame,
- error_code, error_description));
+ error_code, error_description,
+ message_source_));
}
void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
diff --git a/content/browser/web_contents/web_contents_impl.h b/content/browser/web_contents/web_contents_impl.h
index 49959b3..b4a86c7b 100644
--- a/content/browser/web_contents/web_contents_impl.h
+++ b/content/browser/web_contents/web_contents_impl.h
@@ -259,7 +259,8 @@
virtual content::RenderViewHostDelegateView* GetDelegateView() OVERRIDE;
virtual content::RenderViewHostDelegate::RendererManagement*
GetRendererManagementDelegate() OVERRIDE;
- virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
+ virtual bool OnMessageReceived(content::RenderViewHost* render_view_host,
+ const IPC::Message& message) OVERRIDE;
virtual const GURL& GetURL() const OVERRIDE;
virtual WebContents* GetAsWebContents() OVERRIDE;
virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE;
@@ -795,6 +796,10 @@
// member variables that are gone.
content::NotificationRegistrar registrar_;
+ // Used during IPC message dispatching so that the handlers can get a pointer
+ // to the RVH through which the message was received.
+ content::RenderViewHost* message_source_;
+
DISALLOW_COPY_AND_ASSIGN(WebContentsImpl);
};