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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « Source/modules/websockets/MainThreadWebSocketChannel.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 28 matching lines...) Expand all
39 #include "FileError.h" 39 #include "FileError.h"
40 #include "FileReaderLoader.h" 40 #include "FileReaderLoader.h"
41 #include "Frame.h" 41 #include "Frame.h"
42 #include "FrameLoader.h" 42 #include "FrameLoader.h"
43 #include "FrameLoaderClient.h" 43 #include "FrameLoaderClient.h"
44 #include "InspectorInstrumentation.h" 44 #include "InspectorInstrumentation.h"
45 #include "Logging.h" 45 #include "Logging.h"
46 #include "Page.h" 46 #include "Page.h"
47 #include "ProgressTracker.h" 47 #include "ProgressTracker.h"
48 #include "ScriptCallStack.h" 48 #include "ScriptCallStack.h"
49 #include "ScriptCallStackFactory.h"
49 #include "ScriptExecutionContext.h" 50 #include "ScriptExecutionContext.h"
50 #include "Settings.h" 51 #include "Settings.h"
51 #include "SocketStreamError.h" 52 #include "SocketStreamError.h"
52 #include "SocketStreamHandle.h" 53 #include "SocketStreamHandle.h"
53 #include "WebSocketChannel.h" 54 #include "WebSocketChannel.h"
54 #include "WebSocketChannelClient.h" 55 #include "WebSocketChannelClient.h"
55 #include "WebSocketHandshake.h" 56 #include "WebSocketHandshake.h"
56 57
57 #include <wtf/ArrayBuffer.h> 58 #include <wtf/ArrayBuffer.h>
58 #include <wtf/Deque.h> 59 #include <wtf/Deque.h>
(...skipping 20 matching lines...) Expand all
79 , m_receivedClosingHandshake(false) 80 , m_receivedClosingHandshake(false)
80 , m_closingTimer(this, &MainThreadWebSocketChannel::closingTimerFired) 81 , m_closingTimer(this, &MainThreadWebSocketChannel::closingTimerFired)
81 , m_closed(false) 82 , m_closed(false)
82 , m_shouldDiscardReceivedData(false) 83 , m_shouldDiscardReceivedData(false)
83 , m_unhandledBufferedAmount(0) 84 , m_unhandledBufferedAmount(0)
84 , m_identifier(0) 85 , m_identifier(0)
85 , m_hasContinuousFrame(false) 86 , m_hasContinuousFrame(false)
86 , m_closeEventCode(CloseEventCodeAbnormalClosure) 87 , m_closeEventCode(CloseEventCodeAbnormalClosure)
87 , m_outgoingFrameQueueStatus(OutgoingFrameQueueOpen) 88 , m_outgoingFrameQueueStatus(OutgoingFrameQueueOpen)
88 , m_blobLoaderStatus(BlobLoaderNotStarted) 89 , m_blobLoaderStatus(BlobLoaderNotStarted)
90 , m_callFrameAtConnection("", "", 0)
89 { 91 {
90 if (Page* page = m_document->page()) 92 if (Page* page = m_document->page())
91 m_identifier = page->progress()->createUniqueIdentifier(); 93 m_identifier = page->progress()->createUniqueIdentifier();
92 } 94 }
93 95
94 MainThreadWebSocketChannel::~MainThreadWebSocketChannel() 96 MainThreadWebSocketChannel::~MainThreadWebSocketChannel()
95 { 97 {
96 } 98 }
97 99
98 void MainThreadWebSocketChannel::connect(const KURL& url, const String& protocol ) 100 void MainThreadWebSocketChannel::connect(const KURL& url, const String& protocol )
99 { 101 {
100 LOG(Network, "MainThreadWebSocketChannel %p connect()", this); 102 LOG(Network, "MainThreadWebSocketChannel %p connect()", this);
101 ASSERT(!m_handle); 103 ASSERT(!m_handle);
102 ASSERT(!m_suspended); 104 ASSERT(!m_suspended);
103 m_handshake = adoptPtr(new WebSocketHandshake(url, protocol, m_document)); 105 m_handshake = adoptPtr(new WebSocketHandshake(url, protocol, m_document));
104 m_handshake->reset(); 106 m_handshake->reset();
105 if (m_deflateFramer.canDeflate()) 107 if (m_deflateFramer.canDeflate())
106 m_handshake->addExtensionProcessor(m_deflateFramer.createExtensionProces sor()); 108 m_handshake->addExtensionProcessor(m_deflateFramer.createExtensionProces sor());
107 if (m_identifier) 109 if (m_identifier)
108 InspectorInstrumentation::didCreateWebSocket(m_document, m_identifier, u rl, m_document->url(), protocol); 110 InspectorInstrumentation::didCreateWebSocket(m_document, m_identifier, u rl, m_document->url(), protocol);
109 ref(); 111 ref();
110 m_handle = SocketStreamHandle::create(m_handshake->url(), this); 112 m_handle = SocketStreamHandle::create(m_handshake->url(), this);
113 RefPtr<ScriptCallStack> callstack = createScriptCallStackForConsole(1);
114 m_callFrameAtConnection = callstack && callstack->size() > 0 ? callstack->at (0) : ScriptCallFrame("", m_handshake->clientOrigin(), 0);
111 } 115 }
112 116
113 String MainThreadWebSocketChannel::subprotocol() 117 String MainThreadWebSocketChannel::subprotocol()
114 { 118 {
115 LOG(Network, "MainThreadWebSocketChannel %p subprotocol()", this); 119 LOG(Network, "MainThreadWebSocketChannel %p subprotocol()", this);
116 if (!m_handshake || m_handshake->mode() != WebSocketHandshake::Connected) 120 if (!m_handshake || m_handshake->mode() != WebSocketHandshake::Connected)
117 return ""; 121 return "";
118 String serverProtocol = m_handshake->serverWebSocketProtocol(); 122 String serverProtocol = m_handshake->serverWebSocketProtocol();
119 if (serverProtocol.isNull()) 123 if (serverProtocol.isNull())
120 return ""; 124 return "";
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 if (m_closing && !m_closingTimer.isActive()) 193 if (m_closing && !m_closingTimer.isActive())
190 m_closingTimer.startOneShot(2 * TCPMaximumSegmentLifetime); 194 m_closingTimer.startOneShot(2 * TCPMaximumSegmentLifetime);
191 } 195 }
192 196
193 void MainThreadWebSocketChannel::fail(const String& reason) 197 void MainThreadWebSocketChannel::fail(const String& reason)
194 { 198 {
195 LOG(Network, "MainThreadWebSocketChannel %p fail() reason='%s'", this, reaso n.utf8().data()); 199 LOG(Network, "MainThreadWebSocketChannel %p fail() reason='%s'", this, reaso n.utf8().data());
196 ASSERT(!m_suspended); 200 ASSERT(!m_suspended);
197 if (m_document) { 201 if (m_document) {
198 InspectorInstrumentation::didReceiveWebSocketFrameError(m_document, m_id entifier, reason); 202 InspectorInstrumentation::didReceiveWebSocketFrameError(m_document, m_id entifier, reason);
199 m_document->addConsoleMessage(NetworkMessageSource, ErrorMessageLevel, " WebSocket connection to '" + m_handshake->url().elidedString() + "' failed: " + reason); 203 const String message = "WebSocket connection to '" + m_handshake->url(). elidedString() + "' failed: " + reason;
204 RefPtr<ScriptCallStack> callstack = createScriptCallStackForConsole(1);
205 if (callstack && callstack->size() > 0) {
206 // We are in a JS callstack.
207 // So, the addConsoleMessage method will show the stack appropriatel y.
208 m_document->addConsoleMessage(JSMessageSource, ErrorMessageLevel, me ssage);
209 } else {
210 // We are not in a JS callstack.
211 // Then show the source file and the line number at the connection i nitiation.
212 const String& url = m_callFrameAtConnection.sourceURL();
213 unsigned lineNumber = m_callFrameAtConnection.lineNumber();
214 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.
215 }
200 } 216 }
201 217
202 // Hybi-10 specification explicitly states we must not continue to handle in coming data 218 // Hybi-10 specification explicitly states we must not continue to handle in coming data
203 // once the WebSocket connection is failed (section 7.1.7). 219 // once the WebSocket connection is failed (section 7.1.7).
204 RefPtr<MainThreadWebSocketChannel> protect(this); // The client can close th e channel, potentially removing the last reference. 220 RefPtr<MainThreadWebSocketChannel> protect(this); // The client can close th e channel, potentially removing the last reference.
205 m_shouldDiscardReceivedData = true; 221 m_shouldDiscardReceivedData = true;
206 if (!m_buffer.isEmpty()) 222 if (!m_buffer.isEmpty())
207 skipBuffer(m_buffer.size()); // Save memory. 223 skipBuffer(m_buffer.size()); // Save memory.
208 m_deflateFramer.didFail(); 224 m_deflateFramer.didFail();
209 m_hasContinuousFrame = false; 225 m_hasContinuousFrame = false;
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 return false; 807 return false;
792 } 808 }
793 809
794 Vector<char> frameData; 810 Vector<char> frameData;
795 frame.makeFrameData(frameData); 811 frame.makeFrameData(frameData);
796 812
797 return m_handle->send(frameData.data(), frameData.size()); 813 return m_handle->send(frameData.data(), frameData.size());
798 } 814 }
799 815
800 } // namespace WebCore 816 } // namespace WebCore
OLDNEW
« 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