OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "config.h" | |
6 #include "ServiceWorkerRegistration.h" | |
7 | |
8 #include "bindings/core/v8/CallbackPromiseAdapter.h" | |
9 #include "bindings/core/v8/ScriptPromise.h" | |
10 #include "bindings/core/v8/ScriptPromiseResolver.h" | |
11 #include "bindings/core/v8/ScriptState.h" | |
12 #include "core/dom/DOMException.h" | |
13 #include "core/dom/ExceptionCode.h" | |
14 #include "core/dom/ExecutionContext.h" | |
15 #include "modules/EventTargetModules.h" | |
16 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" | |
17 #include "modules/serviceworkers/ServiceWorkerError.h" | |
18 #include "public/platform/WebServiceWorkerProvider.h" | |
19 | |
20 namespace blink { | |
21 | |
22 class UndefinedValue { | |
23 public: | |
24 #ifdef DISABLE_SERVICE_WORKER_REGISTRATION | |
25 typedef WebServiceWorker WebType; | |
26 #else | |
27 typedef WebServiceWorkerRegistration WebType; | |
28 #endif | |
29 static V8UndefinedType from(ScriptPromiseResolver* resolver, WebType* regist ration) | |
30 { | |
31 ASSERT(!registration); // Anything passed here will be leaked. | |
32 return V8UndefinedType(); | |
33 } | |
34 | |
35 private: | |
36 UndefinedValue(); | |
37 }; | |
38 | |
39 const AtomicString& ServiceWorkerRegistration::interfaceName() const | |
40 { | |
41 return EventTargetNames::ServiceWorkerRegistration; | |
42 } | |
43 | |
44 PassRefPtrWillBeRawPtr<ServiceWorkerRegistration> ServiceWorkerRegistration::fro m(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).
| |
45 { | |
46 if (!registration) | |
47 return nullptr; | |
48 return create(executionContext, adoptPtr(registration)); | |
49 } | |
50 | |
51 PassRefPtrWillBeRawPtr<ServiceWorkerRegistration> ServiceWorkerRegistration::fro m(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
| |
52 { | |
53 return ServiceWorkerRegistration::from(resolver->scriptState()->executionCon text(), registration); | |
54 } | |
55 | |
56 String ServiceWorkerRegistration::scope() const | |
57 { | |
58 return m_outerRegistration->scope().string(); | |
59 } | |
60 | |
61 ScriptPromise ServiceWorkerRegistration::unregister(ScriptState* scriptState) | |
62 { | |
63 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); | |
64 ScriptPromise promise = resolver->promise(); | |
65 | |
66 if (!m_provider) { | |
67 resolver->reject(DOMException::create(InvalidStateError, "No associated provider is available")); | |
68 return promise; | |
69 } | |
70 | |
71 RefPtr<SecurityOrigin> documentOrigin = scriptState->executionContext()->sec urityOrigin(); | |
72 KURL scopeURL = scriptState->executionContext()->completeURL(scope()); | |
73 scopeURL.removeFragmentIdentifier(); | |
74 if (!scope().isEmpty() && !documentOrigin->canRequest(scopeURL)) { | |
75 resolver->reject(DOMException::create(SecurityError, "Can only unregiste r for scopes in the document's origin.")); | |
76 return promise; | |
77 } | |
78 | |
79 m_provider->unregisterServiceWorker(scopeURL, new CallbackPromiseAdapter<Und efinedValue, ServiceWorkerError>(resolver)); | |
80 return promise; | |
81 } | |
82 | |
83 PassRefPtrWillBeRawPtr<ServiceWorkerRegistration> ServiceWorkerRegistration::cre ate(ExecutionContext* executionContext, PassOwnPtr<blink::WebServiceWorkerRegist ration> outerRegistration) | |
tkent
2014/07/25 07:50:24
Remove blink::
nhiroki
2014/07/25 08:28:56
Done.
| |
84 { | |
85 RefPtrWillBeRawPtr<ServiceWorkerRegistration> registration = adoptRefWillBeR efCountedGarbageCollected(new ServiceWorkerRegistration(executionContext, outerR egistration)); | |
86 registration->suspendIfNeeded(); | |
87 return registration.release(); | |
88 } | |
89 | |
90 ServiceWorkerRegistration::ServiceWorkerRegistration(ExecutionContext* execution Context, PassOwnPtr<blink::WebServiceWorkerRegistration> outerRegistration) | |
tkent
2014/07/25 07:50:24
Remove blink::
nhiroki
2014/07/25 08:28:56
Done.
| |
91 : ActiveDOMObject(executionContext) | |
92 , m_outerRegistration(outerRegistration) | |
93 , m_provider(0) | |
94 { | |
95 ASSERT(m_outerRegistration); | |
96 ScriptWrappable::init(this); | |
97 | |
98 if (!executionContext) | |
99 return; | |
100 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro m(executionContext)) | |
101 m_provider = client->provider(); | |
102 } | |
103 | |
104 } // namespace blink | |
OLD | NEW |