diff options
Diffstat (limited to 'third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerClients.cpp')
| -rw-r--r-- | third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerClients.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerClients.cpp b/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerClients.cpp index ff907d2..63a5149 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) { + // 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(); |
