| 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/loader/navigation_resource_throttle.h" | 5 #include "content/browser/loader/navigation_resource_throttle.h" | 
| 6 | 6 | 
| 7 #include <memory> | 7 #include <memory> | 
| 8 | 8 | 
| 9 #include "base/bind.h" | 9 #include "base/bind.h" | 
| 10 #include "base/callback.h" | 10 #include "base/callback.h" | 
| (...skipping 30 matching lines...) Expand all  Loading... | 
| 41 | 41 | 
| 42 // Used in unit tests to transfer all navigations. | 42 // Used in unit tests to transfer all navigations. | 
| 43 bool g_force_transfer = false; | 43 bool g_force_transfer = false; | 
| 44 | 44 | 
| 45 typedef base::Callback<void(NavigationThrottle::ThrottleCheckResult)> | 45 typedef base::Callback<void(NavigationThrottle::ThrottleCheckResult)> | 
| 46     UIChecksPerformedCallback; | 46     UIChecksPerformedCallback; | 
| 47 | 47 | 
| 48 void SendCheckResultToIOThread(UIChecksPerformedCallback callback, | 48 void SendCheckResultToIOThread(UIChecksPerformedCallback callback, | 
| 49                                NavigationThrottle::ThrottleCheckResult result) { | 49                                NavigationThrottle::ThrottleCheckResult result) { | 
| 50   DCHECK_CURRENTLY_ON(BrowserThread::UI); | 50   DCHECK_CURRENTLY_ON(BrowserThread::UI); | 
| 51   DCHECK_NE(result, NavigationThrottle::DEFER); | 51   DCHECK_NE(result.action(), NavigationThrottle::DEFER); | 
| 52   BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 52   BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 
| 53                           base::Bind(callback, result)); | 53                           base::Bind(callback, result)); | 
| 54 } | 54 } | 
| 55 | 55 | 
| 56 // Returns the NavigationHandle to use for a navigation in the frame specified | 56 // Returns the NavigationHandle to use for a navigation in the frame specified | 
| 57 // by |render_process_id| and |render_frame_host_id|. If not found, |callback| | 57 // by |render_process_id| and |render_frame_host_id|. If not found, |callback| | 
| 58 // will be invoked to cancel the request. | 58 // will be invoked to cancel the request. | 
| 59 // | 59 // | 
| 60 // Note: in unit test |callback| may be invoked with a value of proceed if no | 60 // Note: in unit test |callback| may be invoked with a value of proceed if no | 
| 61 // handle is found. This happens when | 61 // handle is found. This happens when | 
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 337 } | 337 } | 
| 338 | 338 | 
| 339 void NavigationResourceThrottle::set_force_transfer_for_testing( | 339 void NavigationResourceThrottle::set_force_transfer_for_testing( | 
| 340     bool force_transfer) { | 340     bool force_transfer) { | 
| 341   g_force_transfer = force_transfer; | 341   g_force_transfer = force_transfer; | 
| 342 } | 342 } | 
| 343 | 343 | 
| 344 void NavigationResourceThrottle::OnUIChecksPerformed( | 344 void NavigationResourceThrottle::OnUIChecksPerformed( | 
| 345     NavigationThrottle::ThrottleCheckResult result) { | 345     NavigationThrottle::ThrottleCheckResult result) { | 
| 346   DCHECK_CURRENTLY_ON(BrowserThread::IO); | 346   DCHECK_CURRENTLY_ON(BrowserThread::IO); | 
| 347   DCHECK_NE(NavigationThrottle::DEFER, result); | 347   DCHECK_NE(NavigationThrottle::DEFER, result.action()); | 
| 348   if (in_cross_site_transition_) { | 348   if (in_cross_site_transition_) { | 
| 349     on_transfer_done_result_ = result; | 349     on_transfer_done_result_ = result; | 
| 350     return; | 350     return; | 
| 351   } | 351   } | 
| 352 | 352 | 
| 353   if (result == NavigationThrottle::CANCEL_AND_IGNORE) { | 353   if (result.action() == NavigationThrottle::CANCEL_AND_IGNORE) { | 
|  | 354     DCHECK_EQ(net::ERR_ABORTED, result.net_error_code()); | 
| 354     CancelAndIgnore(); | 355     CancelAndIgnore(); | 
| 355   } else if (result == NavigationThrottle::CANCEL) { | 356   } else if (result.action() == NavigationThrottle::CANCEL) { | 
|  | 357     DCHECK_EQ(net::ERR_ABORTED, result.net_error_code()); | 
| 356     Cancel(); | 358     Cancel(); | 
| 357   } else if (result == NavigationThrottle::BLOCK_REQUEST) { | 359   } else if (result.action() == NavigationThrottle::BLOCK_REQUEST) { | 
| 358     CancelWithError(net::ERR_BLOCKED_BY_CLIENT); | 360     DCHECK_NE(net::OK, result.net_error_code()); | 
| 359   } else if (result == NavigationThrottle::BLOCK_RESPONSE) { | 361     CancelWithError(result.net_error_code()); | 
|  | 362   } else if (result.action() == NavigationThrottle::BLOCK_RESPONSE) { | 
|  | 363     DCHECK_NE(net::OK, result.net_error_code()); | 
| 360     // TODO(mkwst): If we cancel the main frame request with anything other than | 364     // TODO(mkwst): If we cancel the main frame request with anything other than | 
| 361     // 'net::ERR_ABORTED', we'll trigger some special behavior that might not be | 365     // 'net::ERR_ABORTED', we'll trigger some special behavior that might not be | 
| 362     // desirable here (non-POSTs will reload the page, while POST has some logic | 366     // desirable here (non-POSTs will reload the page, while POST has some logic | 
| 363     // around reloading to avoid duplicating actions server-side). For the | 367     // around reloading to avoid duplicating actions server-side). For the | 
| 364     // moment, only child frame navigations should be blocked. If we need to | 368     // moment, only child frame navigations should be blocked. If we need to | 
| 365     // block main frame navigations in the future, we'll need to carefully | 369     // block main frame navigations in the future, we'll need to carefully | 
| 366     // consider the right thing to do here. | 370     // consider the right thing to do here. | 
| 367     DCHECK(!ResourceRequestInfo::ForRequest(request_)->IsMainFrame()); | 371     DCHECK(!ResourceRequestInfo::ForRequest(request_)->IsMainFrame()); | 
| 368     CancelWithError(net::ERR_BLOCKED_BY_RESPONSE); | 372     CancelWithError(result.net_error_code()); | 
| 369   } else { | 373   } else { | 
| 370     Resume(); | 374     Resume(); | 
| 371   } | 375   } | 
| 372 } | 376 } | 
| 373 | 377 | 
| 374 void NavigationResourceThrottle::InitiateTransfer() { | 378 void NavigationResourceThrottle::InitiateTransfer() { | 
| 375   DCHECK_CURRENTLY_ON(BrowserThread::IO); | 379   DCHECK_CURRENTLY_ON(BrowserThread::IO); | 
| 376   in_cross_site_transition_ = true; | 380   in_cross_site_transition_ = true; | 
| 377   ResourceRequestInfoImpl* info = | 381   ResourceRequestInfoImpl* info = | 
| 378       ResourceRequestInfoImpl::ForRequest(request_); | 382       ResourceRequestInfoImpl::ForRequest(request_); | 
| 379   ResourceDispatcherHostImpl::Get()->MarkAsTransferredNavigation( | 383   ResourceDispatcherHostImpl::Get()->MarkAsTransferredNavigation( | 
| 380       info->GetGlobalRequestID(), | 384       info->GetGlobalRequestID(), | 
| 381       base::Bind(&NavigationResourceThrottle::OnTransferComplete, | 385       base::Bind(&NavigationResourceThrottle::OnTransferComplete, | 
| 382                  weak_ptr_factory_.GetWeakPtr())); | 386                  weak_ptr_factory_.GetWeakPtr())); | 
| 383 } | 387 } | 
| 384 | 388 | 
| 385 void NavigationResourceThrottle::OnTransferComplete() { | 389 void NavigationResourceThrottle::OnTransferComplete() { | 
| 386   DCHECK_CURRENTLY_ON(BrowserThread::IO); | 390   DCHECK_CURRENTLY_ON(BrowserThread::IO); | 
| 387   DCHECK(in_cross_site_transition_); | 391   DCHECK(in_cross_site_transition_); | 
| 388   in_cross_site_transition_ = false; | 392   in_cross_site_transition_ = false; | 
| 389 | 393 | 
| 390   // If the results of the checks on the UI thread are known, unblock the | 394   // If the results of the checks on the UI thread are known, unblock the | 
| 391   // navigation. Otherwise, wait until the callback has executed. | 395   // navigation. Otherwise, wait until the callback has executed. | 
| 392   if (on_transfer_done_result_ != NavigationThrottle::DEFER) { | 396   if (on_transfer_done_result_.action() != NavigationThrottle::DEFER) { | 
| 393     OnUIChecksPerformed(on_transfer_done_result_); | 397     OnUIChecksPerformed(on_transfer_done_result_); | 
| 394     on_transfer_done_result_ = NavigationThrottle::DEFER; | 398     on_transfer_done_result_ = NavigationThrottle::DEFER; | 
| 395   } | 399   } | 
| 396 } | 400 } | 
| 397 | 401 | 
| 398 }  // namespace content | 402 }  // namespace content | 
| OLD | NEW | 
|---|