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/android/browser_media_session_manager.h" | 5 #include "content/browser/media/android/browser_media_session_manager.h" |
6 | 6 |
7 #include "content/common/media/media_session_messages_android.h" | 7 #include "content/common/media/media_session_messages_android.h" |
8 #include "content/public/browser/render_frame_host.h" | 8 #include "content/public/browser/render_frame_host.h" |
9 | 9 |
10 namespace content { | 10 namespace content { |
11 | 11 |
12 BrowserMediaSessionManager::BrowserMediaSessionManager( | 12 BrowserMediaSessionManager::BrowserMediaSessionManager( |
13 RenderFrameHost* render_frame_host) | 13 RenderFrameHost* render_frame_host) |
14 : render_frame_host_(render_frame_host) {} | 14 : render_frame_host_(render_frame_host) {} |
15 | 15 |
| 16 MediaSession* BrowserMediaSessionManager::GetSession(int session_id) { |
| 17 WebContents* web_contents = |
| 18 WebContents::FromRenderFrameHost(render_frame_host_); |
| 19 |
| 20 if (session_id == 0) |
| 21 return MediaSession::Get(web_contents); |
| 22 |
| 23 for (ScopedVector<MediaSession>::iterator it = sessions_.begin(); |
| 24 it != sessions_.end(); ++it) { |
| 25 if ((*it)->session_id() == session_id) |
| 26 return *it; |
| 27 } |
| 28 |
| 29 MediaSession* session = MediaSession::Create(web_contents, session_id); |
| 30 sessions_.push_back(session); |
| 31 return session; |
| 32 } |
| 33 |
16 void BrowserMediaSessionManager::OnActivate(int session_id, int request_id) { | 34 void BrowserMediaSessionManager::OnActivate(int session_id, int request_id) { |
17 NOTIMPLEMENTED(); | 35 bool success = GetSession(session_id)->Activate(); |
18 Send(new MediaSessionMsg_DidActivate(GetRoutingID(), request_id, false)); | 36 Send(new MediaSessionMsg_DidActivate(GetRoutingID(), request_id, success)); |
19 } | 37 } |
20 | 38 |
21 void BrowserMediaSessionManager::OnDeactivate(int session_id, int request_id) { | 39 void BrowserMediaSessionManager::OnDeactivate(int session_id, int request_id) { |
22 NOTIMPLEMENTED(); | 40 if (MediaSession* media_session = GetSession(session_id)) |
| 41 media_session->Deactivate(); |
23 Send(new MediaSessionMsg_DidDeactivate(GetRoutingID(), request_id)); | 42 Send(new MediaSessionMsg_DidDeactivate(GetRoutingID(), request_id)); |
24 } | 43 } |
25 | 44 |
26 int BrowserMediaSessionManager::GetRoutingID() const { | 45 int BrowserMediaSessionManager::GetRoutingID() const { |
27 return render_frame_host_->GetRoutingID(); | 46 return render_frame_host_->GetRoutingID(); |
28 } | 47 } |
29 | 48 |
| 49 void BrowserMediaSessionManager::RemovePlayers(MediaSessionObserver* observer) { |
| 50 // Remove observer from default session and user created sessions. |
| 51 |
| 52 WebContents* web_contents = |
| 53 WebContents::FromRenderFrameHost(render_frame_host_); |
| 54 MediaSession::Get(web_contents)->RemovePlayers(observer); |
| 55 |
| 56 for (ScopedVector<MediaSession>::iterator it = sessions_.begin(); |
| 57 it != sessions_.end(); ++it) |
| 58 (*it)->RemovePlayers(observer); |
| 59 } |
| 60 |
| 61 void BrowserMediaSessionManager::RemovePlayer(MediaSessionObserver* observer, |
| 62 int player_id) { |
| 63 WebContents* web_contents = |
| 64 WebContents::FromRenderFrameHost(render_frame_host_); |
| 65 MediaSession::Get(web_contents)->RemovePlayer(observer, player_id); |
| 66 |
| 67 for (ScopedVector<MediaSession>::iterator it = sessions_.begin(); |
| 68 it != sessions_.end(); ++it) |
| 69 (*it)->RemovePlayer(observer, player_id); |
| 70 } |
| 71 |
| 72 void BrowserMediaSessionManager::OnPlayerPaused(MediaSessionObserver* observer, |
| 73 int player_id) { |
| 74 WebContents* web_contents = |
| 75 WebContents::FromRenderFrameHost(render_frame_host_); |
| 76 MediaSession::Get(web_contents)->OnPlayerPaused(observer, player_id); |
| 77 |
| 78 for (ScopedVector<MediaSession>::iterator it = sessions_.begin(); |
| 79 it != sessions_.end(); ++it) |
| 80 (*it)->OnPlayerPaused(observer, player_id); |
| 81 } |
| 82 |
30 bool BrowserMediaSessionManager::Send(IPC::Message* msg) { | 83 bool BrowserMediaSessionManager::Send(IPC::Message* msg) { |
31 return render_frame_host_->Send(msg); | 84 return render_frame_host_->Send(msg); |
32 } | 85 } |
33 | 86 |
34 } // namespace content | 87 } // namespace content |
OLD | NEW |