OLD | NEW |
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 Loading... |
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()) { |
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 // Allow the delegate to cancel the transfer. |
| 649 if (!delegate_->ShouldTransferNavigation()) |
| 650 return; |
| 651 |
| 652 GURL dest_url(url); |
| 653 Referrer referrer_to_use(referrer); |
| 654 FrameTreeNode* node = render_frame_host->frame_tree_node(); |
| 655 SiteInstance* current_site_instance = render_frame_host->GetSiteInstance(); |
| 656 if (!GetContentClient()->browser()->ShouldAllowOpenURL(current_site_instance, |
| 657 url)) { |
| 658 dest_url = GURL(url::kAboutBlankURL); |
| 659 } |
| 660 |
| 661 DCHECK_EQ(CURRENT_TAB, disposition); |
| 662 |
| 663 // TODO(creis): Determine if this transfer started as a browser-initiated |
| 664 // navigation. See https://crbug.com/495161. |
| 665 bool is_renderer_initiated = true; |
| 666 if (render_frame_host->web_ui()) { |
| 667 // Web UI pages sometimes want to override the page transition type for |
| 668 // link clicks (e.g., so the new tab page can specify AUTO_BOOKMARK for |
| 669 // automatically generated suggestions). We don't override other types |
| 670 // like TYPED because they have different implications (e.g., autocomplete). |
| 671 if (ui::PageTransitionCoreTypeIs(page_transition, ui::PAGE_TRANSITION_LINK)) |
| 672 page_transition = render_frame_host->web_ui()->GetLinkTransitionType(); |
| 673 |
| 674 // Note also that we hide the referrer for Web UI pages. We don't really |
| 675 // want web sites to see a referrer of "chrome://blah" (and some |
| 676 // chrome: URLs might have search terms or other stuff we don't want to |
| 677 // send to the site), so we send no referrer. |
| 678 referrer_to_use = Referrer(); |
| 679 |
| 680 // Navigations in Web UI pages count as browser-initiated navigations. |
| 681 is_renderer_initiated = false; |
| 682 } |
| 683 |
| 684 NavigationController::LoadURLParams load_url_params(dest_url); |
| 685 load_url_params.source_site_instance = source_site_instance; |
| 686 load_url_params.transition_type = page_transition; |
| 687 load_url_params.frame_tree_node_id = node->frame_tree_node_id(); |
| 688 load_url_params.referrer = referrer_to_use; |
| 689 load_url_params.redirect_chain = redirect_chain; |
| 690 load_url_params.is_renderer_initiated = is_renderer_initiated; |
| 691 load_url_params.transferred_global_request_id = transferred_global_request_id; |
| 692 load_url_params.should_replace_current_entry = should_replace_current_entry; |
| 693 |
| 694 controller_->LoadURLWithParams(load_url_params); |
| 695 } |
| 696 |
659 // PlzNavigate | 697 // PlzNavigate |
660 void NavigatorImpl::OnBeforeUnloadACK(FrameTreeNode* frame_tree_node, | 698 void NavigatorImpl::OnBeforeUnloadACK(FrameTreeNode* frame_tree_node, |
661 bool proceed) { | 699 bool proceed) { |
662 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( | 700 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
663 switches::kEnableBrowserSideNavigation)); | 701 switches::kEnableBrowserSideNavigation)); |
664 DCHECK(frame_tree_node); | 702 DCHECK(frame_tree_node); |
665 | 703 |
666 NavigationRequest* navigation_request = frame_tree_node->navigation_request(); | 704 NavigationRequest* navigation_request = frame_tree_node->navigation_request(); |
667 | 705 |
668 // The NavigationRequest may have been canceled while the renderer was | 706 // The NavigationRequest may have been canceled while the renderer was |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
984 entry->set_should_replace_entry(pending_entry->should_replace_entry()); | 1022 entry->set_should_replace_entry(pending_entry->should_replace_entry()); |
985 entry->SetRedirectChain(pending_entry->GetRedirectChain()); | 1023 entry->SetRedirectChain(pending_entry->GetRedirectChain()); |
986 } | 1024 } |
987 controller_->SetPendingEntry(entry.Pass()); | 1025 controller_->SetPendingEntry(entry.Pass()); |
988 if (delegate_) | 1026 if (delegate_) |
989 delegate_->NotifyChangedNavigationState(content::INVALIDATE_TYPE_URL); | 1027 delegate_->NotifyChangedNavigationState(content::INVALIDATE_TYPE_URL); |
990 } | 1028 } |
991 } | 1029 } |
992 | 1030 |
993 } // namespace content | 1031 } // namespace content |
OLD | NEW |