| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 10 matching lines...) Expand all Loading... |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 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 NewWebSocketChannelImpl_h | 31 #ifndef DocumentWebSocketChannel_h |
| 32 #define NewWebSocketChannelImpl_h | 32 #define DocumentWebSocketChannel_h |
| 33 | 33 |
| 34 #include "core/dom/ContextLifecycleObserver.h" | 34 #include "core/dom/ContextLifecycleObserver.h" |
| 35 #include "core/fileapi/Blob.h" | 35 #include "core/fileapi/Blob.h" |
| 36 #include "core/fileapi/FileError.h" | 36 #include "core/fileapi/FileError.h" |
| 37 #include "core/frame/ConsoleTypes.h" | 37 #include "core/frame/ConsoleTypes.h" |
| 38 #include "modules/websockets/WebSocketChannel.h" | 38 #include "modules/websockets/WebSocketChannel.h" |
| 39 #include "platform/weborigin/KURL.h" | 39 #include "platform/weborigin/KURL.h" |
| 40 #include "public/platform/WebSocketHandle.h" | 40 #include "public/platform/WebSocketHandle.h" |
| 41 #include "public/platform/WebSocketHandleClient.h" | 41 #include "public/platform/WebSocketHandleClient.h" |
| 42 #include "wtf/ArrayBuffer.h" | 42 #include "wtf/ArrayBuffer.h" |
| 43 #include "wtf/Deque.h" | 43 #include "wtf/Deque.h" |
| 44 #include "wtf/FastAllocBase.h" | 44 #include "wtf/FastAllocBase.h" |
| 45 #include "wtf/OwnPtr.h" | 45 #include "wtf/OwnPtr.h" |
| 46 #include "wtf/PassOwnPtr.h" | 46 #include "wtf/PassOwnPtr.h" |
| 47 #include "wtf/PassRefPtr.h" | 47 #include "wtf/PassRefPtr.h" |
| 48 #include "wtf/RefPtr.h" | 48 #include "wtf/RefPtr.h" |
| 49 #include "wtf/Vector.h" | 49 #include "wtf/Vector.h" |
| 50 #include "wtf/text/CString.h" | 50 #include "wtf/text/CString.h" |
| 51 #include "wtf/text/WTFString.h" | 51 #include "wtf/text/WTFString.h" |
| 52 | 52 |
| 53 namespace blink { | 53 namespace blink { |
| 54 | 54 |
| 55 class Document; | 55 class Document; |
| 56 class WebSocketHandshakeRequest; | 56 class WebSocketHandshakeRequest; |
| 57 class WebSocketHandshakeRequestInfo; | 57 class WebSocketHandshakeRequestInfo; |
| 58 class WebSocketHandshakeResponseInfo; | 58 class WebSocketHandshakeResponseInfo; |
| 59 | 59 |
| 60 // This class may replace MainThreadWebSocketChannel. | 60 // This class is a WebSocketChannel subclass that works with a Document in a |
| 61 class NewWebSocketChannelImpl final : public WebSocketChannel, public WebSocketH
andleClient, public ContextLifecycleObserver { | 61 // DOMWindow (i.e. works in the main thread). |
| 62 class DocumentWebSocketChannel final : public WebSocketChannel, public WebSocket
HandleClient, public ContextLifecycleObserver { |
| 62 public: | 63 public: |
| 63 // You can specify the source file and the line number information | 64 // You can specify the source file and the line number information |
| 64 // explicitly by passing the last parameter. | 65 // explicitly by passing the last parameter. |
| 65 // In the usual case, they are set automatically and you don't have to | 66 // In the usual case, they are set automatically and you don't have to |
| 66 // pass it. | 67 // pass it. |
| 67 // Specify handle explicitly only in tests. | 68 // Specify handle explicitly only in tests. |
| 68 static NewWebSocketChannelImpl* create(ExecutionContext* context, WebSocketC
hannelClient* client, const String& sourceURL = String(), unsigned lineNumber =
0, WebSocketHandle *handle = 0) | 69 static DocumentWebSocketChannel* create(ExecutionContext* context, WebSocket
ChannelClient* client, const String& sourceURL = String(), unsigned lineNumber =
0, WebSocketHandle *handle = 0) |
| 69 { | 70 { |
| 70 return new NewWebSocketChannelImpl(context, client, sourceURL, lineNumbe
r, handle); | 71 return new DocumentWebSocketChannel(context, client, sourceURL, lineNumb
er, handle); |
| 71 } | 72 } |
| 72 virtual ~NewWebSocketChannelImpl(); | 73 virtual ~DocumentWebSocketChannel(); |
| 73 | 74 |
| 74 // WebSocketChannel functions. | 75 // WebSocketChannel functions. |
| 75 virtual bool connect(const KURL&, const String& protocol) override; | 76 virtual bool connect(const KURL&, const String& protocol) override; |
| 76 virtual void send(const String& message) override; | 77 virtual void send(const String& message) override; |
| 77 virtual void send(const ArrayBuffer&, unsigned byteOffset, unsigned byteLeng
th) override; | 78 virtual void send(const ArrayBuffer&, unsigned byteOffset, unsigned byteLeng
th) override; |
| 78 virtual void send(PassRefPtr<BlobDataHandle>) override; | 79 virtual void send(PassRefPtr<BlobDataHandle>) override; |
| 79 virtual void send(PassOwnPtr<Vector<char> > data) override; | 80 virtual void send(PassOwnPtr<Vector<char> > data) override; |
| 80 // Start closing handshake. Use the CloseEventCodeNotSpecified for the code | 81 // Start closing handshake. Use the CloseEventCodeNotSpecified for the code |
| 81 // argument to omit payload. | 82 // argument to omit payload. |
| 82 virtual void close(int code, const String& reason) override; | 83 virtual void close(int code, const String& reason) override; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 String reason; | 115 String reason; |
| 115 }; | 116 }; |
| 116 | 117 |
| 117 struct ReceivedMessage { | 118 struct ReceivedMessage { |
| 118 bool isMessageText; | 119 bool isMessageText; |
| 119 Vector<char> data; | 120 Vector<char> data; |
| 120 }; | 121 }; |
| 121 | 122 |
| 122 class BlobLoader; | 123 class BlobLoader; |
| 123 | 124 |
| 124 NewWebSocketChannelImpl(ExecutionContext*, WebSocketChannelClient*, const St
ring&, unsigned, WebSocketHandle*); | 125 DocumentWebSocketChannel(ExecutionContext*, WebSocketChannelClient*, const S
tring&, unsigned, WebSocketHandle*); |
| 125 void sendInternal(); | 126 void sendInternal(); |
| 126 void flowControlIfNecessary(); | 127 void flowControlIfNecessary(); |
| 127 void failAsError(const String& reason) { fail(reason, ErrorMessageLevel, m_s
ourceURLAtConstruction, m_lineNumberAtConstruction); } | 128 void failAsError(const String& reason) { fail(reason, ErrorMessageLevel, m_s
ourceURLAtConstruction, m_lineNumberAtConstruction); } |
| 128 void abortAsyncOperations(); | 129 void abortAsyncOperations(); |
| 129 void handleDidClose(bool wasClean, unsigned short code, const String& reason
); | 130 void handleDidClose(bool wasClean, unsigned short code, const String& reason
); |
| 130 Document* document(); // can be called only when m_identifier > 0. | 131 Document* document(); // can be called only when m_identifier > 0. |
| 131 | 132 |
| 132 // WebSocketHandleClient functions. | 133 // WebSocketHandleClient functions. |
| 133 virtual void didConnect(WebSocketHandle*, bool fail, const WebString& select
edProtocol, const WebString& extensions) override; | 134 virtual void didConnect(WebSocketHandle*, bool fail, const WebString& select
edProtocol, const WebString& extensions) override; |
| 134 virtual void didStartOpeningHandshake(WebSocketHandle*, const WebSocketHands
hakeRequestInfo&) override; | 135 virtual void didStartOpeningHandshake(WebSocketHandle*, const WebSocketHands
hakeRequestInfo&) override; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 | 181 |
| 181 String m_sourceURLAtConstruction; | 182 String m_sourceURLAtConstruction; |
| 182 unsigned m_lineNumberAtConstruction; | 183 unsigned m_lineNumberAtConstruction; |
| 183 RefPtr<WebSocketHandshakeRequest> m_handshakeRequest; | 184 RefPtr<WebSocketHandshakeRequest> m_handshakeRequest; |
| 184 | 185 |
| 185 static const int64_t receivedDataSizeForFlowControlHighWaterMark = 1 << 15; | 186 static const int64_t receivedDataSizeForFlowControlHighWaterMark = 1 << 15; |
| 186 }; | 187 }; |
| 187 | 188 |
| 188 } // namespace blink | 189 } // namespace blink |
| 189 | 190 |
| 190 #endif // NewWebSocketChannelImpl_h | 191 #endif // DocumentWebSocketChannel_h |
| OLD | NEW |