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 11 matching lines...) Expand all Loading... |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "modules/websockets/NewWebSocketChannelImpl.h" | 32 #include "modules/websockets/DocumentWebSocketChannel.h" |
33 | 33 |
34 #include "core/dom/Document.h" | 34 #include "core/dom/Document.h" |
35 #include "core/dom/ExecutionContext.h" | 35 #include "core/dom/ExecutionContext.h" |
36 #include "core/fileapi/FileReaderLoader.h" | 36 #include "core/fileapi/FileReaderLoader.h" |
37 #include "core/fileapi/FileReaderLoaderClient.h" | 37 #include "core/fileapi/FileReaderLoaderClient.h" |
38 #include "core/frame/LocalFrame.h" | 38 #include "core/frame/LocalFrame.h" |
39 #include "core/inspector/ConsoleMessage.h" | 39 #include "core/inspector/ConsoleMessage.h" |
40 #include "core/inspector/InspectorInstrumentation.h" | 40 #include "core/inspector/InspectorInstrumentation.h" |
41 #include "core/inspector/InspectorTraceEvents.h" | 41 #include "core/inspector/InspectorTraceEvents.h" |
42 #include "core/loader/FrameLoader.h" | 42 #include "core/loader/FrameLoader.h" |
(...skipping 10 matching lines...) Expand all Loading... |
53 #include "public/platform/WebSocketHandshakeRequestInfo.h" | 53 #include "public/platform/WebSocketHandshakeRequestInfo.h" |
54 #include "public/platform/WebSocketHandshakeResponseInfo.h" | 54 #include "public/platform/WebSocketHandshakeResponseInfo.h" |
55 #include "public/platform/WebString.h" | 55 #include "public/platform/WebString.h" |
56 #include "public/platform/WebURL.h" | 56 #include "public/platform/WebURL.h" |
57 #include "public/platform/WebVector.h" | 57 #include "public/platform/WebVector.h" |
58 | 58 |
59 using blink::WebSocketHandle; | 59 using blink::WebSocketHandle; |
60 | 60 |
61 namespace blink { | 61 namespace blink { |
62 | 62 |
63 class NewWebSocketChannelImpl::BlobLoader final : public GarbageCollectedFinaliz
ed<NewWebSocketChannelImpl::BlobLoader>, public FileReaderLoaderClient { | 63 class DocumentWebSocketChannel::BlobLoader final : public GarbageCollectedFinali
zed<DocumentWebSocketChannel::BlobLoader>, public FileReaderLoaderClient { |
64 public: | 64 public: |
65 BlobLoader(PassRefPtr<BlobDataHandle>, NewWebSocketChannelImpl*); | 65 BlobLoader(PassRefPtr<BlobDataHandle>, DocumentWebSocketChannel*); |
66 virtual ~BlobLoader() { } | 66 virtual ~BlobLoader() { } |
67 | 67 |
68 void cancel(); | 68 void cancel(); |
69 | 69 |
70 // FileReaderLoaderClient functions. | 70 // FileReaderLoaderClient functions. |
71 virtual void didStartLoading() override { } | 71 virtual void didStartLoading() override { } |
72 virtual void didReceiveData() override { } | 72 virtual void didReceiveData() override { } |
73 virtual void didFinishLoading() override; | 73 virtual void didFinishLoading() override; |
74 virtual void didFail(FileError::ErrorCode) override; | 74 virtual void didFail(FileError::ErrorCode) override; |
75 | 75 |
76 void trace(Visitor* visitor) | 76 void trace(Visitor* visitor) |
77 { | 77 { |
78 visitor->trace(m_channel); | 78 visitor->trace(m_channel); |
79 } | 79 } |
80 | 80 |
81 private: | 81 private: |
82 Member<NewWebSocketChannelImpl> m_channel; | 82 Member<DocumentWebSocketChannel> m_channel; |
83 FileReaderLoader m_loader; | 83 FileReaderLoader m_loader; |
84 }; | 84 }; |
85 | 85 |
86 NewWebSocketChannelImpl::BlobLoader::BlobLoader(PassRefPtr<BlobDataHandle> blobD
ataHandle, NewWebSocketChannelImpl* channel) | 86 DocumentWebSocketChannel::BlobLoader::BlobLoader(PassRefPtr<BlobDataHandle> blob
DataHandle, DocumentWebSocketChannel* channel) |
87 : m_channel(channel) | 87 : m_channel(channel) |
88 , m_loader(FileReaderLoader::ReadAsArrayBuffer, this) | 88 , m_loader(FileReaderLoader::ReadAsArrayBuffer, this) |
89 { | 89 { |
90 m_loader.start(channel->executionContext(), blobDataHandle); | 90 m_loader.start(channel->executionContext(), blobDataHandle); |
91 } | 91 } |
92 | 92 |
93 void NewWebSocketChannelImpl::BlobLoader::cancel() | 93 void DocumentWebSocketChannel::BlobLoader::cancel() |
94 { | 94 { |
95 m_loader.cancel(); | 95 m_loader.cancel(); |
96 // didFail will be called immediately. | 96 // didFail will be called immediately. |
97 // |this| is deleted here. | 97 // |this| is deleted here. |
98 } | 98 } |
99 | 99 |
100 void NewWebSocketChannelImpl::BlobLoader::didFinishLoading() | 100 void DocumentWebSocketChannel::BlobLoader::didFinishLoading() |
101 { | 101 { |
102 m_channel->didFinishLoadingBlob(m_loader.arrayBufferResult()); | 102 m_channel->didFinishLoadingBlob(m_loader.arrayBufferResult()); |
103 // |this| is deleted here. | 103 // |this| is deleted here. |
104 } | 104 } |
105 | 105 |
106 void NewWebSocketChannelImpl::BlobLoader::didFail(FileError::ErrorCode errorCode
) | 106 void DocumentWebSocketChannel::BlobLoader::didFail(FileError::ErrorCode errorCod
e) |
107 { | 107 { |
108 m_channel->didFailLoadingBlob(errorCode); | 108 m_channel->didFailLoadingBlob(errorCode); |
109 // |this| is deleted here. | 109 // |this| is deleted here. |
110 } | 110 } |
111 | 111 |
112 NewWebSocketChannelImpl::NewWebSocketChannelImpl(ExecutionContext* context, WebS
ocketChannelClient* client, const String& sourceURL, unsigned lineNumber, WebSoc
ketHandle *handle) | 112 DocumentWebSocketChannel::DocumentWebSocketChannel(ExecutionContext* context, We
bSocketChannelClient* client, const String& sourceURL, unsigned lineNumber, WebS
ocketHandle *handle) |
113 : ContextLifecycleObserver(context) | 113 : ContextLifecycleObserver(context) |
114 , m_handle(adoptPtr(handle ? handle : Platform::current()->createWebSocketHa
ndle())) | 114 , m_handle(adoptPtr(handle ? handle : Platform::current()->createWebSocketHa
ndle())) |
115 , m_client(client) | 115 , m_client(client) |
116 , m_identifier(0) | 116 , m_identifier(0) |
117 , m_sendingQuota(0) | 117 , m_sendingQuota(0) |
118 , m_receivedDataSizeForFlowControl(receivedDataSizeForFlowControlHighWaterMa
rk * 2) // initial quota | 118 , m_receivedDataSizeForFlowControl(receivedDataSizeForFlowControlHighWaterMa
rk * 2) // initial quota |
119 , m_sentSizeOfTopMessage(0) | 119 , m_sentSizeOfTopMessage(0) |
120 , m_sourceURLAtConstruction(sourceURL) | 120 , m_sourceURLAtConstruction(sourceURL) |
121 , m_lineNumberAtConstruction(lineNumber) | 121 , m_lineNumberAtConstruction(lineNumber) |
122 { | 122 { |
123 if (context->isDocument() && toDocument(context)->page()) | 123 if (context->isDocument() && toDocument(context)->page()) |
124 m_identifier = createUniqueIdentifier(); | 124 m_identifier = createUniqueIdentifier(); |
125 } | 125 } |
126 | 126 |
127 NewWebSocketChannelImpl::~NewWebSocketChannelImpl() | 127 DocumentWebSocketChannel::~DocumentWebSocketChannel() |
128 { | 128 { |
129 ASSERT(!m_blobLoader); | 129 ASSERT(!m_blobLoader); |
130 } | 130 } |
131 | 131 |
132 bool NewWebSocketChannelImpl::connect(const KURL& url, const String& protocol) | 132 bool DocumentWebSocketChannel::connect(const KURL& url, const String& protocol) |
133 { | 133 { |
134 WTF_LOG(Network, "NewWebSocketChannelImpl %p connect()", this); | 134 WTF_LOG(Network, "DocumentWebSocketChannel %p connect()", this); |
135 if (!m_handle) | 135 if (!m_handle) |
136 return false; | 136 return false; |
137 | 137 |
138 if (executionContext()->isDocument() && document()->frame()) { | 138 if (executionContext()->isDocument() && document()->frame()) { |
139 if (!document()->frame()->loader().mixedContentChecker()->canConnectInse
cureWebSocket(document()->securityOrigin(), url)) | 139 if (!document()->frame()->loader().mixedContentChecker()->canConnectInse
cureWebSocket(document()->securityOrigin(), url)) |
140 return false; | 140 return false; |
141 } | 141 } |
142 if (MixedContentChecker::isMixedContent(document()->securityOrigin(), url))
{ | 142 if (MixedContentChecker::isMixedContent(document()->securityOrigin(), url))
{ |
143 String message = "Connecting to a non-secure WebSocket server from a sec
ure origin is deprecated."; | 143 String message = "Connecting to a non-secure WebSocket server from a sec
ure origin is deprecated."; |
144 document()->addConsoleMessage(ConsoleMessage::create(JSMessageSource, Wa
rningMessageLevel, message)); | 144 document()->addConsoleMessage(ConsoleMessage::create(JSMessageSource, Wa
rningMessageLevel, message)); |
(...skipping 20 matching lines...) Expand all Loading... |
165 flowControlIfNecessary(); | 165 flowControlIfNecessary(); |
166 if (m_identifier) { | 166 if (m_identifier) { |
167 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "We
bSocketCreate", "data", InspectorWebSocketCreateEvent::data(document(), m_identi
fier, url, protocol)); | 167 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "We
bSocketCreate", "data", InspectorWebSocketCreateEvent::data(document(), m_identi
fier, url, protocol)); |
168 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.stack"
), "CallStack", "stack", InspectorCallStackEvent::currentCallStack()); | 168 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.stack"
), "CallStack", "stack", InspectorCallStackEvent::currentCallStack()); |
169 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Ti
meline migrates to tracing. | 169 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Ti
meline migrates to tracing. |
170 InspectorInstrumentation::didCreateWebSocket(document(), m_identifier, u
rl, protocol); | 170 InspectorInstrumentation::didCreateWebSocket(document(), m_identifier, u
rl, protocol); |
171 } | 171 } |
172 return true; | 172 return true; |
173 } | 173 } |
174 | 174 |
175 void NewWebSocketChannelImpl::send(const String& message) | 175 void DocumentWebSocketChannel::send(const String& message) |
176 { | 176 { |
177 WTF_LOG(Network, "NewWebSocketChannelImpl %p sendText(%s)", this, message.ut
f8().data()); | 177 WTF_LOG(Network, "DocumentWebSocketChannel %p sendText(%s)", this, message.u
tf8().data()); |
178 if (m_identifier) { | 178 if (m_identifier) { |
179 // FIXME: Change the inspector API to show the entire message instead | 179 // FIXME: Change the inspector API to show the entire message instead |
180 // of individual frames. | 180 // of individual frames. |
181 CString data = message.utf8(); | 181 CString data = message.utf8(); |
182 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier
, WebSocketFrame::OpCodeText, true, data.data(), data.length()); | 182 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier
, WebSocketFrame::OpCodeText, true, data.data(), data.length()); |
183 } | 183 } |
184 m_messages.append(adoptPtr(new Message(message))); | 184 m_messages.append(adoptPtr(new Message(message))); |
185 sendInternal(); | 185 sendInternal(); |
186 } | 186 } |
187 | 187 |
188 void NewWebSocketChannelImpl::send(PassRefPtr<BlobDataHandle> blobDataHandle) | 188 void DocumentWebSocketChannel::send(PassRefPtr<BlobDataHandle> blobDataHandle) |
189 { | 189 { |
190 WTF_LOG(Network, "NewWebSocketChannelImpl %p sendBlob(%s, %s, %llu)", this,
blobDataHandle->uuid().utf8().data(), blobDataHandle->type().utf8().data(), blob
DataHandle->size()); | 190 WTF_LOG(Network, "DocumentWebSocketChannel %p sendBlob(%s, %s, %llu)", this,
blobDataHandle->uuid().utf8().data(), blobDataHandle->type().utf8().data(), blo
bDataHandle->size()); |
191 if (m_identifier) { | 191 if (m_identifier) { |
192 // FIXME: Change the inspector API to show the entire message instead | 192 // FIXME: Change the inspector API to show the entire message instead |
193 // of individual frames. | 193 // of individual frames. |
194 // FIXME: We can't access the data here. | 194 // FIXME: We can't access the data here. |
195 // Since Binary data are not displayed in Inspector, this does not | 195 // Since Binary data are not displayed in Inspector, this does not |
196 // affect actual behavior. | 196 // affect actual behavior. |
197 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier
, WebSocketFrame::OpCodeBinary, true, "", 0); | 197 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier
, WebSocketFrame::OpCodeBinary, true, "", 0); |
198 } | 198 } |
199 m_messages.append(adoptPtr(new Message(blobDataHandle))); | 199 m_messages.append(adoptPtr(new Message(blobDataHandle))); |
200 sendInternal(); | 200 sendInternal(); |
201 } | 201 } |
202 | 202 |
203 void NewWebSocketChannelImpl::send(const ArrayBuffer& buffer, unsigned byteOffse
t, unsigned byteLength) | 203 void DocumentWebSocketChannel::send(const ArrayBuffer& buffer, unsigned byteOffs
et, unsigned byteLength) |
204 { | 204 { |
205 WTF_LOG(Network, "NewWebSocketChannelImpl %p sendArrayBuffer(%p, %u, %u)", t
his, buffer.data(), byteOffset, byteLength); | 205 WTF_LOG(Network, "DocumentWebSocketChannel %p sendArrayBuffer(%p, %u, %u)",
this, buffer.data(), byteOffset, byteLength); |
206 if (m_identifier) { | 206 if (m_identifier) { |
207 // FIXME: Change the inspector API to show the entire message instead | 207 // FIXME: Change the inspector API to show the entire message instead |
208 // of individual frames. | 208 // of individual frames. |
209 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier
, WebSocketFrame::OpCodeBinary, true, static_cast<const char*>(buffer.data()) +
byteOffset, byteLength); | 209 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier
, WebSocketFrame::OpCodeBinary, true, static_cast<const char*>(buffer.data()) +
byteOffset, byteLength); |
210 } | 210 } |
211 // buffer.slice copies its contents. | 211 // buffer.slice copies its contents. |
212 // FIXME: Reduce copy by sending the data immediately when we don't need to | 212 // FIXME: Reduce copy by sending the data immediately when we don't need to |
213 // queue the data. | 213 // queue the data. |
214 m_messages.append(adoptPtr(new Message(buffer.slice(byteOffset, byteOffset +
byteLength)))); | 214 m_messages.append(adoptPtr(new Message(buffer.slice(byteOffset, byteOffset +
byteLength)))); |
215 sendInternal(); | 215 sendInternal(); |
216 } | 216 } |
217 | 217 |
218 void NewWebSocketChannelImpl::send(PassOwnPtr<Vector<char> > data) | 218 void DocumentWebSocketChannel::send(PassOwnPtr<Vector<char> > data) |
219 { | 219 { |
220 WTF_LOG(Network, "NewWebSocketChannelImpl %p sendVector(%p, %llu)", this, da
ta.get(), static_cast<unsigned long long>(data->size())); | 220 WTF_LOG(Network, "DocumentWebSocketChannel %p sendVector(%p, %llu)", this, d
ata.get(), static_cast<unsigned long long>(data->size())); |
221 if (m_identifier) { | 221 if (m_identifier) { |
222 // FIXME: Change the inspector API to show the entire message instead | 222 // FIXME: Change the inspector API to show the entire message instead |
223 // of individual frames. | 223 // of individual frames. |
224 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier
, WebSocketFrame::OpCodeBinary, true, data->data(), data->size()); | 224 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier
, WebSocketFrame::OpCodeBinary, true, data->data(), data->size()); |
225 } | 225 } |
226 m_messages.append(adoptPtr(new Message(data))); | 226 m_messages.append(adoptPtr(new Message(data))); |
227 sendInternal(); | 227 sendInternal(); |
228 } | 228 } |
229 | 229 |
230 void NewWebSocketChannelImpl::close(int code, const String& reason) | 230 void DocumentWebSocketChannel::close(int code, const String& reason) |
231 { | 231 { |
232 WTF_LOG(Network, "NewWebSocketChannelImpl %p close(%d, %s)", this, code, rea
son.utf8().data()); | 232 WTF_LOG(Network, "DocumentWebSocketChannel %p close(%d, %s)", this, code, re
ason.utf8().data()); |
233 ASSERT(m_handle); | 233 ASSERT(m_handle); |
234 unsigned short codeToSend = static_cast<unsigned short>(code == CloseEventCo
deNotSpecified ? CloseEventCodeNoStatusRcvd : code); | 234 unsigned short codeToSend = static_cast<unsigned short>(code == CloseEventCo
deNotSpecified ? CloseEventCodeNoStatusRcvd : code); |
235 m_messages.append(adoptPtr(new Message(codeToSend, reason))); | 235 m_messages.append(adoptPtr(new Message(codeToSend, reason))); |
236 sendInternal(); | 236 sendInternal(); |
237 } | 237 } |
238 | 238 |
239 void NewWebSocketChannelImpl::fail(const String& reason, MessageLevel level, con
st String& sourceURL, unsigned lineNumber) | 239 void DocumentWebSocketChannel::fail(const String& reason, MessageLevel level, co
nst String& sourceURL, unsigned lineNumber) |
240 { | 240 { |
241 WTF_LOG(Network, "NewWebSocketChannelImpl %p fail(%s)", this, reason.utf8().
data()); | 241 WTF_LOG(Network, "DocumentWebSocketChannel %p fail(%s)", this, reason.utf8()
.data()); |
242 // m_handle and m_client can be null here. | 242 // m_handle and m_client can be null here. |
243 | 243 |
244 if (m_identifier) | 244 if (m_identifier) |
245 InspectorInstrumentation::didReceiveWebSocketFrameError(document(), m_id
entifier, reason); | 245 InspectorInstrumentation::didReceiveWebSocketFrameError(document(), m_id
entifier, reason); |
246 const String message = "WebSocket connection to '" + m_url.elidedString() +
"' failed: " + reason; | 246 const String message = "WebSocket connection to '" + m_url.elidedString() +
"' failed: " + reason; |
247 executionContext()->addConsoleMessage(ConsoleMessage::create(JSMessageSource
, level, message, sourceURL, lineNumber)); | 247 executionContext()->addConsoleMessage(ConsoleMessage::create(JSMessageSource
, level, message, sourceURL, lineNumber)); |
248 | 248 |
249 if (m_client) | 249 if (m_client) |
250 m_client->didError(); | 250 m_client->didError(); |
251 // |reason| is only for logging and should not be provided for scripts, | 251 // |reason| is only for logging and should not be provided for scripts, |
252 // hence close reason must be empty. | 252 // hence close reason must be empty. |
253 handleDidClose(false, CloseEventCodeAbnormalClosure, String()); | 253 handleDidClose(false, CloseEventCodeAbnormalClosure, String()); |
254 // handleDidClose may delete this object. | 254 // handleDidClose may delete this object. |
255 } | 255 } |
256 | 256 |
257 void NewWebSocketChannelImpl::disconnect() | 257 void DocumentWebSocketChannel::disconnect() |
258 { | 258 { |
259 WTF_LOG(Network, "NewWebSocketChannelImpl %p disconnect()", this); | 259 WTF_LOG(Network, "DocumentWebSocketChannel %p disconnect()", this); |
260 if (m_identifier) { | 260 if (m_identifier) { |
261 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "We
bSocketDestroy", "data", InspectorWebSocketEvent::data(document(), m_identifier)
); | 261 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "We
bSocketDestroy", "data", InspectorWebSocketEvent::data(document(), m_identifier)
); |
262 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.stack"
), "CallStack", "stack", InspectorCallStackEvent::currentCallStack()); | 262 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.stack"
), "CallStack", "stack", InspectorCallStackEvent::currentCallStack()); |
263 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Ti
meline migrates to tracing. | 263 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Ti
meline migrates to tracing. |
264 InspectorInstrumentation::didCloseWebSocket(document(), m_identifier); | 264 InspectorInstrumentation::didCloseWebSocket(document(), m_identifier); |
265 } | 265 } |
266 abortAsyncOperations(); | 266 abortAsyncOperations(); |
267 m_handle.clear(); | 267 m_handle.clear(); |
268 m_client = nullptr; | 268 m_client = nullptr; |
269 m_identifier = 0; | 269 m_identifier = 0; |
270 } | 270 } |
271 | 271 |
272 void NewWebSocketChannelImpl::suspend() | 272 void DocumentWebSocketChannel::suspend() |
273 { | 273 { |
274 WTF_LOG(Network, "NewWebSocketChannelImpl %p suspend()", this); | 274 WTF_LOG(Network, "DocumentWebSocketChannel %p suspend()", this); |
275 } | 275 } |
276 | 276 |
277 void NewWebSocketChannelImpl::resume() | 277 void DocumentWebSocketChannel::resume() |
278 { | 278 { |
279 WTF_LOG(Network, "NewWebSocketChannelImpl %p resume()", this); | 279 WTF_LOG(Network, "DocumentWebSocketChannel %p resume()", this); |
280 } | 280 } |
281 | 281 |
282 NewWebSocketChannelImpl::Message::Message(const String& text) | 282 DocumentWebSocketChannel::Message::Message(const String& text) |
283 : type(MessageTypeText) | 283 : type(MessageTypeText) |
284 , text(text.utf8(StrictUTF8ConversionReplacingUnpairedSurrogatesWithFFFD)) {
} | 284 , text(text.utf8(StrictUTF8ConversionReplacingUnpairedSurrogatesWithFFFD)) {
} |
285 | 285 |
286 NewWebSocketChannelImpl::Message::Message(PassRefPtr<BlobDataHandle> blobDataHan
dle) | 286 DocumentWebSocketChannel::Message::Message(PassRefPtr<BlobDataHandle> blobDataHa
ndle) |
287 : type(MessageTypeBlob) | 287 : type(MessageTypeBlob) |
288 , blobDataHandle(blobDataHandle) { } | 288 , blobDataHandle(blobDataHandle) { } |
289 | 289 |
290 NewWebSocketChannelImpl::Message::Message(PassRefPtr<ArrayBuffer> arrayBuffer) | 290 DocumentWebSocketChannel::Message::Message(PassRefPtr<ArrayBuffer> arrayBuffer) |
291 : type(MessageTypeArrayBuffer) | 291 : type(MessageTypeArrayBuffer) |
292 , arrayBuffer(arrayBuffer) { } | 292 , arrayBuffer(arrayBuffer) { } |
293 | 293 |
294 NewWebSocketChannelImpl::Message::Message(PassOwnPtr<Vector<char> > vectorData) | 294 DocumentWebSocketChannel::Message::Message(PassOwnPtr<Vector<char> > vectorData) |
295 : type(MessageTypeVector) | 295 : type(MessageTypeVector) |
296 , vectorData(vectorData) { } | 296 , vectorData(vectorData) { } |
297 | 297 |
298 NewWebSocketChannelImpl::Message::Message(unsigned short code, const String& rea
son) | 298 DocumentWebSocketChannel::Message::Message(unsigned short code, const String& re
ason) |
299 : type(MessageTypeClose) | 299 : type(MessageTypeClose) |
300 , code(code) | 300 , code(code) |
301 , reason(reason) { } | 301 , reason(reason) { } |
302 | 302 |
303 void NewWebSocketChannelImpl::sendInternal() | 303 void DocumentWebSocketChannel::sendInternal() |
304 { | 304 { |
305 ASSERT(m_handle); | 305 ASSERT(m_handle); |
306 unsigned long consumedBufferedAmount = 0; | 306 unsigned long consumedBufferedAmount = 0; |
307 while (!m_messages.isEmpty() && !m_blobLoader) { | 307 while (!m_messages.isEmpty() && !m_blobLoader) { |
308 bool final = false; | 308 bool final = false; |
309 Message* message = m_messages.first().get(); | 309 Message* message = m_messages.first().get(); |
310 if (m_sendingQuota <= 0 && message->type != MessageTypeClose) | 310 if (m_sendingQuota <= 0 && message->type != MessageTypeClose) |
311 break; | 311 break; |
312 switch (message->type) { | 312 switch (message->type) { |
313 case MessageTypeText: { | 313 case MessageTypeText: { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 } | 357 } |
358 if (final) { | 358 if (final) { |
359 m_messages.removeFirst(); | 359 m_messages.removeFirst(); |
360 m_sentSizeOfTopMessage = 0; | 360 m_sentSizeOfTopMessage = 0; |
361 } | 361 } |
362 } | 362 } |
363 if (m_client && consumedBufferedAmount > 0) | 363 if (m_client && consumedBufferedAmount > 0) |
364 m_client->didConsumeBufferedAmount(consumedBufferedAmount); | 364 m_client->didConsumeBufferedAmount(consumedBufferedAmount); |
365 } | 365 } |
366 | 366 |
367 void NewWebSocketChannelImpl::flowControlIfNecessary() | 367 void DocumentWebSocketChannel::flowControlIfNecessary() |
368 { | 368 { |
369 if (!m_handle || m_receivedDataSizeForFlowControl < receivedDataSizeForFlowC
ontrolHighWaterMark) { | 369 if (!m_handle || m_receivedDataSizeForFlowControl < receivedDataSizeForFlowC
ontrolHighWaterMark) { |
370 return; | 370 return; |
371 } | 371 } |
372 m_handle->flowControl(m_receivedDataSizeForFlowControl); | 372 m_handle->flowControl(m_receivedDataSizeForFlowControl); |
373 m_receivedDataSizeForFlowControl = 0; | 373 m_receivedDataSizeForFlowControl = 0; |
374 } | 374 } |
375 | 375 |
376 void NewWebSocketChannelImpl::abortAsyncOperations() | 376 void DocumentWebSocketChannel::abortAsyncOperations() |
377 { | 377 { |
378 if (m_blobLoader) { | 378 if (m_blobLoader) { |
379 m_blobLoader->cancel(); | 379 m_blobLoader->cancel(); |
380 m_blobLoader.clear(); | 380 m_blobLoader.clear(); |
381 } | 381 } |
382 } | 382 } |
383 | 383 |
384 void NewWebSocketChannelImpl::handleDidClose(bool wasClean, unsigned short code,
const String& reason) | 384 void DocumentWebSocketChannel::handleDidClose(bool wasClean, unsigned short code
, const String& reason) |
385 { | 385 { |
386 m_handle.clear(); | 386 m_handle.clear(); |
387 abortAsyncOperations(); | 387 abortAsyncOperations(); |
388 if (!m_client) { | 388 if (!m_client) { |
389 return; | 389 return; |
390 } | 390 } |
391 WebSocketChannelClient* client = m_client; | 391 WebSocketChannelClient* client = m_client; |
392 m_client = nullptr; | 392 m_client = nullptr; |
393 WebSocketChannelClient::ClosingHandshakeCompletionStatus status = | 393 WebSocketChannelClient::ClosingHandshakeCompletionStatus status = |
394 wasClean ? WebSocketChannelClient::ClosingHandshakeComplete : WebSocketC
hannelClient::ClosingHandshakeIncomplete; | 394 wasClean ? WebSocketChannelClient::ClosingHandshakeComplete : WebSocketC
hannelClient::ClosingHandshakeIncomplete; |
395 client->didClose(status, code, reason); | 395 client->didClose(status, code, reason); |
396 // client->didClose may delete this object. | 396 // client->didClose may delete this object. |
397 } | 397 } |
398 | 398 |
399 Document* NewWebSocketChannelImpl::document() | 399 Document* DocumentWebSocketChannel::document() |
400 { | 400 { |
401 ASSERT(m_identifier); | 401 ASSERT(m_identifier); |
402 ExecutionContext* context = executionContext(); | 402 ExecutionContext* context = executionContext(); |
403 ASSERT(context->isDocument()); | 403 ASSERT(context->isDocument()); |
404 return toDocument(context); | 404 return toDocument(context); |
405 } | 405 } |
406 | 406 |
407 void NewWebSocketChannelImpl::didConnect(WebSocketHandle* handle, bool fail, con
st WebString& selectedProtocol, const WebString& extensions) | 407 void DocumentWebSocketChannel::didConnect(WebSocketHandle* handle, bool fail, co
nst WebString& selectedProtocol, const WebString& extensions) |
408 { | 408 { |
409 WTF_LOG(Network, "NewWebSocketChannelImpl %p didConnect(%p, %d, %s, %s)", th
is, handle, fail, selectedProtocol.utf8().data(), extensions.utf8().data()); | 409 WTF_LOG(Network, "DocumentWebSocketChannel %p didConnect(%p, %d, %s, %s)", t
his, handle, fail, selectedProtocol.utf8().data(), extensions.utf8().data()); |
410 | 410 |
411 ASSERT(m_handle); | 411 ASSERT(m_handle); |
412 ASSERT(handle == m_handle); | 412 ASSERT(handle == m_handle); |
413 ASSERT(m_client); | 413 ASSERT(m_client); |
414 | 414 |
415 if (fail) { | 415 if (fail) { |
416 failAsError("Cannot connect to " + m_url.string() + "."); | 416 failAsError("Cannot connect to " + m_url.string() + "."); |
417 // failAsError may delete this object. | 417 // failAsError may delete this object. |
418 return; | 418 return; |
419 } | 419 } |
420 m_client->didConnect(selectedProtocol, extensions); | 420 m_client->didConnect(selectedProtocol, extensions); |
421 } | 421 } |
422 | 422 |
423 void NewWebSocketChannelImpl::didStartOpeningHandshake(WebSocketHandle* handle,
const WebSocketHandshakeRequestInfo& request) | 423 void DocumentWebSocketChannel::didStartOpeningHandshake(WebSocketHandle* handle,
const WebSocketHandshakeRequestInfo& request) |
424 { | 424 { |
425 WTF_LOG(Network, "NewWebSocketChannelImpl %p didStartOpeningHandshake(%p)",
this, handle); | 425 WTF_LOG(Network, "DocumentWebSocketChannel %p didStartOpeningHandshake(%p)",
this, handle); |
426 | 426 |
427 ASSERT(m_handle); | 427 ASSERT(m_handle); |
428 ASSERT(handle == m_handle); | 428 ASSERT(handle == m_handle); |
429 | 429 |
430 if (m_identifier) { | 430 if (m_identifier) { |
431 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "We
bSocketSendHandshakeRequest", "data", InspectorWebSocketEvent::data(document(),
m_identifier)); | 431 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "We
bSocketSendHandshakeRequest", "data", InspectorWebSocketEvent::data(document(),
m_identifier)); |
432 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.stack"
), "CallStack", "stack", InspectorCallStackEvent::currentCallStack()); | 432 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.stack"
), "CallStack", "stack", InspectorCallStackEvent::currentCallStack()); |
433 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Ti
meline migrates to tracing. | 433 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Ti
meline migrates to tracing. |
434 InspectorInstrumentation::willSendWebSocketHandshakeRequest(document(),
m_identifier, &request.toCoreRequest()); | 434 InspectorInstrumentation::willSendWebSocketHandshakeRequest(document(),
m_identifier, &request.toCoreRequest()); |
435 m_handshakeRequest = WebSocketHandshakeRequest::create(request.toCoreReq
uest()); | 435 m_handshakeRequest = WebSocketHandshakeRequest::create(request.toCoreReq
uest()); |
436 } | 436 } |
437 } | 437 } |
438 | 438 |
439 void NewWebSocketChannelImpl::didFinishOpeningHandshake(WebSocketHandle* handle,
const WebSocketHandshakeResponseInfo& response) | 439 void DocumentWebSocketChannel::didFinishOpeningHandshake(WebSocketHandle* handle
, const WebSocketHandshakeResponseInfo& response) |
440 { | 440 { |
441 WTF_LOG(Network, "NewWebSocketChannelImpl %p didFinishOpeningHandshake(%p)",
this, handle); | 441 WTF_LOG(Network, "DocumentWebSocketChannel %p didFinishOpeningHandshake(%p)"
, this, handle); |
442 | 442 |
443 ASSERT(m_handle); | 443 ASSERT(m_handle); |
444 ASSERT(handle == m_handle); | 444 ASSERT(handle == m_handle); |
445 | 445 |
446 if (m_identifier) { | 446 if (m_identifier) { |
447 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "We
bSocketReceiveHandshakeResponse", "data", InspectorWebSocketEvent::data(document
(), m_identifier)); | 447 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "We
bSocketReceiveHandshakeResponse", "data", InspectorWebSocketEvent::data(document
(), m_identifier)); |
448 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Ti
meline migrates to tracing. | 448 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Ti
meline migrates to tracing. |
449 InspectorInstrumentation::didReceiveWebSocketHandshakeResponse(document(
), m_identifier, m_handshakeRequest.get(), &response.toCoreResponse()); | 449 InspectorInstrumentation::didReceiveWebSocketHandshakeResponse(document(
), m_identifier, m_handshakeRequest.get(), &response.toCoreResponse()); |
450 } | 450 } |
451 m_handshakeRequest.clear(); | 451 m_handshakeRequest.clear(); |
452 } | 452 } |
453 | 453 |
454 void NewWebSocketChannelImpl::didFail(WebSocketHandle* handle, const WebString&
message) | 454 void DocumentWebSocketChannel::didFail(WebSocketHandle* handle, const WebString&
message) |
455 { | 455 { |
456 WTF_LOG(Network, "NewWebSocketChannelImpl %p didFail(%p, %s)", this, handle,
message.utf8().data()); | 456 WTF_LOG(Network, "DocumentWebSocketChannel %p didFail(%p, %s)", this, handle
, message.utf8().data()); |
457 | 457 |
458 ASSERT(m_handle); | 458 ASSERT(m_handle); |
459 ASSERT(handle == m_handle); | 459 ASSERT(handle == m_handle); |
460 | 460 |
461 // This function is called when the browser is required to fail the | 461 // This function is called when the browser is required to fail the |
462 // WebSocketConnection. Hence we fail this channel by calling | 462 // WebSocketConnection. Hence we fail this channel by calling |
463 // |this->failAsError| function. | 463 // |this->failAsError| function. |
464 failAsError(message); | 464 failAsError(message); |
465 // |this| may be deleted. | 465 // |this| may be deleted. |
466 } | 466 } |
467 | 467 |
468 void NewWebSocketChannelImpl::didReceiveData(WebSocketHandle* handle, bool fin,
WebSocketHandle::MessageType type, const char* data, size_t size) | 468 void DocumentWebSocketChannel::didReceiveData(WebSocketHandle* handle, bool fin,
WebSocketHandle::MessageType type, const char* data, size_t size) |
469 { | 469 { |
470 WTF_LOG(Network, "NewWebSocketChannelImpl %p didReceiveData(%p, %d, %d, (%p,
%zu))", this, handle, fin, type, data, size); | 470 WTF_LOG(Network, "DocumentWebSocketChannel %p didReceiveData(%p, %d, %d, (%p
, %zu))", this, handle, fin, type, data, size); |
471 | 471 |
472 ASSERT(m_handle); | 472 ASSERT(m_handle); |
473 ASSERT(handle == m_handle); | 473 ASSERT(handle == m_handle); |
474 ASSERT(m_client); | 474 ASSERT(m_client); |
475 // Non-final frames cannot be empty. | 475 // Non-final frames cannot be empty. |
476 ASSERT(fin || size); | 476 ASSERT(fin || size); |
477 | 477 |
478 switch (type) { | 478 switch (type) { |
479 case WebSocketHandle::MessageTypeText: | 479 case WebSocketHandle::MessageTypeText: |
480 ASSERT(m_receivingMessageData.isEmpty()); | 480 ASSERT(m_receivingMessageData.isEmpty()); |
(...skipping 30 matching lines...) Expand all Loading... |
511 } else { | 511 } else { |
512 m_client->didReceiveTextMessage(message); | 512 m_client->didReceiveTextMessage(message); |
513 } | 513 } |
514 } else { | 514 } else { |
515 OwnPtr<Vector<char> > binaryData = adoptPtr(new Vector<char>); | 515 OwnPtr<Vector<char> > binaryData = adoptPtr(new Vector<char>); |
516 binaryData->swap(m_receivingMessageData); | 516 binaryData->swap(m_receivingMessageData); |
517 m_client->didReceiveBinaryMessage(binaryData.release()); | 517 m_client->didReceiveBinaryMessage(binaryData.release()); |
518 } | 518 } |
519 } | 519 } |
520 | 520 |
521 void NewWebSocketChannelImpl::didClose(WebSocketHandle* handle, bool wasClean, u
nsigned short code, const WebString& reason) | 521 void DocumentWebSocketChannel::didClose(WebSocketHandle* handle, bool wasClean,
unsigned short code, const WebString& reason) |
522 { | 522 { |
523 WTF_LOG(Network, "NewWebSocketChannelImpl %p didClose(%p, %d, %u, %s)", this
, handle, wasClean, code, String(reason).utf8().data()); | 523 WTF_LOG(Network, "DocumentWebSocketChannel %p didClose(%p, %d, %u, %s)", thi
s, handle, wasClean, code, String(reason).utf8().data()); |
524 | 524 |
525 ASSERT(m_handle); | 525 ASSERT(m_handle); |
526 ASSERT(handle == m_handle); | 526 ASSERT(handle == m_handle); |
527 | 527 |
528 m_handle.clear(); | 528 m_handle.clear(); |
529 | 529 |
530 if (m_identifier) { | 530 if (m_identifier) { |
531 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "We
bSocketDestroy", "data", InspectorWebSocketEvent::data(document(), m_identifier)
); | 531 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "We
bSocketDestroy", "data", InspectorWebSocketEvent::data(document(), m_identifier)
); |
532 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.stack"
), "CallStack", "stack", InspectorCallStackEvent::currentCallStack()); | 532 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.stack"
), "CallStack", "stack", InspectorCallStackEvent::currentCallStack()); |
533 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Ti
meline migrates to tracing. | 533 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Ti
meline migrates to tracing. |
534 InspectorInstrumentation::didCloseWebSocket(document(), m_identifier); | 534 InspectorInstrumentation::didCloseWebSocket(document(), m_identifier); |
535 m_identifier = 0; | 535 m_identifier = 0; |
536 } | 536 } |
537 | 537 |
538 handleDidClose(wasClean, code, reason); | 538 handleDidClose(wasClean, code, reason); |
539 // handleDidClose may delete this object. | 539 // handleDidClose may delete this object. |
540 } | 540 } |
541 | 541 |
542 void NewWebSocketChannelImpl::didReceiveFlowControl(WebSocketHandle* handle, int
64_t quota) | 542 void DocumentWebSocketChannel::didReceiveFlowControl(WebSocketHandle* handle, in
t64_t quota) |
543 { | 543 { |
544 WTF_LOG(Network, "NewWebSocketChannelImpl %p didReceiveFlowControl(%p, %ld)"
, this, handle, static_cast<long>(quota)); | 544 WTF_LOG(Network, "DocumentWebSocketChannel %p didReceiveFlowControl(%p, %ld)
", this, handle, static_cast<long>(quota)); |
545 | 545 |
546 ASSERT(m_handle); | 546 ASSERT(m_handle); |
547 ASSERT(handle == m_handle); | 547 ASSERT(handle == m_handle); |
548 | 548 |
549 m_sendingQuota += quota; | 549 m_sendingQuota += quota; |
550 sendInternal(); | 550 sendInternal(); |
551 } | 551 } |
552 | 552 |
553 void NewWebSocketChannelImpl::didStartClosingHandshake(WebSocketHandle* handle) | 553 void DocumentWebSocketChannel::didStartClosingHandshake(WebSocketHandle* handle) |
554 { | 554 { |
555 WTF_LOG(Network, "NewWebSocketChannelImpl %p didStartClosingHandshake(%p)",
this, handle); | 555 WTF_LOG(Network, "DocumentWebSocketChannel %p didStartClosingHandshake(%p)",
this, handle); |
556 | 556 |
557 ASSERT(m_handle); | 557 ASSERT(m_handle); |
558 ASSERT(handle == m_handle); | 558 ASSERT(handle == m_handle); |
559 | 559 |
560 if (m_client) | 560 if (m_client) |
561 m_client->didStartClosingHandshake(); | 561 m_client->didStartClosingHandshake(); |
562 } | 562 } |
563 | 563 |
564 void NewWebSocketChannelImpl::didFinishLoadingBlob(PassRefPtr<ArrayBuffer> buffe
r) | 564 void DocumentWebSocketChannel::didFinishLoadingBlob(PassRefPtr<ArrayBuffer> buff
er) |
565 { | 565 { |
566 m_blobLoader.clear(); | 566 m_blobLoader.clear(); |
567 ASSERT(m_handle); | 567 ASSERT(m_handle); |
568 // The loaded blob is always placed on m_messages[0]. | 568 // The loaded blob is always placed on m_messages[0]. |
569 ASSERT(m_messages.size() > 0 && m_messages.first()->type == MessageTypeBlob)
; | 569 ASSERT(m_messages.size() > 0 && m_messages.first()->type == MessageTypeBlob)
; |
570 // We replace it with the loaded blob. | 570 // We replace it with the loaded blob. |
571 m_messages.first() = adoptPtr(new Message(buffer)); | 571 m_messages.first() = adoptPtr(new Message(buffer)); |
572 sendInternal(); | 572 sendInternal(); |
573 } | 573 } |
574 | 574 |
575 void NewWebSocketChannelImpl::didFailLoadingBlob(FileError::ErrorCode errorCode) | 575 void DocumentWebSocketChannel::didFailLoadingBlob(FileError::ErrorCode errorCode
) |
576 { | 576 { |
577 m_blobLoader.clear(); | 577 m_blobLoader.clear(); |
578 if (errorCode == FileError::ABORT_ERR) { | 578 if (errorCode == FileError::ABORT_ERR) { |
579 // The error is caused by cancel(). | 579 // The error is caused by cancel(). |
580 return; | 580 return; |
581 } | 581 } |
582 // FIXME: Generate human-friendly reason message. | 582 // FIXME: Generate human-friendly reason message. |
583 failAsError("Failed to load Blob: error code = " + String::number(errorCode)
); | 583 failAsError("Failed to load Blob: error code = " + String::number(errorCode)
); |
584 // |this| can be deleted here. | 584 // |this| can be deleted here. |
585 } | 585 } |
586 | 586 |
587 void NewWebSocketChannelImpl::trace(Visitor* visitor) | 587 void DocumentWebSocketChannel::trace(Visitor* visitor) |
588 { | 588 { |
589 visitor->trace(m_blobLoader); | 589 visitor->trace(m_blobLoader); |
590 visitor->trace(m_client); | 590 visitor->trace(m_client); |
591 WebSocketChannel::trace(visitor); | 591 WebSocketChannel::trace(visitor); |
592 } | 592 } |
593 | 593 |
594 } // namespace blink | 594 } // namespace blink |
OLD | NEW |