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

Side by Side Diff: content/browser/frame_host/render_frame_host_manager.cc

Issue 143183009: When cross-site navigations are cancelled, delete the request being transferred (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: reupload, undo unneeded change Created 6 years, 10 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 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 <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "content/browser/child_process_security_policy_impl.h" 12 #include "content/browser/child_process_security_policy_impl.h"
13 #include "content/browser/devtools/render_view_devtools_agent_host.h" 13 #include "content/browser/devtools/render_view_devtools_agent_host.h"
14 #include "content/browser/frame_host/cross_process_frame_connector.h" 14 #include "content/browser/frame_host/cross_process_frame_connector.h"
15 #include "content/browser/frame_host/debug_urls.h" 15 #include "content/browser/frame_host/debug_urls.h"
16 #include "content/browser/frame_host/interstitial_page_impl.h" 16 #include "content/browser/frame_host/interstitial_page_impl.h"
17 #include "content/browser/frame_host/navigation_controller_impl.h" 17 #include "content/browser/frame_host/navigation_controller_impl.h"
18 #include "content/browser/frame_host/navigation_entry_impl.h" 18 #include "content/browser/frame_host/navigation_entry_impl.h"
19 #include "content/browser/frame_host/render_frame_host_factory.h" 19 #include "content/browser/frame_host/render_frame_host_factory.h"
20 #include "content/browser/frame_host/render_frame_host_impl.h" 20 #include "content/browser/frame_host/render_frame_host_impl.h"
21 #include "content/browser/renderer_host/cross_site_request_transfer.h"
21 #include "content/browser/renderer_host/render_process_host_impl.h" 22 #include "content/browser/renderer_host/render_process_host_impl.h"
22 #include "content/browser/renderer_host/render_view_host_factory.h" 23 #include "content/browser/renderer_host/render_view_host_factory.h"
23 #include "content/browser/renderer_host/render_view_host_impl.h" 24 #include "content/browser/renderer_host/render_view_host_impl.h"
24 #include "content/browser/site_instance_impl.h" 25 #include "content/browser/site_instance_impl.h"
25 #include "content/browser/webui/web_ui_controller_factory_registry.h" 26 #include "content/browser/webui/web_ui_controller_factory_registry.h"
26 #include "content/browser/webui/web_ui_impl.h" 27 #include "content/browser/webui/web_ui_impl.h"
27 #include "content/common/view_messages.h" 28 #include "content/common/view_messages.h"
28 #include "content/port/browser/render_widget_host_view_port.h" 29 #include "content/port/browser/render_widget_host_view_port.h"
29 #include "content/public/browser/content_browser_client.h" 30 #include "content/public/browser/content_browser_client.h"
30 #include "content/public/browser/notification_service.h" 31 #include "content/public/browser/notification_service.h"
31 #include "content/public/browser/notification_types.h" 32 #include "content/public/browser/notification_types.h"
32 #include "content/public/browser/render_widget_host_iterator.h" 33 #include "content/public/browser/render_widget_host_iterator.h"
33 #include "content/public/browser/user_metrics.h" 34 #include "content/public/browser/user_metrics.h"
34 #include "content/public/browser/web_ui_controller.h" 35 #include "content/public/browser/web_ui_controller.h"
35 #include "content/public/common/content_switches.h" 36 #include "content/public/common/content_switches.h"
36 #include "content/public/common/url_constants.h" 37 #include "content/public/common/url_constants.h"
37 38
38 namespace content { 39 namespace content {
39 40
40 RenderFrameHostManager::PendingNavigationParams::PendingNavigationParams()
41 : is_transfer(false), frame_id(-1), should_replace_current_entry(false) {
42 }
43
44 RenderFrameHostManager::PendingNavigationParams::PendingNavigationParams( 41 RenderFrameHostManager::PendingNavigationParams::PendingNavigationParams(
45 const GlobalRequestID& global_request_id, 42 const GlobalRequestID& global_request_id,
46 bool is_transfer, 43 scoped_ptr<CrossSiteRequestTransfer> cross_site_request_transfer,
47 const std::vector<GURL>& transfer_url_chain, 44 const std::vector<GURL>& transfer_url_chain,
48 Referrer referrer, 45 Referrer referrer,
49 PageTransition page_transition, 46 PageTransition page_transition,
50 int64 frame_id, 47 int64 frame_id,
51 bool should_replace_current_entry) 48 bool should_replace_current_entry)
52 : global_request_id(global_request_id), 49 : global_request_id(global_request_id),
53 is_transfer(is_transfer), 50 cross_site_request_transfer(cross_site_request_transfer.Pass()),
54 transfer_url_chain(transfer_url_chain), 51 transfer_url_chain(transfer_url_chain),
55 referrer(referrer), 52 referrer(referrer),
56 page_transition(page_transition), 53 page_transition(page_transition),
57 frame_id(frame_id), 54 frame_id(frame_id),
58 should_replace_current_entry(should_replace_current_entry) { 55 should_replace_current_entry(should_replace_current_entry) {
59 } 56 }
60 57
61 RenderFrameHostManager::PendingNavigationParams::~PendingNavigationParams() {} 58 RenderFrameHostManager::PendingNavigationParams::~PendingNavigationParams() {}
62 59
63 RenderFrameHostManager::RenderFrameHostManager( 60 RenderFrameHostManager::RenderFrameHostManager(
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 !pending_nav_params_.get()) { 269 !pending_nav_params_.get()) {
273 pending_nav_params_.reset(); 270 pending_nav_params_.reset();
274 return; 271 return;
275 } 272 }
276 273
277 // Now that the unload handler has run, we need to either initiate the 274 // Now that the unload handler has run, we need to either initiate the
278 // pending transfer (if there is one) or resume the paused response (if not). 275 // pending transfer (if there is one) or resume the paused response (if not).
279 // TODO(creis): The blank swapped out page is visible during this time, but 276 // TODO(creis): The blank swapped out page is visible during this time, but
280 // we can shorten this by delivering the response directly, rather than 277 // we can shorten this by delivering the response directly, rather than
281 // forcing an identical request to be made. 278 // forcing an identical request to be made.
282 if (pending_nav_params_->is_transfer) { 279 if (pending_nav_params_->cross_site_request_transfer) {
283 // Treat the last URL in the chain as the destination and the remainder as 280 // Treat the last URL in the chain as the destination and the remainder as
284 // the redirect chain. 281 // the redirect chain.
285 CHECK(pending_nav_params_->transfer_url_chain.size()); 282 CHECK(pending_nav_params_->transfer_url_chain.size());
286 GURL transfer_url = pending_nav_params_->transfer_url_chain.back(); 283 GURL transfer_url = pending_nav_params_->transfer_url_chain.back();
287 pending_nav_params_->transfer_url_chain.pop_back(); 284 pending_nav_params_->transfer_url_chain.pop_back();
288 285
289 // We don't know whether the original request had |user_action| set to true. 286 // We don't know whether the original request had |user_action| set to true.
290 // However, since we force the navigation to be in the current tab, it 287 // However, since we force the navigation to be in the current tab, it
291 // doesn't matter. 288 // doesn't matter.
292 render_view_host->GetDelegate()->RequestTransferURL( 289 render_view_host->GetDelegate()->RequestTransferURL(
(...skipping 28 matching lines...) Expand all
321 } 318 }
322 319
323 // Sanity check that this is for the correct frame. 320 // Sanity check that this is for the correct frame.
324 DCHECK_EQ(frame_tree_node_->frame_id(), pending_nav_params_->frame_id); 321 DCHECK_EQ(frame_tree_node_->frame_id(), pending_nav_params_->frame_id);
325 322
326 // Now that the unload handler has run, we need to either initiate the 323 // Now that the unload handler has run, we need to either initiate the
327 // pending transfer (if there is one) or resume the paused response (if not). 324 // pending transfer (if there is one) or resume the paused response (if not).
328 // TODO(creis): The blank swapped out page is visible during this time, but 325 // TODO(creis): The blank swapped out page is visible during this time, but
329 // we can shorten this by delivering the response directly, rather than 326 // we can shorten this by delivering the response directly, rather than
330 // forcing an identical request to be made. 327 // forcing an identical request to be made.
331 if (pending_nav_params_->is_transfer) { 328 if (pending_nav_params_->cross_site_request_transfer) {
332 // Treat the last URL in the chain as the destination and the remainder as 329 // Treat the last URL in the chain as the destination and the remainder as
333 // the redirect chain. 330 // the redirect chain.
334 CHECK(pending_nav_params_->transfer_url_chain.size()); 331 CHECK(pending_nav_params_->transfer_url_chain.size());
335 GURL transfer_url = pending_nav_params_->transfer_url_chain.back(); 332 GURL transfer_url = pending_nav_params_->transfer_url_chain.back();
336 pending_nav_params_->transfer_url_chain.pop_back(); 333 pending_nav_params_->transfer_url_chain.pop_back();
337 334
338 // We don't know whether the original request had |user_action| set to true. 335 // We don't know whether the original request had |user_action| set to true.
339 // However, since we force the navigation to be in the current tab, it 336 // However, since we force the navigation to be in the current tab, it
340 // doesn't matter. 337 // doesn't matter.
341 // TODO(creis): Move RequestTransferURL to RenderFrameHost's navigator. 338 // TODO(creis): Move RequestTransferURL to RenderFrameHost's navigator.
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 // This is not a cross-site navigation, the tab is being closed. 470 // This is not a cross-site navigation, the tab is being closed.
474 render_frame_host_->render_view_host()->ClosePage(); 471 render_frame_host_->render_view_host()->ClosePage();
475 } 472 }
476 } 473 }
477 } 474 }
478 475
479 // TODO(creis): Take in a RenderFrameHost from CSRH. 476 // TODO(creis): Take in a RenderFrameHost from CSRH.
480 void RenderFrameHostManager::OnCrossSiteResponse( 477 void RenderFrameHostManager::OnCrossSiteResponse(
481 RenderViewHost* pending_render_view_host, 478 RenderViewHost* pending_render_view_host,
482 const GlobalRequestID& global_request_id, 479 const GlobalRequestID& global_request_id,
483 bool is_transfer, 480 scoped_ptr<CrossSiteRequestTransfer> cross_site_request_transfer,
484 const std::vector<GURL>& transfer_url_chain, 481 const std::vector<GURL>& transfer_url_chain,
485 const Referrer& referrer, 482 const Referrer& referrer,
486 PageTransition page_transition, 483 PageTransition page_transition,
487 int64 frame_id, 484 int64 frame_id,
488 bool should_replace_current_entry) { 485 bool should_replace_current_entry) {
489 // This should be called either when the pending RVH is ready to commit or 486 // This should be called either when the pending RVH is ready to commit or
490 // when we realize that the current RVH's request requires a transfer. 487 // when we realize that the current RVH's request requires a transfer.
491 DCHECK(pending_render_view_host == render_frame_host_->render_view_host() || 488 DCHECK(pending_render_view_host == render_frame_host_->render_view_host() ||
492 pending_render_view_host == 489 pending_render_view_host ==
493 pending_render_frame_host_->render_view_host()); 490 pending_render_frame_host_->render_view_host());
494 491
495 // TODO(creis): Eventually we will want to check all navigation responses 492 // TODO(creis): Eventually we will want to check all navigation responses
496 // here, but currently we pass information for a transfer if 493 // here, but currently we pass information for a transfer if
497 // ShouldSwapProcessesForRedirect returned true in the network stack. 494 // ShouldSwapProcessesForRedirect returned true in the network stack.
498 // In that case, we should set up a transfer after the unload handler runs. 495 // In that case, we should set up a transfer after the unload handler runs.
499 // If is_transfer is false, we will just run the unload handler and resume. 496 // If |cross_site_request_transfer| is NULL, we will just run the unload
497 // handler and resume.
500 pending_nav_params_.reset(new PendingNavigationParams( 498 pending_nav_params_.reset(new PendingNavigationParams(
501 global_request_id, is_transfer, transfer_url_chain, referrer, 499 global_request_id, cross_site_request_transfer.Pass(), transfer_url_chain,
502 page_transition, frame_id, should_replace_current_entry)); 500 referrer, page_transition, frame_id, should_replace_current_entry));
503 501
504 // Run the unload handler of the current page. 502 // Run the unload handler of the current page.
505 SwapOutOldPage(); 503 SwapOutOldPage();
506 } 504 }
507 505
508 void RenderFrameHostManager::SwapOutOldPage() { 506 void RenderFrameHostManager::SwapOutOldPage() {
509 // Should only see this while we have a pending renderer or transfer. 507 // Should only see this while we have a pending renderer or transfer.
510 CHECK(cross_navigation_pending_ || pending_nav_params_.get()); 508 CHECK(cross_navigation_pending_ || pending_nav_params_.get());
511 509
512 // Tell the renderer to suppress any further modal dialogs so that we can swap 510 // Tell the renderer to suppress any further modal dialogs so that we can swap
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after
1215 ShouldSwapBrowsingInstancesForNavigation(current_entry, &entry); 1213 ShouldSwapBrowsingInstancesForNavigation(current_entry, &entry);
1216 if (!is_guest_scheme && (ShouldTransitionCrossSite() || force_swap)) 1214 if (!is_guest_scheme && (ShouldTransitionCrossSite() || force_swap))
1217 new_instance = GetSiteInstanceForEntry(entry, current_instance, force_swap); 1215 new_instance = GetSiteInstanceForEntry(entry, current_instance, force_swap);
1218 1216
1219 // If force_swap is true, we must use a different SiteInstance. If we didn't, 1217 // If force_swap is true, we must use a different SiteInstance. If we didn't,
1220 // we would have two RenderFrameHosts in the same SiteInstance and the same 1218 // we would have two RenderFrameHosts in the same SiteInstance and the same
1221 // frame, resulting in page_id conflicts for their NavigationEntries. 1219 // frame, resulting in page_id conflicts for their NavigationEntries.
1222 if (force_swap) 1220 if (force_swap)
1223 CHECK_NE(new_instance, current_instance); 1221 CHECK_NE(new_instance, current_instance);
1224 1222
1223 // If entry includes the request ID of a request that is being transferred,
1224 // either the old renderer is about to to reclaim it, or a new one is going
Charlie Reis 2014/02/13 22:12:19 nit: to to I'm not sure I follow this. Do you me
mmenke 2014/02/14 16:30:02 I mean the current_instance can take ownership - I
1225 // claim ownership, so release ownership of the request.
1226 if (pending_nav_params_ &&
1227 pending_nav_params_->global_request_id ==
1228 entry.transferred_global_request_id()) {
1229 pending_nav_params_->cross_site_request_transfer->ReleaseRequest();
1230 }
1231
1225 if (new_instance != current_instance) { 1232 if (new_instance != current_instance) {
1226 // New SiteInstance: create a pending RFH to navigate. 1233 // New SiteInstance: create a pending RFH to navigate.
1227 DCHECK(!cross_navigation_pending_); 1234 DCHECK(!cross_navigation_pending_);
1228 1235
1229 // This will possibly create (set to NULL) a Web UI object for the pending 1236 // This will possibly create (set to NULL) a Web UI object for the pending
1230 // page. We'll use this later to give the page special access. This must 1237 // page. We'll use this later to give the page special access. This must
1231 // happen before the new renderer is created below so it will get bindings. 1238 // happen before the new renderer is created below so it will get bindings.
1232 // It must also happen after the above conditional call to CancelPending(), 1239 // It must also happen after the above conditional call to CancelPending(),
1233 // otherwise CancelPending may clear the pending_web_ui_ and the page will 1240 // otherwise CancelPending may clear the pending_web_ui_ and the page will
1234 // not have its bindings set appropriately. 1241 // not have its bindings set appropriately.
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
1441 SiteInstance* instance) const { 1448 SiteInstance* instance) const {
1442 RenderFrameHostMap::const_iterator iter = 1449 RenderFrameHostMap::const_iterator iter =
1443 swapped_out_hosts_.find(instance->GetId()); 1450 swapped_out_hosts_.find(instance->GetId());
1444 if (iter != swapped_out_hosts_.end()) 1451 if (iter != swapped_out_hosts_.end())
1445 return iter->second; 1452 return iter->second;
1446 1453
1447 return NULL; 1454 return NULL;
1448 } 1455 }
1449 1456
1450 } // namespace content 1457 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698