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

Side by Side 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: generic interface to receive binary messages. 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "modules/presentation/PresentationSession.h" 6 #include "modules/presentation/PresentationSession.h"
7 7
8 #include "core/dom/DOMArrayBuffer.h" 8 #include "core/dom/DOMArrayBuffer.h"
9 #include "core/dom/DOMArrayBufferView.h" 9 #include "core/dom/DOMArrayBufferView.h"
10 #include "core/dom/Document.h" 10 #include "core/dom/Document.h"
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 m_messages.removeFirst(); 212 m_messages.removeFirst();
213 break; 213 break;
214 case MessageTypeBlob: 214 case MessageTypeBlob:
215 ASSERT(!m_blobLoader); 215 ASSERT(!m_blobLoader);
216 m_blobLoader = new BlobLoader(message->blobDataHandle, this); 216 m_blobLoader = new BlobLoader(message->blobDataHandle, this);
217 break; 217 break;
218 } 218 }
219 } 219 }
220 } 220 }
221 221
222 String PresentationSession::binaryType() const
223 {
224 switch (m_binaryType) {
225 case BinaryTypeBlob:
226 return "blob";
227 case BinaryTypeArrayBuffer:
228 return "arraybuffer";
229 }
230 ASSERT_NOT_REACHED();
231 return String();
232 }
233
234 void PresentationSession::setBinaryType(const String& binaryType)
235 {
236 if (binaryType == "blob") {
237 m_binaryType = BinaryTypeBlob;
238 return;
239 }
240 if (binaryType == "arraybuffer") {
241 m_binaryType = BinaryTypeArrayBuffer;
242 return;
243 }
244 ASSERT_NOT_REACHED();
245 }
246
222 void PresentationSession::didReceiveTextMessage(const String& message) 247 void PresentationSession::didReceiveTextMessage(const String& message)
223 { 248 {
249 if (m_state == WebPresentationSessionState::Disconnected)
250 return;
251
224 dispatchEvent(MessageEvent::create(message)); 252 dispatchEvent(MessageEvent::create(message));
225 } 253 }
226 254
255 void PresentationSession::didReceiveBinaryMessage(const uint8_t* data, size_t le ngth)
256 {
257 if (m_state == WebPresentationSessionState::Disconnected)
258 return;
259
260 switch (m_binaryType) {
261 case BinaryTypeBlob: {
262 RefPtr<RawData> rawData = RawData::create();
263 rawData->mutableData()->resize(length);
264 memcpy(rawData->mutableData()->data(), data, length);
265 OwnPtr<BlobData> blobData = BlobData::create();
266 blobData->appendData(rawData.release(), 0, BlobDataItem::toEndOfFile);
267 Blob* blob = Blob::create(BlobDataHandle::create(blobData.release(), len gth));
268 dispatchEvent(MessageEvent::create(blob));
269 return;
270 }
271 case BinaryTypeArrayBuffer:
272 RefPtr<DOMArrayBuffer> buffer = DOMArrayBuffer::create(data, length);
273 dispatchEvent(MessageEvent::create(buffer.release()));
274 return;
275 }
276 ASSERT_NOT_REACHED();
277 }
278
227 void PresentationSession::close() 279 void PresentationSession::close()
228 { 280 {
229 if (m_state != WebPresentationSessionState::Connected) 281 if (m_state != WebPresentationSessionState::Connected)
230 return; 282 return;
231 PresentationController* controller = presentationController(); 283 PresentationController* controller = presentationController();
232 if (controller) 284 if (controller)
233 controller->closeSession(m_url, m_id); 285 controller->closeSession(m_url, m_id);
234 286
235 // Cancel current Blob loading if any. 287 // Cancel current Blob loading if any.
236 if (m_blobLoader) { 288 if (m_blobLoader) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 { 334 {
283 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob) ; 335 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob) ;
284 // FIXME: generate error message? 336 // FIXME: generate error message?
285 // Ignore the current failed blob item and continue with next items. 337 // Ignore the current failed blob item and continue with next items.
286 m_messages.removeFirst(); 338 m_messages.removeFirst();
287 m_blobLoader.clear(); 339 m_blobLoader.clear();
288 handleMessageQueue(); 340 handleMessageQueue();
289 } 341 }
290 342
291 } // namespace blink 343 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698