OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2011, 2012 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 } | 153 } |
154 | 154 |
155 WebSocketChannel::SendResult MainThreadWebSocketChannel::send(const ArrayBuffer&
binaryData, unsigned byteOffset, unsigned byteLength) | 155 WebSocketChannel::SendResult MainThreadWebSocketChannel::send(const ArrayBuffer&
binaryData, unsigned byteOffset, unsigned byteLength) |
156 { | 156 { |
157 LOG(Network, "MainThreadWebSocketChannel %p send() Sending ArrayBuffer %p by
teOffset=%u byteLength=%u", this, &binaryData, byteOffset, byteLength); | 157 LOG(Network, "MainThreadWebSocketChannel %p send() Sending ArrayBuffer %p by
teOffset=%u byteLength=%u", this, &binaryData, byteOffset, byteLength); |
158 enqueueRawFrame(WebSocketFrame::OpCodeBinary, static_cast<const char*>(binar
yData.data()) + byteOffset, byteLength); | 158 enqueueRawFrame(WebSocketFrame::OpCodeBinary, static_cast<const char*>(binar
yData.data()) + byteOffset, byteLength); |
159 processOutgoingFrameQueue(); | 159 processOutgoingFrameQueue(); |
160 return WebSocketChannel::SendSuccess; | 160 return WebSocketChannel::SendSuccess; |
161 } | 161 } |
162 | 162 |
163 WebSocketChannel::SendResult MainThreadWebSocketChannel::send(const Blob& binary
Data) | 163 WebSocketChannel::SendResult MainThreadWebSocketChannel::send(PassRefPtr<BlobDat
aHandle> binaryData) |
164 { | 164 { |
165 LOG(Network, "MainThreadWebSocketChannel %p send() Sending Blob '%s'", this,
binaryData.url().elidedString().utf8().data()); | 165 LOG(Network, "MainThreadWebSocketChannel %p send() Sending Blob '%s'", this,
binaryData->uuid().utf8().data()); |
166 enqueueBlobFrame(WebSocketFrame::OpCodeBinary, binaryData); | 166 enqueueBlobFrame(WebSocketFrame::OpCodeBinary, binaryData); |
167 processOutgoingFrameQueue(); | 167 processOutgoingFrameQueue(); |
168 return WebSocketChannel::SendSuccess; | 168 return WebSocketChannel::SendSuccess; |
169 } | 169 } |
170 | 170 |
171 bool MainThreadWebSocketChannel::send(const char* data, int length) | 171 bool MainThreadWebSocketChannel::send(const char* data, int length) |
172 { | 172 { |
173 LOG(Network, "MainThreadWebSocketChannel %p send() Sending char* data=%p len
gth=%d", this, data, length); | 173 LOG(Network, "MainThreadWebSocketChannel %p send() Sending char* data=%p len
gth=%d", this, data, length); |
174 enqueueRawFrame(WebSocketFrame::OpCodeBinary, data, length); | 174 enqueueRawFrame(WebSocketFrame::OpCodeBinary, data, length); |
175 processOutgoingFrameQueue(); | 175 processOutgoingFrameQueue(); |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 ASSERT(m_outgoingFrameQueueStatus == OutgoingFrameQueueOpen); | 701 ASSERT(m_outgoingFrameQueueStatus == OutgoingFrameQueueOpen); |
702 OwnPtr<QueuedFrame> frame = adoptPtr(new QueuedFrame); | 702 OwnPtr<QueuedFrame> frame = adoptPtr(new QueuedFrame); |
703 frame->opCode = opCode; | 703 frame->opCode = opCode; |
704 frame->frameType = QueuedFrameTypeVector; | 704 frame->frameType = QueuedFrameTypeVector; |
705 frame->vectorData.resize(dataLength); | 705 frame->vectorData.resize(dataLength); |
706 if (dataLength) | 706 if (dataLength) |
707 memcpy(frame->vectorData.data(), data, dataLength); | 707 memcpy(frame->vectorData.data(), data, dataLength); |
708 m_outgoingFrameQueue.append(frame.release()); | 708 m_outgoingFrameQueue.append(frame.release()); |
709 } | 709 } |
710 | 710 |
711 void MainThreadWebSocketChannel::enqueueBlobFrame(WebSocketFrame::OpCode opCode,
const Blob& blob) | 711 void MainThreadWebSocketChannel::enqueueBlobFrame(WebSocketFrame::OpCode opCode,
PassRefPtr<BlobDataHandle> blobData) |
712 { | 712 { |
713 ASSERT(m_outgoingFrameQueueStatus == OutgoingFrameQueueOpen); | 713 ASSERT(m_outgoingFrameQueueStatus == OutgoingFrameQueueOpen); |
714 OwnPtr<QueuedFrame> frame = adoptPtr(new QueuedFrame); | 714 OwnPtr<QueuedFrame> frame = adoptPtr(new QueuedFrame); |
715 frame->opCode = opCode; | 715 frame->opCode = opCode; |
716 frame->frameType = QueuedFrameTypeBlob; | 716 frame->frameType = QueuedFrameTypeBlob; |
717 frame->blobData = Blob::create(blob.url(), blob.type(), blob.size()); | 717 frame->blobData = blobData; |
718 m_outgoingFrameQueue.append(frame.release()); | 718 m_outgoingFrameQueue.append(frame.release()); |
719 } | 719 } |
720 | 720 |
721 void MainThreadWebSocketChannel::processOutgoingFrameQueue() | 721 void MainThreadWebSocketChannel::processOutgoingFrameQueue() |
722 { | 722 { |
723 if (m_outgoingFrameQueueStatus == OutgoingFrameQueueClosed) | 723 if (m_outgoingFrameQueueStatus == OutgoingFrameQueueClosed) |
724 return; | 724 return; |
725 | 725 |
726 while (!m_outgoingFrameQueue.isEmpty()) { | 726 while (!m_outgoingFrameQueue.isEmpty()) { |
727 OwnPtr<QueuedFrame> frame = m_outgoingFrameQueue.takeFirst(); | 727 OwnPtr<QueuedFrame> frame = m_outgoingFrameQueue.takeFirst(); |
728 switch (frame->frameType) { | 728 switch (frame->frameType) { |
729 case QueuedFrameTypeString: { | 729 case QueuedFrameTypeString: { |
730 if (!sendFrame(frame->opCode, frame->stringData.data(), frame->strin
gData.length())) | 730 if (!sendFrame(frame->opCode, frame->stringData.data(), frame->strin
gData.length())) |
731 failAsError("Failed to send WebSocket frame."); | 731 failAsError("Failed to send WebSocket frame."); |
732 break; | 732 break; |
733 } | 733 } |
734 | 734 |
735 case QueuedFrameTypeVector: | 735 case QueuedFrameTypeVector: |
736 if (!sendFrame(frame->opCode, frame->vectorData.data(), frame->vecto
rData.size())) | 736 if (!sendFrame(frame->opCode, frame->vectorData.data(), frame->vecto
rData.size())) |
737 failAsError("Failed to send WebSocket frame."); | 737 failAsError("Failed to send WebSocket frame."); |
738 break; | 738 break; |
739 | 739 |
740 case QueuedFrameTypeBlob: { | 740 case QueuedFrameTypeBlob: { |
741 switch (m_blobLoaderStatus) { | 741 switch (m_blobLoaderStatus) { |
742 case BlobLoaderNotStarted: | 742 case BlobLoaderNotStarted: |
743 ref(); // Will be derefed after didFinishLoading() or didFail(). | 743 ref(); // Will be derefed after didFinishLoading() or didFail(). |
744 ASSERT(!m_blobLoader); | 744 ASSERT(!m_blobLoader); |
745 m_blobLoader = adoptPtr(new FileReaderLoader(FileReaderLoader::R
eadAsArrayBuffer, this)); | 745 m_blobLoader = adoptPtr(new FileReaderLoader(FileReaderLoader::R
eadAsArrayBuffer, this)); |
746 m_blobLoaderStatus = BlobLoaderStarted; | 746 m_blobLoaderStatus = BlobLoaderStarted; |
747 m_blobLoader->start(m_document, *frame->blobData); | 747 m_blobLoader->start(m_document, frame->blobData); |
748 m_outgoingFrameQueue.prepend(frame.release()); | 748 m_outgoingFrameQueue.prepend(frame.release()); |
749 return; | 749 return; |
750 | 750 |
751 case BlobLoaderStarted: | 751 case BlobLoaderStarted: |
752 case BlobLoaderFailed: | 752 case BlobLoaderFailed: |
753 m_outgoingFrameQueue.prepend(frame.release()); | 753 m_outgoingFrameQueue.prepend(frame.release()); |
754 return; | 754 return; |
755 | 755 |
756 case BlobLoaderFinished: { | 756 case BlobLoaderFinished: { |
757 RefPtr<ArrayBuffer> result = m_blobLoader->arrayBufferResult(); | 757 RefPtr<ArrayBuffer> result = m_blobLoader->arrayBufferResult(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 } | 808 } |
809 | 809 |
810 Vector<char> frameData; | 810 Vector<char> frameData; |
811 frame.makeFrameData(frameData); | 811 frame.makeFrameData(frameData); |
812 | 812 |
813 m_perMessageDeflate.resetDeflateBuffer(); | 813 m_perMessageDeflate.resetDeflateBuffer(); |
814 return m_handle->send(frameData.data(), frameData.size()); | 814 return m_handle->send(frameData.data(), frameData.size()); |
815 } | 815 } |
816 | 816 |
817 } // namespace WebCore | 817 } // namespace WebCore |
OLD | NEW |