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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 #include "wtf/OwnPtr.h" | 45 #include "wtf/OwnPtr.h" |
46 #include "wtf/PassOwnPtr.h" | 46 #include "wtf/PassOwnPtr.h" |
47 #include "wtf/PassRefPtr.h" | 47 #include "wtf/PassRefPtr.h" |
48 #include "wtf/RefPtr.h" | 48 #include "wtf/RefPtr.h" |
49 #include "wtf/Vector.h" | 49 #include "wtf/Vector.h" |
50 #include "wtf/text/CString.h" | 50 #include "wtf/text/CString.h" |
51 #include "wtf/text/WTFString.h" | 51 #include "wtf/text/WTFString.h" |
52 | 52 |
53 namespace blink { | 53 namespace blink { |
54 | 54 |
55 class WebSocketHandshakeRequestInfo; | |
56 class WebSocketHandshakeResponseInfo; | |
57 | |
58 } // namespace blink | |
59 | |
60 namespace blink { | |
61 | |
62 class Document; | 55 class Document; |
63 class WebSocketHandshakeRequest; | 56 class WebSocketHandshakeRequest; |
| 57 class WebSocketHandshakeRequestInfo; |
| 58 class WebSocketHandshakeResponseInfo; |
64 | 59 |
65 // This class may replace MainThreadWebSocketChannel. | 60 // This class may replace MainThreadWebSocketChannel. |
66 class NewWebSocketChannelImpl FINAL : public WebSocketChannel, public blink::Web
SocketHandleClient, public ContextLifecycleObserver { | 61 class NewWebSocketChannelImpl FINAL : public WebSocketChannel, public WebSocketH
andleClient, public ContextLifecycleObserver { |
67 public: | 62 public: |
68 // You can specify the source file and the line number information | 63 // You can specify the source file and the line number information |
69 // explicitly by passing the last parameter. | 64 // explicitly by passing the last parameter. |
70 // In the usual case, they are set automatically and you don't have to | 65 // In the usual case, they are set automatically and you don't have to |
71 // pass it. | 66 // pass it. |
72 // Specify handle explicitly only in tests. | 67 // Specify handle explicitly only in tests. |
73 static NewWebSocketChannelImpl* create(ExecutionContext* context, WebSocketC
hannelClient* client, const String& sourceURL = String(), unsigned lineNumber =
0, blink::WebSocketHandle *handle = 0) | 68 static NewWebSocketChannelImpl* create(ExecutionContext* context, WebSocketC
hannelClient* client, const String& sourceURL = String(), unsigned lineNumber =
0, WebSocketHandle *handle = 0) |
74 { | 69 { |
75 return adoptRefCountedGarbageCollected(new NewWebSocketChannelImpl(conte
xt, client, sourceURL, lineNumber, handle)); | 70 return adoptRefCountedGarbageCollected(new NewWebSocketChannelImpl(conte
xt, client, sourceURL, lineNumber, handle)); |
76 } | 71 } |
77 virtual ~NewWebSocketChannelImpl(); | 72 virtual ~NewWebSocketChannelImpl(); |
78 | 73 |
79 // WebSocketChannel functions. | 74 // WebSocketChannel functions. |
80 virtual bool connect(const KURL&, const String& protocol) OVERRIDE; | 75 virtual bool connect(const KURL&, const String& protocol) OVERRIDE; |
81 virtual void send(const String& message) OVERRIDE; | 76 virtual void send(const String& message) OVERRIDE; |
82 virtual void send(const ArrayBuffer&, unsigned byteOffset, unsigned byteLeng
th) OVERRIDE; | 77 virtual void send(const ArrayBuffer&, unsigned byteOffset, unsigned byteLeng
th) OVERRIDE; |
83 virtual void send(PassRefPtr<BlobDataHandle>) OVERRIDE; | 78 virtual void send(PassRefPtr<BlobDataHandle>) OVERRIDE; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 String reason; | 114 String reason; |
120 }; | 115 }; |
121 | 116 |
122 struct ReceivedMessage { | 117 struct ReceivedMessage { |
123 bool isMessageText; | 118 bool isMessageText; |
124 Vector<char> data; | 119 Vector<char> data; |
125 }; | 120 }; |
126 | 121 |
127 class BlobLoader; | 122 class BlobLoader; |
128 | 123 |
129 NewWebSocketChannelImpl(ExecutionContext*, WebSocketChannelClient*, const St
ring&, unsigned, blink::WebSocketHandle*); | 124 NewWebSocketChannelImpl(ExecutionContext*, WebSocketChannelClient*, const St
ring&, unsigned, WebSocketHandle*); |
130 void sendInternal(); | 125 void sendInternal(); |
131 void flowControlIfNecessary(); | 126 void flowControlIfNecessary(); |
132 void failAsError(const String& reason) { fail(reason, ErrorMessageLevel, m_s
ourceURLAtConstruction, m_lineNumberAtConstruction); } | 127 void failAsError(const String& reason) { fail(reason, ErrorMessageLevel, m_s
ourceURLAtConstruction, m_lineNumberAtConstruction); } |
133 void abortAsyncOperations(); | 128 void abortAsyncOperations(); |
134 void handleDidClose(bool wasClean, unsigned short code, const String& reason
); | 129 void handleDidClose(bool wasClean, unsigned short code, const String& reason
); |
135 Document* document(); // can be called only when m_identifier > 0. | 130 Document* document(); // can be called only when m_identifier > 0. |
136 | 131 |
137 // WebSocketHandleClient functions. | 132 // WebSocketHandleClient functions. |
138 virtual void didConnect(blink::WebSocketHandle*, bool fail, const blink::Web
String& selectedProtocol, const blink::WebString& extensions) OVERRIDE; | 133 virtual void didConnect(WebSocketHandle*, bool fail, const WebString& select
edProtocol, const WebString& extensions) OVERRIDE; |
139 virtual void didStartOpeningHandshake(blink::WebSocketHandle*, const blink::
WebSocketHandshakeRequestInfo&) OVERRIDE; | 134 virtual void didStartOpeningHandshake(WebSocketHandle*, const WebSocketHands
hakeRequestInfo&) OVERRIDE; |
140 virtual void didFinishOpeningHandshake(blink::WebSocketHandle*, const blink:
:WebSocketHandshakeResponseInfo&) OVERRIDE; | 135 virtual void didFinishOpeningHandshake(WebSocketHandle*, const WebSocketHand
shakeResponseInfo&) OVERRIDE; |
141 virtual void didFail(blink::WebSocketHandle*, const blink::WebString& messag
e) OVERRIDE; | 136 virtual void didFail(WebSocketHandle*, const WebString& message) OVERRIDE; |
142 virtual void didReceiveData(blink::WebSocketHandle*, bool fin, blink::WebSoc
ketHandle::MessageType, const char* data, size_t /* size */) OVERRIDE; | 137 virtual void didReceiveData(WebSocketHandle*, bool fin, WebSocketHandle::Mes
sageType, const char* data, size_t /* size */) OVERRIDE; |
143 virtual void didClose(blink::WebSocketHandle*, bool wasClean, unsigned short
code, const blink::WebString& reason) OVERRIDE; | 138 virtual void didClose(WebSocketHandle*, bool wasClean, unsigned short code,
const WebString& reason) OVERRIDE; |
144 virtual void didReceiveFlowControl(blink::WebSocketHandle*, int64_t quota) O
VERRIDE; | 139 virtual void didReceiveFlowControl(WebSocketHandle*, int64_t quota) OVERRIDE
; |
145 virtual void didStartClosingHandshake(blink::WebSocketHandle*) OVERRIDE; | 140 virtual void didStartClosingHandshake(WebSocketHandle*) OVERRIDE; |
146 | 141 |
147 // Methods for BlobLoader. | 142 // Methods for BlobLoader. |
148 void didFinishLoadingBlob(PassRefPtr<ArrayBuffer>); | 143 void didFinishLoadingBlob(PassRefPtr<ArrayBuffer>); |
149 void didFailLoadingBlob(FileError::ErrorCode); | 144 void didFailLoadingBlob(FileError::ErrorCode); |
150 | 145 |
151 // LifecycleObserver functions. | 146 // LifecycleObserver functions. |
152 virtual void contextDestroyed() OVERRIDE | 147 virtual void contextDestroyed() OVERRIDE |
153 { | 148 { |
154 // 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 |
155 // 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 |
156 // is no eager finalization. Instead the finalization happens at the | 151 // is no eager finalization. Instead the finalization happens at the |
157 // 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 |
158 // 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 |
159 // is run first this method gets called. Instead we assert the channel | 154 // is run first this method gets called. Instead we assert the channel |
160 // has been disconnected which happens in Peer::destroy. | 155 // has been disconnected which happens in Peer::destroy. |
161 ASSERT(!m_handle); | 156 ASSERT(!m_handle); |
162 ASSERT(!m_client); | 157 ASSERT(!m_client); |
163 ASSERT(!m_identifier); | 158 ASSERT(!m_identifier); |
164 ContextLifecycleObserver::contextDestroyed(); | 159 ContextLifecycleObserver::contextDestroyed(); |
165 } | 160 } |
166 | 161 |
167 // m_handle is a handle of the connection. | 162 // m_handle is a handle of the connection. |
168 // m_handle == 0 means this channel is closed. | 163 // m_handle == 0 means this channel is closed. |
169 OwnPtr<blink::WebSocketHandle> m_handle; | 164 OwnPtr<WebSocketHandle> m_handle; |
170 | 165 |
171 // m_client can be deleted while this channel is alive, but this class | 166 // m_client can be deleted while this channel is alive, but this class |
172 // expects that disconnect() is called before the deletion. | 167 // expects that disconnect() is called before the deletion. |
173 Member<WebSocketChannelClient> m_client; | 168 Member<WebSocketChannelClient> m_client; |
174 KURL m_url; | 169 KURL m_url; |
175 // m_identifier > 0 means calling scriptContextExecution() returns a Documen
t. | 170 // m_identifier > 0 means calling scriptContextExecution() returns a Documen
t. |
176 unsigned long m_identifier; | 171 unsigned long m_identifier; |
177 Member<BlobLoader> m_blobLoader; | 172 Member<BlobLoader> m_blobLoader; |
178 Deque<OwnPtr<Message> > m_messages; | 173 Deque<OwnPtr<Message> > m_messages; |
179 Vector<char> m_receivingMessageData; | 174 Vector<char> m_receivingMessageData; |
180 | 175 |
181 bool m_receivingMessageTypeIsText; | 176 bool m_receivingMessageTypeIsText; |
182 int64_t m_sendingQuota; | 177 int64_t m_sendingQuota; |
183 int64_t m_receivedDataSizeForFlowControl; | 178 int64_t m_receivedDataSizeForFlowControl; |
184 size_t m_sentSizeOfTopMessage; | 179 size_t m_sentSizeOfTopMessage; |
185 | 180 |
186 String m_sourceURLAtConstruction; | 181 String m_sourceURLAtConstruction; |
187 unsigned m_lineNumberAtConstruction; | 182 unsigned m_lineNumberAtConstruction; |
188 RefPtr<WebSocketHandshakeRequest> m_handshakeRequest; | 183 RefPtr<WebSocketHandshakeRequest> m_handshakeRequest; |
189 | 184 |
190 static const int64_t receivedDataSizeForFlowControlHighWaterMark = 1 << 15; | 185 static const int64_t receivedDataSizeForFlowControlHighWaterMark = 1 << 15; |
191 }; | 186 }; |
192 | 187 |
193 } // namespace blink | 188 } // namespace blink |
194 | 189 |
195 #endif // NewWebSocketChannelImpl_h | 190 #endif // NewWebSocketChannelImpl_h |
OLD | NEW |