OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "ServiceWorkerRegistration.h" | 6 #include "ServiceWorkerRegistration.h" |
7 | 7 |
8 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 8 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
9 #include "bindings/core/v8/ScriptPromise.h" | 9 #include "bindings/core/v8/ScriptPromise.h" |
10 #include "bindings/core/v8/ScriptPromiseResolver.h" | 10 #include "bindings/core/v8/ScriptPromiseResolver.h" |
11 #include "bindings/core/v8/ScriptState.h" | 11 #include "bindings/core/v8/ScriptState.h" |
12 #include "core/dom/DOMException.h" | 12 #include "core/dom/DOMException.h" |
13 #include "core/dom/ExceptionCode.h" | 13 #include "core/dom/ExceptionCode.h" |
14 #include "core/dom/ExecutionContext.h" | 14 #include "core/dom/ExecutionContext.h" |
15 #include "core/events/Event.h" | 15 #include "core/events/Event.h" |
16 #include "modules/EventTargetModules.h" | 16 #include "modules/EventTargetModules.h" |
17 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" | 17 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" |
18 #include "modules/serviceworkers/ServiceWorkerError.h" | 18 #include "modules/serviceworkers/ServiceWorkerError.h" |
19 #include "public/platform/WebServiceWorkerProvider.h" | 19 #include "public/platform/WebServiceWorkerProvider.h" |
20 | 20 |
21 namespace blink { | 21 namespace blink { |
22 | 22 |
23 #ifdef DISABLE_SERVICEWORKER_UNREGISTER_RESOLVE_TO_BOOLEAN | |
24 class UndefinedValue { | |
25 public: | |
26 typedef WebServiceWorkerRegistration WebType; | |
27 static V8UndefinedType take(ScriptPromiseResolver* resolver, WebType* regist
ration) | |
28 { | |
29 ASSERT(!registration); // Anything passed here will be leaked. | |
30 return V8UndefinedType(); | |
31 } | |
32 static void dispose(WebType* registration) | |
33 { | |
34 ASSERT(!registration); // Anything passed here will be leaked. | |
35 } | |
36 | |
37 private: | |
38 UndefinedValue(); | |
39 }; | |
40 #else | |
41 class BooleanValue { | 23 class BooleanValue { |
42 public: | 24 public: |
43 typedef bool WebType; | 25 typedef bool WebType; |
44 static bool take(ScriptPromiseResolver* resolver, WebType* boolean) | 26 static bool take(ScriptPromiseResolver* resolver, WebType* boolean) |
45 { | 27 { |
46 return *boolean; | 28 return *boolean; |
47 } | 29 } |
48 static void dispose(WebType* boolean) { } | 30 static void dispose(WebType* boolean) { } |
49 | 31 |
50 private: | 32 private: |
51 BooleanValue(); | 33 BooleanValue(); |
52 }; | 34 }; |
53 #endif | |
54 | 35 |
55 static void deleteIfNoExistingOwner(WebServiceWorker* serviceWorker) | 36 static void deleteIfNoExistingOwner(WebServiceWorker* serviceWorker) |
56 { | 37 { |
57 if (serviceWorker && !serviceWorker->proxy()) | 38 if (serviceWorker && !serviceWorker->proxy()) |
58 delete serviceWorker; | 39 delete serviceWorker; |
59 } | 40 } |
60 | 41 |
61 const AtomicString& ServiceWorkerRegistration::interfaceName() const | 42 const AtomicString& ServiceWorkerRegistration::interfaceName() const |
62 { | 43 { |
63 return EventTargetNames::ServiceWorkerRegistration; | 44 return EventTargetNames::ServiceWorkerRegistration; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 } | 104 } |
124 | 105 |
125 RefPtr<SecurityOrigin> documentOrigin = scriptState->executionContext()->sec
urityOrigin(); | 106 RefPtr<SecurityOrigin> documentOrigin = scriptState->executionContext()->sec
urityOrigin(); |
126 KURL scopeURL = scriptState->executionContext()->completeURL(scope()); | 107 KURL scopeURL = scriptState->executionContext()->completeURL(scope()); |
127 scopeURL.removeFragmentIdentifier(); | 108 scopeURL.removeFragmentIdentifier(); |
128 if (!scope().isEmpty() && !documentOrigin->canRequest(scopeURL)) { | 109 if (!scope().isEmpty() && !documentOrigin->canRequest(scopeURL)) { |
129 resolver->reject(DOMException::create(SecurityError, "Can only unregiste
r for scopes in the document's origin.")); | 110 resolver->reject(DOMException::create(SecurityError, "Can only unregiste
r for scopes in the document's origin.")); |
130 return promise; | 111 return promise; |
131 } | 112 } |
132 | 113 |
133 #ifdef DISABLE_SERVICEWORKER_UNREGISTER_RESOLVE_TO_BOOLEAN | |
134 m_provider->unregisterServiceWorker(scopeURL, new CallbackPromiseAdapter<Und
efinedValue, ServiceWorkerError>(resolver)); | |
135 #else | |
136 m_provider->unregisterServiceWorker(scopeURL, new CallbackPromiseAdapter<Boo
leanValue, ServiceWorkerError>(resolver)); | 114 m_provider->unregisterServiceWorker(scopeURL, new CallbackPromiseAdapter<Boo
leanValue, ServiceWorkerError>(resolver)); |
137 #endif | |
138 return promise; | 115 return promise; |
139 } | 116 } |
140 | 117 |
141 PassRefPtrWillBeRawPtr<ServiceWorkerRegistration> ServiceWorkerRegistration::get
OrCreate(ExecutionContext* executionContext, WebServiceWorkerRegistration* outer
Registration) | 118 PassRefPtrWillBeRawPtr<ServiceWorkerRegistration> ServiceWorkerRegistration::get
OrCreate(ExecutionContext* executionContext, WebServiceWorkerRegistration* outer
Registration) |
142 { | 119 { |
143 if (!outerRegistration) | 120 if (!outerRegistration) |
144 return nullptr; | 121 return nullptr; |
145 | 122 |
146 WebServiceWorkerRegistrationProxy* proxy = outerRegistration->proxy(); | 123 WebServiceWorkerRegistrationProxy* proxy = outerRegistration->proxy(); |
147 if (proxy) { | 124 if (proxy) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 | 166 |
190 void ServiceWorkerRegistration::stop() | 167 void ServiceWorkerRegistration::stop() |
191 { | 168 { |
192 if (m_stopped) | 169 if (m_stopped) |
193 return; | 170 return; |
194 m_stopped = true; | 171 m_stopped = true; |
195 m_outerRegistration->proxyStopped(); | 172 m_outerRegistration->proxyStopped(); |
196 } | 173 } |
197 | 174 |
198 } // namespace blink | 175 } // namespace blink |
OLD | NEW |