| OLD | NEW | 
|    1 /* |    1 /* | 
|    2  * Copyright (C) 2011 Google Inc.  All rights reserved. |    2  * Copyright (C) 2011 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   42 #include "core/dom/SecurityContext.h" |   42 #include "core/dom/SecurityContext.h" | 
|   43 #include "core/events/MessageEvent.h" |   43 #include "core/events/MessageEvent.h" | 
|   44 #include "core/fileapi/Blob.h" |   44 #include "core/fileapi/Blob.h" | 
|   45 #include "core/frame/LocalDOMWindow.h" |   45 #include "core/frame/LocalDOMWindow.h" | 
|   46 #include "core/frame/LocalFrame.h" |   46 #include "core/frame/LocalFrame.h" | 
|   47 #include "core/frame/UseCounter.h" |   47 #include "core/frame/UseCounter.h" | 
|   48 #include "core/frame/csp/ContentSecurityPolicy.h" |   48 #include "core/frame/csp/ContentSecurityPolicy.h" | 
|   49 #include "core/inspector/ConsoleMessage.h" |   49 #include "core/inspector/ConsoleMessage.h" | 
|   50 #include "modules/websockets/CloseEvent.h" |   50 #include "modules/websockets/CloseEvent.h" | 
|   51 #include "platform/Histogram.h" |   51 #include "platform/Histogram.h" | 
|   52 #include "platform/Logging.h" |  | 
|   53 #include "platform/blob/BlobData.h" |   52 #include "platform/blob/BlobData.h" | 
 |   53 #include "platform/network/NetworkLog.h" | 
|   54 #include "platform/weborigin/KnownPorts.h" |   54 #include "platform/weborigin/KnownPorts.h" | 
|   55 #include "platform/weborigin/SecurityOrigin.h" |   55 #include "platform/weborigin/SecurityOrigin.h" | 
|   56 #include "public/platform/Platform.h" |   56 #include "public/platform/Platform.h" | 
|   57 #include "public/platform/WebInsecureRequestPolicy.h" |   57 #include "public/platform/WebInsecureRequestPolicy.h" | 
|   58 #include "wtf/Assertions.h" |   58 #include "wtf/Assertions.h" | 
|   59 #include "wtf/HashSet.h" |   59 #include "wtf/HashSet.h" | 
|   60 #include "wtf/MathExtras.h" |   60 #include "wtf/MathExtras.h" | 
|   61 #include "wtf/StdLibExtras.h" |   61 #include "wtf/StdLibExtras.h" | 
|   62 #include "wtf/text/CString.h" |   62 #include "wtf/text/CString.h" | 
|   63 #include "wtf/text/StringBuilder.h" |   63 #include "wtf/text/StringBuilder.h" | 
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  277     if (exceptionState.hadException()) |  277     if (exceptionState.hadException()) | 
|  278         return nullptr; |  278         return nullptr; | 
|  279  |  279  | 
|  280     return webSocket; |  280     return webSocket; | 
|  281 } |  281 } | 
|  282  |  282  | 
|  283 void DOMWebSocket::connect(const String& url, const Vector<String>& protocols, E
     xceptionState& exceptionState) |  283 void DOMWebSocket::connect(const String& url, const Vector<String>& protocols, E
     xceptionState& exceptionState) | 
|  284 { |  284 { | 
|  285     UseCounter::count(getExecutionContext(), UseCounter::WebSocket); |  285     UseCounter::count(getExecutionContext(), UseCounter::WebSocket); | 
|  286  |  286  | 
|  287     WTF_LOG(Network, "WebSocket %p connect() url='%s'", this, url.utf8().data())
     ; |  287     NETWORK_DVLOG(1) << "WebSocket " << this << " connect() url=" << url; | 
|  288     m_url = KURL(KURL(), url); |  288     m_url = KURL(KURL(), url); | 
|  289  |  289  | 
|  290     if (getExecutionContext()->securityContext().getInsecureRequestPolicy() & kU
     pgradeInsecureRequests && m_url.protocol() == "ws") { |  290     if (getExecutionContext()->securityContext().getInsecureRequestPolicy() & kU
     pgradeInsecureRequests && m_url.protocol() == "ws") { | 
|  291         UseCounter::count(getExecutionContext(), UseCounter::UpgradeInsecureRequ
     estsUpgradedRequest); |  291         UseCounter::count(getExecutionContext(), UseCounter::UpgradeInsecureRequ
     estsUpgradedRequest); | 
|  292         m_url.setProtocol("wss"); |  292         m_url.setProtocol("wss"); | 
|  293         if (m_url.port() == 80) |  293         if (m_url.port() == 80) | 
|  294             m_url.setPort(443); |  294             m_url.setPort(443); | 
|  295     } |  295     } | 
|  296  |  296  | 
|  297     if (!m_url.isValid()) { |  297     if (!m_url.isValid()) { | 
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  363     m_bufferedAmountAfterClose += payloadSize; |  363     m_bufferedAmountAfterClose += payloadSize; | 
|  364  |  364  | 
|  365     logError("WebSocket is already in CLOSING or CLOSED state."); |  365     logError("WebSocket is already in CLOSING or CLOSED state."); | 
|  366 } |  366 } | 
|  367  |  367  | 
|  368 void DOMWebSocket::reflectBufferedAmountConsumption(TimerBase*) |  368 void DOMWebSocket::reflectBufferedAmountConsumption(TimerBase*) | 
|  369 { |  369 { | 
|  370     ASSERT(m_bufferedAmount >= m_consumedBufferedAmount); |  370     ASSERT(m_bufferedAmount >= m_consumedBufferedAmount); | 
|  371     // Cast to unsigned long long is required since clang doesn't accept |  371     // Cast to unsigned long long is required since clang doesn't accept | 
|  372     // combination of %llu and uint64_t (known as unsigned long). |  372     // combination of %llu and uint64_t (known as unsigned long). | 
|  373     WTF_LOG(Network, "WebSocket %p reflectBufferedAmountConsumption() %llu => %l
     lu", this, static_cast<unsigned long long>(m_bufferedAmount), static_cast<unsign
     ed long long>(m_bufferedAmount - m_consumedBufferedAmount)); |  373     NETWORK_DVLOG(1) << "WebSocket " << this << " reflectBufferedAmountConsumpti
     on() " << m_bufferedAmount << " => " << (m_bufferedAmount - m_consumedBufferedAm
     ount); | 
|  374  |  374  | 
|  375     m_bufferedAmount -= m_consumedBufferedAmount; |  375     m_bufferedAmount -= m_consumedBufferedAmount; | 
|  376     m_consumedBufferedAmount = 0; |  376     m_consumedBufferedAmount = 0; | 
|  377 } |  377 } | 
|  378  |  378  | 
|  379 void DOMWebSocket::releaseChannel() |  379 void DOMWebSocket::releaseChannel() | 
|  380 { |  380 { | 
|  381     ASSERT(m_channel); |  381     ASSERT(m_channel); | 
|  382     m_channel->disconnect(); |  382     m_channel->disconnect(); | 
|  383     m_channel = nullptr; |  383     m_channel = nullptr; | 
|  384 } |  384 } | 
|  385  |  385  | 
|  386 void DOMWebSocket::logBinaryTypeChangesAfterOpen() |  386 void DOMWebSocket::logBinaryTypeChangesAfterOpen() | 
|  387 { |  387 { | 
|  388     DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, binaryTypeChangesHisto
     gram, new CustomCountHistogram("WebCore.WebSocket.BinaryTypeChangesAfterOpen", 1
     , 1024, 10)); |  388     DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, binaryTypeChangesHisto
     gram, new CustomCountHistogram("WebCore.WebSocket.BinaryTypeChangesAfterOpen", 1
     , 1024, 10)); | 
|  389     DVLOG(3) << "WebSocket " << static_cast<void*>(this) << " logBinaryTypeChang
     esAfterOpen() logging " << m_binaryTypeChangesAfterOpen; |  389     DVLOG(3) << "WebSocket " << static_cast<void*>(this) << " logBinaryTypeChang
     esAfterOpen() logging " << m_binaryTypeChangesAfterOpen; | 
|  390     binaryTypeChangesHistogram.count(m_binaryTypeChangesAfterOpen); |  390     binaryTypeChangesHistogram.count(m_binaryTypeChangesAfterOpen); | 
|  391 } |  391 } | 
|  392  |  392  | 
|  393 void DOMWebSocket::send(const String& message, ExceptionState& exceptionState) |  393 void DOMWebSocket::send(const String& message, ExceptionState& exceptionState) | 
|  394 { |  394 { | 
|  395     CString encodedMessage = message.utf8(); |  395     CString encodedMessage = message.utf8(); | 
|  396  |  396  | 
|  397     WTF_LOG(Network, "WebSocket %p send() Sending String '%s'", this, encodedMes
     sage.data()); |  397     NETWORK_DVLOG(1) << "WebSocket " << this << " send() Sending String " << mes
     sage; | 
|  398     if (m_state == kConnecting) { |  398     if (m_state == kConnecting) { | 
|  399         setInvalidStateErrorForSendMethod(exceptionState); |  399         setInvalidStateErrorForSendMethod(exceptionState); | 
|  400         return; |  400         return; | 
|  401     } |  401     } | 
|  402     // No exception is raised if the connection was once established but has sub
     sequently been closed. |  402     // No exception is raised if the connection was once established but has sub
     sequently been closed. | 
|  403     if (m_state == kClosing || m_state == kClosed) { |  403     if (m_state == kClosing || m_state == kClosed) { | 
|  404         updateBufferedAmountAfterClose(encodedMessage.length()); |  404         updateBufferedAmountAfterClose(encodedMessage.length()); | 
|  405         return; |  405         return; | 
|  406     } |  406     } | 
|  407  |  407  | 
|  408     recordSendTypeHistogram(WebSocketSendTypeString); |  408     recordSendTypeHistogram(WebSocketSendTypeString); | 
|  409  |  409  | 
|  410     ASSERT(m_channel); |  410     ASSERT(m_channel); | 
|  411     m_bufferedAmount += encodedMessage.length(); |  411     m_bufferedAmount += encodedMessage.length(); | 
|  412     m_channel->send(encodedMessage); |  412     m_channel->send(encodedMessage); | 
|  413 } |  413 } | 
|  414  |  414  | 
|  415 void DOMWebSocket::send(DOMArrayBuffer* binaryData, ExceptionState& exceptionSta
     te) |  415 void DOMWebSocket::send(DOMArrayBuffer* binaryData, ExceptionState& exceptionSta
     te) | 
|  416 { |  416 { | 
|  417     WTF_LOG(Network, "WebSocket %p send() Sending ArrayBuffer %p", this, binaryD
     ata); |  417     NETWORK_DVLOG(1) << "WebSocket " << this << " send() Sending ArrayBuffer " <
     < binaryData; | 
|  418     ASSERT(binaryData && binaryData->buffer()); |  418     ASSERT(binaryData && binaryData->buffer()); | 
|  419     if (m_state == kConnecting) { |  419     if (m_state == kConnecting) { | 
|  420         setInvalidStateErrorForSendMethod(exceptionState); |  420         setInvalidStateErrorForSendMethod(exceptionState); | 
|  421         return; |  421         return; | 
|  422     } |  422     } | 
|  423     if (m_state == kClosing || m_state == kClosed) { |  423     if (m_state == kClosing || m_state == kClosed) { | 
|  424         updateBufferedAmountAfterClose(binaryData->byteLength()); |  424         updateBufferedAmountAfterClose(binaryData->byteLength()); | 
|  425         return; |  425         return; | 
|  426     } |  426     } | 
|  427     recordSendTypeHistogram(WebSocketSendTypeArrayBuffer); |  427     recordSendTypeHistogram(WebSocketSendTypeArrayBuffer); | 
|  428     recordSendMessageSizeHistogram(WebSocketSendTypeArrayBuffer, binaryData->byt
     eLength()); |  428     recordSendMessageSizeHistogram(WebSocketSendTypeArrayBuffer, binaryData->byt
     eLength()); | 
|  429     ASSERT(m_channel); |  429     ASSERT(m_channel); | 
|  430     m_bufferedAmount += binaryData->byteLength(); |  430     m_bufferedAmount += binaryData->byteLength(); | 
|  431     m_channel->send(*binaryData, 0, binaryData->byteLength()); |  431     m_channel->send(*binaryData, 0, binaryData->byteLength()); | 
|  432 } |  432 } | 
|  433  |  433  | 
|  434 void DOMWebSocket::send(DOMArrayBufferView* arrayBufferView, ExceptionState& exc
     eptionState) |  434 void DOMWebSocket::send(DOMArrayBufferView* arrayBufferView, ExceptionState& exc
     eptionState) | 
|  435 { |  435 { | 
|  436     WTF_LOG(Network, "WebSocket %p send() Sending ArrayBufferView %p", this, arr
     ayBufferView); |  436     NETWORK_DVLOG(1) << "WebSocket " << this << " send() Sending ArrayBufferView
      " << arrayBufferView; | 
|  437     ASSERT(arrayBufferView); |  437     ASSERT(arrayBufferView); | 
|  438     if (m_state == kConnecting) { |  438     if (m_state == kConnecting) { | 
|  439         setInvalidStateErrorForSendMethod(exceptionState); |  439         setInvalidStateErrorForSendMethod(exceptionState); | 
|  440         return; |  440         return; | 
|  441     } |  441     } | 
|  442     if (m_state == kClosing || m_state == kClosed) { |  442     if (m_state == kClosing || m_state == kClosed) { | 
|  443         updateBufferedAmountAfterClose(arrayBufferView->byteLength()); |  443         updateBufferedAmountAfterClose(arrayBufferView->byteLength()); | 
|  444         return; |  444         return; | 
|  445     } |  445     } | 
|  446     recordSendTypeHistogram(WebSocketSendTypeArrayBufferView); |  446     recordSendTypeHistogram(WebSocketSendTypeArrayBufferView); | 
|  447     recordSendMessageSizeHistogram(WebSocketSendTypeArrayBufferView, arrayBuffer
     View->byteLength()); |  447     recordSendMessageSizeHistogram(WebSocketSendTypeArrayBufferView, arrayBuffer
     View->byteLength()); | 
|  448     ASSERT(m_channel); |  448     ASSERT(m_channel); | 
|  449     m_bufferedAmount += arrayBufferView->byteLength(); |  449     m_bufferedAmount += arrayBufferView->byteLength(); | 
|  450     m_channel->send(*arrayBufferView->buffer(), arrayBufferView->byteOffset(), a
     rrayBufferView->byteLength()); |  450     m_channel->send(*arrayBufferView->buffer(), arrayBufferView->byteOffset(), a
     rrayBufferView->byteLength()); | 
|  451 } |  451 } | 
|  452  |  452  | 
|  453 void DOMWebSocket::send(Blob* binaryData, ExceptionState& exceptionState) |  453 void DOMWebSocket::send(Blob* binaryData, ExceptionState& exceptionState) | 
|  454 { |  454 { | 
|  455     WTF_LOG(Network, "WebSocket %p send() Sending Blob '%s'", this, binaryData->
     uuid().utf8().data()); |  455     NETWORK_DVLOG(1) << "WebSocket " << this << " send() Sending Blob " << binar
     yData->uuid(); | 
|  456     ASSERT(binaryData); |  456     ASSERT(binaryData); | 
|  457     if (m_state == kConnecting) { |  457     if (m_state == kConnecting) { | 
|  458         setInvalidStateErrorForSendMethod(exceptionState); |  458         setInvalidStateErrorForSendMethod(exceptionState); | 
|  459         return; |  459         return; | 
|  460     } |  460     } | 
|  461     if (m_state == kClosing || m_state == kClosed) { |  461     if (m_state == kClosing || m_state == kClosed) { | 
|  462         updateBufferedAmountAfterClose(binaryData->size()); |  462         updateBufferedAmountAfterClose(binaryData->size()); | 
|  463         return; |  463         return; | 
|  464     } |  464     } | 
|  465     unsigned long long size = binaryData->size(); |  465     unsigned long long size = binaryData->size(); | 
| (...skipping 23 matching lines...) Expand all  Loading... | 
|  489  |  489  | 
|  490 void DOMWebSocket::close(unsigned short code, ExceptionState& exceptionState) |  490 void DOMWebSocket::close(unsigned short code, ExceptionState& exceptionState) | 
|  491 { |  491 { | 
|  492     closeInternal(code, String(), exceptionState); |  492     closeInternal(code, String(), exceptionState); | 
|  493 } |  493 } | 
|  494  |  494  | 
|  495 void DOMWebSocket::closeInternal(int code, const String& reason, ExceptionState&
      exceptionState) |  495 void DOMWebSocket::closeInternal(int code, const String& reason, ExceptionState&
      exceptionState) | 
|  496 { |  496 { | 
|  497     String cleansedReason = reason; |  497     String cleansedReason = reason; | 
|  498     if (code == WebSocketChannel::CloseEventCodeNotSpecified) { |  498     if (code == WebSocketChannel::CloseEventCodeNotSpecified) { | 
|  499         WTF_LOG(Network, "WebSocket %p close() without code and reason", this); |  499         NETWORK_DVLOG(1) << "WebSocket " << this << " close() without code and r
     eason"; | 
|  500     } else { |  500     } else { | 
|  501         WTF_LOG(Network, "WebSocket %p close() code=%d reason='%s'", this, code,
      reason.utf8().data()); |  501         NETWORK_DVLOG(1) << "WebSocket " << this << " close() code=" << code << 
     " reason=" << reason; | 
|  502         if (!(code == WebSocketChannel::CloseEventCodeNormalClosure || (WebSocke
     tChannel::CloseEventCodeMinimumUserDefined <= code && code <= WebSocketChannel::
     CloseEventCodeMaximumUserDefined))) { |  502         if (!(code == WebSocketChannel::CloseEventCodeNormalClosure || (WebSocke
     tChannel::CloseEventCodeMinimumUserDefined <= code && code <= WebSocketChannel::
     CloseEventCodeMaximumUserDefined))) { | 
|  503             exceptionState.throwDOMException(InvalidAccessError, "The code must 
     be either 1000, or between 3000 and 4999. " + String::number(code) + " is neithe
     r."); |  503             exceptionState.throwDOMException(InvalidAccessError, "The code must 
     be either 1000, or between 3000 and 4999. " + String::number(code) + " is neithe
     r."); | 
|  504             return; |  504             return; | 
|  505         } |  505         } | 
|  506         // Bindings specify USVString, so unpaired surrogates are already replac
     ed with U+FFFD. |  506         // Bindings specify USVString, so unpaired surrogates are already replac
     ed with U+FFFD. | 
|  507         CString utf8 = reason.utf8(); |  507         CString utf8 = reason.utf8(); | 
|  508         if (utf8.length() > maxReasonSizeInBytes) { |  508         if (utf8.length() > maxReasonSizeInBytes) { | 
|  509             exceptionState.throwDOMException(SyntaxError, "The message must not 
     be greater than " + String::number(maxReasonSizeInBytes) + " bytes."); |  509             exceptionState.throwDOMException(SyntaxError, "The message must not 
     be greater than " + String::number(maxReasonSizeInBytes) + " bytes."); | 
|  510             return; |  510             return; | 
|  511         } |  511         } | 
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  597     return EventTargetNames::DOMWebSocket; |  597     return EventTargetNames::DOMWebSocket; | 
|  598 } |  598 } | 
|  599  |  599  | 
|  600 ExecutionContext* DOMWebSocket::getExecutionContext() const |  600 ExecutionContext* DOMWebSocket::getExecutionContext() const | 
|  601 { |  601 { | 
|  602     return ActiveDOMObject::getExecutionContext(); |  602     return ActiveDOMObject::getExecutionContext(); | 
|  603 } |  603 } | 
|  604  |  604  | 
|  605 void DOMWebSocket::contextDestroyed() |  605 void DOMWebSocket::contextDestroyed() | 
|  606 { |  606 { | 
|  607     WTF_LOG(Network, "WebSocket %p contextDestroyed()", this); |  607     NETWORK_DVLOG(1) << "WebSocket " << this << " contextDestroyed()"; | 
|  608     DCHECK(!m_channel); |  608     DCHECK(!m_channel); | 
|  609     DCHECK_EQ(kClosed, m_state); |  609     DCHECK_EQ(kClosed, m_state); | 
|  610     ActiveDOMObject::contextDestroyed(); |  610     ActiveDOMObject::contextDestroyed(); | 
|  611 } |  611 } | 
|  612  |  612  | 
|  613 bool DOMWebSocket::hasPendingActivity() const |  613 bool DOMWebSocket::hasPendingActivity() const | 
|  614 { |  614 { | 
|  615     return m_channel || !m_eventQueue->isEmpty(); |  615     return m_channel || !m_eventQueue->isEmpty(); | 
|  616 } |  616 } | 
|  617  |  617  | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
|  633         releaseChannel(); |  633         releaseChannel(); | 
|  634     } |  634     } | 
|  635     if (m_state != kClosed) { |  635     if (m_state != kClosed) { | 
|  636         m_state = kClosed; |  636         m_state = kClosed; | 
|  637         logBinaryTypeChangesAfterOpen(); |  637         logBinaryTypeChangesAfterOpen(); | 
|  638     } |  638     } | 
|  639 } |  639 } | 
|  640  |  640  | 
|  641 void DOMWebSocket::didConnect(const String& subprotocol, const String& extension
     s) |  641 void DOMWebSocket::didConnect(const String& subprotocol, const String& extension
     s) | 
|  642 { |  642 { | 
|  643     WTF_LOG(Network, "WebSocket %p didConnect()", this); |  643     NETWORK_DVLOG(1) << "WebSocket " << this << " didConnect()"; | 
|  644     if (m_state != kConnecting) |  644     if (m_state != kConnecting) | 
|  645         return; |  645         return; | 
|  646     m_state = kOpen; |  646     m_state = kOpen; | 
|  647     m_subprotocol = subprotocol; |  647     m_subprotocol = subprotocol; | 
|  648     m_extensions = extensions; |  648     m_extensions = extensions; | 
|  649     m_eventQueue->dispatch(Event::create(EventTypeNames::open)); |  649     m_eventQueue->dispatch(Event::create(EventTypeNames::open)); | 
|  650 } |  650 } | 
|  651  |  651  | 
|  652 void DOMWebSocket::didReceiveTextMessage(const String& msg) |  652 void DOMWebSocket::didReceiveTextMessage(const String& msg) | 
|  653 { |  653 { | 
|  654     WTF_LOG(Network, "WebSocket %p didReceiveTextMessage() Text message '%s'", t
     his, msg.utf8().data()); |  654     NETWORK_DVLOG(1) << "WebSocket " << this << " didReceiveTextMessage() Text m
     essage " << msg; | 
|  655     if (m_state != kOpen) |  655     if (m_state != kOpen) | 
|  656         return; |  656         return; | 
|  657     recordReceiveTypeHistogram(WebSocketReceiveTypeString); |  657     recordReceiveTypeHistogram(WebSocketReceiveTypeString); | 
|  658  |  658  | 
|  659     m_eventQueue->dispatch(MessageEvent::create(msg, SecurityOrigin::create(m_ur
     l)->toString())); |  659     m_eventQueue->dispatch(MessageEvent::create(msg, SecurityOrigin::create(m_ur
     l)->toString())); | 
|  660 } |  660 } | 
|  661  |  661  | 
|  662 void DOMWebSocket::didReceiveBinaryMessage(std::unique_ptr<Vector<char>> binaryD
     ata) |  662 void DOMWebSocket::didReceiveBinaryMessage(std::unique_ptr<Vector<char>> binaryD
     ata) | 
|  663 { |  663 { | 
|  664     WTF_LOG(Network, "WebSocket %p didReceiveBinaryMessage() %lu byte binary mes
     sage", this, static_cast<unsigned long>(binaryData->size())); |  664     NETWORK_DVLOG(1) << "WebSocket " << this << " didReceiveBinaryMessage() " <<
      binaryData->size() << " byte binary message"; | 
|  665     switch (m_binaryType) { |  665     switch (m_binaryType) { | 
|  666     case BinaryTypeBlob: { |  666     case BinaryTypeBlob: { | 
|  667         size_t size = binaryData->size(); |  667         size_t size = binaryData->size(); | 
|  668         RefPtr<RawData> rawData = RawData::create(); |  668         RefPtr<RawData> rawData = RawData::create(); | 
|  669         binaryData->swap(*rawData->mutableData()); |  669         binaryData->swap(*rawData->mutableData()); | 
|  670         std::unique_ptr<BlobData> blobData = BlobData::create(); |  670         std::unique_ptr<BlobData> blobData = BlobData::create(); | 
|  671         blobData->appendData(rawData.release(), 0, BlobDataItem::toEndOfFile); |  671         blobData->appendData(rawData.release(), 0, BlobDataItem::toEndOfFile); | 
|  672         Blob* blob = Blob::create(BlobDataHandle::create(std::move(blobData), si
     ze)); |  672         Blob* blob = Blob::create(BlobDataHandle::create(std::move(blobData), si
     ze)); | 
|  673         recordReceiveTypeHistogram(WebSocketReceiveTypeBlob); |  673         recordReceiveTypeHistogram(WebSocketReceiveTypeBlob); | 
|  674         recordReceiveMessageSizeHistogram(WebSocketReceiveTypeBlob, size); |  674         recordReceiveMessageSizeHistogram(WebSocketReceiveTypeBlob, size); | 
|  675         m_eventQueue->dispatch(MessageEvent::create(blob, SecurityOrigin::create
     (m_url)->toString())); |  675         m_eventQueue->dispatch(MessageEvent::create(blob, SecurityOrigin::create
     (m_url)->toString())); | 
|  676         break; |  676         break; | 
|  677     } |  677     } | 
|  678  |  678  | 
|  679     case BinaryTypeArrayBuffer: |  679     case BinaryTypeArrayBuffer: | 
|  680         DOMArrayBuffer* arrayBuffer = DOMArrayBuffer::create(binaryData->data(),
      binaryData->size()); |  680         DOMArrayBuffer* arrayBuffer = DOMArrayBuffer::create(binaryData->data(),
      binaryData->size()); | 
|  681         recordReceiveTypeHistogram(WebSocketReceiveTypeArrayBuffer); |  681         recordReceiveTypeHistogram(WebSocketReceiveTypeArrayBuffer); | 
|  682         recordReceiveMessageSizeHistogram(WebSocketReceiveTypeArrayBuffer, binar
     yData->size()); |  682         recordReceiveMessageSizeHistogram(WebSocketReceiveTypeArrayBuffer, binar
     yData->size()); | 
|  683         m_eventQueue->dispatch(MessageEvent::create(arrayBuffer, SecurityOrigin:
     :create(m_url)->toString())); |  683         m_eventQueue->dispatch(MessageEvent::create(arrayBuffer, SecurityOrigin:
     :create(m_url)->toString())); | 
|  684         break; |  684         break; | 
|  685     } |  685     } | 
|  686 } |  686 } | 
|  687  |  687  | 
|  688 void DOMWebSocket::didError() |  688 void DOMWebSocket::didError() | 
|  689 { |  689 { | 
|  690     WTF_LOG(Network, "WebSocket %p didError()", this); |  690     NETWORK_DVLOG(1) << "WebSocket " << this << " didError()"; | 
|  691     m_state = kClosed; |  691     m_state = kClosed; | 
|  692     logBinaryTypeChangesAfterOpen(); |  692     logBinaryTypeChangesAfterOpen(); | 
|  693     m_eventQueue->dispatch(Event::create(EventTypeNames::error)); |  693     m_eventQueue->dispatch(Event::create(EventTypeNames::error)); | 
|  694 } |  694 } | 
|  695  |  695  | 
|  696 void DOMWebSocket::didConsumeBufferedAmount(uint64_t consumed) |  696 void DOMWebSocket::didConsumeBufferedAmount(uint64_t consumed) | 
|  697 { |  697 { | 
|  698     ASSERT(m_bufferedAmount >= consumed + m_consumedBufferedAmount); |  698     ASSERT(m_bufferedAmount >= consumed + m_consumedBufferedAmount); | 
|  699     // Cast to unsigned long long is required since clang doesn't accept |  699     NETWORK_DVLOG(1) << "WebSocket " << this << " didConsumeBufferedAmount(" << 
     consumed << ")"; | 
|  700     // combination of %llu and uint64_t (known as unsigned long). |  | 
|  701     WTF_LOG(Network, "WebSocket %p didConsumeBufferedAmount(%llu)", this, static
     _cast<unsigned long long>(consumed)); |  | 
|  702     if (m_state == kClosed) |  700     if (m_state == kClosed) | 
|  703         return; |  701         return; | 
|  704     m_consumedBufferedAmount += consumed; |  702     m_consumedBufferedAmount += consumed; | 
|  705     if (!m_bufferedAmountConsumeTimer.isActive()) |  703     if (!m_bufferedAmountConsumeTimer.isActive()) | 
|  706         m_bufferedAmountConsumeTimer.startOneShot(0, BLINK_FROM_HERE); |  704         m_bufferedAmountConsumeTimer.startOneShot(0, BLINK_FROM_HERE); | 
|  707 } |  705 } | 
|  708  |  706  | 
|  709 void DOMWebSocket::didStartClosingHandshake() |  707 void DOMWebSocket::didStartClosingHandshake() | 
|  710 { |  708 { | 
|  711     WTF_LOG(Network, "WebSocket %p didStartClosingHandshake()", this); |  709     NETWORK_DVLOG(1) << "WebSocket " << this << " didStartClosingHandshake()"; | 
|  712     m_state = kClosing; |  710     m_state = kClosing; | 
|  713 } |  711 } | 
|  714  |  712  | 
|  715 void DOMWebSocket::didClose(ClosingHandshakeCompletionStatus closingHandshakeCom
     pletion, unsigned short code, const String& reason) |  713 void DOMWebSocket::didClose(ClosingHandshakeCompletionStatus closingHandshakeCom
     pletion, unsigned short code, const String& reason) | 
|  716 { |  714 { | 
|  717     WTF_LOG(Network, "WebSocket %p didClose()", this); |  715     NETWORK_DVLOG(1) << "WebSocket " << this << " didClose()"; | 
|  718     if (!m_channel) |  716     if (!m_channel) | 
|  719         return; |  717         return; | 
|  720     bool allDataHasBeenConsumed = m_bufferedAmount == m_consumedBufferedAmount; |  718     bool allDataHasBeenConsumed = m_bufferedAmount == m_consumedBufferedAmount; | 
|  721     bool wasClean = m_state == kClosing && allDataHasBeenConsumed && closingHand
     shakeCompletion == ClosingHandshakeComplete && code != WebSocketChannel::CloseEv
     entCodeAbnormalClosure; |  719     bool wasClean = m_state == kClosing && allDataHasBeenConsumed && closingHand
     shakeCompletion == ClosingHandshakeComplete && code != WebSocketChannel::CloseEv
     entCodeAbnormalClosure; | 
|  722     m_state = kClosed; |  720     m_state = kClosed; | 
|  723  |  721  | 
|  724     m_eventQueue->dispatch(CloseEvent::create(wasClean, code, reason)); |  722     m_eventQueue->dispatch(CloseEvent::create(wasClean, code, reason)); | 
|  725     releaseChannel(); |  723     releaseChannel(); | 
|  726 } |  724 } | 
|  727  |  725  | 
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  790 DEFINE_TRACE(DOMWebSocket) |  788 DEFINE_TRACE(DOMWebSocket) | 
|  791 { |  789 { | 
|  792     visitor->trace(m_channel); |  790     visitor->trace(m_channel); | 
|  793     visitor->trace(m_eventQueue); |  791     visitor->trace(m_eventQueue); | 
|  794     WebSocketChannelClient::trace(visitor); |  792     WebSocketChannelClient::trace(visitor); | 
|  795     EventTargetWithInlineData::trace(visitor); |  793     EventTargetWithInlineData::trace(visitor); | 
|  796     ActiveDOMObject::trace(visitor); |  794     ActiveDOMObject::trace(visitor); | 
|  797 } |  795 } | 
|  798  |  796  | 
|  799 } // namespace blink |  797 } // namespace blink | 
| OLD | NEW |