Chromium Code Reviews| Index: third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerClients.cpp |
| diff --git a/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerClients.cpp b/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerClients.cpp |
| index ff907d2e33cf8a5dcc584a4ca7a8d8ed251671e4..17df6c736360158812d325edb0b50b572e408021 100644 |
| --- a/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerClients.cpp |
| +++ b/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerClients.cpp |
| @@ -60,6 +60,37 @@ WebServiceWorkerClientType getClientType(const String& type) |
| return WebServiceWorkerClientTypeWindow; |
| } |
| +class GetCallback : public WebServiceWorkerClientCallbacks { |
| +public: |
| + explicit GetCallback(ScriptPromiseResolver* resolver) |
| + : m_resolver(resolver) { } |
| + ~GetCallback() override { } |
| + |
| + void onSuccess(WebPassOwnPtr<WebServiceWorkerClientInfo> webClient) override |
| + { |
| + OwnPtr<WebServiceWorkerClientInfo> client = webClient.release(); |
| + if (!m_resolver->executionContext() || m_resolver->executionContext()->activeDOMObjectsAreStopped()) |
| + return; |
| + if (client->uuid == "") { |
|
nhiroki
2016/02/03 09:40:00
|client->uuid.isEmpty()| could be a bit more reada
jungkees
2016/02/03 14:15:07
Yes. Addressed.
|
| + // Resolve the promise with undefined. |
| + m_resolver->resolve(); |
| + return; |
| + } |
| + m_resolver->resolve(ServiceWorkerClient::take(m_resolver, client.release())); |
| + } |
| + |
| + void onError(const WebServiceWorkerError& error) override |
| + { |
| + if (!m_resolver->executionContext() || m_resolver->executionContext()->activeDOMObjectsAreStopped()) |
| + return; |
| + m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), error)); |
| + } |
| + |
| +private: |
| + Persistent<ScriptPromiseResolver> m_resolver; |
| + WTF_MAKE_NONCOPYABLE(GetCallback); |
| +}; |
| + |
| } // namespace |
| ServiceWorkerClients* ServiceWorkerClients::create() |
| @@ -71,6 +102,20 @@ ServiceWorkerClients::ServiceWorkerClients() |
| { |
| } |
| +ScriptPromise ServiceWorkerClients::get(ScriptState* scriptState, const String& id) |
| +{ |
| + ExecutionContext* executionContext = scriptState->executionContext(); |
| + // FIXME: May be null due to worker termination: http://crbug.com/413518. |
|
nhiroki
2016/02/03 09:40:00
"FIXME" comment is deprecated:
http://www.chromium
jungkees
2016/02/03 14:15:07
Done.
|
| + if (!executionContext) |
| + return ScriptPromise(); |
| + |
| + ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| + ScriptPromise promise = resolver->promise(); |
| + |
| + ServiceWorkerGlobalScopeClient::from(executionContext)->getClient(id, new GetCallback(resolver)); |
| + return promise; |
| +} |
| + |
| ScriptPromise ServiceWorkerClients::matchAll(ScriptState* scriptState, const ClientQueryOptions& options) |
| { |
| ExecutionContext* executionContext = scriptState->executionContext(); |