| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/renderer/presentation/presentation_dispatcher.h" | 5 #include "content/renderer/presentation/presentation_dispatcher.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 | 76 |
| 77 } // namespace | 77 } // namespace |
| 78 | 78 |
| 79 namespace content { | 79 namespace content { |
| 80 | 80 |
| 81 PresentationDispatcher::PresentationDispatcher(RenderFrame* render_frame) | 81 PresentationDispatcher::PresentationDispatcher(RenderFrame* render_frame) |
| 82 : RenderFrameObserver(render_frame), | 82 : RenderFrameObserver(render_frame), |
| 83 controller_(nullptr), | 83 controller_(nullptr), |
| 84 binding_(this) { | 84 receiver_(nullptr), |
| 85 } | 85 binding_(this) {} |
| 86 | 86 |
| 87 PresentationDispatcher::~PresentationDispatcher() { | 87 PresentationDispatcher::~PresentationDispatcher() { |
| 88 // Controller should be destroyed before the dispatcher when frame is | 88 // Controller should be destroyed before the dispatcher when frame is |
| 89 // destroyed. | 89 // destroyed. |
| 90 DCHECK(!controller_); | 90 DCHECK(!controller_); |
| 91 } | 91 } |
| 92 | 92 |
| 93 void PresentationDispatcher::setController( | 93 void PresentationDispatcher::setController( |
| 94 blink::WebPresentationController* controller) { | 94 blink::WebPresentationController* controller) { |
| 95 // There shouldn't be any swapping from one non-null controller to another. | 95 // There shouldn't be any swapping from one non-null controller to another. |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 DCHECK(!connection.is_null()); | 428 DCHECK(!connection.is_null()); |
| 429 controller_->didCloseConnection( | 429 controller_->didCloseConnection( |
| 430 new PresentationConnectionClient(std::move(connection)), | 430 new PresentationConnectionClient(std::move(connection)), |
| 431 GetWebPresentationConnectionCloseReasonFromMojo(reason), | 431 GetWebPresentationConnectionCloseReasonFromMojo(reason), |
| 432 blink::WebString::fromUTF8(message)); | 432 blink::WebString::fromUTF8(message)); |
| 433 } | 433 } |
| 434 | 434 |
| 435 void PresentationDispatcher::OnSessionMessagesReceived( | 435 void PresentationDispatcher::OnSessionMessagesReceived( |
| 436 blink::mojom::PresentationSessionInfoPtr session_info, | 436 blink::mojom::PresentationSessionInfoPtr session_info, |
| 437 std::vector<blink::mojom::SessionMessagePtr> messages) { | 437 std::vector<blink::mojom::SessionMessagePtr> messages) { |
| 438 if (!controller_) | 438 auto observer = |
| 439 (receiver_ |
| 440 ? static_cast<blink::WebPresentationMessageObserver*>(receiver_) |
| 441 : static_cast<blink::WebPresentationMessageObserver*>(controller_)); |
| 442 if (!observer) |
| 439 return; | 443 return; |
| 440 | 444 |
| 441 for (size_t i = 0; i < messages.size(); ++i) { | 445 for (size_t i = 0; i < messages.size(); ++i) { |
| 442 // Note: Passing batches of messages to the Blink layer would be more | 446 // Note: Passing batches of messages to the Blink layer would be more |
| 443 // efficient. | 447 // efficient. |
| 444 std::unique_ptr<PresentationConnectionClient> session_client( | 448 std::unique_ptr<PresentationConnectionClient> session_client( |
| 445 new PresentationConnectionClient(session_info->url, session_info->id)); | 449 new PresentationConnectionClient(session_info->url, session_info->id)); |
| 446 switch (messages[i]->type) { | 450 switch (messages[i]->type) { |
| 447 case blink::mojom::PresentationMessageType::TEXT: { | 451 case blink::mojom::PresentationMessageType::TEXT: { |
| 448 // TODO(mfoltz): Do we need to DCHECK(messages[i]->message)? | 452 // TODO(mfoltz): Do we need to DCHECK(messages[i]->message)? |
| 449 controller_->didReceiveSessionTextMessage( | 453 observer->didReceiveSessionTextMessage( |
| 450 session_client.release(), | 454 session_client.release(), |
| 451 blink::WebString::fromUTF8(messages[i]->message.value())); | 455 blink::WebString::fromUTF8(messages[i]->message.value())); |
| 452 break; | 456 break; |
| 453 } | 457 } |
| 454 case blink::mojom::PresentationMessageType::ARRAY_BUFFER: | 458 case blink::mojom::PresentationMessageType::ARRAY_BUFFER: |
| 455 case blink::mojom::PresentationMessageType::BLOB: { | 459 case blink::mojom::PresentationMessageType::BLOB: { |
| 456 // TODO(mfoltz): Do we need to DCHECK(messages[i]->data)? | 460 // TODO(mfoltz): Do we need to DCHECK(messages[i]->data)? |
| 457 controller_->didReceiveSessionBinaryMessage( | 461 observer->didReceiveSessionBinaryMessage(session_client.release(), |
| 458 session_client.release(), &(messages[i]->data->front()), | 462 &(messages[i]->data->front()), |
| 459 messages[i]->data->size()); | 463 messages[i]->data->size()); |
| 460 break; | 464 break; |
| 461 } | 465 } |
| 462 default: { | 466 default: { |
| 463 NOTREACHED(); | 467 NOTREACHED(); |
| 464 break; | 468 break; |
| 465 } | 469 } |
| 466 } | 470 } |
| 467 } | 471 } |
| 468 } | 472 } |
| 469 | 473 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 PresentationDispatcher::AvailabilityStatus::AvailabilityStatus( | 547 PresentationDispatcher::AvailabilityStatus::AvailabilityStatus( |
| 544 const GURL& availability_url) | 548 const GURL& availability_url) |
| 545 : url(availability_url), | 549 : url(availability_url), |
| 546 last_known_availability(false), | 550 last_known_availability(false), |
| 547 listening_state(ListeningState::INACTIVE) {} | 551 listening_state(ListeningState::INACTIVE) {} |
| 548 | 552 |
| 549 PresentationDispatcher::AvailabilityStatus::~AvailabilityStatus() { | 553 PresentationDispatcher::AvailabilityStatus::~AvailabilityStatus() { |
| 550 } | 554 } |
| 551 | 555 |
| 552 } // namespace content | 556 } // namespace content |
| OLD | NEW |