| 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 27 matching lines...) Expand all Loading... |
| 38 #include "core/fileapi/FileReaderLoaderClient.h" | 38 #include "core/fileapi/FileReaderLoaderClient.h" |
| 39 #include "core/frame/LocalFrame.h" | 39 #include "core/frame/LocalFrame.h" |
| 40 #include "core/inspector/ConsoleMessage.h" | 40 #include "core/inspector/ConsoleMessage.h" |
| 41 #include "core/inspector/InspectorInstrumentation.h" | 41 #include "core/inspector/InspectorInstrumentation.h" |
| 42 #include "core/loader/FrameLoader.h" | 42 #include "core/loader/FrameLoader.h" |
| 43 #include "core/loader/FrameLoaderClient.h" | 43 #include "core/loader/FrameLoaderClient.h" |
| 44 #include "core/loader/MixedContentChecker.h" | 44 #include "core/loader/MixedContentChecker.h" |
| 45 #include "modules/websockets/InspectorWebSocketEvents.h" | 45 #include "modules/websockets/InspectorWebSocketEvents.h" |
| 46 #include "modules/websockets/WebSocketChannelClient.h" | 46 #include "modules/websockets/WebSocketChannelClient.h" |
| 47 #include "modules/websockets/WebSocketFrame.h" | 47 #include "modules/websockets/WebSocketFrame.h" |
| 48 #include "platform/Logging.h" | 48 #include "platform/network/NetworkLog.h" |
| 49 #include "platform/network/WebSocketHandshakeRequest.h" | 49 #include "platform/network/WebSocketHandshakeRequest.h" |
| 50 #include "platform/weborigin/SecurityOrigin.h" | 50 #include "platform/weborigin/SecurityOrigin.h" |
| 51 #include "public/platform/Platform.h" | 51 #include "public/platform/Platform.h" |
| 52 #include "public/platform/WebSecurityOrigin.h" | 52 #include "public/platform/WebSecurityOrigin.h" |
| 53 #include "public/platform/WebString.h" | 53 #include "public/platform/WebString.h" |
| 54 #include "public/platform/WebURL.h" | 54 #include "public/platform/WebURL.h" |
| 55 #include "public/platform/WebVector.h" | 55 #include "public/platform/WebVector.h" |
| 56 #include "public/platform/modules/websockets/WebSocketHandshakeRequestInfo.h" | 56 #include "public/platform/modules/websockets/WebSocketHandshakeRequestInfo.h" |
| 57 #include "public/platform/modules/websockets/WebSocketHandshakeResponseInfo.h" | 57 #include "public/platform/modules/websockets/WebSocketHandshakeResponseInfo.h" |
| 58 #include "wtf/PtrUtil.h" | 58 #include "wtf/PtrUtil.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 { | 146 { |
| 147 } | 147 } |
| 148 | 148 |
| 149 DocumentWebSocketChannel::~DocumentWebSocketChannel() | 149 DocumentWebSocketChannel::~DocumentWebSocketChannel() |
| 150 { | 150 { |
| 151 ASSERT(!m_blobLoader); | 151 ASSERT(!m_blobLoader); |
| 152 } | 152 } |
| 153 | 153 |
| 154 bool DocumentWebSocketChannel::connect(const KURL& url, const String& protocol) | 154 bool DocumentWebSocketChannel::connect(const KURL& url, const String& protocol) |
| 155 { | 155 { |
| 156 WTF_LOG(Network, "DocumentWebSocketChannel %p connect()", this); | 156 NETWORK_DVLOG(1) << this << " connect()"; |
| 157 if (!m_handle) | 157 if (!m_handle) |
| 158 return false; | 158 return false; |
| 159 | 159 |
| 160 if (document()->frame()) { | 160 if (document()->frame()) { |
| 161 if (MixedContentChecker::shouldBlockWebSocket(document()->frame(), url)) | 161 if (MixedContentChecker::shouldBlockWebSocket(document()->frame(), url)) |
| 162 return false; | 162 return false; |
| 163 } | 163 } |
| 164 if (MixedContentChecker::isMixedContent(document()->getSecurityOrigin(), url
)) { | 164 if (MixedContentChecker::isMixedContent(document()->getSecurityOrigin(), url
)) { |
| 165 String message = "Connecting to a non-secure WebSocket server from a sec
ure origin is deprecated."; | 165 String message = "Connecting to a non-secure WebSocket server from a sec
ure origin is deprecated."; |
| 166 document()->addConsoleMessage(ConsoleMessage::create(JSMessageSource, Wa
rningMessageLevel, message)); | 166 document()->addConsoleMessage(ConsoleMessage::create(JSMessageSource, Wa
rningMessageLevel, message)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 185 m_handle->connect(url, webProtocols, WebSecurityOrigin(getExecutionContext()
->getSecurityOrigin()), document()->firstPartyForCookies(), document()->userAgen
t(), this); | 185 m_handle->connect(url, webProtocols, WebSecurityOrigin(getExecutionContext()
->getSecurityOrigin()), document()->firstPartyForCookies(), document()->userAgen
t(), this); |
| 186 | 186 |
| 187 flowControlIfNecessary(); | 187 flowControlIfNecessary(); |
| 188 TRACE_EVENT_INSTANT1("devtools.timeline", "WebSocketCreate", TRACE_EVENT_SCO
PE_THREAD, "data", InspectorWebSocketCreateEvent::data(document(), m_identifier,
url, protocol)); | 188 TRACE_EVENT_INSTANT1("devtools.timeline", "WebSocketCreate", TRACE_EVENT_SCO
PE_THREAD, "data", InspectorWebSocketCreateEvent::data(document(), m_identifier,
url, protocol)); |
| 189 InspectorInstrumentation::didCreateWebSocket(document(), m_identifier, url,
protocol); | 189 InspectorInstrumentation::didCreateWebSocket(document(), m_identifier, url,
protocol); |
| 190 return true; | 190 return true; |
| 191 } | 191 } |
| 192 | 192 |
| 193 void DocumentWebSocketChannel::send(const CString& message) | 193 void DocumentWebSocketChannel::send(const CString& message) |
| 194 { | 194 { |
| 195 WTF_LOG(Network, "DocumentWebSocketChannel %p sendText(%s)", this, message.d
ata()); | 195 NETWORK_DVLOG(1) << this << " sendText(" << message.data() << ")"; |
| 196 // FIXME: Change the inspector API to show the entire message instead | 196 // FIXME: Change the inspector API to show the entire message instead |
| 197 // of individual frames. | 197 // of individual frames. |
| 198 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier, We
bSocketFrame::OpCodeText, true, message.data(), message.length()); | 198 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier, We
bSocketFrame::OpCodeText, true, message.data(), message.length()); |
| 199 m_messages.append(new Message(message)); | 199 m_messages.append(new Message(message)); |
| 200 processSendQueue(); | 200 processSendQueue(); |
| 201 } | 201 } |
| 202 | 202 |
| 203 void DocumentWebSocketChannel::send(PassRefPtr<BlobDataHandle> blobDataHandle) | 203 void DocumentWebSocketChannel::send(PassRefPtr<BlobDataHandle> blobDataHandle) |
| 204 { | 204 { |
| 205 WTF_LOG(Network, "DocumentWebSocketChannel %p sendBlob(%s, %s, %llu)", this,
blobDataHandle->uuid().utf8().data(), blobDataHandle->type().utf8().data(), blo
bDataHandle->size()); | 205 NETWORK_DVLOG(1) << this << " sendBlob(" << blobDataHandle->uuid() << ", " <
< blobDataHandle->type() << ", " << blobDataHandle->size() << ")"; |
| 206 // FIXME: Change the inspector API to show the entire message instead | 206 // FIXME: Change the inspector API to show the entire message instead |
| 207 // of individual frames. | 207 // of individual frames. |
| 208 // FIXME: We can't access the data here. | 208 // FIXME: We can't access the data here. |
| 209 // Since Binary data are not displayed in Inspector, this does not | 209 // Since Binary data are not displayed in Inspector, this does not |
| 210 // affect actual behavior. | 210 // affect actual behavior. |
| 211 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier, We
bSocketFrame::OpCodeBinary, true, "", 0); | 211 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier, We
bSocketFrame::OpCodeBinary, true, "", 0); |
| 212 m_messages.append(new Message(blobDataHandle)); | 212 m_messages.append(new Message(blobDataHandle)); |
| 213 processSendQueue(); | 213 processSendQueue(); |
| 214 } | 214 } |
| 215 | 215 |
| 216 void DocumentWebSocketChannel::send(const DOMArrayBuffer& buffer, unsigned byteO
ffset, unsigned byteLength) | 216 void DocumentWebSocketChannel::send(const DOMArrayBuffer& buffer, unsigned byteO
ffset, unsigned byteLength) |
| 217 { | 217 { |
| 218 WTF_LOG(Network, "DocumentWebSocketChannel %p sendArrayBuffer(%p, %u, %u)",
this, buffer.data(), byteOffset, byteLength); | 218 NETWORK_DVLOG(1) << this << " sendArrayBuffer(" << buffer.data() << ", " <<
byteOffset << ", " << byteLength << ")"; |
| 219 // FIXME: Change the inspector API to show the entire message instead | 219 // FIXME: Change the inspector API to show the entire message instead |
| 220 // of individual frames. | 220 // of individual frames. |
| 221 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier, We
bSocketFrame::OpCodeBinary, true, static_cast<const char*>(buffer.data()) + byte
Offset, byteLength); | 221 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier, We
bSocketFrame::OpCodeBinary, true, static_cast<const char*>(buffer.data()) + byte
Offset, byteLength); |
| 222 // buffer.slice copies its contents. | 222 // buffer.slice copies its contents. |
| 223 // FIXME: Reduce copy by sending the data immediately when we don't need to | 223 // FIXME: Reduce copy by sending the data immediately when we don't need to |
| 224 // queue the data. | 224 // queue the data. |
| 225 m_messages.append(new Message(buffer.slice(byteOffset, byteOffset + byteLeng
th))); | 225 m_messages.append(new Message(buffer.slice(byteOffset, byteOffset + byteLeng
th))); |
| 226 processSendQueue(); | 226 processSendQueue(); |
| 227 } | 227 } |
| 228 | 228 |
| 229 void DocumentWebSocketChannel::sendTextAsCharVector(std::unique_ptr<Vector<char>
> data) | 229 void DocumentWebSocketChannel::sendTextAsCharVector(std::unique_ptr<Vector<char>
> data) |
| 230 { | 230 { |
| 231 WTF_LOG(Network, "DocumentWebSocketChannel %p sendTextAsCharVector(%p, %llu)
", this, data.get(), static_cast<unsigned long long>(data->size())); | 231 NETWORK_DVLOG(1) << this << " sendTextAsCharVector(" << static_cast<void*>(d
ata.get()) << ", " << data->size() << ")"; |
| 232 // FIXME: Change the inspector API to show the entire message instead | 232 // FIXME: Change the inspector API to show the entire message instead |
| 233 // of individual frames. | 233 // of individual frames. |
| 234 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier, We
bSocketFrame::OpCodeText, true, data->data(), data->size()); | 234 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier, We
bSocketFrame::OpCodeText, true, data->data(), data->size()); |
| 235 m_messages.append(new Message(std::move(data), MessageTypeTextAsCharVector))
; | 235 m_messages.append(new Message(std::move(data), MessageTypeTextAsCharVector))
; |
| 236 processSendQueue(); | 236 processSendQueue(); |
| 237 } | 237 } |
| 238 | 238 |
| 239 void DocumentWebSocketChannel::sendBinaryAsCharVector(std::unique_ptr<Vector<cha
r>> data) | 239 void DocumentWebSocketChannel::sendBinaryAsCharVector(std::unique_ptr<Vector<cha
r>> data) |
| 240 { | 240 { |
| 241 WTF_LOG(Network, "DocumentWebSocketChannel %p sendBinaryAsCharVector(%p, %ll
u)", this, data.get(), static_cast<unsigned long long>(data->size())); | 241 NETWORK_DVLOG(1) << this << " sendBinaryAsCharVector(" << static_cast<void*>
(data.get()) << ", " << data->size() << ")"; |
| 242 // FIXME: Change the inspector API to show the entire message instead | 242 // FIXME: Change the inspector API to show the entire message instead |
| 243 // of individual frames. | 243 // of individual frames. |
| 244 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier, We
bSocketFrame::OpCodeBinary, true, data->data(), data->size()); | 244 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier, We
bSocketFrame::OpCodeBinary, true, data->data(), data->size()); |
| 245 m_messages.append(new Message(std::move(data), MessageTypeBinaryAsCharVector
)); | 245 m_messages.append(new Message(std::move(data), MessageTypeBinaryAsCharVector
)); |
| 246 processSendQueue(); | 246 processSendQueue(); |
| 247 } | 247 } |
| 248 | 248 |
| 249 void DocumentWebSocketChannel::close(int code, const String& reason) | 249 void DocumentWebSocketChannel::close(int code, const String& reason) |
| 250 { | 250 { |
| 251 WTF_LOG(Network, "DocumentWebSocketChannel %p close(%d, %s)", this, code, re
ason.utf8().data()); | 251 NETWORK_DVLOG(1) << this << " close(" << code << ", " << reason << ")"; |
| 252 ASSERT(m_handle); | 252 ASSERT(m_handle); |
| 253 unsigned short codeToSend = static_cast<unsigned short>(code == CloseEventCo
deNotSpecified ? CloseEventCodeNoStatusRcvd : code); | 253 unsigned short codeToSend = static_cast<unsigned short>(code == CloseEventCo
deNotSpecified ? CloseEventCodeNoStatusRcvd : code); |
| 254 m_messages.append(new Message(codeToSend, reason)); | 254 m_messages.append(new Message(codeToSend, reason)); |
| 255 processSendQueue(); | 255 processSendQueue(); |
| 256 } | 256 } |
| 257 | 257 |
| 258 void DocumentWebSocketChannel::fail(const String& reason, MessageLevel level, st
d::unique_ptr<SourceLocation> location) | 258 void DocumentWebSocketChannel::fail(const String& reason, MessageLevel level, st
d::unique_ptr<SourceLocation> location) |
| 259 { | 259 { |
| 260 WTF_LOG(Network, "DocumentWebSocketChannel %p fail(%s)", this, reason.utf8()
.data()); | 260 NETWORK_DVLOG(1) << this << " fail(" << reason << ")"; |
| 261 // m_handle and m_client can be null here. | 261 // m_handle and m_client can be null here. |
| 262 | 262 |
| 263 InspectorInstrumentation::didReceiveWebSocketFrameError(document(), m_identi
fier, reason); | 263 InspectorInstrumentation::didReceiveWebSocketFrameError(document(), m_identi
fier, reason); |
| 264 const String message = "WebSocket connection to '" + m_url.elidedString() +
"' failed: " + reason; | 264 const String message = "WebSocket connection to '" + m_url.elidedString() +
"' failed: " + reason; |
| 265 getExecutionContext()->addConsoleMessage(ConsoleMessage::create(JSMessageSou
rce, level, message, std::move(location))); | 265 getExecutionContext()->addConsoleMessage(ConsoleMessage::create(JSMessageSou
rce, level, message, std::move(location))); |
| 266 | 266 |
| 267 if (m_client) | 267 if (m_client) |
| 268 m_client->didError(); | 268 m_client->didError(); |
| 269 // |reason| is only for logging and should not be provided for scripts, | 269 // |reason| is only for logging and should not be provided for scripts, |
| 270 // hence close reason must be empty. | 270 // hence close reason must be empty. |
| 271 handleDidClose(false, CloseEventCodeAbnormalClosure, String()); | 271 handleDidClose(false, CloseEventCodeAbnormalClosure, String()); |
| 272 // handleDidClose may delete this object. | 272 // handleDidClose may delete this object. |
| 273 } | 273 } |
| 274 | 274 |
| 275 void DocumentWebSocketChannel::disconnect() | 275 void DocumentWebSocketChannel::disconnect() |
| 276 { | 276 { |
| 277 WTF_LOG(Network, "DocumentWebSocketChannel %p disconnect()", this); | 277 NETWORK_DVLOG(1) << this << " disconnect()"; |
| 278 if (m_identifier) { | 278 if (m_identifier) { |
| 279 TRACE_EVENT_INSTANT1("devtools.timeline", "WebSocketDestroy", TRACE_EVEN
T_SCOPE_THREAD, "data", InspectorWebSocketEvent::data(document(), m_identifier))
; | 279 TRACE_EVENT_INSTANT1("devtools.timeline", "WebSocketDestroy", TRACE_EVEN
T_SCOPE_THREAD, "data", InspectorWebSocketEvent::data(document(), m_identifier))
; |
| 280 InspectorInstrumentation::didCloseWebSocket(document(), m_identifier); | 280 InspectorInstrumentation::didCloseWebSocket(document(), m_identifier); |
| 281 } | 281 } |
| 282 abortAsyncOperations(); | 282 abortAsyncOperations(); |
| 283 m_handle.reset(); | 283 m_handle.reset(); |
| 284 m_client = nullptr; | 284 m_client = nullptr; |
| 285 m_identifier = 0; | 285 m_identifier = 0; |
| 286 } | 286 } |
| 287 | 287 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 Document* DocumentWebSocketChannel::document() | 406 Document* DocumentWebSocketChannel::document() |
| 407 { | 407 { |
| 408 // This context is always a Document. See the constructor. | 408 // This context is always a Document. See the constructor. |
| 409 ExecutionContext* context = getExecutionContext(); | 409 ExecutionContext* context = getExecutionContext(); |
| 410 ASSERT(context->isDocument()); | 410 ASSERT(context->isDocument()); |
| 411 return toDocument(context); | 411 return toDocument(context); |
| 412 } | 412 } |
| 413 | 413 |
| 414 void DocumentWebSocketChannel::didConnect(WebSocketHandle* handle, const WebStri
ng& selectedProtocol, const WebString& extensions) | 414 void DocumentWebSocketChannel::didConnect(WebSocketHandle* handle, const WebStri
ng& selectedProtocol, const WebString& extensions) |
| 415 { | 415 { |
| 416 WTF_LOG(Network, "DocumentWebSocketChannel %p didConnect(%p, %s, %s)", this,
handle, selectedProtocol.utf8().c_str(), extensions.utf8().c_str()); | 416 NETWORK_DVLOG(1) << this << " didConnect(" << handle << ", " << String(selec
tedProtocol) << ", " << String(extensions) << ")"; |
| 417 | 417 |
| 418 ASSERT(m_handle); | 418 ASSERT(m_handle); |
| 419 ASSERT(handle == m_handle.get()); | 419 ASSERT(handle == m_handle.get()); |
| 420 ASSERT(m_client); | 420 ASSERT(m_client); |
| 421 | 421 |
| 422 m_client->didConnect(selectedProtocol, extensions); | 422 m_client->didConnect(selectedProtocol, extensions); |
| 423 } | 423 } |
| 424 | 424 |
| 425 void DocumentWebSocketChannel::didStartOpeningHandshake(WebSocketHandle* handle,
const WebSocketHandshakeRequestInfo& request) | 425 void DocumentWebSocketChannel::didStartOpeningHandshake(WebSocketHandle* handle,
const WebSocketHandshakeRequestInfo& request) |
| 426 { | 426 { |
| 427 WTF_LOG(Network, "DocumentWebSocketChannel %p didStartOpeningHandshake(%p)",
this, handle); | 427 NETWORK_DVLOG(1) << this << " didStartOpeningHandshake(" << handle << ")"; |
| 428 | 428 |
| 429 ASSERT(m_handle); | 429 ASSERT(m_handle); |
| 430 ASSERT(handle == m_handle.get()); | 430 ASSERT(handle == m_handle.get()); |
| 431 | 431 |
| 432 TRACE_EVENT_INSTANT1("devtools.timeline", "WebSocketSendHandshakeRequest", T
RACE_EVENT_SCOPE_THREAD, "data", InspectorWebSocketEvent::data(document(), m_ide
ntifier)); | 432 TRACE_EVENT_INSTANT1("devtools.timeline", "WebSocketSendHandshakeRequest", T
RACE_EVENT_SCOPE_THREAD, "data", InspectorWebSocketEvent::data(document(), m_ide
ntifier)); |
| 433 InspectorInstrumentation::willSendWebSocketHandshakeRequest(document(), m_id
entifier, &request.toCoreRequest()); | 433 InspectorInstrumentation::willSendWebSocketHandshakeRequest(document(), m_id
entifier, &request.toCoreRequest()); |
| 434 m_handshakeRequest = WebSocketHandshakeRequest::create(request.toCoreRequest
()); | 434 m_handshakeRequest = WebSocketHandshakeRequest::create(request.toCoreRequest
()); |
| 435 } | 435 } |
| 436 | 436 |
| 437 void DocumentWebSocketChannel::didFinishOpeningHandshake(WebSocketHandle* handle
, const WebSocketHandshakeResponseInfo& response) | 437 void DocumentWebSocketChannel::didFinishOpeningHandshake(WebSocketHandle* handle
, const WebSocketHandshakeResponseInfo& response) |
| 438 { | 438 { |
| 439 WTF_LOG(Network, "DocumentWebSocketChannel %p didFinishOpeningHandshake(%p)"
, this, handle); | 439 NETWORK_DVLOG(1) << this << " didFinishOpeningHandshake(" << handle << ")"; |
| 440 | 440 |
| 441 ASSERT(m_handle); | 441 ASSERT(m_handle); |
| 442 ASSERT(handle == m_handle.get()); | 442 ASSERT(handle == m_handle.get()); |
| 443 | 443 |
| 444 TRACE_EVENT_INSTANT1("devtools.timeline", "WebSocketReceiveHandshakeResponse
", TRACE_EVENT_SCOPE_THREAD, "data", InspectorWebSocketEvent::data(document(), m
_identifier)); | 444 TRACE_EVENT_INSTANT1("devtools.timeline", "WebSocketReceiveHandshakeResponse
", TRACE_EVENT_SCOPE_THREAD, "data", InspectorWebSocketEvent::data(document(), m
_identifier)); |
| 445 InspectorInstrumentation::didReceiveWebSocketHandshakeResponse(document(), m
_identifier, m_handshakeRequest.get(), &response.toCoreResponse()); | 445 InspectorInstrumentation::didReceiveWebSocketHandshakeResponse(document(), m
_identifier, m_handshakeRequest.get(), &response.toCoreResponse()); |
| 446 m_handshakeRequest.clear(); | 446 m_handshakeRequest.clear(); |
| 447 } | 447 } |
| 448 | 448 |
| 449 void DocumentWebSocketChannel::didFail(WebSocketHandle* handle, const WebString&
message) | 449 void DocumentWebSocketChannel::didFail(WebSocketHandle* handle, const WebString&
message) |
| 450 { | 450 { |
| 451 WTF_LOG(Network, "DocumentWebSocketChannel %p didFail(%p, %s)", this, handle
, message.utf8().data()); | 451 NETWORK_DVLOG(1) << this << " didFail(" << handle << ", " << String(message)
<< ")"; |
| 452 | 452 |
| 453 ASSERT(m_handle); | 453 ASSERT(m_handle); |
| 454 ASSERT(handle == m_handle.get()); | 454 ASSERT(handle == m_handle.get()); |
| 455 | 455 |
| 456 // This function is called when the browser is required to fail the | 456 // This function is called when the browser is required to fail the |
| 457 // WebSocketConnection. Hence we fail this channel by calling | 457 // WebSocketConnection. Hence we fail this channel by calling |
| 458 // |this->failAsError| function. | 458 // |this->failAsError| function. |
| 459 failAsError(message); | 459 failAsError(message); |
| 460 // |this| may be deleted. | 460 // |this| may be deleted. |
| 461 } | 461 } |
| 462 | 462 |
| 463 void DocumentWebSocketChannel::didReceiveData(WebSocketHandle* handle, bool fin,
WebSocketHandle::MessageType type, const char* data, size_t size) | 463 void DocumentWebSocketChannel::didReceiveData(WebSocketHandle* handle, bool fin,
WebSocketHandle::MessageType type, const char* data, size_t size) |
| 464 { | 464 { |
| 465 WTF_LOG(Network, "DocumentWebSocketChannel %p didReceiveData(%p, %d, %d, (%p
, %zu))", this, handle, fin, type, data, size); | 465 NETWORK_DVLOG(1) << this << " didReceiveData(" << handle << ", " << fin << "
, " << type << ", (" << static_cast<const void*>(data) << ", " << size << "))"; |
| 466 | 466 |
| 467 ASSERT(m_handle); | 467 ASSERT(m_handle); |
| 468 ASSERT(handle == m_handle.get()); | 468 ASSERT(handle == m_handle.get()); |
| 469 ASSERT(m_client); | 469 ASSERT(m_client); |
| 470 // Non-final frames cannot be empty. | 470 // Non-final frames cannot be empty. |
| 471 ASSERT(fin || size); | 471 ASSERT(fin || size); |
| 472 | 472 |
| 473 switch (type) { | 473 switch (type) { |
| 474 case WebSocketHandle::MessageTypeText: | 474 case WebSocketHandle::MessageTypeText: |
| 475 ASSERT(m_receivingMessageData.isEmpty()); | 475 ASSERT(m_receivingMessageData.isEmpty()); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 506 } | 506 } |
| 507 } else { | 507 } else { |
| 508 std::unique_ptr<Vector<char>> binaryData = wrapUnique(new Vector<char>); | 508 std::unique_ptr<Vector<char>> binaryData = wrapUnique(new Vector<char>); |
| 509 binaryData->swap(m_receivingMessageData); | 509 binaryData->swap(m_receivingMessageData); |
| 510 m_client->didReceiveBinaryMessage(std::move(binaryData)); | 510 m_client->didReceiveBinaryMessage(std::move(binaryData)); |
| 511 } | 511 } |
| 512 } | 512 } |
| 513 | 513 |
| 514 void DocumentWebSocketChannel::didClose(WebSocketHandle* handle, bool wasClean,
unsigned short code, const WebString& reason) | 514 void DocumentWebSocketChannel::didClose(WebSocketHandle* handle, bool wasClean,
unsigned short code, const WebString& reason) |
| 515 { | 515 { |
| 516 WTF_LOG(Network, "DocumentWebSocketChannel %p didClose(%p, %d, %u, %s)", thi
s, handle, wasClean, code, String(reason).utf8().data()); | 516 NETWORK_DVLOG(1) << this << " didClose(" << handle << ", " << wasClean << ",
" << code << ", " << String(reason) << ")"; |
| 517 | 517 |
| 518 ASSERT(m_handle); | 518 ASSERT(m_handle); |
| 519 ASSERT(handle == m_handle.get()); | 519 ASSERT(handle == m_handle.get()); |
| 520 | 520 |
| 521 m_handle.reset(); | 521 m_handle.reset(); |
| 522 | 522 |
| 523 if (m_identifier) { | 523 if (m_identifier) { |
| 524 TRACE_EVENT_INSTANT1("devtools.timeline", "WebSocketDestroy", TRACE_EVEN
T_SCOPE_THREAD, "data", InspectorWebSocketEvent::data(document(), m_identifier))
; | 524 TRACE_EVENT_INSTANT1("devtools.timeline", "WebSocketDestroy", TRACE_EVEN
T_SCOPE_THREAD, "data", InspectorWebSocketEvent::data(document(), m_identifier))
; |
| 525 InspectorInstrumentation::didCloseWebSocket(document(), m_identifier); | 525 InspectorInstrumentation::didCloseWebSocket(document(), m_identifier); |
| 526 m_identifier = 0; | 526 m_identifier = 0; |
| 527 } | 527 } |
| 528 | 528 |
| 529 handleDidClose(wasClean, code, reason); | 529 handleDidClose(wasClean, code, reason); |
| 530 // handleDidClose may delete this object. | 530 // handleDidClose may delete this object. |
| 531 } | 531 } |
| 532 | 532 |
| 533 void DocumentWebSocketChannel::didReceiveFlowControl(WebSocketHandle* handle, in
t64_t quota) | 533 void DocumentWebSocketChannel::didReceiveFlowControl(WebSocketHandle* handle, in
t64_t quota) |
| 534 { | 534 { |
| 535 WTF_LOG(Network, "DocumentWebSocketChannel %p didReceiveFlowControl(%p, %ld)
", this, handle, static_cast<long>(quota)); | 535 NETWORK_DVLOG(1) << this << " didReceiveFlowControl(" << handle << ", " << q
uota << ")"; |
| 536 | 536 |
| 537 ASSERT(m_handle); | 537 ASSERT(m_handle); |
| 538 ASSERT(handle == m_handle.get()); | 538 ASSERT(handle == m_handle.get()); |
| 539 ASSERT(quota >= 0); | 539 ASSERT(quota >= 0); |
| 540 | 540 |
| 541 m_sendingQuota += quota; | 541 m_sendingQuota += quota; |
| 542 processSendQueue(); | 542 processSendQueue(); |
| 543 } | 543 } |
| 544 | 544 |
| 545 void DocumentWebSocketChannel::didStartClosingHandshake(WebSocketHandle* handle) | 545 void DocumentWebSocketChannel::didStartClosingHandshake(WebSocketHandle* handle) |
| 546 { | 546 { |
| 547 WTF_LOG(Network, "DocumentWebSocketChannel %p didStartClosingHandshake(%p)",
this, handle); | 547 NETWORK_DVLOG(1) << this << " didStartClosingHandshake(" << handle << ")"; |
| 548 | 548 |
| 549 ASSERT(m_handle); | 549 ASSERT(m_handle); |
| 550 ASSERT(handle == m_handle.get()); | 550 ASSERT(handle == m_handle.get()); |
| 551 | 551 |
| 552 if (m_client) | 552 if (m_client) |
| 553 m_client->didStartClosingHandshake(); | 553 m_client->didStartClosingHandshake(); |
| 554 } | 554 } |
| 555 | 555 |
| 556 void DocumentWebSocketChannel::didFinishLoadingBlob(DOMArrayBuffer* buffer) | 556 void DocumentWebSocketChannel::didFinishLoadingBlob(DOMArrayBuffer* buffer) |
| 557 { | 557 { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 578 | 578 |
| 579 DEFINE_TRACE(DocumentWebSocketChannel) | 579 DEFINE_TRACE(DocumentWebSocketChannel) |
| 580 { | 580 { |
| 581 visitor->trace(m_blobLoader); | 581 visitor->trace(m_blobLoader); |
| 582 visitor->trace(m_messages); | 582 visitor->trace(m_messages); |
| 583 visitor->trace(m_client); | 583 visitor->trace(m_client); |
| 584 WebSocketChannel::trace(visitor); | 584 WebSocketChannel::trace(visitor); |
| 585 ContextLifecycleObserver::trace(visitor); | 585 ContextLifecycleObserver::trace(visitor); |
| 586 } | 586 } |
| 587 | 587 |
| 588 std::ostream& operator<<(std::ostream& ostream, const DocumentWebSocketChannel*
channel) |
| 589 { |
| 590 return ostream << "DocumentWebSocketChannel " << static_cast<const void*>(ch
annel); |
| 591 } |
| 592 |
| 588 } // namespace blink | 593 } // namespace blink |
| OLD | NEW |