| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 #include "public/platform/WebServiceWorkerRegistration.h" | 55 #include "public/platform/WebServiceWorkerRegistration.h" |
| 56 #include "public/platform/WebString.h" | 56 #include "public/platform/WebString.h" |
| 57 #include "public/platform/WebURL.h" | 57 #include "public/platform/WebURL.h" |
| 58 | 58 |
| 59 namespace blink { | 59 namespace blink { |
| 60 | 60 |
| 61 // This wraps CallbackPromiseAdapter and resolves the promise with undefined | 61 // This wraps CallbackPromiseAdapter and resolves the promise with undefined |
| 62 // when nullptr is given to onSuccess. | 62 // when nullptr is given to onSuccess. |
| 63 class GetRegistrationCallback : public WebServiceWorkerProvider::WebServiceWorke
rGetRegistrationCallbacks { | 63 class GetRegistrationCallback : public WebServiceWorkerProvider::WebServiceWorke
rGetRegistrationCallbacks { |
| 64 public: | 64 public: |
| 65 explicit GetRegistrationCallback(PassRefPtr<ScriptPromiseResolver> resolver) | 65 explicit GetRegistrationCallback(PassRefPtrWillBeRawPtr<ScriptPromiseResolve
r> resolver) |
| 66 : m_resolver(resolver) | 66 : m_resolver(resolver) |
| 67 , m_adapter(m_resolver) { } | 67 , m_adapter(m_resolver) { } |
| 68 virtual ~GetRegistrationCallback() { } | 68 virtual ~GetRegistrationCallback() { } |
| 69 virtual void onSuccess(WebServiceWorkerRegistration* registration) override | 69 virtual void onSuccess(WebServiceWorkerRegistration* registration) override |
| 70 { | 70 { |
| 71 if (registration) | 71 if (registration) |
| 72 m_adapter.onSuccess(registration); | 72 m_adapter.onSuccess(registration); |
| 73 else if (m_resolver->executionContext() && !m_resolver->executionContext
()->activeDOMObjectsAreStopped()) | 73 else if (m_resolver->executionContext() && !m_resolver->executionContext
()->activeDOMObjectsAreStopped()) |
| 74 m_resolver->resolve(); | 74 m_resolver->resolve(); |
| 75 } | 75 } |
| 76 virtual void onError(WebServiceWorkerError* error) override { m_adapter.onEr
ror(error); } | 76 virtual void onError(WebServiceWorkerError* error) override { m_adapter.onEr
ror(error); } |
| 77 private: | 77 private: |
| 78 RefPtr<ScriptPromiseResolver> m_resolver; | 78 RefPtrWillBePersistent<ScriptPromiseResolver> m_resolver; |
| 79 CallbackPromiseAdapter<ServiceWorkerRegistration, ServiceWorkerError> m_adap
ter; | 79 CallbackPromiseAdapter<ServiceWorkerRegistration, ServiceWorkerError> m_adap
ter; |
| 80 WTF_MAKE_NONCOPYABLE(GetRegistrationCallback); | 80 WTF_MAKE_NONCOPYABLE(GetRegistrationCallback); |
| 81 }; | 81 }; |
| 82 | 82 |
| 83 ServiceWorkerContainer* ServiceWorkerContainer::create(ExecutionContext* executi
onContext) | 83 ServiceWorkerContainer* ServiceWorkerContainer::create(ExecutionContext* executi
onContext) |
| 84 { | 84 { |
| 85 return new ServiceWorkerContainer(executionContext); | 85 return new ServiceWorkerContainer(executionContext); |
| 86 } | 86 } |
| 87 | 87 |
| 88 ServiceWorkerContainer::~ServiceWorkerContainer() | 88 ServiceWorkerContainer::~ServiceWorkerContainer() |
| (...skipping 13 matching lines...) Expand all Loading... |
| 102 { | 102 { |
| 103 visitor->trace(m_controller); | 103 visitor->trace(m_controller); |
| 104 visitor->trace(m_readyRegistration); | 104 visitor->trace(m_readyRegistration); |
| 105 visitor->trace(m_ready); | 105 visitor->trace(m_ready); |
| 106 EventTargetWithInlineData::trace(visitor); | 106 EventTargetWithInlineData::trace(visitor); |
| 107 } | 107 } |
| 108 | 108 |
| 109 ScriptPromise ServiceWorkerContainer::registerServiceWorker(ScriptState* scriptS
tate, const String& url, const RegistrationOptions& options) | 109 ScriptPromise ServiceWorkerContainer::registerServiceWorker(ScriptState* scriptS
tate, const String& url, const RegistrationOptions& options) |
| 110 { | 110 { |
| 111 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); | 111 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); |
| 112 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); | 112 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); |
| 113 ScriptPromise promise = resolver->promise(); | 113 ScriptPromise promise = resolver->promise(); |
| 114 | 114 |
| 115 if (!m_provider) { | 115 if (!m_provider) { |
| 116 resolver->reject(DOMException::create(InvalidStateError, "The document i
s in an invalid state.")); | 116 resolver->reject(DOMException::create(InvalidStateError, "The document i
s in an invalid state.")); |
| 117 return promise; | 117 return promise; |
| 118 } | 118 } |
| 119 | 119 |
| 120 // FIXME: This should use the container's execution context, not | 120 // FIXME: This should use the container's execution context, not |
| 121 // the callers. | 121 // the callers. |
| 122 ExecutionContext* executionContext = scriptState->executionContext(); | 122 ExecutionContext* executionContext = scriptState->executionContext(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 } | 166 } |
| 167 static void dispose(WebType* boolean) { } | 167 static void dispose(WebType* boolean) { } |
| 168 | 168 |
| 169 private: | 169 private: |
| 170 BooleanValue(); | 170 BooleanValue(); |
| 171 }; | 171 }; |
| 172 | 172 |
| 173 ScriptPromise ServiceWorkerContainer::getRegistration(ScriptState* scriptState,
const String& documentURL) | 173 ScriptPromise ServiceWorkerContainer::getRegistration(ScriptState* scriptState,
const String& documentURL) |
| 174 { | 174 { |
| 175 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); | 175 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); |
| 176 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); | 176 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); |
| 177 ScriptPromise promise = resolver->promise(); | 177 ScriptPromise promise = resolver->promise(); |
| 178 | 178 |
| 179 if (!m_provider) { | 179 if (!m_provider) { |
| 180 resolver->reject(DOMException::create(InvalidStateError, "The document i
s in an invalid state.")); | 180 resolver->reject(DOMException::create(InvalidStateError, "The document i
s in an invalid state.")); |
| 181 return promise; | 181 return promise; |
| 182 } | 182 } |
| 183 | 183 |
| 184 // FIXME: This should use the container's execution context, not | 184 // FIXME: This should use the container's execution context, not |
| 185 // the callers. | 185 // the callers. |
| 186 ExecutionContext* executionContext = scriptState->executionContext(); | 186 ExecutionContext* executionContext = scriptState->executionContext(); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 m_ready = createReadyProperty(); | 312 m_ready = createReadyProperty(); |
| 313 | 313 |
| 314 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { | 314 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { |
| 315 m_provider = client->provider(); | 315 m_provider = client->provider(); |
| 316 if (m_provider) | 316 if (m_provider) |
| 317 m_provider->setClient(this); | 317 m_provider->setClient(this); |
| 318 } | 318 } |
| 319 } | 319 } |
| 320 | 320 |
| 321 } // namespace blink | 321 } // namespace blink |
| OLD | NEW |