Chromium Code Reviews| 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 "content/browser/frame_host/navigator_delegate.h" | 7 #include "content/browser/frame_host/navigator_delegate.h" |
| 8 #include "net/url_request/redirect_info.h" | 8 #include "net/url_request/redirect_info.h" |
| 9 | 9 |
| 10 namespace content { | 10 namespace content { |
| 11 | 11 |
| 12 // static | 12 // static |
| 13 scoped_ptr<NavigationHandleImpl> NavigationHandleImpl::Create( | 13 scoped_ptr<NavigationHandleImpl> NavigationHandleImpl::Create( |
| 14 const GURL& url, | 14 const GURL& url, |
| 15 const GURL& validated_url, | |
| 15 const bool is_main_frame, | 16 const bool is_main_frame, |
| 16 NavigatorDelegate* delegate) { | 17 NavigatorDelegate* delegate) { |
| 17 return scoped_ptr<NavigationHandleImpl>( | 18 return scoped_ptr<NavigationHandleImpl>( |
| 18 new NavigationHandleImpl(url, is_main_frame, delegate)); | 19 new NavigationHandleImpl(url, validated_url, is_main_frame, delegate)); |
| 19 } | 20 } |
| 20 | 21 |
| 21 NavigationHandleImpl::NavigationHandleImpl(const GURL& url, | 22 NavigationHandleImpl::NavigationHandleImpl(const GURL& url, |
| 23 const GURL& validated_url, | |
| 22 const bool is_main_frame, | 24 const bool is_main_frame, |
| 23 NavigatorDelegate* delegate) | 25 NavigatorDelegate* delegate) |
| 24 : url_(url), | 26 : url_(url), |
| 27 validated_url_(validated_url), | |
| 28 is_main_frame_(is_main_frame), | |
| 29 is_post_(false), | |
| 30 has_user_gesture_(false), | |
| 31 transition_(ui::PAGE_TRANSITION_LINK), | |
| 32 is_external_protocol_(false), | |
| 25 net_error_code_(net::OK), | 33 net_error_code_(net::OK), |
| 26 state_(DID_START), | 34 state_(DID_START), |
| 27 is_main_frame_(is_main_frame), | |
| 28 is_transferring_(false), | 35 is_transferring_(false), |
| 29 delegate_(delegate) { | 36 delegate_(delegate) { |
| 30 delegate_->DidStartNavigation(this); | 37 delegate_->DidStartNavigation(this); |
| 31 } | 38 } |
| 32 | 39 |
| 33 NavigationHandleImpl::~NavigationHandleImpl() { | 40 NavigationHandleImpl::~NavigationHandleImpl() { |
| 34 delegate_->DidFinishNavigation(this); | 41 delegate_->DidFinishNavigation(this); |
| 35 } | 42 } |
| 36 | 43 |
| 37 const GURL& NavigationHandleImpl::GetURL() const { | 44 const GURL& NavigationHandleImpl::GetURL() const { |
| 38 return url_; | 45 return url_; |
| 39 } | 46 } |
| 40 | 47 |
| 48 const GURL& NavigationHandleImpl::GetValidatedURL() const { | |
| 49 return validated_url_; | |
| 50 } | |
| 51 | |
| 52 bool NavigationHandleImpl::IsInMainFrame() const { | |
| 53 return is_main_frame_; | |
| 54 } | |
| 55 | |
| 56 bool NavigationHandleImpl::IsPost() const { | |
| 57 DCHECK(state_ != DID_START) | |
| 58 << "This accessor should not be called before the request is started."; | |
| 59 return is_post_; | |
| 60 } | |
| 61 | |
| 62 const Referrer& NavigationHandleImpl::GetSanitizedReferrer() const { | |
| 63 DCHECK(state_ != DID_START) | |
| 64 << "This accessor should not be called before the request is started."; | |
| 65 return sanitized_referrer_; | |
| 66 } | |
| 67 | |
| 68 bool NavigationHandleImpl::HasUserGesture() const { | |
| 69 DCHECK(state_ != DID_START) | |
| 70 << "This accessor should not be called before the request is started."; | |
| 71 return has_user_gesture_; | |
| 72 } | |
| 73 | |
| 74 ui::PageTransition NavigationHandleImpl::GetPageTransition() const { | |
| 75 DCHECK(state_ != DID_START) | |
| 76 << "This accessor should not be called before the request is started."; | |
| 77 return transition_; | |
| 78 } | |
| 79 | |
| 80 bool NavigationHandleImpl::IsExternalProtocol() const { | |
| 81 DCHECK(state_ != DID_START) | |
| 82 << "This accessor should not be called before the request is started."; | |
| 83 return is_external_protocol_; | |
| 84 } | |
| 85 | |
| 41 net::Error NavigationHandleImpl::GetNetErrorCode() const { | 86 net::Error NavigationHandleImpl::GetNetErrorCode() const { |
| 42 return net_error_code_; | 87 return net_error_code_; |
| 43 } | 88 } |
| 44 | 89 |
| 45 bool NavigationHandleImpl::IsInMainFrame() const { | |
| 46 return is_main_frame_; | |
| 47 } | |
| 48 | |
| 49 bool NavigationHandleImpl::HasCommittedDocument() const { | 90 bool NavigationHandleImpl::HasCommittedDocument() const { |
| 50 return state_ == DID_COMMIT; | 91 return state_ == DID_COMMIT; |
| 51 } | 92 } |
| 52 | 93 |
| 53 bool NavigationHandleImpl::HasCommittedErrorPage() const { | 94 bool NavigationHandleImpl::HasCommittedErrorPage() const { |
| 54 return state_ == DID_COMMIT_ERROR_PAGE; | 95 return state_ == DID_COMMIT_ERROR_PAGE; |
| 55 } | 96 } |
| 56 | 97 |
| 98 void NavigationHandleImpl::RegisterThrottle( | |
| 99 scoped_ptr<NavigationThrottle> navigation_throttle) { | |
| 100 throttles_.push_back(navigation_throttle.Pass()); | |
| 101 } | |
| 102 | |
| 103 NavigationThrottle::ThrottleCheckResult NavigationHandleImpl::WillStartRequest( | |
| 104 bool is_post, | |
| 105 const Referrer& sanitized_referrer, | |
| 106 bool has_user_gesture, | |
| 107 ui::PageTransition transition, | |
| 108 bool is_external_protocol) { | |
| 109 // Update the navigation parameters. | |
| 110 is_post_ = is_post; | |
| 111 sanitized_referrer_ = sanitized_referrer; | |
| 112 has_user_gesture_ = has_user_gesture; | |
| 113 transition_ = transition; | |
| 114 is_external_protocol_ = is_external_protocol; | |
| 115 | |
| 116 state_ = WILL_SEND_REQUEST; | |
| 117 | |
| 118 // Register the navigation throttles. | |
| 119 delegate_->AddNavigationThrottles(this); | |
| 120 | |
| 121 // Have each throttle be notified of the request. | |
| 122 for (auto it = throttles_.begin(); it != throttles_.end(); ++it) { | |
| 123 NavigationThrottle::ThrottleCheckResult result = (*it)->WillStartRequest(); | |
| 124 if (result == NavigationThrottle::CANCEL_AND_IGNORE) | |
| 125 return NavigationThrottle::CANCEL_AND_IGNORE; | |
| 126 } | |
| 127 return NavigationThrottle::PROCEED; | |
| 128 } | |
| 129 | |
| 130 NavigationThrottle::ThrottleCheckResult | |
| 131 NavigationHandleImpl::WillRedirectRequest(const GURL& new_url, | |
| 132 const GURL& new_validated_url, | |
| 133 bool new_method_is_post, | |
| 134 const GURL& new_referrer_url, | |
| 135 bool new_is_external_protocol) { | |
| 136 // Update the navigation parameters. | |
| 137 url_ = new_url; | |
| 138 validated_url_ = new_validated_url; | |
| 139 is_post_ = new_method_is_post; | |
| 140 sanitized_referrer_.url = new_referrer_url; | |
| 141 sanitized_referrer_ = Referrer::SanitizeForRequest(url_, sanitized_referrer_); | |
| 142 is_external_protocol_ = new_is_external_protocol; | |
| 143 | |
| 144 state_ = WILL_REDIRECT_REQUEST; | |
|
nasko
2015/09/04 00:01:52
Why did we lose the state update?
clamy
2015/09/04 12:59:14
davidben@ noticed we were not doing anything usefu
| |
| 145 | |
| 146 // Have each throttle be notified of the request. | |
| 147 for (auto it = throttles_.begin(); it != throttles_.end(); ++it) { | |
| 148 NavigationThrottle::ThrottleCheckResult result = | |
| 149 (*it)->WillRedirectRequest(); | |
| 150 if (result == NavigationThrottle::CANCEL_AND_IGNORE) | |
| 151 return NavigationThrottle::CANCEL_AND_IGNORE; | |
| 152 } | |
| 153 return NavigationThrottle::PROCEED; | |
| 154 } | |
| 155 | |
| 57 void NavigationHandleImpl::DidRedirectNavigation(const GURL& new_url) { | 156 void NavigationHandleImpl::DidRedirectNavigation(const GURL& new_url) { |
| 58 url_ = new_url; | 157 url_ = new_url; |
| 59 delegate_->DidRedirectNavigation(this); | 158 delegate_->DidRedirectNavigation(this); |
| 60 } | 159 } |
| 61 | 160 |
| 62 void NavigationHandleImpl::DidCommitNavigation() { | 161 void NavigationHandleImpl::DidCommitNavigation() { |
| 63 state_ = net_error_code_ == net::OK ? DID_COMMIT : DID_COMMIT_ERROR_PAGE; | 162 state_ = net_error_code_ == net::OK ? DID_COMMIT : DID_COMMIT_ERROR_PAGE; |
| 64 delegate_->DidCommitNavigation(this); | 163 delegate_->DidCommitNavigation(this); |
| 65 } | 164 } |
| 66 | 165 |
| 67 } // namespace content | 166 } // namespace content |
| OLD | NEW |