| 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 | 152 |
| 153 ThreadableWebSocketChannel::SendResult WebSocketChannel::send(const ArrayBuffer&
binaryData, unsigned byteOffset, unsigned byteLength) | 153 ThreadableWebSocketChannel::SendResult WebSocketChannel::send(const ArrayBuffer&
binaryData, unsigned byteOffset, unsigned byteLength) |
| 154 { | 154 { |
| 155 LOG(Network, "WebSocketChannel %p send arraybuffer %p %u %u", this, &binaryD
ata, byteOffset, byteLength); | 155 LOG(Network, "WebSocketChannel %p send arraybuffer %p %u %u", this, &binaryD
ata, byteOffset, byteLength); |
| 156 enqueueRawFrame(WebSocketFrame::OpCodeBinary, static_cast<const char*>(binar
yData.data()) + byteOffset, byteLength); | 156 enqueueRawFrame(WebSocketFrame::OpCodeBinary, static_cast<const char*>(binar
yData.data()) + byteOffset, byteLength); |
| 157 return ThreadableWebSocketChannel::SendSuccess; | 157 return ThreadableWebSocketChannel::SendSuccess; |
| 158 } | 158 } |
| 159 | 159 |
| 160 ThreadableWebSocketChannel::SendResult WebSocketChannel::send(const Blob& binary
Data) | 160 ThreadableWebSocketChannel::SendResult WebSocketChannel::send(const Blob& binary
Data) |
| 161 { | 161 { |
| 162 LOG(Network, "WebSocketChannel %p send blob %s", this, binaryData.url().stri
ng().utf8().data()); | 162 LOG(Network, "WebSocketChannel %p send blob %s", this, binaryData.uuid().utf
8().data()); |
| 163 enqueueBlobFrame(WebSocketFrame::OpCodeBinary, binaryData); | 163 enqueueBlobFrame(WebSocketFrame::OpCodeBinary, binaryData); |
| 164 return ThreadableWebSocketChannel::SendSuccess; | 164 return ThreadableWebSocketChannel::SendSuccess; |
| 165 } | 165 } |
| 166 | 166 |
| 167 bool WebSocketChannel::send(const char* data, int length) | 167 bool WebSocketChannel::send(const char* data, int length) |
| 168 { | 168 { |
| 169 LOG(Network, "WebSocketChannel %p send binary %p (%dB)", this, data, length)
; | 169 LOG(Network, "WebSocketChannel %p send binary %p (%dB)", this, data, length)
; |
| 170 enqueueRawFrame(WebSocketFrame::OpCodeBinary, data, length); | 170 enqueueRawFrame(WebSocketFrame::OpCodeBinary, data, length); |
| 171 return true; | 171 return true; |
| 172 } | 172 } |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 m_outgoingFrameQueue.append(frame.release()); | 702 m_outgoingFrameQueue.append(frame.release()); |
| 703 processOutgoingFrameQueue(); | 703 processOutgoingFrameQueue(); |
| 704 } | 704 } |
| 705 | 705 |
| 706 void WebSocketChannel::enqueueBlobFrame(WebSocketFrame::OpCode opCode, const Blo
b& blob) | 706 void WebSocketChannel::enqueueBlobFrame(WebSocketFrame::OpCode opCode, const Blo
b& blob) |
| 707 { | 707 { |
| 708 ASSERT(m_outgoingFrameQueueStatus == OutgoingFrameQueueOpen); | 708 ASSERT(m_outgoingFrameQueueStatus == OutgoingFrameQueueOpen); |
| 709 OwnPtr<QueuedFrame> frame = adoptPtr(new QueuedFrame); | 709 OwnPtr<QueuedFrame> frame = adoptPtr(new QueuedFrame); |
| 710 frame->opCode = opCode; | 710 frame->opCode = opCode; |
| 711 frame->frameType = QueuedFrameTypeBlob; | 711 frame->frameType = QueuedFrameTypeBlob; |
| 712 frame->blobData = Blob::create(blob.url(), blob.type(), blob.size()); | 712 frame->blobData = Blob::create(BlobDataHandle::create(blob.uuid(), blob.type
(), blob.size())); |
| 713 m_outgoingFrameQueue.append(frame.release()); | 713 m_outgoingFrameQueue.append(frame.release()); |
| 714 processOutgoingFrameQueue(); | 714 processOutgoingFrameQueue(); |
| 715 } | 715 } |
| 716 | 716 |
| 717 void WebSocketChannel::processOutgoingFrameQueue() | 717 void WebSocketChannel::processOutgoingFrameQueue() |
| 718 { | 718 { |
| 719 if (m_outgoingFrameQueueStatus == OutgoingFrameQueueClosed) | 719 if (m_outgoingFrameQueueStatus == OutgoingFrameQueueClosed) |
| 720 return; | 720 return; |
| 721 | 721 |
| 722 while (!m_outgoingFrameQueue.isEmpty()) { | 722 while (!m_outgoingFrameQueue.isEmpty()) { |
| 723 OwnPtr<QueuedFrame> frame = m_outgoingFrameQueue.takeFirst(); | 723 OwnPtr<QueuedFrame> frame = m_outgoingFrameQueue.takeFirst(); |
| 724 switch (frame->frameType) { | 724 switch (frame->frameType) { |
| 725 case QueuedFrameTypeString: { | 725 case QueuedFrameTypeString: { |
| 726 if (!sendFrame(frame->opCode, frame->stringData.data(), frame->strin
gData.length())) | 726 if (!sendFrame(frame->opCode, frame->stringData.data(), frame->strin
gData.length())) |
| 727 fail("Failed to send WebSocket frame."); | 727 fail("Failed to send WebSocket frame."); |
| 728 break; | 728 break; |
| 729 } | 729 } |
| 730 | 730 |
| 731 case QueuedFrameTypeVector: | 731 case QueuedFrameTypeVector: |
| 732 if (!sendFrame(frame->opCode, frame->vectorData.data(), frame->vecto
rData.size())) | 732 if (!sendFrame(frame->opCode, frame->vectorData.data(), frame->vecto
rData.size())) |
| 733 fail("Failed to send WebSocket frame."); | 733 fail("Failed to send WebSocket frame."); |
| 734 break; | 734 break; |
| 735 | 735 |
| 736 case QueuedFrameTypeBlob: { | 736 case QueuedFrameTypeBlob: { |
| 737 #if ENABLE(BLOB) | 737 #if ENABLE(BLOB) |
| 738 // FIXME: Read and write incrementally. This may be a large amount o
f data. Too large |
| 739 // to reasonably load into an array buffer. |
| 738 switch (m_blobLoaderStatus) { | 740 switch (m_blobLoaderStatus) { |
| 739 case BlobLoaderNotStarted: | 741 case BlobLoaderNotStarted: |
| 740 ref(); // Will be derefed after didFinishLoading() or didFail(). | 742 ref(); // Will be derefed after didFinishLoading() or didFail(). |
| 741 ASSERT(!m_blobLoader); | 743 ASSERT(!m_blobLoader); |
| 742 m_blobLoader = adoptPtr(new FileReaderLoader(FileReaderLoader::R
eadAsArrayBuffer, this)); | 744 m_blobLoader = adoptPtr(new FileReaderLoader(FileReaderLoader::R
eadAsArrayBuffer, this)); |
| 743 m_blobLoaderStatus = BlobLoaderStarted; | 745 m_blobLoaderStatus = BlobLoaderStarted; |
| 744 m_blobLoader->start(m_document, frame->blobData.get()); | 746 m_blobLoader->start(m_document, frame->blobData.get()); |
| 745 m_outgoingFrameQueue.prepend(frame.release()); | 747 m_outgoingFrameQueue.prepend(frame.release()); |
| 746 return; | 748 return; |
| 747 | 749 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 | 808 |
| 807 Vector<char> frameData; | 809 Vector<char> frameData; |
| 808 frame.makeFrameData(frameData); | 810 frame.makeFrameData(frameData); |
| 809 | 811 |
| 810 return m_handle->send(frameData.data(), frameData.size()); | 812 return m_handle->send(frameData.data(), frameData.size()); |
| 811 } | 813 } |
| 812 | 814 |
| 813 } // namespace WebCore | 815 } // namespace WebCore |
| 814 | 816 |
| 815 #endif // ENABLE(WEB_SOCKETS) | 817 #endif // ENABLE(WEB_SOCKETS) |
| OLD | NEW |