Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1760)

Unified Diff: Source/modules/serviceworkers/RespondWithObserver.cpp

Issue 1228233007: Shows error messages in the inspector when .respondWith() is called with wrong responses. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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)

Powered by Google App Engine
This is Rietveld 408576698