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); |