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

Side by Side Diff: content/browser/frame_host/navigator_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/browser/frame_host/navigator_impl.h" 5 #include "content/browser/frame_host/navigator_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
(...skipping 29 matching lines...) Expand all
40 #include "content/public/browser/render_view_host.h" 40 #include "content/public/browser/render_view_host.h"
41 #include "content/public/browser/stream_handle.h" 41 #include "content/public/browser/stream_handle.h"
42 #include "content/public/browser/user_metrics.h" 42 #include "content/public/browser/user_metrics.h"
43 #include "content/public/common/bindings_policy.h" 43 #include "content/public/common/bindings_policy.h"
44 #include "content/public/common/browser_side_navigation_policy.h" 44 #include "content/public/common/browser_side_navigation_policy.h"
45 #include "content/public/common/content_client.h" 45 #include "content/public/common/content_client.h"
46 #include "content/public/common/content_constants.h" 46 #include "content/public/common/content_constants.h"
47 #include "content/public/common/resource_response.h" 47 #include "content/public/common/resource_response.h"
48 #include "net/base/net_errors.h" 48 #include "net/base/net_errors.h"
49 #include "url/gurl.h" 49 #include "url/gurl.h"
50 #include "url/url_util.h"
50 51
51 namespace content { 52 namespace content {
52 53
53 namespace { 54 namespace {
54 55
55 FrameMsg_Navigate_Type::Value GetNavigationType( 56 FrameMsg_Navigate_Type::Value GetNavigationType(
56 BrowserContext* browser_context, 57 const GURL& old_url,
58 const GURL& new_url,
59 ReloadType reload_type,
57 const NavigationEntryImpl& entry, 60 const NavigationEntryImpl& entry,
58 ReloadType reload_type) { 61 const FrameNavigationEntry& frame_entry,
62 bool is_same_document_history_load) {
63 // Reload navigations
59 switch (reload_type) { 64 switch (reload_type) {
60 case ReloadType::NORMAL: 65 case ReloadType::NORMAL:
61 return FrameMsg_Navigate_Type::RELOAD; 66 return FrameMsg_Navigate_Type::RELOAD;
62 case ReloadType::BYPASSING_CACHE: 67 case ReloadType::BYPASSING_CACHE:
63 case ReloadType::DISABLE_LOFI_MODE: 68 case ReloadType::DISABLE_LOFI_MODE:
64 return FrameMsg_Navigate_Type::RELOAD_BYPASSING_CACHE; 69 return FrameMsg_Navigate_Type::RELOAD_BYPASSING_CACHE;
65 case ReloadType::ORIGINAL_REQUEST_URL: 70 case ReloadType::ORIGINAL_REQUEST_URL:
66 return FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL; 71 return FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
67 case ReloadType::NONE: 72 case ReloadType::NONE:
68 break; // Fall through to rest of function. 73 break; // Fall through to rest of function.
69 } 74 }
70 75
71 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates 76 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
72 // between |RESTORE_WITH_POST| and |RESTORE|. 77 // between |RESTORE_WITH_POST| and |RESTORE|.
73 if (entry.restore_type() == RestoreType::LAST_SESSION_EXITED_CLEANLY) { 78 if (entry.restore_type() == RestoreType::LAST_SESSION_EXITED_CLEANLY) {
74 if (entry.GetHasPostData()) 79 if (entry.GetHasPostData())
75 return FrameMsg_Navigate_Type::RESTORE_WITH_POST; 80 return FrameMsg_Navigate_Type::RESTORE_WITH_POST;
76 return FrameMsg_Navigate_Type::RESTORE; 81 else
82 return FrameMsg_Navigate_Type::RESTORE;
77 } 83 }
78 84
79 return FrameMsg_Navigate_Type::NORMAL; 85 // History navigations.
86 if (frame_entry.page_state().IsValid()) {
87 if (is_same_document_history_load)
88 return FrameMsg_Navigate_Type::HISTORY_SAME_DOCUMENT;
89 else
90 return FrameMsg_Navigate_Type::HISTORY_DIFFERENT_DOCUMENT;
91 }
92 DCHECK(!is_same_document_history_load);
93
94 // A same-document fragment-navigation happens when the only part of the url
95 // that is modified is after the '#' character.
96 //
97 // Be careful not to consider history navigations. For instance, if the
98 // history is: 'A#bar' -> 'B' -> 'A#foo'. Then an history navigation from
99 // 'A#foo' to 'A#bar' is not a same-document navigation, but a
100 // different-document one! The two FrameNavigationEntry doesn't share the same
101 // document_sequence_number.
102 //
103 // When modifying this condition, please take a look at:
104 // FrameLoader::shouldPerformFragmentNavigation.
105 if (new_url.has_ref() && GURL::EqualsIgnoringRef(old_url, new_url) &&
106 frame_entry.method() == "GET") {
107 return FrameMsg_Navigate_Type::SAME_DOCUMENT;
108 } else {
109 return FrameMsg_Navigate_Type::DIFFERENT_DOCUMENT;
110 }
80 } 111 }
81 112
82 } // namespace 113 } // namespace
83 114
84 struct NavigatorImpl::NavigationMetricsData { 115 struct NavigatorImpl::NavigationMetricsData {
85 NavigationMetricsData(base::TimeTicks start_time, 116 NavigationMetricsData(base::TimeTicks start_time,
86 GURL url, 117 GURL url,
87 RestoreType restore_type) 118 RestoreType restore_type)
88 : start_time_(start_time), url_(url) { 119 : start_time_(start_time), url_(url) {
89 is_restoring_from_last_session_ = 120 is_restoring_from_last_session_ =
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 // been issued. In that case, simply resume the response. 439 // been issued. In that case, simply resume the response.
409 bool is_transfer_to_same = 440 bool is_transfer_to_same =
410 is_transfer && 441 is_transfer &&
411 entry.transferred_global_request_id().child_id == 442 entry.transferred_global_request_id().child_id ==
412 dest_render_frame_host->GetProcess()->GetID(); 443 dest_render_frame_host->GetProcess()->GetID();
413 if (!is_transfer_to_same) { 444 if (!is_transfer_to_same) {
414 navigation_data_.reset(new NavigationMetricsData( 445 navigation_data_.reset(new NavigationMetricsData(
415 navigation_start, dest_url, entry.restore_type())); 446 navigation_start, dest_url, entry.restore_type()));
416 // Create the navigation parameters. 447 // Create the navigation parameters.
417 FrameMsg_Navigate_Type::Value navigation_type = GetNavigationType( 448 FrameMsg_Navigate_Type::Value navigation_type = GetNavigationType(
418 controller_->GetBrowserContext(), entry, reload_type); 449 frame_tree_node->current_url(), // old_url
450 dest_url, // new_url
451 reload_type, // reload_type
452 entry, // entry
453 frame_entry, // frame_entry
454 is_same_document_history_load); // is_same_document_history_load
455
419 dest_render_frame_host->Navigate( 456 dest_render_frame_host->Navigate(
420 entry.ConstructCommonNavigationParams( 457 entry.ConstructCommonNavigationParams(
421 frame_entry, post_body, dest_url, dest_referrer, navigation_type, 458 frame_entry, post_body, dest_url, dest_referrer, navigation_type,
422 previews_state, navigation_start), 459 previews_state, navigation_start),
423 entry.ConstructStartNavigationParams(), 460 entry.ConstructStartNavigationParams(),
424 entry.ConstructRequestNavigationParams( 461 entry.ConstructRequestNavigationParams(
425 frame_entry, is_same_document_history_load, 462 frame_entry, is_history_navigation_in_new_child,
426 is_history_navigation_in_new_child,
427 entry.GetSubframeUniqueNames(frame_tree_node), 463 entry.GetSubframeUniqueNames(frame_tree_node),
428 frame_tree_node->has_committed_real_load(), 464 frame_tree_node->has_committed_real_load(),
429 controller_->GetPendingEntryIndex() == -1, 465 controller_->GetPendingEntryIndex() == -1,
430 controller_->GetIndexOfEntry(&entry), 466 controller_->GetIndexOfEntry(&entry),
431 controller_->GetLastCommittedEntryIndex(), 467 controller_->GetLastCommittedEntryIndex(),
432 controller_->GetEntryCount())); 468 controller_->GetEntryCount()));
433 } else { 469 } else {
434 dest_render_frame_host->navigation_handle()->set_is_transferring(false); 470 dest_render_frame_host->navigation_handle()->set_is_transferring(false);
435 } 471 }
436 } 472 }
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after
1123 bool is_history_navigation_in_new_child, 1159 bool is_history_navigation_in_new_child,
1124 base::TimeTicks navigation_start) { 1160 base::TimeTicks navigation_start) {
1125 CHECK(IsBrowserSideNavigationEnabled()); 1161 CHECK(IsBrowserSideNavigationEnabled());
1126 DCHECK(frame_tree_node); 1162 DCHECK(frame_tree_node);
1127 1163
1128 // This value must be set here because creating a NavigationRequest might 1164 // This value must be set here because creating a NavigationRequest might
1129 // change the renderer live/non-live status and change this result. 1165 // change the renderer live/non-live status and change this result.
1130 bool should_dispatch_beforeunload = 1166 bool should_dispatch_beforeunload =
1131 !is_same_document_history_load && 1167 !is_same_document_history_load &&
1132 frame_tree_node->current_frame_host()->ShouldDispatchBeforeUnload(); 1168 frame_tree_node->current_frame_host()->ShouldDispatchBeforeUnload();
1133 FrameMsg_Navigate_Type::Value navigation_type = 1169 FrameMsg_Navigate_Type::Value navigation_type = GetNavigationType(
1134 GetNavigationType(controller_->GetBrowserContext(), entry, reload_type); 1170 frame_tree_node->current_url(), // old_url
1171 dest_url, // new_url
1172 reload_type, // reload_type
1173 entry, // entry
1174 frame_entry, // frame_entry
1175 is_same_document_history_load); // is_same_document_history_load
1135 std::unique_ptr<NavigationRequest> scoped_request = 1176 std::unique_ptr<NavigationRequest> scoped_request =
1136 NavigationRequest::CreateBrowserInitiated( 1177 NavigationRequest::CreateBrowserInitiated(
1137 frame_tree_node, dest_url, dest_referrer, frame_entry, entry, 1178 frame_tree_node, dest_url, dest_referrer, frame_entry, entry,
1138 navigation_type, previews_state, is_same_document_history_load, 1179 navigation_type, previews_state, is_same_document_history_load,
1139 is_history_navigation_in_new_child, navigation_start, controller_); 1180 is_history_navigation_in_new_child, navigation_start, controller_);
1140 1181
1141 // Navigation to a javascript URL is not a "real" navigation so there is no 1182 // Navigation to a javascript URL is not a "real" navigation so there is no
1142 // need to create a NavigationHandle. The navigation commits immediately and 1183 // need to create a NavigationHandle. The navigation commits immediately and
1143 // the NavigationRequest is not assigned to the FrameTreeNode as navigating to 1184 // the NavigationRequest is not assigned to the FrameTreeNode as navigating to
1144 // a Javascript URL should not interrupt a previous navigation. 1185 // a Javascript URL should not interrupt a previous navigation.
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1268 if (navigation_handle) 1309 if (navigation_handle)
1269 navigation_handle->update_entry_id_for_transfer(entry->GetUniqueID()); 1310 navigation_handle->update_entry_id_for_transfer(entry->GetUniqueID());
1270 1311
1271 controller_->SetPendingEntry(std::move(entry)); 1312 controller_->SetPendingEntry(std::move(entry));
1272 if (delegate_) 1313 if (delegate_)
1273 delegate_->NotifyChangedNavigationState(content::INVALIDATE_TYPE_URL); 1314 delegate_->NotifyChangedNavigationState(content::INVALIDATE_TYPE_URL);
1274 } 1315 }
1275 } 1316 }
1276 1317
1277 } // namespace content 1318 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698