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

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: Fixes based on Albert's comments and added explicit test for adding/removing frames using JavaScrip… 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());
245
246 for (RenderViewHostMap::iterator iter = swapped_out_hosts_.begin();
247 iter != swapped_out_hosts_.end();
248 ++iter) {
249 DCHECK(iter->second->GetSiteInstance() !=
250 current_host()->GetSiteInstance());
251
252 iter->second->UpdateFrameTree(
253 render_view_host->GetProcess()->GetID(),
254 render_view_host->GetRoutingID(),
255 render_view_host->GetFrameTree());
256 }
257 }
258
242 void RenderViewHostManager::SetWebUIPostCommit(WebUIImpl* web_ui) { 259 void RenderViewHostManager::SetWebUIPostCommit(WebUIImpl* web_ui) {
243 DCHECK(!web_ui_.get()); 260 DCHECK(!web_ui_.get());
244 web_ui_.reset(web_ui); 261 web_ui_.reset(web_ui);
245 } 262 }
246 263
247 void RenderViewHostManager::RendererAbortedProvisionalLoad( 264 void RenderViewHostManager::RendererAbortedProvisionalLoad(
248 RenderViewHost* render_view_host) { 265 RenderViewHost* render_view_host) {
249 // We used to cancel the pending renderer here for cross-site downloads. 266 // 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 267 // 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 268 // 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)) 505 if (curr_site_instance->HasWrongProcessForURL(dest_url))
489 return curr_site_instance->GetRelatedSiteInstance(dest_url); 506 return curr_site_instance->GetRelatedSiteInstance(dest_url);
490 507
491 // View-source URLs must use a new SiteInstance and BrowsingInstance. 508 // View-source URLs must use a new SiteInstance and BrowsingInstance.
492 // TODO(nasko): This is the same condition as later in the function. This 509 // 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 510 // should be taken into account when refactoring this method as part of
494 // http://crbug.com/123007. 511 // http://crbug.com/123007.
495 if (entry.IsViewSourceMode()) 512 if (entry.IsViewSourceMode())
496 return SiteInstance::CreateForURL(browser_context, dest_url); 513 return SiteInstance::CreateForURL(browser_context, dest_url);
497 514
515 // If we are navigating from blank SiteInstance to WebUI, make sure we
516 // create a new one.
517 const WebUIControllerFactory* web_ui_factory =
518 content::GetContentClient()->browser()->GetWebUIControllerFactory();
519 if (web_ui_factory &&
520 web_ui_factory->UseWebUIForURL(browser_context, dest_url))
521 return SiteInstance::CreateForURL(browser_context, dest_url);
522
498 // Normally the "site" on the SiteInstance is set lazily when the load 523 // Normally the "site" on the SiteInstance is set lazily when the load
499 // actually commits. This is to support better process sharing in case 524 // 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 525 // the site redirects to some other site: we want to use the destination
501 // site in the site instance. 526 // site in the site instance.
502 // 527 //
503 // In the case of session restore, as it loads all the pages immediately 528 // 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 529 // we need to set the site first, otherwise after a restore none of the
505 // pages would share renderers in process-per-site. 530 // pages would share renderers in process-per-site.
506 if (entry.restore_type() != NavigationEntryImpl::RESTORE_NONE) 531 if (entry.restore_type() != NavigationEntryImpl::RESTORE_NONE)
507 curr_site_instance->SetSite(dest_url); 532 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); 595 return curr_instance->GetRelatedSiteInstance(dest_url);
571 } 596 }
572 } 597 }
573 598
574 int RenderViewHostManager::CreateRenderView( 599 int RenderViewHostManager::CreateRenderView(
575 SiteInstance* instance, 600 SiteInstance* instance,
576 int opener_route_id, 601 int opener_route_id,
577 bool swapped_out) { 602 bool swapped_out) {
578 CHECK(instance); 603 CHECK(instance);
579 604
605 // If the current host is already in the site instance we are looking for
606 // and we are creating a swapped out renderer, just return the routing id.
607 if (current_host()->GetSiteInstance() == instance) {
608 // TODO(nasko): Convert this if statement to a DCHECK once all causes
609 // of creating a new non-swapped out RVH for the same SiteInstance as the
610 // active one are tracked down and resolved.
611 if (swapped_out) {
612 return current_host()->GetRoutingID();
613 }
614 }
615
580 // Check if we've already created an RVH for this SiteInstance. If so, try 616 // 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 617 // 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. 618 // remove it from the list of swapped out hosts if it commits.
583 RenderViewHostImpl* new_render_view_host = static_cast<RenderViewHostImpl*>( 619 RenderViewHostImpl* new_render_view_host = static_cast<RenderViewHostImpl*>(
584 GetSwappedOutRenderViewHost(instance)); 620 GetSwappedOutRenderViewHost(instance));
585 if (new_render_view_host) { 621 if (new_render_view_host) {
586 // Prevent the process from exiting while we're trying to use it. 622 // Prevent the process from exiting while we're trying to use it.
587 if (!swapped_out) 623 if (!swapped_out)
588 new_render_view_host->GetProcess()->AddPendingView(); 624 new_render_view_host->GetProcess()->AddPendingView();
589 } else { 625 } else {
(...skipping 10 matching lines...) Expand all
600 if (swapped_out) { 636 if (swapped_out) {
601 swapped_out_hosts_[instance->GetId()] = new_render_view_host; 637 swapped_out_hosts_[instance->GetId()] = new_render_view_host;
602 } else { 638 } else {
603 new_render_view_host->GetProcess()->AddPendingView(); 639 new_render_view_host->GetProcess()->AddPendingView();
604 } 640 }
605 641
606 bool success = InitRenderView(new_render_view_host, opener_route_id); 642 bool success = InitRenderView(new_render_view_host, opener_route_id);
607 if (success) { 643 if (success) {
608 // Don't show the view until we get a DidNavigate from it. 644 // Don't show the view until we get a DidNavigate from it.
609 new_render_view_host->GetView()->Hide(); 645 new_render_view_host->GetView()->Hide();
646
647 // If we are creating a swapped out RVH, send a message to update the
648 // frame tree based on the active RVH for this RenderViewHostManager.
649 if (swapped_out) {
650 new_render_view_host->UpdateFrameTree(
651 current_host()->GetProcess()->GetID(),
652 current_host()->GetRoutingID(),
653 current_host()->GetFrameTree());
654 }
610 } else if (!swapped_out) { 655 } else if (!swapped_out) {
611 CancelPending(); 656 CancelPending();
612 } 657 }
613 } 658 }
614 659
615 // Use this as our new pending RVH if it isn't swapped out. 660 // Use this as our new pending RVH if it isn't swapped out.
616 if (!swapped_out) 661 if (!swapped_out)
617 pending_render_view_host_ = new_render_view_host; 662 pending_render_view_host_ = new_render_view_host;
618 663
619 return new_render_view_host->GetRoutingID(); 664 return new_render_view_host->GetRoutingID();
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 } 966 }
922 967
923 RenderViewHost* RenderViewHostManager::GetSwappedOutRenderViewHost( 968 RenderViewHost* RenderViewHostManager::GetSwappedOutRenderViewHost(
924 SiteInstance* instance) { 969 SiteInstance* instance) {
925 RenderViewHostMap::iterator iter = swapped_out_hosts_.find(instance->GetId()); 970 RenderViewHostMap::iterator iter = swapped_out_hosts_.find(instance->GetId());
926 if (iter != swapped_out_hosts_.end()) 971 if (iter != swapped_out_hosts_.end())
927 return iter->second; 972 return iter->second;
928 973
929 return NULL; 974 return NULL;
930 } 975 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698