Chromium Code Reviews| Index: content/browser/loader/navigation_url_loader_impl_core.cc |
| diff --git a/content/browser/loader/navigation_url_loader_impl_core.cc b/content/browser/loader/navigation_url_loader_impl_core.cc |
| index c7a215d0dd87d8beec3d0d5b948f04ca0193c0be..924ae70c6fc52887c0020e78ffe6cfe583bb6f60 100644 |
| --- a/content/browser/loader/navigation_url_loader_impl_core.cc |
| +++ b/content/browser/loader/navigation_url_loader_impl_core.cc |
| @@ -10,7 +10,8 @@ |
| #include "content/browser/frame_host/navigation_request_info.h" |
| #include "content/browser/loader/navigation_resource_handler.h" |
| #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| -#include "content/browser/service_worker/service_worker_navigation_handle_core.h" |
| +#include "content/browser/service_worker/service_worker_context_wrapper.h" |
| +#include "content/browser/service_worker/service_worker_registration.h" |
| #include "content/common/navigation_params.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/navigation_data.h" |
| @@ -24,7 +25,9 @@ namespace content { |
| NavigationURLLoaderImplCore::NavigationURLLoaderImplCore( |
| const base::WeakPtr<NavigationURLLoaderImpl>& loader) |
| : loader_(loader), |
| - resource_handler_(nullptr) { |
| + resource_handler_(nullptr), |
| + resource_context_(nullptr), |
| + factory_(this) { |
| // This object is created on the UI thread but otherwise is accessed and |
| // deleted on the IO thread. |
| DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| @@ -39,7 +42,7 @@ NavigationURLLoaderImplCore::~NavigationURLLoaderImplCore() { |
| void NavigationURLLoaderImplCore::Start( |
| ResourceContext* resource_context, |
| - ServiceWorkerNavigationHandleCore* service_worker_handle_core, |
| + ServiceWorkerContextWrapper* service_worker_context_wrapper, |
| std::unique_ptr<NavigationRequestInfo> request_info) { |
| DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| @@ -47,11 +50,22 @@ void NavigationURLLoaderImplCore::Start( |
| BrowserThread::UI, FROM_HERE, |
| base::Bind(&NavigationURLLoaderImpl::NotifyRequestStarted, loader_, |
| base::TimeTicks::Now())); |
| - |
| - // The ResourceDispatcherHostImpl can be null in unit tests. |
| - if (ResourceDispatcherHostImpl::Get()) { |
| + request_info_ = std::move(request_info); |
| + resource_context_ = resource_context; |
| + |
| + // Check if there is a ServiceWorker registered for this navigation if |
| + // ServiceWorkers are allowed for this navigation. Otherwise start the |
| + // request right away. |
| + // ServiceWorkerContextWrapper can be null in tests. |
| + if (!request_info_->begin_params.skip_service_worker && |
| + service_worker_context_wrapper) { |
| + service_worker_context_wrapper->FindReadyRegistrationForDocument( |
| + request_info_->common_params.url, |
| + base::Bind(&NavigationURLLoaderImplCore::OnServiceWorkerChecksPerformed, |
| + factory_.GetWeakPtr())); |
| + } else { |
| ResourceDispatcherHostImpl::Get()->BeginNavigationRequest( |
| - resource_context, *request_info, this, service_worker_handle_core); |
| + resource_context_, *request_info_, this); |
| } |
| } |
| @@ -132,4 +146,28 @@ void NavigationURLLoaderImplCore::NotifyRequestFailed(bool in_cache, |
| in_cache, net_error)); |
| } |
| +void NavigationURLLoaderImplCore::OnServiceWorkerChecksPerformed( |
| + ServiceWorkerStatusCode status, |
| + const scoped_refptr<ServiceWorkerRegistration>& registration) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + // If the navigation has a ServiceWorker, bail out immediately. |
| + // TODO(clamy): only bail out when the ServiceWorker has a Fetch event |
| + // handler. |
| + if (status == SERVICE_WORKER_OK) { |
| + BrowserThread::PostTask( |
| + BrowserThread::UI, FROM_HERE, |
| + base::Bind(&NavigationURLLoaderImpl::NotifyServiceWorkerEncountered, |
| + loader_)); |
| + return; |
| + } |
| + |
| + // Otherwise, start the navigation in the network stack. |
| + |
| + // The ResourceDispatcherHostImpl can be null in unit tests. |
| + if (ResourceDispatcherHostImpl::Get()) { |
|
nasko
2016/06/27 16:54:26
nit: if (!RDH::Get()) return;
clamy
2016/06/29 12:15:51
Done.
|
| + ResourceDispatcherHostImpl::Get()->BeginNavigationRequest( |
| + resource_context_, *request_info_, this); |
| + } |
| +} |
| + |
| } // namespace content |