OLD | NEW |
---|---|
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 Loading... | |
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 // Only deliver the message if the request came from a RenderFrameHost in the |
4004 // came from a RenderViewHost in the same BrowsingInstance or if this | 4004 // same BrowsingInstance or if this WebContents is dedicated to a browser |
4005 // WebContents is dedicated to a browser plugin guest. | 4005 // plugin guest. |
4006 // Note: This check means that an embedder could theoretically receive a | 4006 // Note: This check means that an embedder could theoretically receive a |
4007 // postMessage from anyone (not just its own guests). However, this is | 4007 // 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 | 4008 // probably not a risk for apps since other pages won't have references to |
4009 // to App windows. | 4009 // App windows. |
4010 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) && | 4010 SiteInstance* target_site_instance = target_rfh->GetSiteInstance(); |
4011 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder()) | 4011 return target_site_instance->IsRelatedSiteInstance(source_site_instance) || |
Charlie Reis
2015/04/06 16:18:56
As in the earlier comment, let's try to put the re
alexmos
2015/04/07 18:44:40
Done.
| |
4012 return; | 4012 GetBrowserPluginGuest() || GetBrowserPluginEmbedder(); |
4013 } | |
4013 | 4014 |
4014 ViewMsg_PostMessage_Params new_params(params); | 4015 int WebContentsImpl::EnsureOpenerRenderViewsExist( |
4016 RenderFrameHost* render_frame_host) { | |
4017 WebContentsImpl* web_contents = NULL; | |
4018 if (render_frame_host) { | |
4019 web_contents = static_cast<WebContentsImpl*>( | |
4020 static_cast<RenderFrameHostImpl*>(render_frame_host) | |
4021 ->delegate() | |
4022 ->GetAsWebContents()); | |
4023 } | |
4015 | 4024 |
4016 // If there is a source_routing_id, translate it to the routing ID for | 4025 if (web_contents) { |
4017 // the equivalent swapped out RVH in the target process. If we need | 4026 if (GetBrowserPluginGuest()) { |
4018 // to create a swapped out RVH for the source tab, we create its opener | 4027 // 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. | 4028 // render process but we intentionally do not expose the embedder's |
4020 if (new_params.source_routing_id != MSG_ROUTING_NONE) { | 4029 // opener chain to it. |
4021 // Try to look up the WebContents for the source page. | 4030 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 { | 4031 } else { |
4042 // We couldn't find it, so don't pass a source frame. | 4032 return web_contents->CreateOpenerRenderViews(GetSiteInstance()); |
4043 new_params.source_routing_id = MSG_ROUTING_NONE; | |
4044 } | 4033 } |
4045 } | 4034 } |
4046 | 4035 |
4047 // In most cases, we receive this from a swapped out RenderViewHost. | 4036 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 } | 4037 } |
4069 | 4038 |
4070 bool WebContentsImpl::AddMessageToConsole(int32 level, | 4039 bool WebContentsImpl::AddMessageToConsole(int32 level, |
4071 const base::string16& message, | 4040 const base::string16& message, |
4072 int32 line_no, | 4041 int32 line_no, |
4073 const base::string16& source_id) { | 4042 const base::string16& source_id) { |
4074 if (!delegate_) | 4043 if (!delegate_) |
4075 return false; | 4044 return false; |
4076 return delegate_->AddMessageToConsole(this, level, message, line_no, | 4045 return delegate_->AddMessageToConsole(this, level, message, line_no, |
4077 source_id); | 4046 source_id); |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4559 node->render_manager()->ResumeResponseDeferredAtStart(); | 4528 node->render_manager()->ResumeResponseDeferredAtStart(); |
4560 } | 4529 } |
4561 | 4530 |
4562 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { | 4531 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { |
4563 force_disable_overscroll_content_ = force_disable; | 4532 force_disable_overscroll_content_ = force_disable; |
4564 if (view_) | 4533 if (view_) |
4565 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); | 4534 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
4566 } | 4535 } |
4567 | 4536 |
4568 } // namespace content | 4537 } // namespace content |
OLD | NEW |