| 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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 } | 199 } |
| 200 m_handle->connect(url, protocols, m_loadingContext->getSecurityOrigin(), | 200 m_handle->connect(url, protocols, m_loadingContext->getSecurityOrigin(), |
| 201 m_loadingContext->firstPartyForCookies(), | 201 m_loadingContext->firstPartyForCookies(), |
| 202 m_loadingContext->userAgent(), this); | 202 m_loadingContext->userAgent(), this); |
| 203 | 203 |
| 204 flowControlIfNecessary(); | 204 flowControlIfNecessary(); |
| 205 TRACE_EVENT_INSTANT1("devtools.timeline", "WebSocketCreate", | 205 TRACE_EVENT_INSTANT1("devtools.timeline", "WebSocketCreate", |
| 206 TRACE_EVENT_SCOPE_THREAD, "data", | 206 TRACE_EVENT_SCOPE_THREAD, "data", |
| 207 InspectorWebSocketCreateEvent::data( | 207 InspectorWebSocketCreateEvent::data( |
| 208 document(), m_identifier, url, protocol)); | 208 document(), m_identifier, url, protocol)); |
| 209 InspectorInstrumentation::didCreateWebSocket(document(), m_identifier, url, | 209 probe::didCreateWebSocket(document(), m_identifier, url, protocol); |
| 210 protocol); | |
| 211 return true; | 210 return true; |
| 212 } | 211 } |
| 213 | 212 |
| 214 void DocumentWebSocketChannel::send(const CString& message) { | 213 void DocumentWebSocketChannel::send(const CString& message) { |
| 215 NETWORK_DVLOG(1) << this << " sendText(" << message << ")"; | 214 NETWORK_DVLOG(1) << this << " sendText(" << message << ")"; |
| 216 // FIXME: Change the inspector API to show the entire message instead | 215 // FIXME: Change the inspector API to show the entire message instead |
| 217 // of individual frames. | 216 // of individual frames. |
| 218 InspectorInstrumentation::didSendWebSocketFrame( | 217 probe::didSendWebSocketFrame(document(), m_identifier, |
| 219 document(), m_identifier, WebSocketFrame::OpCodeText, true, | 218 WebSocketFrame::OpCodeText, true, message.data(), |
| 220 message.data(), message.length()); | 219 message.length()); |
| 221 m_messages.append(new Message(message)); | 220 m_messages.append(new Message(message)); |
| 222 processSendQueue(); | 221 processSendQueue(); |
| 223 } | 222 } |
| 224 | 223 |
| 225 void DocumentWebSocketChannel::send(PassRefPtr<BlobDataHandle> blobDataHandle) { | 224 void DocumentWebSocketChannel::send(PassRefPtr<BlobDataHandle> blobDataHandle) { |
| 226 NETWORK_DVLOG(1) << this << " sendBlob(" << blobDataHandle->uuid() << ", " | 225 NETWORK_DVLOG(1) << this << " sendBlob(" << blobDataHandle->uuid() << ", " |
| 227 << blobDataHandle->type() << ", " << blobDataHandle->size() | 226 << blobDataHandle->type() << ", " << blobDataHandle->size() |
| 228 << ")"; | 227 << ")"; |
| 229 // FIXME: Change the inspector API to show the entire message instead | 228 // FIXME: Change the inspector API to show the entire message instead |
| 230 // of individual frames. | 229 // of individual frames. |
| 231 // FIXME: We can't access the data here. | 230 // FIXME: We can't access the data here. |
| 232 // Since Binary data are not displayed in Inspector, this does not | 231 // Since Binary data are not displayed in Inspector, this does not |
| 233 // affect actual behavior. | 232 // affect actual behavior. |
| 234 InspectorInstrumentation::didSendWebSocketFrame( | 233 probe::didSendWebSocketFrame(document(), m_identifier, |
| 235 document(), m_identifier, WebSocketFrame::OpCodeBinary, true, "", 0); | 234 WebSocketFrame::OpCodeBinary, true, "", 0); |
| 236 m_messages.append(new Message(std::move(blobDataHandle))); | 235 m_messages.append(new Message(std::move(blobDataHandle))); |
| 237 processSendQueue(); | 236 processSendQueue(); |
| 238 } | 237 } |
| 239 | 238 |
| 240 void DocumentWebSocketChannel::send(const DOMArrayBuffer& buffer, | 239 void DocumentWebSocketChannel::send(const DOMArrayBuffer& buffer, |
| 241 unsigned byteOffset, | 240 unsigned byteOffset, |
| 242 unsigned byteLength) { | 241 unsigned byteLength) { |
| 243 NETWORK_DVLOG(1) << this << " sendArrayBuffer(" << buffer.data() << ", " | 242 NETWORK_DVLOG(1) << this << " sendArrayBuffer(" << buffer.data() << ", " |
| 244 << byteOffset << ", " << byteLength << ")"; | 243 << byteOffset << ", " << byteLength << ")"; |
| 245 // FIXME: Change the inspector API to show the entire message instead | 244 // FIXME: Change the inspector API to show the entire message instead |
| 246 // of individual frames. | 245 // of individual frames. |
| 247 InspectorInstrumentation::didSendWebSocketFrame( | 246 probe::didSendWebSocketFrame( |
| 248 document(), m_identifier, WebSocketFrame::OpCodeBinary, true, | 247 document(), m_identifier, WebSocketFrame::OpCodeBinary, true, |
| 249 static_cast<const char*>(buffer.data()) + byteOffset, byteLength); | 248 static_cast<const char*>(buffer.data()) + byteOffset, byteLength); |
| 250 // buffer.slice copies its contents. | 249 // buffer.slice copies its contents. |
| 251 // FIXME: Reduce copy by sending the data immediately when we don't need to | 250 // FIXME: Reduce copy by sending the data immediately when we don't need to |
| 252 // queue the data. | 251 // queue the data. |
| 253 m_messages.append( | 252 m_messages.append( |
| 254 new Message(buffer.slice(byteOffset, byteOffset + byteLength))); | 253 new Message(buffer.slice(byteOffset, byteOffset + byteLength))); |
| 255 processSendQueue(); | 254 processSendQueue(); |
| 256 } | 255 } |
| 257 | 256 |
| 258 void DocumentWebSocketChannel::sendTextAsCharVector( | 257 void DocumentWebSocketChannel::sendTextAsCharVector( |
| 259 std::unique_ptr<Vector<char>> data) { | 258 std::unique_ptr<Vector<char>> data) { |
| 260 NETWORK_DVLOG(1) << this << " sendTextAsCharVector(" | 259 NETWORK_DVLOG(1) << this << " sendTextAsCharVector(" |
| 261 << static_cast<void*>(data.get()) << ", " << data->size() | 260 << static_cast<void*>(data.get()) << ", " << data->size() |
| 262 << ")"; | 261 << ")"; |
| 263 // FIXME: Change the inspector API to show the entire message instead | 262 // FIXME: Change the inspector API to show the entire message instead |
| 264 // of individual frames. | 263 // of individual frames. |
| 265 InspectorInstrumentation::didSendWebSocketFrame( | 264 probe::didSendWebSocketFrame(document(), m_identifier, |
| 266 document(), m_identifier, WebSocketFrame::OpCodeText, true, data->data(), | 265 WebSocketFrame::OpCodeText, true, data->data(), |
| 267 data->size()); | 266 data->size()); |
| 268 m_messages.append(new Message(std::move(data), MessageTypeTextAsCharVector)); | 267 m_messages.append(new Message(std::move(data), MessageTypeTextAsCharVector)); |
| 269 processSendQueue(); | 268 processSendQueue(); |
| 270 } | 269 } |
| 271 | 270 |
| 272 void DocumentWebSocketChannel::sendBinaryAsCharVector( | 271 void DocumentWebSocketChannel::sendBinaryAsCharVector( |
| 273 std::unique_ptr<Vector<char>> data) { | 272 std::unique_ptr<Vector<char>> data) { |
| 274 NETWORK_DVLOG(1) << this << " sendBinaryAsCharVector(" | 273 NETWORK_DVLOG(1) << this << " sendBinaryAsCharVector(" |
| 275 << static_cast<void*>(data.get()) << ", " << data->size() | 274 << static_cast<void*>(data.get()) << ", " << data->size() |
| 276 << ")"; | 275 << ")"; |
| 277 // FIXME: Change the inspector API to show the entire message instead | 276 // FIXME: Change the inspector API to show the entire message instead |
| 278 // of individual frames. | 277 // of individual frames. |
| 279 InspectorInstrumentation::didSendWebSocketFrame( | 278 probe::didSendWebSocketFrame(document(), m_identifier, |
| 280 document(), m_identifier, WebSocketFrame::OpCodeBinary, true, | 279 WebSocketFrame::OpCodeBinary, true, data->data(), |
| 281 data->data(), data->size()); | 280 data->size()); |
| 282 m_messages.append( | 281 m_messages.append( |
| 283 new Message(std::move(data), MessageTypeBinaryAsCharVector)); | 282 new Message(std::move(data), MessageTypeBinaryAsCharVector)); |
| 284 processSendQueue(); | 283 processSendQueue(); |
| 285 } | 284 } |
| 286 | 285 |
| 287 void DocumentWebSocketChannel::close(int code, const String& reason) { | 286 void DocumentWebSocketChannel::close(int code, const String& reason) { |
| 288 NETWORK_DVLOG(1) << this << " close(" << code << ", " << reason << ")"; | 287 NETWORK_DVLOG(1) << this << " close(" << code << ", " << reason << ")"; |
| 289 DCHECK(m_handle); | 288 DCHECK(m_handle); |
| 290 unsigned short codeToSend = static_cast<unsigned short>( | 289 unsigned short codeToSend = static_cast<unsigned short>( |
| 291 code == CloseEventCodeNotSpecified ? CloseEventCodeNoStatusRcvd : code); | 290 code == CloseEventCodeNotSpecified ? CloseEventCodeNoStatusRcvd : code); |
| 292 m_messages.append(new Message(codeToSend, reason)); | 291 m_messages.append(new Message(codeToSend, reason)); |
| 293 processSendQueue(); | 292 processSendQueue(); |
| 294 } | 293 } |
| 295 | 294 |
| 296 void DocumentWebSocketChannel::fail(const String& reason, | 295 void DocumentWebSocketChannel::fail(const String& reason, |
| 297 MessageLevel level, | 296 MessageLevel level, |
| 298 std::unique_ptr<SourceLocation> location) { | 297 std::unique_ptr<SourceLocation> location) { |
| 299 NETWORK_DVLOG(1) << this << " fail(" << reason << ")"; | 298 NETWORK_DVLOG(1) << this << " fail(" << reason << ")"; |
| 300 // m_handle and m_client can be null here. | 299 // m_handle and m_client can be null here. |
| 301 | 300 |
| 302 connection_handle_for_scheduler_.reset(); | 301 connection_handle_for_scheduler_.reset(); |
| 303 | 302 |
| 304 if (document()) { | 303 if (document()) { |
| 305 InspectorInstrumentation::didReceiveWebSocketFrameError( | 304 probe::didReceiveWebSocketFrameError(document(), m_identifier, reason); |
| 306 document(), m_identifier, reason); | |
| 307 const String message = "WebSocket connection to '" + m_url.elidedString() + | 305 const String message = "WebSocket connection to '" + m_url.elidedString() + |
| 308 "' failed: " + reason; | 306 "' failed: " + reason; |
| 309 document()->addConsoleMessage(ConsoleMessage::create( | 307 document()->addConsoleMessage(ConsoleMessage::create( |
| 310 JSMessageSource, level, message, std::move(location))); | 308 JSMessageSource, level, message, std::move(location))); |
| 311 } | 309 } |
| 312 | 310 |
| 313 if (m_client) | 311 if (m_client) |
| 314 m_client->didError(); | 312 m_client->didError(); |
| 315 // |reason| is only for logging and should not be provided for scripts, | 313 // |reason| is only for logging and should not be provided for scripts, |
| 316 // hence close reason must be empty. | 314 // hence close reason must be empty. |
| 317 handleDidClose(false, CloseEventCodeAbnormalClosure, String()); | 315 handleDidClose(false, CloseEventCodeAbnormalClosure, String()); |
| 318 // handleDidClose may delete this object. | 316 // handleDidClose may delete this object. |
| 319 } | 317 } |
| 320 | 318 |
| 321 void DocumentWebSocketChannel::disconnect() { | 319 void DocumentWebSocketChannel::disconnect() { |
| 322 NETWORK_DVLOG(1) << this << " disconnect()"; | 320 NETWORK_DVLOG(1) << this << " disconnect()"; |
| 323 if (m_identifier) { | 321 if (m_identifier) { |
| 324 TRACE_EVENT_INSTANT1( | 322 TRACE_EVENT_INSTANT1( |
| 325 "devtools.timeline", "WebSocketDestroy", TRACE_EVENT_SCOPE_THREAD, | 323 "devtools.timeline", "WebSocketDestroy", TRACE_EVENT_SCOPE_THREAD, |
| 326 "data", InspectorWebSocketEvent::data(document(), m_identifier)); | 324 "data", InspectorWebSocketEvent::data(document(), m_identifier)); |
| 327 InspectorInstrumentation::didCloseWebSocket(document(), m_identifier); | 325 probe::didCloseWebSocket(document(), m_identifier); |
| 328 } | 326 } |
| 329 connection_handle_for_scheduler_.reset(); | 327 connection_handle_for_scheduler_.reset(); |
| 330 abortAsyncOperations(); | 328 abortAsyncOperations(); |
| 331 m_handle.reset(); | 329 m_handle.reset(); |
| 332 m_client = nullptr; | 330 m_client = nullptr; |
| 333 m_identifier = 0; | 331 m_identifier = 0; |
| 334 } | 332 } |
| 335 | 333 |
| 336 DocumentWebSocketChannel::Message::Message(const CString& text) | 334 DocumentWebSocketChannel::Message::Message(const CString& text) |
| 337 : type(MessageTypeText), text(text) {} | 335 : type(MessageTypeText), text(text) {} |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 NETWORK_DVLOG(1) << this << " didStartOpeningHandshake(" << handle << ")"; | 490 NETWORK_DVLOG(1) << this << " didStartOpeningHandshake(" << handle << ")"; |
| 493 | 491 |
| 494 DCHECK(m_handle); | 492 DCHECK(m_handle); |
| 495 DCHECK_EQ(handle, m_handle.get()); | 493 DCHECK_EQ(handle, m_handle.get()); |
| 496 | 494 |
| 497 if (document()) { | 495 if (document()) { |
| 498 TRACE_EVENT_INSTANT1( | 496 TRACE_EVENT_INSTANT1( |
| 499 "devtools.timeline", "WebSocketSendHandshakeRequest", | 497 "devtools.timeline", "WebSocketSendHandshakeRequest", |
| 500 TRACE_EVENT_SCOPE_THREAD, "data", | 498 TRACE_EVENT_SCOPE_THREAD, "data", |
| 501 InspectorWebSocketEvent::data(document(), m_identifier)); | 499 InspectorWebSocketEvent::data(document(), m_identifier)); |
| 502 InspectorInstrumentation::willSendWebSocketHandshakeRequest( | 500 probe::willSendWebSocketHandshakeRequest(document(), m_identifier, |
| 503 document(), m_identifier, request.get()); | 501 request.get()); |
| 504 } | 502 } |
| 505 m_handshakeRequest = request; | 503 m_handshakeRequest = request; |
| 506 } | 504 } |
| 507 | 505 |
| 508 void DocumentWebSocketChannel::didFinishOpeningHandshake( | 506 void DocumentWebSocketChannel::didFinishOpeningHandshake( |
| 509 WebSocketHandle* handle, | 507 WebSocketHandle* handle, |
| 510 const WebSocketHandshakeResponse* response) { | 508 const WebSocketHandshakeResponse* response) { |
| 511 NETWORK_DVLOG(1) << this << " didFinishOpeningHandshake(" << handle << ")"; | 509 NETWORK_DVLOG(1) << this << " didFinishOpeningHandshake(" << handle << ")"; |
| 512 | 510 |
| 513 DCHECK(m_handle); | 511 DCHECK(m_handle); |
| 514 DCHECK_EQ(handle, m_handle.get()); | 512 DCHECK_EQ(handle, m_handle.get()); |
| 515 | 513 |
| 516 if (document()) { | 514 if (document()) { |
| 517 TRACE_EVENT_INSTANT1( | 515 TRACE_EVENT_INSTANT1( |
| 518 "devtools.timeline", "WebSocketReceiveHandshakeResponse", | 516 "devtools.timeline", "WebSocketReceiveHandshakeResponse", |
| 519 TRACE_EVENT_SCOPE_THREAD, "data", | 517 TRACE_EVENT_SCOPE_THREAD, "data", |
| 520 InspectorWebSocketEvent::data(document(), m_identifier)); | 518 InspectorWebSocketEvent::data(document(), m_identifier)); |
| 521 InspectorInstrumentation::didReceiveWebSocketHandshakeResponse( | 519 probe::didReceiveWebSocketHandshakeResponse( |
| 522 document(), m_identifier, m_handshakeRequest.get(), response); | 520 document(), m_identifier, m_handshakeRequest.get(), response); |
| 523 } | 521 } |
| 524 m_handshakeRequest.clear(); | 522 m_handshakeRequest.clear(); |
| 525 } | 523 } |
| 526 | 524 |
| 527 void DocumentWebSocketChannel::didFail(WebSocketHandle* handle, | 525 void DocumentWebSocketChannel::didFail(WebSocketHandle* handle, |
| 528 const String& message) { | 526 const String& message) { |
| 529 NETWORK_DVLOG(1) << this << " didFail(" << handle << ", " << String(message) | 527 NETWORK_DVLOG(1) << this << " didFail(" << handle << ", " << String(message) |
| 530 << ")"; | 528 << ")"; |
| 531 | 529 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 return; | 575 return; |
| 578 } | 576 } |
| 579 // FIXME: Change the inspector API to show the entire message instead | 577 // FIXME: Change the inspector API to show the entire message instead |
| 580 // of individual frames. | 578 // of individual frames. |
| 581 WebSocketFrame::OpCode opcode = m_receivingMessageTypeIsText | 579 WebSocketFrame::OpCode opcode = m_receivingMessageTypeIsText |
| 582 ? WebSocketFrame::OpCodeText | 580 ? WebSocketFrame::OpCodeText |
| 583 : WebSocketFrame::OpCodeBinary; | 581 : WebSocketFrame::OpCodeBinary; |
| 584 WebSocketFrame frame(opcode, m_receivingMessageData.data(), | 582 WebSocketFrame frame(opcode, m_receivingMessageData.data(), |
| 585 m_receivingMessageData.size(), WebSocketFrame::Final); | 583 m_receivingMessageData.size(), WebSocketFrame::Final); |
| 586 if (document()) { | 584 if (document()) { |
| 587 InspectorInstrumentation::didReceiveWebSocketFrame( | 585 probe::didReceiveWebSocketFrame(document(), m_identifier, frame.opCode, |
| 588 document(), m_identifier, frame.opCode, frame.masked, frame.payload, | 586 frame.masked, frame.payload, |
| 589 frame.payloadLength); | 587 frame.payloadLength); |
| 590 } | 588 } |
| 591 if (m_receivingMessageTypeIsText) { | 589 if (m_receivingMessageTypeIsText) { |
| 592 String message = m_receivingMessageData.isEmpty() | 590 String message = m_receivingMessageData.isEmpty() |
| 593 ? emptyString | 591 ? emptyString |
| 594 : String::fromUTF8(m_receivingMessageData.data(), | 592 : String::fromUTF8(m_receivingMessageData.data(), |
| 595 m_receivingMessageData.size()); | 593 m_receivingMessageData.size()); |
| 596 m_receivingMessageData.clear(); | 594 m_receivingMessageData.clear(); |
| 597 if (message.isNull()) { | 595 if (message.isNull()) { |
| 598 failAsError("Could not decode a text frame as UTF-8."); | 596 failAsError("Could not decode a text frame as UTF-8."); |
| 599 // failAsError may delete this object. | 597 // failAsError may delete this object. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 619 | 617 |
| 620 DCHECK(m_handle); | 618 DCHECK(m_handle); |
| 621 DCHECK_EQ(handle, m_handle.get()); | 619 DCHECK_EQ(handle, m_handle.get()); |
| 622 | 620 |
| 623 m_handle.reset(); | 621 m_handle.reset(); |
| 624 | 622 |
| 625 if (m_identifier && document()) { | 623 if (m_identifier && document()) { |
| 626 TRACE_EVENT_INSTANT1( | 624 TRACE_EVENT_INSTANT1( |
| 627 "devtools.timeline", "WebSocketDestroy", TRACE_EVENT_SCOPE_THREAD, | 625 "devtools.timeline", "WebSocketDestroy", TRACE_EVENT_SCOPE_THREAD, |
| 628 "data", InspectorWebSocketEvent::data(document(), m_identifier)); | 626 "data", InspectorWebSocketEvent::data(document(), m_identifier)); |
| 629 InspectorInstrumentation::didCloseWebSocket(document(), m_identifier); | 627 probe::didCloseWebSocket(document(), m_identifier); |
| 630 m_identifier = 0; | 628 m_identifier = 0; |
| 631 } | 629 } |
| 632 | 630 |
| 633 handleDidClose(wasClean, code, reason); | 631 handleDidClose(wasClean, code, reason); |
| 634 // handleDidClose may delete this object. | 632 // handleDidClose may delete this object. |
| 635 } | 633 } |
| 636 | 634 |
| 637 void DocumentWebSocketChannel::didReceiveFlowControl(WebSocketHandle* handle, | 635 void DocumentWebSocketChannel::didReceiveFlowControl(WebSocketHandle* handle, |
| 638 int64_t quota) { | 636 int64_t quota) { |
| 639 NETWORK_DVLOG(1) << this << " didReceiveFlowControl(" << handle << ", " | 637 NETWORK_DVLOG(1) << this << " didReceiveFlowControl(" << handle << ", " |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 WebSocketChannel::trace(visitor); | 687 WebSocketChannel::trace(visitor); |
| 690 } | 688 } |
| 691 | 689 |
| 692 std::ostream& operator<<(std::ostream& ostream, | 690 std::ostream& operator<<(std::ostream& ostream, |
| 693 const DocumentWebSocketChannel* channel) { | 691 const DocumentWebSocketChannel* channel) { |
| 694 return ostream << "DocumentWebSocketChannel " | 692 return ostream << "DocumentWebSocketChannel " |
| 695 << static_cast<const void*>(channel); | 693 << static_cast<const void*>(channel); |
| 696 } | 694 } |
| 697 | 695 |
| 698 } // namespace blink | 696 } // namespace blink |
| OLD | NEW |