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 // Only deliver the message to the active RenderViewHost if the request |
| 2433 // came from a RenderViewHost in the same BrowsingInstance. |
| 2434 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) |
| 2435 return; |
| 2436 |
| 2437 ViewMsg_PostMessage_Params new_params(params); |
| 2438 |
| 2439 // If there is a source_routing_id, translate it to the routing ID for |
| 2440 // the equivalent swapped out RVH in the target process. If we need |
| 2441 // to create a swapped out RVH for the source tab, we create its opener |
| 2442 // chain as well, since those will also be accessible to the target page. |
| 2443 if (new_params.source_routing_id != MSG_ROUTING_NONE) { |
| 2444 // Try to look up the WebContents for the source page. |
| 2445 WebContentsImpl* source_contents = NULL; |
| 2446 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID( |
| 2447 rvh->GetProcess()->GetID(), params.source_routing_id); |
| 2448 if (source_rvh) { |
| 2449 source_contents = static_cast<WebContentsImpl*>( |
| 2450 source_rvh->GetDelegate()->GetAsWebContents()); |
| 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 |
2429 void WebContentsImpl::RunJavaScriptMessage( | 2469 void WebContentsImpl::RunJavaScriptMessage( |
2430 RenderViewHost* rvh, | 2470 RenderViewHost* rvh, |
2431 const string16& message, | 2471 const string16& message, |
2432 const string16& default_prompt, | 2472 const string16& default_prompt, |
2433 const GURL& frame_url, | 2473 const GURL& frame_url, |
2434 ui::JavascriptMessageType javascript_message_type, | 2474 ui::JavascriptMessageType javascript_message_type, |
2435 IPC::Message* reply_msg, | 2475 IPC::Message* reply_msg, |
2436 bool* did_suppress_message) { | 2476 bool* did_suppress_message) { |
2437 // Suppress JavaScript dialogs when requested. Also suppress messages when | 2477 // 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 | 2478 // 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) { | 2777 void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
2738 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh); | 2778 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh); |
2739 // Can be NULL during tests. | 2779 // Can be NULL during tests. |
2740 if (rwh_view) | 2780 if (rwh_view) |
2741 rwh_view->SetSize(GetView()->GetContainerSize()); | 2781 rwh_view->SetSize(GetView()->GetContainerSize()); |
2742 } | 2782 } |
2743 | 2783 |
2744 RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() { | 2784 RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() { |
2745 return static_cast<RenderViewHostImpl*>(GetRenderViewHost()); | 2785 return static_cast<RenderViewHostImpl*>(GetRenderViewHost()); |
2746 } | 2786 } |
OLD | NEW |