| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 #include "public/platform/WebServiceWorker.h" | 52 #include "public/platform/WebServiceWorker.h" |
| 53 #include "public/platform/WebServiceWorkerProvider.h" | 53 #include "public/platform/WebServiceWorkerProvider.h" |
| 54 #include "public/platform/WebServiceWorkerRegistration.h" | 54 #include "public/platform/WebServiceWorkerRegistration.h" |
| 55 #include "public/platform/WebString.h" | 55 #include "public/platform/WebString.h" |
| 56 #include "public/platform/WebURL.h" | 56 #include "public/platform/WebURL.h" |
| 57 | 57 |
| 58 namespace blink { | 58 namespace blink { |
| 59 | 59 |
| 60 class RegistrationCallback : public WebServiceWorkerProvider::WebServiceWorkerRe
gistrationCallbacks { | 60 class RegistrationCallback : public WebServiceWorkerProvider::WebServiceWorkerRe
gistrationCallbacks { |
| 61 public: | 61 public: |
| 62 explicit RegistrationCallback(PassRefPtrWillBeRawPtr<ScriptPromiseResolver>
resolver) | 62 explicit RegistrationCallback(ScriptPromiseResolver* resolver) |
| 63 : m_resolver(resolver) { } | 63 : m_resolver(resolver) { } |
| 64 ~RegistrationCallback() override { } | 64 ~RegistrationCallback() override { } |
| 65 | 65 |
| 66 void onSuccess(WebServiceWorkerRegistration* registration) override | 66 void onSuccess(WebServiceWorkerRegistration* registration) override |
| 67 { | 67 { |
| 68 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) | 68 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) |
| 69 return; | 69 return; |
| 70 m_resolver->resolve(ServiceWorkerRegistration::take(m_resolver.get(), re
gistration)); | 70 m_resolver->resolve(ServiceWorkerRegistration::take(m_resolver.get(), re
gistration)); |
| 71 } | 71 } |
| 72 | 72 |
| 73 // Takes ownership of |errorRaw|. | 73 // Takes ownership of |errorRaw|. |
| 74 void onError(WebServiceWorkerError* errorRaw) override | 74 void onError(WebServiceWorkerError* errorRaw) override |
| 75 { | 75 { |
| 76 OwnPtr<WebServiceWorkerError> error = adoptPtr(errorRaw); | 76 OwnPtr<WebServiceWorkerError> error = adoptPtr(errorRaw); |
| 77 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) | 77 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) |
| 78 return; | 78 return; |
| 79 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), error.rele
ase())); | 79 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), error.rele
ase())); |
| 80 } | 80 } |
| 81 | 81 |
| 82 private: | 82 private: |
| 83 RefPtrWillBePersistent<ScriptPromiseResolver> m_resolver; | 83 Persistent<ScriptPromiseResolver> m_resolver; |
| 84 WTF_MAKE_NONCOPYABLE(RegistrationCallback); | 84 WTF_MAKE_NONCOPYABLE(RegistrationCallback); |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 class GetRegistrationCallback : public WebServiceWorkerProvider::WebServiceWorke
rGetRegistrationCallbacks { | 87 class GetRegistrationCallback : public WebServiceWorkerProvider::WebServiceWorke
rGetRegistrationCallbacks { |
| 88 public: | 88 public: |
| 89 explicit GetRegistrationCallback(PassRefPtrWillBeRawPtr<ScriptPromiseResolve
r> resolver) | 89 explicit GetRegistrationCallback(ScriptPromiseResolver* resolver) |
| 90 : m_resolver(resolver) { } | 90 : m_resolver(resolver) { } |
| 91 ~GetRegistrationCallback() override { } | 91 ~GetRegistrationCallback() override { } |
| 92 | 92 |
| 93 void onSuccess(WebServiceWorkerRegistration* registration) override | 93 void onSuccess(WebServiceWorkerRegistration* registration) override |
| 94 { | 94 { |
| 95 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) | 95 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) |
| 96 return; | 96 return; |
| 97 if (!registration) { | 97 if (!registration) { |
| 98 // Resolve the promise with undefined. | 98 // Resolve the promise with undefined. |
| 99 m_resolver->resolve(); | 99 m_resolver->resolve(); |
| 100 return; | 100 return; |
| 101 } | 101 } |
| 102 m_resolver->resolve(ServiceWorkerRegistration::take(m_resolver.get(), re
gistration)); | 102 m_resolver->resolve(ServiceWorkerRegistration::take(m_resolver.get(), re
gistration)); |
| 103 } | 103 } |
| 104 | 104 |
| 105 // Takes ownership of |errorRaw|. | 105 // Takes ownership of |errorRaw|. |
| 106 void onError(WebServiceWorkerError* errorRaw) override | 106 void onError(WebServiceWorkerError* errorRaw) override |
| 107 { | 107 { |
| 108 OwnPtr<WebServiceWorkerError> error = adoptPtr(errorRaw); | 108 OwnPtr<WebServiceWorkerError> error = adoptPtr(errorRaw); |
| 109 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) | 109 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) |
| 110 return; | 110 return; |
| 111 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), error.rele
ase())); | 111 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), error.rele
ase())); |
| 112 } | 112 } |
| 113 | 113 |
| 114 private: | 114 private: |
| 115 RefPtrWillBePersistent<ScriptPromiseResolver> m_resolver; | 115 Persistent<ScriptPromiseResolver> m_resolver; |
| 116 WTF_MAKE_NONCOPYABLE(GetRegistrationCallback); | 116 WTF_MAKE_NONCOPYABLE(GetRegistrationCallback); |
| 117 }; | 117 }; |
| 118 | 118 |
| 119 class GetRegistrationsCallback : public WebServiceWorkerProvider::WebServiceWork
erGetRegistrationsCallbacks { | 119 class GetRegistrationsCallback : public WebServiceWorkerProvider::WebServiceWork
erGetRegistrationsCallbacks { |
| 120 public: | 120 public: |
| 121 explicit GetRegistrationsCallback(PassRefPtrWillBeRawPtr<ScriptPromiseResolv
er> resolver) | 121 explicit GetRegistrationsCallback(ScriptPromiseResolver* resolver) |
| 122 : m_resolver(resolver) { } | 122 : m_resolver(resolver) { } |
| 123 ~GetRegistrationsCallback() override { } | 123 ~GetRegistrationsCallback() override { } |
| 124 | 124 |
| 125 // Takes ownership of |registrationsRaw|. | 125 // Takes ownership of |registrationsRaw|. |
| 126 void onSuccess(WebVector<WebServiceWorkerRegistration*>* registrationsRaw) o
verride | 126 void onSuccess(WebVector<WebServiceWorkerRegistration*>* registrationsRaw) o
verride |
| 127 { | 127 { |
| 128 OwnPtr<WebVector<WebServiceWorkerRegistration*>> registrations = adoptPt
r(registrationsRaw); | 128 OwnPtr<WebVector<WebServiceWorkerRegistration*>> registrations = adoptPt
r(registrationsRaw); |
| 129 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) | 129 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) |
| 130 return; | 130 return; |
| 131 m_resolver->resolve(ServiceWorkerRegistrationArray::take(m_resolver.get(
), registrations.release())); | 131 m_resolver->resolve(ServiceWorkerRegistrationArray::take(m_resolver.get(
), registrations.release())); |
| 132 } | 132 } |
| 133 | 133 |
| 134 // Takes ownership of |errorRaw|. | 134 // Takes ownership of |errorRaw|. |
| 135 void onError(WebServiceWorkerError* errorRaw) override | 135 void onError(WebServiceWorkerError* errorRaw) override |
| 136 { | 136 { |
| 137 OwnPtr<WebServiceWorkerError> error = adoptPtr(errorRaw); | 137 OwnPtr<WebServiceWorkerError> error = adoptPtr(errorRaw); |
| 138 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) | 138 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) |
| 139 return; | 139 return; |
| 140 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), error.rele
ase())); | 140 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), error.rele
ase())); |
| 141 } | 141 } |
| 142 | 142 |
| 143 private: | 143 private: |
| 144 RefPtrWillBePersistent<ScriptPromiseResolver> m_resolver; | 144 Persistent<ScriptPromiseResolver> m_resolver; |
| 145 WTF_MAKE_NONCOPYABLE(GetRegistrationsCallback); | 145 WTF_MAKE_NONCOPYABLE(GetRegistrationsCallback); |
| 146 }; | 146 }; |
| 147 | 147 |
| 148 class ServiceWorkerContainer::GetRegistrationForReadyCallback : public WebServic
eWorkerProvider::WebServiceWorkerGetRegistrationForReadyCallbacks { | 148 class ServiceWorkerContainer::GetRegistrationForReadyCallback : public WebServic
eWorkerProvider::WebServiceWorkerGetRegistrationForReadyCallbacks { |
| 149 public: | 149 public: |
| 150 explicit GetRegistrationForReadyCallback(ReadyProperty* ready) | 150 explicit GetRegistrationForReadyCallback(ReadyProperty* ready) |
| 151 : m_ready(ready) { } | 151 : m_ready(ready) { } |
| 152 ~GetRegistrationForReadyCallback() { } | 152 ~GetRegistrationForReadyCallback() { } |
| 153 void onSuccess(WebServiceWorkerRegistration* registration) override | 153 void onSuccess(WebServiceWorkerRegistration* registration) override |
| 154 { | 154 { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 183 DEFINE_TRACE(ServiceWorkerContainer) | 183 DEFINE_TRACE(ServiceWorkerContainer) |
| 184 { | 184 { |
| 185 visitor->trace(m_controller); | 185 visitor->trace(m_controller); |
| 186 visitor->trace(m_ready); | 186 visitor->trace(m_ready); |
| 187 RefCountedGarbageCollectedEventTargetWithInlineData<ServiceWorkerContainer>:
:trace(visitor); | 187 RefCountedGarbageCollectedEventTargetWithInlineData<ServiceWorkerContainer>:
:trace(visitor); |
| 188 ContextLifecycleObserver::trace(visitor); | 188 ContextLifecycleObserver::trace(visitor); |
| 189 } | 189 } |
| 190 | 190 |
| 191 ScriptPromise ServiceWorkerContainer::registerServiceWorker(ScriptState* scriptS
tate, const String& url, const RegistrationOptions& options) | 191 ScriptPromise ServiceWorkerContainer::registerServiceWorker(ScriptState* scriptS
tate, const String& url, const RegistrationOptions& options) |
| 192 { | 192 { |
| 193 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); | 193 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 194 ScriptPromise promise = resolver->promise(); | 194 ScriptPromise promise = resolver->promise(); |
| 195 | 195 |
| 196 if (!m_provider) { | 196 if (!m_provider) { |
| 197 resolver->reject(DOMException::create(InvalidStateError, "Failed to regi
ster a ServiceWorker: The document is in an invalid state.")); | 197 resolver->reject(DOMException::create(InvalidStateError, "Failed to regi
ster a ServiceWorker: The document is in an invalid state.")); |
| 198 return promise; | 198 return promise; |
| 199 } | 199 } |
| 200 | 200 |
| 201 ExecutionContext* executionContext = scriptState->executionContext(); | 201 ExecutionContext* executionContext = scriptState->executionContext(); |
| 202 // FIXME: May be null due to worker termination: http://crbug.com/413518. | 202 // FIXME: May be null due to worker termination: http://crbug.com/413518. |
| 203 if (!executionContext) | 203 if (!executionContext) |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 return promise; | 246 return promise; |
| 247 } | 247 } |
| 248 | 248 |
| 249 m_provider->registerServiceWorker(patternURL, scriptURL, new RegistrationCal
lback(resolver)); | 249 m_provider->registerServiceWorker(patternURL, scriptURL, new RegistrationCal
lback(resolver)); |
| 250 | 250 |
| 251 return promise; | 251 return promise; |
| 252 } | 252 } |
| 253 | 253 |
| 254 ScriptPromise ServiceWorkerContainer::getRegistration(ScriptState* scriptState,
const String& documentURL) | 254 ScriptPromise ServiceWorkerContainer::getRegistration(ScriptState* scriptState,
const String& documentURL) |
| 255 { | 255 { |
| 256 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); | 256 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 257 ScriptPromise promise = resolver->promise(); | 257 ScriptPromise promise = resolver->promise(); |
| 258 | 258 |
| 259 if (!m_provider) { | 259 if (!m_provider) { |
| 260 resolver->reject(DOMException::create(InvalidStateError, "Failed to get
a ServiceWorkerRegistration: The document is in an invalid state.")); | 260 resolver->reject(DOMException::create(InvalidStateError, "Failed to get
a ServiceWorkerRegistration: The document is in an invalid state.")); |
| 261 return promise; | 261 return promise; |
| 262 } | 262 } |
| 263 | 263 |
| 264 ExecutionContext* executionContext = scriptState->executionContext(); | 264 ExecutionContext* executionContext = scriptState->executionContext(); |
| 265 // FIXME: May be null due to worker termination: http://crbug.com/413518. | 265 // FIXME: May be null due to worker termination: http://crbug.com/413518. |
| 266 if (!executionContext) | 266 if (!executionContext) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 286 resolver->reject(DOMException::create(SecurityError, "Failed to get a Se
rviceWorkerRegistration: The origin of the provided documentURL ('" + documentUR
LOrigin->toString() + "') does not match the current origin ('" + documentOrigin
->toString() + "').")); | 286 resolver->reject(DOMException::create(SecurityError, "Failed to get a Se
rviceWorkerRegistration: The origin of the provided documentURL ('" + documentUR
LOrigin->toString() + "') does not match the current origin ('" + documentOrigin
->toString() + "').")); |
| 287 return promise; | 287 return promise; |
| 288 } | 288 } |
| 289 m_provider->getRegistration(completedURL, new GetRegistrationCallback(resolv
er)); | 289 m_provider->getRegistration(completedURL, new GetRegistrationCallback(resolv
er)); |
| 290 | 290 |
| 291 return promise; | 291 return promise; |
| 292 } | 292 } |
| 293 | 293 |
| 294 ScriptPromise ServiceWorkerContainer::getRegistrations(ScriptState* scriptState) | 294 ScriptPromise ServiceWorkerContainer::getRegistrations(ScriptState* scriptState) |
| 295 { | 295 { |
| 296 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); | 296 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 297 ScriptPromise promise = resolver->promise(); | 297 ScriptPromise promise = resolver->promise(); |
| 298 | 298 |
| 299 if (!m_provider) { | 299 if (!m_provider) { |
| 300 resolver->reject(DOMException::create(InvalidStateError, "Failed to get
ServiceWorkerRegistration objects: The document is in an invalid state.")); | 300 resolver->reject(DOMException::create(InvalidStateError, "Failed to get
ServiceWorkerRegistration objects: The document is in an invalid state.")); |
| 301 return promise; | 301 return promise; |
| 302 } | 302 } |
| 303 | 303 |
| 304 ExecutionContext* executionContext = scriptState->executionContext(); | 304 ExecutionContext* executionContext = scriptState->executionContext(); |
| 305 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); | 305 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); |
| 306 String errorMessage; | 306 String errorMessage; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 return; | 390 return; |
| 391 | 391 |
| 392 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { | 392 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { |
| 393 m_provider = client->provider(); | 393 m_provider = client->provider(); |
| 394 if (m_provider) | 394 if (m_provider) |
| 395 m_provider->setClient(this); | 395 m_provider->setClient(this); |
| 396 } | 396 } |
| 397 } | 397 } |
| 398 | 398 |
| 399 } // namespace blink | 399 } // namespace blink |
| OLD | NEW |