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 "modules/presentation/PresentationConnection.h" | 5 #include "modules/presentation/PresentationConnection.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptPromiseResolver.h" | 7 #include "bindings/core/v8/ScriptPromiseResolver.h" |
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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 std::unique_ptr<FileReaderLoader> m_loader; | 146 std::unique_ptr<FileReaderLoader> m_loader; |
147 }; | 147 }; |
148 | 148 |
149 PresentationConnection::PresentationConnection(LocalFrame* frame, | 149 PresentationConnection::PresentationConnection(LocalFrame* frame, |
150 const String& id, | 150 const String& id, |
151 const KURL& url) | 151 const KURL& url) |
152 : ContextClient(frame), | 152 : ContextClient(frame), |
153 m_id(id), | 153 m_id(id), |
154 m_url(url), | 154 m_url(url), |
155 m_state(WebPresentationConnectionState::Connecting), | 155 m_state(WebPresentationConnectionState::Connecting), |
156 m_binaryType(BinaryTypeBlob) {} | 156 m_binaryType(BinaryTypeBlob), |
| 157 m_proxy(nullptr) {} |
157 | 158 |
158 PresentationConnection::~PresentationConnection() { | 159 PresentationConnection::~PresentationConnection() { |
159 ASSERT(!m_blobLoader); | 160 ASSERT(!m_blobLoader); |
160 } | 161 } |
161 | 162 |
| 163 void PresentationConnection::bindProxy( |
| 164 std::unique_ptr<WebPresentationConnectionProxy> proxy) { |
| 165 DCHECK(proxy); |
| 166 // TODO(zhaobin): Restore to DCHECK(!m_proxy) when reconnect() is properly |
| 167 // implemented. |
| 168 if (!m_proxy) |
| 169 m_proxy = std::move(proxy); |
| 170 } |
| 171 |
162 // static | 172 // static |
163 PresentationConnection* PresentationConnection::take( | 173 PresentationConnection* PresentationConnection::take( |
164 ScriptPromiseResolver* resolver, | 174 ScriptPromiseResolver* resolver, |
165 const WebPresentationSessionInfo& sessionInfo, | 175 const WebPresentationSessionInfo& sessionInfo, |
166 PresentationRequest* request) { | 176 PresentationRequest* request) { |
167 ASSERT(resolver); | 177 ASSERT(resolver); |
168 ASSERT(request); | 178 ASSERT(request); |
169 ASSERT(resolver->getExecutionContext()->isDocument()); | 179 ASSERT(resolver->getExecutionContext()->isDocument()); |
170 | 180 |
171 Document* document = toDocument(resolver->getExecutionContext()); | 181 Document* document = toDocument(resolver->getExecutionContext()); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 throwPresentationDisconnectedError(exceptionState); | 308 throwPresentationDisconnectedError(exceptionState); |
299 return false; | 309 return false; |
300 } | 310 } |
301 | 311 |
302 // The connection can send a message if there is a client available. | 312 // The connection can send a message if there is a client available. |
303 return !!presentationClient(getExecutionContext()); | 313 return !!presentationClient(getExecutionContext()); |
304 } | 314 } |
305 | 315 |
306 void PresentationConnection::handleMessageQueue() { | 316 void PresentationConnection::handleMessageQueue() { |
307 WebPresentationClient* client = presentationClient(getExecutionContext()); | 317 WebPresentationClient* client = presentationClient(getExecutionContext()); |
308 if (!client) | 318 if (!client || !m_proxy) |
309 return; | 319 return; |
310 | 320 |
311 while (!m_messages.isEmpty() && !m_blobLoader) { | 321 while (!m_messages.isEmpty() && !m_blobLoader) { |
312 Message* message = m_messages.first().get(); | 322 Message* message = m_messages.first().get(); |
313 switch (message->type) { | 323 switch (message->type) { |
314 case MessageTypeText: | 324 case MessageTypeText: |
315 client->sendString(m_url, m_id, message->text); | 325 client->sendString(m_url, m_id, message->text, m_proxy.get()); |
316 m_messages.removeFirst(); | 326 m_messages.removeFirst(); |
317 break; | 327 break; |
318 case MessageTypeArrayBuffer: | 328 case MessageTypeArrayBuffer: |
319 client->sendArrayBuffer(m_url, m_id, static_cast<const uint8_t*>( | 329 client->sendArrayBuffer( |
320 message->arrayBuffer->data()), | 330 m_url, m_id, |
321 message->arrayBuffer->byteLength()); | 331 static_cast<const uint8_t*>(message->arrayBuffer->data()), |
| 332 message->arrayBuffer->byteLength(), m_proxy.get()); |
322 m_messages.removeFirst(); | 333 m_messages.removeFirst(); |
323 break; | 334 break; |
324 case MessageTypeBlob: | 335 case MessageTypeBlob: |
325 ASSERT(!m_blobLoader); | 336 ASSERT(!m_blobLoader); |
326 m_blobLoader = new BlobLoader(message->blobDataHandle, this); | 337 m_blobLoader = new BlobLoader(message->blobDataHandle, this); |
327 break; | 338 break; |
328 } | 339 } |
329 } | 340 } |
330 } | 341 } |
331 | 342 |
(...skipping 13 matching lines...) Expand all Loading... |
345 m_binaryType = BinaryTypeBlob; | 356 m_binaryType = BinaryTypeBlob; |
346 return; | 357 return; |
347 } | 358 } |
348 if (binaryType == "arraybuffer") { | 359 if (binaryType == "arraybuffer") { |
349 m_binaryType = BinaryTypeArrayBuffer; | 360 m_binaryType = BinaryTypeArrayBuffer; |
350 return; | 361 return; |
351 } | 362 } |
352 ASSERT_NOT_REACHED(); | 363 ASSERT_NOT_REACHED(); |
353 } | 364 } |
354 | 365 |
355 void PresentationConnection::didReceiveTextMessage(const String& message) { | 366 void PresentationConnection::didReceiveTextMessage(const WebString& message) { |
356 if (m_state != WebPresentationConnectionState::Connected) | 367 if (m_state != WebPresentationConnectionState::Connected) |
357 return; | 368 return; |
358 | 369 |
359 dispatchEvent(MessageEvent::create(message)); | 370 dispatchEvent(MessageEvent::create(message)); |
360 } | 371 } |
361 | 372 |
362 void PresentationConnection::didReceiveBinaryMessage(const uint8_t* data, | 373 void PresentationConnection::didReceiveBinaryMessage(const uint8_t* data, |
363 size_t length) { | 374 size_t length) { |
364 if (m_state != WebPresentationConnectionState::Connected) | 375 if (m_state != WebPresentationConnectionState::Connected) |
365 return; | 376 return; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 m_state = WebPresentationConnectionState::Closed; | 460 m_state = WebPresentationConnectionState::Closed; |
450 dispatchStateChangeEvent(PresentationConnectionCloseEvent::create( | 461 dispatchStateChangeEvent(PresentationConnectionCloseEvent::create( |
451 EventTypeNames::close, connectionCloseReasonToString(reason), message)); | 462 EventTypeNames::close, connectionCloseReasonToString(reason), message)); |
452 } | 463 } |
453 | 464 |
454 void PresentationConnection::didFinishLoadingBlob(DOMArrayBuffer* buffer) { | 465 void PresentationConnection::didFinishLoadingBlob(DOMArrayBuffer* buffer) { |
455 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob); | 466 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob); |
456 ASSERT(buffer && buffer->buffer()); | 467 ASSERT(buffer && buffer->buffer()); |
457 // Send the loaded blob immediately here and continue processing the queue. | 468 // Send the loaded blob immediately here and continue processing the queue. |
458 WebPresentationClient* client = presentationClient(getExecutionContext()); | 469 WebPresentationClient* client = presentationClient(getExecutionContext()); |
459 if (client) | 470 if (client) { |
460 client->sendBlobData(m_url, m_id, | 471 client->sendBlobData(m_url, m_id, |
461 static_cast<const uint8_t*>(buffer->data()), | 472 static_cast<const uint8_t*>(buffer->data()), |
462 buffer->byteLength()); | 473 buffer->byteLength(), m_proxy.get()); |
| 474 } |
463 | 475 |
464 m_messages.removeFirst(); | 476 m_messages.removeFirst(); |
465 m_blobLoader.clear(); | 477 m_blobLoader.clear(); |
466 handleMessageQueue(); | 478 handleMessageQueue(); |
467 } | 479 } |
468 | 480 |
469 void PresentationConnection::didFailLoadingBlob( | 481 void PresentationConnection::didFailLoadingBlob( |
470 FileError::ErrorCode errorCode) { | 482 FileError::ErrorCode errorCode) { |
471 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob); | 483 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob); |
472 // FIXME: generate error message? | 484 // FIXME: generate error message? |
(...skipping 21 matching lines...) Expand all Loading... |
494 void PresentationConnection::tearDown() { | 506 void PresentationConnection::tearDown() { |
495 // Cancel current Blob loading if any. | 507 // Cancel current Blob loading if any. |
496 if (m_blobLoader) { | 508 if (m_blobLoader) { |
497 m_blobLoader->cancel(); | 509 m_blobLoader->cancel(); |
498 m_blobLoader.clear(); | 510 m_blobLoader.clear(); |
499 } | 511 } |
500 m_messages.clear(); | 512 m_messages.clear(); |
501 } | 513 } |
502 | 514 |
503 } // namespace blink | 515 } // namespace blink |
OLD | NEW |