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

Side by Side Diff: content/browser/web_contents/web_contents_impl.cc

Issue 1046933005: Refactor postMessage for out-of-process iframes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Enable SupportCrossProcessPostMessage test on FYI bots Created 5 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/web_contents/web_contents_impl.h" 5 #include "content/browser/web_contents/web_contents_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 4067 matching lines...) Expand 10 before | Expand all | Expand 10 after
4078 void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) { 4078 void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
4079 // Tell the active RenderViewHost to run unload handlers and close, as long 4079 // Tell the active RenderViewHost to run unload handlers and close, as long
4080 // as the request came from a RenderViewHost in the same BrowsingInstance. 4080 // as the request came from a RenderViewHost in the same BrowsingInstance.
4081 // In most cases, we receive this from a swapped out RenderViewHost. 4081 // In most cases, we receive this from a swapped out RenderViewHost.
4082 // It is possible to receive it from one that has just been swapped in, 4082 // It is possible to receive it from one that has just been swapped in,
4083 // in which case we might as well deliver the message anyway. 4083 // in which case we might as well deliver the message anyway.
4084 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) 4084 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
4085 GetRenderViewHost()->ClosePage(); 4085 GetRenderViewHost()->ClosePage();
4086 } 4086 }
4087 4087
4088 void WebContentsImpl::RouteMessageEvent( 4088 bool WebContentsImpl::ShouldRouteMessageEvent(
4089 RenderViewHost* rvh, 4089 RenderFrameHost* target_rfh,
4090 const ViewMsg_PostMessage_Params& params) { 4090 SiteInstance* source_site_instance) const {
4091 // Only deliver the message to the active RenderViewHost if the request 4091 // Only deliver the message if the request came from a RenderFrameHost in the
4092 // came from a RenderViewHost in the same BrowsingInstance or if this 4092 // same BrowsingInstance or if this WebContents is dedicated to a browser
4093 // WebContents is dedicated to a browser plugin guest. 4093 // plugin guest.
4094 // Note: This check means that an embedder could theoretically receive a 4094 // Note: This check means that an embedder could theoretically receive a
4095 // postMessage from anyone (not just its own guests). However, this is 4095 // postMessage from anyone (not just its own guests). However, this is
4096 // probably not a risk for apps since other pages won't have references 4096 // probably not a risk for apps since other pages won't have references to
4097 // to App windows. 4097 // App windows.
4098 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) && 4098 SiteInstance* target_site_instance = target_rfh->GetSiteInstance();
4099 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder()) 4099 return target_site_instance->IsRelatedSiteInstance(source_site_instance) ||
4100 return; 4100 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
4101 }
4101 4102
4102 ViewMsg_PostMessage_Params new_params(params); 4103 int WebContentsImpl::EnsureOpenerRenderViewsExist(
4104 RenderFrameHost* render_frame_host) {
4105 WebContentsImpl* web_contents = NULL;
4106 if (render_frame_host) {
4107 web_contents = static_cast<WebContentsImpl*>(
4108 static_cast<RenderFrameHostImpl*>(render_frame_host)
4109 ->delegate()
4110 ->GetAsWebContents());
4111 }
4103 4112
4104 // If there is a source_routing_id, translate it to the routing ID for 4113 if (web_contents) {
4105 // the equivalent swapped out RVH in the target process. If we need 4114 if (GetBrowserPluginGuest()) {
4106 // to create a swapped out RVH for the source tab, we create its opener 4115 // We create a swapped out RenderView for the embedder in the guest's
4107 // chain as well, since those will also be accessible to the target page. 4116 // render process but we intentionally do not expose the embedder's
4108 if (new_params.source_routing_id != MSG_ROUTING_NONE) { 4117 // opener chain to it.
4109 // Try to look up the WebContents for the source page. 4118 return web_contents->CreateSwappedOutRenderView(GetSiteInstance());
4110 WebContentsImpl* source_contents = NULL;
4111 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
4112 rvh->GetProcess()->GetID(), params.source_routing_id);
4113 if (source_rvh) {
4114 source_contents = static_cast<WebContentsImpl*>(
4115 source_rvh->GetDelegate()->GetAsWebContents());
4116 }
4117
4118 if (source_contents) {
4119 if (GetBrowserPluginGuest()) {
4120 // We create a swapped out RenderView for the embedder in the guest's
4121 // render process but we intentionally do not expose the embedder's
4122 // opener chain to it.
4123 new_params.source_routing_id =
4124 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
4125 } else {
4126 new_params.source_routing_id =
4127 source_contents->CreateOpenerRenderViews(GetSiteInstance());
4128 }
4129 } else { 4119 } else {
4130 // We couldn't find it, so don't pass a source frame. 4120 return web_contents->CreateOpenerRenderViews(GetSiteInstance());
4131 new_params.source_routing_id = MSG_ROUTING_NONE;
4132 } 4121 }
4133 } 4122 }
4134 4123
4135 // In most cases, we receive this from a swapped out RenderViewHost. 4124 return MSG_ROUTING_NONE;
4136 // It is possible to receive it from one that has just been swapped in,
4137 // in which case we might as well deliver the message anyway.
4138 if (!params.message_ports.empty()) {
4139 // Updating the message port information has to be done in the IO thread;
4140 // MessagePortMessageFilter::RouteMessageEventWithMessagePorts will send
4141 // ViewMsg_PostMessageEvent after it's done. Note that a trivial solution
4142 // would've been to post a task on the IO thread to do the IO-thread-bound
4143 // work, and make that post a task back to WebContentsImpl in the UI
4144 // thread. But we cannot do that, since there's nothing to guarantee that
4145 // WebContentsImpl stays alive during the round trip.
4146 scoped_refptr<MessagePortMessageFilter> message_port_message_filter(
4147 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
4148 ->message_port_message_filter());
4149 BrowserThread::PostTask(
4150 BrowserThread::IO, FROM_HERE,
4151 base::Bind(&MessagePortMessageFilter::RouteMessageEventWithMessagePorts,
4152 message_port_message_filter, GetRoutingID(), new_params));
4153 } else {
4154 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
4155 }
4156 } 4125 }
4157 4126
4158 bool WebContentsImpl::AddMessageToConsole(int32 level, 4127 bool WebContentsImpl::AddMessageToConsole(int32 level,
4159 const base::string16& message, 4128 const base::string16& message,
4160 int32 line_no, 4129 int32 line_no,
4161 const base::string16& source_id) { 4130 const base::string16& source_id) {
4162 if (!delegate_) 4131 if (!delegate_)
4163 return false; 4132 return false;
4164 return delegate_->AddMessageToConsole(this, level, message, line_no, 4133 return delegate_->AddMessageToConsole(this, level, message, line_no,
4165 source_id); 4134 source_id);
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
4648 node->render_manager()->ResumeResponseDeferredAtStart(); 4617 node->render_manager()->ResumeResponseDeferredAtStart();
4649 } 4618 }
4650 4619
4651 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { 4620 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4652 force_disable_overscroll_content_ = force_disable; 4621 force_disable_overscroll_content_ = force_disable;
4653 if (view_) 4622 if (view_)
4654 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); 4623 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4655 } 4624 }
4656 4625
4657 } // namespace content 4626 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698