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

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

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: 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 15 matching lines...) Expand all
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #ifndef MainThreadWebSocketChannel_h 31 #ifndef MainThreadWebSocketChannel_h
32 #define MainThreadWebSocketChannel_h 32 #define MainThreadWebSocketChannel_h
33 33
34 #include "core/fileapi/FileReaderLoaderClient.h" 34 #include "core/fileapi/FileReaderLoaderClient.h"
35 #include "core/inspector/ScriptCallFrame.h" 35 #include "core/inspector/ScriptCallFrame.h"
36 #include "core/page/ConsoleTypes.h"
36 #include "core/platform/Timer.h" 37 #include "core/platform/Timer.h"
37 #include "core/platform/network/SocketStreamHandleClient.h" 38 #include "core/platform/network/SocketStreamHandleClient.h"
38 #include "modules/websockets/WebSocketChannel.h" 39 #include "modules/websockets/WebSocketChannel.h"
39 #include "modules/websockets/WebSocketDeflateFramer.h" 40 #include "modules/websockets/WebSocketDeflateFramer.h"
40 #include "modules/websockets/WebSocketFrame.h" 41 #include "modules/websockets/WebSocketFrame.h"
41 #include "modules/websockets/WebSocketHandshake.h" 42 #include "modules/websockets/WebSocketHandshake.h"
42 #include "wtf/Deque.h" 43 #include "wtf/Deque.h"
43 #include "wtf/Forward.h" 44 #include "wtf/Forward.h"
45 #include "wtf/PassOwnPtr.h"
44 #include "wtf/RefCounted.h" 46 #include "wtf/RefCounted.h"
45 #include "wtf/Vector.h" 47 #include "wtf/Vector.h"
46 #include "wtf/text/CString.h" 48 #include "wtf/text/CString.h"
47 49
48 namespace WebCore { 50 namespace WebCore {
49 51
50 class Blob; 52 class Blob;
51 class Document; 53 class Document;
52 class FileReaderLoader; 54 class FileReaderLoader;
53 class SocketStreamHandle; 55 class SocketStreamHandle;
54 class SocketStreamError; 56 class SocketStreamError;
55 class WebSocketChannelClient; 57 class WebSocketChannelClient;
56 58
57 class MainThreadWebSocketChannel : public RefCounted<MainThreadWebSocketChannel> , public SocketStreamHandleClient, public WebSocketChannel 59 class MainThreadWebSocketChannel : public RefCounted<MainThreadWebSocketChannel> , public SocketStreamHandleClient, public WebSocketChannel
58 , public FileReaderLoaderClient { 60 , public FileReaderLoaderClient {
59 WTF_MAKE_FAST_ALLOCATED; 61 WTF_MAKE_FAST_ALLOCATED;
60 public: 62 public:
61 static PassRefPtr<MainThreadWebSocketChannel> create(Document* document, Web SocketChannelClient* client) { return adoptRef(new MainThreadWebSocketChannel(do cument, client)); } 63 static PassRefPtr<MainThreadWebSocketChannel> create(Document* document, Web SocketChannelClient* client) { return adoptRef(new MainThreadWebSocketChannel(do cument, client)); }
64 // You can use this create function if you want to specify the source file a nd the line number information
tkent 2013/05/06 22:56:40 nit: Blink style has no column length limitation,
yhirano 2013/05/07 01:08:08 Done.
65 // at the connection initiation manually.
66 static PassRefPtr<MainThreadWebSocketChannel> create(Document* document, Web SocketChannelClient* client, const ScriptCallFrame& frame) { return adoptRef(new MainThreadWebSocketChannel(document, client, frame)); }
62 virtual ~MainThreadWebSocketChannel(); 67 virtual ~MainThreadWebSocketChannel();
63 68
64 bool send(const char* data, int length); 69 bool send(const char* data, int length);
65 70
66 // WebSocketChannel functions. 71 // WebSocketChannel functions.
67 virtual void connect(const KURL&, const String& protocol) OVERRIDE; 72 virtual void connect(const KURL&, const String& protocol) OVERRIDE;
68 virtual String subprotocol() OVERRIDE; 73 virtual String subprotocol() OVERRIDE;
69 virtual String extensions() OVERRIDE; 74 virtual String extensions() OVERRIDE;
70 virtual WebSocketChannel::SendResult send(const String& message) OVERRIDE; 75 virtual WebSocketChannel::SendResult send(const String& message) OVERRIDE;
71 virtual WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteO ffset, unsigned byteLength) OVERRIDE; 76 virtual WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteO ffset, unsigned byteLength) OVERRIDE;
72 virtual WebSocketChannel::SendResult send(const Blob&) OVERRIDE; 77 virtual WebSocketChannel::SendResult send(const Blob&) OVERRIDE;
73 virtual unsigned long bufferedAmount() const OVERRIDE; 78 virtual unsigned long bufferedAmount() const OVERRIDE;
74 // Start closing handshake. Use the CloseEventCodeNotSpecified for the code 79 // Start closing handshake. Use the CloseEventCodeNotSpecified for the code
75 // argument to omit payload. 80 // argument to omit payload.
76 virtual void close(int code, const String& reason) OVERRIDE; 81 virtual void close(int code, const String& reason) OVERRIDE;
77 virtual void fail(const String& reason) OVERRIDE; 82 virtual void fail(const String& reason, MessageLevel) OVERRIDE;
83 virtual void fail(const String& reason, MessageLevel, PassOwnPtr<CallStackWr apper>) OVERRIDE;
78 virtual void disconnect() OVERRIDE; 84 virtual void disconnect() OVERRIDE;
79 85
80 virtual void suspend() OVERRIDE; 86 virtual void suspend() OVERRIDE;
81 virtual void resume() OVERRIDE; 87 virtual void resume() OVERRIDE;
82 88
83 // SocketStreamHandleClient functions. 89 // SocketStreamHandleClient functions.
84 virtual void willOpenSocketStream(SocketStreamHandle*) OVERRIDE; 90 virtual void willOpenSocketStream(SocketStreamHandle*) OVERRIDE;
85 virtual void didOpenSocketStream(SocketStreamHandle*) OVERRIDE; 91 virtual void didOpenSocketStream(SocketStreamHandle*) OVERRIDE;
86 virtual void didCloseSocketStream(SocketStreamHandle*) OVERRIDE; 92 virtual void didCloseSocketStream(SocketStreamHandle*) OVERRIDE;
87 virtual void didReceiveSocketStreamData(SocketStreamHandle*, const char*, in t) OVERRIDE; 93 virtual void didReceiveSocketStreamData(SocketStreamHandle*, const char*, in t) OVERRIDE;
88 virtual void didUpdateBufferedAmount(SocketStreamHandle*, size_t bufferedAmo unt) OVERRIDE; 94 virtual void didUpdateBufferedAmount(SocketStreamHandle*, size_t bufferedAmo unt) OVERRIDE;
89 virtual void didFailSocketStream(SocketStreamHandle*, const SocketStreamErro r&) OVERRIDE; 95 virtual void didFailSocketStream(SocketStreamHandle*, const SocketStreamErro r&) OVERRIDE;
90 96
91 // FileReaderLoaderClient functions. 97 // FileReaderLoaderClient functions.
92 virtual void didStartLoading(); 98 virtual void didStartLoading();
93 virtual void didReceiveData(); 99 virtual void didReceiveData();
94 virtual void didFinishLoading(); 100 virtual void didFinishLoading();
95 virtual void didFail(int errorCode); 101 virtual void didFail(int errorCode);
96 102
97 using RefCounted<MainThreadWebSocketChannel>::ref; 103 using RefCounted<MainThreadWebSocketChannel>::ref;
98 using RefCounted<MainThreadWebSocketChannel>::deref; 104 using RefCounted<MainThreadWebSocketChannel>::deref;
99 105
100 protected: 106 protected:
101 // WebSocketChannel functions. 107 // WebSocketChannel functions.
102 virtual void refWebSocketChannel() OVERRIDE { ref(); } 108 virtual void refWebSocketChannel() OVERRIDE { ref(); }
103 virtual void derefWebSocketChannel() OVERRIDE { deref(); } 109 virtual void derefWebSocketChannel() OVERRIDE { deref(); }
104 110
105 private: 111 private:
106 MainThreadWebSocketChannel(Document*, WebSocketChannelClient*); 112 MainThreadWebSocketChannel(Document*, WebSocketChannelClient*);
113 MainThreadWebSocketChannel(Document*, WebSocketChannelClient*, const ScriptC allFrame&);
107 114
108 bool appendToBuffer(const char* data, size_t len); 115 bool appendToBuffer(const char* data, size_t len);
109 void skipBuffer(size_t len); 116 void skipBuffer(size_t len);
110 bool processBuffer(); 117 bool processBuffer();
111 void resumeTimerFired(Timer<MainThreadWebSocketChannel>*); 118 void resumeTimerFired(Timer<MainThreadWebSocketChannel>*);
112 void startClosingHandshake(int code, const String& reason); 119 void startClosingHandshake(int code, const String& reason);
113 void closingTimerFired(Timer<MainThreadWebSocketChannel>*); 120 void closingTimerFired(Timer<MainThreadWebSocketChannel>*);
121 void failInternal();
114 122
115 bool processFrame(); 123 bool processFrame();
116 124
117 // It is allowed to send a Blob as a binary frame if hybi-10 protocol is in use. Sending a Blob 125 // It is allowed to send a Blob as a binary frame if hybi-10 protocol is in use. Sending a Blob
118 // can be delayed because it must be read asynchronously. Other types of dat a (String or 126 // can be delayed because it must be read asynchronously. Other types of dat a (String or
119 // ArrayBuffer) may also be blocked by preceding sending request of a Blob. 127 // ArrayBuffer) may also be blocked by preceding sending request of a Blob.
120 // 128 //
121 // To address this situation, messages to be sent need to be stored in a que ue. Whenever a new 129 // To address this situation, messages to be sent need to be stored in a que ue. Whenever a new
122 // data frame is going to be sent, it first must go to the queue. Items in t he queue are processed 130 // data frame is going to be sent, it first must go to the queue. Items in t he queue are processed
123 // in the order they were put into the queue. Sending request of a Blob bloc ks further processing 131 // in the order they were put into the queue. Sending request of a Blob bloc ks further processing
124 // until the Blob is completely read and sent to the socket stream. 132 // until the Blob is completely read and sent to the socket stream.
125 enum QueuedFrameType { 133 enum QueuedFrameType {
126 QueuedFrameTypeString, 134 QueuedFrameTypeString,
127 QueuedFrameTypeVector, 135 QueuedFrameTypeVector,
128 QueuedFrameTypeBlob 136 QueuedFrameTypeBlob
129 }; 137 };
130 struct QueuedFrame { 138 struct QueuedFrame {
131 WebSocketFrame::OpCode opCode; 139 WebSocketFrame::OpCode opCode;
132 QueuedFrameType frameType; 140 QueuedFrameType frameType;
133 // Only one of the following items is used, according to the value of fr ameType. 141 // Only one of the following items is used, according to the value of fr ameType.
134 CString stringData; 142 CString stringData;
135 Vector<char> vectorData; 143 Vector<char> vectorData;
136 RefPtr<Blob> blobData; 144 RefPtr<Blob> blobData;
137 }; 145 };
138 void enqueueTextFrame(const CString&); 146 void enqueueTextFrame(const CString&);
139 void enqueueRawFrame(WebSocketFrame::OpCode, const char* data, size_t dataLe ngth); 147 void enqueueRawFrame(WebSocketFrame::OpCode, const char* data, size_t dataLe ngth);
140 void enqueueBlobFrame(WebSocketFrame::OpCode, const Blob&); 148 void enqueueBlobFrame(WebSocketFrame::OpCode, const Blob&);
141 149
150 void failAsError(const String& reason) { fail(reason, ErrorMessageLevel); }
142 void processOutgoingFrameQueue(); 151 void processOutgoingFrameQueue();
143 void abortOutgoingFrameQueue(); 152 void abortOutgoingFrameQueue();
144 153
145 enum OutgoingFrameQueueStatus { 154 enum OutgoingFrameQueueStatus {
146 // It is allowed to put a new item into the queue. 155 // It is allowed to put a new item into the queue.
147 OutgoingFrameQueueOpen, 156 OutgoingFrameQueueOpen,
148 // Close frame has already been put into the queue but may not have been sent yet; 157 // Close frame has already been put into the queue but may not have been sent yet;
149 // m_handle->close() will be called as soon as the queue is cleared. It is not 158 // m_handle->close() will be called as soon as the queue is cleared. It is not
150 // allowed to put a new item into the queue. 159 // allowed to put a new item into the queue.
151 OutgoingFrameQueueClosing, 160 OutgoingFrameQueueClosing,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 OwnPtr<FileReaderLoader> m_blobLoader; 207 OwnPtr<FileReaderLoader> m_blobLoader;
199 BlobLoaderStatus m_blobLoaderStatus; 208 BlobLoaderStatus m_blobLoaderStatus;
200 209
201 ScriptCallFrame m_callFrameAtConnection; 210 ScriptCallFrame m_callFrameAtConnection;
202 WebSocketDeflateFramer m_deflateFramer; 211 WebSocketDeflateFramer m_deflateFramer;
203 }; 212 };
204 213
205 } // namespace WebCore 214 } // namespace WebCore
206 215
207 #endif // MainThreadWebSocketChannel_h 216 #endif // MainThreadWebSocketChannel_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698