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

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

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

Powered by Google App Engine
This is Rietveld 408576698