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