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

Unified Diff: Source/modules/presentation/PresentationSession.cpp

Issue 1206513004: [PresentationAPI] on-session-message handler for binary messages (Blink side). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Revert "add typedef uint8_t for WIN32" Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
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)
« no previous file with comments | « Source/modules/presentation/PresentationSession.h ('k') | Source/modules/presentation/PresentationSession.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698