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
3 // found in the LICENSE file.
6 #include "modules/serviceworkers/ServiceWorkerClients.h"
8 #include "bindings/core/v8/CallbackPromiseAdapter.h"
9 #include "bindings/core/v8/ScriptPromiseResolver.h"
10 #include "modules/serviceworkers/ServiceWorkerClient.h"
11 #include "modules/serviceworkers/ServiceWorkerError.h"
12 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h"
13 #include "public/platform/WebServiceWorkerClientsInfo.h"
14 #include "wtf/RefPtr.h"
15 #include "wtf/Vector.h"
23 typedef blink::WebServiceWorkerClientsInfo WebType;
24 static HeapVector<Member<ServiceWorkerClient> > take(ScriptPromiseResolver*, WebType* webClientsRaw)
26 OwnPtr<WebType> webClients = adoptPtr(webClientsRaw);
27 HeapVector<Member<ServiceWorkerClient> > clients;
28 for (size_t i = 0; i < webClients->clientIDs.size(); ++i) {
29 clients.append(ServiceWorkerClient::create(webClients->clientIDs[i]));
33 static void dispose(WebType* webClientsRaw)
39 WTF_MAKE_NONCOPYABLE(ClientArray);
40 ClientArray() WTF_DELETED_FUNCTION;
45 ServiceWorkerClients* ServiceWorkerClients::create()
47 return new ServiceWorkerClients();
50 ServiceWorkerClients::ServiceWorkerClients()
54 ScriptPromise ServiceWorkerClients::getAll(ScriptState* scriptState, const ServiceWorkerClientQueryOptions& options)
56 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
57 ScriptPromise promise = resolver->promise();
59 if (options.includeUncontrolled()) {
60 // FIXME: Currently we don't support includeUncontrolled=true.
61 resolver->reject(DOMException::create(NotSupportedError, "includeUncontrolled parameter of getAll is not supported."));
65 ServiceWorkerGlobalScopeClient::from(scriptState->executionContext())->getClients(new CallbackPromiseAdapter<ClientArray, ServiceWorkerError>(resolver));