Chromium Code Reviews| 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 2408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2419 void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) { | 2419 void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) { |
| 2420 // Tell the active RenderViewHost to run unload handlers and close, as long | 2420 // Tell the active RenderViewHost to run unload handlers and close, as long |
| 2421 // as the request came from a RenderViewHost in the same BrowsingInstance. | 2421 // as the request came from a RenderViewHost in the same BrowsingInstance. |
| 2422 // In most cases, we receive this from a swapped out RenderViewHost. | 2422 // In most cases, we receive this from a swapped out RenderViewHost. |
| 2423 // It is possible to receive it from one that has just been swapped in, | 2423 // It is possible to receive it from one that has just been swapped in, |
| 2424 // in which case we might as well deliver the message anyway. | 2424 // in which case we might as well deliver the message anyway. |
| 2425 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) | 2425 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) |
| 2426 GetRenderViewHost()->ClosePage(); | 2426 GetRenderViewHost()->ClosePage(); |
| 2427 } | 2427 } |
| 2428 | 2428 |
| 2429 void WebContentsImpl::RouteMessageEvent( | |
| 2430 RenderViewHost* rvh, | |
| 2431 const ViewMsg_PostMessage_Params& params) { | |
| 2432 // Deliver the message to the active RenderViewHost, as long as the request | |
| 2433 // came from a RenderViewHost in the same BrowsingInstance. | |
| 2434 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) { | |
|
Aaron Boodman
2012/05/14 21:27:40
Nit: invert check and return early.
Charlie Reis
2012/05/14 23:20:37
Done.
| |
| 2435 ViewMsg_PostMessage_Params new_params(params); | |
| 2436 | |
| 2437 // If there is a source_routing_id, translate it to the routing ID for | |
| 2438 // the equivalent swapped out RVH in the target process. If we need | |
| 2439 // to create a swapped out RVH for the source tab, we create its opener | |
| 2440 // chain as well, since those will also be accessible to the target page. | |
| 2441 if (new_params.source_routing_id != MSG_ROUTING_NONE) { | |
| 2442 // Try to look up the WebContents for the source page. | |
| 2443 WebContentsImpl* source_contents = NULL; | |
| 2444 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID( | |
| 2445 rvh->GetProcess()->GetID(), params.source_routing_id); | |
| 2446 RenderViewHostDelegate* source_delegate = | |
| 2447 source_rvh ? source_rvh->GetDelegate() : NULL; | |
| 2448 if (source_delegate && source_delegate->GetRenderViewType() == | |
| 2449 content::VIEW_TYPE_WEB_CONTENTS) { | |
| 2450 source_contents = static_cast<WebContentsImpl*>(source_delegate); | |
| 2451 } | |
| 2452 | |
| 2453 if (source_contents) { | |
| 2454 new_params.source_routing_id = | |
| 2455 source_contents->CreateOpenerRenderViews(GetSiteInstance()); | |
| 2456 } else { | |
| 2457 // We couldn't find it, so don't pass a source frame. | |
| 2458 new_params.source_routing_id = MSG_ROUTING_NONE; | |
| 2459 } | |
| 2460 } | |
| 2461 | |
| 2462 // In most cases, we receive this from a swapped out RenderViewHost. | |
| 2463 // It is possible to receive it from one that has just been swapped in, | |
| 2464 // in which case we might as well deliver the message anyway. | |
| 2465 GetRenderViewHost()->Send(new ViewMsg_PostMessageEvent( | |
| 2466 GetRenderViewHost()->GetRoutingID(), new_params)); | |
| 2467 } | |
| 2468 } | |
| 2469 | |
| 2429 void WebContentsImpl::RunJavaScriptMessage( | 2470 void WebContentsImpl::RunJavaScriptMessage( |
| 2430 RenderViewHost* rvh, | 2471 RenderViewHost* rvh, |
| 2431 const string16& message, | 2472 const string16& message, |
| 2432 const string16& default_prompt, | 2473 const string16& default_prompt, |
| 2433 const GURL& frame_url, | 2474 const GURL& frame_url, |
| 2434 ui::JavascriptMessageType javascript_message_type, | 2475 ui::JavascriptMessageType javascript_message_type, |
| 2435 IPC::Message* reply_msg, | 2476 IPC::Message* reply_msg, |
| 2436 bool* did_suppress_message) { | 2477 bool* did_suppress_message) { |
| 2437 // Suppress JavaScript dialogs when requested. Also suppress messages when | 2478 // Suppress JavaScript dialogs when requested. Also suppress messages when |
| 2438 // showing an interstitial as it's shown over the previous page and we don't | 2479 // 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 Loading... | |
| 2737 void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { | 2778 void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
| 2738 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh); | 2779 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh); |
| 2739 // Can be NULL during tests. | 2780 // Can be NULL during tests. |
| 2740 if (rwh_view) | 2781 if (rwh_view) |
| 2741 rwh_view->SetSize(GetView()->GetContainerSize()); | 2782 rwh_view->SetSize(GetView()->GetContainerSize()); |
| 2742 } | 2783 } |
| 2743 | 2784 |
| 2744 RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() { | 2785 RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() { |
| 2745 return static_cast<RenderViewHostImpl*>(GetRenderViewHost()); | 2786 return static_cast<RenderViewHostImpl*>(GetRenderViewHost()); |
| 2746 } | 2787 } |
| OLD | NEW |