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

Side by Side Diff: content/browser/web_contents/render_view_host_manager.cc

Issue 10827078: Support frame tree propagation between renderers in the same browsing instance. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moved away from hardcoded strings and no static cast needed for tests. Created 8 years, 4 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/web_contents/render_view_host_manager.h" 5 #include "content/browser/web_contents/render_view_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/logging.h" 10 #include "base/logging.h"
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 // A navigation in the original page has taken place. Cancel the pending 232 // A navigation in the original page has taken place. Cancel the pending
233 // one. 233 // one.
234 CancelPending(); 234 CancelPending();
235 cross_navigation_pending_ = false; 235 cross_navigation_pending_ = false;
236 } else { 236 } else {
237 // No one else should be sending us DidNavigate in this state. 237 // No one else should be sending us DidNavigate in this state.
238 DCHECK(false); 238 DCHECK(false);
239 } 239 }
240 } 240 }
241 241
242 void RenderViewHostManager::DidUpdateFrameTree(
243 RenderViewHost* render_view_host) {
244 DCHECK(render_view_host == current_host());
awong 2012/08/21 19:27:28 DCHECK_EQ?
nasko 2012/08/21 22:24:13 Done.
245
246 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(render_view_host);
awong 2012/08/21 19:27:28 Shortenings like rvh aren't commonly used in this
nasko 2012/08/21 22:24:13 Done.
247 if (!rvh)
awong 2012/08/21 19:27:28 For parameter validation, do this as close to the
nasko 2012/08/21 22:24:13 Done.
248 return;
249
250 for (RenderViewHostMap::iterator iter = swapped_out_hosts_.begin();
251 iter != swapped_out_hosts_.end();
252 ++iter) {
253 DCHECK(iter->second->GetSiteInstance() !=
awong 2012/08/21 19:27:28 DCHECK_NE?
nasko 2012/08/21 22:24:13 Done.
254 current_host()->GetSiteInstance());
255
256 iter->second->UpdateFrameTree(
257 rvh->GetProcess()->GetID(), rvh->GetRoutingID(), rvh->frame_tree());
258 }
259 }
260
242 void RenderViewHostManager::SetWebUIPostCommit(WebUIImpl* web_ui) { 261 void RenderViewHostManager::SetWebUIPostCommit(WebUIImpl* web_ui) {
243 DCHECK(!web_ui_.get()); 262 DCHECK(!web_ui_.get());
244 web_ui_.reset(web_ui); 263 web_ui_.reset(web_ui);
245 } 264 }
246 265
247 void RenderViewHostManager::RendererAbortedProvisionalLoad( 266 void RenderViewHostManager::RendererAbortedProvisionalLoad(
248 RenderViewHost* render_view_host) { 267 RenderViewHost* render_view_host) {
249 // We used to cancel the pending renderer here for cross-site downloads. 268 // We used to cancel the pending renderer here for cross-site downloads.
250 // However, it's not safe to do that because the download logic repeatedly 269 // However, it's not safe to do that because the download logic repeatedly
251 // looks for this WebContents based on a render view ID. Instead, we just 270 // looks for this WebContents based on a render view ID. Instead, we just
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 if (curr_site_instance->HasWrongProcessForURL(dest_url)) 507 if (curr_site_instance->HasWrongProcessForURL(dest_url))
489 return curr_site_instance->GetRelatedSiteInstance(dest_url); 508 return curr_site_instance->GetRelatedSiteInstance(dest_url);
490 509
491 // View-source URLs must use a new SiteInstance and BrowsingInstance. 510 // View-source URLs must use a new SiteInstance and BrowsingInstance.
492 // TODO(nasko): This is the same condition as later in the function. This 511 // TODO(nasko): This is the same condition as later in the function. This
493 // should be taken into account when refactoring this method as part of 512 // should be taken into account when refactoring this method as part of
494 // http://crbug.com/123007. 513 // http://crbug.com/123007.
495 if (entry.IsViewSourceMode()) 514 if (entry.IsViewSourceMode())
496 return SiteInstance::CreateForURL(browser_context, dest_url); 515 return SiteInstance::CreateForURL(browser_context, dest_url);
497 516
517 // If we are navigating from blank SiteInstance to WebUI, make sure we
awong 2012/08/21 19:27:28 from blank -> from a blank to WebUI -> to a WebUI.
nasko 2012/08/21 22:24:13 Done.
518 // create a new one.
awong 2012/08/21 19:27:28 "new one" is ambiguous. "new SiteInstance" is clea
nasko 2012/08/21 22:24:13 Done.
519 const WebUIControllerFactory* web_ui_factory =
520 content::GetContentClient()->browser()->GetWebUIControllerFactory();
521 if (web_ui_factory &&
522 web_ui_factory->UseWebUIForURL(browser_context, dest_url))
awong 2012/08/21 19:27:28 Use braces around the body of a conditional that h
nasko 2012/08/21 22:24:13 Done.
523 return SiteInstance::CreateForURL(browser_context, dest_url);
524
498 // Normally the "site" on the SiteInstance is set lazily when the load 525 // Normally the "site" on the SiteInstance is set lazily when the load
499 // actually commits. This is to support better process sharing in case 526 // actually commits. This is to support better process sharing in case
500 // the site redirects to some other site: we want to use the destination 527 // the site redirects to some other site: we want to use the destination
501 // site in the site instance. 528 // site in the site instance.
502 // 529 //
503 // In the case of session restore, as it loads all the pages immediately 530 // In the case of session restore, as it loads all the pages immediately
504 // we need to set the site first, otherwise after a restore none of the 531 // we need to set the site first, otherwise after a restore none of the
505 // pages would share renderers in process-per-site. 532 // pages would share renderers in process-per-site.
506 if (entry.restore_type() != NavigationEntryImpl::RESTORE_NONE) 533 if (entry.restore_type() != NavigationEntryImpl::RESTORE_NONE)
507 curr_site_instance->SetSite(dest_url); 534 curr_site_instance->SetSite(dest_url);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 return curr_instance->GetRelatedSiteInstance(dest_url); 597 return curr_instance->GetRelatedSiteInstance(dest_url);
571 } 598 }
572 } 599 }
573 600
574 int RenderViewHostManager::CreateRenderView( 601 int RenderViewHostManager::CreateRenderView(
575 SiteInstance* instance, 602 SiteInstance* instance,
576 int opener_route_id, 603 int opener_route_id,
577 bool swapped_out) { 604 bool swapped_out) {
578 CHECK(instance); 605 CHECK(instance);
579 606
607 // If the current host is already in the site instance we are looking for
608 // and we are creating a swapped out renderer, just return the routing id.
609 if (current_host()->GetSiteInstance() == instance) {
610 // TODO(nasko): Convert this if statement to a DCHECK once all causes
611 // of creating a new non-swapped out RVH for the same SiteInstance as the
612 // active one are tracked down and resolved.
awong 2012/08/21 19:27:28 File a bug for this? Also, I can't tell how sever
nasko 2012/08/21 22:24:13 I'm not quite sure myself yet. I've hit almost 400
613 if (swapped_out) {
awong 2012/08/21 19:27:28 remove brace here :)
nasko 2012/08/21 22:24:13 Done.
614 return current_host()->GetRoutingID();
615 }
616 }
617
580 // Check if we've already created an RVH for this SiteInstance. If so, try 618 // Check if we've already created an RVH for this SiteInstance. If so, try
581 // to re-use the existing one, which has already been initialized. We'll 619 // to re-use the existing one, which has already been initialized. We'll
582 // remove it from the list of swapped out hosts if it commits. 620 // remove it from the list of swapped out hosts if it commits.
583 RenderViewHostImpl* new_render_view_host = static_cast<RenderViewHostImpl*>( 621 RenderViewHostImpl* new_render_view_host = static_cast<RenderViewHostImpl*>(
584 GetSwappedOutRenderViewHost(instance)); 622 GetSwappedOutRenderViewHost(instance));
585 if (new_render_view_host) { 623 if (new_render_view_host) {
586 // Prevent the process from exiting while we're trying to use it. 624 // Prevent the process from exiting while we're trying to use it.
587 if (!swapped_out) 625 if (!swapped_out)
588 new_render_view_host->GetProcess()->AddPendingView(); 626 new_render_view_host->GetProcess()->AddPendingView();
589 } else { 627 } else {
(...skipping 10 matching lines...) Expand all
600 if (swapped_out) { 638 if (swapped_out) {
601 swapped_out_hosts_[instance->GetId()] = new_render_view_host; 639 swapped_out_hosts_[instance->GetId()] = new_render_view_host;
602 } else { 640 } else {
603 new_render_view_host->GetProcess()->AddPendingView(); 641 new_render_view_host->GetProcess()->AddPendingView();
604 } 642 }
605 643
606 bool success = InitRenderView(new_render_view_host, opener_route_id); 644 bool success = InitRenderView(new_render_view_host, opener_route_id);
607 if (success) { 645 if (success) {
608 // Don't show the view until we get a DidNavigate from it. 646 // Don't show the view until we get a DidNavigate from it.
609 new_render_view_host->GetView()->Hide(); 647 new_render_view_host->GetView()->Hide();
648
649 // If we are creating a swapped out RVH, send a message to update the
650 // frame tree based on the active RVH for this RenderViewHostManager.
651 if (swapped_out) {
652 new_render_view_host->UpdateFrameTree(
653 current_host()->GetProcess()->GetID(),
654 current_host()->GetRoutingID(),
655 current_host()->frame_tree());
656 }
610 } else if (!swapped_out) { 657 } else if (!swapped_out) {
611 CancelPending(); 658 CancelPending();
612 } 659 }
613 } 660 }
614 661
615 // Use this as our new pending RVH if it isn't swapped out. 662 // Use this as our new pending RVH if it isn't swapped out.
616 if (!swapped_out) 663 if (!swapped_out)
617 pending_render_view_host_ = new_render_view_host; 664 pending_render_view_host_ = new_render_view_host;
618 665
619 return new_render_view_host->GetRoutingID(); 666 return new_render_view_host->GetRoutingID();
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 } 960 }
914 961
915 bool RenderViewHostManager::IsSwappedOut(RenderViewHost* rvh) { 962 bool RenderViewHostManager::IsSwappedOut(RenderViewHost* rvh) {
916 if (!rvh->GetSiteInstance()) 963 if (!rvh->GetSiteInstance())
917 return false; 964 return false;
918 965
919 return swapped_out_hosts_.find(rvh->GetSiteInstance()->GetId()) != 966 return swapped_out_hosts_.find(rvh->GetSiteInstance()->GetId()) !=
920 swapped_out_hosts_.end(); 967 swapped_out_hosts_.end();
921 } 968 }
922 969
923 RenderViewHost* RenderViewHostManager::GetSwappedOutRenderViewHost( 970 RenderViewHostImpl* RenderViewHostManager::GetSwappedOutRenderViewHost(
924 SiteInstance* instance) { 971 SiteInstance* instance) {
925 RenderViewHostMap::iterator iter = swapped_out_hosts_.find(instance->GetId()); 972 RenderViewHostMap::iterator iter = swapped_out_hosts_.find(instance->GetId());
926 if (iter != swapped_out_hosts_.end()) 973 if (iter != swapped_out_hosts_.end())
927 return iter->second; 974 return iter->second;
928 975
929 return NULL; 976 return NULL;
930 } 977 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698