| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 #include "modules/websockets/WebSocketPerMessageDeflate.h" | 43 #include "modules/websockets/WebSocketPerMessageDeflate.h" |
| 44 #include "wtf/Deque.h" | 44 #include "wtf/Deque.h" |
| 45 #include "wtf/Forward.h" | 45 #include "wtf/Forward.h" |
| 46 #include "wtf/PassOwnPtr.h" | 46 #include "wtf/PassOwnPtr.h" |
| 47 #include "wtf/RefCounted.h" | 47 #include "wtf/RefCounted.h" |
| 48 #include "wtf/Vector.h" | 48 #include "wtf/Vector.h" |
| 49 #include "wtf/text/CString.h" | 49 #include "wtf/text/CString.h" |
| 50 | 50 |
| 51 namespace WebCore { | 51 namespace WebCore { |
| 52 | 52 |
| 53 class Blob; | 53 class BlobDataHandle; |
| 54 class Document; | 54 class Document; |
| 55 class FileReaderLoader; | 55 class FileReaderLoader; |
| 56 class SocketStreamHandle; | 56 class SocketStreamHandle; |
| 57 class SocketStreamError; | 57 class SocketStreamError; |
| 58 class WebSocketChannelClient; | 58 class WebSocketChannelClient; |
| 59 | 59 |
| 60 class MainThreadWebSocketChannel : public RefCounted<MainThreadWebSocketChannel>
, public SocketStreamHandleClient, public WebSocketChannel, public FileReaderLoa
derClient { | 60 class MainThreadWebSocketChannel : public RefCounted<MainThreadWebSocketChannel>
, public SocketStreamHandleClient, public WebSocketChannel, public FileReaderLoa
derClient { |
| 61 WTF_MAKE_FAST_ALLOCATED; | 61 WTF_MAKE_FAST_ALLOCATED; |
| 62 public: | 62 public: |
| 63 // You can specify the source file and the line number information | 63 // You can specify the source file and the line number information |
| 64 // explicitly by passing the last parameter. | 64 // explicitly by passing the last parameter. |
| 65 // In the usual case, they are set automatically and you don't have to | 65 // In the usual case, they are set automatically and you don't have to |
| 66 // pass it. | 66 // pass it. |
| 67 static PassRefPtr<MainThreadWebSocketChannel> create(Document* document, Web
SocketChannelClient* client, const String& sourceURL = String(), unsigned lineNu
mber = 0) { return adoptRef(new MainThreadWebSocketChannel(document, client, sou
rceURL, lineNumber)); } | 67 static PassRefPtr<MainThreadWebSocketChannel> create(Document* document, Web
SocketChannelClient* client, const String& sourceURL = String(), unsigned lineNu
mber = 0) { return adoptRef(new MainThreadWebSocketChannel(document, client, sou
rceURL, lineNumber)); } |
| 68 virtual ~MainThreadWebSocketChannel(); | 68 virtual ~MainThreadWebSocketChannel(); |
| 69 | 69 |
| 70 bool send(const char* data, int length); | 70 bool send(const char* data, int length); |
| 71 | 71 |
| 72 // WebSocketChannel functions. | 72 // WebSocketChannel functions. |
| 73 virtual void connect(const KURL&, const String& protocol) OVERRIDE; | 73 virtual void connect(const KURL&, const String& protocol) OVERRIDE; |
| 74 virtual String subprotocol() OVERRIDE; | 74 virtual String subprotocol() OVERRIDE; |
| 75 virtual String extensions() OVERRIDE; | 75 virtual String extensions() OVERRIDE; |
| 76 virtual WebSocketChannel::SendResult send(const String& message) OVERRIDE; | 76 virtual WebSocketChannel::SendResult send(const String& message) OVERRIDE; |
| 77 virtual WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteO
ffset, unsigned byteLength) OVERRIDE; | 77 virtual WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteO
ffset, unsigned byteLength) OVERRIDE; |
| 78 virtual WebSocketChannel::SendResult send(const Blob&) OVERRIDE; | 78 virtual WebSocketChannel::SendResult send(PassRefPtr<BlobDataHandle>) OVERRI
DE; |
| 79 virtual unsigned long bufferedAmount() const OVERRIDE; | 79 virtual unsigned long bufferedAmount() const OVERRIDE; |
| 80 // Start closing handshake. Use the CloseEventCodeNotSpecified for the code | 80 // Start closing handshake. Use the CloseEventCodeNotSpecified for the code |
| 81 // argument to omit payload. | 81 // argument to omit payload. |
| 82 virtual void close(int code, const String& reason) OVERRIDE; | 82 virtual void close(int code, const String& reason) OVERRIDE; |
| 83 virtual void fail(const String& reason, MessageLevel, const String&, unsigne
d lineNumber) OVERRIDE; | 83 virtual void fail(const String& reason, MessageLevel, const String&, unsigne
d lineNumber) OVERRIDE; |
| 84 using WebSocketChannel::fail; | 84 using WebSocketChannel::fail; |
| 85 virtual void disconnect() OVERRIDE; | 85 virtual void disconnect() OVERRIDE; |
| 86 | 86 |
| 87 virtual void suspend() OVERRIDE; | 87 virtual void suspend() OVERRIDE; |
| 88 virtual void resume() OVERRIDE; | 88 virtual void resume() OVERRIDE; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 QueuedFrameTypeString, | 133 QueuedFrameTypeString, |
| 134 QueuedFrameTypeVector, | 134 QueuedFrameTypeVector, |
| 135 QueuedFrameTypeBlob | 135 QueuedFrameTypeBlob |
| 136 }; | 136 }; |
| 137 struct QueuedFrame { | 137 struct QueuedFrame { |
| 138 WebSocketFrame::OpCode opCode; | 138 WebSocketFrame::OpCode opCode; |
| 139 QueuedFrameType frameType; | 139 QueuedFrameType frameType; |
| 140 // Only one of the following items is used, according to the value of fr
ameType. | 140 // Only one of the following items is used, according to the value of fr
ameType. |
| 141 CString stringData; | 141 CString stringData; |
| 142 Vector<char> vectorData; | 142 Vector<char> vectorData; |
| 143 RefPtr<Blob> blobData; | 143 RefPtr<BlobDataHandle> blobData; |
| 144 }; | 144 }; |
| 145 void enqueueTextFrame(const CString&); | 145 void enqueueTextFrame(const CString&); |
| 146 void enqueueRawFrame(WebSocketFrame::OpCode, const char* data, size_t dataLe
ngth); | 146 void enqueueRawFrame(WebSocketFrame::OpCode, const char* data, size_t dataLe
ngth); |
| 147 void enqueueBlobFrame(WebSocketFrame::OpCode, const Blob&); | 147 void enqueueBlobFrame(WebSocketFrame::OpCode, PassRefPtr<BlobDataHandle>); |
| 148 | 148 |
| 149 void failAsError(const String& reason) { fail(reason, ErrorMessageLevel, m_s
ourceURLAtConnection, m_lineNumberAtConnection); } | 149 void failAsError(const String& reason) { fail(reason, ErrorMessageLevel, m_s
ourceURLAtConnection, m_lineNumberAtConnection); } |
| 150 void processOutgoingFrameQueue(); | 150 void processOutgoingFrameQueue(); |
| 151 void abortOutgoingFrameQueue(); | 151 void abortOutgoingFrameQueue(); |
| 152 | 152 |
| 153 enum OutgoingFrameQueueStatus { | 153 enum OutgoingFrameQueueStatus { |
| 154 // It is allowed to put a new item into the queue. | 154 // It is allowed to put a new item into the queue. |
| 155 OutgoingFrameQueueOpen, | 155 OutgoingFrameQueueOpen, |
| 156 // Close frame has already been put into the queue but may not have been
sent yet; | 156 // Close frame has already been put into the queue but may not have been
sent yet; |
| 157 // m_handle->close() will be called as soon as the queue is cleared. It
is not | 157 // m_handle->close() will be called as soon as the queue is cleared. It
is not |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 | 213 |
| 214 String m_sourceURLAtConnection; | 214 String m_sourceURLAtConnection; |
| 215 unsigned m_lineNumberAtConnection; | 215 unsigned m_lineNumberAtConnection; |
| 216 WebSocketPerMessageDeflate m_perMessageDeflate; | 216 WebSocketPerMessageDeflate m_perMessageDeflate; |
| 217 WebSocketDeflateFramer m_deflateFramer; | 217 WebSocketDeflateFramer m_deflateFramer; |
| 218 }; | 218 }; |
| 219 | 219 |
| 220 } // namespace WebCore | 220 } // namespace WebCore |
| 221 | 221 |
| 222 #endif // MainThreadWebSocketChannel_h | 222 #endif // MainThreadWebSocketChannel_h |
| OLD | NEW |