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

Side by Side Diff: content/browser/frame_host/navigation_request.cc

Issue 2499313003: Set user_gesture bit at NavigationHandle creation time. (Closed)
Patch Set: rebase Created 4 years 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/navigation_request.h" 5 #include "content/browser/frame_host/navigation_request.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "content/browser/child_process_security_policy_impl.h" 9 #include "content/browser/child_process_security_policy_impl.h"
10 #include "content/browser/devtools/render_frame_devtools_agent_host.h" 10 #include "content/browser/devtools/render_frame_devtools_agent_host.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 // Fill POST data in the request body. 152 // Fill POST data in the request body.
153 scoped_refptr<ResourceRequestBodyImpl> request_body; 153 scoped_refptr<ResourceRequestBodyImpl> request_body;
154 if (frame_entry.method() == "POST") 154 if (frame_entry.method() == "POST")
155 request_body = frame_entry.GetPostData(); 155 request_body = frame_entry.GetPostData();
156 156
157 std::unique_ptr<NavigationRequest> navigation_request(new NavigationRequest( 157 std::unique_ptr<NavigationRequest> navigation_request(new NavigationRequest(
158 frame_tree_node, entry.ConstructCommonNavigationParams( 158 frame_tree_node, entry.ConstructCommonNavigationParams(
159 frame_entry, request_body, dest_url, dest_referrer, 159 frame_entry, request_body, dest_url, dest_referrer,
160 navigation_type, lofi_state, navigation_start), 160 navigation_type, lofi_state, navigation_start),
161 BeginNavigationParams(entry.extra_headers(), net::LOAD_NORMAL, 161 BeginNavigationParams(entry.extra_headers(), net::LOAD_NORMAL,
162 false, // has_user_gestures
163 false, // skip_service_worker 162 false, // skip_service_worker
164 REQUEST_CONTEXT_TYPE_LOCATION), 163 REQUEST_CONTEXT_TYPE_LOCATION),
165 entry.ConstructRequestNavigationParams( 164 entry.ConstructRequestNavigationParams(
166 frame_entry, is_same_document_history_load, 165 frame_entry, is_same_document_history_load,
167 is_history_navigation_in_new_child, 166 is_history_navigation_in_new_child,
168 entry.GetSubframeUniqueNames(frame_tree_node), 167 entry.GetSubframeUniqueNames(frame_tree_node),
169 frame_tree_node->has_committed_real_load(), 168 frame_tree_node->has_committed_real_load(),
170 controller->GetPendingEntryIndex() == -1, 169 controller->GetPendingEntryIndex() == -1,
171 controller->GetIndexOfEntry(&entry), 170 controller->GetIndexOfEntry(&entry),
172 controller->GetLastCommittedEntryIndex(), 171 controller->GetLastCommittedEntryIndex(),
173 controller->GetEntryCount()), 172 controller->GetEntryCount()),
174 true, &frame_entry, &entry)); 173 true, &frame_entry, &entry));
175 return navigation_request; 174 return navigation_request;
176 } 175 }
177 176
178 // static 177 // static
179 std::unique_ptr<NavigationRequest> NavigationRequest::CreateRendererInitiated( 178 std::unique_ptr<NavigationRequest> NavigationRequest::CreateRendererInitiated(
180 FrameTreeNode* frame_tree_node, 179 FrameTreeNode* frame_tree_node,
181 const CommonNavigationParams& common_params, 180 const CommonNavigationParams& common_params,
182 const BeginNavigationParams& begin_params, 181 const BeginNavigationParams& begin_params,
183 int current_history_list_offset, 182 int current_history_list_offset,
184 int current_history_list_length) { 183 int current_history_list_length) {
185 // TODO(clamy): Check if some PageState should be provided here. 184 // TODO(clamy): Check if some PageState should be provided here.
186 // TODO(clamy): See how we should handle override of the user agent when the 185 // TODO(clamy): See how we should handle override of the user agent when the
187 // navigation may start in a renderer and commit in another one. 186 // navigation may start in a renderer and commit in another one.
188 // TODO(clamy): See if the navigation start time should be measured in the 187 // TODO(clamy): See if the navigation start time should be measured in the
189 // renderer and sent to the browser instead of being measured here. 188 // renderer and sent to the browser instead of being measured here.
190 // TODO(clamy): The pending history list offset should be properly set. 189 // TODO(clamy): The pending history list offset should be properly set.
191 RequestNavigationParams request_params( 190 RequestNavigationParams request_params(
192 false, // is_overriding_user_agent 191 false, // is_overriding_user_agent
193 std::vector<GURL>(), // redirects 192 std::vector<GURL>(), // redirects
194 false, // can_load_local_resources 193 false, // can_load_local_resources
195 PageState(), // page_state 194 PageState(), // page_state
196 0, // nav_entry_id 195 0, // nav_entry_id
197 false, // is_same_document_history_load 196 false, // is_same_document_history_load
198 false, // is_history_navigation_in_new_child 197 false, // is_history_navigation_in_new_child
199 std::map<std::string, bool>(), // subframe_unique_names 198 std::map<std::string, bool>(), // subframe_unique_names
200 frame_tree_node->has_committed_real_load(), 199 frame_tree_node->has_committed_real_load(),
201 false, // intended_as_new_entry 200 false, // intended_as_new_entry
202 -1, // pending_history_list_offset 201 -1, // pending_history_list_offset
203 current_history_list_offset, current_history_list_length, 202 current_history_list_offset, current_history_list_length,
204 false, // is_view_source 203 false, // is_view_source
205 false, // should_clear_history_list 204 false); // should_clear_history_list
206 begin_params.has_user_gesture);
207 std::unique_ptr<NavigationRequest> navigation_request( 205 std::unique_ptr<NavigationRequest> navigation_request(
208 new NavigationRequest(frame_tree_node, common_params, begin_params, 206 new NavigationRequest(frame_tree_node, common_params, begin_params,
209 request_params, false, nullptr, nullptr)); 207 request_params, false, nullptr, nullptr));
210 return navigation_request; 208 return navigation_request;
211 } 209 }
212 210
213 NavigationRequest::NavigationRequest( 211 NavigationRequest::NavigationRequest(
214 FrameTreeNode* frame_tree_node, 212 FrameTreeNode* frame_tree_node,
215 const CommonNavigationParams& common_params, 213 const CommonNavigationParams& common_params,
216 const BeginNavigationParams& begin_params, 214 const BeginNavigationParams& begin_params,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 if (ShouldMakeNetworkRequestForURL(common_params_.url)) { 270 if (ShouldMakeNetworkRequestForURL(common_params_.url)) {
273 // It's safe to use base::Unretained because this NavigationRequest owns 271 // It's safe to use base::Unretained because this NavigationRequest owns
274 // the NavigationHandle where the callback will be stored. 272 // the NavigationHandle where the callback will be stored.
275 // TODO(clamy): pass the real value for |is_external_protocol| if needed. 273 // TODO(clamy): pass the real value for |is_external_protocol| if needed.
276 // TODO(clamy): pass the method to the NavigationHandle instead of a 274 // TODO(clamy): pass the method to the NavigationHandle instead of a
277 // boolean. 275 // boolean.
278 navigation_handle_->WillStartRequest( 276 navigation_handle_->WillStartRequest(
279 common_params_.method, common_params_.post_data, 277 common_params_.method, common_params_.post_data,
280 Referrer::SanitizeForRequest(common_params_.url, 278 Referrer::SanitizeForRequest(common_params_.url,
281 common_params_.referrer), 279 common_params_.referrer),
282 begin_params_.has_user_gesture, common_params_.transition, false, 280 common_params_.transition, false, begin_params_.request_context_type,
283 begin_params_.request_context_type,
284 base::Bind(&NavigationRequest::OnStartChecksComplete, 281 base::Bind(&NavigationRequest::OnStartChecksComplete,
285 base::Unretained(this))); 282 base::Unretained(this)));
286 return; 283 return;
287 } 284 }
288 285
289 // There is no need to make a network request for this navigation, so commit 286 // There is no need to make a network request for this navigation, so commit
290 // it immediately. 287 // it immediately.
291 state_ = RESPONSE_STARTED; 288 state_ = RESPONSE_STARTED;
292 289
293 // Select an appropriate RenderFrameHost. 290 // Select an appropriate RenderFrameHost.
294 RenderFrameHostImpl* render_frame_host = 291 RenderFrameHostImpl* render_frame_host =
295 frame_tree_node_->render_manager()->GetFrameHostForNavigation(*this); 292 frame_tree_node_->render_manager()->GetFrameHostForNavigation(*this);
296 NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL(render_frame_host, 293 NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL(render_frame_host,
297 common_params_.url); 294 common_params_.url);
298 295
299 // Inform the NavigationHandle that the navigation will commit. 296 // Inform the NavigationHandle that the navigation will commit.
300 navigation_handle_->ReadyToCommitNavigation(render_frame_host); 297 navigation_handle_->ReadyToCommitNavigation(render_frame_host);
301 298
302 CommitNavigation(); 299 CommitNavigation();
303 } 300 }
304 301
305 void NavigationRequest::CreateNavigationHandle(int pending_nav_entry_id) { 302 void NavigationRequest::CreateNavigationHandle(int pending_nav_entry_id) {
306 // TODO(nasko): Update the NavigationHandle creation to ensure that the 303 // TODO(nasko): Update the NavigationHandle creation to ensure that the
307 // proper values are specified for is_same_page and is_srcdoc. 304 // proper values are specified for is_same_page and is_srcdoc.
308 navigation_handle_ = NavigationHandleImpl::Create( 305 navigation_handle_ = NavigationHandleImpl::Create(
309 common_params_.url, frame_tree_node_, !browser_initiated_, 306 common_params_.url, frame_tree_node_, !browser_initiated_,
310 false, // is_same_page 307 false, // is_same_page
311 false, // is_srcdoc 308 false, // is_srcdoc
312 common_params_.navigation_start, pending_nav_entry_id, 309 common_params_.navigation_start, pending_nav_entry_id,
310 common_params_.gesture,
313 false); // started_in_context_menu 311 false); // started_in_context_menu
314 312
315 if (!begin_params_.searchable_form_url.is_empty()) { 313 if (!begin_params_.searchable_form_url.is_empty()) {
316 navigation_handle_->set_searchable_form_url( 314 navigation_handle_->set_searchable_form_url(
317 begin_params_.searchable_form_url); 315 begin_params_.searchable_form_url);
318 navigation_handle_->set_searchable_form_encoding( 316 navigation_handle_->set_searchable_form_encoding(
319 begin_params_.searchable_form_encoding); 317 begin_params_.searchable_form_encoding);
320 } 318 }
321 } 319 }
322 320
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 // Retrieve the RenderFrameHost that needs to commit the navigation. 589 // Retrieve the RenderFrameHost that needs to commit the navigation.
592 RenderFrameHostImpl* render_frame_host = 590 RenderFrameHostImpl* render_frame_host =
593 navigation_handle_->GetRenderFrameHost(); 591 navigation_handle_->GetRenderFrameHost();
594 DCHECK(render_frame_host == 592 DCHECK(render_frame_host ==
595 frame_tree_node_->render_manager()->current_frame_host() || 593 frame_tree_node_->render_manager()->current_frame_host() ||
596 render_frame_host == 594 render_frame_host ==
597 frame_tree_node_->render_manager()->speculative_frame_host()); 595 frame_tree_node_->render_manager()->speculative_frame_host());
598 596
599 TransferNavigationHandleOwnership(render_frame_host); 597 TransferNavigationHandleOwnership(render_frame_host);
600 598
601 DCHECK_EQ(request_params_.has_user_gesture, begin_params_.has_user_gesture);
602
603 render_frame_host->CommitNavigation(response_.get(), std::move(body_), 599 render_frame_host->CommitNavigation(response_.get(), std::move(body_),
604 common_params_, request_params_, 600 common_params_, request_params_,
605 is_view_source_); 601 is_view_source_);
606 602
607 frame_tree_node_->ResetNavigationRequest(true); 603 frame_tree_node_->ResetNavigationRequest(true);
608 } 604 }
609 605
610 } // namespace content 606 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/navigation_handle_impl_unittest.cc ('k') | content/browser/frame_host/navigator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698