| 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/browser/media/session/media_session_impl.h" | 5 #include "content/browser/media/session/media_session_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include "content/browser/media/session/audio_focus_delegate.h" | 8 #include "content/browser/media/session/audio_focus_delegate.h" |
| 9 #include "content/browser/media/session/media_session_controller.h" | 9 #include "content/browser/media/session/media_session_controller.h" |
| 10 #include "content/browser/media/session/media_session_player_observer.h" | 10 #include "content/browser/media/session/media_session_player_observer.h" |
| (...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 void MediaSessionImpl::OnMediaSessionActionsChanged( | 604 void MediaSessionImpl::OnMediaSessionActionsChanged( |
| 605 MediaSessionServiceImpl* service) { | 605 MediaSessionServiceImpl* service) { |
| 606 if (service != routed_service_) | 606 if (service != routed_service_) |
| 607 return; | 607 return; |
| 608 | 608 |
| 609 NotifyMediaSessionActionsChange(routed_service_->actions()); | 609 NotifyMediaSessionActionsChange(routed_service_->actions()); |
| 610 } | 610 } |
| 611 | 611 |
| 612 void MediaSessionImpl::DidReceiveAction( | 612 void MediaSessionImpl::DidReceiveAction( |
| 613 blink::mojom::MediaSessionAction action) { | 613 blink::mojom::MediaSessionAction action) { |
| 614 // Pause all players in non-routed frames if the action is PAUSE. |
| 615 // |
| 616 // This is the default PAUSE action handler per Media Session API spec. The |
| 617 // reason for pausing all players in all other sessions is to avoid the |
| 618 // players in other frames keep the session active so that the UI will always |
| 619 // show the pause button but it does not pause anything (as the routed frame |
| 620 // already pauses when responding to the PAUSE action while other frames does |
| 621 // not). |
| 622 // |
| 623 // TODO(zqzhang): Currently, this might not work well on desktop as Pepper and |
| 624 // OneShot players are not really suspended, so that the session is still |
| 625 // active after this. See https://crbug.com/619084 and |
| 626 // https://crbug.com/596516. |
| 627 if (blink::mojom::MediaSessionAction::PAUSE == action) { |
| 628 RenderFrameHost* rfh_of_routed_service = |
| 629 routed_service_->GetRenderFrameHost(); |
| 630 for (const auto& player : normal_players_) { |
| 631 if (player.observer->GetRenderFrameHost() != rfh_of_routed_service) |
| 632 player.observer->OnSuspend(player.player_id); |
| 633 } |
| 634 for (const auto& player : pepper_players_) { |
| 635 if (player.observer->GetRenderFrameHost() != rfh_of_routed_service) { |
| 636 player.observer->OnSetVolumeMultiplier(player.player_id, |
| 637 kDuckingVolumeMultiplier); |
| 638 } |
| 639 } |
| 640 for (const auto& player : one_shot_players_) { |
| 641 if (player.observer->GetRenderFrameHost() != rfh_of_routed_service) |
| 642 player.observer->OnSuspend(player.player_id); |
| 643 } |
| 644 } |
| 645 |
| 614 if (!routed_service_) | 646 if (!routed_service_) |
| 615 return; | 647 return; |
| 616 | 648 |
| 617 routed_service_->GetClient()->DidReceiveAction(action); | 649 routed_service_->GetClient()->DidReceiveAction(action); |
| 618 } | 650 } |
| 619 | 651 |
| 620 bool MediaSessionImpl::IsServiceActiveForRenderFrameHost(RenderFrameHost* rfh) { | 652 bool MediaSessionImpl::IsServiceActiveForRenderFrameHost(RenderFrameHost* rfh) { |
| 621 return services_.find(rfh) != services_.end(); | 653 return services_.find(rfh) != services_.end(); |
| 622 } | 654 } |
| 623 | 655 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 if (!IsServiceActiveForRenderFrameHost(frame)) | 700 if (!IsServiceActiveForRenderFrameHost(frame)) |
| 669 continue; | 701 continue; |
| 670 best_frame = frame; | 702 best_frame = frame; |
| 671 min_depth = depth; | 703 min_depth = depth; |
| 672 } | 704 } |
| 673 | 705 |
| 674 return best_frame ? services_[best_frame] : nullptr; | 706 return best_frame ? services_[best_frame] : nullptr; |
| 675 } | 707 } |
| 676 | 708 |
| 677 } // namespace content | 709 } // namespace content |
| OLD | NEW |