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

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: 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 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 private: 96 private:
97 Member<PresentationSession> m_presentationSession; 97 Member<PresentationSession> m_presentationSession;
98 FileReaderLoader m_loader; 98 FileReaderLoader m_loader;
99 }; 99 };
100 100
101 PresentationSession::PresentationSession(LocalFrame* frame, const String& id, co nst String& url) 101 PresentationSession::PresentationSession(LocalFrame* frame, const String& id, co nst String& url)
102 : DOMWindowProperty(frame) 102 : DOMWindowProperty(frame)
103 , m_id(id) 103 , m_id(id)
104 , m_url(url) 104 , m_url(url)
105 , m_state(WebPresentationSessionState::Connected) 105 , m_state(WebPresentationSessionState::Connected)
106 , m_binaryType(BinaryTypeBlob)
106 { 107 {
107 } 108 }
108 109
109 PresentationSession::~PresentationSession() 110 PresentationSession::~PresentationSession()
110 { 111 {
111 ASSERT(!m_blobLoader); 112 ASSERT(!m_blobLoader);
112 } 113 }
113 114
114 // static 115 // static
115 PresentationSession* PresentationSession::take(WebPresentationSessionClient* cli ent, Presentation* presentation) 116 PresentationSession* PresentationSession::take(WebPresentationSessionClient* cli ent, Presentation* presentation)
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 m_messages.removeFirst(); 214 m_messages.removeFirst();
214 break; 215 break;
215 case MessageTypeBlob: 216 case MessageTypeBlob:
216 ASSERT(!m_blobLoader); 217 ASSERT(!m_blobLoader);
217 m_blobLoader = new BlobLoader(message->blobDataHandle, this); 218 m_blobLoader = new BlobLoader(message->blobDataHandle, this);
218 break; 219 break;
219 } 220 }
220 } 221 }
221 } 222 }
222 223
224 String PresentationSession::binaryType() const
225 {
226 switch (m_binaryType) {
227 case BinaryTypeBlob:
228 return "blob";
229 case BinaryTypeArrayBuffer:
230 return "arraybuffer";
231 }
232 ASSERT_NOT_REACHED();
233 return String();
234 }
235
236 void PresentationSession::setBinaryType(const String& binaryType)
237 {
238 if (binaryType == "blob") {
239 m_binaryType = BinaryTypeBlob;
240 return;
241 }
242 if (binaryType == "arraybuffer") {
243 m_binaryType = BinaryTypeArrayBuffer;
244 return;
245 }
246 ASSERT_NOT_REACHED();
247 }
248
223 void PresentationSession::didReceiveTextMessage(const String& message) 249 void PresentationSession::didReceiveTextMessage(const String& message)
224 { 250 {
251 if (m_state == WebPresentationSessionState::Disconnected)
252 return;
253
225 dispatchEvent(MessageEvent::create(message)); 254 dispatchEvent(MessageEvent::create(message));
226 } 255 }
227 256
257 void PresentationSession::didReceiveBinaryMessage(const uint8_t* data, size_t le ngth)
258 {
259 if (m_state == WebPresentationSessionState::Disconnected)
260 return;
261
262 switch (m_binaryType) {
263 case BinaryTypeBlob: {
264 OwnPtr<BlobData> blobData = BlobData::create();
265 blobData->appendBytes(data, length);
266 Blob* blob = Blob::create(BlobDataHandle::create(blobData.release(), len gth));
267 dispatchEvent(MessageEvent::create(blob));
268 return;
269 }
270 case BinaryTypeArrayBuffer:
271 RefPtr<DOMArrayBuffer> buffer = DOMArrayBuffer::create(data, length);
272 dispatchEvent(MessageEvent::create(buffer.release()));
273 return;
274 }
275 ASSERT_NOT_REACHED();
276 }
277
228 void PresentationSession::close() 278 void PresentationSession::close()
229 { 279 {
230 if (m_state != WebPresentationSessionState::Connected) 280 if (m_state != WebPresentationSessionState::Connected)
231 return; 281 return;
232 WebPresentationClient* client = presentationClient(executionContext()); 282 WebPresentationClient* client = presentationClient(executionContext());
233 if (client) 283 if (client)
234 client->closeSession(m_url, m_id); 284 client->closeSession(m_url, m_id);
235 285
236 // Cancel current Blob loading if any. 286 // Cancel current Blob loading if any.
237 if (m_blobLoader) { 287 if (m_blobLoader) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 { 326 {
277 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob) ; 327 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob) ;
278 // FIXME: generate error message? 328 // FIXME: generate error message?
279 // Ignore the current failed blob item and continue with next items. 329 // Ignore the current failed blob item and continue with next items.
280 m_messages.removeFirst(); 330 m_messages.removeFirst();
281 m_blobLoader.clear(); 331 m_blobLoader.clear();
282 handleMessageQueue(); 332 handleMessageQueue();
283 } 333 }
284 334
285 } // namespace blink 335 } // namespace blink
OLDNEW
« 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