Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(901)

Unified Diff: third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerClients.cpp

Issue 1439333002: Service Worker: Add Clients.get(id) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unnecessary condition Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..63a51494d0327fc0d5990251ecc2da276af34e7c 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();

Powered by Google App Engine
This is Rietveld 408576698