| OLD | NEW |
| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 private: | 84 private: |
| 85 Member<PresentationSession> m_presentationSession; | 85 Member<PresentationSession> m_presentationSession; |
| 86 FileReaderLoader m_loader; | 86 FileReaderLoader m_loader; |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 PresentationSession::PresentationSession(LocalFrame* frame, const String& id, co
nst String& url) | 89 PresentationSession::PresentationSession(LocalFrame* frame, const String& id, co
nst String& url) |
| 90 : DOMWindowProperty(frame) | 90 : DOMWindowProperty(frame) |
| 91 , m_id(id) | 91 , m_id(id) |
| 92 , m_url(url) | 92 , m_url(url) |
| 93 , m_state(WebPresentationSessionState::Connected) | 93 , m_state(WebPresentationSessionState::Connected) |
| 94 , m_binaryType(BinaryTypeBlob) |
| 94 { | 95 { |
| 95 } | 96 } |
| 96 | 97 |
| 97 PresentationSession::~PresentationSession() | 98 PresentationSession::~PresentationSession() |
| 98 { | 99 { |
| 99 ASSERT(!m_blobLoader); | 100 ASSERT(!m_blobLoader); |
| 100 } | 101 } |
| 101 | 102 |
| 102 // static | 103 // static |
| 103 PresentationSession* PresentationSession::take(WebPresentationSessionClient* cli
entRaw, Presentation* presentation) | 104 PresentationSession* PresentationSession::take(WebPresentationSessionClient* cli
entRaw, Presentation* presentation) |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 m_messages.removeFirst(); | 213 m_messages.removeFirst(); |
| 213 break; | 214 break; |
| 214 case MessageTypeBlob: | 215 case MessageTypeBlob: |
| 215 ASSERT(!m_blobLoader); | 216 ASSERT(!m_blobLoader); |
| 216 m_blobLoader = new BlobLoader(message->blobDataHandle, this); | 217 m_blobLoader = new BlobLoader(message->blobDataHandle, this); |
| 217 break; | 218 break; |
| 218 } | 219 } |
| 219 } | 220 } |
| 220 } | 221 } |
| 221 | 222 |
| 223 String PresentationSession::binaryType() const |
| 224 { |
| 225 switch (m_binaryType) { |
| 226 case BinaryTypeBlob: |
| 227 return "blob"; |
| 228 case BinaryTypeArrayBuffer: |
| 229 return "arraybuffer"; |
| 230 } |
| 231 ASSERT_NOT_REACHED(); |
| 232 return String(); |
| 233 } |
| 234 |
| 235 void PresentationSession::setBinaryType(const String& binaryType) |
| 236 { |
| 237 if (binaryType == "blob") { |
| 238 m_binaryType = BinaryTypeBlob; |
| 239 return; |
| 240 } |
| 241 if (binaryType == "arraybuffer") { |
| 242 m_binaryType = BinaryTypeArrayBuffer; |
| 243 return; |
| 244 } |
| 245 ASSERT_NOT_REACHED(); |
| 246 } |
| 247 |
| 222 void PresentationSession::didReceiveTextMessage(const String& message) | 248 void PresentationSession::didReceiveTextMessage(const String& message) |
| 223 { | 249 { |
| 250 if (m_state == WebPresentationSessionState::Disconnected) |
| 251 return; |
| 252 |
| 224 dispatchEvent(MessageEvent::create(message)); | 253 dispatchEvent(MessageEvent::create(message)); |
| 225 } | 254 } |
| 226 | 255 |
| 256 void PresentationSession::didReceiveBinaryMessage(const uint8_t* data, size_t le
ngth) |
| 257 { |
| 258 if (m_state == WebPresentationSessionState::Disconnected) |
| 259 return; |
| 260 |
| 261 switch (m_binaryType) { |
| 262 case BinaryTypeBlob: { |
| 263 RefPtr<RawData> rawData = RawData::create(); |
| 264 rawData->mutableData()->resize(length); |
| 265 memcpy(rawData->mutableData()->data(), data, length); |
| 266 OwnPtr<BlobData> blobData = BlobData::create(); |
| 267 blobData->appendData(rawData.release(), 0, BlobDataItem::toEndOfFile); |
| 268 Blob* blob = Blob::create(BlobDataHandle::create(blobData.release(), len
gth)); |
| 269 dispatchEvent(MessageEvent::create(blob)); |
| 270 return; |
| 271 } |
| 272 case BinaryTypeArrayBuffer: |
| 273 RefPtr<DOMArrayBuffer> buffer = DOMArrayBuffer::create(data, length); |
| 274 dispatchEvent(MessageEvent::create(buffer.release())); |
| 275 return; |
| 276 } |
| 277 ASSERT_NOT_REACHED(); |
| 278 } |
| 279 |
| 227 void PresentationSession::close() | 280 void PresentationSession::close() |
| 228 { | 281 { |
| 229 if (m_state != WebPresentationSessionState::Connected) | 282 if (m_state != WebPresentationSessionState::Connected) |
| 230 return; | 283 return; |
| 231 PresentationController* controller = presentationController(); | 284 PresentationController* controller = presentationController(); |
| 232 if (controller) | 285 if (controller) |
| 233 controller->closeSession(m_url, m_id); | 286 controller->closeSession(m_url, m_id); |
| 234 | 287 |
| 235 // Cancel current Blob loading if any. | 288 // Cancel current Blob loading if any. |
| 236 if (m_blobLoader) { | 289 if (m_blobLoader) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 { | 335 { |
| 283 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob)
; | 336 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob)
; |
| 284 // FIXME: generate error message? | 337 // FIXME: generate error message? |
| 285 // Ignore the current failed blob item and continue with next items. | 338 // Ignore the current failed blob item and continue with next items. |
| 286 m_messages.removeFirst(); | 339 m_messages.removeFirst(); |
| 287 m_blobLoader.clear(); | 340 m_blobLoader.clear(); |
| 288 handleMessageQueue(); | 341 handleMessageQueue(); |
| 289 } | 342 } |
| 290 | 343 |
| 291 } // namespace blink | 344 } // namespace blink |
| OLD | NEW |