Chromium Code Reviews| 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" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 class ClientArray { | 25 class ClientArray { |
| 26 public: | 26 public: |
| 27 typedef blink::WebServiceWorkerClientsInfo WebType; | 27 typedef blink::WebServiceWorkerClientsInfo WebType; |
| 28 static HeapVector<Member<ServiceWorkerClient>> take(ScriptPromiseResolver*, WebType* webClientsRaw) | 28 static HeapVector<Member<ServiceWorkerClient>> take(ScriptPromiseResolver*, WebType* webClientsRaw) |
| 29 { | 29 { |
| 30 OwnPtr<WebType> webClients = adoptPtr(webClientsRaw); | 30 OwnPtr<WebType> webClients = adoptPtr(webClientsRaw); |
| 31 HeapVector<Member<ServiceWorkerClient>> clients; | 31 HeapVector<Member<ServiceWorkerClient>> clients; |
| 32 for (size_t i = 0; i < webClients->clients.size(); ++i) { | 32 for (size_t i = 0; i < webClients->clients.size(); ++i) { |
| 33 // FIXME: For now we only support getting "window" type clients. | 33 WebServiceWorkerClientInfo& client = webClients->clients[i]; |
|
falken
2015/03/31 04:34:32
can this be const?
nhiroki
2015/04/01 04:51:34
Done.
| |
| 34 ASSERT(webClients->clients[i].clientType == WebServiceWorkerClientTy peWindow); | 34 if (client.clientType == WebServiceWorkerClientTypeWindow) |
| 35 clients.append(ServiceWorkerWindowClient::create(webClients->clients [i])); | 35 clients.append(ServiceWorkerWindowClient::create(client)); |
| 36 else | |
| 37 clients.append(ServiceWorkerClient::create(client)); | |
| 36 } | 38 } |
| 37 return clients; | 39 return clients; |
| 38 } | 40 } |
| 39 static void dispose(WebType* webClientsRaw) | 41 static void dispose(WebType* webClientsRaw) |
| 40 { | 42 { |
| 41 delete webClientsRaw; | 43 delete webClientsRaw; |
| 42 } | 44 } |
| 43 | 45 |
| 44 private: | 46 private: |
| 45 WTF_MAKE_NONCOPYABLE(ClientArray); | 47 WTF_MAKE_NONCOPYABLE(ClientArray); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 74 ScriptPromise ServiceWorkerClients::matchAll(ScriptState* scriptState, const Cli entQueryOptions& options) | 76 ScriptPromise ServiceWorkerClients::matchAll(ScriptState* scriptState, const Cli entQueryOptions& options) |
| 75 { | 77 { |
| 76 ExecutionContext* executionContext = scriptState->executionContext(); | 78 ExecutionContext* executionContext = scriptState->executionContext(); |
| 77 // FIXME: May be null due to worker termination: http://crbug.com/413518. | 79 // FIXME: May be null due to worker termination: http://crbug.com/413518. |
| 78 if (!executionContext) | 80 if (!executionContext) |
| 79 return ScriptPromise(); | 81 return ScriptPromise(); |
| 80 | 82 |
| 81 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); | 83 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); |
| 82 ScriptPromise promise = resolver->promise(); | 84 ScriptPromise promise = resolver->promise(); |
| 83 | 85 |
| 84 if (options.type() != "window") { | |
| 85 // FIXME: Remove this when query options are supported in the embedder. | |
| 86 resolver->reject(DOMException::create(NotSupportedError, "type parameter of getAll is not supported.")); | |
| 87 return promise; | |
| 88 } | |
| 89 | |
| 90 WebServiceWorkerClientQueryOptions webOptions; | 86 WebServiceWorkerClientQueryOptions webOptions; |
| 91 webOptions.clientType = getClientType(options.type()); | 87 webOptions.clientType = getClientType(options.type()); |
| 92 webOptions.includeUncontrolled = options.includeUncontrolled(); | 88 webOptions.includeUncontrolled = options.includeUncontrolled(); |
| 93 ServiceWorkerGlobalScopeClient::from(executionContext)->getClients(webOption s, new CallbackPromiseAdapter<ClientArray, ServiceWorkerError>(resolver)); | 89 ServiceWorkerGlobalScopeClient::from(executionContext)->getClients(webOption s, new CallbackPromiseAdapter<ClientArray, ServiceWorkerError>(resolver)); |
| 94 return promise; | 90 return promise; |
| 95 } | 91 } |
| 96 | 92 |
| 97 ScriptPromise ServiceWorkerClients::claim(ScriptState* scriptState) | 93 ScriptPromise ServiceWorkerClients::claim(ScriptState* scriptState) |
| 98 { | 94 { |
| 99 ExecutionContext* executionContext = scriptState->executionContext(); | 95 ExecutionContext* executionContext = scriptState->executionContext(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 resolver->reject(DOMException::create(InvalidAccessError, "Not allowed t o open a window.")); | 127 resolver->reject(DOMException::create(InvalidAccessError, "Not allowed t o open a window.")); |
| 132 return promise; | 128 return promise; |
| 133 } | 129 } |
| 134 context->consumeWindowInteraction(); | 130 context->consumeWindowInteraction(); |
| 135 | 131 |
| 136 ServiceWorkerGlobalScopeClient::from(context)->openWindow(parsedUrl, new Cal lbackPromiseAdapter<ServiceWorkerWindowClient, ServiceWorkerError>(resolver)); | 132 ServiceWorkerGlobalScopeClient::from(context)->openWindow(parsedUrl, new Cal lbackPromiseAdapter<ServiceWorkerWindowClient, ServiceWorkerError>(resolver)); |
| 137 return promise; | 133 return promise; |
| 138 } | 134 } |
| 139 | 135 |
| 140 } // namespace blink | 136 } // namespace blink |
| OLD | NEW |