Chromium Code Reviews| 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 906e19a8051303833ff54cbacddf6a03dcfe3304..fb68ebffe920f9a0b8a3ebc2844c8ff2976d01ef 100644 |
| --- a/content/browser/web_contents/web_contents_impl.cc |
| +++ b/content/browser/web_contents/web_contents_impl.cc |
| @@ -4085,74 +4085,43 @@ void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) { |
| GetRenderViewHost()->ClosePage(); |
| } |
| -void WebContentsImpl::RouteMessageEvent( |
| - RenderViewHost* rvh, |
| - const ViewMsg_PostMessage_Params& params) { |
| - // Only deliver the message to the active RenderViewHost if the request |
| - // came from a RenderViewHost in the same BrowsingInstance or if this |
| - // WebContents is dedicated to a browser plugin guest. |
| +bool WebContentsImpl::ShouldRouteMessageEvent( |
| + RenderFrameHost* target_rfh, |
| + SiteInstance* source_site_instance) const { |
| + // Only deliver the message if the request came from a RenderFrameHost in the |
| + // same BrowsingInstance or if this WebContents is dedicated to a browser |
| + // plugin guest. |
| // Note: This check means that an embedder could theoretically receive a |
| // postMessage from anyone (not just its own guests). However, this is |
| - // probably not a risk for apps since other pages won't have references |
| - // to App windows. |
| - if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) && |
| - !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder()) |
| - return; |
| + // probably not a risk for apps since other pages won't have references to |
| + // App windows. |
| + SiteInstance* target_site_instance = target_rfh->GetSiteInstance(); |
| + return target_site_instance->IsRelatedSiteInstance(source_site_instance) || |
| + GetBrowserPluginGuest() || GetBrowserPluginEmbedder(); |
|
alexmos
2015/04/02 23:17:00
I really wanted to do the related SiteInstance che
Charlie Reis
2015/04/06 16:18:55
Actually, I think it would be better to move the r
|
| +} |
| - 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); |
| - if (source_rvh) { |
| - source_contents = static_cast<WebContentsImpl*>( |
| - source_rvh->GetDelegate()->GetAsWebContents()); |
| - } |
| +int WebContentsImpl::EnsureOpenerRenderViewsExist( |
| + RenderFrameHost* render_frame_host) { |
| + WebContentsImpl* web_contents = NULL; |
| + if (render_frame_host) { |
| + web_contents = static_cast<WebContentsImpl*>( |
| + static_cast<RenderFrameHostImpl*>(render_frame_host) |
| + ->delegate() |
| + ->GetAsWebContents()); |
| + } |
| - if (source_contents) { |
| - if (GetBrowserPluginGuest()) { |
| - // We create a swapped out RenderView for the embedder in the guest's |
| - // render process but we intentionally do not expose the embedder's |
| - // opener chain to it. |
| - new_params.source_routing_id = |
| - source_contents->CreateSwappedOutRenderView(GetSiteInstance()); |
| - } else { |
| - new_params.source_routing_id = |
| - source_contents->CreateOpenerRenderViews(GetSiteInstance()); |
| - } |
| + if (web_contents) { |
| + if (GetBrowserPluginGuest()) { |
| + // We create a swapped out RenderView for the embedder in the guest's |
| + // render process but we intentionally do not expose the embedder's |
| + // opener chain to it. |
| + return web_contents->CreateSwappedOutRenderView(GetSiteInstance()); |
| } else { |
| - // We couldn't find it, so don't pass a source frame. |
| - new_params.source_routing_id = MSG_ROUTING_NONE; |
| + return web_contents->CreateOpenerRenderViews(GetSiteInstance()); |
| } |
| } |
| - // 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. |
| - if (!params.message_ports.empty()) { |
| - // Updating the message port information has to be done in the IO thread; |
| - // MessagePortMessageFilter::RouteMessageEventWithMessagePorts will send |
| - // ViewMsg_PostMessageEvent after it's done. Note that a trivial solution |
| - // would've been to post a task on the IO thread to do the IO-thread-bound |
| - // work, and make that post a task back to WebContentsImpl in the UI |
| - // thread. But we cannot do that, since there's nothing to guarantee that |
| - // WebContentsImpl stays alive during the round trip. |
| - scoped_refptr<MessagePortMessageFilter> message_port_message_filter( |
| - static_cast<RenderProcessHostImpl*>(GetRenderProcessHost()) |
| - ->message_port_message_filter()); |
| - BrowserThread::PostTask( |
| - BrowserThread::IO, FROM_HERE, |
| - base::Bind(&MessagePortMessageFilter::RouteMessageEventWithMessagePorts, |
| - message_port_message_filter, GetRoutingID(), new_params)); |
| - } else { |
| - Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params)); |
| - } |
| + return MSG_ROUTING_NONE; |
| } |
| bool WebContentsImpl::AddMessageToConsole(int32 level, |