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

Side by Side Diff: Source/modules/websockets/MainThreadWebSocketChannel.cpp

Issue 14657008: Make websocket error messages look better at the devtools console. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: cleanup Created 7 years, 7 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 , m_hasContinuousFrame(false) 87 , m_hasContinuousFrame(false)
88 , m_closeEventCode(CloseEventCodeAbnormalClosure) 88 , m_closeEventCode(CloseEventCodeAbnormalClosure)
89 , m_outgoingFrameQueueStatus(OutgoingFrameQueueOpen) 89 , m_outgoingFrameQueueStatus(OutgoingFrameQueueOpen)
90 , m_blobLoaderStatus(BlobLoaderNotStarted) 90 , m_blobLoaderStatus(BlobLoaderNotStarted)
91 , m_callFrameAtConnection("", "", 0) 91 , m_callFrameAtConnection("", "", 0)
92 { 92 {
93 if (Page* page = m_document->page()) 93 if (Page* page = m_document->page())
94 m_identifier = createUniqueIdentifier(); 94 m_identifier = createUniqueIdentifier();
95 } 95 }
96 96
97 MainThreadWebSocketChannel::MainThreadWebSocketChannel(Document* document, WebSo cketChannelClient* client, const ScriptCallFrame& callFrame)
98 : m_document(document)
99 , m_client(client)
100 , m_resumeTimer(this, &MainThreadWebSocketChannel::resumeTimerFired)
101 , m_suspended(false)
102 , m_closing(false)
103 , m_didFailOfClientAlreadyRun(false)
104 , m_receivedClosingHandshake(false)
105 , m_closingTimer(this, &MainThreadWebSocketChannel::closingTimerFired)
106 , m_closed(false)
107 , m_shouldDiscardReceivedData(false)
108 , m_unhandledBufferedAmount(0)
109 , m_identifier(0)
110 , m_hasContinuousFrame(false)
111 , m_closeEventCode(CloseEventCodeAbnormalClosure)
112 , m_outgoingFrameQueueStatus(OutgoingFrameQueueOpen)
113 , m_blobLoaderStatus(BlobLoaderNotStarted)
114 , m_callFrameAtConnection(callFrame)
115 {
116 if (Page* page = m_document->page())
117 m_identifier = createUniqueIdentifier();
118 }
119
97 MainThreadWebSocketChannel::~MainThreadWebSocketChannel() 120 MainThreadWebSocketChannel::~MainThreadWebSocketChannel()
98 { 121 {
99 } 122 }
100 123
101 void MainThreadWebSocketChannel::connect(const KURL& url, const String& protocol ) 124 void MainThreadWebSocketChannel::connect(const KURL& url, const String& protocol )
102 { 125 {
103 LOG(Network, "MainThreadWebSocketChannel %p connect()", this); 126 LOG(Network, "MainThreadWebSocketChannel %p connect()", this);
104 ASSERT(!m_handle); 127 ASSERT(!m_handle);
105 ASSERT(!m_suspended); 128 ASSERT(!m_suspended);
106 m_handshake = adoptPtr(new WebSocketHandshake(url, protocol, m_document)); 129 m_handshake = adoptPtr(new WebSocketHandshake(url, protocol, m_document));
107 m_handshake->reset(); 130 m_handshake->reset();
108 m_handshake->addExtensionProcessor(m_deflateFramer.createExtensionProcessor( )); 131 m_handshake->addExtensionProcessor(m_deflateFramer.createExtensionProcessor( ));
109 if (m_identifier) 132 if (m_identifier)
110 InspectorInstrumentation::didCreateWebSocket(m_document, m_identifier, u rl, m_document->url(), protocol); 133 InspectorInstrumentation::didCreateWebSocket(m_document, m_identifier, u rl, m_document->url(), protocol);
111 ref(); 134 ref();
112 m_handle = SocketStreamHandle::create(m_handshake->url(), this); 135 m_handle = SocketStreamHandle::create(m_handshake->url(), this);
113 RefPtr<ScriptCallStack> callstack = createScriptCallStack(1, true); 136 RefPtr<ScriptCallStack> callStack = createScriptCallStack(1, true);
114 m_callFrameAtConnection = callstack && callstack->size() > 0 ? callstack->at (0) : ScriptCallFrame("", "", 0); 137 if (callStack && callStack->size() > 0)
138 m_callFrameAtConnection = callStack->at(0);
115 } 139 }
116 140
117 String MainThreadWebSocketChannel::subprotocol() 141 String MainThreadWebSocketChannel::subprotocol()
118 { 142 {
119 LOG(Network, "MainThreadWebSocketChannel %p subprotocol()", this); 143 LOG(Network, "MainThreadWebSocketChannel %p subprotocol()", this);
120 if (!m_handshake || m_handshake->mode() != WebSocketHandshake::Connected) 144 if (!m_handshake || m_handshake->mode() != WebSocketHandshake::Connected)
121 return ""; 145 return "";
122 String serverProtocol = m_handshake->serverWebSocketProtocol(); 146 String serverProtocol = m_handshake->serverWebSocketProtocol();
123 if (serverProtocol.isNull()) 147 if (serverProtocol.isNull())
124 return ""; 148 return "";
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 { 211 {
188 LOG(Network, "MainThreadWebSocketChannel %p close() code=%d reason='%s'", th is, code, reason.utf8().data()); 212 LOG(Network, "MainThreadWebSocketChannel %p close() code=%d reason='%s'", th is, code, reason.utf8().data());
189 ASSERT(!m_suspended); 213 ASSERT(!m_suspended);
190 if (!m_handle) 214 if (!m_handle)
191 return; 215 return;
192 startClosingHandshake(code, reason); 216 startClosingHandshake(code, reason);
193 if (m_closing && !m_closingTimer.isActive()) 217 if (m_closing && !m_closingTimer.isActive())
194 m_closingTimer.startOneShot(2 * TCPMaximumSegmentLifetime); 218 m_closingTimer.startOneShot(2 * TCPMaximumSegmentLifetime);
195 } 219 }
196 220
197 void MainThreadWebSocketChannel::fail(const String& reason) 221 void MainThreadWebSocketChannel::fail(const String& reason, MessageLevel level)
222 {
223 fail(reason, level, 0);
224 }
225
226 void MainThreadWebSocketChannel::fail(const String& reason, MessageLevel level, PassOwnPtr<CallStackWrapper> wrapper)
198 { 227 {
199 LOG(Network, "MainThreadWebSocketChannel %p fail() reason='%s'", this, reaso n.utf8().data()); 228 LOG(Network, "MainThreadWebSocketChannel %p fail() reason='%s'", this, reaso n.utf8().data());
200 ASSERT(!m_suspended); 229 ASSERT(!m_suspended);
201 if (m_document) { 230 if (m_document) {
202 InspectorInstrumentation::didReceiveWebSocketFrameError(m_document, m_id entifier, reason); 231 InspectorInstrumentation::didReceiveWebSocketFrameError(m_document, m_id entifier, reason);
203 const String message = "WebSocket connection to '" + m_handshake->url(). elidedString() + "' failed: " + reason; 232 const String message = "WebSocket connection to '" + m_handshake->url(). elidedString() + "' failed: " + reason;
204 RefPtr<ScriptCallStack> callstack = createScriptCallStack(1, true); 233 RefPtr<ScriptCallStack> callStack = wrapper ? wrapper->callStack() : ado ptRef<ScriptCallStack>(0);
205 if (callstack && callstack->size() > 0) { 234 if (callStack && callStack->size() > 0) {
206 // We are in a JS callstack. 235 String url = callStack->at(0).sourceURL();
207 // So, the addConsoleMessage method will show the stack appropriatel y. 236 unsigned lineNumber = callStack->at(0).lineNumber();
208 m_document->addConsoleMessage(JSMessageSource, ErrorMessageLevel, me ssage); 237 static_cast<ScriptExecutionContext*>(m_document)->addConsoleMessage( JSMessageSource, level, message, url, lineNumber);
209 } else { 238 } else {
210 // We are not in a JS callstack. 239 RefPtr<ScriptCallStack> callStack = createScriptCallStack(1, true);
211 // Then show the source file and the line number at the connection i nitiation. 240 if (callStack && callStack->size() > 0) {
212 const String& url = m_callFrameAtConnection.sourceURL(); 241 // We are in a JS callstack.
213 unsigned lineNumber = m_callFrameAtConnection.lineNumber(); 242 // So, the addConsoleMessage method will show the stack appropri ately.
214 static_cast<ScriptExecutionContext*>(m_document)->addConsoleMessage( JSMessageSource, ErrorMessageLevel, message, url, lineNumber, 0, 0); 243 m_document->addConsoleMessage(JSMessageSource, level, message);
244 } else {
245 // We are not in a JS callstack.
246 // Then show the source file and the line number at the connecti on initiation.
247 const String& url = m_callFrameAtConnection.sourceURL();
248 unsigned lineNumber = m_callFrameAtConnection.lineNumber();
249 static_cast<ScriptExecutionContext*>(m_document)->addConsoleMess age(JSMessageSource, level, message, url, lineNumber, 0, 0);
250 }
215 } 251 }
216 } 252 }
253 failInternal();
254 }
217 255
256 void MainThreadWebSocketChannel::failInternal()
257 {
218 // Hybi-10 specification explicitly states we must not continue to handle in coming data 258 // Hybi-10 specification explicitly states we must not continue to handle in coming data
219 // once the WebSocket connection is failed (section 7.1.7). 259 // once the WebSocket connection is failed (section 7.1.7).
220 RefPtr<MainThreadWebSocketChannel> protect(this); // The client can close th e channel, potentially removing the last reference. 260 RefPtr<MainThreadWebSocketChannel> protect(this); // The client can close th e channel, potentially removing the last reference.
221 m_shouldDiscardReceivedData = true; 261 m_shouldDiscardReceivedData = true;
222 if (!m_buffer.isEmpty()) 262 if (!m_buffer.isEmpty())
223 skipBuffer(m_buffer.size()); // Save memory. 263 skipBuffer(m_buffer.size()); // Save memory.
224 m_deflateFramer.didFail(); 264 m_deflateFramer.didFail();
225 m_hasContinuousFrame = false; 265 m_hasContinuousFrame = false;
226 m_continuousFrameData.clear(); 266 m_continuousFrameData.clear();
227 if (!m_didFailOfClientAlreadyRun) { 267 if (!m_didFailOfClientAlreadyRun) {
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 return false; 849 return false;
810 } 850 }
811 851
812 Vector<char> frameData; 852 Vector<char> frameData;
813 frame.makeFrameData(frameData); 853 frame.makeFrameData(frameData);
814 854
815 return m_handle->send(frameData.data(), frameData.size()); 855 return m_handle->send(frameData.data(), frameData.size());
816 } 856 }
817 857
818 } // namespace WebCore 858 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698