| 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 "content/browser/frame_host/ancestor_throttle.h" |
| 9 #include "content/browser/frame_host/frame_tree_node.h" | 10 #include "content/browser/frame_host/frame_tree_node.h" |
| 10 #include "content/browser/frame_host/navigator.h" | 11 #include "content/browser/frame_host/navigator.h" |
| 11 #include "content/browser/frame_host/navigator_delegate.h" | 12 #include "content/browser/frame_host/navigator_delegate.h" |
| 12 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 13 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 13 #include "content/browser/service_worker/service_worker_navigation_handle.h" | 14 #include "content/browser/service_worker/service_worker_navigation_handle.h" |
| 14 #include "content/common/frame_messages.h" | 15 #include "content/common/frame_messages.h" |
| 15 #include "content/public/browser/content_browser_client.h" | 16 #include "content/public/browser/content_browser_client.h" |
| 16 #include "content/public/common/browser_side_navigation_policy.h" | 17 #include "content/public/common/browser_side_navigation_policy.h" |
| 17 #include "content/public/common/content_client.h" | 18 #include "content/public/common/content_client.h" |
| 18 #include "net/url_request/redirect_info.h" | 19 #include "net/url_request/redirect_info.h" |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 CHECK_NE(INITIAL, state_) | 153 CHECK_NE(INITIAL, state_) |
| 153 << "This accessor should not be called before the request is started."; | 154 << "This accessor should not be called before the request is started."; |
| 154 return is_external_protocol_; | 155 return is_external_protocol_; |
| 155 } | 156 } |
| 156 | 157 |
| 157 net::Error NavigationHandleImpl::GetNetErrorCode() { | 158 net::Error NavigationHandleImpl::GetNetErrorCode() { |
| 158 return net_error_code_; | 159 return net_error_code_; |
| 159 } | 160 } |
| 160 | 161 |
| 161 RenderFrameHostImpl* NavigationHandleImpl::GetRenderFrameHost() { | 162 RenderFrameHostImpl* NavigationHandleImpl::GetRenderFrameHost() { |
| 162 CHECK(state_ >= READY_TO_COMMIT) | 163 CHECK(state_ >= WILL_PROCESS_RESPONSE) |
| 163 << "This accessor should only be called " | 164 << "This accessor should only be called " |
| 164 "after the navigation is ready to commit."; | 165 "after a response has been received."; |
| 165 return render_frame_host_; | 166 return render_frame_host_; |
| 166 } | 167 } |
| 167 | 168 |
| 168 bool NavigationHandleImpl::IsSamePage() { | 169 bool NavigationHandleImpl::IsSamePage() { |
| 169 DCHECK(state_ == DID_COMMIT || state_ == DID_COMMIT_ERROR_PAGE) | 170 DCHECK(state_ == DID_COMMIT || state_ == DID_COMMIT_ERROR_PAGE) |
| 170 << "This accessor should not be called before the navigation has " | 171 << "This accessor should not be called before the navigation has " |
| 171 "committed."; | 172 "committed."; |
| 172 return is_same_page_; | 173 return is_same_page_; |
| 173 } | 174 } |
| 174 | 175 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 // Update the navigation parameters. | 274 // Update the navigation parameters. |
| 274 method_ = method; | 275 method_ = method; |
| 275 sanitized_referrer_ = sanitized_referrer; | 276 sanitized_referrer_ = sanitized_referrer; |
| 276 has_user_gesture_ = has_user_gesture; | 277 has_user_gesture_ = has_user_gesture; |
| 277 transition_ = transition; | 278 transition_ = transition; |
| 278 is_external_protocol_ = is_external_protocol; | 279 is_external_protocol_ = is_external_protocol; |
| 279 | 280 |
| 280 state_ = WILL_SEND_REQUEST; | 281 state_ = WILL_SEND_REQUEST; |
| 281 complete_callback_ = callback; | 282 complete_callback_ = callback; |
| 282 | 283 |
| 283 // Register the navigation throttles. The ScopedVector returned by | 284 // Register the platform's navigation throttles. |
| 284 // GetNavigationThrottles is not assigned to throttles_ directly because it | 285 std::unique_ptr<content::NavigationThrottle> ancestor_throttle = |
| 285 // would overwrite any throttle previously added with | 286 AncestorThrottle::MaybeCreateThrottleFor(this); |
| 286 // RegisterThrottleForTesting. | 287 if (ancestor_throttle) |
| 288 throttles_.push_back(std::move(ancestor_throttle)); |
| 289 |
| 290 // Register the embedder's navigation throttles. |
| 287 ScopedVector<NavigationThrottle> throttles_to_register = | 291 ScopedVector<NavigationThrottle> throttles_to_register = |
| 288 GetContentClient()->browser()->CreateThrottlesForNavigation(this); | 292 GetContentClient()->browser()->CreateThrottlesForNavigation(this); |
| 289 if (throttles_to_register.size() > 0) { | 293 if (throttles_to_register.size() > 0) { |
| 290 throttles_.insert(throttles_.end(), throttles_to_register.begin(), | 294 throttles_.insert(throttles_.end(), throttles_to_register.begin(), |
| 291 throttles_to_register.end()); | 295 throttles_to_register.end()); |
| 292 throttles_to_register.weak_clear(); | 296 throttles_to_register.weak_clear(); |
| 293 } | 297 } |
| 294 | 298 |
| 295 // Notify each throttle of the request. | 299 // Notify each throttle of the request. |
| 296 NavigationThrottle::ThrottleCheckResult result = CheckWillStartRequest(); | 300 NavigationThrottle::ThrottleCheckResult result = CheckWillStartRequest(); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 case NavigationThrottle::CANCEL: | 397 case NavigationThrottle::CANCEL: |
| 394 case NavigationThrottle::CANCEL_AND_IGNORE: | 398 case NavigationThrottle::CANCEL_AND_IGNORE: |
| 395 state_ = CANCELING; | 399 state_ = CANCELING; |
| 396 return result; | 400 return result; |
| 397 | 401 |
| 398 case NavigationThrottle::DEFER: | 402 case NavigationThrottle::DEFER: |
| 399 state_ = DEFERRING_START; | 403 state_ = DEFERRING_START; |
| 400 next_index_ = i + 1; | 404 next_index_ = i + 1; |
| 401 return result; | 405 return result; |
| 402 | 406 |
| 403 default: | 407 case NavigationThrottle::BLOCK_RESPONSE: |
| 404 NOTREACHED(); | 408 NOTREACHED(); |
| 405 } | 409 } |
| 406 } | 410 } |
| 407 next_index_ = 0; | 411 next_index_ = 0; |
| 408 state_ = WILL_SEND_REQUEST; | 412 state_ = WILL_SEND_REQUEST; |
| 409 return NavigationThrottle::PROCEED; | 413 return NavigationThrottle::PROCEED; |
| 410 } | 414 } |
| 411 | 415 |
| 412 NavigationThrottle::ThrottleCheckResult | 416 NavigationThrottle::ThrottleCheckResult |
| 413 NavigationHandleImpl::CheckWillRedirectRequest() { | 417 NavigationHandleImpl::CheckWillRedirectRequest() { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 424 case NavigationThrottle::CANCEL: | 428 case NavigationThrottle::CANCEL: |
| 425 case NavigationThrottle::CANCEL_AND_IGNORE: | 429 case NavigationThrottle::CANCEL_AND_IGNORE: |
| 426 state_ = CANCELING; | 430 state_ = CANCELING; |
| 427 return result; | 431 return result; |
| 428 | 432 |
| 429 case NavigationThrottle::DEFER: | 433 case NavigationThrottle::DEFER: |
| 430 state_ = DEFERRING_REDIRECT; | 434 state_ = DEFERRING_REDIRECT; |
| 431 next_index_ = i + 1; | 435 next_index_ = i + 1; |
| 432 return result; | 436 return result; |
| 433 | 437 |
| 434 default: | 438 case NavigationThrottle::BLOCK_RESPONSE: |
| 435 NOTREACHED(); | 439 NOTREACHED(); |
| 436 } | 440 } |
| 437 } | 441 } |
| 438 next_index_ = 0; | 442 next_index_ = 0; |
| 439 state_ = WILL_REDIRECT_REQUEST; | 443 state_ = WILL_REDIRECT_REQUEST; |
| 440 | 444 |
| 441 // Notify the delegate that a redirect was encountered and will be followed. | 445 // Notify the delegate that a redirect was encountered and will be followed. |
| 442 if (GetDelegate()) | 446 if (GetDelegate()) |
| 443 GetDelegate()->DidRedirectNavigation(this); | 447 GetDelegate()->DidRedirectNavigation(this); |
| 444 | 448 |
| 445 return NavigationThrottle::PROCEED; | 449 return NavigationThrottle::PROCEED; |
| 446 } | 450 } |
| 447 | 451 |
| 448 NavigationThrottle::ThrottleCheckResult | 452 NavigationThrottle::ThrottleCheckResult |
| 449 NavigationHandleImpl::CheckWillProcessResponse() { | 453 NavigationHandleImpl::CheckWillProcessResponse() { |
| 450 DCHECK(state_ == WILL_PROCESS_RESPONSE || state_ == DEFERRING_RESPONSE); | 454 DCHECK(state_ == WILL_PROCESS_RESPONSE || state_ == DEFERRING_RESPONSE); |
| 451 DCHECK(state_ != WILL_PROCESS_RESPONSE || next_index_ == 0); | 455 DCHECK(state_ != WILL_PROCESS_RESPONSE || next_index_ == 0); |
| 452 DCHECK(state_ != DEFERRING_RESPONSE || next_index_ != 0); | 456 DCHECK(state_ != DEFERRING_RESPONSE || next_index_ != 0); |
| 453 for (size_t i = next_index_; i < throttles_.size(); ++i) { | 457 for (size_t i = next_index_; i < throttles_.size(); ++i) { |
| 454 NavigationThrottle::ThrottleCheckResult result = | 458 NavigationThrottle::ThrottleCheckResult result = |
| 455 throttles_[i]->WillProcessResponse(); | 459 throttles_[i]->WillProcessResponse(); |
| 456 switch (result) { | 460 switch (result) { |
| 457 case NavigationThrottle::PROCEED: | 461 case NavigationThrottle::PROCEED: |
| 458 continue; | 462 continue; |
| 459 | 463 |
| 464 case NavigationThrottle::BLOCK_RESPONSE: |
| 460 case NavigationThrottle::CANCEL: | 465 case NavigationThrottle::CANCEL: |
| 461 case NavigationThrottle::CANCEL_AND_IGNORE: | 466 case NavigationThrottle::CANCEL_AND_IGNORE: |
| 462 state_ = CANCELING; | 467 state_ = CANCELING; |
| 463 return result; | 468 return result; |
| 464 | 469 |
| 465 case NavigationThrottle::DEFER: | 470 case NavigationThrottle::DEFER: |
| 466 state_ = DEFERRING_RESPONSE; | 471 state_ = DEFERRING_RESPONSE; |
| 467 next_index_ = i + 1; | 472 next_index_ = i + 1; |
| 468 return result; | 473 return result; |
| 469 } | 474 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 481 complete_callback_.Reset(); | 486 complete_callback_.Reset(); |
| 482 | 487 |
| 483 if (!callback.is_null()) | 488 if (!callback.is_null()) |
| 484 callback.Run(result); | 489 callback.Run(result); |
| 485 | 490 |
| 486 // No code after running the callback, as it might have resulted in our | 491 // No code after running the callback, as it might have resulted in our |
| 487 // destruction. | 492 // destruction. |
| 488 } | 493 } |
| 489 | 494 |
| 490 } // namespace content | 495 } // namespace content |
| OLD | NEW |