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

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

Issue 2584513003: PlzNavigate: identify same-page browser-initiated navigation. (Closed)
Patch Set: Addressed comment (@nasko) #2. Created 3 years, 11 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 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 } 548 }
549 549
550 // Returns false unless this is a top-level navigation. 550 // Returns false unless this is a top-level navigation.
551 bool IsTopLevelNavigation(WebFrame* frame) { 551 bool IsTopLevelNavigation(WebFrame* frame) {
552 return frame->parent() == NULL; 552 return frame->parent() == NULL;
553 } 553 }
554 554
555 WebURLRequest CreateURLRequestForNavigation( 555 WebURLRequest CreateURLRequestForNavigation(
556 const CommonNavigationParams& common_params, 556 const CommonNavigationParams& common_params,
557 std::unique_ptr<StreamOverrideParameters> stream_override, 557 std::unique_ptr<StreamOverrideParameters> stream_override,
558 bool is_view_source_mode_enabled) { 558 bool is_view_source_mode_enabled,
559 bool is_same_document_navigation) {
559 WebURLRequest request(common_params.url); 560 WebURLRequest request(common_params.url);
560 if (is_view_source_mode_enabled) 561 if (is_view_source_mode_enabled)
561 request.setCachePolicy(WebCachePolicy::ReturnCacheDataElseLoad); 562 request.setCachePolicy(WebCachePolicy::ReturnCacheDataElseLoad);
562 563
563 request.setHTTPMethod(WebString::fromUTF8(common_params.method)); 564 request.setHTTPMethod(WebString::fromUTF8(common_params.method));
564 if (common_params.referrer.url.is_valid()) { 565 if (common_params.referrer.url.is_valid()) {
565 WebString web_referrer = WebSecurityPolicy::generateReferrerHeader( 566 WebString web_referrer = WebSecurityPolicy::generateReferrerHeader(
566 common_params.referrer.policy, 567 common_params.referrer.policy,
567 common_params.url, 568 common_params.url,
568 WebString::fromUTF8(common_params.referrer.url.spec())); 569 WebString::fromUTF8(common_params.referrer.url.spec()));
569 if (!web_referrer.isEmpty()) { 570 if (!web_referrer.isEmpty()) {
570 request.setHTTPReferrer(web_referrer, common_params.referrer.policy); 571 request.setHTTPReferrer(web_referrer, common_params.referrer.policy);
571 request.addHTTPOriginIfNeeded( 572 request.addHTTPOriginIfNeeded(
572 WebSecurityOrigin(url::Origin(common_params.referrer.url))); 573 WebSecurityOrigin(url::Origin(common_params.referrer.url)));
573 } 574 }
574 } 575 }
575 576
577 request.setIsSameDocumentNavigation(is_same_document_navigation);
576 request.setPreviewsState( 578 request.setPreviewsState(
577 static_cast<WebURLRequest::PreviewsState>(common_params.previews_state)); 579 static_cast<WebURLRequest::PreviewsState>(common_params.previews_state));
578 580
579 RequestExtraData* extra_data = new RequestExtraData(); 581 RequestExtraData* extra_data = new RequestExtraData();
580 extra_data->set_stream_override(std::move(stream_override)); 582 extra_data->set_stream_override(std::move(stream_override));
581 request.setExtraData(extra_data); 583 request.setExtraData(extra_data);
582 584
583 // Set the ui timestamp for this navigation. Currently the timestamp here is 585 // Set the ui timestamp for this navigation. Currently the timestamp here is
584 // only non empty when the navigation was triggered by an Android intent. The 586 // only non empty when the navigation was triggered by an Android intent. The
585 // timestamp is converted to a double version supported by blink. It will be 587 // timestamp is converted to a double version supported by blink. It will be
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 // version supported by blink. It will be passed back to the renderer in the 625 // version supported by blink. It will be passed back to the renderer in the
624 // CommitNavigation IPC, and then back to the browser again in the 626 // CommitNavigation IPC, and then back to the browser again in the
625 // DidCommitProvisionalLoad and the DocumentLoadComplete IPCs. 627 // DidCommitProvisionalLoad and the DocumentLoadComplete IPCs.
626 base::TimeTicks ui_timestamp = 628 base::TimeTicks ui_timestamp =
627 base::TimeTicks() + 629 base::TimeTicks() +
628 base::TimeDelta::FromSecondsD(info.urlRequest.uiStartTime()); 630 base::TimeDelta::FromSecondsD(info.urlRequest.uiStartTime());
629 FrameMsg_UILoadMetricsReportType::Value report_type = 631 FrameMsg_UILoadMetricsReportType::Value report_type =
630 static_cast<FrameMsg_UILoadMetricsReportType::Value>( 632 static_cast<FrameMsg_UILoadMetricsReportType::Value>(
631 info.urlRequest.inputPerfMetricReportPolicy()); 633 info.urlRequest.inputPerfMetricReportPolicy());
632 634
635 // No history-navigation is expected to happen.
636 DCHECK(info.navigationType != blink::WebNavigationTypeBackForward);
637
633 FrameMsg_Navigate_Type::Value navigation_type = 638 FrameMsg_Navigate_Type::Value navigation_type =
634 info.navigationType == blink::WebNavigationTypeReload 639 info.navigationType == blink::WebNavigationTypeReload
635 ? FrameMsg_Navigate_Type::RELOAD 640 ? FrameMsg_Navigate_Type::RELOAD
636 : FrameMsg_Navigate_Type::NORMAL; 641 // No same-document navigation is expected because it is loaded
642 // immediately by the FrameLoader.
643 : FrameMsg_Navigate_Type::DIFFERENT_DOCUMENT;
637 644
638 const RequestExtraData* extra_data = 645 const RequestExtraData* extra_data =
639 static_cast<RequestExtraData*>(info.urlRequest.getExtraData()); 646 static_cast<RequestExtraData*>(info.urlRequest.getExtraData());
640 DCHECK(extra_data); 647 DCHECK(extra_data);
641 return CommonNavigationParams( 648 return CommonNavigationParams(
642 info.urlRequest.url(), referrer, extra_data->transition_type(), 649 info.urlRequest.url(), referrer, extra_data->transition_type(),
643 navigation_type, true, info.replacesCurrentHistoryItem, ui_timestamp, 650 navigation_type, true, info.replacesCurrentHistoryItem, ui_timestamp,
644 report_type, GURL(), GURL(), 651 report_type, GURL(), GURL(),
645 static_cast<PreviewsState>(info.urlRequest.getPreviewsState()), 652 static_cast<PreviewsState>(info.urlRequest.getPreviewsState()),
646 base::TimeTicks::Now(), info.urlRequest.httpMethod().latin1(), 653 base::TimeTicks::Now(), info.urlRequest.httpMethod().latin1(),
647 GetRequestBodyForWebURLRequest(info.urlRequest)); 654 GetRequestBodyForWebURLRequest(info.urlRequest));
648 } 655 }
649 656
650 media::Context3D GetSharedMainThreadContext3D( 657 media::Context3D GetSharedMainThreadContext3D(
651 scoped_refptr<ui::ContextProviderCommandBuffer> provider) { 658 scoped_refptr<ui::ContextProviderCommandBuffer> provider) {
652 if (!provider) 659 if (!provider)
653 return media::Context3D(); 660 return media::Context3D();
654 return media::Context3D(provider->ContextGL(), provider->GrContext()); 661 return media::Context3D(provider->ContextGL(), provider->GrContext());
655 } 662 }
656 663
657 bool IsReload(FrameMsg_Navigate_Type::Value navigation_type) {
658 switch (navigation_type) {
659 case FrameMsg_Navigate_Type::RELOAD:
660 case FrameMsg_Navigate_Type::RELOAD_BYPASSING_CACHE:
661 case FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL:
662 return true;
663 case FrameMsg_Navigate_Type::RESTORE:
664 case FrameMsg_Navigate_Type::RESTORE_WITH_POST:
665 case FrameMsg_Navigate_Type::NORMAL:
666 return false;
667 }
668 NOTREACHED();
669 return false;
670 }
671
672 WebFrameLoadType ReloadFrameLoadTypeFor( 664 WebFrameLoadType ReloadFrameLoadTypeFor(
673 FrameMsg_Navigate_Type::Value navigation_type) { 665 FrameMsg_Navigate_Type::Value navigation_type) {
674 switch (navigation_type) { 666 switch (navigation_type) {
675 case FrameMsg_Navigate_Type::RELOAD: 667 case FrameMsg_Navigate_Type::RELOAD:
676 case FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL: 668 case FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL:
677 return WebFrameLoadType::ReloadMainResource; 669 return WebFrameLoadType::ReloadMainResource;
670
678 case FrameMsg_Navigate_Type::RELOAD_BYPASSING_CACHE: 671 case FrameMsg_Navigate_Type::RELOAD_BYPASSING_CACHE:
679 return WebFrameLoadType::ReloadBypassingCache; 672 return WebFrameLoadType::ReloadBypassingCache;
680 case FrameMsg_Navigate_Type::RESTORE: 673
681 case FrameMsg_Navigate_Type::RESTORE_WITH_POST: 674 default:
682 case FrameMsg_Navigate_Type::NORMAL:
683 NOTREACHED(); 675 NOTREACHED();
684 return WebFrameLoadType::Standard; 676 return WebFrameLoadType::Standard;
685 } 677 }
686 NOTREACHED();
687 return WebFrameLoadType::Standard;
688 } 678 }
689 679
690 RenderFrameImpl::CreateRenderFrameImplFunction g_create_render_frame_impl = 680 RenderFrameImpl::CreateRenderFrameImplFunction g_create_render_frame_impl =
691 nullptr; 681 nullptr;
692 682
693 WebString ConvertRelativePathToHtmlAttribute(const base::FilePath& path) { 683 WebString ConvertRelativePathToHtmlAttribute(const base::FilePath& path) {
694 DCHECK(!path.IsAbsolute()); 684 DCHECK(!path.IsAbsolute());
695 return WebString::fromUTF8( 685 return WebString::fromUTF8(
696 std::string("./") + 686 std::string("./") +
697 path.NormalizePathSeparatorsTo(FILE_PATH_LITERAL('/')).AsUTF8Unsafe()); 687 path.NormalizePathSeparatorsTo(FILE_PATH_LITERAL('/')).AsUTF8Unsafe());
(...skipping 4489 matching lines...) Expand 10 before | Expand all | Expand 10 after
5187 browser_side_navigation_pending_ = false; 5177 browser_side_navigation_pending_ = false;
5188 } 5178 }
5189 5179
5190 // PlzNavigate 5180 // PlzNavigate
5191 void RenderFrameImpl::OnFailedNavigation( 5181 void RenderFrameImpl::OnFailedNavigation(
5192 const CommonNavigationParams& common_params, 5182 const CommonNavigationParams& common_params,
5193 const RequestNavigationParams& request_params, 5183 const RequestNavigationParams& request_params,
5194 bool has_stale_copy_in_cache, 5184 bool has_stale_copy_in_cache,
5195 int error_code) { 5185 int error_code) {
5196 DCHECK(IsBrowserSideNavigationEnabled()); 5186 DCHECK(IsBrowserSideNavigationEnabled());
5197 bool is_reload = IsReload(common_params.navigation_type); 5187 bool is_reload =
5188 FrameMsg_Navigate_Type::IsReload(common_params.navigation_type);
5198 RenderFrameImpl::PrepareRenderViewForNavigation( 5189 RenderFrameImpl::PrepareRenderViewForNavigation(
5199 common_params.url, request_params); 5190 common_params.url, request_params);
5200 5191
5201 GetContentClient()->SetActiveURL(common_params.url); 5192 GetContentClient()->SetActiveURL(common_params.url);
5202 5193
5203 // If this frame isn't in the same process as the main frame, it may naively 5194 // If this frame isn't in the same process as the main frame, it may naively
5204 // assume that this is the first navigation in the iframe, but this may not 5195 // assume that this is the first navigation in the iframe, but this may not
5205 // actually be the case. Inform the frame's state machine if this frame has 5196 // actually be the case. Inform the frame's state machine if this frame has
5206 // already committed other loads. 5197 // already committed other loads.
5207 if (request_params.has_committed_real_load && frame_->parent()) 5198 if (request_params.has_committed_real_load && frame_->parent())
5208 frame_->setCommittedFirstRealLoad(); 5199 frame_->setCommittedFirstRealLoad();
5209 5200
5210 pending_navigation_params_.reset(new NavigationParams( 5201 pending_navigation_params_.reset(new NavigationParams(
5211 common_params, StartNavigationParams(), request_params)); 5202 common_params, StartNavigationParams(), request_params));
5212 5203
5213 // Send the provisional load failure. 5204 // Send the provisional load failure.
5214 blink::WebURLError error = 5205 blink::WebURLError error =
5215 CreateWebURLError(common_params.url, has_stale_copy_in_cache, error_code); 5206 CreateWebURLError(common_params.url, has_stale_copy_in_cache, error_code);
5216 WebURLRequest failed_request = CreateURLRequestForNavigation( 5207 WebURLRequest failed_request = CreateURLRequestForNavigation(
5217 common_params, std::unique_ptr<StreamOverrideParameters>(), 5208 common_params, std::unique_ptr<StreamOverrideParameters>(),
5218 frame_->isViewSourceModeEnabled()); 5209 frame_->isViewSourceModeEnabled(),
5210 false); // is_same_document_navigation
5219 5211
5220 if (!ShouldDisplayErrorPageForFailedLoad(error_code, common_params.url)) { 5212 if (!ShouldDisplayErrorPageForFailedLoad(error_code, common_params.url)) {
5221 // The browser expects this frame to be loading an error page. Inform it 5213 // The browser expects this frame to be loading an error page. Inform it
5222 // that the load stopped. 5214 // that the load stopped.
5223 Send(new FrameHostMsg_DidStopLoading(routing_id_)); 5215 Send(new FrameHostMsg_DidStopLoading(routing_id_));
5224 browser_side_navigation_pending_ = false; 5216 browser_side_navigation_pending_ = false;
5225 return; 5217 return;
5226 } 5218 }
5227 5219
5228 // On load failure, a frame can ask its owner to render fallback content. 5220 // On load failure, a frame can ask its owner to render fallback content.
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
5838 5830
5839 void RenderFrameImpl::NavigateInternal( 5831 void RenderFrameImpl::NavigateInternal(
5840 const CommonNavigationParams& common_params, 5832 const CommonNavigationParams& common_params,
5841 const StartNavigationParams& start_params, 5833 const StartNavigationParams& start_params,
5842 const RequestNavigationParams& request_params, 5834 const RequestNavigationParams& request_params,
5843 std::unique_ptr<StreamOverrideParameters> stream_params) { 5835 std::unique_ptr<StreamOverrideParameters> stream_params) {
5844 bool browser_side_navigation = IsBrowserSideNavigationEnabled(); 5836 bool browser_side_navigation = IsBrowserSideNavigationEnabled();
5845 5837
5846 // Lower bound for browser initiated navigation start time. 5838 // Lower bound for browser initiated navigation start time.
5847 base::TimeTicks renderer_navigation_start = base::TimeTicks::Now(); 5839 base::TimeTicks renderer_navigation_start = base::TimeTicks::Now();
5848 bool is_reload = IsReload(common_params.navigation_type); 5840 bool is_reload =
5841 FrameMsg_Navigate_Type::IsReload(common_params.navigation_type);
5849 bool is_history_navigation = request_params.page_state.IsValid(); 5842 bool is_history_navigation = request_params.page_state.IsValid();
5850 WebCachePolicy cache_policy = WebCachePolicy::UseProtocolCachePolicy; 5843 WebCachePolicy cache_policy = WebCachePolicy::UseProtocolCachePolicy;
5851 RenderFrameImpl::PrepareRenderViewForNavigation( 5844 RenderFrameImpl::PrepareRenderViewForNavigation(
5852 common_params.url, request_params); 5845 common_params.url, request_params);
5853 5846
5854 GetContentClient()->SetActiveURL(common_params.url); 5847 GetContentClient()->SetActiveURL(common_params.url);
5855 5848
5856 // If this frame isn't in the same process as the main frame, it may naively 5849 // If this frame isn't in the same process as the main frame, it may naively
5857 // assume that this is the first navigation in the iframe, but this may not 5850 // assume that this is the first navigation in the iframe, but this may not
5858 // actually be the case. Inform the frame's state machine if this frame has 5851 // actually be the case. Inform the frame's state machine if this frame has
(...skipping 29 matching lines...) Expand all
5888 // Create parameters for a standard navigation, indicating whether it should 5881 // Create parameters for a standard navigation, indicating whether it should
5889 // replace the current NavigationEntry. 5882 // replace the current NavigationEntry.
5890 blink::WebFrameLoadType load_type = 5883 blink::WebFrameLoadType load_type =
5891 common_params.should_replace_current_entry 5884 common_params.should_replace_current_entry
5892 ? blink::WebFrameLoadType::ReplaceCurrentItem 5885 ? blink::WebFrameLoadType::ReplaceCurrentItem
5893 : blink::WebFrameLoadType::Standard; 5886 : blink::WebFrameLoadType::Standard;
5894 blink::WebHistoryLoadType history_load_type = 5887 blink::WebHistoryLoadType history_load_type =
5895 blink::WebHistoryDifferentDocumentLoad; 5888 blink::WebHistoryDifferentDocumentLoad;
5896 bool should_load_request = false; 5889 bool should_load_request = false;
5897 WebHistoryItem item_for_history_navigation; 5890 WebHistoryItem item_for_history_navigation;
5898 WebURLRequest request = 5891
5899 CreateURLRequestForNavigation(common_params, std::move(stream_params), 5892 WebURLRequest request = CreateURLRequestForNavigation(
5900 frame_->isViewSourceModeEnabled()); 5893 common_params, std::move(stream_params),
5894 frame_->isViewSourceModeEnabled(),
5895 FrameMsg_Navigate_Type::IsSameDocument(common_params.navigation_type));
5901 request.setFrameType(IsTopLevelNavigation(frame_) 5896 request.setFrameType(IsTopLevelNavigation(frame_)
5902 ? blink::WebURLRequest::FrameTypeTopLevel 5897 ? blink::WebURLRequest::FrameTypeTopLevel
5903 : blink::WebURLRequest::FrameTypeNested); 5898 : blink::WebURLRequest::FrameTypeNested);
5904 5899
5905 if (IsBrowserSideNavigationEnabled() && common_params.post_data) 5900 if (IsBrowserSideNavigationEnabled() && common_params.post_data)
5906 request.setHTTPBody(GetWebHTTPBodyForRequestBody(common_params.post_data)); 5901 request.setHTTPBody(GetWebHTTPBodyForRequestBody(common_params.post_data));
5907 5902
5908 // Used to determine whether this frame is actually loading a request as part 5903 // Used to determine whether this frame is actually loading a request as part
5909 // of a history navigation. 5904 // of a history navigation.
5910 bool has_history_navigation_in_frame = false; 5905 bool has_history_navigation_in_frame = false;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
5958 render_view_->history_controller()->GoToEntry( 5953 render_view_->history_controller()->GoToEntry(
5959 frame_, std::move(entry), std::move(navigation_params), 5954 frame_, std::move(entry), std::move(navigation_params),
5960 cache_policy); 5955 cache_policy);
5961 } else { 5956 } else {
5962 // In --site-per-process, the browser process sends a single 5957 // In --site-per-process, the browser process sends a single
5963 // WebHistoryItem destined for this frame. 5958 // WebHistoryItem destined for this frame.
5964 // TODO(creis): Change PageState to FrameState. In the meantime, we 5959 // TODO(creis): Change PageState to FrameState. In the meantime, we
5965 // store the relevant frame's WebHistoryItem in the root of the 5960 // store the relevant frame's WebHistoryItem in the root of the
5966 // PageState. 5961 // PageState.
5967 item_for_history_navigation = entry->root(); 5962 item_for_history_navigation = entry->root();
5968 history_load_type = request_params.is_same_document_history_load 5963 switch (common_params.navigation_type) {
5969 ? blink::WebHistorySameDocumentLoad 5964 case FrameMsg_Navigate_Type::RELOAD:
5970 : blink::WebHistoryDifferentDocumentLoad; 5965 case FrameMsg_Navigate_Type::RELOAD_BYPASSING_CACHE:
5966 case FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL:
5967 case FrameMsg_Navigate_Type::RESTORE:
5968 case FrameMsg_Navigate_Type::RESTORE_WITH_POST:
5969 case FrameMsg_Navigate_Type::HISTORY_DIFFERENT_DOCUMENT:
5970 history_load_type = blink::WebHistoryDifferentDocumentLoad;
5971 break;
5972 case FrameMsg_Navigate_Type::HISTORY_SAME_DOCUMENT:
5973 history_load_type = blink::WebHistorySameDocumentLoad;
5974 break;
5975 default:
5976 NOTREACHED();
5977 history_load_type = blink::WebHistoryDifferentDocumentLoad;
5978 }
5971 load_type = request_params.is_history_navigation_in_new_child 5979 load_type = request_params.is_history_navigation_in_new_child
5972 ? blink::WebFrameLoadType::InitialHistoryLoad 5980 ? blink::WebFrameLoadType::InitialHistoryLoad
5973 : blink::WebFrameLoadType::BackForward; 5981 : blink::WebFrameLoadType::BackForward;
5974 should_load_request = true; 5982 should_load_request = true;
5975 5983
5976 // Keep track of which subframes the browser process has history items 5984 // Keep track of which subframes the browser process has history items
5977 // for during a history navigation. 5985 // for during a history navigation.
5978 history_subframe_unique_names_ = request_params.subframe_unique_names; 5986 history_subframe_unique_names_ = request_params.subframe_unique_names;
5979 5987
5980 if (history_load_type == blink::WebHistorySameDocumentLoad) { 5988 if (history_load_type == blink::WebHistorySameDocumentLoad) {
(...skipping 895 matching lines...) Expand 10 before | Expand all | Expand 10 after
6876 // event target. Potentially a Pepper plugin will receive the event. 6884 // event target. Potentially a Pepper plugin will receive the event.
6877 // In order to tell whether a plugin gets the last mouse event and which it 6885 // In order to tell whether a plugin gets the last mouse event and which it
6878 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets 6886 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets
6879 // the event, it will notify us via DidReceiveMouseEvent() and set itself as 6887 // the event, it will notify us via DidReceiveMouseEvent() and set itself as
6880 // |pepper_last_mouse_event_target_|. 6888 // |pepper_last_mouse_event_target_|.
6881 pepper_last_mouse_event_target_ = nullptr; 6889 pepper_last_mouse_event_target_ = nullptr;
6882 #endif 6890 #endif
6883 } 6891 }
6884 6892
6885 } // namespace content 6893 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698