| 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 |
| 23 class UndefinedValue { | 24 class UndefinedValue { |
| 24 public: | 25 public: |
| 25 typedef WebServiceWorkerRegistration WebType; | 26 typedef WebServiceWorkerRegistration WebType; |
| 26 static V8UndefinedType take(ScriptPromiseResolver* resolver, WebType* regist
ration) | 27 static V8UndefinedType take(ScriptPromiseResolver* resolver, WebType* regist
ration) |
| 27 { | 28 { |
| 28 ASSERT(!registration); // Anything passed here will be leaked. | 29 ASSERT(!registration); // Anything passed here will be leaked. |
| 29 return V8UndefinedType(); | 30 return V8UndefinedType(); |
| 30 } | 31 } |
| 31 static void dispose(WebType* registration) | 32 static void dispose(WebType* registration) |
| 32 { | 33 { |
| 33 ASSERT(!registration); // Anything passed here will be leaked. | 34 ASSERT(!registration); // Anything passed here will be leaked. |
| 34 } | 35 } |
| 35 | 36 |
| 36 private: | 37 private: |
| 37 UndefinedValue(); | 38 UndefinedValue(); |
| 38 }; | 39 }; |
| 40 #else |
| 41 class BooleanValue { |
| 42 public: |
| 43 typedef bool WebType; |
| 44 static bool take(ScriptPromiseResolver* resolver, WebType* boolean) |
| 45 { |
| 46 return *boolean; |
| 47 } |
| 48 static void dispose(WebType* boolean) { } |
| 49 |
| 50 private: |
| 51 BooleanValue(); |
| 52 }; |
| 53 #endif |
| 39 | 54 |
| 40 static void deleteIfNoExistingOwner(WebServiceWorker* serviceWorker) | 55 static void deleteIfNoExistingOwner(WebServiceWorker* serviceWorker) |
| 41 { | 56 { |
| 42 if (serviceWorker && !serviceWorker->proxy()) | 57 if (serviceWorker && !serviceWorker->proxy()) |
| 43 delete serviceWorker; | 58 delete serviceWorker; |
| 44 } | 59 } |
| 45 | 60 |
| 46 const AtomicString& ServiceWorkerRegistration::interfaceName() const | 61 const AtomicString& ServiceWorkerRegistration::interfaceName() const |
| 47 { | 62 { |
| 48 return EventTargetNames::ServiceWorkerRegistration; | 63 return EventTargetNames::ServiceWorkerRegistration; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 } | 123 } |
| 109 | 124 |
| 110 RefPtr<SecurityOrigin> documentOrigin = scriptState->executionContext()->sec
urityOrigin(); | 125 RefPtr<SecurityOrigin> documentOrigin = scriptState->executionContext()->sec
urityOrigin(); |
| 111 KURL scopeURL = scriptState->executionContext()->completeURL(scope()); | 126 KURL scopeURL = scriptState->executionContext()->completeURL(scope()); |
| 112 scopeURL.removeFragmentIdentifier(); | 127 scopeURL.removeFragmentIdentifier(); |
| 113 if (!scope().isEmpty() && !documentOrigin->canRequest(scopeURL)) { | 128 if (!scope().isEmpty() && !documentOrigin->canRequest(scopeURL)) { |
| 114 resolver->reject(DOMException::create(SecurityError, "Can only unregiste
r for scopes in the document's origin.")); | 129 resolver->reject(DOMException::create(SecurityError, "Can only unregiste
r for scopes in the document's origin.")); |
| 115 return promise; | 130 return promise; |
| 116 } | 131 } |
| 117 | 132 |
| 133 #ifdef DISABLE_SERVICEWORKER_UNREGISTER_RESOLVE_TO_BOOLEAN |
| 118 m_provider->unregisterServiceWorker(scopeURL, new CallbackPromiseAdapter<Und
efinedValue, ServiceWorkerError>(resolver)); | 134 m_provider->unregisterServiceWorker(scopeURL, new CallbackPromiseAdapter<Und
efinedValue, ServiceWorkerError>(resolver)); |
| 135 #else |
| 136 m_provider->unregisterServiceWorker(scopeURL, new CallbackPromiseAdapter<Boo
leanValue, ServiceWorkerError>(resolver)); |
| 137 #endif |
| 119 return promise; | 138 return promise; |
| 120 } | 139 } |
| 121 | 140 |
| 122 PassRefPtrWillBeRawPtr<ServiceWorkerRegistration> ServiceWorkerRegistration::get
OrCreate(ExecutionContext* executionContext, WebServiceWorkerRegistration* outer
Registration) | 141 PassRefPtrWillBeRawPtr<ServiceWorkerRegistration> ServiceWorkerRegistration::get
OrCreate(ExecutionContext* executionContext, WebServiceWorkerRegistration* outer
Registration) |
| 123 { | 142 { |
| 124 if (!outerRegistration) | 143 if (!outerRegistration) |
| 125 return nullptr; | 144 return nullptr; |
| 126 | 145 |
| 127 WebServiceWorkerRegistrationProxy* proxy = outerRegistration->proxy(); | 146 WebServiceWorkerRegistrationProxy* proxy = outerRegistration->proxy(); |
| 128 if (proxy) { | 147 if (proxy) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 189 |
| 171 void ServiceWorkerRegistration::stop() | 190 void ServiceWorkerRegistration::stop() |
| 172 { | 191 { |
| 173 if (m_stopped) | 192 if (m_stopped) |
| 174 return; | 193 return; |
| 175 m_stopped = true; | 194 m_stopped = true; |
| 176 m_outerRegistration->proxyStopped(); | 195 m_outerRegistration->proxyStopped(); |
| 177 } | 196 } |
| 178 | 197 |
| 179 } // namespace blink | 198 } // namespace blink |
| OLD | NEW |