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