Index: content/browser/service_worker/service_worker_request_handler.cc |
diff --git a/content/browser/service_worker/service_worker_request_handler.cc b/content/browser/service_worker/service_worker_request_handler.cc |
index 6d7d04b2e0a1b99a9101916faee3f4dd1612a9fb..7a19f8e09cb27c07e43be0d24db2d5bd2597b2b2 100644 |
--- a/content/browser/service_worker/service_worker_request_handler.cc |
+++ b/content/browser/service_worker/service_worker_request_handler.cc |
@@ -6,6 +6,8 @@ |
#include <string> |
+#include "base/command_line.h" |
+#include "content/browser/loader/navigation_url_loader_impl_core.h" |
#include "content/browser/service_worker/service_worker_context_core.h" |
#include "content/browser/service_worker/service_worker_context_wrapper.h" |
#include "content/browser/service_worker/service_worker_provider_host.h" |
@@ -15,6 +17,7 @@ |
#include "content/common/service_worker/service_worker_types.h" |
#include "content/common/service_worker/service_worker_utils.h" |
#include "content/public/browser/resource_context.h" |
+#include "content/public/common/content_switches.h" |
#include "content/public/common/origin_util.h" |
#include "net/base/net_util.h" |
#include "net/url_request/url_request.h" |
@@ -64,7 +67,8 @@ void ServiceWorkerRequestHandler::InitializeHandler( |
ResourceType resource_type, |
RequestContextType request_context_type, |
RequestContextFrameType frame_type, |
- scoped_refptr<ResourceRequestBody> body) { |
+ scoped_refptr<ResourceRequestBody> body, |
+ NavigationURLLoaderImplCore* loader) { |
// Create the handler even for insecure HTTP since it's used in the |
// case of redirect to HTTPS. |
if (!request->url().SchemeIsHTTPOrHTTPS() && |
@@ -77,13 +81,28 @@ void ServiceWorkerRequestHandler::InitializeHandler( |
return; |
} |
- ServiceWorkerProviderHost* provider_host = |
- context_wrapper->context()->GetProviderHost(process_id, provider_id); |
+ ServiceWorkerProviderHost* provider_host = nullptr; |
+ if (process_id == -1) { |
+ // PlzNavigate |
+ // Initialize a dummy SWProviderHost for browser-initiated navigations. |
+ CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
+ switches::kEnableBrowserSideNavigation)); |
+ DCHECK(ServiceWorkerUtils::IsBrowserAssignedProviderId(provider_id)); |
clamy
2015/08/31 12:09:27
nit: add a DCHECK(loader)?
Fabrice (no longer in Chrome)
2015/08/31 14:00:35
Good idea. Done.
|
+ scoped_ptr<ServiceWorkerProviderHost> scoped_provider_host( |
+ context_wrapper->context()->CreateBrowserProviderHost(provider_id)); |
+ provider_host = scoped_provider_host.get(); |
+ loader->SetServiceWorkerProviderHost(scoped_provider_host.Pass()); |
+ } else { |
+ provider_host = |
+ context_wrapper->context()->GetProviderHost(process_id, provider_id); |
+ } |
+ |
if (!provider_host || !provider_host->IsContextAlive()) |
return; |
if (skip_service_worker) { |
if (ServiceWorkerUtils::IsMainResourceType(resource_type)) { |
+ // TODO(horo): Does this work properly for PlzNavigate? |
provider_host->SetDocumentUrl(net::SimplifyUrlForRequest(request->url())); |
provider_host->SetTopmostFrameUrl(request->first_party_for_cookies()); |
// A page load with skip_service_worker should be triggered by |