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..eee83e92d4778185dc983f6592c000b89df93d5d 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,19 +42,29 @@ 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); |
+ DCHECK(service_worker_context_wrapper); |
BrowserThread::PostTask( |
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. |
+ if (!request_info_->begin_params.skip_service_worker) { |
+ 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 +145,27 @@ 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_)); |
falken
2016/06/24 08:21:51
do you need to return; here?
clamy
2016/06/24 11:16:54
Yes, good catch.
|
+ } |
+ |
+ // Otherwise, start the navigation in the network stack. |
+ |
+ // The ResourceDispatcherHostImpl can be null in unit tests. |
+ if (ResourceDispatcherHostImpl::Get()) { |
+ ResourceDispatcherHostImpl::Get()->BeginNavigationRequest( |
+ resource_context_, *request_info_, this); |
+ } |
+} |
+ |
} // namespace content |