Index: Source/modules/websockets/MainThreadWebSocketChannel.cpp |
diff --git a/Source/modules/websockets/MainThreadWebSocketChannel.cpp b/Source/modules/websockets/MainThreadWebSocketChannel.cpp |
index ca8a50c6c5675fc6a3fa7a3e6d70b9a81e92e6aa..50b77f17f7e8dae7af05c4f471ebe11f0d7f7c67 100644 |
--- a/Source/modules/websockets/MainThreadWebSocketChannel.cpp |
+++ b/Source/modules/websockets/MainThreadWebSocketChannel.cpp |
@@ -94,6 +94,29 @@ MainThreadWebSocketChannel::MainThreadWebSocketChannel(Document* document, WebSo |
m_identifier = createUniqueIdentifier(); |
} |
+MainThreadWebSocketChannel::MainThreadWebSocketChannel(Document* document, WebSocketChannelClient* client, const ScriptCallFrame& callFrame) |
+ : m_document(document) |
+ , m_client(client) |
+ , m_resumeTimer(this, &MainThreadWebSocketChannel::resumeTimerFired) |
+ , m_suspended(false) |
+ , m_closing(false) |
+ , m_didFailOfClientAlreadyRun(false) |
+ , m_receivedClosingHandshake(false) |
+ , m_closingTimer(this, &MainThreadWebSocketChannel::closingTimerFired) |
+ , m_closed(false) |
+ , m_shouldDiscardReceivedData(false) |
+ , m_unhandledBufferedAmount(0) |
+ , m_identifier(0) |
+ , m_hasContinuousFrame(false) |
+ , m_closeEventCode(CloseEventCodeAbnormalClosure) |
+ , m_outgoingFrameQueueStatus(OutgoingFrameQueueOpen) |
+ , m_blobLoaderStatus(BlobLoaderNotStarted) |
+ , m_callFrameAtConnection(callFrame) |
+{ |
+ if (Page* page = m_document->page()) |
+ m_identifier = createUniqueIdentifier(); |
+} |
+ |
MainThreadWebSocketChannel::~MainThreadWebSocketChannel() |
{ |
} |
@@ -110,8 +133,9 @@ 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 = createScriptCallStack(1, true); |
- m_callFrameAtConnection = callstack && callstack->size() > 0 ? callstack->at(0) : ScriptCallFrame("", "", 0); |
+ RefPtr<ScriptCallStack> callStack = createScriptCallStack(1, true); |
+ if (callStack && callStack->size() > 0) |
+ m_callFrameAtConnection = callStack->at(0); |
} |
String MainThreadWebSocketChannel::subprotocol() |
@@ -194,27 +218,43 @@ void MainThreadWebSocketChannel::close(int code, const String& reason) |
m_closingTimer.startOneShot(2 * TCPMaximumSegmentLifetime); |
} |
-void MainThreadWebSocketChannel::fail(const String& reason) |
+void MainThreadWebSocketChannel::fail(const String& reason, MessageLevel level) |
+{ |
+ fail(reason, level, 0); |
+} |
+ |
+void MainThreadWebSocketChannel::fail(const String& reason, MessageLevel level, PassOwnPtr<CallStackWrapper> wrapper) |
{ |
LOG(Network, "MainThreadWebSocketChannel %p fail() reason='%s'", this, reason.utf8().data()); |
ASSERT(!m_suspended); |
if (m_document) { |
InspectorInstrumentation::didReceiveWebSocketFrameError(m_document, m_identifier, reason); |
const String message = "WebSocket connection to '" + m_handshake->url().elidedString() + "' failed: " + reason; |
- RefPtr<ScriptCallStack> callstack = createScriptCallStack(1, true); |
- 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); |
+ RefPtr<ScriptCallStack> callStack = wrapper ? wrapper->callStack() : adoptRef<ScriptCallStack>(0); |
+ if (callStack && callStack->size() > 0) { |
+ String url = callStack->at(0).sourceURL(); |
+ unsigned lineNumber = callStack->at(0).lineNumber(); |
+ static_cast<ScriptExecutionContext*>(m_document)->addConsoleMessage(JSMessageSource, level, message, url, lineNumber); |
} 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); |
+ RefPtr<ScriptCallStack> callStack = createScriptCallStack(1, true); |
+ if (callStack && callStack->size() > 0) { |
+ // We are in a JS callstack. |
+ // So, the addConsoleMessage method will show the stack appropriately. |
+ m_document->addConsoleMessage(JSMessageSource, level, 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, level, message, url, lineNumber, 0, 0); |
+ } |
} |
} |
+ failInternal(); |
+} |
+void MainThreadWebSocketChannel::failInternal() |
+{ |
// Hybi-10 specification explicitly states we must not continue to handle incoming data |
// once the WebSocket connection is failed (section 7.1.7). |
RefPtr<MainThreadWebSocketChannel> protect(this); // The client can close the channel, potentially removing the last reference. |