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

Side by Side Diff: third_party/WebKit/Source/modules/websockets/DOMWebSocket.cpp

Issue 1666893003: [ABANDONED] WebSocket Blob receive in the browser process: renderer changes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@websocket_blob_receive_host_merged
Patch Set: Created 4 years, 10 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 Google Inc. All rights reserved. 2 * Copyright (C) 2011 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 23 matching lines...) Expand all
34 #include "bindings/core/v8/ScriptController.h" 34 #include "bindings/core/v8/ScriptController.h"
35 #include "bindings/modules/v8/UnionTypesModules.h" 35 #include "bindings/modules/v8/UnionTypesModules.h"
36 #include "core/dom/DOMArrayBuffer.h" 36 #include "core/dom/DOMArrayBuffer.h"
37 #include "core/dom/DOMArrayBufferView.h" 37 #include "core/dom/DOMArrayBufferView.h"
38 #include "core/dom/Document.h" 38 #include "core/dom/Document.h"
39 #include "core/dom/ExceptionCode.h" 39 #include "core/dom/ExceptionCode.h"
40 #include "core/dom/ExecutionContext.h" 40 #include "core/dom/ExecutionContext.h"
41 #include "core/dom/SecurityContext.h" 41 #include "core/dom/SecurityContext.h"
42 #include "core/events/MessageEvent.h" 42 #include "core/events/MessageEvent.h"
43 #include "core/fileapi/Blob.h" 43 #include "core/fileapi/Blob.h"
44 #include "core/fileapi/FileReaderLoader.h"
44 #include "core/frame/ConsoleTypes.h" 45 #include "core/frame/ConsoleTypes.h"
45 #include "core/frame/LocalDOMWindow.h" 46 #include "core/frame/LocalDOMWindow.h"
46 #include "core/frame/LocalFrame.h" 47 #include "core/frame/LocalFrame.h"
47 #include "core/frame/UseCounter.h" 48 #include "core/frame/UseCounter.h"
48 #include "core/frame/csp/ContentSecurityPolicy.h" 49 #include "core/frame/csp/ContentSecurityPolicy.h"
49 #include "core/inspector/ConsoleMessage.h" 50 #include "core/inspector/ConsoleMessage.h"
50 #include "core/inspector/ScriptCallStack.h" 51 #include "core/inspector/ScriptCallStack.h"
51 #include "modules/websockets/CloseEvent.h" 52 #include "modules/websockets/CloseEvent.h"
52 #include "platform/Logging.h" 53 #include "platform/Logging.h"
53 #include "platform/blob/BlobData.h" 54 #include "platform/blob/BlobData.h"
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 switch (m_binaryType) { 546 switch (m_binaryType) {
546 case BinaryTypeBlob: 547 case BinaryTypeBlob:
547 return "blob"; 548 return "blob";
548 case BinaryTypeArrayBuffer: 549 case BinaryTypeArrayBuffer:
549 return "arraybuffer"; 550 return "arraybuffer";
550 } 551 }
551 ASSERT_NOT_REACHED(); 552 ASSERT_NOT_REACHED();
552 return String(); 553 return String();
553 } 554 }
554 555
556 // static
557 WebSocketChannel::BinaryType DOMWebSocket::toChannelBinaryType(BinaryType binary Type)
558 {
559 static_assert(static_cast<WebSocketChannel::BinaryType>(BinaryTypeBlob) == W ebSocketChannel::BinaryTypeBlob, "enums must match");
560 static_assert(static_cast<WebSocketChannel::BinaryType>(BinaryTypeArrayBuffe r) == WebSocketChannel::BinaryTypeArrayBuffer, "enums must match");
561 ASSERT(binaryType == BinaryTypeBlob || binaryType == BinaryTypeArrayBuffer);
562 return static_cast<WebSocketChannel::BinaryType>(binaryType);
563 }
564
555 void DOMWebSocket::setBinaryType(const String& binaryType) 565 void DOMWebSocket::setBinaryType(const String& binaryType)
556 { 566 {
557 if (binaryType == "blob") { 567 if (binaryType == "blob") {
558 m_binaryType = BinaryTypeBlob; 568 if (m_binaryType != BinaryTypeBlob) {
569 m_binaryType = BinaryTypeBlob;
570 if (m_channel)
571 m_channel->changeBinaryType(toChannelBinaryType(m_binaryType));
572 }
559 return; 573 return;
560 } 574 }
561 if (binaryType == "arraybuffer") { 575 if (binaryType == "arraybuffer") {
562 m_binaryType = BinaryTypeArrayBuffer; 576 if (m_binaryType != BinaryTypeArrayBuffer) {
577 m_binaryType = BinaryTypeArrayBuffer;
578 if (m_channel)
579 m_channel->changeBinaryType(toChannelBinaryType(m_binaryType));
580 }
563 return; 581 return;
564 } 582 }
565 ASSERT_NOT_REACHED(); 583 ASSERT_NOT_REACHED();
566 } 584 }
567 585
568 const AtomicString& DOMWebSocket::interfaceName() const 586 const AtomicString& DOMWebSocket::interfaceName() const
569 { 587 {
570 return EventTargetNames::DOMWebSocket; 588 return EventTargetNames::DOMWebSocket;
571 } 589 }
572 590
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 639
622 void DOMWebSocket::didReceiveTextMessage(const String& msg) 640 void DOMWebSocket::didReceiveTextMessage(const String& msg)
623 { 641 {
624 WTF_LOG(Network, "WebSocket %p didReceiveTextMessage() Text message '%s'", t his, msg.utf8().data()); 642 WTF_LOG(Network, "WebSocket %p didReceiveTextMessage() Text message '%s'", t his, msg.utf8().data());
625 if (m_state != OPEN) 643 if (m_state != OPEN)
626 return; 644 return;
627 Platform::current()->histogramEnumeration("WebCore.WebSocket.ReceiveType", W ebSocketReceiveTypeString, WebSocketReceiveTypeMax); 645 Platform::current()->histogramEnumeration("WebCore.WebSocket.ReceiveType", W ebSocketReceiveTypeString, WebSocketReceiveTypeMax);
628 m_eventQueue->dispatch(MessageEvent::create(msg, SecurityOrigin::create(m_ur l)->toString())); 646 m_eventQueue->dispatch(MessageEvent::create(msg, SecurityOrigin::create(m_ur l)->toString()));
629 } 647 }
630 648
631 void DOMWebSocket::didReceiveBinaryMessage(PassOwnPtr<Vector<char>> binaryData) 649 void DOMWebSocket::didReceiveArrayBuffer(PassOwnPtr<Vector<char>> binaryData)
632 { 650 {
633 WTF_LOG(Network, "WebSocket %p didReceiveBinaryMessage() %lu byte binary mes sage", this, static_cast<unsigned long>(binaryData->size())); 651 WTF_LOG(Network, "WebSocket %p didReceiveArrayBuffer() %lu byte binary messa ge", this, static_cast<unsigned long>(binaryData->size()));
634 switch (m_binaryType) { 652 switch (m_binaryType) {
635 case BinaryTypeBlob: { 653 case BinaryTypeBlob: {
636 size_t size = binaryData->size(); 654 size_t size = binaryData->size();
637 RefPtr<RawData> rawData = RawData::create(); 655 RefPtr<RawData> rawData = RawData::create();
638 binaryData->swap(*rawData->mutableData()); 656 binaryData->swap(*rawData->mutableData());
639 OwnPtr<BlobData> blobData = BlobData::create(); 657 OwnPtr<BlobData> blobData = BlobData::create();
640 blobData->appendData(rawData.release(), 0, BlobDataItem::toEndOfFile); 658 blobData->appendData(rawData.release(), 0, BlobDataItem::toEndOfFile);
641 Blob* blob = Blob::create(BlobDataHandle::create(blobData.release(), siz e)); 659 Blob* blob = Blob::create(BlobDataHandle::create(blobData.release(), siz e));
642 Platform::current()->histogramEnumeration("WebCore.WebSocket.ReceiveType ", WebSocketReceiveTypeBlob, WebSocketReceiveTypeMax); 660 Platform::current()->histogramEnumeration("WebCore.WebSocket.ReceiveType ", WebSocketReceiveTypeBlob, WebSocketReceiveTypeMax);
643 m_eventQueue->dispatch(MessageEvent::create(blob, SecurityOrigin::create (m_url)->toString())); 661 m_eventQueue->dispatch(MessageEvent::create(blob, SecurityOrigin::create (m_url)->toString()));
644 break; 662 break;
645 } 663 }
646 664
647 case BinaryTypeArrayBuffer: 665 case BinaryTypeArrayBuffer:
648 RefPtr<DOMArrayBuffer> arrayBuffer = DOMArrayBuffer::create(binaryData-> data(), binaryData->size()); 666 RefPtr<DOMArrayBuffer> arrayBuffer = DOMArrayBuffer::create(binaryData-> data(), binaryData->size());
649 Platform::current()->histogramEnumeration("WebCore.WebSocket.ReceiveType ", WebSocketReceiveTypeArrayBuffer, WebSocketReceiveTypeMax); 667 Platform::current()->histogramEnumeration("WebCore.WebSocket.ReceiveType ", WebSocketReceiveTypeArrayBuffer, WebSocketReceiveTypeMax);
650 m_eventQueue->dispatch(MessageEvent::create(arrayBuffer.release(), Secur ityOrigin::create(m_url)->toString())); 668 m_eventQueue->dispatch(MessageEvent::create(arrayBuffer.release(), Secur ityOrigin::create(m_url)->toString()));
651 break; 669 break;
652 } 670 }
653 } 671 }
654 672
673 void DOMWebSocket::didReceiveBlob(PassRefPtr<BlobDataHandle> blobDataHandle)
674 {
675 WTF_LOG(Network, "WebSocket %p didReceiveBlob() %llu byte binary message", t his, blobDataHandle->size());
676 switch (m_binaryType) {
677 case BinaryTypeBlob: {
678 Blob* blob = Blob::create(blobDataHandle);
679 Platform::current()->histogramEnumeration("WebCore.WebSocket.ReceiveType ", WebSocketReceiveTypeBlob, WebSocketReceiveTypeMax);
680 m_eventQueue->dispatch(MessageEvent::create(blob, SecurityOrigin::create (m_url)->toString()));
681 break;
682 }
683
684 case BinaryTypeArrayBuffer: {
685 // FIXME: Make this async.
686 FileReaderLoader fileReaderLoader(FileReaderLoader::ReadAsArrayBuffer, n ullptr);
687 fileReaderLoader.start(executionContext(), blobDataHandle);
688 RefPtr<DOMArrayBuffer> arrayBuffer = fileReaderLoader.arrayBufferResult( );
689 Platform::current()->histogramEnumeration("WebCore.WebSocket.ReceiveType ", WebSocketReceiveTypeArrayBuffer, WebSocketReceiveTypeMax);
690 m_eventQueue->dispatch(MessageEvent::create(arrayBuffer.release(), Secur ityOrigin::create(m_url)->toString()));
691 break;
692 }
693 }
694 }
695
655 void DOMWebSocket::didError() 696 void DOMWebSocket::didError()
656 { 697 {
657 WTF_LOG(Network, "WebSocket %p didError()", this); 698 WTF_LOG(Network, "WebSocket %p didError()", this);
658 m_state = CLOSED; 699 m_state = CLOSED;
659 m_eventQueue->dispatch(Event::create(EventTypeNames::error)); 700 m_eventQueue->dispatch(Event::create(EventTypeNames::error));
660 } 701 }
661 702
662 void DOMWebSocket::didConsumeBufferedAmount(uint64_t consumed) 703 void DOMWebSocket::didConsumeBufferedAmount(uint64_t consumed)
663 { 704 {
664 ASSERT(m_bufferedAmount >= consumed + m_consumedBufferedAmount); 705 ASSERT(m_bufferedAmount >= consumed + m_consumedBufferedAmount);
(...skipping 29 matching lines...) Expand all
694 DEFINE_TRACE(DOMWebSocket) 735 DEFINE_TRACE(DOMWebSocket)
695 { 736 {
696 visitor->trace(m_channel); 737 visitor->trace(m_channel);
697 visitor->trace(m_eventQueue); 738 visitor->trace(m_eventQueue);
698 WebSocketChannelClient::trace(visitor); 739 WebSocketChannelClient::trace(visitor);
699 RefCountedGarbageCollectedEventTargetWithInlineData<DOMWebSocket>::trace(vis itor); 740 RefCountedGarbageCollectedEventTargetWithInlineData<DOMWebSocket>::trace(vis itor);
700 ActiveDOMObject::trace(visitor); 741 ActiveDOMObject::trace(visitor);
701 } 742 }
702 743
703 } // namespace blink 744 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698