Chromium Code Reviews| 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" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "content/public/common/presentation_constants.h" | 13 #include "content/public/common/presentation_constants.h" |
| 14 #include "content/public/renderer/render_frame.h" | 14 #include "content/public/renderer/render_frame.h" |
| 15 #include "content/renderer/presentation/presentation_connection_client.h" | 15 #include "content/renderer/presentation/presentation_connection_client.h" |
| 16 #include "content/renderer/presentation/presentation_connection_proxy.h" | |
| 16 #include "services/service_manager/public/cpp/interface_provider.h" | 17 #include "services/service_manager/public/cpp/interface_provider.h" |
| 17 #include "third_party/WebKit/public/platform/WebString.h" | 18 #include "third_party/WebKit/public/platform/WebString.h" |
| 18 #include "third_party/WebKit/public/platform/WebURL.h" | 19 #include "third_party/WebKit/public/platform/WebURL.h" |
| 19 #include "third_party/WebKit/public/platform/WebVector.h" | 20 #include "third_party/WebKit/public/platform/WebVector.h" |
| 20 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nAvailabilityObserver.h" | 21 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nAvailabilityObserver.h" |
| 21 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nController.h" | 22 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nController.h" |
| 22 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nError.h" | 23 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nError.h" |
| 23 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nReceiver.h" | 24 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nReceiver.h" |
| 24 #include "third_party/WebKit/public/platform/modules/presentation/presentation.m ojom.h" | 25 #include "third_party/WebKit/public/platform/modules/presentation/presentation.m ojom.h" |
| 25 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 26 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 case blink::mojom::PresentationConnectionCloseReason::CLOSED: | 69 case blink::mojom::PresentationConnectionCloseReason::CLOSED: |
| 69 return blink::WebPresentationConnectionCloseReason::Closed; | 70 return blink::WebPresentationConnectionCloseReason::Closed; |
| 70 case blink::mojom::PresentationConnectionCloseReason::WENT_AWAY: | 71 case blink::mojom::PresentationConnectionCloseReason::WENT_AWAY: |
| 71 return blink::WebPresentationConnectionCloseReason::WentAway; | 72 return blink::WebPresentationConnectionCloseReason::WentAway; |
| 72 default: | 73 default: |
| 73 NOTREACHED(); | 74 NOTREACHED(); |
| 74 return blink::WebPresentationConnectionCloseReason::Error; | 75 return blink::WebPresentationConnectionCloseReason::Error; |
| 75 } | 76 } |
| 76 } | 77 } |
| 77 | 78 |
| 79 blink::mojom::SessionMessagePtr ToMojoTextMessage( | |
|
mark a. foltz
2016/11/16 01:25:37
We should really implement Mojo type traits for se
| |
| 80 const blink::WebString& message) { | |
| 81 blink::mojom::SessionMessagePtr session_message = | |
| 82 blink::mojom::SessionMessage::New(); | |
| 83 session_message->type = blink::mojom::PresentationMessageType::TEXT; | |
| 84 session_message->message = message.utf8(); | |
| 85 return session_message; | |
| 86 } | |
| 87 | |
| 88 blink::mojom::SessionMessagePtr ToMojoBinaryMessage( | |
| 89 blink::mojom::PresentationMessageType type, | |
| 90 const uint8_t* data, | |
| 91 size_t length) { | |
|
mark a. foltz
2016/11/16 01:25:37
We'd have to implement a converter between blink::
| |
| 92 blink::mojom::SessionMessagePtr session_message = | |
| 93 blink::mojom::SessionMessage::New(); | |
| 94 session_message->type = type; | |
| 95 session_message->data = std::vector<uint8_t>(data, data + length); | |
| 96 return session_message; | |
| 97 } | |
| 98 | |
| 78 } // namespace | 99 } // namespace |
| 79 | 100 |
| 80 namespace content { | 101 namespace content { |
| 81 | 102 |
| 82 PresentationDispatcher::PresentationDispatcher(RenderFrame* render_frame) | 103 PresentationDispatcher::PresentationDispatcher(RenderFrame* render_frame) |
| 83 : RenderFrameObserver(render_frame), | 104 : RenderFrameObserver(render_frame), |
| 84 controller_(nullptr), | 105 controller_(nullptr), |
| 85 binding_(this) { | 106 receiver_(nullptr), |
| 86 } | 107 binding_(this) {} |
| 87 | 108 |
| 88 PresentationDispatcher::~PresentationDispatcher() { | 109 PresentationDispatcher::~PresentationDispatcher() { |
| 89 // Controller should be destroyed before the dispatcher when frame is | 110 // Controller should be destroyed before the dispatcher when frame is |
| 90 // destroyed. | 111 // destroyed. |
| 91 DCHECK(!controller_); | 112 DCHECK(!controller_); |
| 92 } | 113 } |
| 93 | 114 |
| 94 void PresentationDispatcher::setController( | 115 void PresentationDispatcher::setController( |
| 95 blink::WebPresentationController* controller) { | 116 blink::WebPresentationController* controller) { |
| 96 // There shouldn't be any swapping from one non-null controller to another. | 117 // There shouldn't be any swapping from one non-null controller to another. |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 369 } | 390 } |
| 370 status->availability_callbacks.Clear(); | 391 status->availability_callbacks.Clear(); |
| 371 UpdateListeningState(status); | 392 UpdateListeningState(status); |
| 372 } | 393 } |
| 373 | 394 |
| 374 void PresentationDispatcher::OnDefaultSessionStarted( | 395 void PresentationDispatcher::OnDefaultSessionStarted( |
| 375 blink::mojom::PresentationSessionInfoPtr session_info) { | 396 blink::mojom::PresentationSessionInfoPtr session_info) { |
| 376 if (!controller_) | 397 if (!controller_) |
| 377 return; | 398 return; |
| 378 | 399 |
| 379 if (!session_info.is_null()) { | 400 if (session_info.is_null()) |
| 401 return; | |
| 402 | |
| 403 if (!session_info->is_offscreen) | |
| 380 presentation_service_->ListenForSessionMessages(session_info.Clone()); | 404 presentation_service_->ListenForSessionMessages(session_info.Clone()); |
| 381 controller_->didStartDefaultSession( | 405 |
| 382 new PresentationConnectionClient(std::move(session_info))); | 406 controller_->didStartDefaultSession(new PresentationConnectionClient( |
| 383 } | 407 session_info.Clone(), |
| 408 CreateAndSetControllerConnectionProxy(session_info.Clone()))); | |
| 384 } | 409 } |
| 385 | 410 |
| 386 void PresentationDispatcher::OnSessionCreated( | 411 void PresentationDispatcher::OnSessionCreated( |
| 387 blink::WebPresentationConnectionClientCallbacks* callback, | 412 blink::WebPresentationConnectionClientCallbacks* callback, |
| 388 blink::mojom::PresentationSessionInfoPtr session_info, | 413 blink::mojom::PresentationSessionInfoPtr session_info, |
| 389 blink::mojom::PresentationErrorPtr error) { | 414 blink::mojom::PresentationErrorPtr error) { |
| 390 DCHECK(callback); | 415 DCHECK(callback); |
| 391 if (!error.is_null()) { | 416 if (!error.is_null()) { |
| 392 DCHECK(session_info.is_null()); | 417 DCHECK(session_info.is_null()); |
| 393 callback->onError(blink::WebPresentationError( | 418 callback->onError(blink::WebPresentationError( |
| 394 GetWebPresentationErrorTypeFromMojo(error->error_type), | 419 GetWebPresentationErrorTypeFromMojo(error->error_type), |
| 395 blink::WebString::fromUTF8(error->message))); | 420 blink::WebString::fromUTF8(error->message))); |
| 396 return; | 421 return; |
| 397 } | 422 } |
| 398 | 423 |
| 399 DCHECK(!session_info.is_null()); | 424 DCHECK(!session_info.is_null()); |
| 400 presentation_service_->ListenForSessionMessages(session_info.Clone()); | 425 if (!session_info->is_offscreen) |
| 401 callback->onSuccess( | 426 presentation_service_->ListenForSessionMessages(session_info.Clone()); |
| 402 base::MakeUnique<PresentationConnectionClient>(std::move(session_info))); | 427 |
| 428 callback->onSuccess(base::MakeUnique<PresentationConnectionClient>( | |
| 429 session_info.Clone(), | |
| 430 CreateAndSetControllerConnectionProxy(session_info.Clone()))); | |
| 403 } | 431 } |
| 404 | 432 |
| 405 void PresentationDispatcher::OnReceiverConnectionAvailable( | 433 void PresentationDispatcher::OnReceiverConnectionAvailable( |
| 406 blink::mojom::PresentationSessionInfoPtr session_info) { | 434 blink::mojom::PresentationSessionInfoPtr session_info, |
| 407 if (receiver_) { | 435 blink::mojom::PresentationConnectionPtr controller) { |
| 408 receiver_->onReceiverConnectionAvailable( | 436 DCHECK(receiver_); |
| 409 new PresentationConnectionClient(std::move(session_info))); | 437 |
| 410 } | 438 std::unique_ptr<PresentationConnectionProxy> receiver_connection_proxy = |
| 439 base::MakeUnique<PresentationConnectionProxy>(); | |
| 440 | |
| 441 controller->SetTargetConnection(receiver_connection_proxy->Bind()); | |
| 442 receiver_connection_proxy->SetTargetConnection(std::move(controller)); | |
| 443 // Bind receiver_connection_proxy with PresentationConnection | |
| 444 // in receiver page. | |
| 445 receiver_->onReceiverConnectionAvailable(new PresentationConnectionClient( | |
| 446 std::move(session_info), std::move(receiver_connection_proxy))); | |
| 411 } | 447 } |
| 412 | 448 |
| 413 void PresentationDispatcher::OnConnectionStateChanged( | 449 void PresentationDispatcher::OnConnectionStateChanged( |
| 414 blink::mojom::PresentationSessionInfoPtr connection, | 450 blink::mojom::PresentationSessionInfoPtr connection, |
| 415 blink::mojom::PresentationConnectionState state) { | 451 blink::mojom::PresentationConnectionState state) { |
| 416 if (!controller_) | 452 if (!controller_) |
| 417 return; | 453 return; |
| 418 | 454 |
| 419 DCHECK(!connection.is_null()); | 455 DCHECK(!connection.is_null()); |
| 420 controller_->didChangeSessionState( | 456 controller_->didChangeSessionState( |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 490 ConnectToPresentationServiceIfNeeded(); | 526 ConnectToPresentationServiceIfNeeded(); |
| 491 if (should_listen) { | 527 if (should_listen) { |
| 492 status->listening_state = ListeningState::WAITING; | 528 status->listening_state = ListeningState::WAITING; |
| 493 presentation_service_->ListenForScreenAvailability(status->url); | 529 presentation_service_->ListenForScreenAvailability(status->url); |
| 494 } else { | 530 } else { |
| 495 status->listening_state = ListeningState::INACTIVE; | 531 status->listening_state = ListeningState::INACTIVE; |
| 496 presentation_service_->StopListeningForScreenAvailability(status->url); | 532 presentation_service_->StopListeningForScreenAvailability(status->url); |
| 497 } | 533 } |
| 498 } | 534 } |
| 499 | 535 |
| 536 std::unique_ptr<PresentationConnectionProxy> | |
| 537 PresentationDispatcher::CreateAndSetControllerConnectionProxy( | |
| 538 blink::mojom::PresentationSessionInfoPtr session_info) { | |
| 539 if (!session_info->is_offscreen) | |
| 540 return nullptr; | |
| 541 | |
| 542 std::unique_ptr<PresentationConnectionProxy> controller_connection_proxy = | |
| 543 base::MakeUnique<PresentationConnectionProxy>(); | |
| 544 // Pass controller_connection_proxy to PSImpl and register | |
| 545 // it with OffscreenPresentationManager. | |
| 546 presentation_service_->SetPresentationConnection( | |
| 547 session_info.Clone(), controller_connection_proxy->Bind()); | |
| 548 | |
| 549 return controller_connection_proxy; | |
| 550 } | |
| 551 | |
| 500 PresentationDispatcher::SendMessageRequest::SendMessageRequest( | 552 PresentationDispatcher::SendMessageRequest::SendMessageRequest( |
| 501 blink::mojom::PresentationSessionInfoPtr session_info, | 553 blink::mojom::PresentationSessionInfoPtr session_info, |
| 502 blink::mojom::SessionMessagePtr message) | 554 blink::mojom::SessionMessagePtr message) |
| 503 : session_info(std::move(session_info)), message(std::move(message)) {} | 555 : session_info(std::move(session_info)), message(std::move(message)) {} |
| 504 | 556 |
| 505 PresentationDispatcher::SendMessageRequest::~SendMessageRequest() {} | 557 PresentationDispatcher::SendMessageRequest::~SendMessageRequest() {} |
| 506 | 558 |
| 507 // static | 559 // static |
| 508 PresentationDispatcher::SendMessageRequest* | 560 PresentationDispatcher::SendMessageRequest* |
| 509 PresentationDispatcher::CreateSendTextMessageRequest( | 561 PresentationDispatcher::CreateSendTextMessageRequest( |
| 510 const blink::WebURL& presentationUrl, | 562 const blink::WebURL& presentationUrl, |
| 511 const blink::WebString& presentationId, | 563 const blink::WebString& presentationId, |
| 512 const blink::WebString& message) { | 564 const blink::WebString& message) { |
| 513 blink::mojom::PresentationSessionInfoPtr session_info = | 565 blink::mojom::PresentationSessionInfoPtr session_info = |
| 514 blink::mojom::PresentationSessionInfo::New(); | 566 blink::mojom::PresentationSessionInfo::New(); |
| 515 session_info->url = presentationUrl; | 567 session_info->url = presentationUrl; |
| 516 session_info->id = presentationId.utf8(); | 568 session_info->id = presentationId.utf8(); |
| 517 | 569 |
| 518 blink::mojom::SessionMessagePtr session_message = | |
| 519 blink::mojom::SessionMessage::New(); | |
| 520 session_message->type = blink::mojom::PresentationMessageType::TEXT; | |
| 521 session_message->message = message.utf8(); | |
| 522 return new SendMessageRequest(std::move(session_info), | 570 return new SendMessageRequest(std::move(session_info), |
| 523 std::move(session_message)); | 571 ToMojoTextMessage(message)); |
| 524 } | 572 } |
| 525 | 573 |
| 526 // static | 574 // static |
| 527 PresentationDispatcher::SendMessageRequest* | 575 PresentationDispatcher::SendMessageRequest* |
| 528 PresentationDispatcher::CreateSendBinaryMessageRequest( | 576 PresentationDispatcher::CreateSendBinaryMessageRequest( |
| 529 const blink::WebURL& presentationUrl, | 577 const blink::WebURL& presentationUrl, |
| 530 const blink::WebString& presentationId, | 578 const blink::WebString& presentationId, |
| 531 blink::mojom::PresentationMessageType type, | 579 blink::mojom::PresentationMessageType type, |
| 532 const uint8_t* data, | 580 const uint8_t* data, |
| 533 size_t length) { | 581 size_t length) { |
| 534 blink::mojom::PresentationSessionInfoPtr session_info = | 582 blink::mojom::PresentationSessionInfoPtr session_info = |
| 535 blink::mojom::PresentationSessionInfo::New(); | 583 blink::mojom::PresentationSessionInfo::New(); |
| 536 session_info->url = presentationUrl; | 584 session_info->url = presentationUrl; |
| 537 session_info->id = presentationId.utf8(); | 585 session_info->id = presentationId.utf8(); |
| 538 | 586 |
| 539 blink::mojom::SessionMessagePtr session_message = | |
| 540 blink::mojom::SessionMessage::New(); | |
| 541 session_message->type = type; | |
| 542 session_message->data = std::vector<uint8_t>(data, data + length); | |
| 543 return new SendMessageRequest(std::move(session_info), | 587 return new SendMessageRequest(std::move(session_info), |
| 544 std::move(session_message)); | 588 ToMojoBinaryMessage(type, data, length)); |
| 545 } | 589 } |
| 546 | 590 |
| 547 PresentationDispatcher::AvailabilityStatus::AvailabilityStatus( | 591 PresentationDispatcher::AvailabilityStatus::AvailabilityStatus( |
| 548 const GURL& availability_url) | 592 const GURL& availability_url) |
| 549 : url(availability_url), | 593 : url(availability_url), |
| 550 last_known_availability(false), | 594 last_known_availability(false), |
| 551 listening_state(ListeningState::INACTIVE) {} | 595 listening_state(ListeningState::INACTIVE) {} |
| 552 | 596 |
| 553 PresentationDispatcher::AvailabilityStatus::~AvailabilityStatus() { | 597 PresentationDispatcher::AvailabilityStatus::~AvailabilityStatus() { |
| 554 } | 598 } |
| 555 | 599 |
| 556 } // namespace content | 600 } // namespace content |
| OLD | NEW |