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

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 7 years, 11 months 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 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 m_outgoingFrameQueue.append(frame.release()); 697 m_outgoingFrameQueue.append(frame.release());
698 processOutgoingFrameQueue(); 698 processOutgoingFrameQueue();
699 } 699 }
700 700
701 void WebSocketChannel::enqueueBlobFrame(WebSocketFrame::OpCode opCode, const Blo b& blob) 701 void WebSocketChannel::enqueueBlobFrame(WebSocketFrame::OpCode opCode, const Blo b& blob)
702 { 702 {
703 ASSERT(m_outgoingFrameQueueStatus == OutgoingFrameQueueOpen); 703 ASSERT(m_outgoingFrameQueueStatus == OutgoingFrameQueueOpen);
704 OwnPtr<QueuedFrame> frame = adoptPtr(new QueuedFrame); 704 OwnPtr<QueuedFrame> frame = adoptPtr(new QueuedFrame);
705 frame->opCode = opCode; 705 frame->opCode = opCode;
706 frame->frameType = QueuedFrameTypeBlob; 706 frame->frameType = QueuedFrameTypeBlob;
707 frame->blobData = Blob::create(blob.url(), blob.type(), blob.size()); 707 frame->blobData = Blob::create(blob.blobDataHandle());
708 m_outgoingFrameQueue.append(frame.release()); 708 m_outgoingFrameQueue.append(frame.release());
709 processOutgoingFrameQueue(); 709 processOutgoingFrameQueue();
710 } 710 }
711 711
712 void WebSocketChannel::processOutgoingFrameQueue() 712 void WebSocketChannel::processOutgoingFrameQueue()
713 { 713 {
714 if (m_outgoingFrameQueueStatus == OutgoingFrameQueueClosed) 714 if (m_outgoingFrameQueueStatus == OutgoingFrameQueueClosed)
715 return; 715 return;
716 716
717 while (!m_outgoingFrameQueue.isEmpty()) { 717 while (!m_outgoingFrameQueue.isEmpty()) {
718 OwnPtr<QueuedFrame> frame = m_outgoingFrameQueue.takeFirst(); 718 OwnPtr<QueuedFrame> frame = m_outgoingFrameQueue.takeFirst();
719 switch (frame->frameType) { 719 switch (frame->frameType) {
720 case QueuedFrameTypeString: { 720 case QueuedFrameTypeString: {
721 if (!sendFrame(frame->opCode, frame->stringData.data(), frame->strin gData.length())) 721 if (!sendFrame(frame->opCode, frame->stringData.data(), frame->strin gData.length()))
722 fail("Failed to send WebSocket frame."); 722 fail("Failed to send WebSocket frame.");
723 break; 723 break;
724 } 724 }
725 725
726 case QueuedFrameTypeVector: 726 case QueuedFrameTypeVector:
727 if (!sendFrame(frame->opCode, frame->vectorData.data(), frame->vecto rData.size())) 727 if (!sendFrame(frame->opCode, frame->vectorData.data(), frame->vecto rData.size()))
728 fail("Failed to send WebSocket frame."); 728 fail("Failed to send WebSocket frame.");
729 break; 729 break;
730 730
731 case QueuedFrameTypeBlob: { 731 case QueuedFrameTypeBlob: {
732 #if ENABLE(BLOB) 732 #if ENABLE(BLOB)
733 // FIXME: Read and write incrementally. This may be a large amount o f data, too large
734 // to reasonably load into an array buffer.
733 switch (m_blobLoaderStatus) { 735 switch (m_blobLoaderStatus) {
734 case BlobLoaderNotStarted: 736 case BlobLoaderNotStarted:
735 ref(); // Will be derefed after didFinishLoading() or didFail(). 737 ref(); // Will be derefed after didFinishLoading() or didFail().
736 ASSERT(!m_blobLoader); 738 ASSERT(!m_blobLoader);
737 m_blobLoader = adoptPtr(new FileReaderLoader(FileReaderLoader::R eadAsArrayBuffer, this)); 739 m_blobLoader = adoptPtr(new FileReaderLoader(FileReaderLoader::R eadAsArrayBuffer, this));
738 m_blobLoaderStatus = BlobLoaderStarted; 740 m_blobLoaderStatus = BlobLoaderStarted;
739 m_blobLoader->start(m_document, frame->blobData.get()); 741 m_blobLoader->start(m_document, frame->blobData.get());
740 m_outgoingFrameQueue.prepend(frame.release()); 742 m_outgoingFrameQueue.prepend(frame.release());
741 return; 743 return;
742 744
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 803
802 Vector<char> frameData; 804 Vector<char> frameData;
803 frame.makeFrameData(frameData); 805 frame.makeFrameData(frameData);
804 806
805 return m_handle->send(frameData.data(), frameData.size()); 807 return m_handle->send(frameData.data(), frameData.size());
806 } 808 }
807 809
808 } // namespace WebCore 810 } // namespace WebCore
809 811
810 #endif // ENABLE(WEB_SOCKETS) 812 #endif // ENABLE(WEB_SOCKETS)
OLDNEW
« no previous file with comments | « WebCore/Modules/websockets/WebSocket.cpp ('k') | WebCore/Modules/websockets/WorkerThreadableWebSocketChannel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698