OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 if (method != "POST") | 424 if (method != "POST") |
426 DCHECK(!resource_request_body); | 425 DCHECK(!resource_request_body); |
427 | 426 |
428 // Update the navigation parameters. | 427 // Update the navigation parameters. |
429 method_ = method; | 428 method_ = method; |
430 if (method_ == "POST") | 429 if (method_ == "POST") |
431 resource_request_body_ = resource_request_body; | 430 resource_request_body_ = resource_request_body; |
432 sanitized_referrer_ = sanitized_referrer; | 431 sanitized_referrer_ = sanitized_referrer; |
433 has_user_gesture_ = has_user_gesture; | |
434 transition_ = transition; | 432 transition_ = transition; |
435 is_external_protocol_ = is_external_protocol; | 433 is_external_protocol_ = is_external_protocol; |
436 request_context_type_ = request_context_type; | 434 request_context_type_ = request_context_type; |
437 state_ = WILL_SEND_REQUEST; | 435 state_ = WILL_SEND_REQUEST; |
438 complete_callback_ = callback; | 436 complete_callback_ = callback; |
439 | 437 |
440 RegisterNavigationThrottles(); | 438 RegisterNavigationThrottles(); |
441 | 439 |
442 if (IsBrowserSideNavigationEnabled()) | 440 if (IsBrowserSideNavigationEnabled()) |
443 navigation_ui_data_ = GetDelegate()->GetNavigationUIData(this); | 441 navigation_ui_data_ = GetDelegate()->GetNavigationUIData(this); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 } | 531 } |
534 | 532 |
535 void NavigationHandleImpl::DidCommitNavigation( | 533 void NavigationHandleImpl::DidCommitNavigation( |
536 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, | 534 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, |
537 bool same_page, | 535 bool same_page, |
538 RenderFrameHostImpl* render_frame_host) { | 536 RenderFrameHostImpl* render_frame_host) { |
539 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); | 537 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); |
540 DCHECK_EQ(frame_tree_node_, render_frame_host->frame_tree_node()); | 538 DCHECK_EQ(frame_tree_node_, render_frame_host->frame_tree_node()); |
541 CHECK_EQ(url_, params.url); | 539 CHECK_EQ(url_, params.url); |
542 | 540 |
| 541 // TODO(clamy): Once crbug.com/667572 is addressed, apply this DCHECK on all |
| 542 // navigations, not just same-page navigations, and make gesture_ a const |
| 543 // member, set only in the constructor. |
| 544 if (same_page) |
| 545 DCHECK_EQ(gesture_, params.gesture); |
| 546 gesture_ = params.gesture; |
| 547 |
543 method_ = params.method; | 548 method_ = params.method; |
544 has_user_gesture_ = (params.gesture == NavigationGestureUser); | |
545 transition_ = params.transition; | 549 transition_ = params.transition; |
546 render_frame_host_ = render_frame_host; | 550 render_frame_host_ = render_frame_host; |
547 | 551 |
548 // If an error page reloads, net_error_code might be 200 but we still want to | 552 // If an error page reloads, net_error_code might be 200 but we still want to |
549 // count it as an error page. | 553 // count it as an error page. |
550 if (params.base_url.spec() == kUnreachableWebDataURL || | 554 if (params.base_url.spec() == kUnreachableWebDataURL || |
551 net_error_code_ != net::OK) { | 555 net_error_code_ != net::OK) { |
552 state_ = DID_COMMIT_ERROR_PAGE; | 556 state_ = DID_COMMIT_ERROR_PAGE; |
553 } else { | 557 } else { |
554 state_ = DID_COMMIT; | 558 state_ = DID_COMMIT; |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
784 throttles_to_register.push_back(std::move(clear_site_data_throttle)); | 788 throttles_to_register.push_back(std::move(clear_site_data_throttle)); |
785 | 789 |
786 if (throttles_to_register.size() > 0) { | 790 if (throttles_to_register.size() > 0) { |
787 throttles_.insert(throttles_.begin(), throttles_to_register.begin(), | 791 throttles_.insert(throttles_.begin(), throttles_to_register.begin(), |
788 throttles_to_register.end()); | 792 throttles_to_register.end()); |
789 throttles_to_register.weak_clear(); | 793 throttles_to_register.weak_clear(); |
790 } | 794 } |
791 } | 795 } |
792 | 796 |
793 } // namespace content | 797 } // namespace content |
OLD | NEW |