| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 #include "platform/Logging.h" | 48 #include "platform/Logging.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" | |
| 59 #include <memory> | |
| 60 | 58 |
| 61 using blink::WebSocketHandle; | 59 using blink::WebSocketHandle; |
| 62 | 60 |
| 63 namespace blink { | 61 namespace blink { |
| 64 | 62 |
| 65 class DocumentWebSocketChannel::BlobLoader final : public GarbageCollectedFinali
zed<DocumentWebSocketChannel::BlobLoader>, public FileReaderLoaderClient { | 63 class DocumentWebSocketChannel::BlobLoader final : public GarbageCollectedFinali
zed<DocumentWebSocketChannel::BlobLoader>, public FileReaderLoaderClient { |
| 66 public: | 64 public: |
| 67 BlobLoader(PassRefPtr<BlobDataHandle>, DocumentWebSocketChannel*); | 65 BlobLoader(PassRefPtr<BlobDataHandle>, DocumentWebSocketChannel*); |
| 68 ~BlobLoader() override { } | 66 ~BlobLoader() override { } |
| 69 | 67 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 84 Member<DocumentWebSocketChannel> m_channel; | 82 Member<DocumentWebSocketChannel> m_channel; |
| 85 FileReaderLoader m_loader; | 83 FileReaderLoader m_loader; |
| 86 }; | 84 }; |
| 87 | 85 |
| 88 class DocumentWebSocketChannel::Message : public GarbageCollectedFinalized<Docum
entWebSocketChannel::Message> { | 86 class DocumentWebSocketChannel::Message : public GarbageCollectedFinalized<Docum
entWebSocketChannel::Message> { |
| 89 public: | 87 public: |
| 90 explicit Message(const CString&); | 88 explicit Message(const CString&); |
| 91 explicit Message(PassRefPtr<BlobDataHandle>); | 89 explicit Message(PassRefPtr<BlobDataHandle>); |
| 92 explicit Message(DOMArrayBuffer*); | 90 explicit Message(DOMArrayBuffer*); |
| 93 // For WorkerWebSocketChannel | 91 // For WorkerWebSocketChannel |
| 94 explicit Message(std::unique_ptr<Vector<char>>, MessageType); | 92 explicit Message(PassOwnPtr<Vector<char>>, MessageType); |
| 95 // Close message | 93 // Close message |
| 96 Message(unsigned short code, const String& reason); | 94 Message(unsigned short code, const String& reason); |
| 97 | 95 |
| 98 DEFINE_INLINE_TRACE() | 96 DEFINE_INLINE_TRACE() |
| 99 { | 97 { |
| 100 visitor->trace(arrayBuffer); | 98 visitor->trace(arrayBuffer); |
| 101 } | 99 } |
| 102 | 100 |
| 103 MessageType type; | 101 MessageType type; |
| 104 | 102 |
| 105 CString text; | 103 CString text; |
| 106 RefPtr<BlobDataHandle> blobDataHandle; | 104 RefPtr<BlobDataHandle> blobDataHandle; |
| 107 Member<DOMArrayBuffer> arrayBuffer; | 105 Member<DOMArrayBuffer> arrayBuffer; |
| 108 std::unique_ptr<Vector<char>> vectorData; | 106 OwnPtr<Vector<char>> vectorData; |
| 109 unsigned short code; | 107 unsigned short code; |
| 110 String reason; | 108 String reason; |
| 111 }; | 109 }; |
| 112 | 110 |
| 113 DocumentWebSocketChannel::BlobLoader::BlobLoader(PassRefPtr<BlobDataHandle> blob
DataHandle, DocumentWebSocketChannel* channel) | 111 DocumentWebSocketChannel::BlobLoader::BlobLoader(PassRefPtr<BlobDataHandle> blob
DataHandle, DocumentWebSocketChannel* channel) |
| 114 : m_channel(channel) | 112 : m_channel(channel) |
| 115 , m_loader(FileReaderLoader::ReadAsArrayBuffer, this) | 113 , m_loader(FileReaderLoader::ReadAsArrayBuffer, this) |
| 116 { | 114 { |
| 117 m_loader.start(channel->getExecutionContext(), blobDataHandle); | 115 m_loader.start(channel->getExecutionContext(), blobDataHandle); |
| 118 } | 116 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 129 m_channel->didFinishLoadingBlob(m_loader.arrayBufferResult()); | 127 m_channel->didFinishLoadingBlob(m_loader.arrayBufferResult()); |
| 130 // |this| is deleted here. | 128 // |this| is deleted here. |
| 131 } | 129 } |
| 132 | 130 |
| 133 void DocumentWebSocketChannel::BlobLoader::didFail(FileError::ErrorCode errorCod
e) | 131 void DocumentWebSocketChannel::BlobLoader::didFail(FileError::ErrorCode errorCod
e) |
| 134 { | 132 { |
| 135 m_channel->didFailLoadingBlob(errorCode); | 133 m_channel->didFailLoadingBlob(errorCode); |
| 136 // |this| is deleted here. | 134 // |this| is deleted here. |
| 137 } | 135 } |
| 138 | 136 |
| 139 DocumentWebSocketChannel::DocumentWebSocketChannel(Document* document, WebSocket
ChannelClient* client, std::unique_ptr<SourceLocation> location, WebSocketHandle
*handle) | 137 DocumentWebSocketChannel::DocumentWebSocketChannel(Document* document, WebSocket
ChannelClient* client, PassOwnPtr<SourceLocation> location, WebSocketHandle *han
dle) |
| 140 : ContextLifecycleObserver(document) | 138 : ContextLifecycleObserver(document) |
| 141 , m_handle(wrapUnique(handle ? handle : Platform::current()->createWebSocket
Handle())) | 139 , m_handle(adoptPtr(handle ? handle : Platform::current()->createWebSocketHa
ndle())) |
| 142 , m_client(client) | 140 , m_client(client) |
| 143 , m_identifier(createUniqueIdentifier()) | 141 , m_identifier(createUniqueIdentifier()) |
| 144 , m_sendingQuota(0) | 142 , m_sendingQuota(0) |
| 145 , m_receivedDataSizeForFlowControl(receivedDataSizeForFlowControlHighWaterMa
rk * 2) // initial quota | 143 , m_receivedDataSizeForFlowControl(receivedDataSizeForFlowControlHighWaterMa
rk * 2) // initial quota |
| 146 , m_sentSizeOfTopMessage(0) | 144 , m_sentSizeOfTopMessage(0) |
| 147 , m_locationAtConstruction(std::move(location)) | 145 , m_locationAtConstruction(std::move(location)) |
| 148 { | 146 { |
| 149 } | 147 } |
| 150 | 148 |
| 151 DocumentWebSocketChannel::~DocumentWebSocketChannel() | 149 DocumentWebSocketChannel::~DocumentWebSocketChannel() |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 // FIXME: Change the inspector API to show the entire message instead | 219 // FIXME: Change the inspector API to show the entire message instead |
| 222 // of individual frames. | 220 // of individual frames. |
| 223 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); |
| 224 // buffer.slice copies its contents. | 222 // buffer.slice copies its contents. |
| 225 // 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 |
| 226 // queue the data. | 224 // queue the data. |
| 227 m_messages.append(new Message(buffer.slice(byteOffset, byteOffset + byteLeng
th))); | 225 m_messages.append(new Message(buffer.slice(byteOffset, byteOffset + byteLeng
th))); |
| 228 processSendQueue(); | 226 processSendQueue(); |
| 229 } | 227 } |
| 230 | 228 |
| 231 void DocumentWebSocketChannel::sendTextAsCharVector(std::unique_ptr<Vector<char>
> data) | 229 void DocumentWebSocketChannel::sendTextAsCharVector(PassOwnPtr<Vector<char>> dat
a) |
| 232 { | 230 { |
| 233 WTF_LOG(Network, "DocumentWebSocketChannel %p sendTextAsCharVector(%p, %llu)
", this, data.get(), static_cast<unsigned long long>(data->size())); | 231 WTF_LOG(Network, "DocumentWebSocketChannel %p sendTextAsCharVector(%p, %llu)
", this, data.get(), static_cast<unsigned long long>(data->size())); |
| 234 // FIXME: Change the inspector API to show the entire message instead | 232 // FIXME: Change the inspector API to show the entire message instead |
| 235 // of individual frames. | 233 // of individual frames. |
| 236 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()); |
| 237 m_messages.append(new Message(std::move(data), MessageTypeTextAsCharVector))
; | 235 m_messages.append(new Message(std::move(data), MessageTypeTextAsCharVector))
; |
| 238 processSendQueue(); | 236 processSendQueue(); |
| 239 } | 237 } |
| 240 | 238 |
| 241 void DocumentWebSocketChannel::sendBinaryAsCharVector(std::unique_ptr<Vector<cha
r>> data) | 239 void DocumentWebSocketChannel::sendBinaryAsCharVector(PassOwnPtr<Vector<char>> d
ata) |
| 242 { | 240 { |
| 243 WTF_LOG(Network, "DocumentWebSocketChannel %p sendBinaryAsCharVector(%p, %ll
u)", this, data.get(), static_cast<unsigned long long>(data->size())); | 241 WTF_LOG(Network, "DocumentWebSocketChannel %p sendBinaryAsCharVector(%p, %ll
u)", this, data.get(), static_cast<unsigned long long>(data->size())); |
| 244 // FIXME: Change the inspector API to show the entire message instead | 242 // FIXME: Change the inspector API to show the entire message instead |
| 245 // of individual frames. | 243 // of individual frames. |
| 246 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()); |
| 247 m_messages.append(new Message(std::move(data), MessageTypeBinaryAsCharVector
)); | 245 m_messages.append(new Message(std::move(data), MessageTypeBinaryAsCharVector
)); |
| 248 processSendQueue(); | 246 processSendQueue(); |
| 249 } | 247 } |
| 250 | 248 |
| 251 void DocumentWebSocketChannel::close(int code, const String& reason) | 249 void DocumentWebSocketChannel::close(int code, const String& reason) |
| 252 { | 250 { |
| 253 WTF_LOG(Network, "DocumentWebSocketChannel %p close(%d, %s)", this, code, re
ason.utf8().data()); | 251 WTF_LOG(Network, "DocumentWebSocketChannel %p close(%d, %s)", this, code, re
ason.utf8().data()); |
| 254 ASSERT(m_handle); | 252 ASSERT(m_handle); |
| 255 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); |
| 256 m_messages.append(new Message(codeToSend, reason)); | 254 m_messages.append(new Message(codeToSend, reason)); |
| 257 processSendQueue(); | 255 processSendQueue(); |
| 258 } | 256 } |
| 259 | 257 |
| 260 void DocumentWebSocketChannel::fail(const String& reason, MessageLevel level, st
d::unique_ptr<SourceLocation> location) | 258 void DocumentWebSocketChannel::fail(const String& reason, MessageLevel level, Pa
ssOwnPtr<SourceLocation> location) |
| 261 { | 259 { |
| 262 WTF_LOG(Network, "DocumentWebSocketChannel %p fail(%s)", this, reason.utf8()
.data()); | 260 WTF_LOG(Network, "DocumentWebSocketChannel %p fail(%s)", this, reason.utf8()
.data()); |
| 263 // m_handle and m_client can be null here. | 261 // m_handle and m_client can be null here. |
| 264 | 262 |
| 265 InspectorInstrumentation::didReceiveWebSocketFrameError(document(), m_identi
fier, reason); | 263 InspectorInstrumentation::didReceiveWebSocketFrameError(document(), m_identi
fier, reason); |
| 266 const String message = "WebSocket connection to '" + m_url.elidedString() +
"' failed: " + reason; | 264 const String message = "WebSocket connection to '" + m_url.elidedString() +
"' failed: " + reason; |
| 267 getExecutionContext()->addConsoleMessage(ConsoleMessage::create(JSMessageSou
rce, level, message, std::move(location))); | 265 getExecutionContext()->addConsoleMessage(ConsoleMessage::create(JSMessageSou
rce, level, message, std::move(location))); |
| 268 | 266 |
| 269 if (m_client) | 267 if (m_client) |
| 270 m_client->didError(); | 268 m_client->didError(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 292 , text(text) { } | 290 , text(text) { } |
| 293 | 291 |
| 294 DocumentWebSocketChannel::Message::Message(PassRefPtr<BlobDataHandle> blobDataHa
ndle) | 292 DocumentWebSocketChannel::Message::Message(PassRefPtr<BlobDataHandle> blobDataHa
ndle) |
| 295 : type(MessageTypeBlob) | 293 : type(MessageTypeBlob) |
| 296 , blobDataHandle(blobDataHandle) { } | 294 , blobDataHandle(blobDataHandle) { } |
| 297 | 295 |
| 298 DocumentWebSocketChannel::Message::Message(DOMArrayBuffer* arrayBuffer) | 296 DocumentWebSocketChannel::Message::Message(DOMArrayBuffer* arrayBuffer) |
| 299 : type(MessageTypeArrayBuffer) | 297 : type(MessageTypeArrayBuffer) |
| 300 , arrayBuffer(arrayBuffer) { } | 298 , arrayBuffer(arrayBuffer) { } |
| 301 | 299 |
| 302 DocumentWebSocketChannel::Message::Message(std::unique_ptr<Vector<char>> vectorD
ata, MessageType type) | 300 DocumentWebSocketChannel::Message::Message(PassOwnPtr<Vector<char>> vectorData,
MessageType type) |
| 303 : type(type) | 301 : type(type) |
| 304 , vectorData(std::move(vectorData)) | 302 , vectorData(std::move(vectorData)) |
| 305 { | 303 { |
| 306 ASSERT(type == MessageTypeTextAsCharVector || type == MessageTypeBinaryAsCha
rVector); | 304 ASSERT(type == MessageTypeTextAsCharVector || type == MessageTypeBinaryAsCha
rVector); |
| 307 } | 305 } |
| 308 | 306 |
| 309 DocumentWebSocketChannel::Message::Message(unsigned short code, const String& re
ason) | 307 DocumentWebSocketChannel::Message::Message(unsigned short code, const String& re
ason) |
| 310 : type(MessageTypeClose) | 308 : type(MessageTypeClose) |
| 311 , code(code) | 309 , code(code) |
| 312 , reason(reason) { } | 310 , reason(reason) { } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 ExecutionContext* context = getExecutionContext(); | 409 ExecutionContext* context = getExecutionContext(); |
| 412 ASSERT(context->isDocument()); | 410 ASSERT(context->isDocument()); |
| 413 return toDocument(context); | 411 return toDocument(context); |
| 414 } | 412 } |
| 415 | 413 |
| 416 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) |
| 417 { | 415 { |
| 418 WTF_LOG(Network, "DocumentWebSocketChannel %p didConnect(%p, %s, %s)", this,
handle, selectedProtocol.utf8().c_str(), extensions.utf8().c_str()); | 416 WTF_LOG(Network, "DocumentWebSocketChannel %p didConnect(%p, %s, %s)", this,
handle, selectedProtocol.utf8().c_str(), extensions.utf8().c_str()); |
| 419 | 417 |
| 420 ASSERT(m_handle); | 418 ASSERT(m_handle); |
| 421 ASSERT(handle == m_handle.get()); | 419 ASSERT(handle == m_handle); |
| 422 ASSERT(m_client); | 420 ASSERT(m_client); |
| 423 | 421 |
| 424 m_client->didConnect(selectedProtocol, extensions); | 422 m_client->didConnect(selectedProtocol, extensions); |
| 425 } | 423 } |
| 426 | 424 |
| 427 void DocumentWebSocketChannel::didStartOpeningHandshake(WebSocketHandle* handle,
const WebSocketHandshakeRequestInfo& request) | 425 void DocumentWebSocketChannel::didStartOpeningHandshake(WebSocketHandle* handle,
const WebSocketHandshakeRequestInfo& request) |
| 428 { | 426 { |
| 429 WTF_LOG(Network, "DocumentWebSocketChannel %p didStartOpeningHandshake(%p)",
this, handle); | 427 WTF_LOG(Network, "DocumentWebSocketChannel %p didStartOpeningHandshake(%p)",
this, handle); |
| 430 | 428 |
| 431 ASSERT(m_handle); | 429 ASSERT(m_handle); |
| 432 ASSERT(handle == m_handle.get()); | 430 ASSERT(handle == m_handle); |
| 433 | 431 |
| 434 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)); |
| 435 InspectorInstrumentation::willSendWebSocketHandshakeRequest(document(), m_id
entifier, &request.toCoreRequest()); | 433 InspectorInstrumentation::willSendWebSocketHandshakeRequest(document(), m_id
entifier, &request.toCoreRequest()); |
| 436 m_handshakeRequest = WebSocketHandshakeRequest::create(request.toCoreRequest
()); | 434 m_handshakeRequest = WebSocketHandshakeRequest::create(request.toCoreRequest
()); |
| 437 } | 435 } |
| 438 | 436 |
| 439 void DocumentWebSocketChannel::didFinishOpeningHandshake(WebSocketHandle* handle
, const WebSocketHandshakeResponseInfo& response) | 437 void DocumentWebSocketChannel::didFinishOpeningHandshake(WebSocketHandle* handle
, const WebSocketHandshakeResponseInfo& response) |
| 440 { | 438 { |
| 441 WTF_LOG(Network, "DocumentWebSocketChannel %p didFinishOpeningHandshake(%p)"
, this, handle); | 439 WTF_LOG(Network, "DocumentWebSocketChannel %p didFinishOpeningHandshake(%p)"
, this, handle); |
| 442 | 440 |
| 443 ASSERT(m_handle); | 441 ASSERT(m_handle); |
| 444 ASSERT(handle == m_handle.get()); | 442 ASSERT(handle == m_handle); |
| 445 | 443 |
| 446 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)); |
| 447 InspectorInstrumentation::didReceiveWebSocketHandshakeResponse(document(), m
_identifier, m_handshakeRequest.get(), &response.toCoreResponse()); | 445 InspectorInstrumentation::didReceiveWebSocketHandshakeResponse(document(), m
_identifier, m_handshakeRequest.get(), &response.toCoreResponse()); |
| 448 m_handshakeRequest.clear(); | 446 m_handshakeRequest.clear(); |
| 449 } | 447 } |
| 450 | 448 |
| 451 void DocumentWebSocketChannel::didFail(WebSocketHandle* handle, const WebString&
message) | 449 void DocumentWebSocketChannel::didFail(WebSocketHandle* handle, const WebString&
message) |
| 452 { | 450 { |
| 453 WTF_LOG(Network, "DocumentWebSocketChannel %p didFail(%p, %s)", this, handle
, message.utf8().data()); | 451 WTF_LOG(Network, "DocumentWebSocketChannel %p didFail(%p, %s)", this, handle
, message.utf8().data()); |
| 454 | 452 |
| 455 ASSERT(m_handle); | 453 ASSERT(m_handle); |
| 456 ASSERT(handle == m_handle.get()); | 454 ASSERT(handle == m_handle); |
| 457 | 455 |
| 458 // 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 |
| 459 // WebSocketConnection. Hence we fail this channel by calling | 457 // WebSocketConnection. Hence we fail this channel by calling |
| 460 // |this->failAsError| function. | 458 // |this->failAsError| function. |
| 461 failAsError(message); | 459 failAsError(message); |
| 462 // |this| may be deleted. | 460 // |this| may be deleted. |
| 463 } | 461 } |
| 464 | 462 |
| 465 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) |
| 466 { | 464 { |
| 467 WTF_LOG(Network, "DocumentWebSocketChannel %p didReceiveData(%p, %d, %d, (%p
, %zu))", this, handle, fin, type, data, size); | 465 WTF_LOG(Network, "DocumentWebSocketChannel %p didReceiveData(%p, %d, %d, (%p
, %zu))", this, handle, fin, type, data, size); |
| 468 | 466 |
| 469 ASSERT(m_handle); | 467 ASSERT(m_handle); |
| 470 ASSERT(handle == m_handle.get()); | 468 ASSERT(handle == m_handle); |
| 471 ASSERT(m_client); | 469 ASSERT(m_client); |
| 472 // Non-final frames cannot be empty. | 470 // Non-final frames cannot be empty. |
| 473 ASSERT(fin || size); | 471 ASSERT(fin || size); |
| 474 | 472 |
| 475 switch (type) { | 473 switch (type) { |
| 476 case WebSocketHandle::MessageTypeText: | 474 case WebSocketHandle::MessageTypeText: |
| 477 ASSERT(m_receivingMessageData.isEmpty()); | 475 ASSERT(m_receivingMessageData.isEmpty()); |
| 478 m_receivingMessageTypeIsText = true; | 476 m_receivingMessageTypeIsText = true; |
| 479 break; | 477 break; |
| 480 case WebSocketHandle::MessageTypeBinary: | 478 case WebSocketHandle::MessageTypeBinary: |
| (...skipping 19 matching lines...) Expand all Loading... |
| 500 if (m_receivingMessageTypeIsText) { | 498 if (m_receivingMessageTypeIsText) { |
| 501 String message = m_receivingMessageData.isEmpty() ? emptyString() : Stri
ng::fromUTF8(m_receivingMessageData.data(), m_receivingMessageData.size()); | 499 String message = m_receivingMessageData.isEmpty() ? emptyString() : Stri
ng::fromUTF8(m_receivingMessageData.data(), m_receivingMessageData.size()); |
| 502 m_receivingMessageData.clear(); | 500 m_receivingMessageData.clear(); |
| 503 if (message.isNull()) { | 501 if (message.isNull()) { |
| 504 failAsError("Could not decode a text frame as UTF-8."); | 502 failAsError("Could not decode a text frame as UTF-8."); |
| 505 // failAsError may delete this object. | 503 // failAsError may delete this object. |
| 506 } else { | 504 } else { |
| 507 m_client->didReceiveTextMessage(message); | 505 m_client->didReceiveTextMessage(message); |
| 508 } | 506 } |
| 509 } else { | 507 } else { |
| 510 std::unique_ptr<Vector<char>> binaryData = wrapUnique(new Vector<char>); | 508 OwnPtr<Vector<char>> binaryData = adoptPtr(new Vector<char>); |
| 511 binaryData->swap(m_receivingMessageData); | 509 binaryData->swap(m_receivingMessageData); |
| 512 m_client->didReceiveBinaryMessage(std::move(binaryData)); | 510 m_client->didReceiveBinaryMessage(std::move(binaryData)); |
| 513 } | 511 } |
| 514 } | 512 } |
| 515 | 513 |
| 516 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) |
| 517 { | 515 { |
| 518 WTF_LOG(Network, "DocumentWebSocketChannel %p didClose(%p, %d, %u, %s)", thi
s, handle, wasClean, code, String(reason).utf8().data()); | 516 WTF_LOG(Network, "DocumentWebSocketChannel %p didClose(%p, %d, %u, %s)", thi
s, handle, wasClean, code, String(reason).utf8().data()); |
| 519 | 517 |
| 520 ASSERT(m_handle); | 518 ASSERT(m_handle); |
| 521 ASSERT(handle == m_handle.get()); | 519 ASSERT(handle == m_handle); |
| 522 | 520 |
| 523 m_handle.reset(); | 521 m_handle.reset(); |
| 524 | 522 |
| 525 if (m_identifier) { | 523 if (m_identifier) { |
| 526 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))
; |
| 527 InspectorInstrumentation::didCloseWebSocket(document(), m_identifier); | 525 InspectorInstrumentation::didCloseWebSocket(document(), m_identifier); |
| 528 m_identifier = 0; | 526 m_identifier = 0; |
| 529 } | 527 } |
| 530 | 528 |
| 531 handleDidClose(wasClean, code, reason); | 529 handleDidClose(wasClean, code, reason); |
| 532 // handleDidClose may delete this object. | 530 // handleDidClose may delete this object. |
| 533 } | 531 } |
| 534 | 532 |
| 535 void DocumentWebSocketChannel::didReceiveFlowControl(WebSocketHandle* handle, in
t64_t quota) | 533 void DocumentWebSocketChannel::didReceiveFlowControl(WebSocketHandle* handle, in
t64_t quota) |
| 536 { | 534 { |
| 537 WTF_LOG(Network, "DocumentWebSocketChannel %p didReceiveFlowControl(%p, %ld)
", this, handle, static_cast<long>(quota)); | 535 WTF_LOG(Network, "DocumentWebSocketChannel %p didReceiveFlowControl(%p, %ld)
", this, handle, static_cast<long>(quota)); |
| 538 | 536 |
| 539 ASSERT(m_handle); | 537 ASSERT(m_handle); |
| 540 ASSERT(handle == m_handle.get()); | 538 ASSERT(handle == m_handle); |
| 541 ASSERT(quota >= 0); | 539 ASSERT(quota >= 0); |
| 542 | 540 |
| 543 m_sendingQuota += quota; | 541 m_sendingQuota += quota; |
| 544 processSendQueue(); | 542 processSendQueue(); |
| 545 } | 543 } |
| 546 | 544 |
| 547 void DocumentWebSocketChannel::didStartClosingHandshake(WebSocketHandle* handle) | 545 void DocumentWebSocketChannel::didStartClosingHandshake(WebSocketHandle* handle) |
| 548 { | 546 { |
| 549 WTF_LOG(Network, "DocumentWebSocketChannel %p didStartClosingHandshake(%p)",
this, handle); | 547 WTF_LOG(Network, "DocumentWebSocketChannel %p didStartClosingHandshake(%p)",
this, handle); |
| 550 | 548 |
| 551 ASSERT(m_handle); | 549 ASSERT(m_handle); |
| 552 ASSERT(handle == m_handle.get()); | 550 ASSERT(handle == m_handle); |
| 553 | 551 |
| 554 if (m_client) | 552 if (m_client) |
| 555 m_client->didStartClosingHandshake(); | 553 m_client->didStartClosingHandshake(); |
| 556 } | 554 } |
| 557 | 555 |
| 558 void DocumentWebSocketChannel::didFinishLoadingBlob(DOMArrayBuffer* buffer) | 556 void DocumentWebSocketChannel::didFinishLoadingBlob(DOMArrayBuffer* buffer) |
| 559 { | 557 { |
| 560 m_blobLoader.clear(); | 558 m_blobLoader.clear(); |
| 561 ASSERT(m_handle); | 559 ASSERT(m_handle); |
| 562 // The loaded blob is always placed on m_messages[0]. | 560 // The loaded blob is always placed on m_messages[0]. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 581 DEFINE_TRACE(DocumentWebSocketChannel) | 579 DEFINE_TRACE(DocumentWebSocketChannel) |
| 582 { | 580 { |
| 583 visitor->trace(m_blobLoader); | 581 visitor->trace(m_blobLoader); |
| 584 visitor->trace(m_messages); | 582 visitor->trace(m_messages); |
| 585 visitor->trace(m_client); | 583 visitor->trace(m_client); |
| 586 WebSocketChannel::trace(visitor); | 584 WebSocketChannel::trace(visitor); |
| 587 ContextLifecycleObserver::trace(visitor); | 585 ContextLifecycleObserver::trace(visitor); |
| 588 } | 586 } |
| 589 | 587 |
| 590 } // namespace blink | 588 } // namespace blink |
| OLD | NEW |