Index: third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerContainerClient.cpp |
diff --git a/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerContainerClient.cpp b/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerContainerClient.cpp |
index 13d91c7fed2d70c4dd60ed60e46526a591a93e85..964ad6f09bd44fe1e6f6fad73f496968e1f429a3 100644 |
--- a/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerContainerClient.cpp |
+++ b/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerContainerClient.cpp |
@@ -19,6 +19,11 @@ PassOwnPtrWillBeRawPtr<ServiceWorkerContainerClient> ServiceWorkerContainerClien |
return adoptPtrWillBeNoop(new ServiceWorkerContainerClient(provider)); |
} |
+ServiceWorkerContainerClient::ServiceWorkerContainerClient(PassOwnPtr<WebServiceWorkerProvider> provider) |
+ : m_provider(provider) |
+{ |
+} |
+ |
ServiceWorkerContainerClient::~ServiceWorkerContainerClient() |
{ |
} |
@@ -30,28 +35,21 @@ const char* ServiceWorkerContainerClient::supplementName() |
ServiceWorkerContainerClient* ServiceWorkerContainerClient::from(ExecutionContext* context) |
{ |
- if (context->isDocument()) { |
- Document* document = toDocument(context); |
- if (!document->frame()) |
- return 0; |
- |
- ServiceWorkerContainerClient* client = static_cast<ServiceWorkerContainerClient*>(WillBeHeapSupplement<Document>::from(document, supplementName())); |
- if (client) |
- return client; |
- |
- // If it's not provided yet, create it lazily. |
- document->WillBeHeapSupplementable<Document>::provideSupplement(ServiceWorkerContainerClient::supplementName(), ServiceWorkerContainerClient::create(document->frame()->loader().client()->createServiceWorkerProvider())); |
- return static_cast<ServiceWorkerContainerClient*>(WillBeHeapSupplement<Document>::from(document, supplementName())); |
+ if (context->isWorkerGlobalScope()) { |
+ WorkerClients* clients = toWorkerGlobalScope(context)->clients(); |
+ ASSERT(clients); |
+ return static_cast<ServiceWorkerContainerClient*>(WillBeHeapSupplement<WorkerClients>::from(clients, supplementName())); |
} |
- |
- WorkerClients* clients = toWorkerGlobalScope(context)->clients(); |
- ASSERT(clients); |
- return static_cast<ServiceWorkerContainerClient*>(WillBeHeapSupplement<WorkerClients>::from(clients, supplementName())); |
-} |
- |
-ServiceWorkerContainerClient::ServiceWorkerContainerClient(PassOwnPtr<WebServiceWorkerProvider> provider) |
- : m_provider(provider) |
-{ |
+ Document* document = toDocument(context); |
+ if (!document->frame()) |
+ return nullptr; |
+ |
+ ServiceWorkerContainerClient* client = static_cast<ServiceWorkerContainerClient*>(WillBeHeapSupplement<Document>::from(document, supplementName())); |
+ if (!client) { |
+ client = new ServiceWorkerContainerClient(document->frame()->loader().client()->createServiceWorkerProvider()); |
+ WillBeHeapSupplement<Document>::provideTo(*document, supplementName(), adoptPtrWillBeNoop(client)); |
+ } |
+ return client; |
} |
void provideServiceWorkerContainerClientToWorker(WorkerClients* clients, PassOwnPtr<WebServiceWorkerProvider> provider) |