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

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

Issue 2696493003: Introduce SubframeNavigationFilteringThrottle (Closed)
Patch Set: fix use after stack return, make code nicer Created 3 years, 10 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 <iterator> 7 #include <iterator>
8 8
9 #include "base/debug/dump_without_crashing.h" 9 #include "base/debug/dump_without_crashing.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 24 matching lines...) Expand all
35 #include "net/base/net_errors.h" 35 #include "net/base/net_errors.h"
36 #include "net/url_request/redirect_info.h" 36 #include "net/url_request/redirect_info.h"
37 #include "third_party/WebKit/public/platform/WebMixedContentContextType.h" 37 #include "third_party/WebKit/public/platform/WebMixedContentContextType.h"
38 #include "url/gurl.h" 38 #include "url/gurl.h"
39 #include "url/url_constants.h" 39 #include "url/url_constants.h"
40 40
41 namespace content { 41 namespace content {
42 42
43 namespace { 43 namespace {
44 44
45 void UpdateThrottleCheckResult(
46 NavigationThrottle::ThrottleCheckResult* to_update,
47 NavigationThrottle::ThrottleCheckResult result) {
48 *to_update = result;
49 }
50
51 void NotifyAbandonedTransferNavigation(const GlobalRequestID& id) { 45 void NotifyAbandonedTransferNavigation(const GlobalRequestID& id) {
52 DCHECK_CURRENTLY_ON(BrowserThread::IO); 46 DCHECK_CURRENTLY_ON(BrowserThread::IO);
53 if (ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get()) 47 if (ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get())
54 rdh->CancelRequest(id.child_id, id.request_id); 48 rdh->CancelRequest(id.child_id, id.request_id);
55 } 49 }
56 50
57 } // namespace 51 } // namespace
58 52
59 // static 53 // static
60 std::unique_ptr<NavigationHandleImpl> NavigationHandleImpl::Create( 54 std::unique_ptr<NavigationHandleImpl> NavigationHandleImpl::Create(
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 std::unique_ptr<NavigationThrottle> navigation_throttle) { 341 std::unique_ptr<NavigationThrottle> navigation_throttle) {
348 throttles_.push_back(std::move(navigation_throttle)); 342 throttles_.push_back(std::move(navigation_throttle));
349 } 343 }
350 344
351 NavigationThrottle::ThrottleCheckResult 345 NavigationThrottle::ThrottleCheckResult
352 NavigationHandleImpl::CallWillStartRequestForTesting( 346 NavigationHandleImpl::CallWillStartRequestForTesting(
353 bool is_post, 347 bool is_post,
354 const Referrer& sanitized_referrer, 348 const Referrer& sanitized_referrer,
355 bool has_user_gesture, 349 bool has_user_gesture,
356 ui::PageTransition transition, 350 ui::PageTransition transition,
357 bool is_external_protocol) { 351 bool is_external_protocol,
358 NavigationThrottle::ThrottleCheckResult result = NavigationThrottle::DEFER; 352 const ThrottleChecksFinishedCallback& complete_callback) {
359
360 scoped_refptr<ResourceRequestBodyImpl> resource_request_body; 353 scoped_refptr<ResourceRequestBodyImpl> resource_request_body;
361 std::string method = "GET"; 354 std::string method = "GET";
362 if (is_post) { 355 if (is_post) {
363 method = "POST"; 356 method = "POST";
364 357
365 std::string body = "test=body"; 358 std::string body = "test=body";
366 resource_request_body = new ResourceRequestBodyImpl(); 359 resource_request_body = new ResourceRequestBodyImpl();
367 resource_request_body->AppendBytes(body.data(), body.size()); 360 resource_request_body->AppendBytes(body.data(), body.size());
368 } 361 }
369 362 return WillStartRequest(
370 WillStartRequest(method, resource_request_body, sanitized_referrer, 363 method, resource_request_body, sanitized_referrer, has_user_gesture,
371 has_user_gesture, transition, is_external_protocol, 364 transition, is_external_protocol, REQUEST_CONTEXT_TYPE_LOCATION,
372 REQUEST_CONTEXT_TYPE_LOCATION, 365 blink::WebMixedContentContextType::Blockable, complete_callback);
373 blink::WebMixedContentContextType::Blockable,
374 base::Bind(&UpdateThrottleCheckResult, &result));
375
376 // Reset the callback to ensure it will not be called later.
377 complete_callback_.Reset();
378 return result;
379 } 366 }
380 367
381 NavigationThrottle::ThrottleCheckResult 368 NavigationThrottle::ThrottleCheckResult
382 NavigationHandleImpl::CallWillRedirectRequestForTesting( 369 NavigationHandleImpl::CallWillRedirectRequestForTesting(
383 const GURL& new_url, 370 const GURL& new_url,
384 bool new_method_is_post, 371 bool new_method_is_post,
385 const GURL& new_referrer_url, 372 const GURL& new_referrer_url,
386 bool new_is_external_protocol) { 373 bool new_is_external_protocol,
387 NavigationThrottle::ThrottleCheckResult result = NavigationThrottle::DEFER; 374 const ThrottleChecksFinishedCallback& complete_callback) {
388 WillRedirectRequest(new_url, new_method_is_post ? "POST" : "GET", 375 return WillRedirectRequest(
389 new_referrer_url, new_is_external_protocol, 376 new_url, new_method_is_post ? "POST" : "GET", new_referrer_url,
390 scoped_refptr<net::HttpResponseHeaders>(), 377 new_is_external_protocol, scoped_refptr<net::HttpResponseHeaders>(),
391 net::HttpResponseInfo::CONNECTION_INFO_UNKNOWN, 378 net::HttpResponseInfo::CONNECTION_INFO_UNKNOWN, complete_callback);
392 base::Bind(&UpdateThrottleCheckResult, &result));
393
394 // Reset the callback to ensure it will not be called later.
395 complete_callback_.Reset();
396 return result;
397 } 379 }
398 380
399 NavigationThrottle::ThrottleCheckResult 381 NavigationThrottle::ThrottleCheckResult
400 NavigationHandleImpl::CallWillProcessResponseForTesting( 382 NavigationHandleImpl::CallWillProcessResponseForTesting(
401 content::RenderFrameHost* render_frame_host, 383 content::RenderFrameHost* render_frame_host,
402 const std::string& raw_response_headers) { 384 const std::string& raw_response_headers,
385 const ThrottleChecksFinishedCallback& complete_callback) {
403 scoped_refptr<net::HttpResponseHeaders> headers = 386 scoped_refptr<net::HttpResponseHeaders> headers =
404 new net::HttpResponseHeaders(raw_response_headers); 387 new net::HttpResponseHeaders(raw_response_headers);
405 NavigationThrottle::ThrottleCheckResult result = NavigationThrottle::DEFER; 388 return WillProcessResponse(
406 WillProcessResponse(static_cast<RenderFrameHostImpl*>(render_frame_host), 389 static_cast<RenderFrameHostImpl*>(render_frame_host), headers,
407 headers, net::HttpResponseInfo::CONNECTION_INFO_UNKNOWN, 390 net::HttpResponseInfo::CONNECTION_INFO_UNKNOWN, SSLStatus(),
408 SSLStatus(), GlobalRequestID(), false, false, false, 391 GlobalRequestID(), false, false, false, base::Closure(),
409 base::Closure(), 392 complete_callback);
410 base::Bind(&UpdateThrottleCheckResult, &result));
411
412 // Reset the callback to ensure it will not be called later.
413 complete_callback_.Reset();
414 return result;
415 } 393 }
416 394
417 void NavigationHandleImpl::CallDidCommitNavigationForTesting(const GURL& url) { 395 void NavigationHandleImpl::CallDidCommitNavigationForTesting(const GURL& url) {
418 FrameHostMsg_DidCommitProvisionalLoad_Params params; 396 FrameHostMsg_DidCommitProvisionalLoad_Params params;
419 397
420 params.nav_entry_id = 1; 398 params.nav_entry_id = 1;
421 params.url = url; 399 params.url = url;
422 params.referrer = content::Referrer(); 400 params.referrer = content::Referrer();
423 params.transition = ui::PAGE_TRANSITION_TYPED; 401 params.transition = ui::PAGE_TRANSITION_TYPED;
424 params.redirects = std::vector<GURL>(); 402 params.redirects = std::vector<GURL>();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 service_worker_handle_.reset( 446 service_worker_handle_.reset(
469 new ServiceWorkerNavigationHandle(service_worker_context)); 447 new ServiceWorkerNavigationHandle(service_worker_context));
470 } 448 }
471 449
472 void NavigationHandleImpl::InitAppCacheHandle( 450 void NavigationHandleImpl::InitAppCacheHandle(
473 ChromeAppCacheService* appcache_service) { 451 ChromeAppCacheService* appcache_service) {
474 DCHECK(IsBrowserSideNavigationEnabled()); 452 DCHECK(IsBrowserSideNavigationEnabled());
475 appcache_handle_.reset(new AppCacheNavigationHandle(appcache_service)); 453 appcache_handle_.reset(new AppCacheNavigationHandle(appcache_service));
476 } 454 }
477 455
478 void NavigationHandleImpl::WillStartRequest( 456 NavigationThrottle::ThrottleCheckResult NavigationHandleImpl::WillStartRequest(
479 const std::string& method, 457 const std::string& method,
480 scoped_refptr<content::ResourceRequestBodyImpl> resource_request_body, 458 scoped_refptr<content::ResourceRequestBodyImpl> resource_request_body,
481 const Referrer& sanitized_referrer, 459 const Referrer& sanitized_referrer,
482 bool has_user_gesture, 460 bool has_user_gesture,
483 ui::PageTransition transition, 461 ui::PageTransition transition,
484 bool is_external_protocol, 462 bool is_external_protocol,
485 RequestContextType request_context_type, 463 RequestContextType request_context_type,
486 blink::WebMixedContentContextType mixed_content_context_type, 464 blink::WebMixedContentContextType mixed_content_context_type,
487 const ThrottleChecksFinishedCallback& callback) { 465 const ThrottleChecksFinishedCallback& callback) {
488 if (method != "POST") 466 if (method != "POST")
(...skipping 24 matching lines...) Expand all
513 491
514 if (IsBrowserSideNavigationEnabled()) 492 if (IsBrowserSideNavigationEnabled())
515 navigation_ui_data_ = GetDelegate()->GetNavigationUIData(this); 493 navigation_ui_data_ = GetDelegate()->GetNavigationUIData(this);
516 494
517 // Notify each throttle of the request. 495 // Notify each throttle of the request.
518 NavigationThrottle::ThrottleCheckResult result = CheckWillStartRequest(); 496 NavigationThrottle::ThrottleCheckResult result = CheckWillStartRequest();
519 497
520 // If the navigation is not deferred, run the callback. 498 // If the navigation is not deferred, run the callback.
521 if (result != NavigationThrottle::DEFER) 499 if (result != NavigationThrottle::DEFER)
522 RunCompleteCallback(result); 500 RunCompleteCallback(result);
501 return result;
523 } 502 }
524 503
525 void NavigationHandleImpl::WillRedirectRequest( 504 NavigationThrottle::ThrottleCheckResult
505 NavigationHandleImpl::WillRedirectRequest(
526 const GURL& new_url, 506 const GURL& new_url,
527 const std::string& new_method, 507 const std::string& new_method,
528 const GURL& new_referrer_url, 508 const GURL& new_referrer_url,
529 bool new_is_external_protocol, 509 bool new_is_external_protocol,
530 scoped_refptr<net::HttpResponseHeaders> response_headers, 510 scoped_refptr<net::HttpResponseHeaders> response_headers,
531 net::HttpResponseInfo::ConnectionInfo connection_info, 511 net::HttpResponseInfo::ConnectionInfo connection_info,
532 const ThrottleChecksFinishedCallback& callback) { 512 const ThrottleChecksFinishedCallback& callback) {
533 // Update the navigation parameters. 513 // Update the navigation parameters.
534 url_ = new_url; 514 url_ = new_url;
535 method_ = new_method; 515 method_ = new_method;
(...skipping 14 matching lines...) Expand all
550 530
551 state_ = WILL_REDIRECT_REQUEST; 531 state_ = WILL_REDIRECT_REQUEST;
552 complete_callback_ = callback; 532 complete_callback_ = callback;
553 533
554 // Notify each throttle of the request. 534 // Notify each throttle of the request.
555 NavigationThrottle::ThrottleCheckResult result = CheckWillRedirectRequest(); 535 NavigationThrottle::ThrottleCheckResult result = CheckWillRedirectRequest();
556 536
557 // If the navigation is not deferred, run the callback. 537 // If the navigation is not deferred, run the callback.
558 if (result != NavigationThrottle::DEFER) 538 if (result != NavigationThrottle::DEFER)
559 RunCompleteCallback(result); 539 RunCompleteCallback(result);
540 return result;
560 } 541 }
561 542
562 void NavigationHandleImpl::WillProcessResponse( 543 NavigationThrottle::ThrottleCheckResult
544 NavigationHandleImpl::WillProcessResponse(
563 RenderFrameHostImpl* render_frame_host, 545 RenderFrameHostImpl* render_frame_host,
564 scoped_refptr<net::HttpResponseHeaders> response_headers, 546 scoped_refptr<net::HttpResponseHeaders> response_headers,
565 net::HttpResponseInfo::ConnectionInfo connection_info, 547 net::HttpResponseInfo::ConnectionInfo connection_info,
566 const SSLStatus& ssl_status, 548 const SSLStatus& ssl_status,
567 const GlobalRequestID& request_id, 549 const GlobalRequestID& request_id,
568 bool should_replace_current_entry, 550 bool should_replace_current_entry,
569 bool is_download, 551 bool is_download,
570 bool is_stream, 552 bool is_stream,
571 const base::Closure& transfer_callback, 553 const base::Closure& transfer_callback,
572 const ThrottleChecksFinishedCallback& callback) { 554 const ThrottleChecksFinishedCallback& callback) {
(...skipping 12 matching lines...) Expand all
585 567
586 // Notify each throttle of the response. 568 // Notify each throttle of the response.
587 NavigationThrottle::ThrottleCheckResult result = CheckWillProcessResponse(); 569 NavigationThrottle::ThrottleCheckResult result = CheckWillProcessResponse();
588 570
589 // If the navigation is done processing the response, then it's ready to 571 // If the navigation is done processing the response, then it's ready to
590 // commit. Determine which RenderFrameHost should render the response, based 572 // commit. Determine which RenderFrameHost should render the response, based
591 // on its site (after any redirects). 573 // on its site (after any redirects).
592 // Note: if MaybeTransferAndProceed returns false, this means that this 574 // Note: if MaybeTransferAndProceed returns false, this means that this
593 // NavigationHandle was deleted, so return immediately. 575 // NavigationHandle was deleted, so return immediately.
594 if (result == NavigationThrottle::PROCEED && !MaybeTransferAndProceed()) 576 if (result == NavigationThrottle::PROCEED && !MaybeTransferAndProceed())
595 return; 577 return result;
596 578
597 // If the navigation is not deferred, run the callback. 579 // If the navigation is not deferred, run the callback.
598 if (result != NavigationThrottle::DEFER) 580 if (result != NavigationThrottle::DEFER)
599 RunCompleteCallback(result); 581 RunCompleteCallback(result);
582 return result;
600 } 583 }
601 584
602 void NavigationHandleImpl::ReadyToCommitNavigation( 585 void NavigationHandleImpl::ReadyToCommitNavigation(
603 RenderFrameHostImpl* render_frame_host) { 586 RenderFrameHostImpl* render_frame_host) {
604 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); 587 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host);
605 render_frame_host_ = render_frame_host; 588 render_frame_host_ = render_frame_host;
606 state_ = READY_TO_COMMIT; 589 state_ = READY_TO_COMMIT;
607 590
608 if (!IsRendererDebugURL(url_) && !IsSamePage()) 591 if (!IsRendererDebugURL(url_) && !IsSamePage())
609 GetDelegate()->ReadyToCommitNavigation(this); 592 GetDelegate()->ReadyToCommitNavigation(this);
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 content::AncestorThrottle::MaybeCreateThrottleFor(this); 866 content::AncestorThrottle::MaybeCreateThrottleFor(this);
884 if (ancestor_throttle) 867 if (ancestor_throttle)
885 throttles_.push_back(std::move(ancestor_throttle)); 868 throttles_.push_back(std::move(ancestor_throttle));
886 869
887 throttles_.insert(throttles_.begin(), 870 throttles_.insert(throttles_.begin(),
888 std::make_move_iterator(throttles_to_register.begin()), 871 std::make_move_iterator(throttles_to_register.begin()),
889 std::make_move_iterator(throttles_to_register.end())); 872 std::make_move_iterator(throttles_to_register.end()));
890 } 873 }
891 874
892 } // namespace content 875 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698