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/shell/public/cpp/interface_provider.h" | 17 #include "services/shell/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()); |
| 383 | |
| 384 std::unique_ptr<PresentationConnectionProxy> controller_connection_proxy = | |
| 385 nullptr; | |
| 386 if (session_info->is_offscreen_presentation) { | |
|
mark a. foltz
2016/10/21 00:53:03
Can you factor out the common code to create and s
zhaobin
2016/10/22 02:44:13
Done.
| |
| 387 controller_connection_proxy = | |
| 388 base::MakeUnique<PresentationConnectionProxy>(); | |
| 389 // Pass controller_connection_proxy to PSImpl and register | |
| 390 // it with OffscreenPresentationManager. | |
| 391 presentation_service_->SetPresentationConnection( | |
| 392 session_info.Clone(), controller_connection_proxy->Bind()); | |
| 382 } | 393 } |
| 394 controller_->didStartDefaultSession(new PresentationConnectionClient( | |
| 395 std::move(session_info), std::move(controller_connection_proxy))); | |
|
mark a. foltz
2016/10/21 00:53:03
Is it legal to std::move(nullptr)?
zhaobin
2016/10/22 02:44:13
It works fine...
| |
| 383 } | 396 } |
| 384 | 397 |
| 385 void PresentationDispatcher::OnSessionCreated( | 398 void PresentationDispatcher::OnSessionCreated( |
| 386 blink::WebPresentationConnectionClientCallbacks* callback, | 399 blink::WebPresentationConnectionClientCallbacks* callback, |
| 387 blink::mojom::PresentationSessionInfoPtr session_info, | 400 blink::mojom::PresentationSessionInfoPtr session_info, |
| 388 blink::mojom::PresentationErrorPtr error) { | 401 blink::mojom::PresentationErrorPtr error) { |
| 389 DCHECK(callback); | 402 DCHECK(callback); |
| 390 if (!error.is_null()) { | 403 if (!error.is_null()) { |
| 391 DCHECK(session_info.is_null()); | 404 DCHECK(session_info.is_null()); |
| 392 callback->onError(blink::WebPresentationError( | 405 callback->onError(blink::WebPresentationError( |
| 393 GetWebPresentationErrorTypeFromMojo(error->error_type), | 406 GetWebPresentationErrorTypeFromMojo(error->error_type), |
| 394 blink::WebString::fromUTF8(error->message))); | 407 blink::WebString::fromUTF8(error->message))); |
| 395 return; | 408 return; |
| 396 } | 409 } |
| 397 | 410 |
| 398 DCHECK(!session_info.is_null()); | 411 DCHECK(!session_info.is_null()); |
| 399 presentation_service_->ListenForSessionMessages(session_info.Clone()); | 412 presentation_service_->ListenForSessionMessages(session_info.Clone()); |
| 400 callback->onSuccess( | 413 |
| 401 base::MakeUnique<PresentationConnectionClient>(std::move(session_info))); | 414 std::unique_ptr<PresentationConnectionProxy> controller_connection_proxy = |
| 415 nullptr; | |
| 416 if (session_info->is_offscreen_presentation) { | |
| 417 controller_connection_proxy = | |
| 418 base::MakeUnique<PresentationConnectionProxy>(); | |
| 419 // Pass controller_connection_proxy to PSImpl and register | |
| 420 // it with OffscreenPresentationManager. | |
| 421 presentation_service_->SetPresentationConnection( | |
| 422 session_info.Clone(), controller_connection_proxy->Bind()); | |
| 423 } | |
| 424 // Bind controller_connection_proxy with PresentationConnection | |
| 425 // on controller page. | |
| 426 callback->onSuccess(base::MakeUnique<PresentationConnectionClient>( | |
| 427 session_info.Clone(), std::move(controller_connection_proxy))); | |
| 402 } | 428 } |
| 403 | 429 |
| 404 void PresentationDispatcher::OnReceiverConnectionAvailable( | 430 void PresentationDispatcher::OnReceiverConnectionAvailable( |
| 405 blink::mojom::PresentationSessionInfoPtr session_info) { | 431 blink::mojom::PresentationSessionInfoPtr session_info, |
| 406 if (receiver_) { | 432 blink::mojom::PresentationConnectionPtr controller) { |
| 407 receiver_->onReceiverConnectionAvailable( | 433 if (!receiver_) |
| 408 new PresentationConnectionClient(std::move(session_info))); | 434 return; |
|
mark a. foltz
2016/10/21 00:53:03
This seems like a bug, so DCHECK(). IIUC this must
zhaobin
2016/10/22 02:44:13
Done.
| |
| 409 } | 435 |
| 436 std::unique_ptr<PresentationConnectionProxy> receiver_connection_proxy = | |
| 437 base::MakeUnique<PresentationConnectionProxy>(); | |
| 438 | |
| 439 controller->SetTargetConnection(receiver_connection_proxy->Bind()); | |
| 440 receiver_connection_proxy->SetTargetConnection(std::move(controller)); | |
| 441 // Bind receiver_connection_proxy with PresentationConnection | |
| 442 // in receiver page. | |
| 443 receiver_->onReceiverConnectionAvailable(new PresentationConnectionClient( | |
| 444 std::move(session_info), std::move(receiver_connection_proxy))); | |
| 410 } | 445 } |
| 411 | 446 |
| 412 void PresentationDispatcher::OnConnectionStateChanged( | 447 void PresentationDispatcher::OnConnectionStateChanged( |
| 413 blink::mojom::PresentationSessionInfoPtr connection, | 448 blink::mojom::PresentationSessionInfoPtr connection, |
| 414 blink::mojom::PresentationConnectionState state) { | 449 blink::mojom::PresentationConnectionState state) { |
| 415 if (!controller_) | 450 if (!controller_) |
| 416 return; | 451 return; |
| 417 | 452 |
| 418 DCHECK(!connection.is_null()); | 453 DCHECK(!connection.is_null()); |
| 419 controller_->didChangeSessionState( | 454 controller_->didChangeSessionState( |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 546 PresentationDispatcher::AvailabilityStatus::AvailabilityStatus( | 581 PresentationDispatcher::AvailabilityStatus::AvailabilityStatus( |
| 547 const GURL& availability_url) | 582 const GURL& availability_url) |
| 548 : url(availability_url), | 583 : url(availability_url), |
| 549 last_known_availability(false), | 584 last_known_availability(false), |
| 550 listening_state(ListeningState::INACTIVE) {} | 585 listening_state(ListeningState::INACTIVE) {} |
| 551 | 586 |
| 552 PresentationDispatcher::AvailabilityStatus::~AvailabilityStatus() { | 587 PresentationDispatcher::AvailabilityStatus::~AvailabilityStatus() { |
| 553 } | 588 } |
| 554 | 589 |
| 555 } // namespace content | 590 } // namespace content |
| OLD | NEW |