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 "config.h" | 5 #include "config.h" |
6 #include "modules/serviceworkers/ServiceWorkerClients.h" | 6 #include "modules/serviceworkers/ServiceWorkerClients.h" |
7 | 7 |
8 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 8 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
10 #include "core/dom/ExceptionCode.h" | 10 #include "core/dom/ExceptionCode.h" |
11 #include "core/workers/WorkerGlobalScope.h" | 11 #include "core/workers/WorkerGlobalScope.h" |
12 #include "core/workers/WorkerLocation.h" | 12 #include "core/workers/WorkerLocation.h" |
13 #include "modules/serviceworkers/ServiceWorkerError.h" | 13 #include "modules/serviceworkers/ServiceWorkerError.h" |
14 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" | 14 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" |
15 #include "modules/serviceworkers/ServiceWorkerWindowClient.h" | 15 #include "modules/serviceworkers/ServiceWorkerWindowClient.h" |
| 16 #include "public/platform/WebServiceWorkerClientQueryOptions.h" |
16 #include "public/platform/WebServiceWorkerClientsInfo.h" | 17 #include "public/platform/WebServiceWorkerClientsInfo.h" |
17 #include "wtf/RefPtr.h" | 18 #include "wtf/RefPtr.h" |
18 #include "wtf/Vector.h" | 19 #include "wtf/Vector.h" |
19 | 20 |
20 namespace blink { | 21 namespace blink { |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 class ClientArray { | 25 class ClientArray { |
25 public: | 26 public: |
26 typedef blink::WebServiceWorkerClientsInfo WebType; | 27 typedef blink::WebServiceWorkerClientsInfo WebType; |
27 static HeapVector<Member<ServiceWorkerClient>> take(ScriptPromiseResolve
r*, WebType* webClientsRaw) | 28 static HeapVector<Member<ServiceWorkerClient>> take(ScriptPromiseResolver*,
WebType* webClientsRaw) |
28 { | 29 { |
29 OwnPtr<WebType> webClients = adoptPtr(webClientsRaw); | 30 OwnPtr<WebType> webClients = adoptPtr(webClientsRaw); |
30 HeapVector<Member<ServiceWorkerClient>> clients; | 31 HeapVector<Member<ServiceWorkerClient>> clients; |
31 for (size_t i = 0; i < webClients->clients.size(); ++i) { | 32 for (size_t i = 0; i < webClients->clients.size(); ++i) { |
32 clients.append(ServiceWorkerWindowClient::create(webClients->cli
ents[i])); | 33 clients.append(ServiceWorkerWindowClient::create(webClients->clients
[i])); |
33 } | |
34 return clients; | |
35 } | 34 } |
36 static void dispose(WebType* webClientsRaw) | 35 return clients; |
37 { | 36 } |
38 delete webClientsRaw; | 37 static void dispose(WebType* webClientsRaw) |
39 } | 38 { |
| 39 delete webClientsRaw; |
| 40 } |
40 | 41 |
41 private: | 42 private: |
42 WTF_MAKE_NONCOPYABLE(ClientArray); | 43 WTF_MAKE_NONCOPYABLE(ClientArray); |
43 ClientArray() = delete; | 44 ClientArray() = delete; |
44 }; | 45 }; |
| 46 |
| 47 WebServiceWorkerClientType getClientType(const String& type) |
| 48 { |
| 49 if (type == "window") |
| 50 return WebServiceWorkerClientTypeWindow; |
| 51 if (type == "worker") |
| 52 return WebServiceWorkerClientTypeWorker; |
| 53 if (type == "sharedworker") |
| 54 return WebServiceWorkerClientTypeSharedWorker; |
| 55 if (type == "all") |
| 56 return WebServiceWorkerClientTypeAll; |
| 57 ASSERT_NOT_REACHED(); |
| 58 return WebServiceWorkerClientTypeWindow; |
| 59 } |
45 | 60 |
46 } // namespace | 61 } // namespace |
47 | 62 |
48 ServiceWorkerClients* ServiceWorkerClients::create() | 63 ServiceWorkerClients* ServiceWorkerClients::create() |
49 { | 64 { |
50 return new ServiceWorkerClients(); | 65 return new ServiceWorkerClients(); |
51 } | 66 } |
52 | 67 |
53 ServiceWorkerClients::ServiceWorkerClients() | 68 ServiceWorkerClients::ServiceWorkerClients() |
54 { | 69 { |
55 } | 70 } |
56 | 71 |
57 ScriptPromise ServiceWorkerClients::matchAll(ScriptState* scriptState, const Cli
entQueryOptions& options) | 72 ScriptPromise ServiceWorkerClients::matchAll(ScriptState* scriptState, const Cli
entQueryOptions& options) |
58 { | 73 { |
59 ExecutionContext* executionContext = scriptState->executionContext(); | 74 ExecutionContext* executionContext = scriptState->executionContext(); |
60 // FIXME: May be null due to worker termination: http://crbug.com/413518. | 75 // FIXME: May be null due to worker termination: http://crbug.com/413518. |
61 if (!executionContext) | 76 if (!executionContext) |
62 return ScriptPromise(); | 77 return ScriptPromise(); |
63 | 78 |
64 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); | 79 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); |
65 ScriptPromise promise = resolver->promise(); | 80 ScriptPromise promise = resolver->promise(); |
66 | 81 |
67 if (options.includeUncontrolled()) { | 82 if (options.includeUncontrolled()) { |
68 // FIXME: Currently we don't support includeUncontrolled=true. | 83 // FIXME: Remove this when query options are supported in the embedder. |
69 resolver->reject(DOMException::create(NotSupportedError, "includeUncontr
olled parameter of getAll is not supported.")); | 84 resolver->reject(DOMException::create(NotSupportedError, "includeUncontr
olled parameter of getAll is not supported.")); |
70 return promise; | 85 return promise; |
71 } | 86 } |
72 | 87 |
73 if (options.type() != "window") { | 88 if (options.type() != "window") { |
74 // FIXME: Currently we only support WindowClients. | 89 // FIXME: Remove this when query options are supported in the embedder. |
75 resolver->reject(DOMException::create(NotSupportedError, "type parameter
of getAll is not supported.")); | 90 resolver->reject(DOMException::create(NotSupportedError, "type parameter
of getAll is not supported.")); |
76 return promise; | 91 return promise; |
77 } | 92 } |
78 | 93 |
79 ServiceWorkerGlobalScopeClient::from(executionContext)->getClients(new Callb
ackPromiseAdapter<ClientArray, ServiceWorkerError>(resolver)); | 94 WebServiceWorkerClientQueryOptions webOptions; |
| 95 webOptions.clientType = getClientType(options.type()); |
| 96 webOptions.includeUncontrolled = options.includeUncontrolled; |
| 97 ServiceWorkerGlobalScopeClient::from(executionContext)->getClients(webOption
s, new CallbackPromiseAdapter<ClientArray, ServiceWorkerError>(resolver)); |
80 return promise; | 98 return promise; |
81 } | 99 } |
82 | 100 |
83 ScriptPromise ServiceWorkerClients::claim(ScriptState* scriptState) | 101 ScriptPromise ServiceWorkerClients::claim(ScriptState* scriptState) |
84 { | 102 { |
85 ExecutionContext* executionContext = scriptState->executionContext(); | 103 ExecutionContext* executionContext = scriptState->executionContext(); |
86 | 104 |
87 // FIXME: May be null due to worker termination: http://crbug.com/413518. | 105 // FIXME: May be null due to worker termination: http://crbug.com/413518. |
88 if (!executionContext) | 106 if (!executionContext) |
89 return ScriptPromise(); | 107 return ScriptPromise(); |
(...skipping 27 matching lines...) Expand all Loading... |
117 resolver->reject(DOMException::create(InvalidAccessError, "Not allowed t
o open a window.")); | 135 resolver->reject(DOMException::create(InvalidAccessError, "Not allowed t
o open a window.")); |
118 return promise; | 136 return promise; |
119 } | 137 } |
120 context->consumeWindowInteraction(); | 138 context->consumeWindowInteraction(); |
121 | 139 |
122 ServiceWorkerGlobalScopeClient::from(context)->openWindow(parsedUrl, new Cal
lbackPromiseAdapter<ServiceWorkerWindowClient, ServiceWorkerError>(resolver)); | 140 ServiceWorkerGlobalScopeClient::from(context)->openWindow(parsedUrl, new Cal
lbackPromiseAdapter<ServiceWorkerWindowClient, ServiceWorkerError>(resolver)); |
123 return promise; | 141 return promise; |
124 } | 142 } |
125 | 143 |
126 } // namespace blink | 144 } // namespace blink |
OLD | NEW |