Chromium Code Reviews| 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 "modules/serviceworkers/ServiceWorkerRegistration.h" | 5 #include "modules/serviceworkers/ServiceWorkerRegistration.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 7 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
| 8 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
| 9 #include "bindings/core/v8/ScriptState.h" | 9 #include "bindings/core/v8/ScriptState.h" |
| 10 #include "core/dom/DOMException.h" | 10 #include "core/dom/DOMException.h" |
| 11 #include "core/dom/ExceptionCode.h" | 11 #include "core/dom/ExceptionCode.h" |
| 12 #include "core/dom/ExecutionContext.h" | 12 #include "core/dom/ExecutionContext.h" |
| 13 #include "core/events/Event.h" | 13 #include "core/events/Event.h" |
| 14 #include "modules/EventTargetModules.h" | 14 #include "modules/EventTargetModules.h" |
| 15 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" | 15 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" |
| 16 #include "modules/serviceworkers/ServiceWorkerError.h" | 16 #include "modules/serviceworkers/ServiceWorkerError.h" |
| 17 #include "public/platform/modules/serviceworker/WebServiceWorkerProvider.h" | 17 #include "public/platform/modules/serviceworker/WebServiceWorkerProvider.h" |
| 18 | 18 |
| 19 namespace blink { | 19 namespace blink { |
| 20 | 20 |
| 21 namespace { | |
| 22 | |
| 23 class UpdateCallbacks : public WebServiceWorkerRegistration::WebServiceWorkerUpd ateCallbacks { | |
| 24 public: | |
| 25 explicit UpdateCallbacks(ScriptPromiseResolver* resolver) | |
| 26 : m_resolver(resolver) {} | |
| 27 | |
| 28 ~UpdateCallbacks() override {} | |
| 29 | |
| 30 void onSuccess() override | |
| 31 { | |
| 32 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex t()->activeDOMObjectsAreStopped()) | |
| 33 return; | |
| 34 m_resolver->resolve(); | |
| 35 } | |
| 36 | |
| 37 void onError(const WebServiceWorkerError& error) override | |
| 38 { | |
| 39 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex t()->activeDOMObjectsAreStopped()) | |
| 40 return; | |
| 41 switch (error.errorType) { | |
| 42 case WebServiceWorkerError::ErrorTypeNetwork: | |
| 43 case WebServiceWorkerError::ErrorTypeScriptEvaluateFailed: | |
| 44 case WebServiceWorkerError::ErrorTypeType: { | |
|
falken
2016/06/14 02:27:53
Can you explain why are network, script evaluate,
e_hakkinen
2016/06/16 20:55:14
ServiceWorkerError::take returns a DOMException wh
falken
2016/06/17 02:12:14
I see. Looks like that changed here:
https://githu
e_hakkinen
2016/06/17 12:29:18
Yes, but that tests the register code path and not
| |
| 45 ScriptState* scriptState = m_resolver->getScriptState(); | |
| 46 ScriptState::Scope scope(scriptState); | |
| 47 m_resolver->reject(V8ThrowException::createTypeError(scriptState->is olate(), error.message)); | |
| 48 break; | |
| 49 } | |
| 50 default: | |
| 51 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), error) ); | |
| 52 } | |
| 53 } | |
| 54 | |
| 55 private: | |
| 56 Persistent<ScriptPromiseResolver> m_resolver; | |
| 57 WTF_MAKE_NONCOPYABLE(UpdateCallbacks); | |
| 58 }; | |
| 59 | |
| 60 } // namespace | |
| 61 | |
| 21 const AtomicString& ServiceWorkerRegistration::interfaceName() const | 62 const AtomicString& ServiceWorkerRegistration::interfaceName() const |
| 22 { | 63 { |
| 23 return EventTargetNames::ServiceWorkerRegistration; | 64 return EventTargetNames::ServiceWorkerRegistration; |
| 24 } | 65 } |
| 25 | 66 |
| 26 void ServiceWorkerRegistration::dispatchUpdateFoundEvent() | 67 void ServiceWorkerRegistration::dispatchUpdateFoundEvent() |
| 27 { | 68 { |
| 28 dispatchEvent(Event::create(EventTypeNames::updatefound)); | 69 dispatchEvent(Event::create(EventTypeNames::updatefound)); |
| 29 } | 70 } |
| 30 | 71 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 } | 111 } |
| 71 | 112 |
| 72 ScriptPromise ServiceWorkerRegistration::update(ScriptState* scriptState) | 113 ScriptPromise ServiceWorkerRegistration::update(ScriptState* scriptState) |
| 73 { | 114 { |
| 74 ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::from(ge tExecutionContext()); | 115 ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::from(ge tExecutionContext()); |
| 75 if (!client || !client->provider()) | 116 if (!client || !client->provider()) |
| 76 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, "Failed to update a ServiceWorkerRegistration: No asso ciated provider is available.")); | 117 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, "Failed to update a ServiceWorkerRegistration: No asso ciated provider is available.")); |
| 77 | 118 |
| 78 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | 119 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; |
| 79 ScriptPromise promise = resolver->promise(); | 120 ScriptPromise promise = resolver->promise(); |
| 80 m_handle->registration()->update(client->provider(), new CallbackPromiseAdap ter<void, ServiceWorkerError>(resolver)); | 121 m_handle->registration()->update(client->provider(), new UpdateCallbacks(res olver)); |
| 81 return promise; | 122 return promise; |
| 82 } | 123 } |
| 83 | 124 |
| 84 ScriptPromise ServiceWorkerRegistration::unregister(ScriptState* scriptState) | 125 ScriptPromise ServiceWorkerRegistration::unregister(ScriptState* scriptState) |
| 85 { | 126 { |
| 86 ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::from(ge tExecutionContext()); | 127 ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::from(ge tExecutionContext()); |
| 87 if (!client || !client->provider()) | 128 if (!client || !client->provider()) |
| 88 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, "Failed to unregister a ServiceWorkerRegistration: No associated provider is available.")); | 129 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, "Failed to unregister a ServiceWorkerRegistration: No associated provider is available.")); |
| 89 | 130 |
| 90 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | 131 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 | 177 |
| 137 void ServiceWorkerRegistration::stop() | 178 void ServiceWorkerRegistration::stop() |
| 138 { | 179 { |
| 139 if (m_stopped) | 180 if (m_stopped) |
| 140 return; | 181 return; |
| 141 m_stopped = true; | 182 m_stopped = true; |
| 142 m_handle->registration()->proxyStopped(); | 183 m_handle->registration()->proxyStopped(); |
| 143 } | 184 } |
| 144 | 185 |
| 145 } // namespace blink | 186 } // namespace blink |
| OLD | NEW |