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

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

Issue 2499313003: Set user_gesture bit at NavigationHandle creation time. (Closed)
Patch Set: address comments Created 4 years, 1 month 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_handle_impl.h" 5 #include "content/browser/frame_host/navigation_handle_impl.h"
6 6
7 #include "base/debug/dump_without_crashing.h" 7 #include "base/debug/dump_without_crashing.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "content/browser/browsing_data/clear_site_data_throttle.h" 9 #include "content/browser/browsing_data/clear_site_data_throttle.h"
10 #include "content/browser/child_process_security_policy_impl.h" 10 #include "content/browser/child_process_security_policy_impl.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 49
50 // static 50 // static
51 std::unique_ptr<NavigationHandleImpl> NavigationHandleImpl::Create( 51 std::unique_ptr<NavigationHandleImpl> NavigationHandleImpl::Create(
52 const GURL& url, 52 const GURL& url,
53 FrameTreeNode* frame_tree_node, 53 FrameTreeNode* frame_tree_node,
54 bool is_renderer_initiated, 54 bool is_renderer_initiated,
55 bool is_same_page, 55 bool is_same_page,
56 bool is_srcdoc, 56 bool is_srcdoc,
57 const base::TimeTicks& navigation_start, 57 const base::TimeTicks& navigation_start,
58 int pending_nav_entry_id, 58 int pending_nav_entry_id,
59 NavigationGesture gesture,
59 bool started_from_context_menu) { 60 bool started_from_context_menu) {
60 return std::unique_ptr<NavigationHandleImpl>(new NavigationHandleImpl( 61 return std::unique_ptr<NavigationHandleImpl>(new NavigationHandleImpl(
61 url, frame_tree_node, is_renderer_initiated, is_same_page, is_srcdoc, 62 url, frame_tree_node, is_renderer_initiated, is_same_page, is_srcdoc,
62 navigation_start, pending_nav_entry_id, started_from_context_menu)); 63 navigation_start, pending_nav_entry_id, gesture,
64 started_from_context_menu));
63 } 65 }
64 66
65 NavigationHandleImpl::NavigationHandleImpl( 67 NavigationHandleImpl::NavigationHandleImpl(
66 const GURL& url, 68 const GURL& url,
67 FrameTreeNode* frame_tree_node, 69 FrameTreeNode* frame_tree_node,
68 bool is_renderer_initiated, 70 bool is_renderer_initiated,
69 bool is_same_page, 71 bool is_same_page,
70 bool is_srcdoc, 72 bool is_srcdoc,
71 const base::TimeTicks& navigation_start, 73 const base::TimeTicks& navigation_start,
72 int pending_nav_entry_id, 74 int pending_nav_entry_id,
75 NavigationGesture gesture,
73 bool started_from_context_menu) 76 bool started_from_context_menu)
74 : url_(url), 77 : url_(url),
75 has_user_gesture_(false), 78 gesture_(gesture),
76 transition_(ui::PAGE_TRANSITION_LINK), 79 transition_(ui::PAGE_TRANSITION_LINK),
77 is_external_protocol_(false), 80 is_external_protocol_(false),
78 net_error_code_(net::OK), 81 net_error_code_(net::OK),
79 render_frame_host_(nullptr), 82 render_frame_host_(nullptr),
80 is_renderer_initiated_(is_renderer_initiated), 83 is_renderer_initiated_(is_renderer_initiated),
81 is_same_page_(is_same_page), 84 is_same_page_(is_same_page),
82 is_srcdoc_(is_srcdoc), 85 is_srcdoc_(is_srcdoc),
83 was_redirected_(false), 86 was_redirected_(false),
84 connection_info_(net::HttpResponseInfo::CONNECTION_INFO_UNKNOWN), 87 connection_info_(net::HttpResponseInfo::CONNECTION_INFO_UNKNOWN),
85 original_url_(url), 88 original_url_(url),
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 return method_ == "POST"; 200 return method_ == "POST";
198 } 201 }
199 202
200 const Referrer& NavigationHandleImpl::GetReferrer() { 203 const Referrer& NavigationHandleImpl::GetReferrer() {
201 CHECK_NE(INITIAL, state_) 204 CHECK_NE(INITIAL, state_)
202 << "This accessor should not be called before the request is started."; 205 << "This accessor should not be called before the request is started.";
203 return sanitized_referrer_; 206 return sanitized_referrer_;
204 } 207 }
205 208
206 bool NavigationHandleImpl::HasUserGesture() { 209 bool NavigationHandleImpl::HasUserGesture() {
207 CHECK_NE(INITIAL, state_) 210 return gesture_ == NavigationGestureUser;
208 << "This accessor should not be called before the request is started.";
209 return has_user_gesture_;
210 } 211 }
211 212
212 ui::PageTransition NavigationHandleImpl::GetPageTransition() { 213 ui::PageTransition NavigationHandleImpl::GetPageTransition() {
213 CHECK_NE(INITIAL, state_) 214 CHECK_NE(INITIAL, state_)
214 << "This accessor should not be called before the request is started."; 215 << "This accessor should not be called before the request is started.";
215 return transition_; 216 return transition_;
216 } 217 }
217 218
218 bool NavigationHandleImpl::IsExternalProtocol() { 219 bool NavigationHandleImpl::IsExternalProtocol() {
219 CHECK_NE(INITIAL, state_) 220 CHECK_NE(INITIAL, state_)
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 296
296 void NavigationHandleImpl::RegisterThrottleForTesting( 297 void NavigationHandleImpl::RegisterThrottleForTesting(
297 std::unique_ptr<NavigationThrottle> navigation_throttle) { 298 std::unique_ptr<NavigationThrottle> navigation_throttle) {
298 throttles_.push_back(std::move(navigation_throttle)); 299 throttles_.push_back(std::move(navigation_throttle));
299 } 300 }
300 301
301 NavigationThrottle::ThrottleCheckResult 302 NavigationThrottle::ThrottleCheckResult
302 NavigationHandleImpl::CallWillStartRequestForTesting( 303 NavigationHandleImpl::CallWillStartRequestForTesting(
303 bool is_post, 304 bool is_post,
304 const Referrer& sanitized_referrer, 305 const Referrer& sanitized_referrer,
305 bool has_user_gesture,
306 ui::PageTransition transition, 306 ui::PageTransition transition,
307 bool is_external_protocol) { 307 bool is_external_protocol) {
308 NavigationThrottle::ThrottleCheckResult result = NavigationThrottle::DEFER; 308 NavigationThrottle::ThrottleCheckResult result = NavigationThrottle::DEFER;
309 309
310 scoped_refptr<ResourceRequestBodyImpl> resource_request_body; 310 scoped_refptr<ResourceRequestBodyImpl> resource_request_body;
311 std::string method = "GET"; 311 std::string method = "GET";
312 if (is_post) { 312 if (is_post) {
313 method = "POST"; 313 method = "POST";
314 314
315 std::string body = "test=body"; 315 std::string body = "test=body";
316 resource_request_body = new ResourceRequestBodyImpl(); 316 resource_request_body = new ResourceRequestBodyImpl();
317 resource_request_body->AppendBytes(body.data(), body.size()); 317 resource_request_body->AppendBytes(body.data(), body.size());
318 } 318 }
319 319
320 WillStartRequest(method, resource_request_body, sanitized_referrer, 320 WillStartRequest(method, resource_request_body, sanitized_referrer,
321 has_user_gesture, transition, is_external_protocol, 321 transition, is_external_protocol,
322 REQUEST_CONTEXT_TYPE_LOCATION, 322 REQUEST_CONTEXT_TYPE_LOCATION,
323 base::Bind(&UpdateThrottleCheckResult, &result)); 323 base::Bind(&UpdateThrottleCheckResult, &result));
324 324
325 // Reset the callback to ensure it will not be called later. 325 // Reset the callback to ensure it will not be called later.
326 complete_callback_.Reset(); 326 complete_callback_.Reset();
327 return result; 327 return result;
328 } 328 }
329 329
330 NavigationThrottle::ThrottleCheckResult 330 NavigationThrottle::ThrottleCheckResult
331 NavigationHandleImpl::CallWillRedirectRequestForTesting( 331 NavigationHandleImpl::CallWillRedirectRequestForTesting(
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 ServiceWorkerContextWrapper* service_worker_context) { 410 ServiceWorkerContextWrapper* service_worker_context) {
411 DCHECK(IsBrowserSideNavigationEnabled()); 411 DCHECK(IsBrowserSideNavigationEnabled());
412 service_worker_handle_.reset( 412 service_worker_handle_.reset(
413 new ServiceWorkerNavigationHandle(service_worker_context)); 413 new ServiceWorkerNavigationHandle(service_worker_context));
414 } 414 }
415 415
416 void NavigationHandleImpl::WillStartRequest( 416 void NavigationHandleImpl::WillStartRequest(
417 const std::string& method, 417 const std::string& method,
418 scoped_refptr<content::ResourceRequestBodyImpl> resource_request_body, 418 scoped_refptr<content::ResourceRequestBodyImpl> resource_request_body,
419 const Referrer& sanitized_referrer, 419 const Referrer& sanitized_referrer,
420 bool has_user_gesture,
421 ui::PageTransition transition, 420 ui::PageTransition transition,
422 bool is_external_protocol, 421 bool is_external_protocol,
423 RequestContextType request_context_type, 422 RequestContextType request_context_type,
424 const ThrottleChecksFinishedCallback& callback) { 423 const ThrottleChecksFinishedCallback& callback) {
425 // |method != "POST"| should imply absence of |resource_request_body|. 424 // |method != "POST"| should imply absence of |resource_request_body|.
426 if (method != "POST" && resource_request_body) { 425 if (method != "POST" && resource_request_body) {
427 NOTREACHED(); 426 NOTREACHED();
428 resource_request_body = nullptr; 427 resource_request_body = nullptr;
429 } 428 }
430 429
431 // Update the navigation parameters. 430 // Update the navigation parameters.
432 method_ = method; 431 method_ = method;
433 if (method_ == "POST") 432 if (method_ == "POST")
434 resource_request_body_ = resource_request_body; 433 resource_request_body_ = resource_request_body;
435 sanitized_referrer_ = sanitized_referrer; 434 sanitized_referrer_ = sanitized_referrer;
436 has_user_gesture_ = has_user_gesture;
437 transition_ = transition; 435 transition_ = transition;
438 is_external_protocol_ = is_external_protocol; 436 is_external_protocol_ = is_external_protocol;
439 request_context_type_ = request_context_type; 437 request_context_type_ = request_context_type;
440 state_ = WILL_SEND_REQUEST; 438 state_ = WILL_SEND_REQUEST;
441 complete_callback_ = callback; 439 complete_callback_ = callback;
442 440
443 RegisterNavigationThrottles(); 441 RegisterNavigationThrottles();
444 442
445 if (IsBrowserSideNavigationEnabled()) 443 if (IsBrowserSideNavigationEnabled())
446 navigation_ui_data_ = GetDelegate()->GetNavigationUIData(this); 444 navigation_ui_data_ = GetDelegate()->GetNavigationUIData(this);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 GetDelegate()->ReadyToCommitNavigation(this); 533 GetDelegate()->ReadyToCommitNavigation(this);
536 } 534 }
537 535
538 void NavigationHandleImpl::DidCommitNavigation( 536 void NavigationHandleImpl::DidCommitNavigation(
539 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, 537 const FrameHostMsg_DidCommitProvisionalLoad_Params& params,
540 bool same_page, 538 bool same_page,
541 RenderFrameHostImpl* render_frame_host) { 539 RenderFrameHostImpl* render_frame_host) {
542 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); 540 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host);
543 DCHECK_EQ(frame_tree_node_, render_frame_host->frame_tree_node()); 541 DCHECK_EQ(frame_tree_node_, render_frame_host->frame_tree_node());
544 CHECK_EQ(url_, params.url); 542 CHECK_EQ(url_, params.url);
543 // TODO(clamy): DCHECK that params.gesture matches
clamy 2016/11/24 12:20:02 nit: empty line above.
Bryan McQuade 2016/11/28 01:41:03 Done
544 // has_user_gesture_. See crbug.com/667572.
545 545
546 method_ = params.method; 546 method_ = params.method;
547 has_user_gesture_ = (params.gesture == NavigationGestureUser);
clamy 2016/11/24 12:20:02 While we investigate why the gesture doesn't match
Bryan McQuade 2016/11/28 01:41:03 Sure, updated.
548 transition_ = params.transition; 547 transition_ = params.transition;
549 render_frame_host_ = render_frame_host; 548 render_frame_host_ = render_frame_host;
550 549
551 // If an error page reloads, net_error_code might be 200 but we still want to 550 // If an error page reloads, net_error_code might be 200 but we still want to
552 // count it as an error page. 551 // count it as an error page.
553 if (params.base_url.spec() == kUnreachableWebDataURL || 552 if (params.base_url.spec() == kUnreachableWebDataURL ||
554 net_error_code_ != net::OK) { 553 net_error_code_ != net::OK) {
555 state_ = DID_COMMIT_ERROR_PAGE; 554 state_ = DID_COMMIT_ERROR_PAGE;
556 } else { 555 } else {
557 state_ = DID_COMMIT; 556 state_ = DID_COMMIT;
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 throttles_to_register.push_back(std::move(clear_site_data_throttle)); 786 throttles_to_register.push_back(std::move(clear_site_data_throttle));
788 787
789 if (throttles_to_register.size() > 0) { 788 if (throttles_to_register.size() > 0) {
790 throttles_.insert(throttles_.begin(), throttles_to_register.begin(), 789 throttles_.insert(throttles_.begin(), throttles_to_register.begin(),
791 throttles_to_register.end()); 790 throttles_to_register.end());
792 throttles_to_register.weak_clear(); 791 throttles_to_register.weak_clear();
793 } 792 }
794 } 793 }
795 794
796 } // namespace content 795 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/navigation_handle_impl.h ('k') | content/browser/frame_host/navigation_handle_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698