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

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: Use FromRoutingID 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 =
2439 source_rvh ? source_rvh->GetDelegate() : NULL;
2440 if (source_delegate && source_delegate->GetRenderViewType() ==
2441 content::VIEW_TYPE_WEB_CONTENTS) {
2442 source_contents = static_cast<WebContentsImpl*>(source_delegate);
2443 }
2444
2445 if (source_contents) {
2446 new_params.source_routing_id =
2447 source_contents->CreateOpenerRenderViews(GetSiteInstance());
2448 } else {
2449 // We couldn't find it, so don't pass a source frame.
2450 new_params.source_routing_id = MSG_ROUTING_NONE;
2451 }
2452 }
2453
2454 // In most cases, we receive this from a swapped out RenderViewHost.
2455 // It is possible to receive it from one that has just been swapped in,
2456 // in which case we might as well deliver the message anyway.
2457 GetRenderViewHost()->Send(new ViewMsg_PostMessageEvent(
2458 GetRenderViewHost()->GetRoutingID(), new_params));
2459 }
2460 }
2461
2421 void WebContentsImpl::RunJavaScriptMessage( 2462 void WebContentsImpl::RunJavaScriptMessage(
2422 RenderViewHost* rvh, 2463 RenderViewHost* rvh,
2423 const string16& message, 2464 const string16& message,
2424 const string16& default_prompt, 2465 const string16& default_prompt,
2425 const GURL& frame_url, 2466 const GURL& frame_url,
2426 ui::JavascriptMessageType javascript_message_type, 2467 ui::JavascriptMessageType javascript_message_type,
2427 IPC::Message* reply_msg, 2468 IPC::Message* reply_msg,
2428 bool* did_suppress_message) { 2469 bool* did_suppress_message) {
2429 // Suppress JavaScript dialogs when requested. Also suppress messages when 2470 // 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 2471 // 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) { 2770 void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
2730 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh); 2771 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
2731 // Can be NULL during tests. 2772 // Can be NULL during tests.
2732 if (rwh_view) 2773 if (rwh_view)
2733 rwh_view->SetSize(GetView()->GetContainerSize()); 2774 rwh_view->SetSize(GetView()->GetContainerSize());
2734 } 2775 }
2735 2776
2736 RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() { 2777 RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
2737 return static_cast<RenderViewHostImpl*>(GetRenderViewHost()); 2778 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
2738 } 2779 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698