Chromium Code Reviews| Index: Source/modules/serviceworkers/RespondWithObserver.cpp |
| diff --git a/Source/modules/serviceworkers/RespondWithObserver.cpp b/Source/modules/serviceworkers/RespondWithObserver.cpp |
| index 286054ba8de3e1535b873a05d8b2a49221eea48c..249c822f7c0a9e15c5fe323233e9c42eaf6181c7 100644 |
| --- a/Source/modules/serviceworkers/RespondWithObserver.cpp |
| +++ b/Source/modules/serviceworkers/RespondWithObserver.cpp |
| @@ -12,6 +12,7 @@ |
| #include "bindings/modules/v8/V8Response.h" |
| #include "core/dom/ExecutionContext.h" |
| #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" |
| +#include "public/platform/WebServiceWorkerResponse.h" |
| #include "wtf/Assertions.h" |
| #include "wtf/RefPtr.h" |
| #include <v8.h> |
| @@ -74,8 +75,11 @@ void RespondWithObserver::contextDestroyed() |
| void RespondWithObserver::didDispatchEvent() |
| { |
| - if (m_state == Initial) |
| - sendResponse(nullptr); |
| + ASSERT(executionContext()); |
| + if (m_state != Initial) |
| + return; |
| + ServiceWorkerGlobalScopeClient::from(executionContext())->didHandleFetchEvent(m_eventID); |
| + m_state = Done; |
| } |
| void RespondWithObserver::respondWith(ScriptState* scriptState, const ScriptValue& value, ExceptionState& exceptionState) |
| @@ -91,30 +95,26 @@ void RespondWithObserver::respondWith(ScriptState* scriptState, const ScriptValu |
| ThenFunction::createFunction(scriptState, this, ThenFunction::Rejected)); |
| } |
| -void RespondWithObserver::sendResponse(Response* response) |
| -{ |
| - if (!executionContext()) |
| - return; |
| - ServiceWorkerGlobalScopeClient::from(executionContext())->didHandleFetchEvent(m_eventID, response); |
| - m_state = Done; |
| -} |
| - |
| void RespondWithObserver::responseWasRejected() |
| { |
| - // FIXME: Throw a NetworkError to service worker's execution context. |
| - sendResponse(nullptr); |
| + ASSERT(executionContext()); |
| + // The default value of WebServiceWorkerResponse's status is 0, which maps to a network error. |
|
yhirano
2014/09/17 02:25:31
Please wrap the comment in 80 columns.
horo
2014/09/17 04:45:20
Done.
|
| + WebServiceWorkerResponse webResponse; |
| + ServiceWorkerGlobalScopeClient::from(executionContext())->didHandleFetchEvent(m_eventID, webResponse); |
| + m_state = Done; |
| } |
| void RespondWithObserver::responseWasFulfilled(const ScriptValue& value) |
| { |
| - if (!executionContext()) |
| - return; |
| + ASSERT(executionContext()); |
| if (!V8Response::hasInstance(value.v8Value(), toIsolate(executionContext()))) { |
| responseWasRejected(); |
| return; |
| } |
| - v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(value.v8Value()); |
| - sendResponse(V8Response::toImpl(object)); |
| + WebServiceWorkerResponse webResponse; |
| + V8Response::toImplWithTypeCheck(toIsolate(executionContext()), value.v8Value())->populateWebServiceWorkerResponse(webResponse); |
| + ServiceWorkerGlobalScopeClient::from(executionContext())->didHandleFetchEvent(m_eventID, webResponse); |
| + m_state = Done; |
| } |
| RespondWithObserver::RespondWithObserver(ExecutionContext* context, int eventID) |