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

Side by Side Diff: content/browser/frame_host/navigator_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/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 28 matching lines...) Expand all
39 #include "content/public/browser/page_navigator.h" 39 #include "content/public/browser/page_navigator.h"
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 "net/base/url_util.h"
49 #include "url/gurl.h" 50 #include "url/gurl.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 (net::IsFragmentAddedOrUpdated(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 688 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 bool is_history_navigation_in_new_child, 1161 bool is_history_navigation_in_new_child,
1126 base::TimeTicks navigation_start) { 1162 base::TimeTicks navigation_start) {
1127 CHECK(IsBrowserSideNavigationEnabled()); 1163 CHECK(IsBrowserSideNavigationEnabled());
1128 DCHECK(frame_tree_node); 1164 DCHECK(frame_tree_node);
1129 1165
1130 // This value must be set here because creating a NavigationRequest might 1166 // This value must be set here because creating a NavigationRequest might
1131 // change the renderer live/non-live status and change this result. 1167 // change the renderer live/non-live status and change this result.
1132 bool should_dispatch_beforeunload = 1168 bool should_dispatch_beforeunload =
1133 !is_same_document_history_load && 1169 !is_same_document_history_load &&
1134 frame_tree_node->current_frame_host()->ShouldDispatchBeforeUnload(); 1170 frame_tree_node->current_frame_host()->ShouldDispatchBeforeUnload();
1135 FrameMsg_Navigate_Type::Value navigation_type = 1171 FrameMsg_Navigate_Type::Value navigation_type = GetNavigationType(
1136 GetNavigationType(controller_->GetBrowserContext(), entry, reload_type); 1172 frame_tree_node->current_url(), // old_url
1173 dest_url, // new_url
1174 reload_type, // reload_type
1175 entry, // entry
1176 frame_entry, // frame_entry
1177 is_same_document_history_load); // is_same_document_history_load
1137 std::unique_ptr<NavigationRequest> scoped_request = 1178 std::unique_ptr<NavigationRequest> scoped_request =
1138 NavigationRequest::CreateBrowserInitiated( 1179 NavigationRequest::CreateBrowserInitiated(
1139 frame_tree_node, dest_url, dest_referrer, frame_entry, entry, 1180 frame_tree_node, dest_url, dest_referrer, frame_entry, entry,
1140 navigation_type, previews_state, is_same_document_history_load, 1181 navigation_type, previews_state, is_same_document_history_load,
1141 is_history_navigation_in_new_child, navigation_start, controller_); 1182 is_history_navigation_in_new_child, navigation_start, controller_);
1142 1183
1143 // Navigation to a javascript URL is not a "real" navigation so there is no 1184 // Navigation to a javascript URL is not a "real" navigation so there is no
1144 // need to create a NavigationHandle. The navigation commits immediately and 1185 // need to create a NavigationHandle. The navigation commits immediately and
1145 // the NavigationRequest is not assigned to the FrameTreeNode as navigating to 1186 // the NavigationRequest is not assigned to the FrameTreeNode as navigating to
1146 // a Javascript URL should not interrupt a previous navigation. 1187 // a Javascript URL should not interrupt a previous navigation.
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1270 if (navigation_handle) 1311 if (navigation_handle)
1271 navigation_handle->update_entry_id_for_transfer(entry->GetUniqueID()); 1312 navigation_handle->update_entry_id_for_transfer(entry->GetUniqueID());
1272 1313
1273 controller_->SetPendingEntry(std::move(entry)); 1314 controller_->SetPendingEntry(std::move(entry));
1274 if (delegate_) 1315 if (delegate_)
1275 delegate_->NotifyChangedNavigationState(content::INVALIDATE_TYPE_URL); 1316 delegate_->NotifyChangedNavigationState(content::INVALIDATE_TYPE_URL);
1276 } 1317 }
1277 } 1318 }
1278 1319
1279 } // namespace content 1320 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698