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

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

Issue 1519943002: Shortcut cross-process frame transfers to avoid pending NavigationEntries. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clean up Created 5 years 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
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/navigator_impl.h" 5 #include "content/browser/frame_host/navigator_impl.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "content/browser/frame_host/frame_tree.h" 10 #include "content/browser/frame_host/frame_tree.h"
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 GetSiteInstance(); 572 GetSiteInstance();
573 // If this came from a swapped out RenderFrameHost, we only allow the request 573 // If this came from a swapped out RenderFrameHost, we only allow the request
574 // if we are still in the same BrowsingInstance. 574 // if we are still in the same BrowsingInstance.
575 // TODO(creis): Move this to RenderFrameProxyHost::OpenURL. 575 // TODO(creis): Move this to RenderFrameProxyHost::OpenURL.
576 if (render_frame_host->is_swapped_out() && 576 if (render_frame_host->is_swapped_out() &&
577 !render_frame_host->GetSiteInstance()->IsRelatedSiteInstance( 577 !render_frame_host->GetSiteInstance()->IsRelatedSiteInstance(
578 current_site_instance)) { 578 current_site_instance)) {
579 return; 579 return;
580 } 580 }
581 581
582 // Delegate to RequestTransferURL because this is just the generic
583 // case where |old_request_id| is empty.
584 // TODO(creis): Pass the redirect_chain into this method to support client 582 // TODO(creis): Pass the redirect_chain into this method to support client
585 // redirects. http://crbug.com/311721. 583 // redirects. http://crbug.com/311721.
586 std::vector<GURL> redirect_chain; 584 std::vector<GURL> redirect_chain;
587 RequestTransferURL(render_frame_host, url, source_site_instance,
588 redirect_chain, referrer, ui::PAGE_TRANSITION_LINK,
589 disposition, GlobalRequestID(),
590 should_replace_current_entry, user_gesture);
591 }
592 585
593 void NavigatorImpl::RequestTransferURL(
594 RenderFrameHostImpl* render_frame_host,
595 const GURL& url,
596 SiteInstance* source_site_instance,
597 const std::vector<GURL>& redirect_chain,
598 const Referrer& referrer,
599 ui::PageTransition page_transition,
600 WindowOpenDisposition disposition,
601 const GlobalRequestID& transferred_global_request_id,
602 bool should_replace_current_entry,
603 bool user_gesture) {
604 GURL dest_url(url); 586 GURL dest_url(url);
605 RenderFrameHostImpl* current_render_frame_host =
606 GetRenderManager(render_frame_host)->current_frame_host();
607 SiteInstance* current_site_instance =
608 current_render_frame_host->GetSiteInstance();
609 if (!GetContentClient()->browser()->ShouldAllowOpenURL( 587 if (!GetContentClient()->browser()->ShouldAllowOpenURL(
610 current_site_instance, url)) { 588 current_site_instance, url)) {
611 dest_url = GURL(url::kAboutBlankURL); 589 dest_url = GURL(url::kAboutBlankURL);
612 } 590 }
613 591
614 int frame_tree_node_id = -1; 592 int frame_tree_node_id = -1;
615 593
616 // Send the navigation to the current FrameTreeNode if it's destined for a 594 // Send the navigation to the current FrameTreeNode if it's destined for a
617 // subframe in the current tab. We'll assume it's for the main frame 595 // subframe in the current tab. We'll assume it's for the main frame
618 // (possibly of a new or different WebContents) otherwise. 596 // (possibly of a new or different WebContents) otherwise.
619 if (SiteIsolationPolicy::AreCrossProcessFramesPossible() && 597 if (SiteIsolationPolicy::AreCrossProcessFramesPossible() &&
620 disposition == CURRENT_TAB && render_frame_host->GetParent()) { 598 disposition == CURRENT_TAB && render_frame_host->GetParent()) {
621 frame_tree_node_id = 599 frame_tree_node_id =
622 render_frame_host->frame_tree_node()->frame_tree_node_id(); 600 render_frame_host->frame_tree_node()->frame_tree_node_id();
623 } 601 }
624 602
625 OpenURLParams params( 603 OpenURLParams params(dest_url, referrer, frame_tree_node_id, disposition,
626 dest_url, referrer, frame_tree_node_id, disposition, page_transition, 604 ui::PAGE_TRANSITION_LINK,
627 true /* is_renderer_initiated */); 605 true /* is_renderer_initiated */);
628 params.source_site_instance = source_site_instance; 606 params.source_site_instance = source_site_instance;
629 if (redirect_chain.size() > 0) 607 if (redirect_chain.size() > 0)
630 params.redirect_chain = redirect_chain; 608 params.redirect_chain = redirect_chain;
631 params.transferred_global_request_id = transferred_global_request_id; 609 // TODO(creis): Remove transferred_global_request_id from OpenURLParams.
610 // See https://crbug.com/495161.
611 params.transferred_global_request_id = GlobalRequestID();
632 params.should_replace_current_entry = should_replace_current_entry; 612 params.should_replace_current_entry = should_replace_current_entry;
633 params.user_gesture = user_gesture; 613 params.user_gesture = user_gesture;
634 614
635 if (current_render_frame_host->web_ui()) { 615 if (render_frame_host->web_ui()) {
alexmos 2015/12/15 23:44:02 Just to help me understand: previously, it seems t
Charlie Reis 2015/12/16 00:27:30 Nice catch-- GetRenderManager looks pretty fragile
alexmos 2015/12/16 00:40:04 Yes, this makes sense to me now, and killing the m
636 // Web UI pages sometimes want to override the page transition type for 616 // Web UI pages sometimes want to override the page transition type for
637 // link clicks (e.g., so the new tab page can specify AUTO_BOOKMARK for 617 // link clicks (e.g., so the new tab page can specify AUTO_BOOKMARK for
638 // automatically generated suggestions). We don't override other types 618 // automatically generated suggestions). We don't override other types
639 // like TYPED because they have different implications (e.g., autocomplete). 619 // like TYPED because they have different implications (e.g., autocomplete).
640 if (ui::PageTransitionCoreTypeIs( 620 if (ui::PageTransitionCoreTypeIs(
641 params.transition, ui::PAGE_TRANSITION_LINK)) 621 params.transition, ui::PAGE_TRANSITION_LINK))
642 params.transition = 622 params.transition = render_frame_host->web_ui()->GetLinkTransitionType();
643 current_render_frame_host->web_ui()->GetLinkTransitionType();
644 623
645 // Note also that we hide the referrer for Web UI pages. We don't really 624 // Note also that we hide the referrer for Web UI pages. We don't really
646 // want web sites to see a referrer of "chrome://blah" (and some 625 // want web sites to see a referrer of "chrome://blah" (and some
647 // chrome: URLs might have search terms or other stuff we don't want to 626 // chrome: URLs might have search terms or other stuff we don't want to
648 // send to the site), so we send no referrer. 627 // send to the site), so we send no referrer.
649 params.referrer = Referrer(); 628 params.referrer = Referrer();
650 629
651 // Navigations in Web UI pages count as browser-initiated navigations. 630 // Navigations in Web UI pages count as browser-initiated navigations.
652 params.is_renderer_initiated = false; 631 params.is_renderer_initiated = false;
653 } 632 }
654 633
655 if (delegate_) 634 if (delegate_)
656 delegate_->RequestOpenURL(render_frame_host, params); 635 delegate_->RequestOpenURL(render_frame_host, params);
657 } 636 }
658 637
638 void NavigatorImpl::RequestTransferURL(
639 RenderFrameHostImpl* render_frame_host,
640 const GURL& url,
641 SiteInstance* source_site_instance,
642 const std::vector<GURL>& redirect_chain,
643 const Referrer& referrer,
644 ui::PageTransition page_transition,
645 WindowOpenDisposition disposition,
646 const GlobalRequestID& transferred_global_request_id,
647 bool should_replace_current_entry,
648 bool user_gesture) {
alexmos 2015/12/15 23:44:02 This looks unused now. Any reason to still keep i
Charlie Reis 2015/12/16 00:27:30 Good catch. It didn't seem to make it through to
649 // Allow the delegate to cancel the transfer.
650 if (!delegate_->ShouldTransferNavigation())
651 return;
652
653 GURL dest_url(url);
654 Referrer referrer_to_use(referrer);
655 FrameTreeNode* node = render_frame_host->frame_tree_node();
656 SiteInstance* current_site_instance = render_frame_host->GetSiteInstance();
657 if (!GetContentClient()->browser()->ShouldAllowOpenURL(current_site_instance,
658 url)) {
659 dest_url = GURL(url::kAboutBlankURL);
660 }
661
662 DCHECK_EQ(CURRENT_TAB, disposition);
663
664 // TODO(creis): Determine if this transfer started as a browser-initiated
665 // navigation. See https://crbug.com/495161.
666 bool is_renderer_initiated = true;
667 if (render_frame_host->web_ui()) {
alexmos 2015/12/15 23:44:02 Is it ok that this block is now duplicated between
Charlie Reis 2015/12/16 00:27:30 Good idea. I'll abstract them out separately.
668 // Web UI pages sometimes want to override the page transition type for
669 // link clicks (e.g., so the new tab page can specify AUTO_BOOKMARK for
670 // automatically generated suggestions). We don't override other types
671 // like TYPED because they have different implications (e.g., autocomplete).
672 if (ui::PageTransitionCoreTypeIs(page_transition, ui::PAGE_TRANSITION_LINK))
673 page_transition = render_frame_host->web_ui()->GetLinkTransitionType();
674
675 // Note also that we hide the referrer for Web UI pages. We don't really
676 // want web sites to see a referrer of "chrome://blah" (and some
677 // chrome: URLs might have search terms or other stuff we don't want to
678 // send to the site), so we send no referrer.
679 referrer_to_use = Referrer();
680
681 // Navigations in Web UI pages count as browser-initiated navigations.
682 is_renderer_initiated = false;
683 }
684
685 NavigationController::LoadURLParams load_url_params(dest_url);
686 load_url_params.source_site_instance = source_site_instance;
687 load_url_params.transition_type = page_transition;
688 load_url_params.frame_tree_node_id = node->frame_tree_node_id();
689 load_url_params.referrer = referrer_to_use;
690 load_url_params.redirect_chain = redirect_chain;
691 load_url_params.is_renderer_initiated = is_renderer_initiated;
692 load_url_params.transferred_global_request_id = transferred_global_request_id;
693 load_url_params.should_replace_current_entry = should_replace_current_entry;
694
695 controller_->LoadURLWithParams(load_url_params);
696 }
697
659 // PlzNavigate 698 // PlzNavigate
660 void NavigatorImpl::OnBeforeUnloadACK(FrameTreeNode* frame_tree_node, 699 void NavigatorImpl::OnBeforeUnloadACK(FrameTreeNode* frame_tree_node,
661 bool proceed) { 700 bool proceed) {
662 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( 701 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
663 switches::kEnableBrowserSideNavigation)); 702 switches::kEnableBrowserSideNavigation));
664 DCHECK(frame_tree_node); 703 DCHECK(frame_tree_node);
665 704
666 NavigationRequest* navigation_request = frame_tree_node->navigation_request(); 705 NavigationRequest* navigation_request = frame_tree_node->navigation_request();
667 706
668 // The NavigationRequest may have been canceled while the renderer was 707 // The NavigationRequest may have been canceled while the renderer was
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 entry->set_should_replace_entry(pending_entry->should_replace_entry()); 1023 entry->set_should_replace_entry(pending_entry->should_replace_entry());
985 entry->SetRedirectChain(pending_entry->GetRedirectChain()); 1024 entry->SetRedirectChain(pending_entry->GetRedirectChain());
986 } 1025 }
987 controller_->SetPendingEntry(entry.Pass()); 1026 controller_->SetPendingEntry(entry.Pass());
988 if (delegate_) 1027 if (delegate_)
989 delegate_->NotifyChangedNavigationState(content::INVALIDATE_TYPE_URL); 1028 delegate_->NotifyChangedNavigationState(content::INVALIDATE_TYPE_URL);
990 } 1029 }
991 } 1030 }
992 1031
993 } // namespace content 1032 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/navigator_delegate.cc ('k') | content/browser/web_contents/web_contents_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698