| 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 is being |
| 85 // destroyed in the middle of the NavigationThrottles checks. |
| 86 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 87 switches::kEnableBrowserSideNavigation) && |
| 88 !complete_callback_.is_null()) { |
| 89 RunCompleteCallback(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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 (result != NavigationThrottle::DEFER) |
| 163 complete_callback_.Run(result); | 171 RunCompleteCallback(result); |
| 172 } |
| 173 |
| 174 void NavigationHandleImpl::CancelDeferredNavigation( |
| 175 NavigationThrottle::ThrottleCheckResult result) { |
| 176 DCHECK(state_ == DEFERRING_START || state_ == DEFERRING_REDIRECT); |
| 177 DCHECK(result == NavigationThrottle::CANCEL_AND_IGNORE || |
| 178 result == NavigationThrottle::CANCEL); |
| 179 state_ = CANCELING; |
| 180 RunCompleteCallback(result); |
| 164 } | 181 } |
| 165 | 182 |
| 166 void NavigationHandleImpl::RegisterThrottleForTesting( | 183 void NavigationHandleImpl::RegisterThrottleForTesting( |
| 167 scoped_ptr<NavigationThrottle> navigation_throttle) { | 184 scoped_ptr<NavigationThrottle> navigation_throttle) { |
| 168 throttles_.push_back(navigation_throttle.Pass()); | 185 throttles_.push_back(navigation_throttle.Pass()); |
| 169 } | 186 } |
| 170 | 187 |
| 171 NavigationThrottle::ThrottleCheckResult | 188 NavigationThrottle::ThrottleCheckResult |
| 172 NavigationHandleImpl::CallWillStartRequestForTesting( | 189 NavigationHandleImpl::CallWillStartRequestForTesting( |
| 173 bool is_post, | 190 bool is_post, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 throttles_.insert(throttles_.end(), throttles_to_register.begin(), | 245 throttles_.insert(throttles_.end(), throttles_to_register.begin(), |
| 229 throttles_to_register.end()); | 246 throttles_to_register.end()); |
| 230 throttles_to_register.weak_clear(); | 247 throttles_to_register.weak_clear(); |
| 231 } | 248 } |
| 232 | 249 |
| 233 // Notify each throttle of the request. | 250 // Notify each throttle of the request. |
| 234 NavigationThrottle::ThrottleCheckResult result = CheckWillStartRequest(); | 251 NavigationThrottle::ThrottleCheckResult result = CheckWillStartRequest(); |
| 235 | 252 |
| 236 // If the navigation is not deferred, run the callback. | 253 // If the navigation is not deferred, run the callback. |
| 237 if (result != NavigationThrottle::DEFER) | 254 if (result != NavigationThrottle::DEFER) |
| 238 callback.Run(result); | 255 RunCompleteCallback(result); |
| 239 } | 256 } |
| 240 | 257 |
| 241 void NavigationHandleImpl::WillRedirectRequest( | 258 void NavigationHandleImpl::WillRedirectRequest( |
| 242 const GURL& new_url, | 259 const GURL& new_url, |
| 243 bool new_method_is_post, | 260 bool new_method_is_post, |
| 244 const GURL& new_referrer_url, | 261 const GURL& new_referrer_url, |
| 245 bool new_is_external_protocol, | 262 bool new_is_external_protocol, |
| 246 const ThrottleChecksFinishedCallback& callback) { | 263 const ThrottleChecksFinishedCallback& callback) { |
| 247 // Update the navigation parameters. | 264 // Update the navigation parameters. |
| 248 url_ = new_url; | 265 url_ = new_url; |
| 249 is_post_ = new_method_is_post; | 266 is_post_ = new_method_is_post; |
| 250 sanitized_referrer_.url = new_referrer_url; | 267 sanitized_referrer_.url = new_referrer_url; |
| 251 sanitized_referrer_ = Referrer::SanitizeForRequest(url_, sanitized_referrer_); | 268 sanitized_referrer_ = Referrer::SanitizeForRequest(url_, sanitized_referrer_); |
| 252 is_external_protocol_ = new_is_external_protocol; | 269 is_external_protocol_ = new_is_external_protocol; |
| 253 | 270 |
| 254 state_ = WILL_REDIRECT_REQUEST; | 271 state_ = WILL_REDIRECT_REQUEST; |
| 255 complete_callback_ = callback; | 272 complete_callback_ = callback; |
| 256 | 273 |
| 257 // Notify each throttle of the request. | 274 // Notify each throttle of the request. |
| 258 NavigationThrottle::ThrottleCheckResult result = CheckWillRedirectRequest(); | 275 NavigationThrottle::ThrottleCheckResult result = CheckWillRedirectRequest(); |
| 259 | 276 |
| 260 // If the navigation is not deferred, run the callback. | 277 // If the navigation is not deferred, run the callback. |
| 261 if (result != NavigationThrottle::DEFER) | 278 if (result != NavigationThrottle::DEFER) |
| 262 callback.Run(result); | 279 RunCompleteCallback(result); |
| 263 } | 280 } |
| 264 | 281 |
| 265 void NavigationHandleImpl::DidRedirectNavigation(const GURL& new_url) { | 282 void NavigationHandleImpl::DidRedirectNavigation(const GURL& new_url) { |
| 266 url_ = new_url; | 283 url_ = new_url; |
| 267 GetDelegate()->DidRedirectNavigation(this); | 284 GetDelegate()->DidRedirectNavigation(this); |
| 268 } | 285 } |
| 269 | 286 |
| 270 void NavigationHandleImpl::ReadyToCommitNavigation( | 287 void NavigationHandleImpl::ReadyToCommitNavigation( |
| 271 RenderFrameHostImpl* render_frame_host) { | 288 RenderFrameHostImpl* render_frame_host) { |
| 272 CHECK(!render_frame_host_); | 289 CHECK(!render_frame_host_); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 289 DCHECK(state_ == WILL_SEND_REQUEST || state_ == DEFERRING_START); | 306 DCHECK(state_ == WILL_SEND_REQUEST || state_ == DEFERRING_START); |
| 290 DCHECK(state_ != WILL_SEND_REQUEST || next_index_ == 0); | 307 DCHECK(state_ != WILL_SEND_REQUEST || next_index_ == 0); |
| 291 DCHECK(state_ != DEFERRING_START || next_index_ != 0); | 308 DCHECK(state_ != DEFERRING_START || next_index_ != 0); |
| 292 for (size_t i = next_index_; i < throttles_.size(); ++i) { | 309 for (size_t i = next_index_; i < throttles_.size(); ++i) { |
| 293 NavigationThrottle::ThrottleCheckResult result = | 310 NavigationThrottle::ThrottleCheckResult result = |
| 294 throttles_[i]->WillStartRequest(); | 311 throttles_[i]->WillStartRequest(); |
| 295 switch (result) { | 312 switch (result) { |
| 296 case NavigationThrottle::PROCEED: | 313 case NavigationThrottle::PROCEED: |
| 297 continue; | 314 continue; |
| 298 | 315 |
| 316 case NavigationThrottle::CANCEL: |
| 299 case NavigationThrottle::CANCEL_AND_IGNORE: | 317 case NavigationThrottle::CANCEL_AND_IGNORE: |
| 318 state_ = CANCELING; |
| 300 return result; | 319 return result; |
| 301 | 320 |
| 302 case NavigationThrottle::DEFER: | 321 case NavigationThrottle::DEFER: |
| 303 state_ = DEFERRING_START; | 322 state_ = DEFERRING_START; |
| 304 next_index_ = i + 1; | 323 next_index_ = i + 1; |
| 305 return result; | 324 return result; |
| 306 | 325 |
| 307 default: | 326 default: |
| 308 NOTREACHED(); | 327 NOTREACHED(); |
| 309 } | 328 } |
| 310 } | 329 } |
| 311 next_index_ = 0; | 330 next_index_ = 0; |
| 312 state_ = WILL_SEND_REQUEST; | 331 state_ = WILL_SEND_REQUEST; |
| 313 return NavigationThrottle::PROCEED; | 332 return NavigationThrottle::PROCEED; |
| 314 } | 333 } |
| 315 | 334 |
| 316 NavigationThrottle::ThrottleCheckResult | 335 NavigationThrottle::ThrottleCheckResult |
| 317 NavigationHandleImpl::CheckWillRedirectRequest() { | 336 NavigationHandleImpl::CheckWillRedirectRequest() { |
| 318 DCHECK(state_ == WILL_REDIRECT_REQUEST || state_ == DEFERRING_REDIRECT); | 337 DCHECK(state_ == WILL_REDIRECT_REQUEST || state_ == DEFERRING_REDIRECT); |
| 319 DCHECK(state_ != WILL_REDIRECT_REQUEST || next_index_ == 0); | 338 DCHECK(state_ != WILL_REDIRECT_REQUEST || next_index_ == 0); |
| 320 DCHECK(state_ != DEFERRING_REDIRECT || next_index_ != 0); | 339 DCHECK(state_ != DEFERRING_REDIRECT || next_index_ != 0); |
| 321 for (size_t i = next_index_; i < throttles_.size(); ++i) { | 340 for (size_t i = next_index_; i < throttles_.size(); ++i) { |
| 322 NavigationThrottle::ThrottleCheckResult result = | 341 NavigationThrottle::ThrottleCheckResult result = |
| 323 throttles_[i]->WillRedirectRequest(); | 342 throttles_[i]->WillRedirectRequest(); |
| 324 switch (result) { | 343 switch (result) { |
| 325 case NavigationThrottle::PROCEED: | 344 case NavigationThrottle::PROCEED: |
| 326 continue; | 345 continue; |
| 327 | 346 |
| 347 case NavigationThrottle::CANCEL: |
| 328 case NavigationThrottle::CANCEL_AND_IGNORE: | 348 case NavigationThrottle::CANCEL_AND_IGNORE: |
| 349 state_ = CANCELING; |
| 329 return result; | 350 return result; |
| 330 | 351 |
| 331 case NavigationThrottle::DEFER: | 352 case NavigationThrottle::DEFER: |
| 332 state_ = DEFERRING_REDIRECT; | 353 state_ = DEFERRING_REDIRECT; |
| 333 next_index_ = i + 1; | 354 next_index_ = i + 1; |
| 334 return result; | 355 return result; |
| 335 | 356 |
| 336 default: | 357 default: |
| 337 NOTREACHED(); | 358 NOTREACHED(); |
| 338 } | 359 } |
| 339 } | 360 } |
| 340 next_index_ = 0; | 361 next_index_ = 0; |
| 341 state_ = WILL_REDIRECT_REQUEST; | 362 state_ = WILL_REDIRECT_REQUEST; |
| 342 return NavigationThrottle::PROCEED; | 363 return NavigationThrottle::PROCEED; |
| 343 } | 364 } |
| 344 | 365 |
| 366 void NavigationHandleImpl::RunCompleteCallback( |
| 367 NavigationThrottle::ThrottleCheckResult result) { |
| 368 DCHECK(result != NavigationThrottle::DEFER); |
| 369 if (!complete_callback_.is_null()) |
| 370 complete_callback_.Run(result); |
| 371 |
| 372 complete_callback_.Reset(); |
| 373 } |
| 374 |
| 345 } // namespace content | 375 } // namespace content |
| OLD | NEW |