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

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

Issue 2584513003: PlzNavigate: identify same-page browser-initiated navigation. (Closed)
Patch Set: Addressed comments(@brettw) 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 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 554
555 // Returns false unless this is a top-level navigation. 555 // Returns false unless this is a top-level navigation.
556 bool IsTopLevelNavigation(WebFrame* frame) { 556 bool IsTopLevelNavigation(WebFrame* frame) {
557 return frame->parent() == NULL; 557 return frame->parent() == NULL;
558 } 558 }
559 559
560 WebURLRequest CreateURLRequestForNavigation( 560 WebURLRequest CreateURLRequestForNavigation(
561 const CommonNavigationParams& common_params, 561 const CommonNavigationParams& common_params,
562 std::unique_ptr<StreamOverrideParameters> stream_override, 562 std::unique_ptr<StreamOverrideParameters> stream_override,
563 bool is_view_source_mode_enabled, 563 bool is_view_source_mode_enabled,
564 bool is_same_document_navigation,
564 int nav_entry_id) { 565 int nav_entry_id) {
565 WebURLRequest request(common_params.url); 566 WebURLRequest request(common_params.url);
566 if (is_view_source_mode_enabled) 567 if (is_view_source_mode_enabled)
567 request.setCachePolicy(WebCachePolicy::ReturnCacheDataElseLoad); 568 request.setCachePolicy(WebCachePolicy::ReturnCacheDataElseLoad);
568 569
569 request.setHTTPMethod(WebString::fromUTF8(common_params.method)); 570 request.setHTTPMethod(WebString::fromUTF8(common_params.method));
570 if (common_params.referrer.url.is_valid()) { 571 if (common_params.referrer.url.is_valid()) {
571 WebString web_referrer = WebSecurityPolicy::generateReferrerHeader( 572 WebString web_referrer = WebSecurityPolicy::generateReferrerHeader(
572 common_params.referrer.policy, 573 common_params.referrer.policy, common_params.url,
573 common_params.url,
574 WebString::fromUTF8(common_params.referrer.url.spec())); 574 WebString::fromUTF8(common_params.referrer.url.spec()));
575 if (!web_referrer.isEmpty()) { 575 if (!web_referrer.isEmpty()) {
576 request.setHTTPReferrer(web_referrer, common_params.referrer.policy); 576 request.setHTTPReferrer(web_referrer, common_params.referrer.policy);
577 request.addHTTPOriginIfNeeded( 577 request.addHTTPOriginIfNeeded(
578 WebSecurityOrigin(url::Origin(common_params.referrer.url))); 578 WebSecurityOrigin(url::Origin(common_params.referrer.url)));
579 } 579 }
580 } 580 }
581 581
582 request.setIsSameDocumentNavigation(is_same_document_navigation);
582 request.setPreviewsState( 583 request.setPreviewsState(
583 static_cast<WebURLRequest::PreviewsState>(common_params.previews_state)); 584 static_cast<WebURLRequest::PreviewsState>(common_params.previews_state));
584 585
585 RequestExtraData* extra_data = new RequestExtraData(); 586 RequestExtraData* extra_data = new RequestExtraData();
586 extra_data->set_stream_override(std::move(stream_override)); 587 extra_data->set_stream_override(std::move(stream_override));
587 extra_data->set_navigation_initiated_by_renderer(nav_entry_id == 0); 588 extra_data->set_navigation_initiated_by_renderer(nav_entry_id == 0);
588 request.setExtraData(extra_data); 589 request.setExtraData(extra_data);
589 590
590 // Set the ui timestamp for this navigation. Currently the timestamp here is 591 // Set the ui timestamp for this navigation. Currently the timestamp here is
591 // only non empty when the navigation was triggered by an Android intent. The 592 // 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
630 // version supported by blink. It will be passed back to the renderer in the 631 // version supported by blink. It will be passed back to the renderer in the
631 // CommitNavigation IPC, and then back to the browser again in the 632 // CommitNavigation IPC, and then back to the browser again in the
632 // DidCommitProvisionalLoad and the DocumentLoadComplete IPCs. 633 // DidCommitProvisionalLoad and the DocumentLoadComplete IPCs.
633 base::TimeTicks ui_timestamp = 634 base::TimeTicks ui_timestamp =
634 base::TimeTicks() + 635 base::TimeTicks() +
635 base::TimeDelta::FromSecondsD(info.urlRequest.uiStartTime()); 636 base::TimeDelta::FromSecondsD(info.urlRequest.uiStartTime());
636 FrameMsg_UILoadMetricsReportType::Value report_type = 637 FrameMsg_UILoadMetricsReportType::Value report_type =
637 static_cast<FrameMsg_UILoadMetricsReportType::Value>( 638 static_cast<FrameMsg_UILoadMetricsReportType::Value>(
638 info.urlRequest.inputPerfMetricReportPolicy()); 639 info.urlRequest.inputPerfMetricReportPolicy());
639 640
641 // No history-navigation is expected to happen.
642 DCHECK(info.navigationType != blink::WebNavigationTypeBackForward);
643
640 FrameMsg_Navigate_Type::Value navigation_type = 644 FrameMsg_Navigate_Type::Value navigation_type =
641 info.navigationType == blink::WebNavigationTypeReload 645 info.navigationType == blink::WebNavigationTypeReload
642 ? FrameMsg_Navigate_Type::RELOAD 646 ? FrameMsg_Navigate_Type::RELOAD
643 : FrameMsg_Navigate_Type::NORMAL; 647 // No same-document navigation is expected because it is loaded
648 // immediately by the FrameLoader.
649 : FrameMsg_Navigate_Type::DIFFERENT_DOCUMENT;
644 650
645 const RequestExtraData* extra_data = 651 const RequestExtraData* extra_data =
646 static_cast<RequestExtraData*>(info.urlRequest.getExtraData()); 652 static_cast<RequestExtraData*>(info.urlRequest.getExtraData());
647 DCHECK(extra_data); 653 DCHECK(extra_data);
648 return CommonNavigationParams( 654 return CommonNavigationParams(
649 info.urlRequest.url(), referrer, extra_data->transition_type(), 655 info.urlRequest.url(), referrer, extra_data->transition_type(),
650 navigation_type, true, info.replacesCurrentHistoryItem, ui_timestamp, 656 navigation_type, true, info.replacesCurrentHistoryItem, ui_timestamp,
651 report_type, GURL(), GURL(), 657 report_type, GURL(), GURL(),
652 static_cast<PreviewsState>(info.urlRequest.getPreviewsState()), 658 static_cast<PreviewsState>(info.urlRequest.getPreviewsState()),
653 base::TimeTicks::Now(), info.urlRequest.httpMethod().latin1(), 659 base::TimeTicks::Now(), info.urlRequest.httpMethod().latin1(),
654 GetRequestBodyForWebURLRequest(info.urlRequest)); 660 GetRequestBodyForWebURLRequest(info.urlRequest));
655 } 661 }
656 662
657 media::Context3D GetSharedMainThreadContext3D( 663 media::Context3D GetSharedMainThreadContext3D(
658 scoped_refptr<ui::ContextProviderCommandBuffer> provider) { 664 scoped_refptr<ui::ContextProviderCommandBuffer> provider) {
659 if (!provider) 665 if (!provider)
660 return media::Context3D(); 666 return media::Context3D();
661 return media::Context3D(provider->ContextGL(), provider->GrContext()); 667 return media::Context3D(provider->ContextGL(), provider->GrContext());
662 } 668 }
663 669
664 bool IsReload(FrameMsg_Navigate_Type::Value navigation_type) {
665 switch (navigation_type) {
666 case FrameMsg_Navigate_Type::RELOAD:
667 case FrameMsg_Navigate_Type::RELOAD_BYPASSING_CACHE:
668 case FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL:
669 return true;
670 case FrameMsg_Navigate_Type::RESTORE:
671 case FrameMsg_Navigate_Type::RESTORE_WITH_POST:
672 case FrameMsg_Navigate_Type::NORMAL:
673 return false;
674 }
675 NOTREACHED();
676 return false;
677 }
678
679 WebFrameLoadType ReloadFrameLoadTypeFor( 670 WebFrameLoadType ReloadFrameLoadTypeFor(
680 FrameMsg_Navigate_Type::Value navigation_type) { 671 FrameMsg_Navigate_Type::Value navigation_type) {
681 switch (navigation_type) { 672 switch (navigation_type) {
682 case FrameMsg_Navigate_Type::RELOAD: 673 case FrameMsg_Navigate_Type::RELOAD:
683 case FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL: 674 case FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL:
684 return WebFrameLoadType::ReloadMainResource; 675 return WebFrameLoadType::ReloadMainResource;
676
685 case FrameMsg_Navigate_Type::RELOAD_BYPASSING_CACHE: 677 case FrameMsg_Navigate_Type::RELOAD_BYPASSING_CACHE:
686 return WebFrameLoadType::ReloadBypassingCache; 678 return WebFrameLoadType::ReloadBypassingCache;
687 case FrameMsg_Navigate_Type::RESTORE: 679
688 case FrameMsg_Navigate_Type::RESTORE_WITH_POST: 680 default:
689 case FrameMsg_Navigate_Type::NORMAL:
690 NOTREACHED(); 681 NOTREACHED();
691 return WebFrameLoadType::Standard; 682 return WebFrameLoadType::Standard;
692 } 683 }
693 NOTREACHED();
694 return WebFrameLoadType::Standard;
695 } 684 }
696 685
697 RenderFrameImpl::CreateRenderFrameImplFunction g_create_render_frame_impl = 686 RenderFrameImpl::CreateRenderFrameImplFunction g_create_render_frame_impl =
698 nullptr; 687 nullptr;
699 688
700 WebString ConvertRelativePathToHtmlAttribute(const base::FilePath& path) { 689 WebString ConvertRelativePathToHtmlAttribute(const base::FilePath& path) {
701 DCHECK(!path.IsAbsolute()); 690 DCHECK(!path.IsAbsolute());
702 return WebString::fromUTF8( 691 return WebString::fromUTF8(
703 std::string("./") + 692 std::string("./") +
704 path.NormalizePathSeparatorsTo(FILE_PATH_LITERAL('/')).AsUTF8Unsafe()); 693 path.NormalizePathSeparatorsTo(FILE_PATH_LITERAL('/')).AsUTF8Unsafe());
(...skipping 4454 matching lines...) Expand 10 before | Expand all | Expand 10 after
5159 // RenderFrameImpl. 5148 // RenderFrameImpl.
5160 } 5149 }
5161 5150
5162 // PlzNavigate 5151 // PlzNavigate
5163 void RenderFrameImpl::OnFailedNavigation( 5152 void RenderFrameImpl::OnFailedNavigation(
5164 const CommonNavigationParams& common_params, 5153 const CommonNavigationParams& common_params,
5165 const RequestNavigationParams& request_params, 5154 const RequestNavigationParams& request_params,
5166 bool has_stale_copy_in_cache, 5155 bool has_stale_copy_in_cache,
5167 int error_code) { 5156 int error_code) {
5168 DCHECK(IsBrowserSideNavigationEnabled()); 5157 DCHECK(IsBrowserSideNavigationEnabled());
5169 bool is_reload = IsReload(common_params.navigation_type); 5158 bool is_reload =
5159 FrameMsg_Navigate_Type::IsReload(common_params.navigation_type);
5170 RenderFrameImpl::PrepareRenderViewForNavigation( 5160 RenderFrameImpl::PrepareRenderViewForNavigation(
5171 common_params.url, request_params); 5161 common_params.url, request_params);
5172 5162
5173 GetContentClient()->SetActiveURL(common_params.url); 5163 GetContentClient()->SetActiveURL(common_params.url);
5174 5164
5175 // If this frame isn't in the same process as the main frame, it may naively 5165 // If this frame isn't in the same process as the main frame, it may naively
5176 // assume that this is the first navigation in the iframe, but this may not 5166 // assume that this is the first navigation in the iframe, but this may not
5177 // actually be the case. Inform the frame's state machine if this frame has 5167 // actually be the case. Inform the frame's state machine if this frame has
5178 // already committed other loads. 5168 // already committed other loads.
5179 if (request_params.has_committed_real_load && frame_->parent()) 5169 if (request_params.has_committed_real_load && frame_->parent())
5180 frame_->setCommittedFirstRealLoad(); 5170 frame_->setCommittedFirstRealLoad();
5181 5171
5182 pending_navigation_params_.reset(new NavigationParams( 5172 pending_navigation_params_.reset(new NavigationParams(
5183 common_params, StartNavigationParams(), request_params)); 5173 common_params, StartNavigationParams(), request_params));
5184 5174
5185 // Send the provisional load failure. 5175 // Send the provisional load failure.
5186 blink::WebURLError error = 5176 blink::WebURLError error =
5187 CreateWebURLError(common_params.url, has_stale_copy_in_cache, error_code); 5177 CreateWebURLError(common_params.url, has_stale_copy_in_cache, error_code);
5188 WebURLRequest failed_request = CreateURLRequestForNavigation( 5178 WebURLRequest failed_request = CreateURLRequestForNavigation(
5189 common_params, std::unique_ptr<StreamOverrideParameters>(), 5179 common_params, std::unique_ptr<StreamOverrideParameters>(),
5190 frame_->isViewSourceModeEnabled(), request_params.nav_entry_id); 5180 frame_->isViewSourceModeEnabled(),
5181 false, // is_same_document_navigation
5182 request_params.nav_entry_id);
5191 5183
5192 if (!ShouldDisplayErrorPageForFailedLoad(error_code, common_params.url)) { 5184 if (!ShouldDisplayErrorPageForFailedLoad(error_code, common_params.url)) {
5193 // The browser expects this frame to be loading an error page. Inform it 5185 // The browser expects this frame to be loading an error page. Inform it
5194 // that the load stopped. 5186 // that the load stopped.
5195 Send(new FrameHostMsg_DidStopLoading(routing_id_)); 5187 Send(new FrameHostMsg_DidStopLoading(routing_id_));
5196 browser_side_navigation_pending_ = false; 5188 browser_side_navigation_pending_ = false;
5197 return; 5189 return;
5198 } 5190 }
5199 5191
5200 // On load failure, a frame can ask its owner to render fallback content. 5192 // 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
5807 5799
5808 void RenderFrameImpl::NavigateInternal( 5800 void RenderFrameImpl::NavigateInternal(
5809 const CommonNavigationParams& common_params, 5801 const CommonNavigationParams& common_params,
5810 const StartNavigationParams& start_params, 5802 const StartNavigationParams& start_params,
5811 const RequestNavigationParams& request_params, 5803 const RequestNavigationParams& request_params,
5812 std::unique_ptr<StreamOverrideParameters> stream_params) { 5804 std::unique_ptr<StreamOverrideParameters> stream_params) {
5813 bool browser_side_navigation = IsBrowserSideNavigationEnabled(); 5805 bool browser_side_navigation = IsBrowserSideNavigationEnabled();
5814 5806
5815 // Lower bound for browser initiated navigation start time. 5807 // Lower bound for browser initiated navigation start time.
5816 base::TimeTicks renderer_navigation_start = base::TimeTicks::Now(); 5808 base::TimeTicks renderer_navigation_start = base::TimeTicks::Now();
5817 bool is_reload = IsReload(common_params.navigation_type); 5809 bool is_reload =
5810 FrameMsg_Navigate_Type::IsReload(common_params.navigation_type);
5818 bool is_history_navigation = request_params.page_state.IsValid(); 5811 bool is_history_navigation = request_params.page_state.IsValid();
5819 WebCachePolicy cache_policy = WebCachePolicy::UseProtocolCachePolicy; 5812 WebCachePolicy cache_policy = WebCachePolicy::UseProtocolCachePolicy;
5820 RenderFrameImpl::PrepareRenderViewForNavigation( 5813 RenderFrameImpl::PrepareRenderViewForNavigation(
5821 common_params.url, request_params); 5814 common_params.url, request_params);
5822 5815
5823 GetContentClient()->SetActiveURL(common_params.url); 5816 GetContentClient()->SetActiveURL(common_params.url);
5824 5817
5825 // If this frame isn't in the same process as the main frame, it may naively 5818 // If this frame isn't in the same process as the main frame, it may naively
5826 // assume that this is the first navigation in the iframe, but this may not 5819 // assume that this is the first navigation in the iframe, but this may not
5827 // actually be the case. Inform the frame's state machine if this frame has 5820 // actually be the case. Inform the frame's state machine if this frame has
(...skipping 25 matching lines...) Expand all
5853 // Create parameters for a standard navigation, indicating whether it should 5846 // Create parameters for a standard navigation, indicating whether it should
5854 // replace the current NavigationEntry. 5847 // replace the current NavigationEntry.
5855 blink::WebFrameLoadType load_type = 5848 blink::WebFrameLoadType load_type =
5856 common_params.should_replace_current_entry 5849 common_params.should_replace_current_entry
5857 ? blink::WebFrameLoadType::ReplaceCurrentItem 5850 ? blink::WebFrameLoadType::ReplaceCurrentItem
5858 : blink::WebFrameLoadType::Standard; 5851 : blink::WebFrameLoadType::Standard;
5859 blink::WebHistoryLoadType history_load_type = 5852 blink::WebHistoryLoadType history_load_type =
5860 blink::WebHistoryDifferentDocumentLoad; 5853 blink::WebHistoryDifferentDocumentLoad;
5861 bool should_load_request = false; 5854 bool should_load_request = false;
5862 WebHistoryItem item_for_history_navigation; 5855 WebHistoryItem item_for_history_navigation;
5863 WebURLRequest request = 5856 WebURLRequest request = CreateURLRequestForNavigation(
5864 CreateURLRequestForNavigation(common_params, std::move(stream_params), 5857 common_params, std::move(stream_params),
5865 frame_->isViewSourceModeEnabled(), 5858 frame_->isViewSourceModeEnabled(),
5866 request_params.nav_entry_id); 5859 FrameMsg_Navigate_Type::IsSameDocument(common_params.navigation_type),
5860 request_params.nav_entry_id);
5867 request.setFrameType(IsTopLevelNavigation(frame_) 5861 request.setFrameType(IsTopLevelNavigation(frame_)
5868 ? blink::WebURLRequest::FrameTypeTopLevel 5862 ? blink::WebURLRequest::FrameTypeTopLevel
5869 : blink::WebURLRequest::FrameTypeNested); 5863 : blink::WebURLRequest::FrameTypeNested);
5870 5864
5871 if (IsBrowserSideNavigationEnabled() && common_params.post_data) 5865 if (IsBrowserSideNavigationEnabled() && common_params.post_data)
5872 request.setHTTPBody(GetWebHTTPBodyForRequestBody(common_params.post_data)); 5866 request.setHTTPBody(GetWebHTTPBodyForRequestBody(common_params.post_data));
5873 5867
5874 // Used to determine whether this frame is actually loading a request as part 5868 // Used to determine whether this frame is actually loading a request as part
5875 // of a history navigation. 5869 // of a history navigation.
5876 bool has_history_navigation_in_frame = false; 5870 bool has_history_navigation_in_frame = false;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
5910 // browser. 5904 // browser.
5911 DCHECK_NE(0, request_params.nav_entry_id); 5905 DCHECK_NE(0, request_params.nav_entry_id);
5912 std::unique_ptr<HistoryEntry> entry = 5906 std::unique_ptr<HistoryEntry> entry =
5913 PageStateToHistoryEntry(request_params.page_state); 5907 PageStateToHistoryEntry(request_params.page_state);
5914 if (entry) { 5908 if (entry) {
5915 // The browser process sends a single WebHistoryItem for this frame. 5909 // The browser process sends a single WebHistoryItem for this frame.
5916 // TODO(creis): Change PageState to FrameState. In the meantime, we 5910 // TODO(creis): Change PageState to FrameState. In the meantime, we
5917 // store the relevant frame's WebHistoryItem in the root of the 5911 // store the relevant frame's WebHistoryItem in the root of the
5918 // PageState. 5912 // PageState.
5919 item_for_history_navigation = entry->root(); 5913 item_for_history_navigation = entry->root();
5920 history_load_type = request_params.is_same_document_history_load 5914 switch (common_params.navigation_type) {
5921 ? blink::WebHistorySameDocumentLoad 5915 case FrameMsg_Navigate_Type::RELOAD:
5922 : blink::WebHistoryDifferentDocumentLoad; 5916 case FrameMsg_Navigate_Type::RELOAD_BYPASSING_CACHE:
5917 case FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL:
5918 case FrameMsg_Navigate_Type::RESTORE:
5919 case FrameMsg_Navigate_Type::RESTORE_WITH_POST:
5920 case FrameMsg_Navigate_Type::HISTORY_DIFFERENT_DOCUMENT:
5921 history_load_type = blink::WebHistoryDifferentDocumentLoad;
5922 break;
5923 case FrameMsg_Navigate_Type::HISTORY_SAME_DOCUMENT:
5924 history_load_type = blink::WebHistorySameDocumentLoad;
5925 break;
5926 default:
5927 NOTREACHED();
5928 history_load_type = blink::WebHistoryDifferentDocumentLoad;
5929 }
5923 load_type = request_params.is_history_navigation_in_new_child 5930 load_type = request_params.is_history_navigation_in_new_child
5924 ? blink::WebFrameLoadType::InitialHistoryLoad 5931 ? blink::WebFrameLoadType::InitialHistoryLoad
5925 : blink::WebFrameLoadType::BackForward; 5932 : blink::WebFrameLoadType::BackForward;
5926 should_load_request = true; 5933 should_load_request = true;
5927 5934
5928 // Keep track of which subframes the browser process has history items 5935 // Keep track of which subframes the browser process has history items
5929 // for during a history navigation. 5936 // for during a history navigation.
5930 history_subframe_unique_names_ = request_params.subframe_unique_names; 5937 history_subframe_unique_names_ = request_params.subframe_unique_names;
5931 5938
5932 if (history_load_type == blink::WebHistorySameDocumentLoad) { 5939 if (history_load_type == blink::WebHistorySameDocumentLoad) {
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after
6808 // event target. Potentially a Pepper plugin will receive the event. 6815 // event target. Potentially a Pepper plugin will receive the event.
6809 // In order to tell whether a plugin gets the last mouse event and which it 6816 // In order to tell whether a plugin gets the last mouse event and which it
6810 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets 6817 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets
6811 // the event, it will notify us via DidReceiveMouseEvent() and set itself as 6818 // the event, it will notify us via DidReceiveMouseEvent() and set itself as
6812 // |pepper_last_mouse_event_target_|. 6819 // |pepper_last_mouse_event_target_|.
6813 pepper_last_mouse_event_target_ = nullptr; 6820 pepper_last_mouse_event_target_ = nullptr;
6814 #endif 6821 #endif
6815 } 6822 }
6816 6823
6817 } // namespace content 6824 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698