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/appcache/appcache_navigation_handle.h" | 9 #include "content/browser/appcache/appcache_navigation_handle.h" |
10 #include "content/browser/appcache/appcache_service_impl.h" | 10 #include "content/browser/appcache/appcache_service_impl.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 } // namespace | 50 } // namespace |
51 | 51 |
52 // static | 52 // static |
53 std::unique_ptr<NavigationHandleImpl> NavigationHandleImpl::Create( | 53 std::unique_ptr<NavigationHandleImpl> NavigationHandleImpl::Create( |
54 const GURL& url, | 54 const GURL& url, |
55 FrameTreeNode* frame_tree_node, | 55 FrameTreeNode* frame_tree_node, |
56 bool is_renderer_initiated, | 56 bool is_renderer_initiated, |
57 bool is_same_page, | 57 bool is_same_page, |
58 const base::TimeTicks& navigation_start, | 58 const base::TimeTicks& navigation_start, |
59 int pending_nav_entry_id, | 59 int pending_nav_entry_id, |
60 NavigationGesture gesture, | |
61 bool started_from_context_menu) { | 60 bool started_from_context_menu) { |
62 return std::unique_ptr<NavigationHandleImpl>(new NavigationHandleImpl( | 61 return std::unique_ptr<NavigationHandleImpl>(new NavigationHandleImpl( |
63 url, frame_tree_node, is_renderer_initiated, is_same_page, | 62 url, frame_tree_node, is_renderer_initiated, is_same_page, |
64 navigation_start, pending_nav_entry_id, gesture, | 63 navigation_start, pending_nav_entry_id, |
65 started_from_context_menu)); | 64 started_from_context_menu)); |
66 } | 65 } |
67 | 66 |
68 NavigationHandleImpl::NavigationHandleImpl( | 67 NavigationHandleImpl::NavigationHandleImpl( |
69 const GURL& url, | 68 const GURL& url, |
70 FrameTreeNode* frame_tree_node, | 69 FrameTreeNode* frame_tree_node, |
71 bool is_renderer_initiated, | 70 bool is_renderer_initiated, |
72 bool is_same_page, | 71 bool is_same_page, |
73 const base::TimeTicks& navigation_start, | 72 const base::TimeTicks& navigation_start, |
74 int pending_nav_entry_id, | 73 int pending_nav_entry_id, |
75 NavigationGesture gesture, | |
76 bool started_from_context_menu) | 74 bool started_from_context_menu) |
77 : url_(url), | 75 : url_(url), |
78 gesture_(gesture), | 76 has_user_gesture_(false), |
79 transition_(ui::PAGE_TRANSITION_LINK), | 77 transition_(ui::PAGE_TRANSITION_LINK), |
80 is_external_protocol_(false), | 78 is_external_protocol_(false), |
81 net_error_code_(net::OK), | 79 net_error_code_(net::OK), |
82 render_frame_host_(nullptr), | 80 render_frame_host_(nullptr), |
83 is_renderer_initiated_(is_renderer_initiated), | 81 is_renderer_initiated_(is_renderer_initiated), |
84 is_same_page_(is_same_page), | 82 is_same_page_(is_same_page), |
85 was_redirected_(false), | 83 was_redirected_(false), |
86 connection_info_(net::HttpResponseInfo::CONNECTION_INFO_UNKNOWN), | 84 connection_info_(net::HttpResponseInfo::CONNECTION_INFO_UNKNOWN), |
87 original_url_(url), | 85 original_url_(url), |
88 state_(INITIAL), | 86 state_(INITIAL), |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 return method_ == "POST"; | 193 return method_ == "POST"; |
196 } | 194 } |
197 | 195 |
198 const Referrer& NavigationHandleImpl::GetReferrer() { | 196 const Referrer& NavigationHandleImpl::GetReferrer() { |
199 CHECK_NE(INITIAL, state_) | 197 CHECK_NE(INITIAL, state_) |
200 << "This accessor should not be called before the request is started."; | 198 << "This accessor should not be called before the request is started."; |
201 return sanitized_referrer_; | 199 return sanitized_referrer_; |
202 } | 200 } |
203 | 201 |
204 bool NavigationHandleImpl::HasUserGesture() { | 202 bool NavigationHandleImpl::HasUserGesture() { |
205 return gesture_ == NavigationGestureUser; | 203 CHECK_NE(INITIAL, state_) |
| 204 << "This accessor should not be called before the request is started."; |
| 205 return has_user_gesture_; |
206 } | 206 } |
207 | 207 |
208 ui::PageTransition NavigationHandleImpl::GetPageTransition() { | 208 ui::PageTransition NavigationHandleImpl::GetPageTransition() { |
209 CHECK_NE(INITIAL, state_) | 209 CHECK_NE(INITIAL, state_) |
210 << "This accessor should not be called before the request is started."; | 210 << "This accessor should not be called before the request is started."; |
211 return transition_; | 211 return transition_; |
212 } | 212 } |
213 | 213 |
214 bool NavigationHandleImpl::IsExternalProtocol() { | 214 bool NavigationHandleImpl::IsExternalProtocol() { |
215 CHECK_NE(INITIAL, state_) | 215 CHECK_NE(INITIAL, state_) |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 | 291 |
292 void NavigationHandleImpl::RegisterThrottleForTesting( | 292 void NavigationHandleImpl::RegisterThrottleForTesting( |
293 std::unique_ptr<NavigationThrottle> navigation_throttle) { | 293 std::unique_ptr<NavigationThrottle> navigation_throttle) { |
294 throttles_.push_back(std::move(navigation_throttle)); | 294 throttles_.push_back(std::move(navigation_throttle)); |
295 } | 295 } |
296 | 296 |
297 NavigationThrottle::ThrottleCheckResult | 297 NavigationThrottle::ThrottleCheckResult |
298 NavigationHandleImpl::CallWillStartRequestForTesting( | 298 NavigationHandleImpl::CallWillStartRequestForTesting( |
299 bool is_post, | 299 bool is_post, |
300 const Referrer& sanitized_referrer, | 300 const Referrer& sanitized_referrer, |
| 301 bool has_user_gesture, |
301 ui::PageTransition transition, | 302 ui::PageTransition transition, |
302 bool is_external_protocol) { | 303 bool is_external_protocol) { |
303 NavigationThrottle::ThrottleCheckResult result = NavigationThrottle::DEFER; | 304 NavigationThrottle::ThrottleCheckResult result = NavigationThrottle::DEFER; |
304 | 305 |
305 scoped_refptr<ResourceRequestBodyImpl> resource_request_body; | 306 scoped_refptr<ResourceRequestBodyImpl> resource_request_body; |
306 std::string method = "GET"; | 307 std::string method = "GET"; |
307 if (is_post) { | 308 if (is_post) { |
308 method = "POST"; | 309 method = "POST"; |
309 | 310 |
310 std::string body = "test=body"; | 311 std::string body = "test=body"; |
311 resource_request_body = new ResourceRequestBodyImpl(); | 312 resource_request_body = new ResourceRequestBodyImpl(); |
312 resource_request_body->AppendBytes(body.data(), body.size()); | 313 resource_request_body->AppendBytes(body.data(), body.size()); |
313 } | 314 } |
314 | 315 |
315 WillStartRequest(method, resource_request_body, sanitized_referrer, | 316 WillStartRequest(method, resource_request_body, sanitized_referrer, |
316 transition, is_external_protocol, | 317 has_user_gesture, transition, is_external_protocol, |
317 REQUEST_CONTEXT_TYPE_LOCATION, | 318 REQUEST_CONTEXT_TYPE_LOCATION, |
318 base::Bind(&UpdateThrottleCheckResult, &result)); | 319 base::Bind(&UpdateThrottleCheckResult, &result)); |
319 | 320 |
320 // Reset the callback to ensure it will not be called later. | 321 // Reset the callback to ensure it will not be called later. |
321 complete_callback_.Reset(); | 322 complete_callback_.Reset(); |
322 return result; | 323 return result; |
323 } | 324 } |
324 | 325 |
325 NavigationThrottle::ThrottleCheckResult | 326 NavigationThrottle::ThrottleCheckResult |
326 NavigationHandleImpl::CallWillRedirectRequestForTesting( | 327 NavigationHandleImpl::CallWillRedirectRequestForTesting( |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 void NavigationHandleImpl::InitAppCacheHandle( | 412 void NavigationHandleImpl::InitAppCacheHandle( |
412 ChromeAppCacheService* appcache_service) { | 413 ChromeAppCacheService* appcache_service) { |
413 DCHECK(IsBrowserSideNavigationEnabled()); | 414 DCHECK(IsBrowserSideNavigationEnabled()); |
414 appcache_handle_.reset(new AppCacheNavigationHandle(appcache_service)); | 415 appcache_handle_.reset(new AppCacheNavigationHandle(appcache_service)); |
415 } | 416 } |
416 | 417 |
417 void NavigationHandleImpl::WillStartRequest( | 418 void NavigationHandleImpl::WillStartRequest( |
418 const std::string& method, | 419 const std::string& method, |
419 scoped_refptr<content::ResourceRequestBodyImpl> resource_request_body, | 420 scoped_refptr<content::ResourceRequestBodyImpl> resource_request_body, |
420 const Referrer& sanitized_referrer, | 421 const Referrer& sanitized_referrer, |
| 422 bool has_user_gesture, |
421 ui::PageTransition transition, | 423 ui::PageTransition transition, |
422 bool is_external_protocol, | 424 bool is_external_protocol, |
423 RequestContextType request_context_type, | 425 RequestContextType request_context_type, |
424 const ThrottleChecksFinishedCallback& callback) { | 426 const ThrottleChecksFinishedCallback& callback) { |
425 if (method != "POST") | 427 if (method != "POST") |
426 DCHECK(!resource_request_body); | 428 DCHECK(!resource_request_body); |
427 | 429 |
428 // Update the navigation parameters. | 430 // Update the navigation parameters. |
429 method_ = method; | 431 method_ = method; |
430 if (method_ == "POST") | 432 if (method_ == "POST") |
431 resource_request_body_ = resource_request_body; | 433 resource_request_body_ = resource_request_body; |
432 sanitized_referrer_ = sanitized_referrer; | 434 sanitized_referrer_ = sanitized_referrer; |
| 435 has_user_gesture_ = has_user_gesture; |
433 transition_ = transition; | 436 transition_ = transition; |
434 is_external_protocol_ = is_external_protocol; | 437 is_external_protocol_ = is_external_protocol; |
435 request_context_type_ = request_context_type; | 438 request_context_type_ = request_context_type; |
436 state_ = WILL_SEND_REQUEST; | 439 state_ = WILL_SEND_REQUEST; |
437 complete_callback_ = callback; | 440 complete_callback_ = callback; |
438 | 441 |
439 RegisterNavigationThrottles(); | 442 RegisterNavigationThrottles(); |
440 | 443 |
441 if (IsBrowserSideNavigationEnabled()) | 444 if (IsBrowserSideNavigationEnabled()) |
442 navigation_ui_data_ = GetDelegate()->GetNavigationUIData(this); | 445 navigation_ui_data_ = GetDelegate()->GetNavigationUIData(this); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 } | 535 } |
533 | 536 |
534 void NavigationHandleImpl::DidCommitNavigation( | 537 void NavigationHandleImpl::DidCommitNavigation( |
535 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, | 538 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, |
536 bool same_page, | 539 bool same_page, |
537 RenderFrameHostImpl* render_frame_host) { | 540 RenderFrameHostImpl* render_frame_host) { |
538 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); | 541 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); |
539 DCHECK_EQ(frame_tree_node_, render_frame_host->frame_tree_node()); | 542 DCHECK_EQ(frame_tree_node_, render_frame_host->frame_tree_node()); |
540 CHECK_EQ(url_, params.url); | 543 CHECK_EQ(url_, params.url); |
541 | 544 |
542 // TODO(clamy): Once crbug.com/667572 is addressed, apply this DCHECK on all | |
543 // navigations, not just same-page navigations, and make gesture_ a const | |
544 // member, set only in the constructor. | |
545 if (same_page) | |
546 DCHECK_EQ(gesture_, params.gesture); | |
547 gesture_ = params.gesture; | |
548 | |
549 method_ = params.method; | 545 method_ = params.method; |
| 546 has_user_gesture_ = (params.gesture == NavigationGestureUser); |
550 transition_ = params.transition; | 547 transition_ = params.transition; |
551 render_frame_host_ = render_frame_host; | 548 render_frame_host_ = render_frame_host; |
552 | 549 |
553 // 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 |
554 // count it as an error page. | 551 // count it as an error page. |
555 if (params.base_url.spec() == kUnreachableWebDataURL || | 552 if (params.base_url.spec() == kUnreachableWebDataURL || |
556 net_error_code_ != net::OK) { | 553 net_error_code_ != net::OK) { |
557 state_ = DID_COMMIT_ERROR_PAGE; | 554 state_ = DID_COMMIT_ERROR_PAGE; |
558 } else { | 555 } else { |
559 state_ = DID_COMMIT; | 556 state_ = DID_COMMIT; |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 throttles_to_register.push_back(std::move(clear_site_data_throttle)); | 786 throttles_to_register.push_back(std::move(clear_site_data_throttle)); |
790 | 787 |
791 if (throttles_to_register.size() > 0) { | 788 if (throttles_to_register.size() > 0) { |
792 throttles_.insert(throttles_.begin(), throttles_to_register.begin(), | 789 throttles_.insert(throttles_.begin(), throttles_to_register.begin(), |
793 throttles_to_register.end()); | 790 throttles_to_register.end()); |
794 throttles_to_register.weak_clear(); | 791 throttles_to_register.weak_clear(); |
795 } | 792 } |
796 } | 793 } |
797 | 794 |
798 } // namespace content | 795 } // namespace content |
OLD | NEW |