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

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 nits 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
« no previous file with comments | « content/browser/web_contents/web_contents_impl.h ('k') | content/common/frame_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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* source_rfh) {
4014 WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>(
4015 WebContents::FromRenderFrameHost(source_rfh));
4015 4016
4016 // If there is a source_routing_id, translate it to the routing ID for 4017 if (source_web_contents) {
4017 // the equivalent swapped out RVH in the target process. If we need 4018 if (GetBrowserPluginGuest()) {
4018 // to create a swapped out RVH for the source tab, we create its opener 4019 // 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. 4020 // render process but we intentionally do not expose the embedder's
4020 if (new_params.source_routing_id != MSG_ROUTING_NONE) { 4021 // opener chain to it.
4021 // Try to look up the WebContents for the source page. 4022 return
4022 WebContentsImpl* source_contents = NULL; 4023 source_web_contents->CreateSwappedOutRenderView(GetSiteInstance());
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 { 4024 } else {
4042 // We couldn't find it, so don't pass a source frame. 4025 return source_web_contents->CreateOpenerRenderViews(GetSiteInstance());
4043 new_params.source_routing_id = MSG_ROUTING_NONE;
4044 } 4026 }
4045 } 4027 }
4046 4028
4047 // In most cases, we receive this from a swapped out RenderViewHost. 4029 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 } 4030 }
4069 4031
4070 bool WebContentsImpl::AddMessageToConsole(int32 level, 4032 bool WebContentsImpl::AddMessageToConsole(int32 level,
4071 const base::string16& message, 4033 const base::string16& message,
4072 int32 line_no, 4034 int32 line_no,
4073 const base::string16& source_id) { 4035 const base::string16& source_id) {
4074 if (!delegate_) 4036 if (!delegate_)
4075 return false; 4037 return false;
4076 return delegate_->AddMessageToConsole(this, level, message, line_no, 4038 return delegate_->AddMessageToConsole(this, level, message, line_no,
4077 source_id); 4039 source_id);
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
4559 node->render_manager()->ResumeResponseDeferredAtStart(); 4521 node->render_manager()->ResumeResponseDeferredAtStart();
4560 } 4522 }
4561 4523
4562 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { 4524 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4563 force_disable_overscroll_content_ = force_disable; 4525 force_disable_overscroll_content_ = force_disable;
4564 if (view_) 4526 if (view_)
4565 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); 4527 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4566 } 4528 }
4567 4529
4568 } // namespace content 4530 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_impl.h ('k') | content/common/frame_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698