Index: Source/modules/serviceworkers/ServiceWorkerRegistration.cpp |
diff --git a/Source/modules/serviceworkers/ServiceWorkerRegistration.cpp b/Source/modules/serviceworkers/ServiceWorkerRegistration.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4e89134b779a14cfa4f86bfbb90b9a4eb307023a |
--- /dev/null |
+++ b/Source/modules/serviceworkers/ServiceWorkerRegistration.cpp |
@@ -0,0 +1,104 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "config.h" |
+#include "ServiceWorkerRegistration.h" |
+ |
+#include "bindings/core/v8/CallbackPromiseAdapter.h" |
+#include "bindings/core/v8/ScriptPromise.h" |
+#include "bindings/core/v8/ScriptPromiseResolver.h" |
+#include "bindings/core/v8/ScriptState.h" |
+#include "core/dom/DOMException.h" |
+#include "core/dom/ExceptionCode.h" |
+#include "core/dom/ExecutionContext.h" |
+#include "modules/EventTargetModules.h" |
+#include "modules/serviceworkers/ServiceWorkerContainerClient.h" |
+#include "modules/serviceworkers/ServiceWorkerError.h" |
+#include "public/platform/WebServiceWorkerProvider.h" |
+ |
+namespace blink { |
+ |
+class UndefinedValue { |
+public: |
+#ifdef DISABLE_SERVICE_WORKER_REGISTRATION |
+ typedef WebServiceWorker WebType; |
+#else |
+ typedef WebServiceWorkerRegistration WebType; |
+#endif |
+ static V8UndefinedType from(ScriptPromiseResolver* resolver, WebType* registration) |
+ { |
+ ASSERT(!registration); // Anything passed here will be leaked. |
+ return V8UndefinedType(); |
+ } |
+ |
+private: |
+ UndefinedValue(); |
+}; |
+ |
+const AtomicString& ServiceWorkerRegistration::interfaceName() const |
+{ |
+ return EventTargetNames::ServiceWorkerRegistration; |
+} |
+ |
+PassRefPtrWillBeRawPtr<ServiceWorkerRegistration> ServiceWorkerRegistration::from(ExecutionContext* executionContext, WebType* registration) |
tkent
2014/07/25 07:50:24
We don't name 'from' for such function. 'from' is
nhiroki
2014/07/25 08:28:56
Removed (this was not necessary).
|
+{ |
+ if (!registration) |
+ return nullptr; |
+ return create(executionContext, adoptPtr(registration)); |
+} |
+ |
+PassRefPtrWillBeRawPtr<ServiceWorkerRegistration> ServiceWorkerRegistration::from(ScriptPromiseResolver* resolver, WebType* registration) |
tkent
2014/07/25 07:50:24
Ditto.
nhiroki
2014/07/25 08:28:56
This function name is defined by CallbackPromiseAd
|
+{ |
+ return ServiceWorkerRegistration::from(resolver->scriptState()->executionContext(), registration); |
+} |
+ |
+String ServiceWorkerRegistration::scope() const |
+{ |
+ return m_outerRegistration->scope().string(); |
+} |
+ |
+ScriptPromise ServiceWorkerRegistration::unregister(ScriptState* scriptState) |
+{ |
+ RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState); |
+ ScriptPromise promise = resolver->promise(); |
+ |
+ if (!m_provider) { |
+ resolver->reject(DOMException::create(InvalidStateError, "No associated provider is available")); |
+ return promise; |
+ } |
+ |
+ RefPtr<SecurityOrigin> documentOrigin = scriptState->executionContext()->securityOrigin(); |
+ KURL scopeURL = scriptState->executionContext()->completeURL(scope()); |
+ scopeURL.removeFragmentIdentifier(); |
+ if (!scope().isEmpty() && !documentOrigin->canRequest(scopeURL)) { |
+ resolver->reject(DOMException::create(SecurityError, "Can only unregister for scopes in the document's origin.")); |
+ return promise; |
+ } |
+ |
+ m_provider->unregisterServiceWorker(scopeURL, new CallbackPromiseAdapter<UndefinedValue, ServiceWorkerError>(resolver)); |
+ return promise; |
+} |
+ |
+PassRefPtrWillBeRawPtr<ServiceWorkerRegistration> ServiceWorkerRegistration::create(ExecutionContext* executionContext, PassOwnPtr<blink::WebServiceWorkerRegistration> outerRegistration) |
tkent
2014/07/25 07:50:24
Remove blink::
nhiroki
2014/07/25 08:28:56
Done.
|
+{ |
+ RefPtrWillBeRawPtr<ServiceWorkerRegistration> registration = adoptRefWillBeRefCountedGarbageCollected(new ServiceWorkerRegistration(executionContext, outerRegistration)); |
+ registration->suspendIfNeeded(); |
+ return registration.release(); |
+} |
+ |
+ServiceWorkerRegistration::ServiceWorkerRegistration(ExecutionContext* executionContext, PassOwnPtr<blink::WebServiceWorkerRegistration> outerRegistration) |
tkent
2014/07/25 07:50:24
Remove blink::
nhiroki
2014/07/25 08:28:56
Done.
|
+ : ActiveDOMObject(executionContext) |
+ , m_outerRegistration(outerRegistration) |
+ , m_provider(0) |
+{ |
+ ASSERT(m_outerRegistration); |
+ ScriptWrappable::init(this); |
+ |
+ if (!executionContext) |
+ return; |
+ if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::from(executionContext)) |
+ m_provider = client->provider(); |
+} |
+ |
+} // namespace blink |