Index: Source/modules/serviceworkers/RespondWithObserver.cpp |
diff --git a/Source/modules/serviceworkers/RespondWithObserver.cpp b/Source/modules/serviceworkers/RespondWithObserver.cpp |
index 6f1081817dfef940614d22d9860023fd797431dd..286054ba8de3e1535b873a05d8b2a49221eea48c 100644 |
--- a/Source/modules/serviceworkers/RespondWithObserver.cpp |
+++ b/Source/modules/serviceworkers/RespondWithObserver.cpp |
@@ -12,7 +12,6 @@ |
#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> |
@@ -75,11 +74,8 @@ |
void RespondWithObserver::didDispatchEvent() |
{ |
- ASSERT(executionContext()); |
- if (m_state != Initial) |
- return; |
- ServiceWorkerGlobalScopeClient::from(executionContext())->didHandleFetchEvent(m_eventID); |
- m_state = Done; |
+ if (m_state == Initial) |
+ sendResponse(nullptr); |
} |
void RespondWithObserver::respondWith(ScriptState* scriptState, const ScriptValue& value, ExceptionState& exceptionState) |
@@ -95,27 +91,30 @@ |
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() |
{ |
- ASSERT(executionContext()); |
- // 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; |
+ // FIXME: Throw a NetworkError to service worker's execution context. |
+ sendResponse(nullptr); |
} |
void RespondWithObserver::responseWasFulfilled(const ScriptValue& value) |
{ |
- ASSERT(executionContext()); |
+ if (!executionContext()) |
+ return; |
if (!V8Response::hasInstance(value.v8Value(), toIsolate(executionContext()))) { |
responseWasRejected(); |
return; |
} |
- WebServiceWorkerResponse webResponse; |
- V8Response::toImplWithTypeCheck(toIsolate(executionContext()), value.v8Value())->populateWebServiceWorkerResponse(webResponse); |
- ServiceWorkerGlobalScopeClient::from(executionContext())->didHandleFetchEvent(m_eventID, webResponse); |
- m_state = Done; |
+ v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(value.v8Value()); |
+ sendResponse(V8Response::toImpl(object)); |
} |
RespondWithObserver::RespondWithObserver(ExecutionContext* context, int eventID) |