| 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 21 matching lines...) Expand all Loading... |
| 32 #define DocumentWebSocketChannel_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" | |
| 43 #include "wtf/Deque.h" | 42 #include "wtf/Deque.h" |
| 44 #include "wtf/FastAllocBase.h" | 43 #include "wtf/FastAllocBase.h" |
| 45 #include "wtf/OwnPtr.h" | 44 #include "wtf/OwnPtr.h" |
| 46 #include "wtf/PassOwnPtr.h" | 45 #include "wtf/PassOwnPtr.h" |
| 47 #include "wtf/PassRefPtr.h" | 46 #include "wtf/PassRefPtr.h" |
| 48 #include "wtf/RefPtr.h" | 47 #include "wtf/RefPtr.h" |
| 49 #include "wtf/Vector.h" | 48 #include "wtf/Vector.h" |
| 50 #include "wtf/text/CString.h" | 49 #include "wtf/text/CString.h" |
| 51 #include "wtf/text/WTFString.h" | 50 #include "wtf/text/WTFString.h" |
| 52 | 51 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 68 // Specify handle explicitly only in tests. | 67 // Specify handle explicitly only in tests. |
| 69 static DocumentWebSocketChannel* create(ExecutionContext* context, WebSocket
ChannelClient* client, const String& sourceURL = String(), unsigned lineNumber =
0, WebSocketHandle *handle = 0) | 68 static DocumentWebSocketChannel* create(ExecutionContext* context, WebSocket
ChannelClient* client, const String& sourceURL = String(), unsigned lineNumber =
0, WebSocketHandle *handle = 0) |
| 70 { | 69 { |
| 71 return new DocumentWebSocketChannel(context, client, sourceURL, lineNumb
er, handle); | 70 return new DocumentWebSocketChannel(context, client, sourceURL, lineNumb
er, handle); |
| 72 } | 71 } |
| 73 virtual ~DocumentWebSocketChannel(); | 72 virtual ~DocumentWebSocketChannel(); |
| 74 | 73 |
| 75 // WebSocketChannel functions. | 74 // WebSocketChannel functions. |
| 76 virtual bool connect(const KURL&, const String& protocol) override; | 75 virtual bool connect(const KURL&, const String& protocol) override; |
| 77 virtual void send(const String& message) override; | 76 virtual void send(const String& message) override; |
| 78 virtual void send(const ArrayBuffer&, unsigned byteOffset, unsigned byteLeng
th) override; | 77 virtual void send(const DOMArrayBuffer&, unsigned byteOffset, unsigned byteL
ength) override; |
| 79 virtual void send(PassRefPtr<BlobDataHandle>) override; | 78 virtual void send(PassRefPtr<BlobDataHandle>) override; |
| 80 virtual void send(PassOwnPtr<Vector<char> > data) override; | 79 virtual void send(PassOwnPtr<Vector<char> > data) override; |
| 81 // Start closing handshake. Use the CloseEventCodeNotSpecified for the code | 80 // Start closing handshake. Use the CloseEventCodeNotSpecified for the code |
| 82 // argument to omit payload. | 81 // argument to omit payload. |
| 83 virtual void close(int code, const String& reason) override; | 82 virtual void close(int code, const String& reason) override; |
| 84 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; |
| 85 virtual void disconnect() override; | 84 virtual void disconnect() override; |
| 86 | 85 |
| 87 virtual void suspend() override; | 86 virtual void suspend() override; |
| 88 virtual void resume() override; | 87 virtual void resume() override; |
| 89 | 88 |
| 90 virtual void trace(Visitor*) override; | 89 virtual void trace(Visitor*) override; |
| 91 | 90 |
| 92 private: | 91 private: |
| 93 enum MessageType { | 92 enum MessageType { |
| 94 MessageTypeText, | 93 MessageTypeText, |
| 95 MessageTypeBlob, | 94 MessageTypeBlob, |
| 96 MessageTypeArrayBuffer, | 95 MessageTypeArrayBuffer, |
| 97 MessageTypeVector, | 96 MessageTypeVector, |
| 98 MessageTypeClose, | 97 MessageTypeClose, |
| 99 }; | 98 }; |
| 100 | 99 |
| 101 struct Message { | 100 struct Message { |
| 102 explicit Message(const String&); | 101 explicit Message(const String&); |
| 103 explicit Message(PassRefPtr<BlobDataHandle>); | 102 explicit Message(PassRefPtr<BlobDataHandle>); |
| 104 explicit Message(PassRefPtr<ArrayBuffer>); | 103 explicit Message(PassRefPtr<DOMArrayBuffer>); |
| 105 explicit Message(PassOwnPtr<Vector<char> >); | 104 explicit Message(PassOwnPtr<Vector<char> >); |
| 106 Message(unsigned short code, const String& reason); | 105 Message(unsigned short code, const String& reason); |
| 107 | 106 |
| 108 MessageType type; | 107 MessageType type; |
| 109 | 108 |
| 110 CString text; | 109 CString text; |
| 111 RefPtr<BlobDataHandle> blobDataHandle; | 110 RefPtr<BlobDataHandle> blobDataHandle; |
| 112 RefPtr<ArrayBuffer> arrayBuffer; | 111 RefPtr<DOMArrayBuffer> arrayBuffer; |
| 113 OwnPtr<Vector<char> > vectorData; | 112 OwnPtr<Vector<char> > vectorData; |
| 114 unsigned short code; | 113 unsigned short code; |
| 115 String reason; | 114 String reason; |
| 116 }; | 115 }; |
| 117 | 116 |
| 118 struct ReceivedMessage { | 117 struct ReceivedMessage { |
| 119 bool isMessageText; | 118 bool isMessageText; |
| 120 Vector<char> data; | 119 Vector<char> data; |
| 121 }; | 120 }; |
| 122 | 121 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 134 virtual void didConnect(WebSocketHandle*, bool fail, const WebString& select
edProtocol, const WebString& extensions) override; | 133 virtual void didConnect(WebSocketHandle*, bool fail, const WebString& select
edProtocol, const WebString& extensions) override; |
| 135 virtual void didStartOpeningHandshake(WebSocketHandle*, const WebSocketHands
hakeRequestInfo&) override; | 134 virtual void didStartOpeningHandshake(WebSocketHandle*, const WebSocketHands
hakeRequestInfo&) override; |
| 136 virtual void didFinishOpeningHandshake(WebSocketHandle*, const WebSocketHand
shakeResponseInfo&) override; | 135 virtual void didFinishOpeningHandshake(WebSocketHandle*, const WebSocketHand
shakeResponseInfo&) override; |
| 137 virtual void didFail(WebSocketHandle*, const WebString& message) override; | 136 virtual void didFail(WebSocketHandle*, const WebString& message) override; |
| 138 virtual void didReceiveData(WebSocketHandle*, bool fin, WebSocketHandle::Mes
sageType, const char* data, size_t /* size */) override; | 137 virtual void didReceiveData(WebSocketHandle*, bool fin, WebSocketHandle::Mes
sageType, const char* data, size_t /* size */) override; |
| 139 virtual void didClose(WebSocketHandle*, bool wasClean, unsigned short code,
const WebString& reason) override; | 138 virtual void didClose(WebSocketHandle*, bool wasClean, unsigned short code,
const WebString& reason) override; |
| 140 virtual void didReceiveFlowControl(WebSocketHandle*, int64_t quota) override
; | 139 virtual void didReceiveFlowControl(WebSocketHandle*, int64_t quota) override
; |
| 141 virtual void didStartClosingHandshake(WebSocketHandle*) override; | 140 virtual void didStartClosingHandshake(WebSocketHandle*) override; |
| 142 | 141 |
| 143 // Methods for BlobLoader. | 142 // Methods for BlobLoader. |
| 144 void didFinishLoadingBlob(PassRefPtr<ArrayBuffer>); | 143 void didFinishLoadingBlob(PassRefPtr<DOMArrayBuffer>); |
| 145 void didFailLoadingBlob(FileError::ErrorCode); | 144 void didFailLoadingBlob(FileError::ErrorCode); |
| 146 | 145 |
| 147 // LifecycleObserver functions. | 146 // LifecycleObserver functions. |
| 148 virtual void contextDestroyed() override | 147 virtual void contextDestroyed() override |
| 149 { | 148 { |
| 150 // In oilpan we cannot assume this channel's finalizer has been called | 149 // In oilpan we cannot assume this channel's finalizer has been called |
| 151 // before the document it is observing is dead and finalized since there | 150 // before the document it is observing is dead and finalized since there |
| 152 // is no eager finalization. Instead the finalization happens at the | 151 // is no eager finalization. Instead the finalization happens at the |
| 153 // next GC which could be long enough after the Peer::destroy call for | 152 // next GC which could be long enough after the Peer::destroy call for |
| 154 // the context (ie. Document) to be dead too. If the context's finalizer | 153 // the context (ie. Document) to be dead too. If the context's finalizer |
| (...skipping 27 matching lines...) Expand all Loading... |
| 182 String m_sourceURLAtConstruction; | 181 String m_sourceURLAtConstruction; |
| 183 unsigned m_lineNumberAtConstruction; | 182 unsigned m_lineNumberAtConstruction; |
| 184 RefPtr<WebSocketHandshakeRequest> m_handshakeRequest; | 183 RefPtr<WebSocketHandshakeRequest> m_handshakeRequest; |
| 185 | 184 |
| 186 static const int64_t receivedDataSizeForFlowControlHighWaterMark = 1 << 15; | 185 static const int64_t receivedDataSizeForFlowControlHighWaterMark = 1 << 15; |
| 187 }; | 186 }; |
| 188 | 187 |
| 189 } // namespace blink | 188 } // namespace blink |
| 190 | 189 |
| 191 #endif // DocumentWebSocketChannel_h | 190 #endif // DocumentWebSocketChannel_h |
| OLD | NEW |