Index: Source/modules/presentation/PresentationSession.cpp |
diff --git a/Source/modules/presentation/PresentationSession.cpp b/Source/modules/presentation/PresentationSession.cpp |
index 7ecc9132d9f7778f62601c7fe04bacbd0aa95860..76b4daec022dc3bc49f1ffa7cce1830ebff48464 100644 |
--- a/Source/modules/presentation/PresentationSession.cpp |
+++ b/Source/modules/presentation/PresentationSession.cpp |
@@ -103,6 +103,7 @@ PresentationSession::PresentationSession(LocalFrame* frame, const String& id, co |
, m_id(id) |
, m_url(url) |
, m_state(WebPresentationSessionState::Connected) |
+ , m_binaryType(BinaryTypeBlob) |
{ |
} |
@@ -220,11 +221,60 @@ void PresentationSession::handleMessageQueue() |
} |
} |
+String PresentationSession::binaryType() const |
+{ |
+ switch (m_binaryType) { |
+ case BinaryTypeBlob: |
+ return "blob"; |
+ case BinaryTypeArrayBuffer: |
+ return "arraybuffer"; |
+ } |
+ ASSERT_NOT_REACHED(); |
+ return String(); |
+} |
+ |
+void PresentationSession::setBinaryType(const String& binaryType) |
+{ |
+ if (binaryType == "blob") { |
+ m_binaryType = BinaryTypeBlob; |
+ return; |
+ } |
+ if (binaryType == "arraybuffer") { |
+ m_binaryType = BinaryTypeArrayBuffer; |
+ return; |
+ } |
+ ASSERT_NOT_REACHED(); |
+} |
+ |
void PresentationSession::didReceiveTextMessage(const String& message) |
{ |
+ if (m_state == WebPresentationSessionState::Disconnected) |
+ return; |
+ |
dispatchEvent(MessageEvent::create(message)); |
} |
+void PresentationSession::didReceiveBinaryMessage(const uint8_t* data, size_t length) |
+{ |
+ if (m_state == WebPresentationSessionState::Disconnected) |
+ return; |
+ |
+ switch (m_binaryType) { |
+ case BinaryTypeBlob: { |
+ OwnPtr<BlobData> blobData = BlobData::create(); |
+ blobData->appendBytes(data, length); |
+ Blob* blob = Blob::create(BlobDataHandle::create(blobData.release(), length)); |
+ dispatchEvent(MessageEvent::create(blob)); |
+ return; |
+ } |
+ case BinaryTypeArrayBuffer: |
+ RefPtr<DOMArrayBuffer> buffer = DOMArrayBuffer::create(data, length); |
+ dispatchEvent(MessageEvent::create(buffer.release())); |
+ return; |
+ } |
+ ASSERT_NOT_REACHED(); |
+} |
+ |
void PresentationSession::close() |
{ |
if (m_state != WebPresentationSessionState::Connected) |