| 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 <string> |
| 10 #include <utility> | 11 #include <utility> |
| 12 #include <vector> |
| 11 | 13 |
| 12 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 13 #include "base/debug/crash_logging.h" | 15 #include "base/debug/crash_logging.h" |
| 14 #include "base/debug/dump_without_crashing.h" | 16 #include "base/debug/dump_without_crashing.h" |
| 15 #include "base/logging.h" | 17 #include "base/logging.h" |
| 16 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
| 17 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
| 18 #include "base/trace_event/trace_event.h" | 20 #include "base/trace_event/trace_event.h" |
| 19 #include "content/browser/child_process_security_policy_impl.h" | 21 #include "content/browser/child_process_security_policy_impl.h" |
| 20 #include "content/browser/devtools/render_frame_devtools_agent_host.h" | 22 #include "content/browser/devtools/render_frame_devtools_agent_host.h" |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 // See https://crbug.com/462682. | 279 // See https://crbug.com/462682. |
| 278 delegate_->NotifyMainFrameSwappedFromRenderManager( | 280 delegate_->NotifyMainFrameSwappedFromRenderManager( |
| 279 nullptr, render_frame_host_->render_view_host()); | 281 nullptr, render_frame_host_->render_view_host()); |
| 280 } | 282 } |
| 281 } | 283 } |
| 282 | 284 |
| 283 // If entry includes the request ID of a request that is being transferred, | 285 // If entry includes the request ID of a request that is being transferred, |
| 284 // the destination render frame will take ownership, so release ownership of | 286 // the destination render frame will take ownership, so release ownership of |
| 285 // the transferring NavigationHandle. | 287 // the transferring NavigationHandle. |
| 286 if (transfer_navigation_handle_.get() && | 288 if (transfer_navigation_handle_.get() && |
| 287 transfer_navigation_handle_->request_id() == | 289 transfer_navigation_handle_->GetGlobalRequestID() == |
| 288 entry.transferred_global_request_id()) { | 290 entry.transferred_global_request_id()) { |
| 289 // The navigating RenderFrameHost should take ownership of the | 291 // The navigating RenderFrameHost should take ownership of the |
| 290 // NavigationHandle that came from the transferring RenderFrameHost. | 292 // NavigationHandle that came from the transferring RenderFrameHost. |
| 291 dest_render_frame_host->SetNavigationHandle( | 293 dest_render_frame_host->SetNavigationHandle( |
| 292 std::move(transfer_navigation_handle_)); | 294 std::move(transfer_navigation_handle_)); |
| 293 | 295 |
| 294 dest_render_frame_host->navigation_handle()->set_render_frame_host( | 296 dest_render_frame_host->navigation_handle()->set_render_frame_host( |
| 295 dest_render_frame_host); | 297 dest_render_frame_host); |
| 296 } | 298 } |
| 297 | 299 |
| (...skipping 1971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2269 scoped_refptr<SiteInstance> new_instance = GetSiteInstanceForNavigation( | 2271 scoped_refptr<SiteInstance> new_instance = GetSiteInstanceForNavigation( |
| 2270 dest_url, source_instance, dest_instance, nullptr, transition, | 2272 dest_url, source_instance, dest_instance, nullptr, transition, |
| 2271 dest_is_restore, dest_is_view_source_mode); | 2273 dest_is_restore, dest_is_view_source_mode); |
| 2272 | 2274 |
| 2273 // Inform the transferring NavigationHandle of a transfer to a different | 2275 // Inform the transferring NavigationHandle of a transfer to a different |
| 2274 // SiteInstance. It is important do so now, in order to mark the request as | 2276 // SiteInstance. It is important do so now, in order to mark the request as |
| 2275 // transferring on the IO thread before attempting to destroy the pending RFH. | 2277 // transferring on the IO thread before attempting to destroy the pending RFH. |
| 2276 // This ensures the network request will not be destroyed along the pending | 2278 // This ensures the network request will not be destroyed along the pending |
| 2277 // RFH but will persist until it is picked up by the new RFH. | 2279 // RFH but will persist until it is picked up by the new RFH. |
| 2278 if (transfer_navigation_handle_.get() && | 2280 if (transfer_navigation_handle_.get() && |
| 2279 transfer_navigation_handle_->request_id() == transferred_request_id && | 2281 transfer_navigation_handle_->GetGlobalRequestID() == |
| 2282 transferred_request_id && |
| 2280 new_instance.get() != | 2283 new_instance.get() != |
| 2281 transfer_navigation_handle_->GetRenderFrameHost() | 2284 transfer_navigation_handle_->GetRenderFrameHost() |
| 2282 ->GetSiteInstance()) { | 2285 ->GetSiteInstance()) { |
| 2283 transfer_navigation_handle_->Transfer(); | 2286 transfer_navigation_handle_->Transfer(); |
| 2284 } | 2287 } |
| 2285 | 2288 |
| 2286 // If we are currently navigating cross-process to a pending RFH for a | 2289 // If we are currently navigating cross-process to a pending RFH for a |
| 2287 // different SiteInstance, we want to get back to normal and then navigate as | 2290 // different SiteInstance, we want to get back to normal and then navigate as |
| 2288 // usual. We will reuse the pending RFH below if it matches the destination | 2291 // usual. We will reuse the pending RFH below if it matches the destination |
| 2289 // SiteInstance. | 2292 // SiteInstance. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2336 CommitPending(); | 2339 CommitPending(); |
| 2337 return render_frame_host_.get(); | 2340 return render_frame_host_.get(); |
| 2338 } | 2341 } |
| 2339 // Otherwise, it's safe to treat this as a pending cross-process transition. | 2342 // Otherwise, it's safe to treat this as a pending cross-process transition. |
| 2340 | 2343 |
| 2341 bool is_transfer = transferred_request_id != GlobalRequestID(); | 2344 bool is_transfer = transferred_request_id != GlobalRequestID(); |
| 2342 if (is_transfer) { | 2345 if (is_transfer) { |
| 2343 // We don't need to stop the old renderer or run beforeunload/unload | 2346 // We don't need to stop the old renderer or run beforeunload/unload |
| 2344 // handlers, because those have already been done. | 2347 // handlers, because those have already been done. |
| 2345 DCHECK(transfer_navigation_handle_ && | 2348 DCHECK(transfer_navigation_handle_ && |
| 2346 transfer_navigation_handle_->request_id() == | 2349 transfer_navigation_handle_->GetGlobalRequestID() == |
| 2347 transferred_request_id); | 2350 transferred_request_id); |
| 2348 } else if (!pending_render_frame_host_->are_navigations_suspended()) { | 2351 } else if (!pending_render_frame_host_->are_navigations_suspended()) { |
| 2349 // If the pending RFH hasn't already been suspended from a previous | 2352 // If the pending RFH hasn't already been suspended from a previous |
| 2350 // attempt to navigate it, then we need to wait for the beforeunload | 2353 // attempt to navigate it, then we need to wait for the beforeunload |
| 2351 // handler to run. Suspend navigations in the pending RFH until we hear | 2354 // handler to run. Suspend navigations in the pending RFH until we hear |
| 2352 // back from the old RFH's beforeunload handler (via OnBeforeUnloadACK or | 2355 // back from the old RFH's beforeunload handler (via OnBeforeUnloadACK or |
| 2353 // a timeout). If the handler returns false, we'll have to cancel the | 2356 // a timeout). If the handler returns false, we'll have to cancel the |
| 2354 // request. | 2357 // request. |
| 2355 // | 2358 // |
| 2356 // Also make sure the old RenderFrame stops, in case a load is in | 2359 // Also make sure the old RenderFrame stops, in case a load is in |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2463 if (old_render_frame_host) { | 2466 if (old_render_frame_host) { |
| 2464 old_render_frame_host->GetSiteInstance()-> | 2467 old_render_frame_host->GetSiteInstance()-> |
| 2465 DecrementRelatedActiveContentsCount(); | 2468 DecrementRelatedActiveContentsCount(); |
| 2466 } | 2469 } |
| 2467 } | 2470 } |
| 2468 | 2471 |
| 2469 return old_render_frame_host; | 2472 return old_render_frame_host; |
| 2470 } | 2473 } |
| 2471 | 2474 |
| 2472 RenderViewHostImpl* RenderFrameHostManager::GetSwappedOutRenderViewHost( | 2475 RenderViewHostImpl* RenderFrameHostManager::GetSwappedOutRenderViewHost( |
| 2473 SiteInstance* instance) const { | 2476 SiteInstance* instance) const { |
| 2474 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(instance); | 2477 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(instance); |
| 2475 if (proxy) | 2478 if (proxy) |
| 2476 return proxy->GetRenderViewHost(); | 2479 return proxy->GetRenderViewHost(); |
| 2477 return nullptr; | 2480 return nullptr; |
| 2478 } | 2481 } |
| 2479 | 2482 |
| 2480 RenderFrameProxyHost* RenderFrameHostManager::GetRenderFrameProxyHost( | 2483 RenderFrameProxyHost* RenderFrameHostManager::GetRenderFrameProxyHost( |
| 2481 SiteInstance* instance) const { | 2484 SiteInstance* instance) const { |
| 2482 auto it = proxy_hosts_.find(instance->GetId()); | 2485 auto it = proxy_hosts_.find(instance->GetId()); |
| 2483 if (it != proxy_hosts_.end()) | 2486 if (it != proxy_hosts_.end()) |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2722 resolved_url)) { | 2725 resolved_url)) { |
| 2723 DCHECK(!dest_instance || | 2726 DCHECK(!dest_instance || |
| 2724 dest_instance == render_frame_host_->GetSiteInstance()); | 2727 dest_instance == render_frame_host_->GetSiteInstance()); |
| 2725 return false; | 2728 return false; |
| 2726 } | 2729 } |
| 2727 | 2730 |
| 2728 return true; | 2731 return true; |
| 2729 } | 2732 } |
| 2730 | 2733 |
| 2731 } // namespace content | 2734 } // namespace content |
| OLD | NEW |