Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Side by Side Diff: content/browser/frame_host/navigation_handle_impl.cc

Issue 2321503002: (Re-)introduce AncestorThrottle to handle 'X-Frame-Options'. (Closed)
Patch Set: Ugh. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/logging.h" 9 #include "base/logging.h"
10 #include "content/browser/browsing_data/clear_site_data_throttle.h" 10 #include "content/browser/browsing_data/clear_site_data_throttle.h"
11 #include "content/browser/devtools/render_frame_devtools_agent_host.h" 11 #include "content/browser/devtools/render_frame_devtools_agent_host.h"
12 #include "content/browser/frame_host/ancestor_throttle.h"
12 #include "content/browser/frame_host/frame_tree_node.h" 13 #include "content/browser/frame_host/frame_tree_node.h"
13 #include "content/browser/frame_host/navigator.h" 14 #include "content/browser/frame_host/navigator.h"
14 #include "content/browser/frame_host/navigator_delegate.h" 15 #include "content/browser/frame_host/navigator_delegate.h"
15 #include "content/browser/service_worker/service_worker_context_wrapper.h" 16 #include "content/browser/service_worker/service_worker_context_wrapper.h"
16 #include "content/common/frame_messages.h" 17 #include "content/common/frame_messages.h"
17 #include "content/common/resource_request_body_impl.h" 18 #include "content/common/resource_request_body_impl.h"
18 #include "content/public/browser/content_browser_client.h" 19 #include "content/public/browser/content_browser_client.h"
19 #include "content/public/common/browser_side_navigation_policy.h" 20 #include "content/public/common/browser_side_navigation_policy.h"
20 #include "content/public/common/content_client.h" 21 #include "content/public/common/content_client.h"
21 #include "net/url_request/redirect_info.h" 22 #include "net/url_request/redirect_info.h"
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 242
242 if (result != NavigationThrottle::DEFER) 243 if (result != NavigationThrottle::DEFER)
243 RunCompleteCallback(result); 244 RunCompleteCallback(result);
244 } 245 }
245 246
246 void NavigationHandleImpl::CancelDeferredNavigation( 247 void NavigationHandleImpl::CancelDeferredNavigation(
247 NavigationThrottle::ThrottleCheckResult result) { 248 NavigationThrottle::ThrottleCheckResult result) {
248 DCHECK(state_ == DEFERRING_START || state_ == DEFERRING_REDIRECT); 249 DCHECK(state_ == DEFERRING_START || state_ == DEFERRING_REDIRECT);
249 DCHECK(result == NavigationThrottle::CANCEL_AND_IGNORE || 250 DCHECK(result == NavigationThrottle::CANCEL_AND_IGNORE ||
250 result == NavigationThrottle::CANCEL); 251 result == NavigationThrottle::CANCEL);
251 state_ = CANCELING; 252 state_ = CANCELING_REQUEST;
252 RunCompleteCallback(result); 253 RunCompleteCallback(result);
253 } 254 }
254 255
255 void NavigationHandleImpl::RegisterThrottleForTesting( 256 void NavigationHandleImpl::RegisterThrottleForTesting(
256 std::unique_ptr<NavigationThrottle> navigation_throttle) { 257 std::unique_ptr<NavigationThrottle> navigation_throttle) {
257 throttles_.push_back(std::move(navigation_throttle)); 258 throttles_.push_back(std::move(navigation_throttle));
258 } 259 }
259 260
260 NavigationThrottle::ThrottleCheckResult 261 NavigationThrottle::ThrottleCheckResult
261 NavigationHandleImpl::CallWillStartRequestForTesting( 262 NavigationHandleImpl::CallWillStartRequestForTesting(
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 DCHECK(state_ != DEFERRING_START || next_index_ != 0); 447 DCHECK(state_ != DEFERRING_START || next_index_ != 0);
447 for (size_t i = next_index_; i < throttles_.size(); ++i) { 448 for (size_t i = next_index_; i < throttles_.size(); ++i) {
448 NavigationThrottle::ThrottleCheckResult result = 449 NavigationThrottle::ThrottleCheckResult result =
449 throttles_[i]->WillStartRequest(); 450 throttles_[i]->WillStartRequest();
450 switch (result) { 451 switch (result) {
451 case NavigationThrottle::PROCEED: 452 case NavigationThrottle::PROCEED:
452 continue; 453 continue;
453 454
454 case NavigationThrottle::CANCEL: 455 case NavigationThrottle::CANCEL:
455 case NavigationThrottle::CANCEL_AND_IGNORE: 456 case NavigationThrottle::CANCEL_AND_IGNORE:
457 state_ = CANCELING_REQUEST;
458 return result;
459
456 case NavigationThrottle::BLOCK_REQUEST: 460 case NavigationThrottle::BLOCK_REQUEST:
457 state_ = CANCELING; 461 state_ = CANCELING_RESPONSE;
458 return result; 462 return result;
459 463
460 case NavigationThrottle::DEFER: 464 case NavigationThrottle::DEFER:
461 state_ = DEFERRING_START; 465 state_ = DEFERRING_START;
462 next_index_ = i + 1; 466 next_index_ = i + 1;
463 return result; 467 return result;
468
469 case NavigationThrottle::BLOCK_RESPONSE:
470 NOTREACHED();
464 } 471 }
465 } 472 }
466 next_index_ = 0; 473 next_index_ = 0;
467 state_ = WILL_SEND_REQUEST; 474 state_ = WILL_SEND_REQUEST;
468 return NavigationThrottle::PROCEED; 475 return NavigationThrottle::PROCEED;
469 } 476 }
470 477
471 NavigationThrottle::ThrottleCheckResult 478 NavigationThrottle::ThrottleCheckResult
472 NavigationHandleImpl::CheckWillRedirectRequest() { 479 NavigationHandleImpl::CheckWillRedirectRequest() {
473 DCHECK(state_ == WILL_REDIRECT_REQUEST || state_ == DEFERRING_REDIRECT); 480 DCHECK(state_ == WILL_REDIRECT_REQUEST || state_ == DEFERRING_REDIRECT);
474 DCHECK(state_ != WILL_REDIRECT_REQUEST || next_index_ == 0); 481 DCHECK(state_ != WILL_REDIRECT_REQUEST || next_index_ == 0);
475 DCHECK(state_ != DEFERRING_REDIRECT || next_index_ != 0); 482 DCHECK(state_ != DEFERRING_REDIRECT || next_index_ != 0);
476 for (size_t i = next_index_; i < throttles_.size(); ++i) { 483 for (size_t i = next_index_; i < throttles_.size(); ++i) {
477 NavigationThrottle::ThrottleCheckResult result = 484 NavigationThrottle::ThrottleCheckResult result =
478 throttles_[i]->WillRedirectRequest(); 485 throttles_[i]->WillRedirectRequest();
479 switch (result) { 486 switch (result) {
480 case NavigationThrottle::PROCEED: 487 case NavigationThrottle::PROCEED:
481 continue; 488 continue;
482 489
483 case NavigationThrottle::CANCEL: 490 case NavigationThrottle::CANCEL:
484 case NavigationThrottle::CANCEL_AND_IGNORE: 491 case NavigationThrottle::CANCEL_AND_IGNORE:
485 state_ = CANCELING; 492 state_ = CANCELING_REQUEST;
486 return result; 493 return result;
487 494
488 case NavigationThrottle::DEFER: 495 case NavigationThrottle::DEFER:
489 state_ = DEFERRING_REDIRECT; 496 state_ = DEFERRING_REDIRECT;
490 next_index_ = i + 1; 497 next_index_ = i + 1;
491 return result; 498 return result;
492 499
493 case NavigationThrottle::BLOCK_REQUEST: 500 case NavigationThrottle::BLOCK_REQUEST:
501 case NavigationThrottle::BLOCK_RESPONSE:
494 NOTREACHED(); 502 NOTREACHED();
495 } 503 }
496 } 504 }
497 next_index_ = 0; 505 next_index_ = 0;
498 state_ = WILL_REDIRECT_REQUEST; 506 state_ = WILL_REDIRECT_REQUEST;
499 507
500 // Notify the delegate that a redirect was encountered and will be followed. 508 // Notify the delegate that a redirect was encountered and will be followed.
501 if (GetDelegate()) 509 if (GetDelegate())
502 GetDelegate()->DidRedirectNavigation(this); 510 GetDelegate()->DidRedirectNavigation(this);
503 511
504 return NavigationThrottle::PROCEED; 512 return NavigationThrottle::PROCEED;
505 } 513 }
506 514
507 NavigationThrottle::ThrottleCheckResult 515 NavigationThrottle::ThrottleCheckResult
508 NavigationHandleImpl::CheckWillProcessResponse() { 516 NavigationHandleImpl::CheckWillProcessResponse() {
509 DCHECK(state_ == WILL_PROCESS_RESPONSE || state_ == DEFERRING_RESPONSE); 517 DCHECK(state_ == WILL_PROCESS_RESPONSE || state_ == DEFERRING_RESPONSE);
510 DCHECK(state_ != WILL_PROCESS_RESPONSE || next_index_ == 0); 518 DCHECK(state_ != WILL_PROCESS_RESPONSE || next_index_ == 0);
511 DCHECK(state_ != DEFERRING_RESPONSE || next_index_ != 0); 519 DCHECK(state_ != DEFERRING_RESPONSE || next_index_ != 0);
512 for (size_t i = next_index_; i < throttles_.size(); ++i) { 520 for (size_t i = next_index_; i < throttles_.size(); ++i) {
513 NavigationThrottle::ThrottleCheckResult result = 521 NavigationThrottle::ThrottleCheckResult result =
514 throttles_[i]->WillProcessResponse(); 522 throttles_[i]->WillProcessResponse();
515 switch (result) { 523 switch (result) {
516 case NavigationThrottle::PROCEED: 524 case NavigationThrottle::PROCEED:
517 continue; 525 continue;
518 526
519 case NavigationThrottle::CANCEL: 527 case NavigationThrottle::CANCEL:
520 case NavigationThrottle::CANCEL_AND_IGNORE: 528 case NavigationThrottle::CANCEL_AND_IGNORE:
521 state_ = CANCELING; 529 state_ = CANCELING_REQUEST;
530 return result;
531
532 case NavigationThrottle::BLOCK_RESPONSE:
533 state_ = CANCELING_RESPONSE;
522 return result; 534 return result;
523 535
524 case NavigationThrottle::DEFER: 536 case NavigationThrottle::DEFER:
525 state_ = DEFERRING_RESPONSE; 537 state_ = DEFERRING_RESPONSE;
526 next_index_ = i + 1; 538 next_index_ = i + 1;
527 return result; 539 return result;
528 540
529 case NavigationThrottle::BLOCK_REQUEST: 541 case NavigationThrottle::BLOCK_REQUEST:
530 NOTREACHED(); 542 NOTREACHED();
531 } 543 }
(...skipping 15 matching lines...) Expand all
547 559
548 // No code after running the callback, as it might have resulted in our 560 // No code after running the callback, as it might have resulted in our
549 // destruction. 561 // destruction.
550 } 562 }
551 563
552 void NavigationHandleImpl::RegisterNavigationThrottles() { 564 void NavigationHandleImpl::RegisterNavigationThrottles() {
553 // Register the navigation throttles. The ScopedVector returned by 565 // Register the navigation throttles. The ScopedVector returned by
554 // GetNavigationThrottles is not assigned to throttles_ directly because it 566 // GetNavigationThrottles is not assigned to throttles_ directly because it
555 // would overwrite any throttle previously added with 567 // would overwrite any throttle previously added with
556 // RegisterThrottleForTesting. 568 // RegisterThrottleForTesting.
569
557 ScopedVector<NavigationThrottle> throttles_to_register = 570 ScopedVector<NavigationThrottle> throttles_to_register =
558 GetContentClient()->browser()->CreateThrottlesForNavigation(this); 571 GetContentClient()->browser()->CreateThrottlesForNavigation(this);
572
559 std::unique_ptr<NavigationThrottle> devtools_throttle = 573 std::unique_ptr<NavigationThrottle> devtools_throttle =
560 RenderFrameDevToolsAgentHost::CreateThrottleForNavigation(this); 574 RenderFrameDevToolsAgentHost::CreateThrottleForNavigation(this);
561 if (devtools_throttle) 575 if (devtools_throttle)
562 throttles_to_register.push_back(std::move(devtools_throttle)); 576 throttles_to_register.push_back(std::move(devtools_throttle));
563 577
564 std::unique_ptr<NavigationThrottle> clear_site_data_throttle = 578 std::unique_ptr<NavigationThrottle> clear_site_data_throttle =
565 ClearSiteDataThrottle::CreateThrottleForNavigation(this); 579 ClearSiteDataThrottle::CreateThrottleForNavigation(this);
566 if (clear_site_data_throttle) 580 if (clear_site_data_throttle)
567 throttles_to_register.push_back(std::move(clear_site_data_throttle)); 581 throttles_to_register.push_back(std::move(clear_site_data_throttle));
568 582
583 std::unique_ptr<content::NavigationThrottle> ancestor_throttle =
584 content::AncestorThrottle::MaybeCreateThrottleFor(this);
585 if (ancestor_throttle)
586 throttles_.push_back(std::move(ancestor_throttle));
587
569 if (throttles_to_register.size() > 0) { 588 if (throttles_to_register.size() > 0) {
570 throttles_.insert(throttles_.begin(), throttles_to_register.begin(), 589 throttles_.insert(throttles_.begin(), throttles_to_register.begin(),
571 throttles_to_register.end()); 590 throttles_to_register.end());
572 throttles_to_register.weak_clear(); 591 throttles_to_register.weak_clear();
573 } 592 }
574 } 593 }
575 594
576 } // namespace content 595 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698