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

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: 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
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)
59 {
60 return adoptRef(new NewWebSocketChannelImpl(context, client, sourceURL, lineNumber));
61 }
62 virtual ~NewWebSocketChannelImpl() { }
63
64 // WebSocketChannel functions.
65 virtual void connect(const KURL&, const String& protocol) OVERRIDE;
66 virtual String subprotocol() OVERRIDE;
67 virtual String extensions() OVERRIDE;
68 virtual WebSocketChannel::SendResult send(const String& message) OVERRIDE;
69 virtual WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteO ffset, unsigned byteLength) OVERRIDE;
70 virtual WebSocketChannel::SendResult send(const Blob&) OVERRIDE;
71 virtual unsigned long bufferedAmount() const OVERRIDE;
72 // Start closing handshake. Use the CloseEventCodeNotSpecified for the code
73 // argument to omit payload.
74 virtual void close(int code, const String& reason) OVERRIDE;
75 virtual void fail(const String& reason, MessageLevel, const String&, unsigne d lineNumber) OVERRIDE;
76 using WebSocketChannel::fail;
77 virtual void disconnect() OVERRIDE;
78
79 using RefCounted<NewWebSocketChannelImpl>::ref;
80 using RefCounted<NewWebSocketChannelImpl>::deref;
81
82 virtual void suspend() OVERRIDE;
83 virtual void resume() OVERRIDE;
84
85 private:
86 enum MessageType {
87 MessageTypeText,
88 MessageTypeBlob,
89 MessageTypeArrayBuffer,
90 };
91 struct Message {
92 Message(const String&);
93 Message(const Blob&);
94 Message(PassRefPtr<ArrayBuffer>);
95 MessageType type;
96 CString text;
97 RefPtr<Blob> blob;
98 RefPtr<ArrayBuffer> arrayBuffer;
99 };
100
101 struct ReceivedMessage {
102 bool isMessageText;
103 Vector<char> data;
104 };
105
106 enum State {
107 NotConnected,
108 Connecting,
109 Open,
110 Closing,
111 Closed,
112 };
113
114 struct PendingEvent {
115 enum Type {
116 DidConnectComplete,
117 DidReceiveTextMessage,
118 DidReceiveBinaryMessage,
119 DidReceiveError,
120 DidClose,
121 };
122 Type type;
123 Vector<char> message; // for DidReceive*Message
124 int closingCode; // for DidClose
125 String closingReason; // for DidClose
126
127 PendingEvent(Type type) : type(type) { }
128 PendingEvent(int code, const String& reason) : type(DidClose), closingCo de(code), closingReason(reason) { }
129 };
130
131 NewWebSocketChannelImpl(ScriptExecutionContext*, WebSocketChannelClient*, co nst String&, unsigned);
132 void sendInternal();
133 void flowControlIfNecessary();
134 void failAsError(const String& reason) { fail(reason, ErrorMessageLevel, m_s ourceURLAtConnection, m_lineNumberAtConnection); }
135
136 // WebSocketChannelHandleClient functions.
137 virtual void didConnect(WebKit::WebSocketChannelHandle*, bool succeed, const WebKit::WebString& selectedProtocol, const WebKit::WebString& extensions) OVERR IDE;
138 virtual void didReceiveData(WebKit::WebSocketChannelHandle*, const WebKit::W ebData&, WebKit::WebSocketChannelHandle::MessageType, bool fin) OVERRIDE;
139 virtual void didClose(WebKit::WebSocketChannelHandle*, unsigned short code, const WebKit::WebString& reason) OVERRIDE;
140 virtual void didReceiveFlowControl(WebKit::WebSocketChannelHandle*, int64_t quota) OVERRIDE { m_sendingQuota += quota; }
141
142 // FileReaderLoaderClient functions.
143 virtual void didStartLoading() OVERRIDE { }
144 virtual void didReceiveData() OVERRIDE { }
145 virtual void didFinishLoading() OVERRIDE;
146 virtual void didFail(FileError::ErrorCode) OVERRIDE;
147
148 void startLoadingBlob(const Blob&);
149 // Calling this function may delete this object.
150 void processPendingEvents();
151
152 // WebSocketChannel functions.
153 virtual void refWebSocketChannel() OVERRIDE { ref(); }
154 virtual void derefWebSocketChannel() OVERRIDE { deref(); }
155
156 ScriptExecutionContext* m_context;
abarth-chromium 2013/08/22 19:39:07 Is this raw pointer safe? Should this object be a
yhirano 2013/08/23 01:35:13 WebCore::WebSocket is a ContextLifecycleObserver a
157 WebSocketChannel* m_channel;
158 OwnPtr<WebKit::WebSocketChannelHandle> m_handle;
159 WebSocketChannelClient* m_client;
160 unsigned long m_identifier; // m_identifier == 0 means that we could not obt ain a valid identifier.
161 KURL m_url;
162 OwnPtr<FileReaderLoader> m_blobLoader;
163 bool m_isLoadingBlob;
164 Vector<Message> m_messages;
165 Vector<PendingEvent> m_pendingEvents;
166 Vector<char> m_receivingMessageData;
167
168 State m_state;
169 bool m_receivingMessageTypeIsText;
170 int64_t m_sendingQuota;
171 int64_t m_receivedDataSizeForFlowControl;
172 unsigned long m_bufferedAmount;
173 size_t m_sentSizeOfTopMessage;
174 String m_subprotocol;
175 String m_extensions;
176 bool m_hasAlreadyFailed;
177 bool m_isSuspended;
178 String m_sourceURLAtConnection;
179 int m_lineNumberAtConnection;
180
181 static const int64_t receivedDataSizeForFlowControlHighWaterMark = 1 << 13;
182 };
183
184 } // namespace WebCore
185
186 #endif // NewWebSocketChannelImpl_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698