Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Side by Side Diff: WebCore/Modules/websockets/WebSocketChannel.cpp

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

Powered by Google App Engine
This is Rietveld 408576698