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..6e12c92d02f5b97926882ed660985bad83614af9 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,10 @@ void RespondWithObserver::contextDestroyed() |
| void RespondWithObserver::didDispatchEvent() |
| { |
| - if (m_state == Initial) |
| - sendResponse(nullptr); |
| + if (m_state != Initial || !executionContext()) |
| + return; |
| + ServiceWorkerGlobalScopeClient::from(executionContext())->didHandleFetchEvent(m_eventID); |
| + m_state = Done; |
| } |
| void RespondWithObserver::respondWith(ScriptState* scriptState, const ScriptValue& value, ExceptionState& exceptionState) |
| @@ -91,20 +94,16 @@ void RespondWithObserver::respondWith(ScriptState* scriptState, const ScriptValu |
| ThenFunction::createFunction(scriptState, this, ThenFunction::Rejected)); |
| } |
| -void RespondWithObserver::sendResponse(Response* response) |
| +void RespondWithObserver::responseWasRejected() |
| { |
| if (!executionContext()) |
|
Mike West
2014/09/16 11:01:38
Nit: Can the response be rejected outside of an ex
horo
2014/09/16 11:17:40
I think we can use ASSERT here.
Done.
|
| return; |
| - ServiceWorkerGlobalScopeClient::from(executionContext())->didHandleFetchEvent(m_eventID, response); |
| + // The default value of WebServiceWorkerResponse's status is 0 that means a network error. |
|
Mike West
2014/09/16 11:01:38
Nit: I'd suggest "... is 0, which maps to a networ
horo
2014/09/16 11:17:41
Done.
|
| + WebServiceWorkerResponse webResponse; |
| + ServiceWorkerGlobalScopeClient::from(executionContext())->didHandleFetchEvent(m_eventID, webResponse); |
| m_state = Done; |
| } |
| -void RespondWithObserver::responseWasRejected() |
| -{ |
| - // FIXME: Throw a NetworkError to service worker's execution context. |
| - sendResponse(nullptr); |
| -} |
| - |
| void RespondWithObserver::responseWasFulfilled(const ScriptValue& value) |
| { |
| if (!executionContext()) |
| @@ -114,7 +113,10 @@ void RespondWithObserver::responseWasFulfilled(const ScriptValue& value) |
| return; |
| } |
| v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(value.v8Value()); |
| - sendResponse(V8Response::toImpl(object)); |
| + WebServiceWorkerResponse webResponse; |
| + V8Response::toImpl(object)->populateWebServiceWorkerResponse(webResponse); |
|
Mike West
2014/09/16 11:01:38
Nit: You could use 'toImplWithTypeCheck' to skip t
horo
2014/09/16 11:17:40
Done.
|
| + ServiceWorkerGlobalScopeClient::from(executionContext())->didHandleFetchEvent(m_eventID, webResponse); |
| + m_state = Done; |
| } |
| RespondWithObserver::RespondWithObserver(ExecutionContext* context, int eventID) |