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

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: Charlie's comments; moving set_render_frame_proxy() up in OnSwapOut 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 3979 matching lines...) Expand 10 before | Expand all | Expand 10 after
3990 void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) { 3990 void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3991 // Tell the active RenderViewHost to run unload handlers and close, as long 3991 // Tell the active RenderViewHost to run unload handlers and close, as long
3992 // as the request came from a RenderViewHost in the same BrowsingInstance. 3992 // as the request came from a RenderViewHost in the same BrowsingInstance.
3993 // In most cases, we receive this from a swapped out RenderViewHost. 3993 // In most cases, we receive this from a swapped out RenderViewHost.
3994 // It is possible to receive it from one that has just been swapped in, 3994 // It is possible to receive it from one that has just been swapped in,
3995 // in which case we might as well deliver the message anyway. 3995 // in which case we might as well deliver the message anyway.
3996 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) 3996 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3997 GetRenderViewHost()->ClosePage(); 3997 GetRenderViewHost()->ClosePage();
3998 } 3998 }
3999 3999
4000 void WebContentsImpl::RouteMessageEvent( 4000 bool WebContentsImpl::ShouldRouteMessageEvent(
4001 RenderViewHost* rvh, 4001 RenderFrameHost* target_rfh,
4002 const ViewMsg_PostMessage_Params& params) { 4002 SiteInstance* source_site_instance) const {
4003 // Only deliver the message to the active RenderViewHost if the request 4003 // Allow the message if this WebContents is dedicated to a browser plugin
4004 // came from a RenderViewHost in the same BrowsingInstance or if this 4004 // guest.
4005 // WebContents is dedicated to a browser plugin guest.
4006 // Note: This check means that an embedder could theoretically receive a 4005 // Note: This check means that an embedder could theoretically receive a
4007 // postMessage from anyone (not just its own guests). However, this is 4006 // postMessage from anyone (not just its own guests). However, this is
4008 // probably not a risk for apps since other pages won't have references 4007 // probably not a risk for apps since other pages won't have references
4009 // to App windows. 4008 // to App windows.
4010 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) && 4009 return GetBrowserPluginGuest() || GetBrowserPluginEmbedder();
4011 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder()) 4010 }
4012 return;
4013 4011
4014 ViewMsg_PostMessage_Params new_params(params); 4012 int WebContentsImpl::EnsureOpenerRenderViewsExist(
4013 RenderFrameHost* render_frame_host) {
Charlie Reis 2015/04/07 21:14:32 I think it might be worthwhile to keep "source_" i
alexmos 2015/04/07 21:47:30 Done.
4014 WebContentsImpl* web_contents = NULL;
Charlie Reis 2015/04/07 21:14:32 nit: source_web_contents nit: nullptr
alexmos 2015/04/07 21:47:30 Done. nullptr is gone since the check below isn't
4015 if (render_frame_host) {
Charlie Reis 2015/04/07 21:14:32 Looks like we don't expect this to be null.
alexmos 2015/04/07 21:47:30 Done.
4016 web_contents = static_cast<WebContentsImpl*>(
4017 static_cast<RenderFrameHostImpl*>(render_frame_host)
Charlie Reis 2015/04/07 21:14:32 nit: We can remove at least one of these casts usi
alexmos 2015/04/07 21:47:31 Done.
4018 ->delegate()
4019 ->GetAsWebContents());
4020 }
4015 4021
4016 // If there is a source_routing_id, translate it to the routing ID for 4022 if (web_contents) {
4017 // the equivalent swapped out RVH in the target process. If we need 4023 if (GetBrowserPluginGuest()) {
4018 // to create a swapped out RVH for the source tab, we create its opener 4024 // We create a swapped out RenderView for the embedder in the guest's
4019 // chain as well, since those will also be accessible to the target page. 4025 // render process but we intentionally do not expose the embedder's
4020 if (new_params.source_routing_id != MSG_ROUTING_NONE) { 4026 // opener chain to it.
4021 // Try to look up the WebContents for the source page. 4027 return web_contents->CreateSwappedOutRenderView(GetSiteInstance());
4022 WebContentsImpl* source_contents = NULL;
4023 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
4024 rvh->GetProcess()->GetID(), params.source_routing_id);
4025 if (source_rvh) {
4026 source_contents = static_cast<WebContentsImpl*>(
4027 source_rvh->GetDelegate()->GetAsWebContents());
4028 }
4029
4030 if (source_contents) {
4031 if (GetBrowserPluginGuest()) {
4032 // We create a swapped out RenderView for the embedder in the guest's
4033 // render process but we intentionally do not expose the embedder's
4034 // opener chain to it.
4035 new_params.source_routing_id =
4036 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
4037 } else {
4038 new_params.source_routing_id =
4039 source_contents->CreateOpenerRenderViews(GetSiteInstance());
4040 }
4041 } else { 4028 } else {
4042 // We couldn't find it, so don't pass a source frame. 4029 return web_contents->CreateOpenerRenderViews(GetSiteInstance());
4043 new_params.source_routing_id = MSG_ROUTING_NONE;
4044 } 4030 }
4045 } 4031 }
4046 4032
4047 // In most cases, we receive this from a swapped out RenderViewHost. 4033 return MSG_ROUTING_NONE;
4048 // It is possible to receive it from one that has just been swapped in,
4049 // in which case we might as well deliver the message anyway.
4050 if (!params.message_ports.empty()) {
4051 // Updating the message port information has to be done in the IO thread;
4052 // MessagePortMessageFilter::RouteMessageEventWithMessagePorts will send
4053 // ViewMsg_PostMessageEvent after it's done. Note that a trivial solution
4054 // would've been to post a task on the IO thread to do the IO-thread-bound
4055 // work, and make that post a task back to WebContentsImpl in the UI
4056 // thread. But we cannot do that, since there's nothing to guarantee that
4057 // WebContentsImpl stays alive during the round trip.
4058 scoped_refptr<MessagePortMessageFilter> message_port_message_filter(
4059 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
4060 ->message_port_message_filter());
4061 BrowserThread::PostTask(
4062 BrowserThread::IO, FROM_HERE,
4063 base::Bind(&MessagePortMessageFilter::RouteMessageEventWithMessagePorts,
4064 message_port_message_filter, GetRoutingID(), new_params));
4065 } else {
4066 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
4067 }
4068 } 4034 }
4069 4035
4070 bool WebContentsImpl::AddMessageToConsole(int32 level, 4036 bool WebContentsImpl::AddMessageToConsole(int32 level,
4071 const base::string16& message, 4037 const base::string16& message,
4072 int32 line_no, 4038 int32 line_no,
4073 const base::string16& source_id) { 4039 const base::string16& source_id) {
4074 if (!delegate_) 4040 if (!delegate_)
4075 return false; 4041 return false;
4076 return delegate_->AddMessageToConsole(this, level, message, line_no, 4042 return delegate_->AddMessageToConsole(this, level, message, line_no,
4077 source_id); 4043 source_id);
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
4559 node->render_manager()->ResumeResponseDeferredAtStart(); 4525 node->render_manager()->ResumeResponseDeferredAtStart();
4560 } 4526 }
4561 4527
4562 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { 4528 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4563 force_disable_overscroll_content_ = force_disable; 4529 force_disable_overscroll_content_ = force_disable;
4564 if (view_) 4530 if (view_)
4565 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); 4531 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4566 } 4532 }
4567 4533
4568 } // namespace content 4534 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698