OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/frame_host/render_frame_host_manager.h" | 5 #include "content/browser/frame_host/render_frame_host_manager.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/debug/crash_logging.h" | 13 #include "base/debug/crash_logging.h" |
14 #include "base/debug/dump_without_crashing.h" | 14 #include "base/debug/dump_without_crashing.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
18 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
19 #include "content/browser/child_process_security_policy_impl.h" | 19 #include "content/browser/child_process_security_policy_impl.h" |
20 #include "content/browser/devtools/render_frame_devtools_agent_host.h" | 20 #include "content/browser/devtools/render_frame_devtools_agent_host.h" |
21 #include "content/browser/frame_host/cross_site_transferring_request.h" | |
22 #include "content/browser/frame_host/debug_urls.h" | 21 #include "content/browser/frame_host/debug_urls.h" |
23 #include "content/browser/frame_host/frame_navigation_entry.h" | 22 #include "content/browser/frame_host/frame_navigation_entry.h" |
24 #include "content/browser/frame_host/interstitial_page_impl.h" | 23 #include "content/browser/frame_host/interstitial_page_impl.h" |
25 #include "content/browser/frame_host/navigation_controller_impl.h" | 24 #include "content/browser/frame_host/navigation_controller_impl.h" |
26 #include "content/browser/frame_host/navigation_entry_impl.h" | 25 #include "content/browser/frame_host/navigation_entry_impl.h" |
27 #include "content/browser/frame_host/navigation_handle_impl.h" | 26 #include "content/browser/frame_host/navigation_handle_impl.h" |
28 #include "content/browser/frame_host/navigation_request.h" | 27 #include "content/browser/frame_host/navigation_request.h" |
29 #include "content/browser/frame_host/navigator.h" | 28 #include "content/browser/frame_host/navigator.h" |
30 #include "content/browser/frame_host/render_frame_host_factory.h" | 29 #include "content/browser/frame_host/render_frame_host_factory.h" |
31 #include "content/browser/frame_host/render_frame_host_impl.h" | 30 #include "content/browser/frame_host/render_frame_host_impl.h" |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 // RenderFrameHostManager are completely initialized. This should be | 273 // RenderFrameHostManager are completely initialized. This should be |
275 // removed once the process manager moves away from NotificationService. | 274 // removed once the process manager moves away from NotificationService. |
276 // See https://crbug.com/462682. | 275 // See https://crbug.com/462682. |
277 delegate_->NotifyMainFrameSwappedFromRenderManager( | 276 delegate_->NotifyMainFrameSwappedFromRenderManager( |
278 nullptr, render_frame_host_->render_view_host()); | 277 nullptr, render_frame_host_->render_view_host()); |
279 } | 278 } |
280 } | 279 } |
281 | 280 |
282 // If entry includes the request ID of a request that is being transferred, | 281 // If entry includes the request ID of a request that is being transferred, |
283 // the destination render frame will take ownership, so release ownership of | 282 // the destination render frame will take ownership, so release ownership of |
284 // the request. | 283 // the transferring NavigationHandle. |
285 if (cross_site_transferring_request_.get() && | 284 if (transfer_navigation_handle_.get() && |
286 cross_site_transferring_request_->request_id() == | 285 transfer_navigation_handle_->request_id() == |
287 entry.transferred_global_request_id()) { | 286 entry.transferred_global_request_id()) { |
288 cross_site_transferring_request_->ReleaseRequest(); | |
289 | |
290 DCHECK(transfer_navigation_handle_); | |
291 | |
292 // Update the pending NavigationEntry ID on the transferring handle. | |
293 // TODO(creis): Make this line unnecessary by avoiding having a pending | |
294 // entry for transfer navigations. See https://crbug.com/495161. | |
295 transfer_navigation_handle_->update_entry_id_for_transfer( | |
296 entry.GetUniqueID()); | |
297 | |
298 // The navigating RenderFrameHost should take ownership of the | 287 // The navigating RenderFrameHost should take ownership of the |
299 // NavigationHandle that came from the transferring RenderFrameHost. | 288 // NavigationHandle that came from the transferring RenderFrameHost. |
300 dest_render_frame_host->SetNavigationHandle( | 289 dest_render_frame_host->SetNavigationHandle( |
301 std::move(transfer_navigation_handle_)); | 290 std::move(transfer_navigation_handle_)); |
291 | |
292 dest_render_frame_host->navigation_handle()->set_render_frame_host( | |
293 dest_render_frame_host); | |
302 } | 294 } |
303 DCHECK(!transfer_navigation_handle_); | |
304 | 295 |
305 return dest_render_frame_host; | 296 return dest_render_frame_host; |
306 } | 297 } |
307 | 298 |
308 void RenderFrameHostManager::Stop() { | 299 void RenderFrameHostManager::Stop() { |
309 render_frame_host_->Stop(); | 300 render_frame_host_->Stop(); |
310 | 301 |
311 // If a cross-process navigation is happening, the pending RenderFrameHost | 302 // If a cross-process navigation is happening, the pending RenderFrameHost |
312 // should stop. This will lead to a DidFailProvisionalLoad, which will | 303 // should stop. This will lead to a DidFailProvisionalLoad, which will |
313 // properly destroy it. | 304 // properly destroy it. |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
415 | 406 |
416 // This is not a cross-process navigation; the tab is being closed. | 407 // This is not a cross-process navigation; the tab is being closed. |
417 render_frame_host_->render_view_host()->ClosePage(); | 408 render_frame_host_->render_view_host()->ClosePage(); |
418 } | 409 } |
419 } | 410 } |
420 } | 411 } |
421 | 412 |
422 void RenderFrameHostManager::OnCrossSiteResponse( | 413 void RenderFrameHostManager::OnCrossSiteResponse( |
423 RenderFrameHostImpl* transferring_render_frame_host, | 414 RenderFrameHostImpl* transferring_render_frame_host, |
424 const GlobalRequestID& global_request_id, | 415 const GlobalRequestID& global_request_id, |
425 std::unique_ptr<CrossSiteTransferringRequest> | |
426 cross_site_transferring_request, | |
427 const std::vector<GURL>& transfer_url_chain, | 416 const std::vector<GURL>& transfer_url_chain, |
428 const Referrer& referrer, | 417 const Referrer& referrer, |
429 ui::PageTransition page_transition, | 418 ui::PageTransition page_transition, |
430 bool should_replace_current_entry) { | 419 bool should_replace_current_entry) { |
431 // We should only get here for transfer navigations. Most cross-process | |
432 // navigations can just continue and wait to run the unload handler (by | |
433 // swapping out) when the new navigation commits. | |
434 CHECK(cross_site_transferring_request); | |
435 | |
436 // A transfer should only have come from our pending or current RFH. If it | 420 // A transfer should only have come from our pending or current RFH. If it |
437 // started as a cross-process navigation via OpenURL, this is the pending | 421 // started as a cross-process navigation via OpenURL, this is the pending |
438 // one. If it wasn't cross-process until the transfer, this is the current | 422 // one. If it wasn't cross-process until the transfer, this is the current |
439 // one. | 423 // one. |
440 // | 424 // |
441 // Note that having a pending RFH does not imply that it was the one that | 425 // Note that having a pending RFH does not imply that it was the one that |
442 // made the request. Suppose that during a pending cross-site navigation, | 426 // made the request. Suppose that during a pending cross-site navigation, |
443 // the frame performs a different same-site navigation which redirects | 427 // the frame performs a different same-site navigation which redirects |
444 // cross-site. In this case, there will be a pending RFH, but this request | 428 // cross-site. In this case, there will be a pending RFH, but this request |
445 // is made by the current RFH. Later, this will create a new pending RFH and | 429 // is made by the current RFH. Later, this will create a new pending RFH and |
446 // clean up the old one. | 430 // clean up the old one. |
447 // | 431 // |
448 // TODO(creis): We need to handle the case that the pending RFH has changed | 432 // TODO(creis): We need to handle the case that the pending RFH has changed |
449 // in the mean time, while this was being posted from the IO thread. We | 433 // in the mean time, while this was being posted from the IO thread. We |
450 // should probably cancel the request in that case. | 434 // should probably cancel the request in that case. |
451 DCHECK(transferring_render_frame_host == pending_render_frame_host_.get() || | 435 DCHECK(transferring_render_frame_host == pending_render_frame_host_.get() || |
452 transferring_render_frame_host == render_frame_host_.get()); | 436 transferring_render_frame_host == render_frame_host_.get()); |
453 | 437 |
454 // Check if the FrameTreeNode is loading. This will be used later to notify | 438 // Check if the FrameTreeNode is loading. This will be used later to notify |
455 // the FrameTreeNode that the load stop if the transfer fails. | 439 // the FrameTreeNode that the load stop if the transfer fails. |
456 bool frame_tree_node_was_loading = frame_tree_node_->IsLoading(); | 440 bool frame_tree_node_was_loading = frame_tree_node_->IsLoading(); |
457 | 441 |
458 // Store the NavigationHandle to give it to the appropriate RenderFrameHost | 442 // Store the NavigationHandle to give it to the appropriate RenderFrameHost |
459 // after it started navigating. | 443 // after it started navigating. |
460 transfer_navigation_handle_ = | 444 transfer_navigation_handle_ = |
461 transferring_render_frame_host->PassNavigationHandleOwnership(); | 445 transferring_render_frame_host->PassNavigationHandleOwnership(); |
462 | 446 CHECK(transfer_navigation_handle_); |
463 // If something caused the cancellation of this navigation on the UI thread | |
464 // (possibly for security reasons) the navigation should not be allowed to | |
465 // proceed. | |
466 if (!transfer_navigation_handle_) | |
467 return; | |
468 | |
469 // Store the transferring request so that we can release it if the transfer | |
470 // navigation matches. | |
471 cross_site_transferring_request_ = std::move(cross_site_transferring_request); | |
472 | 447 |
473 // Set the transferring RenderFrameHost as not loading, so that it does not | 448 // Set the transferring RenderFrameHost as not loading, so that it does not |
474 // emit a DidStopLoading notification if it is destroyed when creating the | 449 // emit a DidStopLoading notification if it is destroyed when creating the |
475 // new navigating RenderFrameHost. | 450 // new navigating RenderFrameHost. |
476 transferring_render_frame_host->set_is_loading(false); | 451 transferring_render_frame_host->set_is_loading(false); |
477 | 452 |
478 // Treat the last URL in the chain as the destination and the remainder as | 453 // Treat the last URL in the chain as the destination and the remainder as |
479 // the redirect chain. | 454 // the redirect chain. |
480 CHECK(transfer_url_chain.size()); | 455 CHECK(transfer_url_chain.size()); |
481 GURL transfer_url = transfer_url_chain.back(); | 456 GURL transfer_url = transfer_url_chain.back(); |
482 std::vector<GURL> rest_of_chain = transfer_url_chain; | 457 std::vector<GURL> rest_of_chain = transfer_url_chain; |
483 rest_of_chain.pop_back(); | 458 rest_of_chain.pop_back(); |
484 | 459 |
485 transferring_render_frame_host->frame_tree_node() | 460 transferring_render_frame_host->frame_tree_node() |
486 ->navigator() | 461 ->navigator() |
487 ->RequestTransferURL( | 462 ->RequestTransferURL( |
488 transferring_render_frame_host, transfer_url, nullptr, rest_of_chain, | 463 transferring_render_frame_host, transfer_url, nullptr, rest_of_chain, |
489 referrer, page_transition, global_request_id, | 464 referrer, page_transition, global_request_id, |
490 should_replace_current_entry, | 465 should_replace_current_entry, |
491 transfer_navigation_handle_->IsPost() ? "POST" : "GET", | 466 transfer_navigation_handle_->IsPost() ? "POST" : "GET", |
492 transfer_navigation_handle_->resource_request_body()); | 467 transfer_navigation_handle_->resource_request_body()); |
493 | 468 |
494 // The transferring request was only needed during the RequestTransferURL | |
495 // call, so it is safe to clear at this point. | |
496 cross_site_transferring_request_.reset(); | |
497 | |
498 // If the navigation continued, the NavigationHandle should have been | 469 // If the navigation continued, the NavigationHandle should have been |
499 // transfered to a RenderFrameHost. In the other cases, it should be cleared. | 470 // transfered to a RenderFrameHost. In the other cases, it should be cleared. |
471 // If the NavigationHandle wasn't claimed, this will lead to the cancelation | |
472 // of the request in the network stack. | |
500 transfer_navigation_handle_.reset(); | 473 transfer_navigation_handle_.reset(); |
501 | 474 |
502 // If the navigation in the new renderer did not start, inform the | 475 // If the navigation in the new renderer did not start, inform the |
503 // FrameTreeNode that it stopped loading. | 476 // FrameTreeNode that it stopped loading. |
504 if (!frame_tree_node_->IsLoading() && frame_tree_node_was_loading) | 477 if (!frame_tree_node_->IsLoading() && frame_tree_node_was_loading) |
505 frame_tree_node_->DidStopLoading(); | 478 frame_tree_node_->DidStopLoading(); |
506 } | 479 } |
507 | 480 |
508 void RenderFrameHostManager::DidNavigateFrame( | 481 void RenderFrameHostManager::DidNavigateFrame( |
509 RenderFrameHostImpl* render_frame_host, | 482 RenderFrameHostImpl* render_frame_host, |
(...skipping 1723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2233 // Note: Do not add code here to determine whether the subframe should swap | 2206 // Note: Do not add code here to determine whether the subframe should swap |
2234 // or not. Add it to CanSubframeSwapProcess instead. | 2207 // or not. Add it to CanSubframeSwapProcess instead. |
2235 return render_frame_host_.get(); | 2208 return render_frame_host_.get(); |
2236 } | 2209 } |
2237 | 2210 |
2238 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); | 2211 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); |
2239 scoped_refptr<SiteInstance> new_instance = GetSiteInstanceForNavigation( | 2212 scoped_refptr<SiteInstance> new_instance = GetSiteInstanceForNavigation( |
2240 dest_url, source_instance, dest_instance, nullptr, transition, | 2213 dest_url, source_instance, dest_instance, nullptr, transition, |
2241 dest_is_restore, dest_is_view_source_mode); | 2214 dest_is_restore, dest_is_view_source_mode); |
2242 | 2215 |
2216 // Inform the transferring NavigationHandle of a transfer to a different | |
2217 // SiteInstance. It is important do so now, in order to mark the request as | |
2218 // transferring on the IO thread before attempting to destroy the pending RFH. | |
2219 // This ensures the network request will not be destroyed along the pending | |
2220 // RFH but will presist until it is picked up by the new RFH. | |
Charlie Reis
2016/09/21 03:31:47
nit: persist
clamy
2016/09/21 15:04:06
Done.
| |
2221 if (transfer_navigation_handle_.get() && | |
2222 transfer_navigation_handle_->request_id() == transferred_request_id && | |
2223 new_instance->GetId() != | |
Charlie Reis
2016/09/21 03:31:47
It should be safe to compare the SiteInstances dir
clamy
2016/09/21 15:04:06
Done.
| |
2224 transfer_navigation_handle_->GetRenderFrameHost() | |
2225 ->GetSiteInstance() | |
2226 ->GetId()) { | |
2227 transfer_navigation_handle_->Transfer(); | |
2228 } | |
2229 | |
2243 // If we are currently navigating cross-process to a pending RFH for a | 2230 // If we are currently navigating cross-process to a pending RFH for a |
2244 // different SiteInstance, we want to get back to normal and then navigate as | 2231 // different SiteInstance, we want to get back to normal and then navigate as |
2245 // usual. We will reuse the pending RFH below if it matches the destination | 2232 // usual. We will reuse the pending RFH below if it matches the destination |
2246 // SiteInstance. | 2233 // SiteInstance. |
2247 if (pending_render_frame_host_) { | 2234 if (pending_render_frame_host_) { |
2248 if (pending_render_frame_host_->GetSiteInstance() != new_instance) { | 2235 if (pending_render_frame_host_->GetSiteInstance() != new_instance) { |
2249 CancelPending(); | 2236 CancelPending(); |
2250 } else { | 2237 } else { |
2251 // When a pending RFH is reused, it should always be live, since it is | 2238 // When a pending RFH is reused, it should always be live, since it is |
2252 // cleared whenever a process dies. | 2239 // cleared whenever a process dies. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2292 // RFH isn't live.) | 2279 // RFH isn't live.) |
2293 CommitPending(); | 2280 CommitPending(); |
2294 return render_frame_host_.get(); | 2281 return render_frame_host_.get(); |
2295 } | 2282 } |
2296 // Otherwise, it's safe to treat this as a pending cross-process transition. | 2283 // Otherwise, it's safe to treat this as a pending cross-process transition. |
2297 | 2284 |
2298 bool is_transfer = transferred_request_id != GlobalRequestID(); | 2285 bool is_transfer = transferred_request_id != GlobalRequestID(); |
2299 if (is_transfer) { | 2286 if (is_transfer) { |
2300 // We don't need to stop the old renderer or run beforeunload/unload | 2287 // We don't need to stop the old renderer or run beforeunload/unload |
2301 // handlers, because those have already been done. | 2288 // handlers, because those have already been done. |
2302 DCHECK(cross_site_transferring_request_->request_id() == | 2289 DCHECK(transfer_navigation_handle_ && |
2303 transferred_request_id); | 2290 transfer_navigation_handle_->request_id() == |
2291 transferred_request_id); | |
2304 } else if (!pending_render_frame_host_->are_navigations_suspended()) { | 2292 } else if (!pending_render_frame_host_->are_navigations_suspended()) { |
2305 // If the pending RFH hasn't already been suspended from a previous | 2293 // If the pending RFH hasn't already been suspended from a previous |
2306 // attempt to navigate it, then we need to wait for the beforeunload | 2294 // attempt to navigate it, then we need to wait for the beforeunload |
2307 // handler to run. Suspend navigations in the pending RFH until we hear | 2295 // handler to run. Suspend navigations in the pending RFH until we hear |
2308 // back from the old RFH's beforeunload handler (via OnBeforeUnloadACK or | 2296 // back from the old RFH's beforeunload handler (via OnBeforeUnloadACK or |
2309 // a timeout). If the handler returns false, we'll have to cancel the | 2297 // a timeout). If the handler returns false, we'll have to cancel the |
2310 // request. | 2298 // request. |
2311 // | 2299 // |
2312 // Also make sure the old RenderFrame stops, in case a load is in | 2300 // Also make sure the old RenderFrame stops, in case a load is in |
2313 // progress. (We don't want to do this for transfers, since it will | 2301 // progress. (We don't want to do this for transfers, since it will |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2678 resolved_url)) { | 2666 resolved_url)) { |
2679 DCHECK(!dest_instance || | 2667 DCHECK(!dest_instance || |
2680 dest_instance == render_frame_host_->GetSiteInstance()); | 2668 dest_instance == render_frame_host_->GetSiteInstance()); |
2681 return false; | 2669 return false; |
2682 } | 2670 } |
2683 | 2671 |
2684 return true; | 2672 return true; |
2685 } | 2673 } |
2686 | 2674 |
2687 } // namespace content | 2675 } // namespace content |
OLD | NEW |