| 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/Dictionary.h" | 9 #include "bindings/core/v8/Dictionary.h" |
| 10 #include "bindings/core/v8/ScriptPromiseResolver.h" | 10 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 11 #include "modules/serviceworkers/ServiceWorkerClient.h" | 11 #include "modules/serviceworkers/ServiceWorkerClient.h" |
| 12 #include "modules/serviceworkers/ServiceWorkerError.h" | 12 #include "modules/serviceworkers/ServiceWorkerError.h" |
| 13 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" | 13 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" |
| 14 #include "public/platform/WebServiceWorkerClientsInfo.h" | 14 #include "public/platform/WebServiceWorkerClientsInfo.h" |
| 15 #include "wtf/RefPtr.h" | 15 #include "wtf/RefPtr.h" |
| 16 #include "wtf/Vector.h" | 16 #include "wtf/Vector.h" |
| 17 | 17 |
| 18 namespace blink { | 18 namespace blink { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 class ClientArray { | 22 class ClientArray { |
| 23 public: | 23 public: |
| 24 typedef blink::WebServiceWorkerClientsInfo WebType; | 24 typedef blink::WebServiceWorkerClientsInfo WebType; |
| 25 static WillBeHeapVector<RefPtrWillBeMember<ServiceWorkerClient> > take(S
criptPromiseResolver*, WebType* webClientsRaw) | 25 static HeapVector<Member<ServiceWorkerClient> > take(ScriptPromiseResolv
er*, WebType* webClientsRaw) |
| 26 { | 26 { |
| 27 OwnPtr<WebType> webClients = adoptPtr(webClientsRaw); | 27 OwnPtr<WebType> webClients = adoptPtr(webClientsRaw); |
| 28 WillBeHeapVector<RefPtrWillBeMember<ServiceWorkerClient> > clients; | 28 HeapVector<Member<ServiceWorkerClient> > clients; |
| 29 for (size_t i = 0; i < webClients->clientIDs.size(); ++i) { | 29 for (size_t i = 0; i < webClients->clientIDs.size(); ++i) { |
| 30 clients.append(ServiceWorkerClient::create(webClients->clientIDs
[i])); | 30 clients.append(ServiceWorkerClient::create(webClients->clientIDs
[i])); |
| 31 } | 31 } |
| 32 return clients; | 32 return clients; |
| 33 } | 33 } |
| 34 static void dispose(WebType* webClientsRaw) | 34 static void dispose(WebType* webClientsRaw) |
| 35 { | 35 { |
| 36 delete webClientsRaw; | 36 delete webClientsRaw; |
| 37 } | 37 } |
| 38 | 38 |
| 39 private: | 39 private: |
| 40 WTF_MAKE_NONCOPYABLE(ClientArray); | 40 WTF_MAKE_NONCOPYABLE(ClientArray); |
| 41 ClientArray() WTF_DELETED_FUNCTION; | 41 ClientArray() WTF_DELETED_FUNCTION; |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 } // namespace | 44 } // namespace |
| 45 | 45 |
| 46 PassRefPtrWillBeRawPtr<ServiceWorkerClients> ServiceWorkerClients::create() | 46 ServiceWorkerClients* ServiceWorkerClients::create() |
| 47 { | 47 { |
| 48 return adoptRefWillBeNoop(new ServiceWorkerClients()); | 48 return new ServiceWorkerClients(); |
| 49 } | 49 } |
| 50 | 50 |
| 51 ServiceWorkerClients::ServiceWorkerClients() | 51 ServiceWorkerClients::ServiceWorkerClients() |
| 52 { | 52 { |
| 53 ScriptWrappable::init(this); | 53 ScriptWrappable::init(this); |
| 54 } | 54 } |
| 55 | 55 |
| 56 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(ServiceWorkerClients); | |
| 57 | |
| 58 ScriptPromise ServiceWorkerClients::getAll(ScriptState* scriptState, const Dicti
onary& options) | 56 ScriptPromise ServiceWorkerClients::getAll(ScriptState* scriptState, const Dicti
onary& options) |
| 59 { | 57 { |
| 60 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); | 58 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); |
| 61 ScriptPromise promise = resolver->promise(); | 59 ScriptPromise promise = resolver->promise(); |
| 62 | 60 |
| 63 bool includeUncontrolled = false; | 61 bool includeUncontrolled = false; |
| 64 DictionaryHelper::get(options, "includeUncontrolled", includeUncontrolled); | 62 DictionaryHelper::get(options, "includeUncontrolled", includeUncontrolled); |
| 65 if (includeUncontrolled) { | 63 if (includeUncontrolled) { |
| 66 // FIXME: Currently we don't support includeUncontrolled=true. | 64 // FIXME: Currently we don't support includeUncontrolled=true. |
| 67 resolver->reject(DOMException::create(NotSupportedError, "includeUncontr
olled parameter of getAll is not supported.")); | 65 resolver->reject(DOMException::create(NotSupportedError, "includeUncontr
olled parameter of getAll is not supported.")); |
| 68 return promise; | 66 return promise; |
| 69 } | 67 } |
| 70 | 68 |
| 71 ServiceWorkerGlobalScopeClient::from(scriptState->executionContext())->getCl
ients(new CallbackPromiseAdapter<ClientArray, ServiceWorkerError>(resolver)); | 69 ServiceWorkerGlobalScopeClient::from(scriptState->executionContext())->getCl
ients(new CallbackPromiseAdapter<ClientArray, ServiceWorkerError>(resolver)); |
| 72 return promise; | 70 return promise; |
| 73 } | 71 } |
| 74 | 72 |
| 75 } // namespace blink | 73 } // namespace blink |
| OLD | NEW |