| OLD | NEW |
| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 return adoptRefWillBeRefCountedGarbageCollected(new MainThreadWebSocketC
hannel(document, client, sourceURL, lineNumber)); | 68 return adoptRefWillBeRefCountedGarbageCollected(new MainThreadWebSocketC
hannel(document, client, sourceURL, lineNumber)); |
| 69 } | 69 } |
| 70 virtual ~MainThreadWebSocketChannel(); | 70 virtual ~MainThreadWebSocketChannel(); |
| 71 | 71 |
| 72 // WebSocketChannel functions. | 72 // WebSocketChannel functions. |
| 73 virtual bool connect(const KURL&, const String& protocol) OVERRIDE; | 73 virtual bool connect(const KURL&, const String& protocol) OVERRIDE; |
| 74 virtual WebSocketChannel::SendResult send(const String& message) OVERRIDE; | 74 virtual WebSocketChannel::SendResult send(const String& message) OVERRIDE; |
| 75 virtual WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteO
ffset, unsigned byteLength) OVERRIDE; | 75 virtual WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteO
ffset, unsigned byteLength) OVERRIDE; |
| 76 virtual WebSocketChannel::SendResult send(PassRefPtr<BlobDataHandle>) OVERRI
DE; | 76 virtual WebSocketChannel::SendResult send(PassRefPtr<BlobDataHandle>) OVERRI
DE; |
| 77 virtual WebSocketChannel::SendResult send(PassOwnPtr<Vector<char> > data) OV
ERRIDE; | 77 virtual WebSocketChannel::SendResult send(PassOwnPtr<Vector<char> > data) OV
ERRIDE; |
| 78 virtual unsigned long bufferedAmount() const OVERRIDE; | |
| 79 // Start closing handshake. Use the CloseEventCodeNotSpecified for the code | 78 // Start closing handshake. Use the CloseEventCodeNotSpecified for the code |
| 80 // argument to omit payload. | 79 // argument to omit payload. |
| 81 virtual void close(int code, const String& reason) OVERRIDE; | 80 virtual void close(int code, const String& reason) OVERRIDE; |
| 82 virtual void fail(const String& reason, MessageLevel, const String&, unsigne
d lineNumber) OVERRIDE; | 81 virtual void fail(const String& reason, MessageLevel, const String&, unsigne
d lineNumber) OVERRIDE; |
| 83 virtual void disconnect() OVERRIDE; | 82 virtual void disconnect() OVERRIDE; |
| 84 | 83 |
| 85 virtual void suspend() OVERRIDE; | 84 virtual void suspend() OVERRIDE; |
| 86 virtual void resume() OVERRIDE; | 85 virtual void resume() OVERRIDE; |
| 87 | 86 |
| 88 // SocketStreamHandleClient functions. | 87 // SocketStreamHandleClient functions. |
| 89 virtual void didOpenSocketStream(SocketStreamHandle*) OVERRIDE; | 88 virtual void didOpenSocketStream(SocketStreamHandle*) OVERRIDE; |
| 90 virtual void didCloseSocketStream(SocketStreamHandle*) OVERRIDE; | 89 virtual void didCloseSocketStream(SocketStreamHandle*) OVERRIDE; |
| 91 virtual void didReceiveSocketStreamData(SocketStreamHandle*, const char*, in
t) OVERRIDE; | 90 virtual void didReceiveSocketStreamData(SocketStreamHandle*, const char*, in
t) OVERRIDE; |
| 92 virtual void didUpdateBufferedAmount(SocketStreamHandle*, size_t bufferedAmo
unt) OVERRIDE; | 91 virtual void didConsumeBufferedAmount(SocketStreamHandle*, size_t consumed)
OVERRIDE; |
| 93 virtual void didFailSocketStream(SocketStreamHandle*, const SocketStreamErro
r&) OVERRIDE; | 92 virtual void didFailSocketStream(SocketStreamHandle*, const SocketStreamErro
r&) OVERRIDE; |
| 94 | 93 |
| 95 // FileReaderLoaderClient functions. | 94 // FileReaderLoaderClient functions. |
| 96 virtual void didStartLoading() OVERRIDE; | 95 virtual void didStartLoading() OVERRIDE; |
| 97 virtual void didReceiveData() OVERRIDE; | 96 virtual void didReceiveData() OVERRIDE; |
| 98 virtual void didFinishLoading() OVERRIDE; | 97 virtual void didFinishLoading() OVERRIDE; |
| 99 virtual void didFail(FileError::ErrorCode) OVERRIDE; | 98 virtual void didFail(FileError::ErrorCode) OVERRIDE; |
| 100 | 99 |
| 101 private: | 100 private: |
| 102 MainThreadWebSocketChannel(Document*, WebSocketChannelClient*, const String&
, unsigned); | 101 MainThreadWebSocketChannel(Document*, WebSocketChannelClient*, const String&
, unsigned); |
| 103 | 102 |
| 103 class FramingOverhead { |
| 104 public: |
| 105 FramingOverhead(WebSocketFrame::OpCode opcode, size_t frameDataSize, siz
e_t originalPayloadLength) |
| 106 : m_opcode(opcode) |
| 107 , m_frameDataSize(frameDataSize) |
| 108 , m_originalPayloadLength(originalPayloadLength) |
| 109 { |
| 110 } |
| 111 |
| 112 WebSocketFrame::OpCode opcode() const { return m_opcode; } |
| 113 size_t frameDataSize() const { return m_frameDataSize; } |
| 114 size_t originalPayloadLength() const { return m_originalPayloadLength; } |
| 115 |
| 116 private: |
| 117 WebSocketFrame::OpCode m_opcode; |
| 118 size_t m_frameDataSize; |
| 119 size_t m_originalPayloadLength; |
| 120 }; |
| 121 |
| 104 void clearDocument(); | 122 void clearDocument(); |
| 105 | 123 |
| 106 void disconnectHandle(); | 124 void disconnectHandle(); |
| 107 | 125 |
| 108 // Calls didReceiveMessageError() on m_client if we haven't yet. | 126 // Calls didReceiveMessageError() on m_client if we haven't yet. |
| 109 void callDidReceiveMessageError(); | 127 void callDidReceiveMessageError(); |
| 110 | 128 |
| 111 bool appendToBuffer(const char* data, size_t len); | 129 bool appendToBuffer(const char* data, size_t len); |
| 112 void skipBuffer(size_t len); | 130 void skipBuffer(size_t len); |
| 113 // Repeats parsing data from m_buffer until instructed to stop. | 131 // Repeats parsing data from m_buffer until instructed to stop. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 207 |
| 190 Timer<MainThreadWebSocketChannel> m_resumeTimer; | 208 Timer<MainThreadWebSocketChannel> m_resumeTimer; |
| 191 bool m_suspended; | 209 bool m_suspended; |
| 192 bool m_didFailOfClientAlreadyRun; | 210 bool m_didFailOfClientAlreadyRun; |
| 193 // Set to true iff this instance called disconnect() on m_handle. | 211 // Set to true iff this instance called disconnect() on m_handle. |
| 194 bool m_hasCalledDisconnectOnHandle; | 212 bool m_hasCalledDisconnectOnHandle; |
| 195 bool m_receivedClosingHandshake; | 213 bool m_receivedClosingHandshake; |
| 196 Timer<MainThreadWebSocketChannel> m_closingTimer; | 214 Timer<MainThreadWebSocketChannel> m_closingTimer; |
| 197 ChannelState m_state; | 215 ChannelState m_state; |
| 198 bool m_shouldDiscardReceivedData; | 216 bool m_shouldDiscardReceivedData; |
| 199 unsigned long m_unhandledBufferedAmount; | |
| 200 | 217 |
| 201 unsigned long m_identifier; // m_identifier == 0 means that we could not obt
ain a valid identifier. | 218 unsigned long m_identifier; // m_identifier == 0 means that we could not obt
ain a valid identifier. |
| 202 | 219 |
| 203 // Private members only for hybi-10 protocol. | 220 // Private members only for hybi-10 protocol. |
| 204 bool m_hasContinuousFrame; | 221 bool m_hasContinuousFrame; |
| 205 WebSocketFrame::OpCode m_continuousFrameOpCode; | 222 WebSocketFrame::OpCode m_continuousFrameOpCode; |
| 206 Vector<char> m_continuousFrameData; | 223 Vector<char> m_continuousFrameData; |
| 207 unsigned short m_closeEventCode; | 224 unsigned short m_closeEventCode; |
| 208 String m_closeEventReason; | 225 String m_closeEventReason; |
| 209 | 226 |
| 210 Deque<OwnPtr<QueuedFrame> > m_outgoingFrameQueue; | 227 Deque<OwnPtr<QueuedFrame> > m_outgoingFrameQueue; |
| 211 OutgoingFrameQueueStatus m_outgoingFrameQueueStatus; | 228 OutgoingFrameQueueStatus m_outgoingFrameQueueStatus; |
| 229 Deque<FramingOverhead> m_framingOverheadQueue; |
| 230 // The number of bytes that are already consumed (i.e. sent) in the |
| 231 // current frame. |
| 232 size_t m_numConsumedBytesInCurrentFrame; |
| 212 | 233 |
| 213 // FIXME: Load two or more Blobs simultaneously for better performance. | 234 // FIXME: Load two or more Blobs simultaneously for better performance. |
| 214 OwnPtr<FileReaderLoader> m_blobLoader; | 235 OwnPtr<FileReaderLoader> m_blobLoader; |
| 215 BlobLoaderStatus m_blobLoaderStatus; | 236 BlobLoaderStatus m_blobLoaderStatus; |
| 216 | 237 |
| 217 // Source code position where construction happened. To be used to show a | 238 // Source code position where construction happened. To be used to show a |
| 218 // console message where no JS callstack info available. | 239 // console message where no JS callstack info available. |
| 219 String m_sourceURLAtConstruction; | 240 String m_sourceURLAtConstruction; |
| 220 unsigned m_lineNumberAtConstruction; | 241 unsigned m_lineNumberAtConstruction; |
| 221 | 242 |
| 222 WebSocketPerMessageDeflate m_perMessageDeflate; | 243 WebSocketPerMessageDeflate m_perMessageDeflate; |
| 223 | 244 |
| 224 WebSocketDeflateFramer m_deflateFramer; | 245 WebSocketDeflateFramer m_deflateFramer; |
| 225 }; | 246 }; |
| 226 | 247 |
| 227 } // namespace WebCore | 248 } // namespace WebCore |
| 228 | 249 |
| 229 #endif // MainThreadWebSocketChannel_h | 250 #endif // MainThreadWebSocketChannel_h |
| OLD | NEW |