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

Side by Side Diff: content/renderer/render_frame_impl.cc

Issue 2584513003: PlzNavigate: identify same-page browser-initiated navigation. (Closed)
Patch Set: Rebase. Created 3 years, 10 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
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/renderer/render_frame_impl.h" 5 #include "content/renderer/render_frame_impl.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 550
551 // Returns false unless this is a top-level navigation. 551 // Returns false unless this is a top-level navigation.
552 bool IsTopLevelNavigation(WebFrame* frame) { 552 bool IsTopLevelNavigation(WebFrame* frame) {
553 return frame->parent() == NULL; 553 return frame->parent() == NULL;
554 } 554 }
555 555
556 WebURLRequest CreateURLRequestForNavigation( 556 WebURLRequest CreateURLRequestForNavigation(
557 const CommonNavigationParams& common_params, 557 const CommonNavigationParams& common_params,
558 std::unique_ptr<StreamOverrideParameters> stream_override, 558 std::unique_ptr<StreamOverrideParameters> stream_override,
559 bool is_view_source_mode_enabled, 559 bool is_view_source_mode_enabled,
560 bool is_same_document_navigation,
560 int nav_entry_id) { 561 int nav_entry_id) {
561 WebURLRequest request(common_params.url); 562 WebURLRequest request(common_params.url);
562 if (is_view_source_mode_enabled) 563 if (is_view_source_mode_enabled)
563 request.setCachePolicy(WebCachePolicy::ReturnCacheDataElseLoad); 564 request.setCachePolicy(WebCachePolicy::ReturnCacheDataElseLoad);
564 565
565 request.setHTTPMethod(WebString::fromUTF8(common_params.method)); 566 request.setHTTPMethod(WebString::fromUTF8(common_params.method));
566 if (common_params.referrer.url.is_valid()) { 567 if (common_params.referrer.url.is_valid()) {
567 WebString web_referrer = WebSecurityPolicy::generateReferrerHeader( 568 WebString web_referrer = WebSecurityPolicy::generateReferrerHeader(
568 common_params.referrer.policy, 569 common_params.referrer.policy, common_params.url,
569 common_params.url,
570 WebString::fromUTF8(common_params.referrer.url.spec())); 570 WebString::fromUTF8(common_params.referrer.url.spec()));
571 if (!web_referrer.isEmpty()) { 571 if (!web_referrer.isEmpty()) {
572 request.setHTTPReferrer(web_referrer, common_params.referrer.policy); 572 request.setHTTPReferrer(web_referrer, common_params.referrer.policy);
573 request.addHTTPOriginIfNeeded( 573 request.addHTTPOriginIfNeeded(
574 WebSecurityOrigin(url::Origin(common_params.referrer.url))); 574 WebSecurityOrigin(url::Origin(common_params.referrer.url)));
575 } 575 }
576 } 576 }
577 577
578 request.setIsSameDocumentNavigation(is_same_document_navigation);
578 request.setPreviewsState( 579 request.setPreviewsState(
579 static_cast<WebURLRequest::PreviewsState>(common_params.previews_state)); 580 static_cast<WebURLRequest::PreviewsState>(common_params.previews_state));
580 581
581 RequestExtraData* extra_data = new RequestExtraData(); 582 RequestExtraData* extra_data = new RequestExtraData();
582 extra_data->set_stream_override(std::move(stream_override)); 583 extra_data->set_stream_override(std::move(stream_override));
583 extra_data->set_navigation_initiated_by_renderer(nav_entry_id == 0); 584 extra_data->set_navigation_initiated_by_renderer(nav_entry_id == 0);
584 request.setExtraData(extra_data); 585 request.setExtraData(extra_data);
585 586
586 // Set the ui timestamp for this navigation. Currently the timestamp here is 587 // Set the ui timestamp for this navigation. Currently the timestamp here is
587 // only non empty when the navigation was triggered by an Android intent. The 588 // only non empty when the navigation was triggered by an Android intent. The
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 // version supported by blink. It will be passed back to the renderer in the 627 // version supported by blink. It will be passed back to the renderer in the
627 // CommitNavigation IPC, and then back to the browser again in the 628 // CommitNavigation IPC, and then back to the browser again in the
628 // DidCommitProvisionalLoad and the DocumentLoadComplete IPCs. 629 // DidCommitProvisionalLoad and the DocumentLoadComplete IPCs.
629 base::TimeTicks ui_timestamp = 630 base::TimeTicks ui_timestamp =
630 base::TimeTicks() + 631 base::TimeTicks() +
631 base::TimeDelta::FromSecondsD(info.urlRequest.uiStartTime()); 632 base::TimeDelta::FromSecondsD(info.urlRequest.uiStartTime());
632 FrameMsg_UILoadMetricsReportType::Value report_type = 633 FrameMsg_UILoadMetricsReportType::Value report_type =
633 static_cast<FrameMsg_UILoadMetricsReportType::Value>( 634 static_cast<FrameMsg_UILoadMetricsReportType::Value>(
634 info.urlRequest.inputPerfMetricReportPolicy()); 635 info.urlRequest.inputPerfMetricReportPolicy());
635 636
637 // No history-navigation is expected to happen.
638 DCHECK(info.navigationType != blink::WebNavigationTypeBackForward);
639
636 FrameMsg_Navigate_Type::Value navigation_type = 640 FrameMsg_Navigate_Type::Value navigation_type =
637 info.navigationType == blink::WebNavigationTypeReload 641 info.navigationType == blink::WebNavigationTypeReload
638 ? FrameMsg_Navigate_Type::RELOAD 642 ? FrameMsg_Navigate_Type::RELOAD
639 : FrameMsg_Navigate_Type::NORMAL; 643 // No same-document navigation is expected because it is loaded
644 // immediately by the FrameLoader.
645 : FrameMsg_Navigate_Type::DIFFERENT_DOCUMENT;
640 646
641 const RequestExtraData* extra_data = 647 const RequestExtraData* extra_data =
642 static_cast<RequestExtraData*>(info.urlRequest.getExtraData()); 648 static_cast<RequestExtraData*>(info.urlRequest.getExtraData());
643 DCHECK(extra_data); 649 DCHECK(extra_data);
644 return CommonNavigationParams( 650 return CommonNavigationParams(
645 info.urlRequest.url(), referrer, extra_data->transition_type(), 651 info.urlRequest.url(), referrer, extra_data->transition_type(),
646 navigation_type, true, info.replacesCurrentHistoryItem, ui_timestamp, 652 navigation_type, true, info.replacesCurrentHistoryItem, ui_timestamp,
647 report_type, GURL(), GURL(), 653 report_type, GURL(), GURL(),
648 static_cast<PreviewsState>(info.urlRequest.getPreviewsState()), 654 static_cast<PreviewsState>(info.urlRequest.getPreviewsState()),
649 base::TimeTicks::Now(), info.urlRequest.httpMethod().latin1(), 655 base::TimeTicks::Now(), info.urlRequest.httpMethod().latin1(),
650 GetRequestBodyForWebURLRequest(info.urlRequest)); 656 GetRequestBodyForWebURLRequest(info.urlRequest));
651 } 657 }
652 658
653 media::Context3D GetSharedMainThreadContext3D( 659 media::Context3D GetSharedMainThreadContext3D(
654 scoped_refptr<ui::ContextProviderCommandBuffer> provider) { 660 scoped_refptr<ui::ContextProviderCommandBuffer> provider) {
655 if (!provider) 661 if (!provider)
656 return media::Context3D(); 662 return media::Context3D();
657 return media::Context3D(provider->ContextGL(), provider->GrContext()); 663 return media::Context3D(provider->ContextGL(), provider->GrContext());
658 } 664 }
659 665
660 bool IsReload(FrameMsg_Navigate_Type::Value navigation_type) {
661 switch (navigation_type) {
662 case FrameMsg_Navigate_Type::RELOAD:
663 case FrameMsg_Navigate_Type::RELOAD_BYPASSING_CACHE:
664 case FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL:
665 return true;
666 case FrameMsg_Navigate_Type::RESTORE:
667 case FrameMsg_Navigate_Type::RESTORE_WITH_POST:
668 case FrameMsg_Navigate_Type::NORMAL:
669 return false;
670 }
671 NOTREACHED();
672 return false;
673 }
674
675 WebFrameLoadType ReloadFrameLoadTypeFor( 666 WebFrameLoadType ReloadFrameLoadTypeFor(
676 FrameMsg_Navigate_Type::Value navigation_type) { 667 FrameMsg_Navigate_Type::Value navigation_type) {
677 switch (navigation_type) { 668 switch (navigation_type) {
678 case FrameMsg_Navigate_Type::RELOAD: 669 case FrameMsg_Navigate_Type::RELOAD:
679 case FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL: 670 case FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL:
680 return WebFrameLoadType::ReloadMainResource; 671 return WebFrameLoadType::ReloadMainResource;
672
681 case FrameMsg_Navigate_Type::RELOAD_BYPASSING_CACHE: 673 case FrameMsg_Navigate_Type::RELOAD_BYPASSING_CACHE:
682 return WebFrameLoadType::ReloadBypassingCache; 674 return WebFrameLoadType::ReloadBypassingCache;
683 case FrameMsg_Navigate_Type::RESTORE: 675
684 case FrameMsg_Navigate_Type::RESTORE_WITH_POST: 676 default:
685 case FrameMsg_Navigate_Type::NORMAL:
686 NOTREACHED(); 677 NOTREACHED();
687 return WebFrameLoadType::Standard; 678 return WebFrameLoadType::Standard;
688 } 679 }
689 NOTREACHED();
690 return WebFrameLoadType::Standard;
691 } 680 }
692 681
693 RenderFrameImpl::CreateRenderFrameImplFunction g_create_render_frame_impl = 682 RenderFrameImpl::CreateRenderFrameImplFunction g_create_render_frame_impl =
694 nullptr; 683 nullptr;
695 684
696 WebString ConvertRelativePathToHtmlAttribute(const base::FilePath& path) { 685 WebString ConvertRelativePathToHtmlAttribute(const base::FilePath& path) {
697 DCHECK(!path.IsAbsolute()); 686 DCHECK(!path.IsAbsolute());
698 return WebString::fromUTF8( 687 return WebString::fromUTF8(
699 std::string("./") + 688 std::string("./") +
700 path.NormalizePathSeparatorsTo(FILE_PATH_LITERAL('/')).AsUTF8Unsafe()); 689 path.NormalizePathSeparatorsTo(FILE_PATH_LITERAL('/')).AsUTF8Unsafe());
(...skipping 4437 matching lines...) Expand 10 before | Expand all | Expand 10 after
5138 // RenderFrameImpl. 5127 // RenderFrameImpl.
5139 } 5128 }
5140 5129
5141 // PlzNavigate 5130 // PlzNavigate
5142 void RenderFrameImpl::OnFailedNavigation( 5131 void RenderFrameImpl::OnFailedNavigation(
5143 const CommonNavigationParams& common_params, 5132 const CommonNavigationParams& common_params,
5144 const RequestNavigationParams& request_params, 5133 const RequestNavigationParams& request_params,
5145 bool has_stale_copy_in_cache, 5134 bool has_stale_copy_in_cache,
5146 int error_code) { 5135 int error_code) {
5147 DCHECK(IsBrowserSideNavigationEnabled()); 5136 DCHECK(IsBrowserSideNavigationEnabled());
5148 bool is_reload = IsReload(common_params.navigation_type); 5137 bool is_reload =
5138 FrameMsg_Navigate_Type::IsReload(common_params.navigation_type);
5149 RenderFrameImpl::PrepareRenderViewForNavigation( 5139 RenderFrameImpl::PrepareRenderViewForNavigation(
5150 common_params.url, request_params); 5140 common_params.url, request_params);
5151 5141
5152 GetContentClient()->SetActiveURL(common_params.url); 5142 GetContentClient()->SetActiveURL(common_params.url);
5153 5143
5154 // If this frame isn't in the same process as the main frame, it may naively 5144 // If this frame isn't in the same process as the main frame, it may naively
5155 // assume that this is the first navigation in the iframe, but this may not 5145 // assume that this is the first navigation in the iframe, but this may not
5156 // actually be the case. Inform the frame's state machine if this frame has 5146 // actually be the case. Inform the frame's state machine if this frame has
5157 // already committed other loads. 5147 // already committed other loads.
5158 if (request_params.has_committed_real_load && frame_->parent()) 5148 if (request_params.has_committed_real_load && frame_->parent())
5159 frame_->setCommittedFirstRealLoad(); 5149 frame_->setCommittedFirstRealLoad();
5160 5150
5161 pending_navigation_params_.reset(new NavigationParams( 5151 pending_navigation_params_.reset(new NavigationParams(
5162 common_params, StartNavigationParams(), request_params)); 5152 common_params, StartNavigationParams(), request_params));
5163 5153
5164 // Send the provisional load failure. 5154 // Send the provisional load failure.
5165 blink::WebURLError error = 5155 blink::WebURLError error =
5166 CreateWebURLError(common_params.url, has_stale_copy_in_cache, error_code); 5156 CreateWebURLError(common_params.url, has_stale_copy_in_cache, error_code);
5167 WebURLRequest failed_request = CreateURLRequestForNavigation( 5157 WebURLRequest failed_request = CreateURLRequestForNavigation(
5168 common_params, std::unique_ptr<StreamOverrideParameters>(), 5158 common_params, std::unique_ptr<StreamOverrideParameters>(),
5169 frame_->isViewSourceModeEnabled(), request_params.nav_entry_id); 5159 frame_->isViewSourceModeEnabled(),
5160 false, // is_same_document_navigation
5161 request_params.nav_entry_id);
5170 5162
5171 if (!ShouldDisplayErrorPageForFailedLoad(error_code, common_params.url)) { 5163 if (!ShouldDisplayErrorPageForFailedLoad(error_code, common_params.url)) {
5172 // The browser expects this frame to be loading an error page. Inform it 5164 // The browser expects this frame to be loading an error page. Inform it
5173 // that the load stopped. 5165 // that the load stopped.
5174 Send(new FrameHostMsg_DidStopLoading(routing_id_)); 5166 Send(new FrameHostMsg_DidStopLoading(routing_id_));
5175 browser_side_navigation_pending_ = false; 5167 browser_side_navigation_pending_ = false;
5176 return; 5168 return;
5177 } 5169 }
5178 5170
5179 // On load failure, a frame can ask its owner to render fallback content. 5171 // On load failure, a frame can ask its owner to render fallback content.
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
5786 5778
5787 void RenderFrameImpl::NavigateInternal( 5779 void RenderFrameImpl::NavigateInternal(
5788 const CommonNavigationParams& common_params, 5780 const CommonNavigationParams& common_params,
5789 const StartNavigationParams& start_params, 5781 const StartNavigationParams& start_params,
5790 const RequestNavigationParams& request_params, 5782 const RequestNavigationParams& request_params,
5791 std::unique_ptr<StreamOverrideParameters> stream_params) { 5783 std::unique_ptr<StreamOverrideParameters> stream_params) {
5792 bool browser_side_navigation = IsBrowserSideNavigationEnabled(); 5784 bool browser_side_navigation = IsBrowserSideNavigationEnabled();
5793 5785
5794 // Lower bound for browser initiated navigation start time. 5786 // Lower bound for browser initiated navigation start time.
5795 base::TimeTicks renderer_navigation_start = base::TimeTicks::Now(); 5787 base::TimeTicks renderer_navigation_start = base::TimeTicks::Now();
5796 bool is_reload = IsReload(common_params.navigation_type); 5788 bool is_reload =
5789 FrameMsg_Navigate_Type::IsReload(common_params.navigation_type);
5797 bool is_history_navigation = request_params.page_state.IsValid(); 5790 bool is_history_navigation = request_params.page_state.IsValid();
5798 WebCachePolicy cache_policy = WebCachePolicy::UseProtocolCachePolicy; 5791 WebCachePolicy cache_policy = WebCachePolicy::UseProtocolCachePolicy;
5799 RenderFrameImpl::PrepareRenderViewForNavigation( 5792 RenderFrameImpl::PrepareRenderViewForNavigation(
5800 common_params.url, request_params); 5793 common_params.url, request_params);
5801 5794
5802 GetContentClient()->SetActiveURL(common_params.url); 5795 GetContentClient()->SetActiveURL(common_params.url);
5803 5796
5804 // If this frame isn't in the same process as the main frame, it may naively 5797 // If this frame isn't in the same process as the main frame, it may naively
5805 // assume that this is the first navigation in the iframe, but this may not 5798 // assume that this is the first navigation in the iframe, but this may not
5806 // actually be the case. Inform the frame's state machine if this frame has 5799 // actually be the case. Inform the frame's state machine if this frame has
(...skipping 25 matching lines...) Expand all
5832 // Create parameters for a standard navigation, indicating whether it should 5825 // Create parameters for a standard navigation, indicating whether it should
5833 // replace the current NavigationEntry. 5826 // replace the current NavigationEntry.
5834 blink::WebFrameLoadType load_type = 5827 blink::WebFrameLoadType load_type =
5835 common_params.should_replace_current_entry 5828 common_params.should_replace_current_entry
5836 ? blink::WebFrameLoadType::ReplaceCurrentItem 5829 ? blink::WebFrameLoadType::ReplaceCurrentItem
5837 : blink::WebFrameLoadType::Standard; 5830 : blink::WebFrameLoadType::Standard;
5838 blink::WebHistoryLoadType history_load_type = 5831 blink::WebHistoryLoadType history_load_type =
5839 blink::WebHistoryDifferentDocumentLoad; 5832 blink::WebHistoryDifferentDocumentLoad;
5840 bool should_load_request = false; 5833 bool should_load_request = false;
5841 WebHistoryItem item_for_history_navigation; 5834 WebHistoryItem item_for_history_navigation;
5842 WebURLRequest request = 5835 WebURLRequest request = CreateURLRequestForNavigation(
5843 CreateURLRequestForNavigation(common_params, std::move(stream_params), 5836 common_params, std::move(stream_params),
5844 frame_->isViewSourceModeEnabled(), 5837 frame_->isViewSourceModeEnabled(),
5845 request_params.nav_entry_id); 5838 FrameMsg_Navigate_Type::IsSameDocument(common_params.navigation_type),
5839 request_params.nav_entry_id);
5846 request.setFrameType(IsTopLevelNavigation(frame_) 5840 request.setFrameType(IsTopLevelNavigation(frame_)
5847 ? blink::WebURLRequest::FrameTypeTopLevel 5841 ? blink::WebURLRequest::FrameTypeTopLevel
5848 : blink::WebURLRequest::FrameTypeNested); 5842 : blink::WebURLRequest::FrameTypeNested);
5849 5843
5850 if (IsBrowserSideNavigationEnabled() && common_params.post_data) 5844 if (IsBrowserSideNavigationEnabled() && common_params.post_data)
5851 request.setHTTPBody(GetWebHTTPBodyForRequestBody(common_params.post_data)); 5845 request.setHTTPBody(GetWebHTTPBodyForRequestBody(common_params.post_data));
5852 5846
5853 // Used to determine whether this frame is actually loading a request as part 5847 // Used to determine whether this frame is actually loading a request as part
5854 // of a history navigation. 5848 // of a history navigation.
5855 bool has_history_navigation_in_frame = false; 5849 bool has_history_navigation_in_frame = false;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
5889 // browser. 5883 // browser.
5890 DCHECK_NE(0, request_params.nav_entry_id); 5884 DCHECK_NE(0, request_params.nav_entry_id);
5891 std::unique_ptr<HistoryEntry> entry = 5885 std::unique_ptr<HistoryEntry> entry =
5892 PageStateToHistoryEntry(request_params.page_state); 5886 PageStateToHistoryEntry(request_params.page_state);
5893 if (entry) { 5887 if (entry) {
5894 // The browser process sends a single WebHistoryItem for this frame. 5888 // The browser process sends a single WebHistoryItem for this frame.
5895 // TODO(creis): Change PageState to FrameState. In the meantime, we 5889 // TODO(creis): Change PageState to FrameState. In the meantime, we
5896 // store the relevant frame's WebHistoryItem in the root of the 5890 // store the relevant frame's WebHistoryItem in the root of the
5897 // PageState. 5891 // PageState.
5898 item_for_history_navigation = entry->root(); 5892 item_for_history_navigation = entry->root();
5899 history_load_type = request_params.is_same_document_history_load 5893 switch (common_params.navigation_type) {
5900 ? blink::WebHistorySameDocumentLoad 5894 case FrameMsg_Navigate_Type::RELOAD:
5901 : blink::WebHistoryDifferentDocumentLoad; 5895 case FrameMsg_Navigate_Type::RELOAD_BYPASSING_CACHE:
5896 case FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL:
5897 case FrameMsg_Navigate_Type::RESTORE:
5898 case FrameMsg_Navigate_Type::RESTORE_WITH_POST:
5899 case FrameMsg_Navigate_Type::HISTORY_DIFFERENT_DOCUMENT:
5900 history_load_type = blink::WebHistoryDifferentDocumentLoad;
5901 break;
5902 case FrameMsg_Navigate_Type::HISTORY_SAME_DOCUMENT:
5903 history_load_type = blink::WebHistorySameDocumentLoad;
5904 break;
5905 default:
5906 NOTREACHED();
5907 history_load_type = blink::WebHistoryDifferentDocumentLoad;
5908 }
5902 load_type = request_params.is_history_navigation_in_new_child 5909 load_type = request_params.is_history_navigation_in_new_child
5903 ? blink::WebFrameLoadType::InitialHistoryLoad 5910 ? blink::WebFrameLoadType::InitialHistoryLoad
5904 : blink::WebFrameLoadType::BackForward; 5911 : blink::WebFrameLoadType::BackForward;
5905 should_load_request = true; 5912 should_load_request = true;
5906 5913
5907 // Keep track of which subframes the browser process has history items 5914 // Keep track of which subframes the browser process has history items
5908 // for during a history navigation. 5915 // for during a history navigation.
5909 history_subframe_unique_names_ = request_params.subframe_unique_names; 5916 history_subframe_unique_names_ = request_params.subframe_unique_names;
5910 5917
5911 if (history_load_type == blink::WebHistorySameDocumentLoad) { 5918 if (history_load_type == blink::WebHistorySameDocumentLoad) {
(...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after
6796 // event target. Potentially a Pepper plugin will receive the event. 6803 // event target. Potentially a Pepper plugin will receive the event.
6797 // In order to tell whether a plugin gets the last mouse event and which it 6804 // In order to tell whether a plugin gets the last mouse event and which it
6798 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets 6805 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets
6799 // the event, it will notify us via DidReceiveMouseEvent() and set itself as 6806 // the event, it will notify us via DidReceiveMouseEvent() and set itself as
6800 // |pepper_last_mouse_event_target_|. 6807 // |pepper_last_mouse_event_target_|.
6801 pepper_last_mouse_event_target_ = nullptr; 6808 pepper_last_mouse_event_target_ = nullptr;
6802 #endif 6809 #endif
6803 } 6810 }
6804 6811
6805 } // namespace content 6812 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698