Chromium Code Reviews

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: Use provider's origin in browser instead of passing client's url from renderer. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Index: Source/modules/serviceworkers/ServiceWorkerContainer.cpp
diff --git a/Source/modules/serviceworkers/ServiceWorkerContainer.cpp b/Source/modules/serviceworkers/ServiceWorkerContainer.cpp
index 612d37b84959a9cb12573e8e280c148853c39798..481066d16992ba64604e2992becddde3ad7fdde8 100644
--- a/Source/modules/serviceworkers/ServiceWorkerContainer.cpp
+++ b/Source/modules/serviceworkers/ServiceWorkerContainer.cpp
@@ -218,6 +218,36 @@ ScriptPromise ServiceWorkerContainer::getRegistration(ScriptState* scriptState,
return promise;
}
+ScriptPromise ServiceWorkerContainer::getRegistrations(ScriptState* scriptState)
+{
+ ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled());
falken 2015/05/25 00:43:02 We should not add this, since we'd like to remove
+ 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);

Powered by Google App Engine