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

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

Issue 208243019: Move SwapOut methods to RenderFrameHost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 9 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"
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 pending_nav_params_.reset(new PendingNavigationParams( 337 pending_nav_params_.reset(new PendingNavigationParams(
338 global_request_id, cross_site_transferring_request.Pass(), 338 global_request_id, cross_site_transferring_request.Pass(),
339 transfer_url_chain, referrer, page_transition, 339 transfer_url_chain, referrer, page_transition,
340 pending_render_frame_host->GetRoutingID(), 340 pending_render_frame_host->GetRoutingID(),
341 should_replace_current_entry)); 341 should_replace_current_entry));
342 342
343 // Run the unload handler of the current page. 343 // Run the unload handler of the current page.
344 SwapOutOldPage(); 344 SwapOutOldPage();
345 } 345 }
346 346
347 // TODO(creis): Remove this in favor of SwappedOutFrame. 347 void RenderFrameHostManager::SwappedOut(
348 void RenderFrameHostManager::SwappedOut(RenderViewHost* render_view_host) {
349 // Make sure this is from our current RVH, and that we have a pending
350 // navigation from OnCrossSiteResponse. (There may be no pending navigation
351 // for data URLs that don't make network requests, for example.) If not,
352 // just return early and ignore.
353 if (render_view_host != render_frame_host_->render_view_host() ||
354 !pending_nav_params_.get()) {
355 pending_nav_params_.reset();
356 return;
357 }
358
359 // Now that the unload handler has run, we need to either initiate the
360 // pending transfer (if there is one) or resume the paused response (if not).
361 // TODO(creis): The blank swapped out page is visible during this time, but
362 // we can shorten this by delivering the response directly, rather than
363 // forcing an identical request to be made.
364 if (pending_nav_params_->cross_site_transferring_request) {
365 // Treat the last URL in the chain as the destination and the remainder as
366 // the redirect chain.
367 CHECK(pending_nav_params_->transfer_url_chain.size());
368 GURL transfer_url = pending_nav_params_->transfer_url_chain.back();
369 pending_nav_params_->transfer_url_chain.pop_back();
370
371 // We use GetMainFrame here because this version of SwappedOut is only
372 // called for the main frame. We will remove it in favor of the frame
373 // specific version.
374 RenderFrameHostImpl* render_frame_host =
375 static_cast<RenderFrameHostImpl*>(render_view_host->GetMainFrame());
376
377 // We don't know whether the original request had |user_action| set to true.
378 // However, since we force the navigation to be in the current tab, it
379 // doesn't matter.
380 render_frame_host->frame_tree_node()->navigator()->RequestTransferURL(
381 render_frame_host,
382 transfer_url,
383 pending_nav_params_->transfer_url_chain,
384 pending_nav_params_->referrer,
385 pending_nav_params_->page_transition,
386 CURRENT_TAB,
387 pending_nav_params_->global_request_id,
388 pending_nav_params_->should_replace_current_entry,
389 true);
390 } else if (pending_render_frame_host_) {
391 RenderProcessHostImpl* pending_process =
392 static_cast<RenderProcessHostImpl*>(
393 pending_render_frame_host_->GetProcess());
394 pending_process->ResumeDeferredNavigation(
395 pending_nav_params_->global_request_id);
396 }
397 pending_nav_params_.reset();
398 }
399
400 void RenderFrameHostManager::SwappedOutFrame(
401 RenderFrameHostImpl* render_frame_host) { 348 RenderFrameHostImpl* render_frame_host) {
402 // Make sure this is from our current RFH, and that we have a pending 349 // Make sure this is from our current RFH, and that we have a pending
403 // navigation from OnCrossSiteResponse. (There may be no pending navigation 350 // navigation from OnCrossSiteResponse. (There may be no pending navigation
404 // for data URLs that don't make network requests, for example.) If not, 351 // for data URLs that don't make network requests, for example.) If not,
405 // just return early and ignore. 352 // just return early and ignore.
406 if (render_frame_host != render_frame_host_ || !pending_nav_params_.get()) { 353 if (render_frame_host != render_frame_host_ || !pending_nav_params_.get()) {
407 pending_nav_params_.reset(); 354 pending_nav_params_.reset();
408 return; 355 return;
409 } 356 }
410 357
411 // Sanity check that this is for the correct frame.
412 DCHECK_EQ(render_frame_host_->GetRoutingID(),
413 pending_nav_params_->render_frame_id);
414 DCHECK_EQ(render_frame_host_->GetProcess()->GetID(),
415 pending_nav_params_->global_request_id.child_id);
416
417 // Now that the unload handler has run, we need to either initiate the 358 // Now that the unload handler has run, we need to either initiate the
418 // pending transfer (if there is one) or resume the paused response (if not). 359 // pending transfer (if there is one) or resume the paused response (if not).
419 // TODO(creis): The blank swapped out page is visible during this time, but 360 // TODO(creis): The blank swapped out page is visible during this time, but
420 // we can shorten this by delivering the response directly, rather than 361 // we can shorten this by delivering the response directly, rather than
421 // forcing an identical request to be made. 362 // forcing an identical request to be made.
422 if (pending_nav_params_->cross_site_transferring_request) { 363 if (pending_nav_params_->cross_site_transferring_request) {
364 // Sanity check that this is for the correct frame.
365 DCHECK_EQ(render_frame_host_->GetRoutingID(),
366 pending_nav_params_->render_frame_id);
367 DCHECK_EQ(render_frame_host_->GetProcess()->GetID(),
368 pending_nav_params_->global_request_id.child_id);
369
423 // Treat the last URL in the chain as the destination and the remainder as 370 // Treat the last URL in the chain as the destination and the remainder as
424 // the redirect chain. 371 // the redirect chain.
425 CHECK(pending_nav_params_->transfer_url_chain.size()); 372 CHECK(pending_nav_params_->transfer_url_chain.size());
426 GURL transfer_url = pending_nav_params_->transfer_url_chain.back(); 373 GURL transfer_url = pending_nav_params_->transfer_url_chain.back();
427 pending_nav_params_->transfer_url_chain.pop_back(); 374 pending_nav_params_->transfer_url_chain.pop_back();
428 375
429 // We don't know whether the original request had |user_action| set to true. 376 // We don't know whether the original request had |user_action| set to true.
430 // However, since we force the navigation to be in the current tab, it 377 // However, since we force the navigation to be in the current tab, it
431 // doesn't matter. 378 // doesn't matter.
432 render_frame_host_->frame_tree_node()->navigator()->RequestTransferURL( 379 render_frame_host->frame_tree_node()->navigator()->RequestTransferURL(
433 render_frame_host, 380 render_frame_host,
434 transfer_url, 381 transfer_url,
435 pending_nav_params_->transfer_url_chain, 382 pending_nav_params_->transfer_url_chain,
436 pending_nav_params_->referrer, 383 pending_nav_params_->referrer,
437 pending_nav_params_->page_transition, 384 pending_nav_params_->page_transition,
438 CURRENT_TAB, 385 CURRENT_TAB,
439 pending_nav_params_->global_request_id, 386 pending_nav_params_->global_request_id,
440 false, 387 pending_nav_params_->should_replace_current_entry,
441 true); 388 true);
442 } else if (pending_render_frame_host_) { 389 } else if (pending_render_frame_host_) {
443 RenderProcessHostImpl* pending_process = 390 RenderProcessHostImpl* pending_process =
444 static_cast<RenderProcessHostImpl*>( 391 static_cast<RenderProcessHostImpl*>(
445 pending_render_frame_host_->GetProcess()); 392 pending_render_frame_host_->GetProcess());
446 pending_process->ResumeDeferredNavigation( 393 pending_process->ResumeDeferredNavigation(
447 pending_nav_params_->global_request_id); 394 pending_nav_params_->global_request_id);
448 } 395 }
449 pending_nav_params_.reset(); 396 pending_nav_params_.reset();
450 } 397 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 } 465 }
519 } 466 }
520 467
521 void RenderFrameHostManager::SwapOutOldPage() { 468 void RenderFrameHostManager::SwapOutOldPage() {
522 // Should only see this while we have a pending renderer or transfer. 469 // Should only see this while we have a pending renderer or transfer.
523 CHECK(cross_navigation_pending_ || pending_nav_params_.get()); 470 CHECK(cross_navigation_pending_ || pending_nav_params_.get());
524 471
525 // Tell the renderer to suppress any further modal dialogs so that we can swap 472 // Tell the renderer to suppress any further modal dialogs so that we can swap
526 // it out. This must be done before canceling any current dialog, in case 473 // it out. This must be done before canceling any current dialog, in case
527 // there is a loop creating additional dialogs. 474 // there is a loop creating additional dialogs.
475 // TODO(creis): Handle modal dialogs in subframe processes.
528 render_frame_host_->render_view_host()->SuppressDialogsUntilSwapOut(); 476 render_frame_host_->render_view_host()->SuppressDialogsUntilSwapOut();
529 477
530 // Now close any modal dialogs that would prevent us from swapping out. This 478 // Now close any modal dialogs that would prevent us from swapping out. This
531 // must be done separately from SwapOut, so that the PageGroupLoadDeferrer is 479 // must be done separately from SwapOut, so that the PageGroupLoadDeferrer is
532 // no longer on the stack when we send the SwapOut message. 480 // no longer on the stack when we send the SwapOut message.
533 delegate_->CancelModalDialogsForRenderManager(); 481 delegate_->CancelModalDialogsForRenderManager();
534 482
535 // Tell the old renderer it is being swapped out. This will fire the unload 483 if (!frame_tree_node_->IsMainFrame()) {
536 // handler (without firing the beforeunload handler a second time). When the
537 // unload handler finishes and the navigation completes, we will send a
538 // message to the ResourceDispatcherHost, allowing the pending RVH's response
539 // to resume.
540 // Note: This must be done on the RFH or else we'll swap out the top-level
541 // page when subframes navigate.
542 if (frame_tree_node_->IsMainFrame()) {
543 render_frame_host_->render_view_host()->SwapOut();
544 } else {
545 // The RenderFrameHost being swapped out becomes the proxy for this 484 // The RenderFrameHost being swapped out becomes the proxy for this
546 // frame in its parent's process. CrossProcessFrameConnector 485 // frame in its parent's process. CrossProcessFrameConnector
547 // initialization only needs to happen on an initial cross-process 486 // initialization only needs to happen on an initial cross-process
548 // navigation, when the RenderFrame leaves the same process as its parent. 487 // navigation, when the RenderFrame leaves the same process as its parent.
549 // The same CrossProcessFrameConnector is used for subsequent cross- 488 // The same CrossProcessFrameConnector is used for subsequent cross-
550 // process navigations, but it will be destroyed if the Frame is 489 // process navigations, but it will be destroyed if the Frame is
551 // navigated back to the same site instance as its parent. 490 // navigated back to the same site instance as its parent.
552 // TODO(kenrb): This will change when RenderFrameProxyHost is created. 491 // TODO(kenrb): This will change when RenderFrameProxyHost is created.
553 if (!cross_process_frame_connector_) { 492 if (!cross_process_frame_connector_) {
554 cross_process_frame_connector_ = 493 cross_process_frame_connector_ =
555 new CrossProcessFrameConnector(render_frame_host_.get()); 494 new CrossProcessFrameConnector(render_frame_host_.get());
556 } 495 }
557 render_frame_host_->SwapOut();
558 } 496 }
559 497
498 // Tell the old frame it is being swapped out. This will fire the unload
499 // handler in the background (without firing the beforeunload handler a second
500 // time). When the navigation completes, we will send a message to the
501 // ResourceDispatcherHost, allowing the pending RVH's response to resume.
502 render_frame_host_->SwapOut();
503
560 // ResourceDispatcherHost has told us to run the onunload handler, which 504 // ResourceDispatcherHost has told us to run the onunload handler, which
561 // means it is not a download or unsafe page, and we are going to perform the 505 // means it is not a download or unsafe page, and we are going to perform the
562 // navigation. Thus, we no longer need to remember that the RenderFrameHost 506 // navigation. Thus, we no longer need to remember that the RenderFrameHost
563 // is part of a pending cross-site request. 507 // is part of a pending cross-site request.
564 if (pending_render_frame_host_) { 508 if (pending_render_frame_host_) {
565 pending_render_frame_host_->render_view_host()-> 509 pending_render_frame_host_->render_view_host()->
566 SetHasPendingCrossSiteRequest(false); 510 SetHasPendingCrossSiteRequest(false);
567 } 511 }
568 } 512 }
569 513
(...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after
1376 pending_render_frame_host->GetProcess()->RemovePendingView(); 1320 pending_render_frame_host->GetProcess()->RemovePendingView();
1377 1321
1378 // The pending RFH may already be on the swapped out list if we started to 1322 // The pending RFH may already be on the swapped out list if we started to
1379 // swap it back in and then canceled. If so, make sure it gets swapped out 1323 // swap it back in and then canceled. If so, make sure it gets swapped out
1380 // again. If it's not on the swapped out list (e.g., aborting a pending 1324 // again. If it's not on the swapped out list (e.g., aborting a pending
1381 // load), then it's safe to shut down. 1325 // load), then it's safe to shut down.
1382 if (IsOnSwappedOutList(pending_render_frame_host)) { 1326 if (IsOnSwappedOutList(pending_render_frame_host)) {
1383 // Any currently suspended navigations are no longer needed. 1327 // Any currently suspended navigations are no longer needed.
1384 pending_render_frame_host->render_view_host()->CancelSuspendedNavigations(); 1328 pending_render_frame_host->render_view_host()->CancelSuspendedNavigations();
1385 1329
1386 // TODO(creis): We need to swap out the RFH. 1330 pending_render_frame_host->SwapOut();
1387 pending_render_frame_host->render_view_host()->SwapOut();
1388 } else { 1331 } else {
1389 // We won't be coming back, so shut this one down. 1332 // We won't be coming back, so shut this one down.
1390 delete pending_render_frame_host; 1333 delete pending_render_frame_host;
1391 } 1334 }
1392 1335
1393 pending_web_ui_.reset(); 1336 pending_web_ui_.reset();
1394 pending_and_current_web_ui_.reset(); 1337 pending_and_current_web_ui_.reset();
1395 } 1338 }
1396 1339
1397 void RenderFrameHostManager::RenderViewDeleted(RenderViewHost* rvh) { 1340 void RenderFrameHostManager::RenderViewDeleted(RenderViewHost* rvh) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1459 SiteInstance* instance) const { 1402 SiteInstance* instance) const {
1460 RenderFrameHostMap::const_iterator iter = 1403 RenderFrameHostMap::const_iterator iter =
1461 swapped_out_hosts_.find(instance->GetId()); 1404 swapped_out_hosts_.find(instance->GetId());
1462 if (iter != swapped_out_hosts_.end()) 1405 if (iter != swapped_out_hosts_.end())
1463 return iter->second; 1406 return iter->second;
1464 1407
1465 return NULL; 1408 return NULL;
1466 } 1409 }
1467 1410
1468 } // namespace content 1411 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698