| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" | 5 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" |
| 6 | 6 |
| 7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
| 8 #include "core/dom/ExecutionContext.h" | 8 #include "core/dom/ExecutionContext.h" |
| 9 #include "core/frame/LocalFrame.h" | 9 #include "core/frame/LocalFrame.h" |
| 10 #include "core/loader/FrameLoaderClient.h" | 10 #include "core/loader/FrameLoaderClient.h" |
| 11 #include "core/workers/WorkerGlobalScope.h" | 11 #include "core/workers/WorkerGlobalScope.h" |
| 12 #include "public/platform/modules/serviceworker/WebServiceWorkerProvider.h" | 12 #include "public/platform/modules/serviceworker/WebServiceWorkerProvider.h" |
| 13 | 13 |
| 14 namespace blink { | 14 namespace blink { |
| 15 | 15 |
| 16 PassOwnPtrWillBeRawPtr<ServiceWorkerContainerClient> ServiceWorkerContainerClien
t::create(PassOwnPtr<WebServiceWorkerProvider> provider) | 16 RawPtr<ServiceWorkerContainerClient> ServiceWorkerContainerClient::create(PassOw
nPtr<WebServiceWorkerProvider> provider) |
| 17 { | 17 { |
| 18 return adoptPtrWillBeNoop(new ServiceWorkerContainerClient(provider)); | 18 return (new ServiceWorkerContainerClient(provider)); |
| 19 } | 19 } |
| 20 | 20 |
| 21 ServiceWorkerContainerClient::ServiceWorkerContainerClient(PassOwnPtr<WebService
WorkerProvider> provider) | 21 ServiceWorkerContainerClient::ServiceWorkerContainerClient(PassOwnPtr<WebService
WorkerProvider> provider) |
| 22 : m_provider(provider) | 22 : m_provider(provider) |
| 23 { | 23 { |
| 24 } | 24 } |
| 25 | 25 |
| 26 ServiceWorkerContainerClient::~ServiceWorkerContainerClient() | 26 ServiceWorkerContainerClient::~ServiceWorkerContainerClient() |
| 27 { | 27 { |
| 28 } | 28 } |
| 29 | 29 |
| 30 const char* ServiceWorkerContainerClient::supplementName() | 30 const char* ServiceWorkerContainerClient::supplementName() |
| 31 { | 31 { |
| 32 return "ServiceWorkerContainerClient"; | 32 return "ServiceWorkerContainerClient"; |
| 33 } | 33 } |
| 34 | 34 |
| 35 ServiceWorkerContainerClient* ServiceWorkerContainerClient::from(ExecutionContex
t* context) | 35 ServiceWorkerContainerClient* ServiceWorkerContainerClient::from(ExecutionContex
t* context) |
| 36 { | 36 { |
| 37 if (context->isWorkerGlobalScope()) { | 37 if (context->isWorkerGlobalScope()) { |
| 38 WorkerClients* clients = toWorkerGlobalScope(context)->clients(); | 38 WorkerClients* clients = toWorkerGlobalScope(context)->clients(); |
| 39 ASSERT(clients); | 39 ASSERT(clients); |
| 40 return static_cast<ServiceWorkerContainerClient*>(WillBeHeapSupplement<W
orkerClients>::from(clients, supplementName())); | 40 return static_cast<ServiceWorkerContainerClient*>(HeapSupplement<WorkerC
lients>::from(clients, supplementName())); |
| 41 } | 41 } |
| 42 Document* document = toDocument(context); | 42 Document* document = toDocument(context); |
| 43 if (!document->frame()) | 43 if (!document->frame()) |
| 44 return nullptr; | 44 return nullptr; |
| 45 | 45 |
| 46 ServiceWorkerContainerClient* client = static_cast<ServiceWorkerContainerCli
ent*>(WillBeHeapSupplement<Document>::from(document, supplementName())); | 46 ServiceWorkerContainerClient* client = static_cast<ServiceWorkerContainerCli
ent*>(HeapSupplement<Document>::from(document, supplementName())); |
| 47 if (!client) { | 47 if (!client) { |
| 48 client = new ServiceWorkerContainerClient(document->frame()->loader().cl
ient()->createServiceWorkerProvider()); | 48 client = new ServiceWorkerContainerClient(document->frame()->loader().cl
ient()->createServiceWorkerProvider()); |
| 49 WillBeHeapSupplement<Document>::provideTo(*document, supplementName(), a
doptPtrWillBeNoop(client)); | 49 HeapSupplement<Document>::provideTo(*document, supplementName(), (client
)); |
| 50 } | 50 } |
| 51 return client; | 51 return client; |
| 52 } | 52 } |
| 53 | 53 |
| 54 void provideServiceWorkerContainerClientToWorker(WorkerClients* clients, PassOwn
Ptr<WebServiceWorkerProvider> provider) | 54 void provideServiceWorkerContainerClientToWorker(WorkerClients* clients, PassOwn
Ptr<WebServiceWorkerProvider> provider) |
| 55 { | 55 { |
| 56 clients->provideSupplement(ServiceWorkerContainerClient::supplementName(), S
erviceWorkerContainerClient::create(provider)); | 56 clients->provideSupplement(ServiceWorkerContainerClient::supplementName(), S
erviceWorkerContainerClient::create(provider)); |
| 57 } | 57 } |
| 58 | 58 |
| 59 } // namespace blink | 59 } // namespace blink |
| OLD | NEW |