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

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() && old_url.EqualsIgnoringRef(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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 // been issued. In that case, simply resume the response. 441 // been issued. In that case, simply resume the response.
411 bool is_transfer_to_same = 442 bool is_transfer_to_same =
412 is_transfer && 443 is_transfer &&
413 entry.transferred_global_request_id().child_id == 444 entry.transferred_global_request_id().child_id ==
414 dest_render_frame_host->GetProcess()->GetID(); 445 dest_render_frame_host->GetProcess()->GetID();
415 if (!is_transfer_to_same) { 446 if (!is_transfer_to_same) {
416 navigation_data_.reset(new NavigationMetricsData( 447 navigation_data_.reset(new NavigationMetricsData(
417 navigation_start, dest_url, entry.restore_type())); 448 navigation_start, dest_url, entry.restore_type()));
418 // Create the navigation parameters. 449 // Create the navigation parameters.
419 FrameMsg_Navigate_Type::Value navigation_type = GetNavigationType( 450 FrameMsg_Navigate_Type::Value navigation_type = GetNavigationType(
420 controller_->GetBrowserContext(), entry, reload_type); 451 frame_tree_node->current_url(), // old_url
452 dest_url, // new_url
453 reload_type, // reload_type
454 entry, // entry
455 frame_entry, // frame_entry
456 is_same_document_history_load); // is_same_document_history_load
457
421 dest_render_frame_host->Navigate( 458 dest_render_frame_host->Navigate(
422 entry.ConstructCommonNavigationParams( 459 entry.ConstructCommonNavigationParams(
423 frame_entry, post_body, dest_url, dest_referrer, navigation_type, 460 frame_entry, post_body, dest_url, dest_referrer, navigation_type,
424 previews_state, navigation_start), 461 previews_state, navigation_start),
425 entry.ConstructStartNavigationParams(), 462 entry.ConstructStartNavigationParams(),
426 entry.ConstructRequestNavigationParams( 463 entry.ConstructRequestNavigationParams(
427 frame_entry, is_same_document_history_load, 464 frame_entry, is_history_navigation_in_new_child,
428 is_history_navigation_in_new_child,
429 entry.GetSubframeUniqueNames(frame_tree_node), 465 entry.GetSubframeUniqueNames(frame_tree_node),
430 frame_tree_node->has_committed_real_load(), 466 frame_tree_node->has_committed_real_load(),
431 controller_->GetPendingEntryIndex() == -1, 467 controller_->GetPendingEntryIndex() == -1,
432 controller_->GetIndexOfEntry(&entry), 468 controller_->GetIndexOfEntry(&entry),
433 controller_->GetLastCommittedEntryIndex(), 469 controller_->GetLastCommittedEntryIndex(),
434 controller_->GetEntryCount())); 470 controller_->GetEntryCount()));
435 } else { 471 } else {
436 dest_render_frame_host->navigation_handle()->set_is_transferring(false); 472 dest_render_frame_host->navigation_handle()->set_is_transferring(false);
437 } 473 }
438 } 474 }
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 bool is_history_navigation_in_new_child, 1162 bool is_history_navigation_in_new_child,
1127 base::TimeTicks navigation_start) { 1163 base::TimeTicks navigation_start) {
1128 CHECK(IsBrowserSideNavigationEnabled()); 1164 CHECK(IsBrowserSideNavigationEnabled());
1129 DCHECK(frame_tree_node); 1165 DCHECK(frame_tree_node);
1130 1166
1131 // This value must be set here because creating a NavigationRequest might 1167 // This value must be set here because creating a NavigationRequest might
1132 // change the renderer live/non-live status and change this result. 1168 // change the renderer live/non-live status and change this result.
1133 bool should_dispatch_beforeunload = 1169 bool should_dispatch_beforeunload =
1134 !is_same_document_history_load && 1170 !is_same_document_history_load &&
1135 frame_tree_node->current_frame_host()->ShouldDispatchBeforeUnload(); 1171 frame_tree_node->current_frame_host()->ShouldDispatchBeforeUnload();
1136 FrameMsg_Navigate_Type::Value navigation_type = 1172 FrameMsg_Navigate_Type::Value navigation_type = GetNavigationType(
1137 GetNavigationType(controller_->GetBrowserContext(), entry, reload_type); 1173 frame_tree_node->current_url(), // old_url
1174 dest_url, // new_url
1175 reload_type, // reload_type
1176 entry, // entry
1177 frame_entry, // frame_entry
1178 is_same_document_history_load); // is_same_document_history_load
1138 std::unique_ptr<NavigationRequest> scoped_request = 1179 std::unique_ptr<NavigationRequest> scoped_request =
1139 NavigationRequest::CreateBrowserInitiated( 1180 NavigationRequest::CreateBrowserInitiated(
1140 frame_tree_node, dest_url, dest_referrer, frame_entry, entry, 1181 frame_tree_node, dest_url, dest_referrer, frame_entry, entry,
1141 navigation_type, previews_state, is_same_document_history_load, 1182 navigation_type, previews_state, is_same_document_history_load,
1142 is_history_navigation_in_new_child, navigation_start, controller_); 1183 is_history_navigation_in_new_child, navigation_start, controller_);
1143 1184
1144 // Navigation to a javascript URL is not a "real" navigation so there is no 1185 // Navigation to a javascript URL is not a "real" navigation so there is no
1145 // need to create a NavigationHandle. The navigation commits immediately and 1186 // need to create a NavigationHandle. The navigation commits immediately and
1146 // the NavigationRequest is not assigned to the FrameTreeNode as navigating to 1187 // the NavigationRequest is not assigned to the FrameTreeNode as navigating to
1147 // a Javascript URL should not interrupt a previous navigation. 1188 // a Javascript URL should not interrupt a previous navigation.
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 if (navigation_handle) 1321 if (navigation_handle)
1281 navigation_handle->update_entry_id_for_transfer(entry->GetUniqueID()); 1322 navigation_handle->update_entry_id_for_transfer(entry->GetUniqueID());
1282 1323
1283 controller_->SetPendingEntry(std::move(entry)); 1324 controller_->SetPendingEntry(std::move(entry));
1284 if (delegate_) 1325 if (delegate_)
1285 delegate_->NotifyChangedNavigationState(content::INVALIDATE_TYPE_URL); 1326 delegate_->NotifyChangedNavigationState(content::INVALIDATE_TYPE_URL);
1286 } 1327 }
1287 } 1328 }
1288 1329
1289 } // namespace content 1330 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/navigation_request.cc ('k') | content/browser/frame_host/render_frame_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698