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 <memory> | 7 #include <memory> |
8 #include "bindings/core/v8/ScriptPromiseResolver.h" | 8 #include "bindings/core/v8/ScriptPromiseResolver.h" |
9 #include "core/dom/DOMArrayBuffer.h" | 9 #include "core/dom/DOMArrayBuffer.h" |
10 #include "core/dom/DOMArrayBufferView.h" | 10 #include "core/dom/DOMArrayBufferView.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "modules/presentation/PresentationRequest.h" | 27 #include "modules/presentation/PresentationRequest.h" |
28 #include "platform/wtf/Assertions.h" | 28 #include "platform/wtf/Assertions.h" |
29 #include "platform/wtf/text/AtomicString.h" | 29 #include "platform/wtf/text/AtomicString.h" |
30 | 30 |
31 namespace blink { | 31 namespace blink { |
32 | 32 |
33 namespace { | 33 namespace { |
34 | 34 |
35 // TODO(mlamouri): refactor in one common place. | 35 // TODO(mlamouri): refactor in one common place. |
36 WebPresentationClient* PresentationClient(ExecutionContext* execution_context) { | 36 WebPresentationClient* PresentationClient(ExecutionContext* execution_context) { |
37 ASSERT(execution_context && execution_context->IsDocument()); | 37 DCHECK(execution_context); |
| 38 DCHECK(execution_context->IsDocument()); |
38 | 39 |
39 Document* document = ToDocument(execution_context); | 40 Document* document = ToDocument(execution_context); |
40 if (!document->GetFrame()) | 41 if (!document->GetFrame()) |
41 return nullptr; | 42 return nullptr; |
42 PresentationController* controller = | 43 PresentationController* controller = |
43 PresentationController::From(*document->GetFrame()); | 44 PresentationController::From(*document->GetFrame()); |
44 return controller ? controller->Client() : nullptr; | 45 return controller ? controller->Client() : nullptr; |
45 } | 46 } |
46 | 47 |
47 const AtomicString& ConnectionStateToString( | 48 const AtomicString& ConnectionStateToString( |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 ExceptionState& exception_state) { | 268 ExceptionState& exception_state) { |
268 if (!CanSendMessage(exception_state)) | 269 if (!CanSendMessage(exception_state)) |
269 return; | 270 return; |
270 | 271 |
271 messages_.push_back(new Message(message)); | 272 messages_.push_back(new Message(message)); |
272 HandleMessageQueue(); | 273 HandleMessageQueue(); |
273 } | 274 } |
274 | 275 |
275 void PresentationConnection::send(DOMArrayBuffer* array_buffer, | 276 void PresentationConnection::send(DOMArrayBuffer* array_buffer, |
276 ExceptionState& exception_state) { | 277 ExceptionState& exception_state) { |
277 ASSERT(array_buffer && array_buffer->Buffer()); | 278 DCHECK(array_buffer); |
| 279 DCHECK(array_buffer->Buffer()); |
278 if (!CanSendMessage(exception_state)) | 280 if (!CanSendMessage(exception_state)) |
279 return; | 281 return; |
280 | 282 |
281 messages_.push_back(new Message(array_buffer)); | 283 messages_.push_back(new Message(array_buffer)); |
282 HandleMessageQueue(); | 284 HandleMessageQueue(); |
283 } | 285 } |
284 | 286 |
285 void PresentationConnection::send( | 287 void PresentationConnection::send( |
286 NotShared<DOMArrayBufferView> array_buffer_view, | 288 NotShared<DOMArrayBufferView> array_buffer_view, |
287 ExceptionState& exception_state) { | 289 ExceptionState& exception_state) { |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 state_ = WebPresentationConnectionState::kClosed; | 471 state_ = WebPresentationConnectionState::kClosed; |
470 DispatchStateChangeEvent(PresentationConnectionCloseEvent::Create( | 472 DispatchStateChangeEvent(PresentationConnectionCloseEvent::Create( |
471 EventTypeNames::close, ConnectionCloseReasonToString(reason), message)); | 473 EventTypeNames::close, ConnectionCloseReasonToString(reason), message)); |
472 } | 474 } |
473 | 475 |
474 void PresentationConnection::DidClose() { | 476 void PresentationConnection::DidClose() { |
475 DidClose(WebPresentationConnectionCloseReason::kClosed, ""); | 477 DidClose(WebPresentationConnectionCloseReason::kClosed, ""); |
476 } | 478 } |
477 | 479 |
478 void PresentationConnection::DidFinishLoadingBlob(DOMArrayBuffer* buffer) { | 480 void PresentationConnection::DidFinishLoadingBlob(DOMArrayBuffer* buffer) { |
479 ASSERT(!messages_.IsEmpty() && messages_.front()->type == kMessageTypeBlob); | 481 DCHECK(!messages_.IsEmpty()); |
480 ASSERT(buffer && buffer->Buffer()); | 482 DCHECK_EQ(messages_.front()->type, kMessageTypeBlob); |
| 483 DCHECK(buffer); |
| 484 DCHECK(buffer->Buffer()); |
481 // Send the loaded blob immediately here and continue processing the queue. | 485 // Send the loaded blob immediately here and continue processing the queue. |
482 WebPresentationClient* client = PresentationClient(GetExecutionContext()); | 486 WebPresentationClient* client = PresentationClient(GetExecutionContext()); |
483 if (client) { | 487 if (client) { |
484 client->SendBlobData(url_, id_, static_cast<const uint8_t*>(buffer->Data()), | 488 client->SendBlobData(url_, id_, static_cast<const uint8_t*>(buffer->Data()), |
485 buffer->ByteLength(), proxy_.get()); | 489 buffer->ByteLength(), proxy_.get()); |
486 } | 490 } |
487 | 491 |
488 messages_.pop_front(); | 492 messages_.pop_front(); |
489 blob_loader_.Clear(); | 493 blob_loader_.Clear(); |
490 HandleMessageQueue(); | 494 HandleMessageQueue(); |
491 } | 495 } |
492 | 496 |
493 void PresentationConnection::DidFailLoadingBlob( | 497 void PresentationConnection::DidFailLoadingBlob( |
494 FileError::ErrorCode error_code) { | 498 FileError::ErrorCode error_code) { |
495 ASSERT(!messages_.IsEmpty() && messages_.front()->type == kMessageTypeBlob); | 499 DCHECK(!messages_.IsEmpty()); |
| 500 DCHECK_EQ(messages_.front()->type, kMessageTypeBlob); |
496 // FIXME: generate error message? | 501 // FIXME: generate error message? |
497 // Ignore the current failed blob item and continue with next items. | 502 // Ignore the current failed blob item and continue with next items. |
498 messages_.pop_front(); | 503 messages_.pop_front(); |
499 blob_loader_.Clear(); | 504 blob_loader_.Clear(); |
500 HandleMessageQueue(); | 505 HandleMessageQueue(); |
501 } | 506 } |
502 | 507 |
503 void PresentationConnection::DispatchStateChangeEvent(Event* event) { | 508 void PresentationConnection::DispatchStateChangeEvent(Event* event) { |
504 TaskRunnerHelper::Get(TaskType::kPresentation, GetExecutionContext()) | 509 TaskRunnerHelper::Get(TaskType::kPresentation, GetExecutionContext()) |
505 ->PostTask(BLINK_FROM_HERE, | 510 ->PostTask(BLINK_FROM_HERE, |
(...skipping 12 matching lines...) Expand all Loading... |
518 void PresentationConnection::TearDown() { | 523 void PresentationConnection::TearDown() { |
519 // Cancel current Blob loading if any. | 524 // Cancel current Blob loading if any. |
520 if (blob_loader_) { | 525 if (blob_loader_) { |
521 blob_loader_->Cancel(); | 526 blob_loader_->Cancel(); |
522 blob_loader_.Clear(); | 527 blob_loader_.Clear(); |
523 } | 528 } |
524 messages_.clear(); | 529 messages_.clear(); |
525 } | 530 } |
526 | 531 |
527 } // namespace blink | 532 } // namespace blink |
OLD | NEW |