Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1552)

Unified Diff: content/browser/web_contents/web_contents_impl.cc

Issue 9108001: Adds support for calling postMessage on a frame living in a different renderer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename struct, hide FromRoutingID. Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/web_contents/web_contents_impl.h ('k') | content/common/swapped_out_messages.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/web_contents/web_contents_impl.cc
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 558fa451b5a1089c3ca7e446a339c538804076c7..bb5b1855ba418b60a00304fe3e239dbb0fb9adf6 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -2426,6 +2426,47 @@ void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
GetRenderViewHost()->ClosePage();
}
+void WebContentsImpl::RouteMessageEvent(
+ RenderViewHost* rvh,
+ const ViewMsg_PostMessage_Params& params) {
+ // Deliver the message to the active RenderViewHost, as long as the request
+ // came from a RenderViewHost in the same BrowsingInstance.
+ if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
Aaron Boodman 2012/05/14 21:27:40 Nit: invert check and return early.
Charlie Reis 2012/05/14 23:20:37 Done.
+ ViewMsg_PostMessage_Params new_params(params);
+
+ // If there is a source_routing_id, translate it to the routing ID for
+ // the equivalent swapped out RVH in the target process. If we need
+ // to create a swapped out RVH for the source tab, we create its opener
+ // chain as well, since those will also be accessible to the target page.
+ if (new_params.source_routing_id != MSG_ROUTING_NONE) {
+ // Try to look up the WebContents for the source page.
+ WebContentsImpl* source_contents = NULL;
+ RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
+ rvh->GetProcess()->GetID(), params.source_routing_id);
+ RenderViewHostDelegate* source_delegate =
+ source_rvh ? source_rvh->GetDelegate() : NULL;
+ if (source_delegate && source_delegate->GetRenderViewType() ==
+ content::VIEW_TYPE_WEB_CONTENTS) {
+ source_contents = static_cast<WebContentsImpl*>(source_delegate);
+ }
+
+ if (source_contents) {
+ new_params.source_routing_id =
+ source_contents->CreateOpenerRenderViews(GetSiteInstance());
+ } else {
+ // We couldn't find it, so don't pass a source frame.
+ new_params.source_routing_id = MSG_ROUTING_NONE;
+ }
+ }
+
+ // In most cases, we receive this from a swapped out RenderViewHost.
+ // It is possible to receive it from one that has just been swapped in,
+ // in which case we might as well deliver the message anyway.
+ GetRenderViewHost()->Send(new ViewMsg_PostMessageEvent(
+ GetRenderViewHost()->GetRoutingID(), new_params));
+ }
+}
+
void WebContentsImpl::RunJavaScriptMessage(
RenderViewHost* rvh,
const string16& message,
« no previous file with comments | « content/browser/web_contents/web_contents_impl.h ('k') | content/common/swapped_out_messages.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698