| 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 13 matching lines...) Expand all Loading... |
| 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 DocumentWebSocketChannel_h | 31 #ifndef DocumentWebSocketChannel_h |
| 32 #define DocumentWebSocketChannel_h | 32 #define DocumentWebSocketChannel_h |
| 33 | 33 |
| 34 #include "bindings/core/v8/SourceLocation.h" |
| 34 #include "core/dom/ContextLifecycleObserver.h" | 35 #include "core/dom/ContextLifecycleObserver.h" |
| 35 #include "core/fileapi/Blob.h" | 36 #include "core/fileapi/Blob.h" |
| 36 #include "core/fileapi/FileError.h" | 37 #include "core/fileapi/FileError.h" |
| 37 #include "modules/ModulesExport.h" | 38 #include "modules/ModulesExport.h" |
| 38 #include "modules/websockets/WebSocketChannel.h" | 39 #include "modules/websockets/WebSocketChannel.h" |
| 39 #include "platform/heap/Handle.h" | 40 #include "platform/heap/Handle.h" |
| 40 #include "platform/v8_inspector/public/ConsoleTypes.h" | 41 #include "platform/v8_inspector/public/ConsoleTypes.h" |
| 41 #include "platform/weborigin/KURL.h" | 42 #include "platform/weborigin/KURL.h" |
| 42 #include "public/platform/modules/websockets/WebSocketHandle.h" | 43 #include "public/platform/modules/websockets/WebSocketHandle.h" |
| 43 #include "public/platform/modules/websockets/WebSocketHandleClient.h" | 44 #include "public/platform/modules/websockets/WebSocketHandleClient.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 61 // This class is a WebSocketChannel subclass that works with a Document in a | 62 // This class is a WebSocketChannel subclass that works with a Document in a |
| 62 // DOMWindow (i.e. works in the main thread). | 63 // DOMWindow (i.e. works in the main thread). |
| 63 class MODULES_EXPORT DocumentWebSocketChannel final : public WebSocketChannel, p
ublic WebSocketHandleClient, public ContextLifecycleObserver { | 64 class MODULES_EXPORT DocumentWebSocketChannel final : public WebSocketChannel, p
ublic WebSocketHandleClient, public ContextLifecycleObserver { |
| 64 USING_GARBAGE_COLLECTED_MIXIN(DocumentWebSocketChannel); | 65 USING_GARBAGE_COLLECTED_MIXIN(DocumentWebSocketChannel); |
| 65 public: | 66 public: |
| 66 // You can specify the source file and the line number information | 67 // You can specify the source file and the line number information |
| 67 // explicitly by passing the last parameter. | 68 // explicitly by passing the last parameter. |
| 68 // In the usual case, they are set automatically and you don't have to | 69 // In the usual case, they are set automatically and you don't have to |
| 69 // pass it. | 70 // pass it. |
| 70 // Specify handle explicitly only in tests. | 71 // Specify handle explicitly only in tests. |
| 71 static DocumentWebSocketChannel* create(Document* document, WebSocketChannel
Client* client, const String& sourceURL = String(), unsigned lineNumber = 0, Web
SocketHandle *handle = 0) | 72 static DocumentWebSocketChannel* create(Document* document, WebSocketChannel
Client* client, PassOwnPtr<SourceLocation> location, WebSocketHandle *handle = 0
) |
| 72 { | 73 { |
| 73 return new DocumentWebSocketChannel(document, client, sourceURL, lineNum
ber, handle); | 74 return new DocumentWebSocketChannel(document, client, std::move(location
), handle); |
| 74 } | 75 } |
| 75 ~DocumentWebSocketChannel() override; | 76 ~DocumentWebSocketChannel() override; |
| 76 | 77 |
| 77 // WebSocketChannel functions. | 78 // WebSocketChannel functions. |
| 78 bool connect(const KURL&, const String& protocol) override; | 79 bool connect(const KURL&, const String& protocol) override; |
| 79 void send(const CString& message) override; | 80 void send(const CString& message) override; |
| 80 void send(const DOMArrayBuffer&, unsigned byteOffset, unsigned byteLength) o
verride; | 81 void send(const DOMArrayBuffer&, unsigned byteOffset, unsigned byteLength) o
verride; |
| 81 void send(PassRefPtr<BlobDataHandle>) override; | 82 void send(PassRefPtr<BlobDataHandle>) override; |
| 82 void sendTextAsCharVector(PassOwnPtr<Vector<char>> data) override; | 83 void sendTextAsCharVector(PassOwnPtr<Vector<char>> data) override; |
| 83 void sendBinaryAsCharVector(PassOwnPtr<Vector<char>> data) override; | 84 void sendBinaryAsCharVector(PassOwnPtr<Vector<char>> data) override; |
| 84 // Start closing handshake. Use the CloseEventCodeNotSpecified for the code | 85 // Start closing handshake. Use the CloseEventCodeNotSpecified for the code |
| 85 // argument to omit payload. | 86 // argument to omit payload. |
| 86 void close(int code, const String& reason) override; | 87 void close(int code, const String& reason) override; |
| 87 void fail(const String& reason, MessageLevel, const String&, unsigned lineNu
mber) override; | 88 void fail(const String& reason, MessageLevel, PassOwnPtr<SourceLocation>) ov
erride; |
| 88 void disconnect() override; | 89 void disconnect() override; |
| 89 | 90 |
| 90 DECLARE_VIRTUAL_TRACE(); | 91 DECLARE_VIRTUAL_TRACE(); |
| 91 | 92 |
| 92 private: | 93 private: |
| 93 class BlobLoader; | 94 class BlobLoader; |
| 94 class Message; | 95 class Message; |
| 95 | 96 |
| 96 enum MessageType { | 97 enum MessageType { |
| 97 MessageTypeText, | 98 MessageTypeText, |
| 98 MessageTypeBlob, | 99 MessageTypeBlob, |
| 99 MessageTypeArrayBuffer, | 100 MessageTypeArrayBuffer, |
| 100 MessageTypeTextAsCharVector, | 101 MessageTypeTextAsCharVector, |
| 101 MessageTypeBinaryAsCharVector, | 102 MessageTypeBinaryAsCharVector, |
| 102 MessageTypeClose, | 103 MessageTypeClose, |
| 103 }; | 104 }; |
| 104 | 105 |
| 105 struct ReceivedMessage { | 106 struct ReceivedMessage { |
| 106 bool isMessageText; | 107 bool isMessageText; |
| 107 Vector<char> data; | 108 Vector<char> data; |
| 108 }; | 109 }; |
| 109 | 110 |
| 110 DocumentWebSocketChannel(Document*, WebSocketChannelClient*, const String&,
unsigned, WebSocketHandle*); | 111 DocumentWebSocketChannel(Document*, WebSocketChannelClient*, PassOwnPtr<Sour
ceLocation>, WebSocketHandle*); |
| 111 void sendInternal(WebSocketHandle::MessageType, const char* data, size_t tot
alSize, uint64_t* consumedBufferedAmount); | 112 void sendInternal(WebSocketHandle::MessageType, const char* data, size_t tot
alSize, uint64_t* consumedBufferedAmount); |
| 112 void processSendQueue(); | 113 void processSendQueue(); |
| 113 void flowControlIfNecessary(); | 114 void flowControlIfNecessary(); |
| 114 void failAsError(const String& reason) { fail(reason, ErrorMessageLevel, m_s
ourceURLAtConstruction, m_lineNumberAtConstruction); } | 115 void failAsError(const String& reason) { fail(reason, ErrorMessageLevel, m_l
ocationAtConstruction->clone()); } |
| 115 void abortAsyncOperations(); | 116 void abortAsyncOperations(); |
| 116 void handleDidClose(bool wasClean, unsigned short code, const String& reason
); | 117 void handleDidClose(bool wasClean, unsigned short code, const String& reason
); |
| 117 Document* document(); | 118 Document* document(); |
| 118 | 119 |
| 119 // WebSocketHandleClient functions. | 120 // WebSocketHandleClient functions. |
| 120 void didConnect(WebSocketHandle*, const WebString& selectedProtocol, const W
ebString& extensions) override; | 121 void didConnect(WebSocketHandle*, const WebString& selectedProtocol, const W
ebString& extensions) override; |
| 121 void didStartOpeningHandshake(WebSocketHandle*, const WebSocketHandshakeRequ
estInfo&) override; | 122 void didStartOpeningHandshake(WebSocketHandle*, const WebSocketHandshakeRequ
estInfo&) override; |
| 122 void didFinishOpeningHandshake(WebSocketHandle*, const WebSocketHandshakeRes
ponseInfo&) override; | 123 void didFinishOpeningHandshake(WebSocketHandle*, const WebSocketHandshakeRes
ponseInfo&) override; |
| 123 void didFail(WebSocketHandle*, const WebString& message) override; | 124 void didFail(WebSocketHandle*, const WebString& message) override; |
| 124 void didReceiveData(WebSocketHandle*, bool fin, WebSocketHandle::MessageType
, const char* data, size_t /* size */) override; | 125 void didReceiveData(WebSocketHandle*, bool fin, WebSocketHandle::MessageType
, const char* data, size_t /* size */) override; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 142 unsigned long m_identifier; | 143 unsigned long m_identifier; |
| 143 Member<BlobLoader> m_blobLoader; | 144 Member<BlobLoader> m_blobLoader; |
| 144 HeapDeque<Member<Message>> m_messages; | 145 HeapDeque<Member<Message>> m_messages; |
| 145 Vector<char> m_receivingMessageData; | 146 Vector<char> m_receivingMessageData; |
| 146 | 147 |
| 147 bool m_receivingMessageTypeIsText; | 148 bool m_receivingMessageTypeIsText; |
| 148 uint64_t m_sendingQuota; | 149 uint64_t m_sendingQuota; |
| 149 uint64_t m_receivedDataSizeForFlowControl; | 150 uint64_t m_receivedDataSizeForFlowControl; |
| 150 size_t m_sentSizeOfTopMessage; | 151 size_t m_sentSizeOfTopMessage; |
| 151 | 152 |
| 152 String m_sourceURLAtConstruction; | 153 OwnPtr<SourceLocation> m_locationAtConstruction; |
| 153 unsigned m_lineNumberAtConstruction; | |
| 154 RefPtr<WebSocketHandshakeRequest> m_handshakeRequest; | 154 RefPtr<WebSocketHandshakeRequest> m_handshakeRequest; |
| 155 | 155 |
| 156 static const uint64_t receivedDataSizeForFlowControlHighWaterMark = 1 << 15; | 156 static const uint64_t receivedDataSizeForFlowControlHighWaterMark = 1 << 15; |
| 157 }; | 157 }; |
| 158 | 158 |
| 159 } // namespace blink | 159 } // namespace blink |
| 160 | 160 |
| 161 #endif // DocumentWebSocketChannel_h | 161 #endif // DocumentWebSocketChannel_h |
| OLD | NEW |