| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/pepper_player_delegate.h" | 5 #include "content/browser/media/session/pepper_player_delegate.h" |
| 6 | 6 |
| 7 #include "content/browser/frame_host/render_frame_host_impl.h" | 7 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 8 #include "content/browser/media/session/pepper_playback_observer.h" | 8 #include "content/browser/media/session/pepper_playback_observer.h" |
| 9 #include "content/browser/web_contents/web_contents_impl.h" | 9 #include "content/browser/web_contents/web_contents_impl.h" |
| 10 #include "content/common/frame_messages.h" | 10 #include "content/common/frame_messages.h" |
| 11 #include "media/base/media_switches.h" |
| 11 | 12 |
| 12 namespace content { | 13 namespace content { |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 const double kDuckVolume = 0.2f; | 17 const double kDuckVolume = 0.2f; |
| 17 | 18 |
| 19 bool ShouldDuckFlash() { |
| 20 return base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 21 switches::kEnableDefaultMediaSession) == |
| 22 switches::kEnableDefaultMediaSessionDuckFlash; |
| 23 } |
| 24 |
| 18 } // anonymous namespace | 25 } // anonymous namespace |
| 19 | 26 |
| 20 const int PepperPlayerDelegate::kPlayerId = 0; | 27 const int PepperPlayerDelegate::kPlayerId = 0; |
| 21 | 28 |
| 22 PepperPlayerDelegate::PepperPlayerDelegate( | 29 PepperPlayerDelegate::PepperPlayerDelegate( |
| 23 WebContentsImpl* contents, int32_t pp_instance) | 30 WebContentsImpl* contents, int32_t pp_instance) |
| 24 : contents_(contents), | 31 : contents_(contents), |
| 25 pp_instance_(pp_instance) {} | 32 pp_instance_(pp_instance) {} |
| 26 | 33 |
| 27 PepperPlayerDelegate::~PepperPlayerDelegate() = default; | 34 PepperPlayerDelegate::~PepperPlayerDelegate() = default; |
| 28 | 35 |
| 29 void PepperPlayerDelegate::OnSuspend(int player_id) { | 36 void PepperPlayerDelegate::OnSuspend(int player_id) { |
| 37 if (!ShouldDuckFlash()) |
| 38 return; |
| 39 |
| 30 // Pepper player cannot be really suspended. Duck the volume instead. | 40 // Pepper player cannot be really suspended. Duck the volume instead. |
| 31 DCHECK_EQ(player_id, kPlayerId); | 41 DCHECK_EQ(player_id, kPlayerId); |
| 32 SetVolume(player_id, kDuckVolume); | 42 SetVolume(player_id, kDuckVolume); |
| 33 } | 43 } |
| 34 | 44 |
| 35 void PepperPlayerDelegate::OnResume(int player_id) { | 45 void PepperPlayerDelegate::OnResume(int player_id) { |
| 46 if (!ShouldDuckFlash()) |
| 47 return; |
| 48 |
| 36 DCHECK_EQ(player_id, kPlayerId); | 49 DCHECK_EQ(player_id, kPlayerId); |
| 37 SetVolume(player_id, 1.0f); | 50 SetVolume(player_id, 1.0f); |
| 38 } | 51 } |
| 39 | 52 |
| 40 void PepperPlayerDelegate::OnSetVolumeMultiplier(int player_id, | 53 void PepperPlayerDelegate::OnSetVolumeMultiplier(int player_id, |
| 41 double volume_multiplier) { | 54 double volume_multiplier) { |
| 55 if (!ShouldDuckFlash()) |
| 56 return; |
| 57 |
| 42 DCHECK_EQ(player_id, kPlayerId); | 58 DCHECK_EQ(player_id, kPlayerId); |
| 43 SetVolume(player_id, volume_multiplier); | 59 SetVolume(player_id, volume_multiplier); |
| 44 } | 60 } |
| 45 | 61 |
| 46 void PepperPlayerDelegate::SetVolume(int player_id, double volume) { | 62 void PepperPlayerDelegate::SetVolume(int player_id, double volume) { |
| 47 contents_->Send(new FrameMsg_SetPepperVolume( | 63 contents_->Send(new FrameMsg_SetPepperVolume( |
| 48 contents_->GetMainFrame()->routing_id(), pp_instance_, volume)); | 64 contents_->GetMainFrame()->routing_id(), pp_instance_, volume)); |
| 49 } | 65 } |
| 50 | 66 |
| 51 } // namespace content | 67 } // namespace content |
| OLD | NEW |