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 #include <memory> | 13 #include <memory> |
14 | 14 |
15 namespace blink { | 15 namespace blink { |
16 | 16 |
17 ServiceWorkerContainerClient* ServiceWorkerContainerClient::create( | 17 ServiceWorkerContainerClient::ServiceWorkerContainerClient( |
18 std::unique_ptr<WebServiceWorkerProvider> provider) { | 18 Document& document, |
19 return new ServiceWorkerContainerClient(std::move(provider)); | 19 std::unique_ptr<WebServiceWorkerProvider> provider) |
20 } | 20 : Supplement<Document>(document), m_provider(std::move(provider)) {} |
21 | 21 |
22 ServiceWorkerContainerClient::ServiceWorkerContainerClient( | 22 ServiceWorkerContainerClient::ServiceWorkerContainerClient( |
| 23 WorkerClients& clients, |
23 std::unique_ptr<WebServiceWorkerProvider> provider) | 24 std::unique_ptr<WebServiceWorkerProvider> provider) |
24 : m_provider(std::move(provider)) {} | 25 : Supplement<WorkerClients>(clients), m_provider(std::move(provider)) {} |
25 | 26 |
26 ServiceWorkerContainerClient::~ServiceWorkerContainerClient() {} | 27 ServiceWorkerContainerClient::~ServiceWorkerContainerClient() {} |
27 | 28 |
28 const char* ServiceWorkerContainerClient::supplementName() { | 29 const char* ServiceWorkerContainerClient::supplementName() { |
29 return "ServiceWorkerContainerClient"; | 30 return "ServiceWorkerContainerClient"; |
30 } | 31 } |
31 | 32 |
32 ServiceWorkerContainerClient* ServiceWorkerContainerClient::from( | 33 ServiceWorkerContainerClient* ServiceWorkerContainerClient::from( |
33 ExecutionContext* context) { | 34 ExecutionContext* context) { |
34 if (!context) | 35 if (!context) |
35 return nullptr; | 36 return nullptr; |
36 if (context->isWorkerGlobalScope()) { | 37 if (context->isWorkerGlobalScope()) { |
37 WorkerClients* clients = toWorkerGlobalScope(context)->clients(); | 38 WorkerClients* workerClients = toWorkerGlobalScope(context)->clients(); |
38 ASSERT(clients); | 39 DCHECK(workerClients); |
39 return static_cast<ServiceWorkerContainerClient*>( | 40 ServiceWorkerContainerClient* client = |
40 Supplement<WorkerClients>::from(clients, supplementName())); | 41 static_cast<ServiceWorkerContainerClient*>( |
| 42 Supplement<WorkerClients>::from(workerClients, supplementName())); |
| 43 DCHECK(client); |
| 44 return client; |
41 } | 45 } |
42 Document* document = toDocument(context); | 46 Document* document = toDocument(context); |
43 if (!document->frame()) | 47 if (!document->frame()) |
44 return nullptr; | 48 return nullptr; |
45 | 49 |
46 ServiceWorkerContainerClient* client = | 50 ServiceWorkerContainerClient* client = |
47 static_cast<ServiceWorkerContainerClient*>( | 51 static_cast<ServiceWorkerContainerClient*>( |
48 Supplement<Document>::from(document, supplementName())); | 52 Supplement<Document>::from(document, supplementName())); |
49 if (!client) { | 53 if (!client) { |
50 client = new ServiceWorkerContainerClient( | 54 client = new ServiceWorkerContainerClient( |
| 55 *document, |
51 document->frame()->loader().client()->createServiceWorkerProvider()); | 56 document->frame()->loader().client()->createServiceWorkerProvider()); |
52 Supplement<Document>::provideTo(*document, supplementName(), client); | 57 Supplement<Document>::provideTo(*document, supplementName(), client); |
53 } | 58 } |
54 return client; | 59 return client; |
55 } | 60 } |
56 | 61 |
57 void provideServiceWorkerContainerClientToWorker( | 62 void provideServiceWorkerContainerClientToWorker( |
58 WorkerClients* clients, | 63 WorkerClients* clients, |
59 std::unique_ptr<WebServiceWorkerProvider> provider) { | 64 std::unique_ptr<WebServiceWorkerProvider> provider) { |
60 clients->provideSupplement( | 65 clients->provideSupplement( |
61 ServiceWorkerContainerClient::supplementName(), | 66 ServiceWorkerContainerClient::supplementName(), |
62 ServiceWorkerContainerClient::create(std::move(provider))); | 67 new ServiceWorkerContainerClient(*clients, std::move(provider))); |
63 } | 68 } |
64 | 69 |
65 } // namespace blink | 70 } // namespace blink |
OLD | NEW |