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