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 "modules/serviceworkers/RespondWithObserver.h" | 6 #include "modules/serviceworkers/RespondWithObserver.h" |
7 | 7 |
8 #include "bindings/core/v8/ScriptFunction.h" | 8 #include "bindings/core/v8/ScriptFunction.h" |
9 #include "bindings/core/v8/ScriptPromise.h" | 9 #include "bindings/core/v8/ScriptPromise.h" |
10 #include "bindings/core/v8/ScriptValue.h" | 10 #include "bindings/core/v8/ScriptValue.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 | 125 |
126 if (defaultPrevented) { | 126 if (defaultPrevented) { |
127 responseWasRejected(WebServiceWorkerResponseErrorDefaultPrevented); | 127 responseWasRejected(WebServiceWorkerResponseErrorDefaultPrevented); |
128 return; | 128 return; |
129 } | 129 } |
130 | 130 |
131 ServiceWorkerGlobalScopeClient::from(executionContext())->didHandleFetchEven
t(m_eventID); | 131 ServiceWorkerGlobalScopeClient::from(executionContext())->didHandleFetchEven
t(m_eventID); |
132 m_state = Done; | 132 m_state = Done; |
133 } | 133 } |
134 | 134 |
135 void RespondWithObserver::respondWith(ScriptState* scriptState, const ScriptValu
e& value, ExceptionState& exceptionState) | 135 void RespondWithObserver::respondWith(ScriptState* scriptState, ScriptPromise& s
criptPromise, ExceptionState& exceptionState) |
136 { | 136 { |
137 if (m_state != Initial) { | 137 if (m_state != Initial) { |
138 exceptionState.throwDOMException(InvalidStateError, "The fetch event has
already been responded to."); | 138 exceptionState.throwDOMException(InvalidStateError, "The fetch event has
already been responded to."); |
139 return; | 139 return; |
140 } | 140 } |
141 | 141 |
142 m_state = Pending; | 142 m_state = Pending; |
143 ScriptPromise::cast(scriptState, value).then( | 143 scriptPromise.then( |
144 ThenFunction::createFunction(scriptState, this, ThenFunction::Fulfilled)
, | 144 ThenFunction::createFunction(scriptState, this, ThenFunction::Fulfilled)
, |
145 ThenFunction::createFunction(scriptState, this, ThenFunction::Rejected))
; | 145 ThenFunction::createFunction(scriptState, this, ThenFunction::Rejected))
; |
146 } | 146 } |
147 | 147 |
148 void RespondWithObserver::responseWasRejected(WebServiceWorkerResponseError erro
r) | 148 void RespondWithObserver::responseWasRejected(WebServiceWorkerResponseError erro
r) |
149 { | 149 { |
150 ASSERT(executionContext()); | 150 ASSERT(executionContext()); |
151 executionContext()->addConsoleMessage(ConsoleMessage::create(JSMessageSource
, WarningMessageLevel, getMessageForResponseError(error, m_requestURL))); | 151 executionContext()->addConsoleMessage(ConsoleMessage::create(JSMessageSource
, WarningMessageLevel, getMessageForResponseError(error, m_requestURL))); |
152 | 152 |
153 // The default value of WebServiceWorkerResponse's status is 0, which maps | 153 // The default value of WebServiceWorkerResponse's status is 0, which maps |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 , m_state(Initial) | 222 , m_state(Initial) |
223 { | 223 { |
224 } | 224 } |
225 | 225 |
226 DEFINE_TRACE(RespondWithObserver) | 226 DEFINE_TRACE(RespondWithObserver) |
227 { | 227 { |
228 ContextLifecycleObserver::trace(visitor); | 228 ContextLifecycleObserver::trace(visitor); |
229 } | 229 } |
230 | 230 |
231 } // namespace blink | 231 } // namespace blink |
OLD | NEW |