Chromium Code Reviews| Index: Source/modules/serviceworkers/ServiceWorkerContainer.cpp |
| diff --git a/Source/modules/serviceworkers/ServiceWorkerContainer.cpp b/Source/modules/serviceworkers/ServiceWorkerContainer.cpp |
| index 0ee4d5dea26eebfa5c5d1d236baeda643e3997a2..b5671144cfdee51148984a291705ad1b645d72f1 100644 |
| --- a/Source/modules/serviceworkers/ServiceWorkerContainer.cpp |
| +++ b/Source/modules/serviceworkers/ServiceWorkerContainer.cpp |
| @@ -54,6 +54,28 @@ |
| namespace blink { |
| +// This wraps CallbackPromiseAdapter and resolves the promise with undefined |
| +// when nullptr is given to onSuccess. |
| +class GetRegistrationCallback : public WebServiceWorkerProvider::WebServiceWorkerGetRegistrationCallbacks { |
| +public: |
| + explicit GetRegistrationCallback(PassRefPtr<ScriptPromiseResolver> resolver) |
| + : m_resolver(resolver) |
| + , m_adapter(m_resolver) { } |
| + virtual ~GetRegistrationCallback() { } |
| + virtual void onSuccess(WebServiceWorkerRegistration* registration) OVERRIDE |
| + { |
| + if (registration) |
| + m_adapter.onSuccess(registration); |
| + else if (m_resolver->executionContext() && !m_resolver->executionContext()->activeDOMObjectsAreStopped()) |
| + m_resolver->resolve(); |
| + } |
| + virtual void onError(WebServiceWorkerError* error) OVERRIDE { m_adapter.onError(error); } |
| +private: |
| + RefPtr<ScriptPromiseResolver> m_resolver; |
| + CallbackPromiseAdapter<ServiceWorkerRegistration, ServiceWorkerError> m_adapter; |
| + WTF_MAKE_NONCOPYABLE(GetRegistrationCallback); |
| +}; |
| + |
| ServiceWorkerContainer* ServiceWorkerContainer::create(ExecutionContext* executionContext) |
| { |
| return new ServiceWorkerContainer(executionContext); |
| @@ -163,6 +185,32 @@ ScriptPromise ServiceWorkerContainer::unregisterServiceWorker(ScriptState* scrip |
| return promise; |
| } |
| +ScriptPromise ServiceWorkerContainer::getRegistration(ScriptState* scriptState, const String& documentURL) |
| +{ |
| + ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); |
| + RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState); |
| + ScriptPromise promise = resolver->promise(); |
| + |
| + // FIXME: This should use the container's execution context, not |
| + // the callers. |
| + ExecutionContext* executionContext = scriptState->executionContext(); |
| + RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); |
| + String errorMessage; |
| + if (!documentOrigin->canAccessFeatureRequiringSecureOrigin(errorMessage)) { |
| + resolver->reject(DOMException::create(NotSupportedError, errorMessage)); |
| + return promise; |
| + } |
| + |
| + KURL completedURL = executionContext->completeURL(documentURL); |
|
nhiroki
2014/09/10 07:45:04
(Just to check my understanding) When the document
Kunihiko Sakamoto
2014/09/10 09:34:51
Yes. I've added a test case to verify this in Serv
|
| + if (!documentOrigin->canRequest(completedURL)) { |
| + resolver->reject(DOMException::create(SecurityError, "The documentURL must match the current origin.")); |
| + return promise; |
| + } |
| + m_provider->getRegistration(completedURL, new GetRegistrationCallback(resolver)); |
| + |
| + return promise; |
| +} |
| + |
| ServiceWorkerContainer::ReadyProperty* ServiceWorkerContainer::createReadyProperty() |
| { |
| return new ReadyProperty(executionContext(), this, ReadyProperty::Ready); |