summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerClients.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerClients.cpp')
-rw-r--r--chromium/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerClients.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/chromium/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerClients.cpp b/chromium/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerClients.cpp
new file mode 100644
index 00000000000..9af10f5fb42
--- /dev/null
+++ b/chromium/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerClients.cpp
@@ -0,0 +1,63 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "modules/serviceworkers/ServiceWorkerClients.h"
+
+#include "bindings/v8/CallbackPromiseAdapter.h"
+#include "bindings/v8/ScriptPromiseResolver.h"
+#include "bindings/v8/ScriptPromiseResolverWithContext.h"
+#include "modules/serviceworkers/Client.h"
+#include "modules/serviceworkers/ServiceWorkerError.h"
+#include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h"
+#include "public/platform/WebServiceWorkerClientsInfo.h"
+#include "wtf/RefPtr.h"
+#include "wtf/Vector.h"
+
+namespace WebCore {
+
+namespace {
+
+ class ClientArray {
+ public:
+ typedef blink::WebServiceWorkerClientsInfo WebType;
+ static Vector<RefPtr<Client> > from(ScriptPromiseResolverWithContext*, WebType* webClientsRaw)
+ {
+ OwnPtr<WebType> webClients = adoptPtr(webClientsRaw);
+ Vector<RefPtr<Client> > clients;
+ for (size_t i = 0; i < webClients->clientIDs.size(); ++i) {
+ clients.append(Client::create(webClients->clientIDs[i]));
+ }
+ return clients;
+ }
+
+ private:
+ WTF_MAKE_NONCOPYABLE(ClientArray);
+ ClientArray() WTF_DELETED_FUNCTION;
+ };
+
+} // namespace
+
+PassRefPtr<ServiceWorkerClients> ServiceWorkerClients::create()
+{
+ return adoptRef(new ServiceWorkerClients());
+}
+
+ServiceWorkerClients::ServiceWorkerClients()
+{
+ ScriptWrappable::init(this);
+}
+
+ServiceWorkerClients::~ServiceWorkerClients()
+{
+}
+
+ScriptPromise ServiceWorkerClients::getServiced(ScriptState* scriptState)
+{
+ RefPtr<ScriptPromiseResolverWithContext> resolver = ScriptPromiseResolverWithContext::create(scriptState);
+ ServiceWorkerGlobalScopeClient::from(scriptState->executionContext())->getClients(new CallbackPromiseAdapter<ClientArray, ServiceWorkerError>(resolver));
+ return resolver->promise();
+}
+
+} // namespace WebCore