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

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

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

Powered by Google App Engine
This is Rietveld 408576698