| 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 CHECK_NE(INITIAL, state_) | 165 CHECK_NE(INITIAL, state_) |
| 165 << "This accessor should not be called before the request is started."; | 166 << "This accessor should not be called before the request is started."; |
| 166 return is_external_protocol_; | 167 return is_external_protocol_; |
| 167 } | 168 } |
| 168 | 169 |
| 169 net::Error NavigationHandleImpl::GetNetErrorCode() { | 170 net::Error NavigationHandleImpl::GetNetErrorCode() { |
| 170 return net_error_code_; | 171 return net_error_code_; |
| 171 } | 172 } |
| 172 | 173 |
| 173 RenderFrameHostImpl* NavigationHandleImpl::GetRenderFrameHost() { | 174 RenderFrameHostImpl* NavigationHandleImpl::GetRenderFrameHost() { |
| 174 CHECK(state_ >= READY_TO_COMMIT) | 175 CHECK_GE(state_, WILL_PROCESS_RESPONSE) |
| 175 << "This accessor should only be called " | 176 << "This accessor should only be called " |
| 176 "after the navigation is ready to commit."; | 177 "after a response has been received."; |
| 177 return render_frame_host_; | 178 return render_frame_host_; |
| 178 } | 179 } |
| 179 | 180 |
| 180 bool NavigationHandleImpl::IsSamePage() { | 181 bool NavigationHandleImpl::IsSamePage() { |
| 181 DCHECK(state_ == DID_COMMIT || state_ == DID_COMMIT_ERROR_PAGE) | 182 DCHECK(state_ == DID_COMMIT || state_ == DID_COMMIT_ERROR_PAGE) |
| 182 << "This accessor should not be called before the navigation has " | 183 << "This accessor should not be called before the navigation has " |
| 183 "committed."; | 184 "committed."; |
| 184 return is_same_page_; | 185 return is_same_page_; |
| 185 } | 186 } |
| 186 | 187 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 // Update the navigation parameters. | 286 // Update the navigation parameters. |
| 286 method_ = method; | 287 method_ = method; |
| 287 sanitized_referrer_ = sanitized_referrer; | 288 sanitized_referrer_ = sanitized_referrer; |
| 288 has_user_gesture_ = has_user_gesture; | 289 has_user_gesture_ = has_user_gesture; |
| 289 transition_ = transition; | 290 transition_ = transition; |
| 290 is_external_protocol_ = is_external_protocol; | 291 is_external_protocol_ = is_external_protocol; |
| 291 | 292 |
| 292 state_ = WILL_SEND_REQUEST; | 293 state_ = WILL_SEND_REQUEST; |
| 293 complete_callback_ = callback; | 294 complete_callback_ = callback; |
| 294 | 295 |
| 295 // Register the navigation throttles. The ScopedVector returned by | 296 // Register the platform's navigation throttles. |
| 296 // GetNavigationThrottles is not assigned to throttles_ directly because it | 297 std::unique_ptr<content::NavigationThrottle> ancestor_throttle = |
| 297 // would overwrite any throttle previously added with | 298 content::AncestorThrottle::MaybeCreateThrottleFor(this); |
| 298 // RegisterThrottleForTesting. | 299 if (ancestor_throttle) |
| 300 throttles_.push_back(std::move(ancestor_throttle)); |
| 301 |
| 302 // Register the embedder's navigation throttles. |
| 299 ScopedVector<NavigationThrottle> throttles_to_register = | 303 ScopedVector<NavigationThrottle> throttles_to_register = |
| 300 GetContentClient()->browser()->CreateThrottlesForNavigation(this); | 304 GetContentClient()->browser()->CreateThrottlesForNavigation(this); |
| 301 if (throttles_to_register.size() > 0) { | 305 if (throttles_to_register.size() > 0) { |
| 302 throttles_.insert(throttles_.end(), throttles_to_register.begin(), | 306 throttles_.insert(throttles_.end(), throttles_to_register.begin(), |
| 303 throttles_to_register.end()); | 307 throttles_to_register.end()); |
| 304 throttles_to_register.weak_clear(); | 308 throttles_to_register.weak_clear(); |
| 305 } | 309 } |
| 306 | 310 |
| 307 // Notify each throttle of the request. | 311 // Notify each throttle of the request. |
| 308 NavigationThrottle::ThrottleCheckResult result = CheckWillStartRequest(); | 312 NavigationThrottle::ThrottleCheckResult result = CheckWillStartRequest(); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 case NavigationThrottle::CANCEL: | 409 case NavigationThrottle::CANCEL: |
| 406 case NavigationThrottle::CANCEL_AND_IGNORE: | 410 case NavigationThrottle::CANCEL_AND_IGNORE: |
| 407 state_ = CANCELING; | 411 state_ = CANCELING; |
| 408 return result; | 412 return result; |
| 409 | 413 |
| 410 case NavigationThrottle::DEFER: | 414 case NavigationThrottle::DEFER: |
| 411 state_ = DEFERRING_START; | 415 state_ = DEFERRING_START; |
| 412 next_index_ = i + 1; | 416 next_index_ = i + 1; |
| 413 return result; | 417 return result; |
| 414 | 418 |
| 415 default: | 419 case NavigationThrottle::BLOCK_RESPONSE: |
| 416 NOTREACHED(); | 420 NOTREACHED(); |
| 417 } | 421 } |
| 418 } | 422 } |
| 419 next_index_ = 0; | 423 next_index_ = 0; |
| 420 state_ = WILL_SEND_REQUEST; | 424 state_ = WILL_SEND_REQUEST; |
| 421 return NavigationThrottle::PROCEED; | 425 return NavigationThrottle::PROCEED; |
| 422 } | 426 } |
| 423 | 427 |
| 424 NavigationThrottle::ThrottleCheckResult | 428 NavigationThrottle::ThrottleCheckResult |
| 425 NavigationHandleImpl::CheckWillRedirectRequest() { | 429 NavigationHandleImpl::CheckWillRedirectRequest() { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 436 case NavigationThrottle::CANCEL: | 440 case NavigationThrottle::CANCEL: |
| 437 case NavigationThrottle::CANCEL_AND_IGNORE: | 441 case NavigationThrottle::CANCEL_AND_IGNORE: |
| 438 state_ = CANCELING; | 442 state_ = CANCELING; |
| 439 return result; | 443 return result; |
| 440 | 444 |
| 441 case NavigationThrottle::DEFER: | 445 case NavigationThrottle::DEFER: |
| 442 state_ = DEFERRING_REDIRECT; | 446 state_ = DEFERRING_REDIRECT; |
| 443 next_index_ = i + 1; | 447 next_index_ = i + 1; |
| 444 return result; | 448 return result; |
| 445 | 449 |
| 446 default: | 450 case NavigationThrottle::BLOCK_RESPONSE: |
| 447 NOTREACHED(); | 451 NOTREACHED(); |
| 448 } | 452 } |
| 449 } | 453 } |
| 450 next_index_ = 0; | 454 next_index_ = 0; |
| 451 state_ = WILL_REDIRECT_REQUEST; | 455 state_ = WILL_REDIRECT_REQUEST; |
| 452 | 456 |
| 453 // Notify the delegate that a redirect was encountered and will be followed. | 457 // Notify the delegate that a redirect was encountered and will be followed. |
| 454 if (GetDelegate()) | 458 if (GetDelegate()) |
| 455 GetDelegate()->DidRedirectNavigation(this); | 459 GetDelegate()->DidRedirectNavigation(this); |
| 456 | 460 |
| 457 return NavigationThrottle::PROCEED; | 461 return NavigationThrottle::PROCEED; |
| 458 } | 462 } |
| 459 | 463 |
| 460 NavigationThrottle::ThrottleCheckResult | 464 NavigationThrottle::ThrottleCheckResult |
| 461 NavigationHandleImpl::CheckWillProcessResponse() { | 465 NavigationHandleImpl::CheckWillProcessResponse() { |
| 462 DCHECK(state_ == WILL_PROCESS_RESPONSE || state_ == DEFERRING_RESPONSE); | 466 DCHECK(state_ == WILL_PROCESS_RESPONSE || state_ == DEFERRING_RESPONSE); |
| 463 DCHECK(state_ != WILL_PROCESS_RESPONSE || next_index_ == 0); | 467 DCHECK(state_ != WILL_PROCESS_RESPONSE || next_index_ == 0); |
| 464 DCHECK(state_ != DEFERRING_RESPONSE || next_index_ != 0); | 468 DCHECK(state_ != DEFERRING_RESPONSE || next_index_ != 0); |
| 465 for (size_t i = next_index_; i < throttles_.size(); ++i) { | 469 for (size_t i = next_index_; i < throttles_.size(); ++i) { |
| 466 NavigationThrottle::ThrottleCheckResult result = | 470 NavigationThrottle::ThrottleCheckResult result = |
| 467 throttles_[i]->WillProcessResponse(); | 471 throttles_[i]->WillProcessResponse(); |
| 468 switch (result) { | 472 switch (result) { |
| 469 case NavigationThrottle::PROCEED: | 473 case NavigationThrottle::PROCEED: |
| 470 continue; | 474 continue; |
| 471 | 475 |
| 476 case NavigationThrottle::BLOCK_RESPONSE: |
| 472 case NavigationThrottle::CANCEL: | 477 case NavigationThrottle::CANCEL: |
| 473 case NavigationThrottle::CANCEL_AND_IGNORE: | 478 case NavigationThrottle::CANCEL_AND_IGNORE: |
| 474 state_ = CANCELING; | 479 state_ = CANCELING; |
| 475 return result; | 480 return result; |
| 476 | 481 |
| 477 case NavigationThrottle::DEFER: | 482 case NavigationThrottle::DEFER: |
| 478 state_ = DEFERRING_RESPONSE; | 483 state_ = DEFERRING_RESPONSE; |
| 479 next_index_ = i + 1; | 484 next_index_ = i + 1; |
| 480 return result; | 485 return result; |
| 481 } | 486 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 493 complete_callback_.Reset(); | 498 complete_callback_.Reset(); |
| 494 | 499 |
| 495 if (!callback.is_null()) | 500 if (!callback.is_null()) |
| 496 callback.Run(result); | 501 callback.Run(result); |
| 497 | 502 |
| 498 // No code after running the callback, as it might have resulted in our | 503 // No code after running the callback, as it might have resulted in our |
| 499 // destruction. | 504 // destruction. |
| 500 } | 505 } |
| 501 | 506 |
| 502 } // namespace content | 507 } // namespace content |
| OLD | NEW |