Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: Source/modules/websockets/NewWebSocketChannelImpl.h

Issue 22914026: [ABANDONED] Introduce blink-side bridges for the new WebSocket implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/modules/modules.gypi ('k') | Source/modules/websockets/NewWebSocketChannelImpl.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
29 */
30
31 #ifndef NewWebSocketChannelImpl_h
32 #define NewWebSocketChannelImpl_h
33
34 #include "core/fileapi/Blob.h"
35 #include "core/fileapi/FileReaderLoader.h"
36 #include "core/fileapi/FileReaderLoaderClient.h"
37 #include "core/platform/SharedBuffer.h"
38 #include "modules/websockets/WebSocketChannel.h"
39 #include "public/platform/WebSocketChannelHandle.h"
40 #include "public/platform/WebSocketChannelHandleClient.h"
41 #include "wtf/ArrayBuffer.h"
42 #include "wtf/PassRefPtr.h"
43 #include "wtf/RefCounted.h"
44 #include "wtf/RefPtr.h"
45 #include "wtf/Vector.h"
46 #include "wtf/text/WTFString.h"
47
48 namespace WebCore {
49
50 // This class may replace MainThreadWebSocketChannel.
51 class NewWebSocketChannelImpl : public WebSocketChannel, public RefCounted<NewWe bSocketChannelImpl>, public FileReaderLoaderClient, public WebKit::WebSocketChan nelHandleClient {
52 WTF_MAKE_FAST_ALLOCATED;
53 public:
54 // You can specify the source file and the line number information
55 // explicitly by passing the last parameter.
56 // In the usual case, they are set automatically and you don't have to
57 // pass it.
58 static PassRefPtr<NewWebSocketChannelImpl> create(ScriptExecutionContext* co ntext, WebSocketChannelClient* client, const String& sourceURL = String(), unsig ned lineNumber = 0) { return adoptRef(new NewWebSocketChannelImpl(context, clien t, sourceURL, lineNumber)); }
tyoshino (SeeGerritForStatus) 2013/08/22 08:25:22 let's break at {
yhirano 2013/08/22 08:40:31 Done.
59 virtual ~NewWebSocketChannelImpl() { }
60
61 // WebSocketChannel functions.
62 virtual void connect(const KURL&, const String& protocol) OVERRIDE;
63 virtual String subprotocol() OVERRIDE;
64 virtual String extensions() OVERRIDE;
65 virtual WebSocketChannel::SendResult send(const String& message) OVERRIDE;
66 virtual WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteO ffset, unsigned byteLength) OVERRIDE;
67 virtual WebSocketChannel::SendResult send(const Blob&) OVERRIDE;
68 virtual unsigned long bufferedAmount() const OVERRIDE;
69 // Start closing handshake. Use the CloseEventCodeNotSpecified for the code
70 // argument to omit payload.
71 virtual void close(int code, const String& reason) OVERRIDE;
72 virtual void fail(const String& reason, MessageLevel, const String&, unsigne d lineNumber) OVERRIDE;
73 using WebSocketChannel::fail;
74 virtual void disconnect() OVERRIDE;
75
76 using RefCounted<NewWebSocketChannelImpl>::ref;
77 using RefCounted<NewWebSocketChannelImpl>::deref;
78
79 virtual void suspend() OVERRIDE;
80 virtual void resume() OVERRIDE;
81
82 private:
83 enum MessageType {
84 MessageTypeText,
85 MessageTypeBlob,
86 MessageTypeArrayBuffer,
87 };
88 struct Message {
89 Message(const String&);
90 Message(const Blob&);
91 Message(PassRefPtr<ArrayBuffer>);
92 MessageType type;
93 CString text;
94 RefPtr<Blob> blob;
95 RefPtr<ArrayBuffer> arrayBuffer;
96 };
97
98 struct ReceivedMessage {
99 bool isMessageText;
100 Vector<char> data;
101 };
102
103 enum State {
104 NotConnected,
105 Connecting,
106 Open,
107 Closing,
108 Closed,
109 };
110
111 struct PendingEvent {
112 enum Type {
113 DidConnectComplete,
114 DidReceiveTextMessage,
115 DidReceiveBinaryMessage,
116 DidReceiveError,
117 DidClose,
118 };
119 Type type;
120 Vector<char> message; // for DidReceive*Message
121 int closingCode; // for DidClose
122 String closingReason; // for DidClose
123
124 PendingEvent(Type type) : type(type) { }
125 PendingEvent(int code, const String& reason) : type(DidClose), closingCo de(code), closingReason(reason) { }
126 };
127
128 NewWebSocketChannelImpl(ScriptExecutionContext*, WebSocketChannelClient*, co nst String&, unsigned);
129 void sendInternal();
130 void flowControlIfNecessary();
131 void failAsError(const String& reason) { fail(reason, ErrorMessageLevel, m_s ourceURLAtConnection, m_lineNumberAtConnection); }
132
133 // WebSocketChannelHandleClient functions.
134 virtual void didConnect(WebKit::WebSocketChannelHandle*, bool succeed, const WebKit::WebString& selectedProtocol, const WebKit::WebString& extensions) OVERR IDE;
135 virtual void didReceiveData(WebKit::WebSocketChannelHandle*, const WebKit::W ebData&, WebKit::WebSocketChannelHandle::MessageType, bool fin) OVERRIDE;
136 virtual void didClose(WebKit::WebSocketChannelHandle*, unsigned short code, const WebKit::WebString& reason) OVERRIDE;
137 virtual void didReceiveFlowControl(WebKit::WebSocketChannelHandle*, int64_t quota) OVERRIDE { m_sendingQuota += quota; }
138
139 // FileReaderLoaderClient functions.
140 virtual void didStartLoading() OVERRIDE { }
141 virtual void didReceiveData() OVERRIDE { }
142 virtual void didFinishLoading() OVERRIDE;
143 virtual void didFail(FileError::ErrorCode) OVERRIDE;
144
145 void startLoadingBlob(const Blob&);
146 // Calling this function may delete this object.
147 void processPendingEvents();
148
tyoshino (SeeGerritForStatus) 2013/08/22 08:25:22 // WebSocketChannel functions
yhirano 2013/08/22 08:40:31 Done.
149 virtual void refWebSocketChannel() OVERRIDE { ref(); }
150 virtual void derefWebSocketChannel() OVERRIDE { deref(); }
151
152 ScriptExecutionContext* m_context;
153 WebSocketChannel* m_channel;
154 OwnPtr<WebKit::WebSocketChannelHandle> m_handle;
155 WebSocketChannelClient* m_client;
156 unsigned long m_identifier; // m_identifier == 0 means that we could not obt ain a valid identifier.
157 KURL m_url;
158 OwnPtr<FileReaderLoader> m_blobLoader;
159 bool m_isLoadingBlob;
160 Vector<Message> m_messages;
161 Vector<PendingEvent> m_pendingEvents;
162 Vector<char> m_receivingMessageData;
163
164 State m_state;
165 bool m_receivingMessageTypeIsText;
166 int64_t m_sendingQuota;
167 int64_t m_receivedDataSizeForFlowControl;
168 unsigned long m_bufferedAmount;
169 size_t m_sentSizeOfTopMessage;
170 String m_subprotocol;
171 String m_extensions;
172 bool m_hasAlreadyFailed;
173 bool m_isSuspended;
174 String m_sourceURLAtConnection;
175 int m_lineNumberAtConnection;
176
177 static const int64_t receivedDataSizeForFlowControlHighWaterMark = 1 << 13;
178 };
179
180 } // namespace WebCore
181
182 #endif // WebSocketMessagePool_h
tyoshino (SeeGerritForStatus) 2013/08/22 08:25:22 correct comment
yhirano 2013/08/22 08:40:31 Done.
OLDNEW
« no previous file with comments | « Source/modules/modules.gypi ('k') | Source/modules/websockets/NewWebSocketChannelImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698