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

Unified Diff: Source/modules/websockets/MainThreadWebSocketChannel.cpp

Issue 14320014: Make the WebSocket fail messages meaningful (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 8 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
« no previous file with comments | « Source/modules/websockets/MainThreadWebSocketChannel.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/websockets/MainThreadWebSocketChannel.cpp
diff --git a/Source/modules/websockets/MainThreadWebSocketChannel.cpp b/Source/modules/websockets/MainThreadWebSocketChannel.cpp
index ba388d054fddf47b3c45b957f5c2a9c4ccf61e3f..88decd5de58e2c0de3890234b567764725c651dd 100644
--- a/Source/modules/websockets/MainThreadWebSocketChannel.cpp
+++ b/Source/modules/websockets/MainThreadWebSocketChannel.cpp
@@ -46,6 +46,7 @@
#include "Page.h"
#include "ProgressTracker.h"
#include "ScriptCallStack.h"
+#include "ScriptCallStackFactory.h"
#include "ScriptExecutionContext.h"
#include "Settings.h"
#include "SocketStreamError.h"
@@ -86,6 +87,7 @@ MainThreadWebSocketChannel::MainThreadWebSocketChannel(Document* document, WebSo
, m_closeEventCode(CloseEventCodeAbnormalClosure)
, m_outgoingFrameQueueStatus(OutgoingFrameQueueOpen)
, m_blobLoaderStatus(BlobLoaderNotStarted)
+ , m_callFrameAtConnection("", "", 0)
{
if (Page* page = m_document->page())
m_identifier = page->progress()->createUniqueIdentifier();
@@ -108,6 +110,8 @@ void MainThreadWebSocketChannel::connect(const KURL& url, const String& protocol
InspectorInstrumentation::didCreateWebSocket(m_document, m_identifier, url, m_document->url(), protocol);
ref();
m_handle = SocketStreamHandle::create(m_handshake->url(), this);
+ RefPtr<ScriptCallStack> callstack = createScriptCallStackForConsole(1);
+ m_callFrameAtConnection = callstack && callstack->size() > 0 ? callstack->at(0) : ScriptCallFrame("", m_handshake->clientOrigin(), 0);
}
String MainThreadWebSocketChannel::subprotocol()
@@ -196,7 +200,19 @@ void MainThreadWebSocketChannel::fail(const String& reason)
ASSERT(!m_suspended);
if (m_document) {
InspectorInstrumentation::didReceiveWebSocketFrameError(m_document, m_identifier, reason);
- m_document->addConsoleMessage(NetworkMessageSource, ErrorMessageLevel, "WebSocket connection to '" + m_handshake->url().elidedString() + "' failed: " + reason);
+ const String message = "WebSocket connection to '" + m_handshake->url().elidedString() + "' failed: " + reason;
+ RefPtr<ScriptCallStack> callstack = createScriptCallStackForConsole(1);
+ if (callstack && callstack->size() > 0) {
+ // We are in a JS callstack.
+ // So, the addConsoleMessage method will show the stack appropriately.
+ m_document->addConsoleMessage(JSMessageSource, ErrorMessageLevel, message);
+ } else {
+ // We are not in a JS callstack.
+ // Then show the source file and the line number at the connection initiation.
+ const String& url = m_callFrameAtConnection.sourceURL();
+ unsigned lineNumber = m_callFrameAtConnection.lineNumber();
+ static_cast<ScriptExecutionContext*>(m_document)->addConsoleMessage(JSMessageSource, ErrorMessageLevel, message, url, lineNumber, 0, 0);
tyoshino (SeeGerritForStatus) 2013/04/22 05:47:18 How about continue not showing lineno here in case
yhirano 2013/04/22 07:33:38 Fixed around the line 113 for this problem.
+ }
}
// Hybi-10 specification explicitly states we must not continue to handle incoming data
« no previous file with comments | « Source/modules/websockets/MainThreadWebSocketChannel.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698