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/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 2987 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2998 // It is possible to receive it from one that has just been swapped in, | 2998 // It is possible to receive it from one that has just been swapped in, |
2999 // in which case we might as well deliver the message anyway. | 2999 // in which case we might as well deliver the message anyway. |
3000 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) | 3000 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) |
3001 GetRenderViewHost()->ClosePage(); | 3001 GetRenderViewHost()->ClosePage(); |
3002 } | 3002 } |
3003 | 3003 |
3004 void WebContentsImpl::RouteMessageEvent( | 3004 void WebContentsImpl::RouteMessageEvent( |
3005 RenderViewHost* rvh, | 3005 RenderViewHost* rvh, |
3006 const ViewMsg_PostMessage_Params& params) { | 3006 const ViewMsg_PostMessage_Params& params) { |
3007 // Only deliver the message to the active RenderViewHost if the request | 3007 // Only deliver the message to the active RenderViewHost if the request |
3008 // came from a RenderViewHost in the same BrowsingInstance. | 3008 // came from a RenderViewHost in the same BrowsingInstance or if this |
3009 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) | 3009 // WebContents is dedicated to a browser plugin guest. |
| 3010 // Note: This check means that an embedder could theoretically receive a |
| 3011 // postMessage from anyone (not just its own guests). However, this is |
| 3012 // probably not a risk for apps since other pages won't have references |
| 3013 // to App windows. |
| 3014 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) && |
| 3015 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder()) |
3010 return; | 3016 return; |
3011 | 3017 |
3012 ViewMsg_PostMessage_Params new_params(params); | 3018 ViewMsg_PostMessage_Params new_params(params); |
3013 | 3019 |
3014 // If the renderer has changed while the post message is being routed, | 3020 // If the renderer has changed while the post message is being routed, |
3015 // drop the message, as it will not be delivered to the right target. | 3021 // drop the message, as it will not be delivered to the right target. |
3016 // TODO(nasko): Check for process ID and target frame id mismatch, once | 3022 // TODO(nasko): Check for process ID and target frame id mismatch, once |
3017 // http://crbug.com/153701 is fixed. | 3023 // http://crbug.com/153701 is fixed. |
3018 | 3024 |
3019 // If there is a source_routing_id, translate it to the routing ID for | 3025 // If there is a source_routing_id, translate it to the routing ID for |
3020 // the equivalent swapped out RVH in the target process. If we need | 3026 // the equivalent swapped out RVH in the target process. If we need |
3021 // to create a swapped out RVH for the source tab, we create its opener | 3027 // to create a swapped out RVH for the source tab, we create its opener |
3022 // chain as well, since those will also be accessible to the target page. | 3028 // chain as well, since those will also be accessible to the target page. |
3023 if (new_params.source_routing_id != MSG_ROUTING_NONE) { | 3029 if (new_params.source_routing_id != MSG_ROUTING_NONE) { |
3024 // Try to look up the WebContents for the source page. | 3030 // Try to look up the WebContents for the source page. |
3025 WebContentsImpl* source_contents = NULL; | 3031 WebContentsImpl* source_contents = NULL; |
3026 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID( | 3032 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID( |
3027 rvh->GetProcess()->GetID(), params.source_routing_id); | 3033 rvh->GetProcess()->GetID(), params.source_routing_id); |
3028 if (source_rvh) { | 3034 if (source_rvh) { |
3029 source_contents = static_cast<WebContentsImpl*>( | 3035 source_contents = static_cast<WebContentsImpl*>( |
3030 source_rvh->GetDelegate()->GetAsWebContents()); | 3036 source_rvh->GetDelegate()->GetAsWebContents()); |
3031 } | 3037 } |
3032 | 3038 |
3033 if (source_contents) { | 3039 if (source_contents) { |
3034 new_params.source_routing_id = | 3040 if (GetBrowserPluginGuest()) { |
3035 source_contents->CreateOpenerRenderViews(GetSiteInstance()); | 3041 // We create a swapped out RenderView for the embedder in the guest's |
| 3042 // render process but we intentionally do not expose the embedder's |
| 3043 // opener chain to it. |
| 3044 new_params.source_routing_id = |
| 3045 source_contents->CreateSwappedOutRenderView(GetSiteInstance()); |
| 3046 } else { |
| 3047 new_params.source_routing_id = |
| 3048 source_contents->CreateOpenerRenderViews(GetSiteInstance()); |
| 3049 } |
3036 } else { | 3050 } else { |
3037 // We couldn't find it, so don't pass a source frame. | 3051 // We couldn't find it, so don't pass a source frame. |
3038 new_params.source_routing_id = MSG_ROUTING_NONE; | 3052 new_params.source_routing_id = MSG_ROUTING_NONE; |
3039 } | 3053 } |
3040 } | 3054 } |
3041 | 3055 |
3042 // In most cases, we receive this from a swapped out RenderViewHost. | 3056 // In most cases, we receive this from a swapped out RenderViewHost. |
3043 // It is possible to receive it from one that has just been swapped in, | 3057 // It is possible to receive it from one that has just been swapped in, |
3044 // in which case we might as well deliver the message anyway. | 3058 // in which case we might as well deliver the message anyway. |
3045 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params)); | 3059 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params)); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3128 } | 3142 } |
3129 | 3143 |
3130 WebPreferences WebContentsImpl::GetWebkitPrefs() { | 3144 WebPreferences WebContentsImpl::GetWebkitPrefs() { |
3131 // We want to base the page config off of the real URL, rather than the | 3145 // We want to base the page config off of the real URL, rather than the |
3132 // display URL. | 3146 // display URL. |
3133 GURL url = controller_.GetActiveEntry() | 3147 GURL url = controller_.GetActiveEntry() |
3134 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL(); | 3148 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL(); |
3135 return GetWebkitPrefs(GetRenderViewHost(), url); | 3149 return GetWebkitPrefs(GetRenderViewHost(), url); |
3136 } | 3150 } |
3137 | 3151 |
| 3152 int WebContentsImpl::CreateSwappedOutRenderView( |
| 3153 content::SiteInstance* instance) { |
| 3154 return render_manager_.CreateRenderView(instance, MSG_ROUTING_NONE, true); |
| 3155 } |
| 3156 |
3138 void WebContentsImpl::OnUserGesture() { | 3157 void WebContentsImpl::OnUserGesture() { |
3139 // Notify observers. | 3158 // Notify observers. |
3140 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture()); | 3159 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture()); |
3141 | 3160 |
3142 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); | 3161 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); |
3143 if (rdh) // NULL in unittests. | 3162 if (rdh) // NULL in unittests. |
3144 rdh->OnUserGesture(this); | 3163 rdh->OnUserGesture(this); |
3145 } | 3164 } |
3146 | 3165 |
3147 void WebContentsImpl::OnIgnoredUIEvent() { | 3166 void WebContentsImpl::OnIgnoredUIEvent() { |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3407 } | 3426 } |
3408 } | 3427 } |
3409 | 3428 |
3410 content::BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() { | 3429 content::BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() { |
3411 return browser_plugin_guest_.get(); | 3430 return browser_plugin_guest_.get(); |
3412 } | 3431 } |
3413 | 3432 |
3414 content::BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() { | 3433 content::BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() { |
3415 return browser_plugin_embedder_.get(); | 3434 return browser_plugin_embedder_.get(); |
3416 } | 3435 } |
OLD | NEW |