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

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

Issue 9108001: Adds support for calling postMessage on a frame living in a different renderer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Minor cleanup Created 8 years, 7 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 2400 matching lines...) Expand 10 before | Expand all | Expand 10 after
2411 void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) { 2411 void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
2412 // Tell the active RenderViewHost to run unload handlers and close, as long 2412 // Tell the active RenderViewHost to run unload handlers and close, as long
2413 // as the request came from a RenderViewHost in the same BrowsingInstance. 2413 // as the request came from a RenderViewHost in the same BrowsingInstance.
2414 // In most cases, we receive this from a swapped out RenderViewHost. 2414 // In most cases, we receive this from a swapped out RenderViewHost.
2415 // It is possible to receive it from one that has just been swapped in, 2415 // It is possible to receive it from one that has just been swapped in,
2416 // in which case we might as well deliver the message anyway. 2416 // in which case we might as well deliver the message anyway.
2417 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) 2417 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2418 GetRenderViewHost()->ClosePage(); 2418 GetRenderViewHost()->ClosePage();
2419 } 2419 }
2420 2420
2421 void WebContentsImpl::RouteMessageEvent(
2422 RenderViewHost* rvh,
2423 const ViewHostMsg_PostMessage_Params& params) {
2424 // Deliver the message to the active RenderViewHost, as long as the request
2425 // came from a RenderViewHost in the same BrowsingInstance.
2426 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2427 ViewHostMsg_PostMessage_Params new_params(params);
2428
2429 // If there is a source_routing_id, translate it to the routing ID for
2430 // the equivalent swapped out RVH in the target process. If we need
2431 // to create a swapped out RVH for the source tab, we create its opener
2432 // chain as well, since those will also be accessible to the target page.
2433 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
2434 // Try to look up the WebContents for the source page.
2435 WebContentsImpl* source_contents = NULL;
2436 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
2437 rvh->GetProcess()->GetID(), params.source_routing_id);
2438 RenderViewHostDelegate* source_delegate = source_rvh->GetDelegate();
Matt Perry 2012/05/11 21:59:34 Is it possible for source_rvh to be NULL?
Charlie Reis 2012/05/11 22:36:02 Good call. Can't trust the renderer to pass a leg
2439 if (source_delegate->GetRenderViewType() ==
2440 content::VIEW_TYPE_WEB_CONTENTS) {
2441 source_contents = static_cast<WebContentsImpl*>(source_delegate);
2442 }
2443
2444 if (source_contents) {
2445 new_params.source_routing_id =
2446 source_contents->CreateOpenerRenderViews(GetSiteInstance());
2447 } else {
2448 // We couldn't find it, so don't pass a source frame.
2449 new_params.source_routing_id = MSG_ROUTING_NONE;
2450 }
2451 }
2452
2453 // In most cases, we receive this from a swapped out RenderViewHost.
2454 // It is possible to receive it from one that has just been swapped in,
2455 // in which case we might as well deliver the message anyway.
2456 GetRenderViewHost()->Send(new ViewMsg_PostMessageEvent(
2457 GetRenderViewHost()->GetRoutingID(), new_params));
2458 }
2459 }
2460
2421 void WebContentsImpl::RunJavaScriptMessage( 2461 void WebContentsImpl::RunJavaScriptMessage(
2422 RenderViewHost* rvh, 2462 RenderViewHost* rvh,
2423 const string16& message, 2463 const string16& message,
2424 const string16& default_prompt, 2464 const string16& default_prompt,
2425 const GURL& frame_url, 2465 const GURL& frame_url,
2426 ui::JavascriptMessageType javascript_message_type, 2466 ui::JavascriptMessageType javascript_message_type,
2427 IPC::Message* reply_msg, 2467 IPC::Message* reply_msg,
2428 bool* did_suppress_message) { 2468 bool* did_suppress_message) {
2429 // Suppress JavaScript dialogs when requested. Also suppress messages when 2469 // Suppress JavaScript dialogs when requested. Also suppress messages when
2430 // showing an interstitial as it's shown over the previous page and we don't 2470 // showing an interstitial as it's shown over the previous page and we don't
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
2729 void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { 2769 void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
2730 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh); 2770 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
2731 // Can be NULL during tests. 2771 // Can be NULL during tests.
2732 if (rwh_view) 2772 if (rwh_view)
2733 rwh_view->SetSize(GetView()->GetContainerSize()); 2773 rwh_view->SetSize(GetView()->GetContainerSize());
2734 } 2774 }
2735 2775
2736 RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() { 2776 RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
2737 return static_cast<RenderViewHostImpl*>(GetRenderViewHost()); 2777 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
2738 } 2778 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698