| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 void sendBinaryAsCharVector(PassOwnPtr<Vector<char>> data) override; | 83 void sendBinaryAsCharVector(PassOwnPtr<Vector<char>> data) override; |
| 84 // Start closing handshake. Use the CloseEventCodeNotSpecified for the code | 84 // Start closing handshake. Use the CloseEventCodeNotSpecified for the code |
| 85 // argument to omit payload. | 85 // argument to omit payload. |
| 86 void close(int code, const String& reason) override; | 86 void close(int code, const String& reason) override; |
| 87 void fail(const String& reason, MessageLevel, const String&, unsigned lineNu
mber) override; | 87 void fail(const String& reason, MessageLevel, const String&, unsigned lineNu
mber) override; |
| 88 void disconnect() override; | 88 void disconnect() override; |
| 89 | 89 |
| 90 DECLARE_VIRTUAL_TRACE(); | 90 DECLARE_VIRTUAL_TRACE(); |
| 91 | 91 |
| 92 private: | 92 private: |
| 93 class BlobLoader; | |
| 94 class Message; | |
| 95 | |
| 96 enum MessageType { | 93 enum MessageType { |
| 97 MessageTypeText, | 94 MessageTypeText, |
| 98 MessageTypeBlob, | 95 MessageTypeBlob, |
| 99 MessageTypeArrayBuffer, | 96 MessageTypeArrayBuffer, |
| 100 MessageTypeTextAsCharVector, | 97 MessageTypeTextAsCharVector, |
| 101 MessageTypeBinaryAsCharVector, | 98 MessageTypeBinaryAsCharVector, |
| 102 MessageTypeClose, | 99 MessageTypeClose, |
| 103 }; | 100 }; |
| 104 | 101 |
| 102 struct Message { |
| 103 explicit Message(const CString&); |
| 104 explicit Message(PassRefPtr<BlobDataHandle>); |
| 105 explicit Message(PassRefPtr<DOMArrayBuffer>); |
| 106 // For WorkerWebSocketChannel |
| 107 explicit Message(PassOwnPtr<Vector<char>>, MessageType); |
| 108 // Close message |
| 109 Message(unsigned short code, const String& reason); |
| 110 |
| 111 MessageType type; |
| 112 |
| 113 CString text; |
| 114 RefPtr<BlobDataHandle> blobDataHandle; |
| 115 RefPtr<DOMArrayBuffer> arrayBuffer; |
| 116 OwnPtr<Vector<char>> vectorData; |
| 117 unsigned short code; |
| 118 String reason; |
| 119 }; |
| 120 |
| 105 struct ReceivedMessage { | 121 struct ReceivedMessage { |
| 106 bool isMessageText; | 122 bool isMessageText; |
| 107 Vector<char> data; | 123 Vector<char> data; |
| 108 }; | 124 }; |
| 109 | 125 |
| 126 class BlobLoader; |
| 127 |
| 110 DocumentWebSocketChannel(Document*, WebSocketChannelClient*, const String&,
unsigned, WebSocketHandle*); | 128 DocumentWebSocketChannel(Document*, WebSocketChannelClient*, const String&,
unsigned, WebSocketHandle*); |
| 111 void sendInternal(WebSocketHandle::MessageType, const char* data, size_t tot
alSize, uint64_t* consumedBufferedAmount); | 129 void sendInternal(WebSocketHandle::MessageType, const char* data, size_t tot
alSize, uint64_t* consumedBufferedAmount); |
| 112 void processSendQueue(); | 130 void processSendQueue(); |
| 113 void flowControlIfNecessary(); | 131 void flowControlIfNecessary(); |
| 114 void failAsError(const String& reason) { fail(reason, ErrorMessageLevel, m_s
ourceURLAtConstruction, m_lineNumberAtConstruction); } | 132 void failAsError(const String& reason) { fail(reason, ErrorMessageLevel, m_s
ourceURLAtConstruction, m_lineNumberAtConstruction); } |
| 115 void abortAsyncOperations(); | 133 void abortAsyncOperations(); |
| 116 void handleDidClose(bool wasClean, unsigned short code, const String& reason
); | 134 void handleDidClose(bool wasClean, unsigned short code, const String& reason
); |
| 117 Document* document(); | 135 Document* document(); |
| 118 | 136 |
| 119 // WebSocketHandleClient functions. | 137 // WebSocketHandleClient functions. |
| 120 void didConnect(WebSocketHandle*, const WebString& selectedProtocol, const W
ebString& extensions) override; | 138 void didConnect(WebSocketHandle*, const WebString& selectedProtocol, const W
ebString& extensions) override; |
| 121 void didStartOpeningHandshake(WebSocketHandle*, const WebSocketHandshakeRequ
estInfo&) override; | 139 void didStartOpeningHandshake(WebSocketHandle*, const WebSocketHandshakeRequ
estInfo&) override; |
| 122 void didFinishOpeningHandshake(WebSocketHandle*, const WebSocketHandshakeRes
ponseInfo&) override; | 140 void didFinishOpeningHandshake(WebSocketHandle*, const WebSocketHandshakeRes
ponseInfo&) override; |
| 123 void didFail(WebSocketHandle*, const WebString& message) override; | 141 void didFail(WebSocketHandle*, const WebString& message) override; |
| 124 void didReceiveData(WebSocketHandle*, bool fin, WebSocketHandle::MessageType
, const char* data, size_t /* size */) override; | 142 void didReceiveData(WebSocketHandle*, bool fin, WebSocketHandle::MessageType
, const char* data, size_t /* size */) override; |
| 125 void didClose(WebSocketHandle*, bool wasClean, unsigned short code, const We
bString& reason) override; | 143 void didClose(WebSocketHandle*, bool wasClean, unsigned short code, const We
bString& reason) override; |
| 126 void didReceiveFlowControl(WebSocketHandle*, int64_t quota) override; | 144 void didReceiveFlowControl(WebSocketHandle*, int64_t quota) override; |
| 127 void didStartClosingHandshake(WebSocketHandle*) override; | 145 void didStartClosingHandshake(WebSocketHandle*) override; |
| 128 | 146 |
| 129 // Methods for BlobLoader. | 147 // Methods for BlobLoader. |
| 130 void didFinishLoadingBlob(DOMArrayBuffer*); | 148 void didFinishLoadingBlob(PassRefPtr<DOMArrayBuffer>); |
| 131 void didFailLoadingBlob(FileError::ErrorCode); | 149 void didFailLoadingBlob(FileError::ErrorCode); |
| 132 | 150 |
| 133 // m_handle is a handle of the connection. | 151 // m_handle is a handle of the connection. |
| 134 // m_handle == 0 means this channel is closed. | 152 // m_handle == 0 means this channel is closed. |
| 135 OwnPtr<WebSocketHandle> m_handle; | 153 OwnPtr<WebSocketHandle> m_handle; |
| 136 | 154 |
| 137 // m_client can be deleted while this channel is alive, but this class | 155 // m_client can be deleted while this channel is alive, but this class |
| 138 // expects that disconnect() is called before the deletion. | 156 // expects that disconnect() is called before the deletion. |
| 139 Member<WebSocketChannelClient> m_client; | 157 Member<WebSocketChannelClient> m_client; |
| 140 KURL m_url; | 158 KURL m_url; |
| 141 // m_identifier > 0 means calling scriptContextExecution() returns a Documen
t. | 159 // m_identifier > 0 means calling scriptContextExecution() returns a Documen
t. |
| 142 unsigned long m_identifier; | 160 unsigned long m_identifier; |
| 143 Member<BlobLoader> m_blobLoader; | 161 Member<BlobLoader> m_blobLoader; |
| 144 HeapDeque<Member<Message>> m_messages; | 162 Deque<OwnPtr<Message>> m_messages; |
| 145 Vector<char> m_receivingMessageData; | 163 Vector<char> m_receivingMessageData; |
| 146 | 164 |
| 147 bool m_receivingMessageTypeIsText; | 165 bool m_receivingMessageTypeIsText; |
| 148 uint64_t m_sendingQuota; | 166 uint64_t m_sendingQuota; |
| 149 uint64_t m_receivedDataSizeForFlowControl; | 167 uint64_t m_receivedDataSizeForFlowControl; |
| 150 size_t m_sentSizeOfTopMessage; | 168 size_t m_sentSizeOfTopMessage; |
| 151 | 169 |
| 152 String m_sourceURLAtConstruction; | 170 String m_sourceURLAtConstruction; |
| 153 unsigned m_lineNumberAtConstruction; | 171 unsigned m_lineNumberAtConstruction; |
| 154 RefPtr<WebSocketHandshakeRequest> m_handshakeRequest; | 172 RefPtr<WebSocketHandshakeRequest> m_handshakeRequest; |
| 155 | 173 |
| 156 static const uint64_t receivedDataSizeForFlowControlHighWaterMark = 1 << 15; | 174 static const uint64_t receivedDataSizeForFlowControlHighWaterMark = 1 << 15; |
| 157 }; | 175 }; |
| 158 | 176 |
| 159 } // namespace blink | 177 } // namespace blink |
| 160 | 178 |
| 161 #endif // DocumentWebSocketChannel_h | 179 #endif // DocumentWebSocketChannel_h |
| OLD | NEW |