Index: Source/modules/serviceworkers/RespondWithObserver.cpp |
diff --git a/Source/modules/serviceworkers/RespondWithObserver.cpp b/Source/modules/serviceworkers/RespondWithObserver.cpp |
index 67aaa550aaba8dc5f33343dab9d5541f52c88549..9a054dddf35817cf5b4c342188f77aaa58ad1851 100644 |
--- a/Source/modules/serviceworkers/RespondWithObserver.cpp |
+++ b/Source/modules/serviceworkers/RespondWithObserver.cpp |
@@ -23,6 +23,42 @@ |
#include <v8.h> |
namespace blink { |
+namespace { |
+ |
+// Outputs the error message to let the developer know about the reason of the unusual failures. |
+void maybeOutputErrorMessage(ExecutionContext* context, WebServiceWorkerResponseError error, const KURL& requestURL) |
+{ |
falken
2015/07/10 11:20:44
I suspect a more user-friendly way to present this
horo
2015/07/10 12:13:26
Done.
|
+ String errorMessage; |
+ switch (error) { |
+ case WebServiceWorkerResponseErrorUnknown: |
+ errorMessage = "An unexpected error occured while handling the FetchEvent (" + requestURL.string() + ")."; |
falken
2015/07/10 11:20:44
"an unexpected error occurred."
(this should proba
horo
2015/07/10 12:13:27
Done.
|
+ break; |
+ case WebServiceWorkerResponseErrorPromiseRejected: |
falken
2015/07/10 11:20:44
Can you comment why this doesn't have a message (I
horo
2015/07/10 12:13:27
Humm.
It may better to show more detailed message
|
+ return; |
+ break; |
+ case WebServiceWorkerResponseErrorDefaultPrevented: |
+ errorMessage = "event.preventDefault() for the FetchEvent (" + requestURL.string() + ") without calling event.respondWith() is treated as a network error."; |
falken
2015/07/10 11:20:44
"preventDefault() was called without calling respo
horo
2015/07/10 12:13:27
Done.
|
+ break; |
+ case WebServiceWorkerResponseErrorNoV8Instance: |
+ errorMessage = "The object with which respond to the request (" + requestURL.string() + ") must be a Response object."; |
falken
2015/07/10 11:20:44
"an object that was not a Response was passed to r
horo
2015/07/10 12:13:27
Done.
|
+ break; |
+ case WebServiceWorkerResponseErrorResponseTypeError: |
falken
2015/07/10 11:20:44
ditto, comment
horo
2015/07/10 12:13:26
Added.
|
+ return; |
+ break; |
+ case WebServiceWorkerResponseErrorResponseTypeOpaque: |
+ errorMessage = "Opaque type response can't respond to the request (" + requestURL.string() + ") which type isn't no-cors."; |
falken
2015/07/10 11:20:44
"an opaque response was used for a request whose t
horo
2015/07/10 12:13:26
Done.
|
+ break; |
+ case WebServiceWorkerResponseErrorResponseTypeNotBasicOrDefault: |
+ errorMessage = "The type of the Response object with which respond to the client request (" + requestURL.string() + ") must be basic or default."; |
falken
2015/07/10 11:20:44
"the response for a client request must have type
horo
2015/07/10 12:13:27
Done.
|
+ break; |
+ case WebServiceWorkerResponseErrorBodyUsed: |
+ errorMessage = "The body used response can't respond to the request (" + requestURL.string() + ")."; |
falken
2015/07/10 11:20:44
"a Response whose \"bodyUsed\" is \"true\" cannot
horo
2015/07/10 12:13:26
Done.
|
+ break; |
+ } |
+ context->addConsoleMessage(ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, errorMessage)); |
falken
2015/07/10 11:20:44
I suspect this should be a Warning or Info, it's c
horo
2015/07/10 12:13:26
Changed to Info.
Mike West
2015/07/10 13:01:09
The "intentionally doing this" worries me a bit; w
falken
2015/07/13 00:51:36
+pfeldman FYI
I don't have a very compelling use
falken
2015/07/13 00:58:10
Ah.. just realized respondWith()'s return value wo
|
+} |
+ |
+} // namespace |
class RespondWithObserver::ThenFunction final : public ScriptFunction { |
public: |
@@ -69,9 +105,9 @@ private: |
ResolveType m_resolveType; |
}; |
-RespondWithObserver* RespondWithObserver::create(ExecutionContext* context, int eventID, WebURLRequest::FetchRequestMode requestMode, WebURLRequest::FrameType frameType) |
+RespondWithObserver* RespondWithObserver::create(ExecutionContext* context, int eventID, const KURL& requestURL, WebURLRequest::FetchRequestMode requestMode, WebURLRequest::FrameType frameType) |
{ |
- return new RespondWithObserver(context, eventID, requestMode, frameType); |
+ return new RespondWithObserver(context, eventID, requestURL, requestMode, frameType); |
} |
void RespondWithObserver::contextDestroyed() |
@@ -111,6 +147,7 @@ void RespondWithObserver::respondWith(ScriptState* scriptState, const ScriptValu |
void RespondWithObserver::responseWasRejected(WebServiceWorkerResponseError error) |
{ |
ASSERT(executionContext()); |
+ maybeOutputErrorMessage(executionContext(), error, m_requestURL); |
// The default value of WebServiceWorkerResponse's status is 0, which maps |
// to a network error. |
WebServiceWorkerResponse webResponse; |
@@ -174,9 +211,10 @@ void RespondWithObserver::responseWasFulfilled(const ScriptValue& value) |
m_state = Done; |
} |
-RespondWithObserver::RespondWithObserver(ExecutionContext* context, int eventID, WebURLRequest::FetchRequestMode requestMode, WebURLRequest::FrameType frameType) |
+RespondWithObserver::RespondWithObserver(ExecutionContext* context, int eventID, const KURL& requestURL, WebURLRequest::FetchRequestMode requestMode, WebURLRequest::FrameType frameType) |
: ContextLifecycleObserver(context) |
, m_eventID(eventID) |
+ , m_requestURL(requestURL) |
, m_requestMode(requestMode) |
, m_frameType(frameType) |
, m_state(Initial) |