Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / modules / serviceworkers / ServiceWorkerClients.cpp
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.
4
5 #include "config.h"
6 #include "modules/serviceworkers/ServiceWorkerClients.h"
7
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"
16
17 namespace blink {
18
19 namespace {
20
21     class ClientArray {
22     public:
23         typedef blink::WebServiceWorkerClientsInfo WebType;
24         static HeapVector<Member<ServiceWorkerClient> > take(ScriptPromiseResolver*, WebType* webClientsRaw)
25         {
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]));
30             }
31             return clients;
32         }
33         static void dispose(WebType* webClientsRaw)
34         {
35             delete webClientsRaw;
36         }
37
38     private:
39         WTF_MAKE_NONCOPYABLE(ClientArray);
40         ClientArray() WTF_DELETED_FUNCTION;
41     };
42
43 } // namespace
44
45 ServiceWorkerClients* ServiceWorkerClients::create()
46 {
47     return new ServiceWorkerClients();
48 }
49
50 ServiceWorkerClients::ServiceWorkerClients()
51 {
52 }
53
54 ScriptPromise ServiceWorkerClients::getAll(ScriptState* scriptState, const ServiceWorkerClientQueryOptions& options)
55 {
56     RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
57     ScriptPromise promise = resolver->promise();
58
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."));
62         return promise;
63     }
64
65     ServiceWorkerGlobalScopeClient::from(scriptState->executionContext())->getClients(new CallbackPromiseAdapter<ClientArray, ServiceWorkerError>(resolver));
66     return promise;
67 }
68
69 } // namespace blink