| 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 <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 void PresentationDispatcher::OnDefaultPresentationStarted( | 528 void PresentationDispatcher::OnDefaultPresentationStarted( |
| 529 const PresentationInfo& presentation_info) { | 529 const PresentationInfo& presentation_info) { |
| 530 if (!controller_) | 530 if (!controller_) |
| 531 return; | 531 return; |
| 532 | 532 |
| 533 auto* connection = | 533 auto* connection = |
| 534 controller_->DidStartDefaultPresentation(blink::WebPresentationInfo( | 534 controller_->DidStartDefaultPresentation(blink::WebPresentationInfo( |
| 535 presentation_info.presentation_url, | 535 presentation_info.presentation_url, |
| 536 blink::WebString::FromUTF8(presentation_info.presentation_id))); | 536 blink::WebString::FromUTF8(presentation_info.presentation_id))); |
| 537 | 537 |
| 538 if (connection) { | 538 if (connection) |
| 539 SetControllerConnection(presentation_info, connection); | 539 SetControllerConnection(presentation_info, connection); |
| 540 // Change blink connection state to 'connected' before listening to | |
| 541 // connection message. Remove ListenForConnectionMessage() after | |
| 542 // TODO(crbug.com/687011): use BrowserPresentationConnectionProxy to send | |
| 543 // message from route to blink connection. | |
| 544 presentation_service_->ListenForConnectionMessages(presentation_info); | |
| 545 } | |
| 546 } | 540 } |
| 547 | 541 |
| 548 void PresentationDispatcher::OnConnectionCreated( | 542 void PresentationDispatcher::OnConnectionCreated( |
| 549 std::unique_ptr<blink::WebPresentationConnectionCallbacks> callback, | 543 std::unique_ptr<blink::WebPresentationConnectionCallbacks> callback, |
| 550 const base::Optional<PresentationInfo>& presentation_info, | 544 const base::Optional<PresentationInfo>& presentation_info, |
| 551 const base::Optional<PresentationError>& error) { | 545 const base::Optional<PresentationError>& error) { |
| 552 DCHECK(callback); | 546 DCHECK(callback); |
| 553 if (error) { | 547 if (error) { |
| 554 DCHECK(!presentation_info); | 548 DCHECK(!presentation_info); |
| 555 callback->OnError(blink::WebPresentationError( | 549 callback->OnError(blink::WebPresentationError( |
| 556 GetWebPresentationErrorType(error->error_type), | 550 GetWebPresentationErrorType(error->error_type), |
| 557 blink::WebString::FromUTF8(error->message))); | 551 blink::WebString::FromUTF8(error->message))); |
| 558 return; | 552 return; |
| 559 } | 553 } |
| 560 | 554 |
| 561 DCHECK(presentation_info); | 555 DCHECK(presentation_info); |
| 562 callback->OnSuccess(blink::WebPresentationInfo( | 556 callback->OnSuccess(blink::WebPresentationInfo( |
| 563 presentation_info->presentation_url, | 557 presentation_info->presentation_url, |
| 564 blink::WebString::FromUTF8(presentation_info->presentation_id))); | 558 blink::WebString::FromUTF8(presentation_info->presentation_id))); |
| 565 // Change blink connection state to 'connected' before listening to | |
| 566 // connection message. Remove ListenForConnectionMessage() after | |
| 567 // TODO(crbug.com/687011): use BrowserPresentationConnectionProxy to send | |
| 568 // message from route to blink connection. | |
| 569 SetControllerConnection(presentation_info.value(), callback->GetConnection()); | 559 SetControllerConnection(presentation_info.value(), callback->GetConnection()); |
| 570 presentation_service_->ListenForConnectionMessages(presentation_info.value()); | |
| 571 } | 560 } |
| 572 | 561 |
| 573 void PresentationDispatcher::OnReceiverConnectionAvailable( | 562 void PresentationDispatcher::OnReceiverConnectionAvailable( |
| 574 const PresentationInfo& presentation_info, | 563 const PresentationInfo& presentation_info, |
| 575 blink::mojom::PresentationConnectionPtr controller_connection_ptr, | 564 blink::mojom::PresentationConnectionPtr controller_connection_ptr, |
| 576 blink::mojom::PresentationConnectionRequest receiver_connection_request) { | 565 blink::mojom::PresentationConnectionRequest receiver_connection_request) { |
| 577 DCHECK(receiver_); | 566 DCHECK(receiver_); |
| 578 | 567 |
| 579 // Bind receiver_connection_proxy with PresentationConnection in receiver | 568 // Bind receiver_connection_proxy with PresentationConnection in receiver |
| 580 // page. | 569 // page. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 return; | 601 return; |
| 613 | 602 |
| 614 controller_->DidCloseConnection( | 603 controller_->DidCloseConnection( |
| 615 blink::WebPresentationInfo( | 604 blink::WebPresentationInfo( |
| 616 presentation_info.presentation_url, | 605 presentation_info.presentation_url, |
| 617 blink::WebString::FromUTF8(presentation_info.presentation_id)), | 606 blink::WebString::FromUTF8(presentation_info.presentation_id)), |
| 618 GetWebPresentationConnectionCloseReason(reason), | 607 GetWebPresentationConnectionCloseReason(reason), |
| 619 blink::WebString::FromUTF8(message)); | 608 blink::WebString::FromUTF8(message)); |
| 620 } | 609 } |
| 621 | 610 |
| 622 void PresentationDispatcher::OnConnectionMessagesReceived( | |
| 623 const PresentationInfo& presentation_info, | |
| 624 std::vector<PresentationConnectionMessage> messages) { | |
| 625 if (!controller_) | |
| 626 return; | |
| 627 | |
| 628 for (size_t i = 0; i < messages.size(); ++i) { | |
| 629 // Note: Passing batches of messages to the Blink layer would be more | |
| 630 // efficient. | |
| 631 auto web_presentation_info = blink::WebPresentationInfo( | |
| 632 presentation_info.presentation_url, | |
| 633 blink::WebString::FromUTF8(presentation_info.presentation_id)); | |
| 634 | |
| 635 if (messages[i].is_binary()) { | |
| 636 controller_->DidReceiveConnectionBinaryMessage( | |
| 637 web_presentation_info, &(messages[i].data->front()), | |
| 638 messages[i].data->size()); | |
| 639 } else { | |
| 640 DCHECK(messages[i].message); | |
| 641 controller_->DidReceiveConnectionTextMessage( | |
| 642 web_presentation_info, | |
| 643 blink::WebString::FromUTF8(*messages[i].message)); | |
| 644 } | |
| 645 } | |
| 646 } | |
| 647 | |
| 648 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { | 611 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { |
| 649 if (presentation_service_.get()) | 612 if (presentation_service_.get()) |
| 650 return; | 613 return; |
| 651 | 614 |
| 652 render_frame()->GetRemoteInterfaces()->GetInterface(&presentation_service_); | 615 render_frame()->GetRemoteInterfaces()->GetInterface(&presentation_service_); |
| 653 blink::mojom::PresentationServiceClientPtr client; | 616 blink::mojom::PresentationServiceClientPtr client; |
| 654 binding_.Bind(mojo::MakeRequest(&client)); | 617 binding_.Bind(mojo::MakeRequest(&client)); |
| 655 presentation_service_->SetClient(std::move(client)); | 618 presentation_service_->SetClient(std::move(client)); |
| 656 } | 619 } |
| 657 | 620 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 818 | 781 |
| 819 PresentationDispatcher::ListeningStatus::ListeningStatus( | 782 PresentationDispatcher::ListeningStatus::ListeningStatus( |
| 820 const GURL& availability_url) | 783 const GURL& availability_url) |
| 821 : url(availability_url), | 784 : url(availability_url), |
| 822 last_known_availability(blink::mojom::ScreenAvailability::UNKNOWN), | 785 last_known_availability(blink::mojom::ScreenAvailability::UNKNOWN), |
| 823 listening_state(ListeningState::INACTIVE) {} | 786 listening_state(ListeningState::INACTIVE) {} |
| 824 | 787 |
| 825 PresentationDispatcher::ListeningStatus::~ListeningStatus() {} | 788 PresentationDispatcher::ListeningStatus::~ListeningStatus() {} |
| 826 | 789 |
| 827 } // namespace content | 790 } // namespace content |
| OLD | NEW |