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..6f1081817dfef940614d22d9860023fd797431dd 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()); |
|
nhiroki
2014/09/17 05:42:46
Is this always true? Who ensures this condition?
horo
2014/09/17 07:45:26
In the constructor of RespondWithObserver, Context
kinuko
2014/09/23 16:44:38
Drive-by nit: if executionContext() can never be n
|
| + 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,27 @@ 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()); |
|
nhiroki
2014/09/17 05:42:46
ditto.
|
| + // The default value of WebServiceWorkerResponse's status is 0, which maps |
| + // to a network error. |
| + WebServiceWorkerResponse webResponse; |
| + ServiceWorkerGlobalScopeClient::from(executionContext())->didHandleFetchEvent(m_eventID, webResponse); |
| + m_state = Done; |
| } |
| void RespondWithObserver::responseWasFulfilled(const ScriptValue& value) |
| { |
| - if (!executionContext()) |
| - return; |
| + ASSERT(executionContext()); |
|
nhiroki
2014/09/17 05:42:46
ditto.
|
| 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) |