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..1635bb546859dc6c1aa154bd8c09776c5a788198 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 || client->uuid.isEmpty()) { |
|
nhiroki
2016/02/22 15:59:09
According to the assertion newly added at line 897
jungkees
2016/02/22 23:08:25
Yes, that's right. I removed the latter condition.
|
| + // 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(); |
| + // TODO(jungkees): May be null due to worker termination: http://crbug.com/413518. |
| + 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(); |