| 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "content/browser/frame_host/frame_tree_node.h" | 8 #include "content/browser/frame_host/frame_tree_node.h" |
| 9 #include "content/browser/frame_host/navigator.h" | 9 #include "content/browser/frame_host/navigator.h" |
| 10 #include "content/browser/frame_host/navigator_delegate.h" | 10 #include "content/browser/frame_host/navigator_delegate.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 partition->GetServiceWorkerContext()); | 73 partition->GetServiceWorkerContext()); |
| 74 service_worker_handle_.reset( | 74 service_worker_handle_.reset( |
| 75 new ServiceWorkerNavigationHandle(service_worker_context)); | 75 new ServiceWorkerNavigationHandle(service_worker_context)); |
| 76 } | 76 } |
| 77 | 77 |
| 78 GetDelegate()->DidStartNavigation(this); | 78 GetDelegate()->DidStartNavigation(this); |
| 79 } | 79 } |
| 80 | 80 |
| 81 NavigationHandleImpl::~NavigationHandleImpl() { | 81 NavigationHandleImpl::~NavigationHandleImpl() { |
| 82 GetDelegate()->DidFinishNavigation(this); | 82 GetDelegate()->DidFinishNavigation(this); |
| 83 |
| 84 // Cancel the navigation on the IO thread if the NavigationHandle was |
| 85 // destroyed in the middle of the NavigationThrottles checks. |
| 86 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 87 switches::kEnableBrowserSideNavigation) && |
| 88 !complete_callback_.is_null()) { |
| 89 complete_callback_.Run(NavigationThrottle::CANCEL_AND_IGNORE); |
| 90 } |
| 83 } | 91 } |
| 84 | 92 |
| 85 NavigatorDelegate* NavigationHandleImpl::GetDelegate() const { | 93 NavigatorDelegate* NavigationHandleImpl::GetDelegate() const { |
| 86 return frame_tree_node_->navigator()->GetDelegate(); | 94 return frame_tree_node_->navigator()->GetDelegate(); |
| 87 } | 95 } |
| 88 | 96 |
| 89 const GURL& NavigationHandleImpl::GetURL() { | 97 const GURL& NavigationHandleImpl::GetURL() { |
| 90 return url_; | 98 return url_; |
| 91 } | 99 } |
| 92 | 100 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 | 160 |
| 153 void NavigationHandleImpl::Resume() { | 161 void NavigationHandleImpl::Resume() { |
| 154 CHECK(state_ == DEFERRING_START || state_ == DEFERRING_REDIRECT); | 162 CHECK(state_ == DEFERRING_START || state_ == DEFERRING_REDIRECT); |
| 155 NavigationThrottle::ThrottleCheckResult result = NavigationThrottle::DEFER; | 163 NavigationThrottle::ThrottleCheckResult result = NavigationThrottle::DEFER; |
| 156 if (state_ == DEFERRING_START) { | 164 if (state_ == DEFERRING_START) { |
| 157 result = CheckWillStartRequest(); | 165 result = CheckWillStartRequest(); |
| 158 } else { | 166 } else { |
| 159 result = CheckWillRedirectRequest(); | 167 result = CheckWillRedirectRequest(); |
| 160 } | 168 } |
| 161 | 169 |
| 162 if (result != NavigationThrottle::DEFER) | 170 // If the navigation is not deferred and the NavigationHandle wasn't |
| 163 complete_callback_.Run(result); | 171 // destroyed, run the callback. |
| 172 if (result == NavigationThrottle::DEFER || |
| 173 result == NavigationThrottle::DESTROYED) |
| 174 return; |
| 175 |
| 176 complete_callback_.Run(result); |
| 177 complete_callback_.Reset(); |
| 164 } | 178 } |
| 165 | 179 |
| 166 void NavigationHandleImpl::RegisterThrottleForTesting( | 180 void NavigationHandleImpl::RegisterThrottleForTesting( |
| 167 scoped_ptr<NavigationThrottle> navigation_throttle) { | 181 scoped_ptr<NavigationThrottle> navigation_throttle) { |
| 168 throttles_.push_back(navigation_throttle.Pass()); | 182 throttles_.push_back(navigation_throttle.Pass()); |
| 169 } | 183 } |
| 170 | 184 |
| 171 NavigationThrottle::ThrottleCheckResult | 185 NavigationThrottle::ThrottleCheckResult |
| 172 NavigationHandleImpl::CallWillStartRequestForTesting( | 186 NavigationHandleImpl::CallWillStartRequestForTesting( |
| 173 bool is_post, | 187 bool is_post, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 GetContentClient()->browser()->CreateThrottlesForNavigation(this); | 240 GetContentClient()->browser()->CreateThrottlesForNavigation(this); |
| 227 if (throttles_to_register.size() > 0) { | 241 if (throttles_to_register.size() > 0) { |
| 228 throttles_.insert(throttles_.end(), throttles_to_register.begin(), | 242 throttles_.insert(throttles_.end(), throttles_to_register.begin(), |
| 229 throttles_to_register.end()); | 243 throttles_to_register.end()); |
| 230 throttles_to_register.weak_clear(); | 244 throttles_to_register.weak_clear(); |
| 231 } | 245 } |
| 232 | 246 |
| 233 // Notify each throttle of the request. | 247 // Notify each throttle of the request. |
| 234 NavigationThrottle::ThrottleCheckResult result = CheckWillStartRequest(); | 248 NavigationThrottle::ThrottleCheckResult result = CheckWillStartRequest(); |
| 235 | 249 |
| 236 // If the navigation is not deferred, run the callback. | 250 // If the navigation is not deferred and the NavigationHandle wasn't |
| 237 if (result != NavigationThrottle::DEFER) | 251 // destroyed, run the callback. |
| 238 callback.Run(result); | 252 if (result == NavigationThrottle::DEFER || |
| 253 result == NavigationThrottle::DESTROYED) |
| 254 return; |
| 255 |
| 256 complete_callback_.Run(result); |
| 257 complete_callback_.Reset(); |
| 239 } | 258 } |
| 240 | 259 |
| 241 void NavigationHandleImpl::WillRedirectRequest( | 260 void NavigationHandleImpl::WillRedirectRequest( |
| 242 const GURL& new_url, | 261 const GURL& new_url, |
| 243 bool new_method_is_post, | 262 bool new_method_is_post, |
| 244 const GURL& new_referrer_url, | 263 const GURL& new_referrer_url, |
| 245 bool new_is_external_protocol, | 264 bool new_is_external_protocol, |
| 246 const ThrottleChecksFinishedCallback& callback) { | 265 const ThrottleChecksFinishedCallback& callback) { |
| 247 // Update the navigation parameters. | 266 // Update the navigation parameters. |
| 248 url_ = new_url; | 267 url_ = new_url; |
| 249 is_post_ = new_method_is_post; | 268 is_post_ = new_method_is_post; |
| 250 sanitized_referrer_.url = new_referrer_url; | 269 sanitized_referrer_.url = new_referrer_url; |
| 251 sanitized_referrer_ = Referrer::SanitizeForRequest(url_, sanitized_referrer_); | 270 sanitized_referrer_ = Referrer::SanitizeForRequest(url_, sanitized_referrer_); |
| 252 is_external_protocol_ = new_is_external_protocol; | 271 is_external_protocol_ = new_is_external_protocol; |
| 253 | 272 |
| 254 state_ = WILL_REDIRECT_REQUEST; | 273 state_ = WILL_REDIRECT_REQUEST; |
| 255 complete_callback_ = callback; | 274 complete_callback_ = callback; |
| 256 | 275 |
| 257 // Notify each throttle of the request. | 276 // Notify each throttle of the request. |
| 258 NavigationThrottle::ThrottleCheckResult result = CheckWillRedirectRequest(); | 277 NavigationThrottle::ThrottleCheckResult result = CheckWillRedirectRequest(); |
| 259 | 278 |
| 260 // If the navigation is not deferred, run the callback. | 279 // If the navigation is not deferred and the NavigationHandle wasn't |
| 261 if (result != NavigationThrottle::DEFER) | 280 // destroyed, run the callback. |
| 262 callback.Run(result); | 281 if (result == NavigationThrottle::DEFER || |
| 282 result == NavigationThrottle::DESTROYED) |
| 283 return; |
| 284 |
| 285 complete_callback_.Run(result); |
| 286 complete_callback_.Reset(); |
| 263 } | 287 } |
| 264 | 288 |
| 265 void NavigationHandleImpl::DidRedirectNavigation(const GURL& new_url) { | 289 void NavigationHandleImpl::DidRedirectNavigation(const GURL& new_url) { |
| 266 url_ = new_url; | 290 url_ = new_url; |
| 267 GetDelegate()->DidRedirectNavigation(this); | 291 GetDelegate()->DidRedirectNavigation(this); |
| 268 } | 292 } |
| 269 | 293 |
| 270 void NavigationHandleImpl::ReadyToCommitNavigation( | 294 void NavigationHandleImpl::ReadyToCommitNavigation( |
| 271 RenderFrameHostImpl* render_frame_host) { | 295 RenderFrameHostImpl* render_frame_host) { |
| 272 CHECK(!render_frame_host_); | 296 CHECK(!render_frame_host_); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 290 DCHECK(state_ != WILL_SEND_REQUEST || next_index_ == 0); | 314 DCHECK(state_ != WILL_SEND_REQUEST || next_index_ == 0); |
| 291 DCHECK(state_ != DEFERRING_START || next_index_ != 0); | 315 DCHECK(state_ != DEFERRING_START || next_index_ != 0); |
| 292 for (size_t i = next_index_; i < throttles_.size(); ++i) { | 316 for (size_t i = next_index_; i < throttles_.size(); ++i) { |
| 293 NavigationThrottle::ThrottleCheckResult result = | 317 NavigationThrottle::ThrottleCheckResult result = |
| 294 throttles_[i]->WillStartRequest(); | 318 throttles_[i]->WillStartRequest(); |
| 295 switch (result) { | 319 switch (result) { |
| 296 case NavigationThrottle::PROCEED: | 320 case NavigationThrottle::PROCEED: |
| 297 continue; | 321 continue; |
| 298 | 322 |
| 299 case NavigationThrottle::CANCEL_AND_IGNORE: | 323 case NavigationThrottle::CANCEL_AND_IGNORE: |
| 324 case NavigationThrottle::DESTROYED: |
| 300 return result; | 325 return result; |
| 301 | 326 |
| 302 case NavigationThrottle::DEFER: | 327 case NavigationThrottle::DEFER: |
| 303 state_ = DEFERRING_START; | 328 state_ = DEFERRING_START; |
| 304 next_index_ = i + 1; | 329 next_index_ = i + 1; |
| 305 return result; | 330 return result; |
| 306 | 331 |
| 307 default: | 332 default: |
| 308 NOTREACHED(); | 333 NOTREACHED(); |
| 309 } | 334 } |
| 310 } | 335 } |
| 311 next_index_ = 0; | 336 next_index_ = 0; |
| 312 state_ = WILL_SEND_REQUEST; | 337 state_ = WILL_SEND_REQUEST; |
| 313 return NavigationThrottle::PROCEED; | 338 return NavigationThrottle::PROCEED; |
| 314 } | 339 } |
| 315 | 340 |
| 316 NavigationThrottle::ThrottleCheckResult | 341 NavigationThrottle::ThrottleCheckResult |
| 317 NavigationHandleImpl::CheckWillRedirectRequest() { | 342 NavigationHandleImpl::CheckWillRedirectRequest() { |
| 318 DCHECK(state_ == WILL_REDIRECT_REQUEST || state_ == DEFERRING_REDIRECT); | 343 DCHECK(state_ == WILL_REDIRECT_REQUEST || state_ == DEFERRING_REDIRECT); |
| 319 DCHECK(state_ != WILL_REDIRECT_REQUEST || next_index_ == 0); | 344 DCHECK(state_ != WILL_REDIRECT_REQUEST || next_index_ == 0); |
| 320 DCHECK(state_ != DEFERRING_REDIRECT || next_index_ != 0); | 345 DCHECK(state_ != DEFERRING_REDIRECT || next_index_ != 0); |
| 321 for (size_t i = next_index_; i < throttles_.size(); ++i) { | 346 for (size_t i = next_index_; i < throttles_.size(); ++i) { |
| 322 NavigationThrottle::ThrottleCheckResult result = | 347 NavigationThrottle::ThrottleCheckResult result = |
| 323 throttles_[i]->WillRedirectRequest(); | 348 throttles_[i]->WillRedirectRequest(); |
| 324 switch (result) { | 349 switch (result) { |
| 325 case NavigationThrottle::PROCEED: | 350 case NavigationThrottle::PROCEED: |
| 326 continue; | 351 continue; |
| 327 | 352 |
| 328 case NavigationThrottle::CANCEL_AND_IGNORE: | 353 case NavigationThrottle::CANCEL_AND_IGNORE: |
| 354 case NavigationThrottle::DESTROYED: |
| 329 return result; | 355 return result; |
| 330 | 356 |
| 331 case NavigationThrottle::DEFER: | 357 case NavigationThrottle::DEFER: |
| 332 state_ = DEFERRING_REDIRECT; | 358 state_ = DEFERRING_REDIRECT; |
| 333 next_index_ = i + 1; | 359 next_index_ = i + 1; |
| 334 return result; | 360 return result; |
| 335 | 361 |
| 336 default: | 362 default: |
| 337 NOTREACHED(); | 363 NOTREACHED(); |
| 338 } | 364 } |
| 339 } | 365 } |
| 340 next_index_ = 0; | 366 next_index_ = 0; |
| 341 state_ = WILL_REDIRECT_REQUEST; | 367 state_ = WILL_REDIRECT_REQUEST; |
| 342 return NavigationThrottle::PROCEED; | 368 return NavigationThrottle::PROCEED; |
| 343 } | 369 } |
| 344 | 370 |
| 345 } // namespace content | 371 } // namespace content |
| OLD | NEW |