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

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

Issue 109653014: Allow RenderFrames to swap out for subframe navigations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix an error during merge. Created 6 years, 11 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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 // in this case because it took too long. 249 // in this case because it took too long.
250 if (pending_render_frame_host_->render_view_host()-> 250 if (pending_render_frame_host_->render_view_host()->
251 are_navigations_suspended()) { 251 are_navigations_suspended()) {
252 pending_render_frame_host_->render_view_host()->SetNavigationsSuspended( 252 pending_render_frame_host_->render_view_host()->SetNavigationsSuspended(
253 false, base::TimeTicks::Now()); 253 false, base::TimeTicks::Now());
254 } 254 }
255 } 255 }
256 return false; 256 return false;
257 } 257 }
258 258
259 // TODO(creis): This should take in a RenderFrameHost. 259 // TODO(creis): Remove this in favor of SwappedOutFrame.
260 void RenderFrameHostManager::SwappedOut(RenderViewHost* render_view_host) { 260 void RenderFrameHostManager::SwappedOut(RenderViewHost* render_view_host) {
261 // Make sure this is from our current RVH, and that we have a pending 261 // Make sure this is from our current RVH, and that we have a pending
262 // navigation from OnCrossSiteResponse. (There may be no pending navigation 262 // navigation from OnCrossSiteResponse. (There may be no pending navigation
263 // for data URLs that don't make network requests, for example.) If not, 263 // for data URLs that don't make network requests, for example.) If not,
264 // just return early and ignore. 264 // just return early and ignore.
265 if (render_view_host != render_frame_host_->render_view_host() || 265 if (render_view_host != render_frame_host_->render_view_host() ||
266 !pending_nav_params_.get()) { 266 !pending_nav_params_.get()) {
267 pending_nav_params_.reset(); 267 pending_nav_params_.reset();
268 return; 268 return;
269 } 269 }
(...skipping 26 matching lines...) Expand all
296 } else if (pending_render_frame_host_) { 296 } else if (pending_render_frame_host_) {
297 RenderProcessHostImpl* pending_process = 297 RenderProcessHostImpl* pending_process =
298 static_cast<RenderProcessHostImpl*>( 298 static_cast<RenderProcessHostImpl*>(
299 pending_render_frame_host_->GetProcess()); 299 pending_render_frame_host_->GetProcess());
300 pending_process->ResumeDeferredNavigation( 300 pending_process->ResumeDeferredNavigation(
301 pending_nav_params_->global_request_id); 301 pending_nav_params_->global_request_id);
302 } 302 }
303 pending_nav_params_.reset(); 303 pending_nav_params_.reset();
304 } 304 }
305 305
306 void RenderFrameHostManager::SwappedOutFrame(
307 RenderFrameHostImpl* render_frame_host) {
308 // Make sure this is from our current RFH, and that we have a pending
309 // navigation from OnCrossSiteResponse. (There may be no pending navigation
310 // for data URLs that don't make network requests, for example.) If not,
311 // just return early and ignore.
312 if (render_frame_host != render_frame_host_ || !pending_nav_params_.get()) {
313 pending_nav_params_.reset();
314 return;
315 }
316
317 // Sanity check that this is for the correct frame.
318 DCHECK_EQ(frame_tree_node_->frame_id(), pending_nav_params_->frame_id);
319
320 // Now that the unload handler has run, we need to either initiate the
321 // pending transfer (if there is one) or resume the paused response (if not).
322 // TODO(creis): The blank swapped out page is visible during this time, but
323 // we can shorten this by delivering the response directly, rather than
324 // forcing an identical request to be made.
325 if (pending_nav_params_->is_transfer) {
326 // Treat the last URL in the chain as the destination and the remainder as
327 // the redirect chain.
328 CHECK(pending_nav_params_->transfer_url_chain.size());
329 GURL transfer_url = pending_nav_params_->transfer_url_chain.back();
330 pending_nav_params_->transfer_url_chain.pop_back();
331
332 // We don't know whether the original request had |user_action| set to true.
333 // However, since we force the navigation to be in the current tab, it
334 // doesn't matter.
335 // TODO(creis): Move RequestTransferURL to RenderFrameHost's navigator.
336 render_frame_host->render_view_host()->GetDelegate()->RequestTransferURL(
337 transfer_url,
338 pending_nav_params_->transfer_url_chain,
339 pending_nav_params_->referrer,
340 pending_nav_params_->page_transition,
341 CURRENT_TAB,
342 pending_nav_params_->frame_id,
343 pending_nav_params_->global_request_id,
344 false,
345 true);
346 } else if (pending_render_frame_host_) {
347 RenderProcessHostImpl* pending_process =
348 static_cast<RenderProcessHostImpl*>(
349 pending_render_frame_host_->GetProcess());
350 pending_process->ResumeDeferredNavigation(
351 pending_nav_params_->global_request_id);
352 }
353 pending_nav_params_.reset();
354 }
355
306 // TODO(creis): This should take in a RenderFrameHost. 356 // TODO(creis): This should take in a RenderFrameHost.
307 void RenderFrameHostManager::DidNavigateMainFrame( 357 void RenderFrameHostManager::DidNavigateMainFrame(
308 RenderViewHost* render_view_host) { 358 RenderViewHost* render_view_host) {
309 if (!cross_navigation_pending_) { 359 if (!cross_navigation_pending_) {
310 DCHECK(!pending_render_frame_host_); 360 DCHECK(!pending_render_frame_host_);
311 361
312 // We should only hear this from our current renderer. 362 // We should only hear this from our current renderer.
313 DCHECK(render_view_host == render_frame_host_->render_view_host()); 363 DCHECK(render_view_host == render_frame_host_->render_view_host());
314 364
315 // Even when there is no pending RVH, there may be a pending Web UI. 365 // Even when there is no pending RVH, there may be a pending Web UI.
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 // Now close any modal dialogs that would prevent us from swapping out. This 525 // Now close any modal dialogs that would prevent us from swapping out. This
476 // must be done separately from SwapOut, so that the PageGroupLoadDeferrer is 526 // must be done separately from SwapOut, so that the PageGroupLoadDeferrer is
477 // no longer on the stack when we send the SwapOut message. 527 // no longer on the stack when we send the SwapOut message.
478 delegate_->CancelModalDialogsForRenderManager(); 528 delegate_->CancelModalDialogsForRenderManager();
479 529
480 // Tell the old renderer it is being swapped out. This will fire the unload 530 // Tell the old renderer it is being swapped out. This will fire the unload
481 // handler (without firing the beforeunload handler a second time). When the 531 // handler (without firing the beforeunload handler a second time). When the
482 // unload handler finishes and the navigation completes, we will send a 532 // unload handler finishes and the navigation completes, we will send a
483 // message to the ResourceDispatcherHost, allowing the pending RVH's response 533 // message to the ResourceDispatcherHost, allowing the pending RVH's response
484 // to resume. 534 // to resume.
485 // TODO(creis): We should do this on the RFH or else we'll swap out the 535 // Note: This must be done on the RFH or else we'll swap out the top-level
486 // top-level page when subframes navigate. Until then, we skip swapping out 536 // page when subframes navigate.
487 // for subframes.
488 if (frame_tree_node_->IsMainFrame()) 537 if (frame_tree_node_->IsMainFrame())
489 render_frame_host_->render_view_host()->SwapOut(); 538 render_frame_host_->render_view_host()->SwapOut();
490 else 539 else
491 SwappedOut(render_frame_host_->render_view_host()); 540 render_frame_host_->SwapOut();
492 541
493 // ResourceDispatcherHost has told us to run the onunload handler, which 542 // ResourceDispatcherHost has told us to run the onunload handler, which
494 // means it is not a download or unsafe page, and we are going to perform the 543 // means it is not a download or unsafe page, and we are going to perform the
495 // navigation. Thus, we no longer need to remember that the RenderViewHost 544 // navigation. Thus, we no longer need to remember that the RenderFrameHost
496 // is part of a pending cross-site request. 545 // is part of a pending cross-site request.
497 if (pending_render_frame_host_) { 546 if (pending_render_frame_host_) {
498 pending_render_frame_host_->render_view_host()-> 547 pending_render_frame_host_->render_view_host()->
499 SetHasPendingCrossSiteRequest(false); 548 SetHasPendingCrossSiteRequest(false);
500 } 549 }
501 } 550 }
502 551
503 void RenderFrameHostManager::Observe( 552 void RenderFrameHostManager::Observe(
504 int type, 553 int type,
505 const NotificationSource& source, 554 const NotificationSource& source,
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 render_frame_host_->render_view_host()->GetView()->Show(); 998 render_frame_host_->render_view_host()->GetView()->Show();
950 } 999 }
951 1000
952 // If the old view is live and top-level, hide it now that the new one is 1001 // If the old view is live and top-level, hide it now that the new one is
953 // visible. 1002 // visible.
954 if (old_render_frame_host->render_view_host()->GetView()) { 1003 if (old_render_frame_host->render_view_host()->GetView()) {
955 if (is_main_frame) { 1004 if (is_main_frame) {
956 old_render_frame_host->render_view_host()->GetView()->Hide(); 1005 old_render_frame_host->render_view_host()->GetView()->Hide();
957 old_render_frame_host->render_view_host()->WasSwappedOut(); 1006 old_render_frame_host->render_view_host()->WasSwappedOut();
958 } else { 1007 } else {
959 // TODO(creis): Swap out the subframe. We'll need to swap it back in when 1008 // TODO(creis): We'll need to set this back to false if we navigate back.
960 // navigating back. 1009 old_render_frame_host->set_swapped_out(true);
961 } 1010 }
962 } 1011 }
963 1012
964 // Make sure the size is up to date. (Fix for bug 1079768.) 1013 // Make sure the size is up to date. (Fix for bug 1079768.)
965 delegate_->UpdateRenderViewSizeForRenderManager(); 1014 delegate_->UpdateRenderViewSizeForRenderManager();
966 1015
967 if (will_focus_location_bar) { 1016 if (will_focus_location_bar) {
968 delegate_->SetFocusToLocationBar(false); 1017 delegate_->SetFocusToLocationBar(false);
969 } else if (focus_render_view && 1018 } else if (focus_render_view &&
970 render_frame_host_->render_view_host()->GetView()) { 1019 render_frame_host_->render_view_host()->GetView()) {
(...skipping 13 matching lines...) Expand all
984 1033
985 // If the pending frame was on the swapped out list, we can remove it. 1034 // If the pending frame was on the swapped out list, we can remove it.
986 swapped_out_hosts_.erase(render_frame_host_->render_view_host()-> 1035 swapped_out_hosts_.erase(render_frame_host_->render_view_host()->
987 GetSiteInstance()->GetId()); 1036 GetSiteInstance()->GetId());
988 1037
989 if (old_render_frame_host->render_view_host()->IsRenderViewLive()) { 1038 if (old_render_frame_host->render_view_host()->IsRenderViewLive()) {
990 // If the old RFH is live, we are swapping it out and should keep track of 1039 // If the old RFH is live, we are swapping it out and should keep track of
991 // it in case we navigate back to it. 1040 // it in case we navigate back to it.
992 // TODO(creis): Swap out the subframe in --site-per-process. 1041 // TODO(creis): Swap out the subframe in --site-per-process.
993 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess)) 1042 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess))
994 DCHECK(old_render_frame_host->render_view_host()->is_swapped_out()); 1043 DCHECK(old_render_frame_host->is_swapped_out() ||
1044 old_render_frame_host->render_view_host()->is_swapped_out());
1045
995 // Temp fix for http://crbug.com/90867 until we do a better cleanup to make 1046 // Temp fix for http://crbug.com/90867 until we do a better cleanup to make
996 // sure we don't get different rvh instances for the same site instance 1047 // sure we don't get different rvh instances for the same site instance
997 // in the same rvhmgr. 1048 // in the same rvhmgr.
998 // TODO(creis): Clean this up. 1049 // TODO(creis): Clean this up.
999 int32 old_site_instance_id = 1050 int32 old_site_instance_id =
1000 old_render_frame_host->render_view_host()->GetSiteInstance()->GetId(); 1051 old_render_frame_host->render_view_host()->GetSiteInstance()->GetId();
1001 RenderFrameHostMap::iterator iter = 1052 RenderFrameHostMap::iterator iter =
1002 swapped_out_hosts_.find(old_site_instance_id); 1053 swapped_out_hosts_.find(old_site_instance_id);
1003 if (iter != swapped_out_hosts_.end() && 1054 if (iter != swapped_out_hosts_.end() &&
1004 iter->second != old_render_frame_host) { 1055 iter->second != old_render_frame_host) {
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
1310 SiteInstance* instance) const { 1361 SiteInstance* instance) const {
1311 RenderFrameHostMap::const_iterator iter = 1362 RenderFrameHostMap::const_iterator iter =
1312 swapped_out_hosts_.find(instance->GetId()); 1363 swapped_out_hosts_.find(instance->GetId());
1313 if (iter != swapped_out_hosts_.end()) 1364 if (iter != swapped_out_hosts_.end())
1314 return iter->second; 1365 return iter->second;
1315 1366
1316 return NULL; 1367 return NULL;
1317 } 1368 }
1318 1369
1319 } // namespace content 1370 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/render_frame_host_manager.h ('k') | content/browser/site_per_process_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698