| Index: content/browser/loader/navigation_resource_throttle.cc
|
| diff --git a/content/browser/loader/navigation_resource_throttle.cc b/content/browser/loader/navigation_resource_throttle.cc
|
| index 6047df2c5855622075e2abacdb89a56738bbeb84..c33a95cb8b062706c91b81360ef5e7a5084b1fe6 100644
|
| --- a/content/browser/loader/navigation_resource_throttle.cc
|
| +++ b/content/browser/loader/navigation_resource_throttle.cc
|
| @@ -15,6 +15,8 @@
|
| #include "content/browser/frame_host/navigator.h"
|
| #include "content/browser/frame_host/render_frame_host_impl.h"
|
| #include "content/browser/loader/navigation_resource_handler.h"
|
| +#include "content/browser/loader/resource_dispatcher_host_impl.h"
|
| +#include "content/browser/loader/resource_loader.h"
|
| #include "content/browser/loader/resource_request_info_impl.h"
|
| #include "content/public/browser/browser_thread.h"
|
| #include "content/public/browser/navigation_data.h"
|
| @@ -38,6 +40,9 @@ namespace {
|
| // NavigationHandle.
|
| bool g_ui_checks_always_succeed = false;
|
|
|
| +// Used in unit tests to transfer all navigations.
|
| +bool g_force_transfer = false;
|
| +
|
| typedef base::Callback<void(NavigationThrottle::ThrottleCheckResult)>
|
| UIChecksPerformedCallback;
|
|
|
| @@ -140,6 +145,11 @@ void WillProcessResponseOnUIThread(
|
| int render_frame_host_id,
|
| scoped_refptr<net::HttpResponseHeaders> headers,
|
| const SSLStatus& ssl_status,
|
| + const GlobalRequestID& request_id,
|
| + bool should_replace_current_entry,
|
| + bool is_download,
|
| + bool is_stream,
|
| + const base::Closure& transfer_callback,
|
| std::unique_ptr<NavigationData> navigation_data) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| NavigationHandleImpl* navigation_handle =
|
| @@ -154,7 +164,8 @@ void WillProcessResponseOnUIThread(
|
| RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id);
|
| DCHECK(render_frame_host);
|
| navigation_handle->WillProcessResponse(
|
| - render_frame_host, headers, ssl_status,
|
| + render_frame_host, headers, ssl_status, request_id,
|
| + should_replace_current_entry, is_download, is_stream, transfer_callback,
|
| base::Bind(&SendCheckResultToIOThread, callback));
|
| }
|
|
|
| @@ -167,6 +178,8 @@ NavigationResourceThrottle::NavigationResourceThrottle(
|
| : request_(request),
|
| resource_dispatcher_host_delegate_(resource_dispatcher_host_delegate),
|
| request_context_type_(request_context_type),
|
| + in_cross_site_transition_(false),
|
| + on_transfer_done_result_(NavigationThrottle::DEFER),
|
| weak_ptr_factory_(this) {}
|
|
|
| NavigationResourceThrottle::~NavigationResourceThrottle() {}
|
| @@ -245,7 +258,8 @@ void NavigationResourceThrottle::WillRedirectRequest(
|
|
|
| void NavigationResourceThrottle::WillProcessResponse(bool* defer) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| - const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request_);
|
| + const ResourceRequestInfoImpl* info =
|
| + ResourceRequestInfoImpl::ForRequest(request_);
|
| if (!info)
|
| return;
|
|
|
| @@ -275,6 +289,9 @@ void NavigationResourceThrottle::WillProcessResponse(bool* defer) {
|
| UIChecksPerformedCallback callback =
|
| base::Bind(&NavigationResourceThrottle::OnUIChecksPerformed,
|
| weak_ptr_factory_.GetWeakPtr());
|
| + base::Closure transfer_callback =
|
| + base::Bind(&NavigationResourceThrottle::InitiateTransfer,
|
| + weak_ptr_factory_.GetWeakPtr());
|
|
|
| SSLStatus ssl_status;
|
| if (request_->ssl_info().cert.get()) {
|
| @@ -286,6 +303,9 @@ void NavigationResourceThrottle::WillProcessResponse(bool* defer) {
|
| BrowserThread::UI, FROM_HERE,
|
| base::Bind(&WillProcessResponseOnUIThread, callback, render_process_id,
|
| render_frame_id, response_headers, ssl_status,
|
| + info->GetGlobalRequestID(),
|
| + info->should_replace_current_entry(), info->IsDownload(),
|
| + info->is_stream(), transfer_callback,
|
| base::Passed(&cloned_data)));
|
| *defer = true;
|
| }
|
| @@ -299,9 +319,20 @@ void NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(
|
| g_ui_checks_always_succeed = ui_checks_always_succeed;
|
| }
|
|
|
| +void NavigationResourceThrottle::set_force_transfer_for_testing(
|
| + bool force_transfer) {
|
| + g_force_transfer = force_transfer;
|
| +}
|
| +
|
| void NavigationResourceThrottle::OnUIChecksPerformed(
|
| NavigationThrottle::ThrottleCheckResult result) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| + DCHECK_NE(NavigationThrottle::DEFER, result);
|
| + if (in_cross_site_transition_) {
|
| + on_transfer_done_result_ = result;
|
| + return;
|
| + }
|
| +
|
| if (result == NavigationThrottle::CANCEL_AND_IGNORE) {
|
| controller()->CancelAndIgnore();
|
| } else if (result == NavigationThrottle::CANCEL) {
|
| @@ -313,4 +344,28 @@ void NavigationResourceThrottle::OnUIChecksPerformed(
|
| }
|
| }
|
|
|
| +void NavigationResourceThrottle::InitiateTransfer() {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| + in_cross_site_transition_ = true;
|
| + ResourceRequestInfoImpl* info =
|
| + ResourceRequestInfoImpl::ForRequest(request_);
|
| + ResourceDispatcherHostImpl::Get()->MarkAsTransferredNavigation(
|
| + info->GetGlobalRequestID(),
|
| + base::Bind(&NavigationResourceThrottle::OnTransferComplete,
|
| + weak_ptr_factory_.GetWeakPtr()));
|
| +}
|
| +
|
| +void NavigationResourceThrottle::OnTransferComplete() {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| + DCHECK(in_cross_site_transition_);
|
| + in_cross_site_transition_ = false;
|
| +
|
| + // If the results of the checks on the UI thread are known, unblock the
|
| + // navigation. Otherwise, wait until the callback has executed.
|
| + if (on_transfer_done_result_ != NavigationThrottle::DEFER) {
|
| + OnUIChecksPerformed(on_transfer_done_result_);
|
| + on_transfer_done_result_ = NavigationThrottle::DEFER;
|
| + }
|
| +}
|
| +
|
| } // namespace content
|
|
|