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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 } | 75 } |
| 75 } | 76 } |
| 76 | 77 |
| 77 } // namespace | 78 } // namespace |
| 78 | 79 |
| 79 namespace content { | 80 namespace content { |
| 80 | 81 |
| 81 PresentationDispatcher::PresentationDispatcher(RenderFrame* render_frame) | 82 PresentationDispatcher::PresentationDispatcher(RenderFrame* render_frame) |
| 82 : RenderFrameObserver(render_frame), | 83 : RenderFrameObserver(render_frame), |
| 83 controller_(nullptr), | 84 controller_(nullptr), |
| 84 binding_(this) { | 85 receiver_(nullptr), |
| 85 } | 86 binding_(this) {} |
| 86 | 87 |
| 87 PresentationDispatcher::~PresentationDispatcher() { | 88 PresentationDispatcher::~PresentationDispatcher() { |
| 88 // Controller should be destroyed before the dispatcher when frame is | 89 // Controller should be destroyed before the dispatcher when frame is |
| 89 // destroyed. | 90 // destroyed. |
| 90 DCHECK(!controller_); | 91 DCHECK(!controller_); |
| 91 } | 92 } |
| 92 | 93 |
| 93 void PresentationDispatcher::setController( | 94 void PresentationDispatcher::setController( |
| 94 blink::WebPresentationController* controller) { | 95 blink::WebPresentationController* controller) { |
| 95 // There shouldn't be any swapping from one non-null controller to another. | 96 // 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... | |
| 368 } | 369 } |
| 369 status->availability_callbacks.Clear(); | 370 status->availability_callbacks.Clear(); |
| 370 UpdateListeningState(status); | 371 UpdateListeningState(status); |
| 371 } | 372 } |
| 372 | 373 |
| 373 void PresentationDispatcher::OnDefaultSessionStarted( | 374 void PresentationDispatcher::OnDefaultSessionStarted( |
| 374 blink::mojom::PresentationSessionInfoPtr session_info) { | 375 blink::mojom::PresentationSessionInfoPtr session_info) { |
| 375 if (!controller_) | 376 if (!controller_) |
| 376 return; | 377 return; |
| 377 | 378 |
| 378 if (!session_info.is_null()) { | 379 if (session_info.is_null()) |
| 379 presentation_service_->ListenForSessionMessages(session_info.Clone()); | 380 return; |
| 380 controller_->didStartDefaultSession( | 381 |
| 381 new PresentationConnectionClient(std::move(session_info))); | 382 presentation_service_->ListenForSessionMessages(session_info.Clone()); |
|
imcheng
2016/11/01 17:20:30
It seems we shouldn't be listening for messages fr
zhaobin
2016/11/02 03:55:48
Done.
| |
| 382 } | 383 |
| 384 controller_->didStartDefaultSession(new PresentationConnectionClient( | |
| 385 session_info.Clone(), | |
| 386 CreateAndSetControllerConnectionProxy(session_info.Clone()))); | |
| 383 } | 387 } |
| 384 | 388 |
| 385 void PresentationDispatcher::OnSessionCreated( | 389 void PresentationDispatcher::OnSessionCreated( |
| 386 blink::WebPresentationConnectionClientCallbacks* callback, | 390 blink::WebPresentationConnectionClientCallbacks* callback, |
| 387 blink::mojom::PresentationSessionInfoPtr session_info, | 391 blink::mojom::PresentationSessionInfoPtr session_info, |
| 388 blink::mojom::PresentationErrorPtr error) { | 392 blink::mojom::PresentationErrorPtr error) { |
| 389 DCHECK(callback); | 393 DCHECK(callback); |
| 390 if (!error.is_null()) { | 394 if (!error.is_null()) { |
| 391 DCHECK(session_info.is_null()); | 395 DCHECK(session_info.is_null()); |
| 392 callback->onError(blink::WebPresentationError( | 396 callback->onError(blink::WebPresentationError( |
| 393 GetWebPresentationErrorTypeFromMojo(error->error_type), | 397 GetWebPresentationErrorTypeFromMojo(error->error_type), |
| 394 blink::WebString::fromUTF8(error->message))); | 398 blink::WebString::fromUTF8(error->message))); |
| 395 return; | 399 return; |
| 396 } | 400 } |
| 397 | 401 |
| 398 DCHECK(!session_info.is_null()); | 402 DCHECK(!session_info.is_null()); |
| 399 presentation_service_->ListenForSessionMessages(session_info.Clone()); | 403 presentation_service_->ListenForSessionMessages(session_info.Clone()); |
|
imcheng
2016/11/01 17:20:30
ditto
zhaobin
2016/11/02 03:55:48
Done.
| |
| 400 callback->onSuccess( | 404 |
| 401 base::MakeUnique<PresentationConnectionClient>(std::move(session_info))); | 405 callback->onSuccess(base::MakeUnique<PresentationConnectionClient>( |
| 406 session_info.Clone(), | |
| 407 CreateAndSetControllerConnectionProxy(session_info.Clone()))); | |
| 402 } | 408 } |
| 403 | 409 |
| 404 void PresentationDispatcher::OnReceiverConnectionAvailable( | 410 void PresentationDispatcher::OnReceiverConnectionAvailable( |
| 405 blink::mojom::PresentationSessionInfoPtr session_info) { | 411 blink::mojom::PresentationSessionInfoPtr session_info, |
| 406 if (receiver_) { | 412 blink::mojom::PresentationConnectionPtr controller) { |
| 407 receiver_->onReceiverConnectionAvailable( | 413 DCHECK(receiver_); |
| 408 new PresentationConnectionClient(std::move(session_info))); | 414 |
| 409 } | 415 std::unique_ptr<PresentationConnectionProxy> receiver_connection_proxy = |
| 416 base::MakeUnique<PresentationConnectionProxy>(); | |
| 417 | |
| 418 controller->SetTargetConnection(receiver_connection_proxy->Bind()); | |
| 419 receiver_connection_proxy->SetTargetConnection(std::move(controller)); | |
| 420 // Bind receiver_connection_proxy with PresentationConnection | |
| 421 // in receiver page. | |
| 422 receiver_->onReceiverConnectionAvailable(new PresentationConnectionClient( | |
| 423 std::move(session_info), std::move(receiver_connection_proxy))); | |
| 410 } | 424 } |
| 411 | 425 |
| 412 void PresentationDispatcher::OnConnectionStateChanged( | 426 void PresentationDispatcher::OnConnectionStateChanged( |
| 413 blink::mojom::PresentationSessionInfoPtr connection, | 427 blink::mojom::PresentationSessionInfoPtr connection, |
| 414 blink::mojom::PresentationConnectionState state) { | 428 blink::mojom::PresentationConnectionState state) { |
| 415 if (!controller_) | 429 if (!controller_) |
| 416 return; | 430 return; |
| 417 | 431 |
| 418 DCHECK(!connection.is_null()); | 432 DCHECK(!connection.is_null()); |
| 419 controller_->didChangeSessionState( | 433 controller_->didChangeSessionState( |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 489 ConnectToPresentationServiceIfNeeded(); | 503 ConnectToPresentationServiceIfNeeded(); |
| 490 if (should_listen) { | 504 if (should_listen) { |
| 491 status->listening_state = ListeningState::WAITING; | 505 status->listening_state = ListeningState::WAITING; |
| 492 presentation_service_->ListenForScreenAvailability(status->url); | 506 presentation_service_->ListenForScreenAvailability(status->url); |
| 493 } else { | 507 } else { |
| 494 status->listening_state = ListeningState::INACTIVE; | 508 status->listening_state = ListeningState::INACTIVE; |
| 495 presentation_service_->StopListeningForScreenAvailability(status->url); | 509 presentation_service_->StopListeningForScreenAvailability(status->url); |
| 496 } | 510 } |
| 497 } | 511 } |
| 498 | 512 |
| 513 std::unique_ptr<PresentationConnectionProxy> | |
| 514 PresentationDispatcher::CreateAndSetControllerConnectionProxy( | |
| 515 blink::mojom::PresentationSessionInfoPtr session_info) { | |
| 516 if (session_info->is_offscreen) { | |
| 517 std::unique_ptr<PresentationConnectionProxy> controller_connection_proxy = | |
| 518 base::MakeUnique<PresentationConnectionProxy>(); | |
| 519 // Pass controller_connection_proxy to PSImpl and register | |
| 520 // it with OffscreenPresentationManager. | |
| 521 presentation_service_->SetPresentationConnection( | |
| 522 session_info.Clone(), controller_connection_proxy->Bind()); | |
| 523 | |
| 524 return controller_connection_proxy; | |
| 525 } | |
| 526 return nullptr; | |
| 527 } | |
| 528 | |
| 529 // static | |
| 530 blink::mojom::SessionMessagePtr PresentationDispatcher::ToMojoTextMessage( | |
| 531 const blink::WebString& message) { | |
| 532 blink::mojom::SessionMessagePtr session_message = | |
| 533 blink::mojom::SessionMessage::New(); | |
| 534 session_message->type = blink::mojom::PresentationMessageType::TEXT; | |
| 535 session_message->message = message.utf8(); | |
| 536 return session_message; | |
| 537 } | |
| 538 | |
| 539 // static | |
| 540 blink::mojom::SessionMessagePtr PresentationDispatcher::ToMojoBinaryMessage( | |
| 541 blink::mojom::PresentationMessageType type, | |
| 542 const uint8_t* data, | |
| 543 size_t length) { | |
| 544 blink::mojom::SessionMessagePtr session_message = | |
| 545 blink::mojom::SessionMessage::New(); | |
| 546 session_message->type = type; | |
| 547 session_message->data = std::vector<uint8_t>(data, data + length); | |
| 548 return session_message; | |
| 549 } | |
| 550 | |
| 499 PresentationDispatcher::SendMessageRequest::SendMessageRequest( | 551 PresentationDispatcher::SendMessageRequest::SendMessageRequest( |
| 500 blink::mojom::PresentationSessionInfoPtr session_info, | 552 blink::mojom::PresentationSessionInfoPtr session_info, |
| 501 blink::mojom::SessionMessagePtr message) | 553 blink::mojom::SessionMessagePtr message) |
| 502 : session_info(std::move(session_info)), message(std::move(message)) {} | 554 : session_info(std::move(session_info)), message(std::move(message)) {} |
| 503 | 555 |
| 504 PresentationDispatcher::SendMessageRequest::~SendMessageRequest() {} | 556 PresentationDispatcher::SendMessageRequest::~SendMessageRequest() {} |
| 505 | 557 |
| 506 // static | 558 // static |
| 507 PresentationDispatcher::SendMessageRequest* | 559 PresentationDispatcher::SendMessageRequest* |
| 508 PresentationDispatcher::CreateSendTextMessageRequest( | 560 PresentationDispatcher::CreateSendTextMessageRequest( |
| 509 const blink::WebURL& presentationUrl, | 561 const blink::WebURL& presentationUrl, |
| 510 const blink::WebString& presentationId, | 562 const blink::WebString& presentationId, |
| 511 const blink::WebString& message) { | 563 const blink::WebString& message) { |
| 512 blink::mojom::PresentationSessionInfoPtr session_info = | 564 blink::mojom::PresentationSessionInfoPtr session_info = |
| 513 blink::mojom::PresentationSessionInfo::New(); | 565 blink::mojom::PresentationSessionInfo::New(); |
| 514 session_info->url = presentationUrl; | 566 session_info->url = presentationUrl; |
| 515 session_info->id = presentationId.utf8(); | 567 session_info->id = presentationId.utf8(); |
| 516 | 568 |
| 517 blink::mojom::SessionMessagePtr session_message = | |
| 518 blink::mojom::SessionMessage::New(); | |
| 519 session_message->type = blink::mojom::PresentationMessageType::TEXT; | |
| 520 session_message->message = message.utf8(); | |
| 521 return new SendMessageRequest(std::move(session_info), | 569 return new SendMessageRequest(std::move(session_info), |
| 522 std::move(session_message)); | 570 ToMojoTextMessage(message)); |
| 523 } | 571 } |
| 524 | 572 |
| 525 // static | 573 // static |
| 526 PresentationDispatcher::SendMessageRequest* | 574 PresentationDispatcher::SendMessageRequest* |
| 527 PresentationDispatcher::CreateSendBinaryMessageRequest( | 575 PresentationDispatcher::CreateSendBinaryMessageRequest( |
| 528 const blink::WebURL& presentationUrl, | 576 const blink::WebURL& presentationUrl, |
| 529 const blink::WebString& presentationId, | 577 const blink::WebString& presentationId, |
| 530 blink::mojom::PresentationMessageType type, | 578 blink::mojom::PresentationMessageType type, |
| 531 const uint8_t* data, | 579 const uint8_t* data, |
| 532 size_t length) { | 580 size_t length) { |
| 533 blink::mojom::PresentationSessionInfoPtr session_info = | 581 blink::mojom::PresentationSessionInfoPtr session_info = |
| 534 blink::mojom::PresentationSessionInfo::New(); | 582 blink::mojom::PresentationSessionInfo::New(); |
| 535 session_info->url = presentationUrl; | 583 session_info->url = presentationUrl; |
| 536 session_info->id = presentationId.utf8(); | 584 session_info->id = presentationId.utf8(); |
| 537 | 585 |
| 538 blink::mojom::SessionMessagePtr session_message = | |
| 539 blink::mojom::SessionMessage::New(); | |
| 540 session_message->type = type; | |
| 541 session_message->data = std::vector<uint8_t>(data, data + length); | |
| 542 return new SendMessageRequest(std::move(session_info), | 586 return new SendMessageRequest(std::move(session_info), |
| 543 std::move(session_message)); | 587 ToMojoBinaryMessage(type, data, length)); |
| 544 } | 588 } |
| 545 | 589 |
| 546 PresentationDispatcher::AvailabilityStatus::AvailabilityStatus( | 590 PresentationDispatcher::AvailabilityStatus::AvailabilityStatus( |
| 547 const GURL& availability_url) | 591 const GURL& availability_url) |
| 548 : url(availability_url), | 592 : url(availability_url), |
| 549 last_known_availability(false), | 593 last_known_availability(false), |
| 550 listening_state(ListeningState::INACTIVE) {} | 594 listening_state(ListeningState::INACTIVE) {} |
| 551 | 595 |
| 552 PresentationDispatcher::AvailabilityStatus::~AvailabilityStatus() { | 596 PresentationDispatcher::AvailabilityStatus::~AvailabilityStatus() { |
| 553 } | 597 } |
| 554 | 598 |
| 555 } // namespace content | 599 } // namespace content |
| OLD | NEW |