Chromium Code Reviews| 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 15 matching lines...) Expand all Loading... | |
| 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 static PassRefPtr<MainThreadWebSocketChannel> create(Document* document, Web SocketChannelClient* client, const ScriptCallFrame& frame) { return adoptRef(new MainThreadWebSocketChannel(document, client, frame)); } | |
| 62 virtual ~MainThreadWebSocketChannel(); | 65 virtual ~MainThreadWebSocketChannel(); |
| 63 | 66 |
| 64 bool send(const char* data, int length); | 67 bool send(const char* data, int length); |
| 65 | 68 |
| 66 // WebSocketChannel functions. | 69 // WebSocketChannel functions. |
| 67 virtual void connect(const KURL&, const String& protocol) OVERRIDE; | 70 virtual void connect(const KURL&, const String& protocol) OVERRIDE; |
| 68 virtual String subprotocol() OVERRIDE; | 71 virtual String subprotocol() OVERRIDE; |
| 69 virtual String extensions() OVERRIDE; | 72 virtual String extensions() OVERRIDE; |
| 70 virtual WebSocketChannel::SendResult send(const String& message) OVERRIDE; | 73 virtual WebSocketChannel::SendResult send(const String& message) OVERRIDE; |
| 71 virtual WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteO ffset, unsigned byteLength) OVERRIDE; | 74 virtual WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteO ffset, unsigned byteLength) OVERRIDE; |
| 72 virtual WebSocketChannel::SendResult send(const Blob&) OVERRIDE; | 75 virtual WebSocketChannel::SendResult send(const Blob&) OVERRIDE; |
| 73 virtual unsigned long bufferedAmount() const OVERRIDE; | 76 virtual unsigned long bufferedAmount() const OVERRIDE; |
| 74 // Start closing handshake. Use the CloseEventCodeNotSpecified for the code | 77 // Start closing handshake. Use the CloseEventCodeNotSpecified for the code |
| 75 // argument to omit payload. | 78 // argument to omit payload. |
| 76 virtual void close(int code, const String& reason) OVERRIDE; | 79 virtual void close(int code, const String& reason) OVERRIDE; |
| 77 virtual void fail(const String& reason) OVERRIDE; | 80 void fail(const String& reason) { fail(reason, ErrorMessageLevel); } |
|
tyoshino (SeeGerritForStatus)
2013/05/01 08:03:23
how about renaming this to failAsError and make th
yhirano
2013/05/01 09:31:44
Done.
| |
| 81 virtual void fail(const String& reason, MessageLevel) OVERRIDE; | |
| 82 virtual void fail(const String& reason, MessageLevel, PassOwnPtr<CallStackWr apper>) OVERRIDE; | |
|
tyoshino (SeeGerritForStatus)
2013/05/01 08:03:23
Comment what this method is for.
yhirano
2013/05/01 09:31:44
Wrote the method description in WebSocketChannel.h
| |
| 78 virtual void disconnect() OVERRIDE; | 83 virtual void disconnect() OVERRIDE; |
| 79 | 84 |
| 80 virtual void suspend() OVERRIDE; | 85 virtual void suspend() OVERRIDE; |
| 81 virtual void resume() OVERRIDE; | 86 virtual void resume() OVERRIDE; |
| 82 | 87 |
| 83 // SocketStreamHandleClient functions. | 88 // SocketStreamHandleClient functions. |
| 84 virtual void willOpenSocketStream(SocketStreamHandle*) OVERRIDE; | 89 virtual void willOpenSocketStream(SocketStreamHandle*) OVERRIDE; |
| 85 virtual void didOpenSocketStream(SocketStreamHandle*) OVERRIDE; | 90 virtual void didOpenSocketStream(SocketStreamHandle*) OVERRIDE; |
| 86 virtual void didCloseSocketStream(SocketStreamHandle*) OVERRIDE; | 91 virtual void didCloseSocketStream(SocketStreamHandle*) OVERRIDE; |
| 87 virtual void didReceiveSocketStreamData(SocketStreamHandle*, const char*, in t) OVERRIDE; | 92 virtual void didReceiveSocketStreamData(SocketStreamHandle*, const char*, in t) OVERRIDE; |
| 88 virtual void didUpdateBufferedAmount(SocketStreamHandle*, size_t bufferedAmo unt) OVERRIDE; | 93 virtual void didUpdateBufferedAmount(SocketStreamHandle*, size_t bufferedAmo unt) OVERRIDE; |
| 89 virtual void didFailSocketStream(SocketStreamHandle*, const SocketStreamErro r&) OVERRIDE; | 94 virtual void didFailSocketStream(SocketStreamHandle*, const SocketStreamErro r&) OVERRIDE; |
| 90 | 95 |
| 91 // FileReaderLoaderClient functions. | 96 // FileReaderLoaderClient functions. |
| 92 virtual void didStartLoading(); | 97 virtual void didStartLoading(); |
| 93 virtual void didReceiveData(); | 98 virtual void didReceiveData(); |
| 94 virtual void didFinishLoading(); | 99 virtual void didFinishLoading(); |
| 95 virtual void didFail(int errorCode); | 100 virtual void didFail(int errorCode); |
| 96 | 101 |
| 97 using RefCounted<MainThreadWebSocketChannel>::ref; | 102 using RefCounted<MainThreadWebSocketChannel>::ref; |
| 98 using RefCounted<MainThreadWebSocketChannel>::deref; | 103 using RefCounted<MainThreadWebSocketChannel>::deref; |
| 99 | 104 |
| 100 protected: | 105 protected: |
| 101 // WebSocketChannel functions. | 106 // WebSocketChannel functions. |
| 102 virtual void refWebSocketChannel() OVERRIDE { ref(); } | 107 virtual void refWebSocketChannel() OVERRIDE { ref(); } |
| 103 virtual void derefWebSocketChannel() OVERRIDE { deref(); } | 108 virtual void derefWebSocketChannel() OVERRIDE { deref(); } |
| 104 | 109 |
| 105 private: | 110 private: |
| 106 MainThreadWebSocketChannel(Document*, WebSocketChannelClient*); | 111 MainThreadWebSocketChannel(Document*, WebSocketChannelClient*); |
| 112 MainThreadWebSocketChannel(Document*, WebSocketChannelClient*, const ScriptC allFrame&); | |
| 107 | 113 |
| 108 bool appendToBuffer(const char* data, size_t len); | 114 bool appendToBuffer(const char* data, size_t len); |
| 109 void skipBuffer(size_t len); | 115 void skipBuffer(size_t len); |
| 110 bool processBuffer(); | 116 bool processBuffer(); |
| 111 void resumeTimerFired(Timer<MainThreadWebSocketChannel>*); | 117 void resumeTimerFired(Timer<MainThreadWebSocketChannel>*); |
| 112 void startClosingHandshake(int code, const String& reason); | 118 void startClosingHandshake(int code, const String& reason); |
| 113 void closingTimerFired(Timer<MainThreadWebSocketChannel>*); | 119 void closingTimerFired(Timer<MainThreadWebSocketChannel>*); |
| 120 void failInternal(); | |
| 114 | 121 |
| 115 bool processFrame(); | 122 bool processFrame(); |
| 116 | 123 |
| 117 // It is allowed to send a Blob as a binary frame if hybi-10 protocol is in use. Sending a Blob | 124 // 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 | 125 // 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. | 126 // ArrayBuffer) may also be blocked by preceding sending request of a Blob. |
| 120 // | 127 // |
| 121 // To address this situation, messages to be sent need to be stored in a que ue. Whenever a new | 128 // 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 | 129 // 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 | 130 // in the order they were put into the queue. Sending request of a Blob bloc ks further processing |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 OwnPtr<FileReaderLoader> m_blobLoader; | 205 OwnPtr<FileReaderLoader> m_blobLoader; |
| 199 BlobLoaderStatus m_blobLoaderStatus; | 206 BlobLoaderStatus m_blobLoaderStatus; |
| 200 | 207 |
| 201 ScriptCallFrame m_callFrameAtConnection; | 208 ScriptCallFrame m_callFrameAtConnection; |
| 202 WebSocketDeflateFramer m_deflateFramer; | 209 WebSocketDeflateFramer m_deflateFramer; |
| 203 }; | 210 }; |
| 204 | 211 |
| 205 } // namespace WebCore | 212 } // namespace WebCore |
| 206 | 213 |
| 207 #endif // MainThreadWebSocketChannel_h | 214 #endif // MainThreadWebSocketChannel_h |
| OLD | NEW |