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

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

Issue 2584513003: PlzNavigate: identify same-page browser-initiated navigation. (Closed)
Patch Set: Allow renderer-initiated reloads. 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 4479 matching lines...) Expand 10 before | Expand all | Expand 10 after
5176 browser_side_navigation_pending_ = false; 5166 browser_side_navigation_pending_ = false;
5177 } 5167 }
5178 5168
5179 // PlzNavigate 5169 // PlzNavigate
5180 void RenderFrameImpl::OnFailedNavigation( 5170 void RenderFrameImpl::OnFailedNavigation(
5181 const CommonNavigationParams& common_params, 5171 const CommonNavigationParams& common_params,
5182 const RequestNavigationParams& request_params, 5172 const RequestNavigationParams& request_params,
5183 bool has_stale_copy_in_cache, 5173 bool has_stale_copy_in_cache,
5184 int error_code) { 5174 int error_code) {
5185 DCHECK(IsBrowserSideNavigationEnabled()); 5175 DCHECK(IsBrowserSideNavigationEnabled());
5186 bool is_reload = IsReload(common_params.navigation_type); 5176 bool is_reload =
5177 FrameMsg_Navigate_Type::IsReload(common_params.navigation_type);
5187 RenderFrameImpl::PrepareRenderViewForNavigation( 5178 RenderFrameImpl::PrepareRenderViewForNavigation(
5188 common_params.url, request_params); 5179 common_params.url, request_params);
5189 5180
5190 GetContentClient()->SetActiveURL(common_params.url); 5181 GetContentClient()->SetActiveURL(common_params.url);
5191 5182
5192 // If this frame isn't in the same process as the main frame, it may naively 5183 // If this frame isn't in the same process as the main frame, it may naively
5193 // assume that this is the first navigation in the iframe, but this may not 5184 // assume that this is the first navigation in the iframe, but this may not
5194 // actually be the case. Inform the frame's state machine if this frame has 5185 // actually be the case. Inform the frame's state machine if this frame has
5195 // already committed other loads. 5186 // already committed other loads.
5196 if (request_params.has_committed_real_load && frame_->parent()) 5187 if (request_params.has_committed_real_load && frame_->parent())
5197 frame_->setCommittedFirstRealLoad(); 5188 frame_->setCommittedFirstRealLoad();
5198 5189
5199 pending_navigation_params_.reset(new NavigationParams( 5190 pending_navigation_params_.reset(new NavigationParams(
5200 common_params, StartNavigationParams(), request_params)); 5191 common_params, StartNavigationParams(), request_params));
5201 5192
5202 // Send the provisional load failure. 5193 // Send the provisional load failure.
5203 blink::WebURLError error = 5194 blink::WebURLError error =
5204 CreateWebURLError(common_params.url, has_stale_copy_in_cache, error_code); 5195 CreateWebURLError(common_params.url, has_stale_copy_in_cache, error_code);
5205 WebURLRequest failed_request = CreateURLRequestForNavigation( 5196 WebURLRequest failed_request = CreateURLRequestForNavigation(
5206 common_params, std::unique_ptr<StreamOverrideParameters>(), 5197 common_params, std::unique_ptr<StreamOverrideParameters>(),
5207 frame_->isViewSourceModeEnabled()); 5198 frame_->isViewSourceModeEnabled(),
5199 false); // is_same_document_navigation
5208 5200
5209 if (!ShouldDisplayErrorPageForFailedLoad(error_code, common_params.url)) { 5201 if (!ShouldDisplayErrorPageForFailedLoad(error_code, common_params.url)) {
5210 // The browser expects this frame to be loading an error page. Inform it 5202 // The browser expects this frame to be loading an error page. Inform it
5211 // that the load stopped. 5203 // that the load stopped.
5212 Send(new FrameHostMsg_DidStopLoading(routing_id_)); 5204 Send(new FrameHostMsg_DidStopLoading(routing_id_));
5213 browser_side_navigation_pending_ = false; 5205 browser_side_navigation_pending_ = false;
5214 return; 5206 return;
5215 } 5207 }
5216 5208
5217 // On load failure, a frame can ask its owner to render fallback content. 5209 // 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
5841 5833
5842 void RenderFrameImpl::NavigateInternal( 5834 void RenderFrameImpl::NavigateInternal(
5843 const CommonNavigationParams& common_params, 5835 const CommonNavigationParams& common_params,
5844 const StartNavigationParams& start_params, 5836 const StartNavigationParams& start_params,
5845 const RequestNavigationParams& request_params, 5837 const RequestNavigationParams& request_params,
5846 std::unique_ptr<StreamOverrideParameters> stream_params) { 5838 std::unique_ptr<StreamOverrideParameters> stream_params) {
5847 bool browser_side_navigation = IsBrowserSideNavigationEnabled(); 5839 bool browser_side_navigation = IsBrowserSideNavigationEnabled();
5848 5840
5849 // Lower bound for browser initiated navigation start time. 5841 // Lower bound for browser initiated navigation start time.
5850 base::TimeTicks renderer_navigation_start = base::TimeTicks::Now(); 5842 base::TimeTicks renderer_navigation_start = base::TimeTicks::Now();
5851 bool is_reload = IsReload(common_params.navigation_type); 5843 bool is_reload =
5844 FrameMsg_Navigate_Type::IsReload(common_params.navigation_type);
5852 bool is_history_navigation = request_params.page_state.IsValid(); 5845 bool is_history_navigation = request_params.page_state.IsValid();
5853 WebCachePolicy cache_policy = WebCachePolicy::UseProtocolCachePolicy; 5846 WebCachePolicy cache_policy = WebCachePolicy::UseProtocolCachePolicy;
5854 RenderFrameImpl::PrepareRenderViewForNavigation( 5847 RenderFrameImpl::PrepareRenderViewForNavigation(
5855 common_params.url, request_params); 5848 common_params.url, request_params);
5856 5849
5857 GetContentClient()->SetActiveURL(common_params.url); 5850 GetContentClient()->SetActiveURL(common_params.url);
5858 5851
5859 // If this frame isn't in the same process as the main frame, it may naively 5852 // If this frame isn't in the same process as the main frame, it may naively
5860 // assume that this is the first navigation in the iframe, but this may not 5853 // assume that this is the first navigation in the iframe, but this may not
5861 // actually be the case. Inform the frame's state machine if this frame has 5854 // actually be the case. Inform the frame's state machine if this frame has
(...skipping 29 matching lines...) Expand all
5891 // Create parameters for a standard navigation, indicating whether it should 5884 // Create parameters for a standard navigation, indicating whether it should
5892 // replace the current NavigationEntry. 5885 // replace the current NavigationEntry.
5893 blink::WebFrameLoadType load_type = 5886 blink::WebFrameLoadType load_type =
5894 common_params.should_replace_current_entry 5887 common_params.should_replace_current_entry
5895 ? blink::WebFrameLoadType::ReplaceCurrentItem 5888 ? blink::WebFrameLoadType::ReplaceCurrentItem
5896 : blink::WebFrameLoadType::Standard; 5889 : blink::WebFrameLoadType::Standard;
5897 blink::WebHistoryLoadType history_load_type = 5890 blink::WebHistoryLoadType history_load_type =
5898 blink::WebHistoryDifferentDocumentLoad; 5891 blink::WebHistoryDifferentDocumentLoad;
5899 bool should_load_request = false; 5892 bool should_load_request = false;
5900 WebHistoryItem item_for_history_navigation; 5893 WebHistoryItem item_for_history_navigation;
5901 WebURLRequest request = 5894
5902 CreateURLRequestForNavigation(common_params, std::move(stream_params), 5895 WebURLRequest request = CreateURLRequestForNavigation(
5903 frame_->isViewSourceModeEnabled()); 5896 common_params, std::move(stream_params),
5897 frame_->isViewSourceModeEnabled(),
5898 FrameMsg_Navigate_Type::IsSameDocument(common_params.navigation_type));
5904 request.setFrameType(IsTopLevelNavigation(frame_) 5899 request.setFrameType(IsTopLevelNavigation(frame_)
5905 ? blink::WebURLRequest::FrameTypeTopLevel 5900 ? blink::WebURLRequest::FrameTypeTopLevel
5906 : blink::WebURLRequest::FrameTypeNested); 5901 : blink::WebURLRequest::FrameTypeNested);
5907 5902
5908 if (IsBrowserSideNavigationEnabled() && common_params.post_data) 5903 if (IsBrowserSideNavigationEnabled() && common_params.post_data)
5909 request.setHTTPBody(GetWebHTTPBodyForRequestBody(common_params.post_data)); 5904 request.setHTTPBody(GetWebHTTPBodyForRequestBody(common_params.post_data));
5910 5905
5911 // Used to determine whether this frame is actually loading a request as part 5906 // Used to determine whether this frame is actually loading a request as part
5912 // of a history navigation. 5907 // of a history navigation.
5913 bool has_history_navigation_in_frame = false; 5908 bool has_history_navigation_in_frame = false;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
5961 render_view_->history_controller()->GoToEntry( 5956 render_view_->history_controller()->GoToEntry(
5962 frame_, std::move(entry), std::move(navigation_params), 5957 frame_, std::move(entry), std::move(navigation_params),
5963 cache_policy); 5958 cache_policy);
5964 } else { 5959 } else {
5965 // In --site-per-process, the browser process sends a single 5960 // In --site-per-process, the browser process sends a single
5966 // WebHistoryItem destined for this frame. 5961 // WebHistoryItem destined for this frame.
5967 // TODO(creis): Change PageState to FrameState. In the meantime, we 5962 // TODO(creis): Change PageState to FrameState. In the meantime, we
5968 // store the relevant frame's WebHistoryItem in the root of the 5963 // store the relevant frame's WebHistoryItem in the root of the
5969 // PageState. 5964 // PageState.
5970 item_for_history_navigation = entry->root(); 5965 item_for_history_navigation = entry->root();
5971 history_load_type = request_params.is_same_document_history_load 5966 switch (common_params.navigation_type) {
5972 ? blink::WebHistorySameDocumentLoad 5967 case FrameMsg_Navigate_Type::RELOAD:
5973 : blink::WebHistoryDifferentDocumentLoad; 5968 case FrameMsg_Navigate_Type::RELOAD_BYPASSING_CACHE:
5969 case FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL:
5970 case FrameMsg_Navigate_Type::RESTORE:
5971 case FrameMsg_Navigate_Type::RESTORE_WITH_POST:
5972 case FrameMsg_Navigate_Type::HISTORY_DIFFERENT_DOCUMENT:
5973 history_load_type = blink::WebHistoryDifferentDocumentLoad;
5974 break;
5975 case FrameMsg_Navigate_Type::HISTORY_SAME_DOCUMENT:
5976 history_load_type = blink::WebHistorySameDocumentLoad;
5977 break;
5978 default:
5979 NOTREACHED();
5980 history_load_type = blink::WebHistoryDifferentDocumentLoad;
5981 }
5974 load_type = request_params.is_history_navigation_in_new_child 5982 load_type = request_params.is_history_navigation_in_new_child
5975 ? blink::WebFrameLoadType::InitialHistoryLoad 5983 ? blink::WebFrameLoadType::InitialHistoryLoad
5976 : blink::WebFrameLoadType::BackForward; 5984 : blink::WebFrameLoadType::BackForward;
5977 should_load_request = true; 5985 should_load_request = true;
5978 5986
5979 // Keep track of which subframes the browser process has history items 5987 // Keep track of which subframes the browser process has history items
5980 // for during a history navigation. 5988 // for during a history navigation.
5981 history_subframe_unique_names_ = request_params.subframe_unique_names; 5989 history_subframe_unique_names_ = request_params.subframe_unique_names;
5982 5990
5983 if (history_load_type == blink::WebHistorySameDocumentLoad) { 5991 if (history_load_type == blink::WebHistorySameDocumentLoad) {
(...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after
6866 // event target. Potentially a Pepper plugin will receive the event. 6874 // event target. Potentially a Pepper plugin will receive the event.
6867 // In order to tell whether a plugin gets the last mouse event and which it 6875 // In order to tell whether a plugin gets the last mouse event and which it
6868 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets 6876 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets
6869 // the event, it will notify us via DidReceiveMouseEvent() and set itself as 6877 // the event, it will notify us via DidReceiveMouseEvent() and set itself as
6870 // |pepper_last_mouse_event_target_|. 6878 // |pepper_last_mouse_event_target_|.
6871 pepper_last_mouse_event_target_ = nullptr; 6879 pepper_last_mouse_event_target_ = nullptr;
6872 #endif 6880 #endif
6873 } 6881 }
6874 6882
6875 } // namespace content 6883 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698