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

Unified Diff: Source/modules/serviceworkers/ServiceWorkerContainer.cpp

Issue 1143293003: Service Worker: Add ServiceWorkerContainer.getRegistrations() method. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Remove unused param in claim-not-using-registration.html Created 5 years, 6 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: Source/modules/serviceworkers/ServiceWorkerContainer.cpp
diff --git a/Source/modules/serviceworkers/ServiceWorkerContainer.cpp b/Source/modules/serviceworkers/ServiceWorkerContainer.cpp
index 612d37b84959a9cb12573e8e280c148853c39798..0c5781ae6a5e19760dd49c296d5f4d0518bb4bd6 100644
--- a/Source/modules/serviceworkers/ServiceWorkerContainer.cpp
+++ b/Source/modules/serviceworkers/ServiceWorkerContainer.cpp
@@ -124,7 +124,6 @@ DEFINE_TRACE(ServiceWorkerContainer)
ScriptPromise ServiceWorkerContainer::registerServiceWorker(ScriptState* scriptState, const String& url, const RegistrationOptions& options)
{
- ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled());
RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
ScriptPromise promise = resolver->promise();
@@ -183,7 +182,6 @@ ScriptPromise ServiceWorkerContainer::registerServiceWorker(ScriptState* scriptS
ScriptPromise ServiceWorkerContainer::getRegistration(ScriptState* scriptState, const String& documentURL)
{
- ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled());
RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
ScriptPromise promise = resolver->promise();
@@ -218,6 +216,35 @@ ScriptPromise ServiceWorkerContainer::getRegistration(ScriptState* scriptState,
return promise;
}
+ScriptPromise ServiceWorkerContainer::getRegistrations(ScriptState* scriptState)
+{
+ RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
+ ScriptPromise promise = resolver->promise();
+
+ if (!m_provider) {
+ resolver->reject(DOMException::create(InvalidStateError, "Failed to get ServiceWorkerRegistration objects: The document is in an invalid state."));
+ return promise;
+ }
+
+ ExecutionContext* executionContext = scriptState->executionContext();
+ RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin();
+ String errorMessage;
+ if (!executionContext->isPrivilegedContext(errorMessage)) {
+ resolver->reject(DOMException::create(NotSupportedError, errorMessage));
+ return promise;
+ }
+
+ KURL pageURL = KURL(KURL(), documentOrigin->toString());
+ if (!pageURL.protocolIsInHTTPFamily()) {
+ resolver->reject(DOMException::create(SecurityError, "Failed to get ServiceWorkerRegistration objects: The URL protocol of the current origin ('" + documentOrigin->toString() + "') is not supported."));
+ return promise;
+ }
+
+ m_provider->getRegistrations(new CallbackPromiseAdapter<ServiceWorkerRegistrationArray, ServiceWorkerError>(resolver));
+
+ return promise;
+}
+
ServiceWorkerContainer::ReadyProperty* ServiceWorkerContainer::createReadyProperty()
{
return new ReadyProperty(executionContext(), this, ReadyProperty::Ready);
« no previous file with comments | « Source/modules/serviceworkers/ServiceWorkerContainer.h ('k') | Source/modules/serviceworkers/ServiceWorkerContainer.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698