|
Lines 56-63
a/Source/WebCore/Modules/websockets/WebSocketChannel.cpp_sec1
|
| 56 |
#include <wtf/Deque.h> |
56 |
#include <wtf/Deque.h> |
| 57 |
#include <wtf/FastMalloc.h> |
57 |
#include <wtf/FastMalloc.h> |
| 58 |
#include <wtf/HashMap.h> |
58 |
#include <wtf/HashMap.h> |
| 59 |
#include <wtf/OwnPtr.h> |
|
|
| 60 |
#include <wtf/PassOwnPtr.h> |
| 61 |
#include <wtf/text/CString.h> |
59 |
#include <wtf/text/CString.h> |
| 62 |
#include <wtf/text/StringHash.h> |
60 |
#include <wtf/text/StringHash.h> |
| 63 |
#include <wtf/text/WTFString.h> |
61 |
#include <wtf/text/WTFString.h> |
|
Lines 99-105
void WebSocketChannel::connect(const URL& url, const String& protocol)
a/Source/WebCore/Modules/websockets/WebSocketChannel.cpp_sec2
|
| 99 |
LOG(Network, "WebSocketChannel %p connect()", this); |
97 |
LOG(Network, "WebSocketChannel %p connect()", this); |
| 100 |
ASSERT(!m_handle); |
98 |
ASSERT(!m_handle); |
| 101 |
ASSERT(!m_suspended); |
99 |
ASSERT(!m_suspended); |
| 102 |
m_handshake = adoptPtr(new WebSocketHandshake(url, protocol, m_document)); |
100 |
m_handshake = std::make_unique<WebSocketHandshake>(url, protocol, m_document); |
| 103 |
m_handshake->reset(); |
101 |
m_handshake->reset(); |
| 104 |
if (m_deflateFramer.canDeflate()) |
102 |
if (m_deflateFramer.canDeflate()) |
| 105 |
m_handshake->addExtensionProcessor(m_deflateFramer.createExtensionProcessor()); |
103 |
m_handshake->addExtensionProcessor(m_deflateFramer.createExtensionProcessor()); |
|
Lines 375-381
void WebSocketChannel::didFail(int errorCode)
a/Source/WebCore/Modules/websockets/WebSocketChannel.cpp_sec3
|
| 375 |
LOG(Network, "WebSocketChannel %p didFail() errorCode=%d", this, errorCode); |
373 |
LOG(Network, "WebSocketChannel %p didFail() errorCode=%d", this, errorCode); |
| 376 |
ASSERT(m_blobLoader); |
374 |
ASSERT(m_blobLoader); |
| 377 |
ASSERT(m_blobLoaderStatus == BlobLoaderStarted); |
375 |
ASSERT(m_blobLoaderStatus == BlobLoaderStarted); |
| 378 |
m_blobLoader.clear(); |
376 |
m_blobLoader = nullptr; |
| 379 |
m_blobLoaderStatus = BlobLoaderFailed; |
377 |
m_blobLoaderStatus = BlobLoaderFailed; |
| 380 |
fail("Failed to load Blob: error code = " + String::number(errorCode)); // FIXME: Generate human-friendly reason message. |
378 |
fail("Failed to load Blob: error code = " + String::number(errorCode)); // FIXME: Generate human-friendly reason message. |
| 381 |
deref(); |
379 |
deref(); |
|
Lines 518-524
bool WebSocketChannel::processFrame()
a/Source/WebCore/Modules/websockets/WebSocketChannel.cpp_sec4
|
| 518 |
ASSERT(m_buffer.data() < frameEnd); |
516 |
ASSERT(m_buffer.data() < frameEnd); |
| 519 |
ASSERT(frameEnd <= m_buffer.data() + m_buffer.size()); |
517 |
ASSERT(frameEnd <= m_buffer.data() + m_buffer.size()); |
| 520 |
|
518 |
|
| 521 |
OwnPtr<InflateResultHolder> inflateResult = m_deflateFramer.inflate(frame); |
519 |
auto inflateResult = m_deflateFramer.inflate(frame); |
| 522 |
if (!inflateResult->succeeded()) { |
520 |
if (!inflateResult->succeeded()) { |
| 523 |
fail(inflateResult->failureReason()); |
521 |
fail(inflateResult->failureReason()); |
| 524 |
return false; |
522 |
return false; |
|
Lines 685-691
bool WebSocketChannel::processFrame()
a/Source/WebCore/Modules/websockets/WebSocketChannel.cpp_sec5
|
| 685 |
void WebSocketChannel::enqueueTextFrame(const CString& string) |
683 |
void WebSocketChannel::enqueueTextFrame(const CString& string) |
| 686 |
{ |
684 |
{ |
| 687 |
ASSERT(m_outgoingFrameQueueStatus == OutgoingFrameQueueOpen); |
685 |
ASSERT(m_outgoingFrameQueueStatus == OutgoingFrameQueueOpen); |
| 688 |
OwnPtr<QueuedFrame> frame = adoptPtr(new QueuedFrame); |
686 |
auto frame = std::make_unique<QueuedFrame>(); |
| 689 |
frame->opCode = WebSocketFrame::OpCodeText; |
687 |
frame->opCode = WebSocketFrame::OpCodeText; |
| 690 |
frame->frameType = QueuedFrameTypeString; |
688 |
frame->frameType = QueuedFrameTypeString; |
| 691 |
frame->stringData = string; |
689 |
frame->stringData = string; |
|
Lines 695-701
void WebSocketChannel::enqueueTextFrame(const CString& string)
a/Source/WebCore/Modules/websockets/WebSocketChannel.cpp_sec6
|
| 695 |
void WebSocketChannel::enqueueRawFrame(WebSocketFrame::OpCode opCode, const char* data, size_t dataLength) |
693 |
void WebSocketChannel::enqueueRawFrame(WebSocketFrame::OpCode opCode, const char* data, size_t dataLength) |
| 696 |
{ |
694 |
{ |
| 697 |
ASSERT(m_outgoingFrameQueueStatus == OutgoingFrameQueueOpen); |
695 |
ASSERT(m_outgoingFrameQueueStatus == OutgoingFrameQueueOpen); |
| 698 |
OwnPtr<QueuedFrame> frame = adoptPtr(new QueuedFrame); |
696 |
auto frame = std::make_unique<QueuedFrame>(); |
| 699 |
frame->opCode = opCode; |
697 |
frame->opCode = opCode; |
| 700 |
frame->frameType = QueuedFrameTypeVector; |
698 |
frame->frameType = QueuedFrameTypeVector; |
| 701 |
frame->vectorData.resize(dataLength); |
699 |
frame->vectorData.resize(dataLength); |
|
Lines 707-713
void WebSocketChannel::enqueueRawFrame(WebSocketFrame::OpCode opCode, const char
a/Source/WebCore/Modules/websockets/WebSocketChannel.cpp_sec7
|
| 707 |
void WebSocketChannel::enqueueBlobFrame(WebSocketFrame::OpCode opCode, Blob& blob) |
705 |
void WebSocketChannel::enqueueBlobFrame(WebSocketFrame::OpCode opCode, Blob& blob) |
| 708 |
{ |
706 |
{ |
| 709 |
ASSERT(m_outgoingFrameQueueStatus == OutgoingFrameQueueOpen); |
707 |
ASSERT(m_outgoingFrameQueueStatus == OutgoingFrameQueueOpen); |
| 710 |
OwnPtr<QueuedFrame> frame = adoptPtr(new QueuedFrame); |
708 |
auto frame = std::make_unique<QueuedFrame>(); |
| 711 |
frame->opCode = opCode; |
709 |
frame->opCode = opCode; |
| 712 |
frame->frameType = QueuedFrameTypeBlob; |
710 |
frame->frameType = QueuedFrameTypeBlob; |
| 713 |
frame->blobData = &blob; |
711 |
frame->blobData = &blob; |
|
Lines 722-728
void WebSocketChannel::processOutgoingFrameQueue()
a/Source/WebCore/Modules/websockets/WebSocketChannel.cpp_sec8
|
| 722 |
Ref<WebSocketChannel> protect(*this); // Any call to fail() will get the channel closed and dereferenced. |
720 |
Ref<WebSocketChannel> protect(*this); // Any call to fail() will get the channel closed and dereferenced. |
| 723 |
|
721 |
|
| 724 |
while (!m_outgoingFrameQueue.isEmpty()) { |
722 |
while (!m_outgoingFrameQueue.isEmpty()) { |
| 725 |
OwnPtr<QueuedFrame> frame = m_outgoingFrameQueue.takeFirst(); |
723 |
auto frame = m_outgoingFrameQueue.takeFirst(); |
| 726 |
switch (frame->frameType) { |
724 |
switch (frame->frameType) { |
| 727 |
case QueuedFrameTypeString: { |
725 |
case QueuedFrameTypeString: { |
| 728 |
if (!sendFrame(frame->opCode, frame->stringData.data(), frame->stringData.length())) |
726 |
if (!sendFrame(frame->opCode, frame->stringData.data(), frame->stringData.length())) |
|
Lines 740-746
void WebSocketChannel::processOutgoingFrameQueue()
a/Source/WebCore/Modules/websockets/WebSocketChannel.cpp_sec9
|
| 740 |
case BlobLoaderNotStarted: |
738 |
case BlobLoaderNotStarted: |
| 741 |
ref(); // Will be derefed after didFinishLoading() or didFail(). |
739 |
ref(); // Will be derefed after didFinishLoading() or didFail(). |
| 742 |
ASSERT(!m_blobLoader); |
740 |
ASSERT(!m_blobLoader); |
| 743 |
m_blobLoader = adoptPtr(new FileReaderLoader(FileReaderLoader::ReadAsArrayBuffer, this)); |
741 |
m_blobLoader = std::make_unique<FileReaderLoader>(FileReaderLoader::ReadAsArrayBuffer, this); |
| 744 |
m_blobLoaderStatus = BlobLoaderStarted; |
742 |
m_blobLoaderStatus = BlobLoaderStarted; |
| 745 |
m_blobLoader->start(m_document, frame->blobData.get()); |
743 |
m_blobLoader->start(m_document, frame->blobData.get()); |
| 746 |
m_outgoingFrameQueue.prepend(frame.release()); |
744 |
m_outgoingFrameQueue.prepend(frame.release()); |
|
Lines 753-759
void WebSocketChannel::processOutgoingFrameQueue()
a/Source/WebCore/Modules/websockets/WebSocketChannel.cpp_sec10
|
| 753 |
|
751 |
|
| 754 |
case BlobLoaderFinished: { |
752 |
case BlobLoaderFinished: { |
| 755 |
RefPtr<ArrayBuffer> result = m_blobLoader->arrayBufferResult(); |
753 |
RefPtr<ArrayBuffer> result = m_blobLoader->arrayBufferResult(); |
| 756 |
m_blobLoader.clear(); |
754 |
m_blobLoader = nullptr; |
| 757 |
m_blobLoaderStatus = BlobLoaderNotStarted; |
755 |
m_blobLoaderStatus = BlobLoaderNotStarted; |
| 758 |
if (!sendFrame(frame->opCode, static_cast<const char*>(result->data()), result->byteLength())) |
756 |
if (!sendFrame(frame->opCode, static_cast<const char*>(result->data()), result->byteLength())) |
| 759 |
fail("Failed to send WebSocket frame."); |
757 |
fail("Failed to send WebSocket frame."); |
|
Lines 794-800
bool WebSocketChannel::sendFrame(WebSocketFrame::OpCode opCode, const char* data
a/Source/WebCore/Modules/websockets/WebSocketChannel.cpp_sec11
|
| 794 |
WebSocketFrame frame(opCode, true, false, true, data, dataLength); |
792 |
WebSocketFrame frame(opCode, true, false, true, data, dataLength); |
| 795 |
InspectorInstrumentation::didSendWebSocketFrame(m_document, m_identifier, frame); |
793 |
InspectorInstrumentation::didSendWebSocketFrame(m_document, m_identifier, frame); |
| 796 |
|
794 |
|
| 797 |
OwnPtr<DeflateResultHolder> deflateResult = m_deflateFramer.deflate(frame); |
795 |
auto deflateResult = m_deflateFramer.deflate(frame); |
| 798 |
if (!deflateResult->succeeded()) { |
796 |
if (!deflateResult->succeeded()) { |
| 799 |
fail(deflateResult->failureReason()); |
797 |
fail(deflateResult->failureReason()); |
| 800 |
return false; |
798 |
return false; |