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" |
11 #include "core/dom/ExceptionCode.h" | 11 #include "core/dom/ExceptionCode.h" |
12 #include "core/dom/ExecutionContextTask.h" | |
12 #include "core/events/Event.h" | 13 #include "core/events/Event.h" |
13 #include "core/events/MessageEvent.h" | 14 #include "core/events/MessageEvent.h" |
14 #include "core/fileapi/FileReaderLoader.h" | 15 #include "core/fileapi/FileReaderLoader.h" |
15 #include "core/fileapi/FileReaderLoaderClient.h" | 16 #include "core/fileapi/FileReaderLoaderClient.h" |
16 #include "core/frame/Deprecation.h" | 17 #include "core/frame/Deprecation.h" |
17 #include "core/frame/LocalFrame.h" | 18 #include "core/frame/LocalFrame.h" |
18 #include "core/frame/UseCounter.h" | 19 #include "core/frame/UseCounter.h" |
19 #include "modules/EventTargetModules.h" | 20 #include "modules/EventTargetModules.h" |
20 #include "modules/presentation/Presentation.h" | 21 #include "modules/presentation/Presentation.h" |
21 #include "modules/presentation/PresentationConnectionAvailableEvent.h" | 22 #include "modules/presentation/PresentationConnectionAvailableEvent.h" |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 PresentationConnection* PresentationConnection::take( | 185 PresentationConnection* PresentationConnection::take( |
185 PresentationController* controller, | 186 PresentationController* controller, |
186 std::unique_ptr<WebPresentationConnectionClient> client, | 187 std::unique_ptr<WebPresentationConnectionClient> client, |
187 PresentationRequest* request) { | 188 PresentationRequest* request) { |
188 ASSERT(controller); | 189 ASSERT(controller); |
189 ASSERT(request); | 190 ASSERT(request); |
190 | 191 |
191 PresentationConnection* connection = new PresentationConnection( | 192 PresentationConnection* connection = new PresentationConnection( |
192 controller->frame(), client->getId(), client->getUrl()); | 193 controller->frame(), client->getId(), client->getUrl()); |
193 controller->registerConnection(connection); | 194 controller->registerConnection(connection); |
194 request->dispatchEvent(PresentationConnectionAvailableEvent::create( | 195 request->getExecutionContext()->postTask( |
195 EventTypeNames::connectionavailable, connection)); | 196 BLINK_FROM_HERE, |
196 | 197 createSameThreadTask( |
198 &PresentationRequest::dispatchConnectionAvailableEvent, | |
199 wrapPersistent(request), wrapPersistent(connection))); | |
197 return connection; | 200 return connection; |
198 } | 201 } |
199 | 202 |
200 // static | 203 // static |
201 PresentationConnection* PresentationConnection::take( | 204 PresentationConnection* PresentationConnection::take( |
202 PresentationReceiver* receiver, | 205 PresentationReceiver* receiver, |
203 std::unique_ptr<WebPresentationConnectionClient> client) { | 206 std::unique_ptr<WebPresentationConnectionClient> client) { |
204 DCHECK(receiver); | 207 DCHECK(receiver); |
205 DCHECK(client); | 208 DCHECK(client); |
206 | 209 |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
408 WebPresentationConnectionState state) { | 411 WebPresentationConnectionState state) { |
409 if (m_state == state) | 412 if (m_state == state) |
410 return; | 413 return; |
411 | 414 |
412 m_state = state; | 415 m_state = state; |
413 switch (m_state) { | 416 switch (m_state) { |
414 case WebPresentationConnectionState::Connecting: | 417 case WebPresentationConnectionState::Connecting: |
415 NOTREACHED(); | 418 NOTREACHED(); |
416 return; | 419 return; |
417 case WebPresentationConnectionState::Connected: | 420 case WebPresentationConnectionState::Connected: |
418 dispatchEvent(Event::create(EventTypeNames::connect)); | 421 dispatchEventAsync(Event::create(EventTypeNames::connect)); |
419 return; | 422 return; |
420 case WebPresentationConnectionState::Terminated: | 423 case WebPresentationConnectionState::Terminated: |
421 dispatchEvent(Event::create(EventTypeNames::terminate)); | 424 dispatchEventAsync(Event::create(EventTypeNames::terminate)); |
422 return; | 425 return; |
423 // Closed state is handled in |didClose()|. | 426 // Closed state is handled in |didClose()|. |
424 case WebPresentationConnectionState::Closed: | 427 case WebPresentationConnectionState::Closed: |
425 NOTREACHED(); | 428 NOTREACHED(); |
426 return; | 429 return; |
427 } | 430 } |
428 NOTREACHED(); | 431 NOTREACHED(); |
429 } | 432 } |
430 | 433 |
431 void PresentationConnection::didClose( | 434 void PresentationConnection::didClose( |
432 WebPresentationConnectionCloseReason reason, | 435 WebPresentationConnectionCloseReason reason, |
433 const String& message) { | 436 const String& message) { |
434 if (m_state == WebPresentationConnectionState::Closed) | 437 if (m_state == WebPresentationConnectionState::Closed) |
435 return; | 438 return; |
436 | 439 |
437 m_state = WebPresentationConnectionState::Closed; | 440 m_state = WebPresentationConnectionState::Closed; |
438 dispatchEvent(PresentationConnectionCloseEvent::create( | 441 dispatchEventAsync(PresentationConnectionCloseEvent::create( |
439 EventTypeNames::close, connectionCloseReasonToString(reason), message)); | 442 EventTypeNames::close, connectionCloseReasonToString(reason), message)); |
440 } | 443 } |
441 | 444 |
442 void PresentationConnection::didFinishLoadingBlob(DOMArrayBuffer* buffer) { | 445 void PresentationConnection::didFinishLoadingBlob(DOMArrayBuffer* buffer) { |
443 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob); | 446 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob); |
444 ASSERT(buffer && buffer->buffer()); | 447 ASSERT(buffer && buffer->buffer()); |
445 // Send the loaded blob immediately here and continue processing the queue. | 448 // Send the loaded blob immediately here and continue processing the queue. |
446 WebPresentationClient* client = presentationClient(getExecutionContext()); | 449 WebPresentationClient* client = presentationClient(getExecutionContext()); |
447 if (client) | 450 if (client) |
448 client->sendBlobData(m_url, m_id, | 451 client->sendBlobData(m_url, m_id, |
449 static_cast<const uint8_t*>(buffer->data()), | 452 static_cast<const uint8_t*>(buffer->data()), |
450 buffer->byteLength()); | 453 buffer->byteLength()); |
451 | 454 |
452 m_messages.removeFirst(); | 455 m_messages.removeFirst(); |
453 m_blobLoader.clear(); | 456 m_blobLoader.clear(); |
454 handleMessageQueue(); | 457 handleMessageQueue(); |
455 } | 458 } |
456 | 459 |
457 void PresentationConnection::didFailLoadingBlob( | 460 void PresentationConnection::didFailLoadingBlob( |
458 FileError::ErrorCode errorCode) { | 461 FileError::ErrorCode errorCode) { |
459 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob); | 462 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob); |
460 // FIXME: generate error message? | 463 // FIXME: generate error message? |
461 // Ignore the current failed blob item and continue with next items. | 464 // Ignore the current failed blob item and continue with next items. |
462 m_messages.removeFirst(); | 465 m_messages.removeFirst(); |
463 m_blobLoader.clear(); | 466 m_blobLoader.clear(); |
464 handleMessageQueue(); | 467 handleMessageQueue(); |
465 } | 468 } |
466 | 469 |
470 void PresentationConnection::dispatchEventAsync(Event* event) { | |
mark a. foltz
2016/12/07 04:23:55
Can this be combined into dispatchStateChangeEvent
zhaobin
2016/12/07 19:30:43
Not sure how to combine them neatly. postTask expe
mark a. foltz
2016/12/07 21:32:44
Ah, got it. Slight preference to call this method
zhaobin
2016/12/08 00:16:46
Done.
| |
471 getExecutionContext()->postTask( | |
472 BLINK_FROM_HERE, | |
473 createSameThreadTask(&PresentationConnection::dispatchStateChangeEvent, | |
474 wrapPersistent(this), wrapPersistent(event))); | |
475 } | |
476 | |
477 void PresentationConnection::dispatchStateChangeEvent(Event* event) { | |
478 dispatchEvent(event); | |
479 } | |
480 | |
467 void PresentationConnection::tearDown() { | 481 void PresentationConnection::tearDown() { |
468 // Cancel current Blob loading if any. | 482 // Cancel current Blob loading if any. |
469 if (m_blobLoader) { | 483 if (m_blobLoader) { |
470 m_blobLoader->cancel(); | 484 m_blobLoader->cancel(); |
471 m_blobLoader.clear(); | 485 m_blobLoader.clear(); |
472 } | 486 } |
473 m_messages.clear(); | 487 m_messages.clear(); |
474 } | 488 } |
475 | 489 |
476 } // namespace blink | 490 } // namespace blink |
OLD | NEW |