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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/debug/dump_without_crashing.h" | 9 #include "base/debug/dump_without_crashing.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 | 44 |
45 // static | 45 // static |
46 std::unique_ptr<NavigationHandleImpl> NavigationHandleImpl::Create( | 46 std::unique_ptr<NavigationHandleImpl> NavigationHandleImpl::Create( |
47 const GURL& url, | 47 const GURL& url, |
48 FrameTreeNode* frame_tree_node, | 48 FrameTreeNode* frame_tree_node, |
49 bool is_renderer_initiated, | 49 bool is_renderer_initiated, |
50 bool is_same_page, | 50 bool is_same_page, |
51 bool is_srcdoc, | 51 bool is_srcdoc, |
52 const base::TimeTicks& navigation_start, | 52 const base::TimeTicks& navigation_start, |
53 int pending_nav_entry_id, | 53 int pending_nav_entry_id, |
54 bool has_user_gesture, | |
54 bool started_from_context_menu) { | 55 bool started_from_context_menu) { |
55 return std::unique_ptr<NavigationHandleImpl>(new NavigationHandleImpl( | 56 return std::unique_ptr<NavigationHandleImpl>(new NavigationHandleImpl( |
56 url, frame_tree_node, is_renderer_initiated, is_same_page, is_srcdoc, | 57 url, frame_tree_node, is_renderer_initiated, is_same_page, is_srcdoc, |
57 navigation_start, pending_nav_entry_id, started_from_context_menu)); | 58 navigation_start, pending_nav_entry_id, has_user_gesture, |
59 started_from_context_menu)); | |
58 } | 60 } |
59 | 61 |
60 NavigationHandleImpl::NavigationHandleImpl( | 62 NavigationHandleImpl::NavigationHandleImpl( |
61 const GURL& url, | 63 const GURL& url, |
62 FrameTreeNode* frame_tree_node, | 64 FrameTreeNode* frame_tree_node, |
63 bool is_renderer_initiated, | 65 bool is_renderer_initiated, |
64 bool is_same_page, | 66 bool is_same_page, |
65 bool is_srcdoc, | 67 bool is_srcdoc, |
66 const base::TimeTicks& navigation_start, | 68 const base::TimeTicks& navigation_start, |
67 int pending_nav_entry_id, | 69 int pending_nav_entry_id, |
70 bool has_user_gesture, | |
68 bool started_from_context_menu) | 71 bool started_from_context_menu) |
69 : url_(url), | 72 : url_(url), |
70 has_user_gesture_(false), | 73 has_user_gesture_(has_user_gesture), |
71 transition_(ui::PAGE_TRANSITION_LINK), | 74 transition_(ui::PAGE_TRANSITION_LINK), |
72 is_external_protocol_(false), | 75 is_external_protocol_(false), |
73 net_error_code_(net::OK), | 76 net_error_code_(net::OK), |
74 render_frame_host_(nullptr), | 77 render_frame_host_(nullptr), |
75 is_renderer_initiated_(is_renderer_initiated), | 78 is_renderer_initiated_(is_renderer_initiated), |
76 is_same_page_(is_same_page), | 79 is_same_page_(is_same_page), |
77 is_srcdoc_(is_srcdoc), | 80 is_srcdoc_(is_srcdoc), |
78 was_redirected_(false), | 81 was_redirected_(false), |
79 connection_info_(net::HttpResponseInfo::CONNECTION_INFO_UNKNOWN), | 82 connection_info_(net::HttpResponseInfo::CONNECTION_INFO_UNKNOWN), |
80 original_url_(url), | 83 original_url_(url), |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 return method_ == "POST"; | 186 return method_ == "POST"; |
184 } | 187 } |
185 | 188 |
186 const Referrer& NavigationHandleImpl::GetReferrer() { | 189 const Referrer& NavigationHandleImpl::GetReferrer() { |
187 CHECK_NE(INITIAL, state_) | 190 CHECK_NE(INITIAL, state_) |
188 << "This accessor should not be called before the request is started."; | 191 << "This accessor should not be called before the request is started."; |
189 return sanitized_referrer_; | 192 return sanitized_referrer_; |
190 } | 193 } |
191 | 194 |
192 bool NavigationHandleImpl::HasUserGesture() { | 195 bool NavigationHandleImpl::HasUserGesture() { |
193 CHECK_NE(INITIAL, state_) | |
194 << "This accessor should not be called before the request is started."; | |
195 return has_user_gesture_; | 196 return has_user_gesture_; |
196 } | 197 } |
197 | 198 |
198 ui::PageTransition NavigationHandleImpl::GetPageTransition() { | 199 ui::PageTransition NavigationHandleImpl::GetPageTransition() { |
199 CHECK_NE(INITIAL, state_) | 200 CHECK_NE(INITIAL, state_) |
200 << "This accessor should not be called before the request is started."; | 201 << "This accessor should not be called before the request is started."; |
201 return transition_; | 202 return transition_; |
202 } | 203 } |
203 | 204 |
204 bool NavigationHandleImpl::IsExternalProtocol() { | 205 bool NavigationHandleImpl::IsExternalProtocol() { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 | 282 |
282 void NavigationHandleImpl::RegisterThrottleForTesting( | 283 void NavigationHandleImpl::RegisterThrottleForTesting( |
283 std::unique_ptr<NavigationThrottle> navigation_throttle) { | 284 std::unique_ptr<NavigationThrottle> navigation_throttle) { |
284 throttles_.push_back(std::move(navigation_throttle)); | 285 throttles_.push_back(std::move(navigation_throttle)); |
285 } | 286 } |
286 | 287 |
287 NavigationThrottle::ThrottleCheckResult | 288 NavigationThrottle::ThrottleCheckResult |
288 NavigationHandleImpl::CallWillStartRequestForTesting( | 289 NavigationHandleImpl::CallWillStartRequestForTesting( |
289 bool is_post, | 290 bool is_post, |
290 const Referrer& sanitized_referrer, | 291 const Referrer& sanitized_referrer, |
291 bool has_user_gesture, | |
292 ui::PageTransition transition, | 292 ui::PageTransition transition, |
293 bool is_external_protocol) { | 293 bool is_external_protocol) { |
294 NavigationThrottle::ThrottleCheckResult result = NavigationThrottle::DEFER; | 294 NavigationThrottle::ThrottleCheckResult result = NavigationThrottle::DEFER; |
295 | 295 |
296 scoped_refptr<ResourceRequestBodyImpl> resource_request_body; | 296 scoped_refptr<ResourceRequestBodyImpl> resource_request_body; |
297 std::string method = "GET"; | 297 std::string method = "GET"; |
298 if (is_post) { | 298 if (is_post) { |
299 method = "POST"; | 299 method = "POST"; |
300 | 300 |
301 std::string body = "test=body"; | 301 std::string body = "test=body"; |
302 resource_request_body = new ResourceRequestBodyImpl(); | 302 resource_request_body = new ResourceRequestBodyImpl(); |
303 resource_request_body->AppendBytes(body.data(), body.size()); | 303 resource_request_body->AppendBytes(body.data(), body.size()); |
304 } | 304 } |
305 | 305 |
306 WillStartRequest(method, resource_request_body, sanitized_referrer, | 306 WillStartRequest(method, resource_request_body, sanitized_referrer, |
307 has_user_gesture, transition, is_external_protocol, | 307 transition, is_external_protocol, |
308 REQUEST_CONTEXT_TYPE_LOCATION, | 308 REQUEST_CONTEXT_TYPE_LOCATION, |
309 base::Bind(&UpdateThrottleCheckResult, &result)); | 309 base::Bind(&UpdateThrottleCheckResult, &result)); |
310 | 310 |
311 // Reset the callback to ensure it will not be called later. | 311 // Reset the callback to ensure it will not be called later. |
312 complete_callback_.Reset(); | 312 complete_callback_.Reset(); |
313 return result; | 313 return result; |
314 } | 314 } |
315 | 315 |
316 NavigationThrottle::ThrottleCheckResult | 316 NavigationThrottle::ThrottleCheckResult |
317 NavigationHandleImpl::CallWillRedirectRequestForTesting( | 317 NavigationHandleImpl::CallWillRedirectRequestForTesting( |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
390 ServiceWorkerContextWrapper* service_worker_context) { | 390 ServiceWorkerContextWrapper* service_worker_context) { |
391 DCHECK(IsBrowserSideNavigationEnabled()); | 391 DCHECK(IsBrowserSideNavigationEnabled()); |
392 service_worker_handle_.reset( | 392 service_worker_handle_.reset( |
393 new ServiceWorkerNavigationHandle(service_worker_context)); | 393 new ServiceWorkerNavigationHandle(service_worker_context)); |
394 } | 394 } |
395 | 395 |
396 void NavigationHandleImpl::WillStartRequest( | 396 void NavigationHandleImpl::WillStartRequest( |
397 const std::string& method, | 397 const std::string& method, |
398 scoped_refptr<content::ResourceRequestBodyImpl> resource_request_body, | 398 scoped_refptr<content::ResourceRequestBodyImpl> resource_request_body, |
399 const Referrer& sanitized_referrer, | 399 const Referrer& sanitized_referrer, |
400 bool has_user_gesture, | |
401 ui::PageTransition transition, | 400 ui::PageTransition transition, |
402 bool is_external_protocol, | 401 bool is_external_protocol, |
403 RequestContextType request_context_type, | 402 RequestContextType request_context_type, |
404 const ThrottleChecksFinishedCallback& callback) { | 403 const ThrottleChecksFinishedCallback& callback) { |
405 // |method != "POST"| should imply absence of |resource_request_body|. | 404 // |method != "POST"| should imply absence of |resource_request_body|. |
406 if (method != "POST" && resource_request_body) { | 405 if (method != "POST" && resource_request_body) { |
407 NOTREACHED(); | 406 NOTREACHED(); |
408 resource_request_body = nullptr; | 407 resource_request_body = nullptr; |
409 } | 408 } |
410 | 409 |
411 // Update the navigation parameters. | 410 // Update the navigation parameters. |
412 method_ = method; | 411 method_ = method; |
413 if (method_ == "POST") | 412 if (method_ == "POST") |
414 resource_request_body_ = resource_request_body; | 413 resource_request_body_ = resource_request_body; |
415 sanitized_referrer_ = sanitized_referrer; | 414 sanitized_referrer_ = sanitized_referrer; |
416 has_user_gesture_ = has_user_gesture; | |
417 transition_ = transition; | 415 transition_ = transition; |
418 is_external_protocol_ = is_external_protocol; | 416 is_external_protocol_ = is_external_protocol; |
419 request_context_type_ = request_context_type; | 417 request_context_type_ = request_context_type; |
420 state_ = WILL_SEND_REQUEST; | 418 state_ = WILL_SEND_REQUEST; |
421 complete_callback_ = callback; | 419 complete_callback_ = callback; |
422 | 420 |
423 RegisterNavigationThrottles(); | 421 RegisterNavigationThrottles(); |
424 | 422 |
425 if (IsBrowserSideNavigationEnabled()) | 423 if (IsBrowserSideNavigationEnabled()) |
426 navigation_ui_data_ = GetDelegate()->GetNavigationUIData(this); | 424 navigation_ui_data_ = GetDelegate()->GetNavigationUIData(this); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
516 } | 514 } |
517 | 515 |
518 void NavigationHandleImpl::DidCommitNavigation( | 516 void NavigationHandleImpl::DidCommitNavigation( |
519 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, | 517 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, |
520 bool same_page, | 518 bool same_page, |
521 RenderFrameHostImpl* render_frame_host) { | 519 RenderFrameHostImpl* render_frame_host) { |
522 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); | 520 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); |
523 DCHECK_EQ(frame_tree_node_, render_frame_host->frame_tree_node()); | 521 DCHECK_EQ(frame_tree_node_, render_frame_host->frame_tree_node()); |
524 CHECK_EQ(url_, params.url); | 522 CHECK_EQ(url_, params.url); |
525 | 523 |
526 method_ = params.method; | 524 method_ = params.method; |
clamy
2016/11/17 14:30:04
I think it'd be nice to DCHECK here that the gestu
Bryan McQuade
2016/11/19 20:21:38
I agree - this seems like something we should do.
clamy
2016/11/21 16:50:46
Acknowledged. Could you add a TODO(clamy) to check
Bryan McQuade
2016/11/22 14:13:03
Done.
| |
527 has_user_gesture_ = (params.gesture == NavigationGestureUser); | |
528 transition_ = params.transition; | 525 transition_ = params.transition; |
529 render_frame_host_ = render_frame_host; | 526 render_frame_host_ = render_frame_host; |
530 | 527 |
531 // If an error page reloads, net_error_code might be 200 but we still want to | 528 // If an error page reloads, net_error_code might be 200 but we still want to |
532 // count it as an error page. | 529 // count it as an error page. |
533 if (params.base_url.spec() == kUnreachableWebDataURL || | 530 if (params.base_url.spec() == kUnreachableWebDataURL || |
534 net_error_code_ != net::OK) { | 531 net_error_code_ != net::OK) { |
535 state_ = DID_COMMIT_ERROR_PAGE; | 532 state_ = DID_COMMIT_ERROR_PAGE; |
536 } else { | 533 } else { |
537 state_ = DID_COMMIT; | 534 state_ = DID_COMMIT; |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
767 throttles_to_register.push_back(std::move(clear_site_data_throttle)); | 764 throttles_to_register.push_back(std::move(clear_site_data_throttle)); |
768 | 765 |
769 if (throttles_to_register.size() > 0) { | 766 if (throttles_to_register.size() > 0) { |
770 throttles_.insert(throttles_.begin(), throttles_to_register.begin(), | 767 throttles_.insert(throttles_.begin(), throttles_to_register.begin(), |
771 throttles_to_register.end()); | 768 throttles_to_register.end()); |
772 throttles_to_register.weak_clear(); | 769 throttles_to_register.weak_clear(); |
773 } | 770 } |
774 } | 771 } |
775 | 772 |
776 } // namespace content | 773 } // namespace content |
OLD | NEW |