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/android/media_web_contents_observer_android.h" | 5 #include "content/browser/media/android/media_web_contents_observer_android.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "content/browser/media/android/browser_media_player_manager.h" | 10 #include "content/browser/media/android/browser_media_player_manager.h" |
11 #include "content/browser/media/android/browser_media_session_manager.h" | 11 #include "content/browser/media/android/browser_media_session_manager.h" |
12 #include "content/browser/media/android/browser_surface_view_manager.h" | 12 #include "content/browser/media/android/browser_surface_view_manager.h" |
13 #include "content/browser/media/cdm/browser_cdm_manager.h" | |
14 #include "content/browser/web_contents/web_contents_impl.h" | 13 #include "content/browser/web_contents/web_contents_impl.h" |
15 #include "content/common/media/media_player_delegate_messages.h" | 14 #include "content/common/media/media_player_delegate_messages.h" |
16 #include "content/common/media/media_player_messages_android.h" | 15 #include "content/common/media/media_player_messages_android.h" |
17 #include "content/common/media/media_session_messages_android.h" | 16 #include "content/common/media/media_session_messages_android.h" |
18 #include "content/common/media/surface_view_manager_messages_android.h" | 17 #include "content/common/media/surface_view_manager_messages_android.h" |
19 #include "content/public/browser/render_frame_host.h" | 18 #include "content/public/browser/render_frame_host.h" |
20 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
21 #include "ipc/ipc_message_macros.h" | 20 #include "ipc/ipc_message_macros.h" |
22 #include "media/base/android/media_player_android.h" | 21 #include "media/base/android/media_player_android.h" |
23 | 22 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 RenderFrameHost* render_frame_host, | 107 RenderFrameHost* render_frame_host, |
109 int delegate_id) { | 108 int delegate_id) { |
110 session_controllers_manager()->OnEnd( | 109 session_controllers_manager()->OnEnd( |
111 MediaPlayerId(render_frame_host, delegate_id)); | 110 MediaPlayerId(render_frame_host, delegate_id)); |
112 } | 111 } |
113 | 112 |
114 void MediaWebContentsObserverAndroid::RenderFrameDeleted( | 113 void MediaWebContentsObserverAndroid::RenderFrameDeleted( |
115 RenderFrameHost* render_frame_host) { | 114 RenderFrameHost* render_frame_host) { |
116 MediaWebContentsObserver::RenderFrameDeleted(render_frame_host); | 115 MediaWebContentsObserver::RenderFrameDeleted(render_frame_host); |
117 | 116 |
118 // Always destroy the media players before CDMs because we do not support | |
119 // detaching CDMs from media players yet. See http://crbug.com/330324 | |
120 media_player_managers_.erase(render_frame_host); | 117 media_player_managers_.erase(render_frame_host); |
121 media_session_managers_.erase(render_frame_host); | 118 media_session_managers_.erase(render_frame_host); |
122 surface_view_managers_.erase(render_frame_host); | 119 surface_view_managers_.erase(render_frame_host); |
123 | |
124 // TODO(xhwang): Currently MediaWebContentsObserver, BrowserMediaPlayerManager | |
125 // and BrowserCdmManager all run on browser UI thread. So this call is okay. | |
126 // In the future we need to support the case where MediaWebContentsObserver | |
127 // get notified on browser UI thread, but BrowserMediaPlayerManager and | |
128 // BrowserCdmManager run on a different thread. | |
129 BrowserCdmManager* browser_cdm_manager = | |
130 BrowserCdmManager::FromProcess(render_frame_host->GetProcess()->GetID()); | |
131 if (browser_cdm_manager) | |
132 browser_cdm_manager->RenderFrameDeleted(render_frame_host->GetRoutingID()); | |
133 } | 120 } |
134 | 121 |
135 bool MediaWebContentsObserverAndroid::OnMessageReceived( | 122 bool MediaWebContentsObserverAndroid::OnMessageReceived( |
136 const IPC::Message& msg, | 123 const IPC::Message& msg, |
137 RenderFrameHost* render_frame_host) { | 124 RenderFrameHost* render_frame_host) { |
138 if (MediaWebContentsObserver::OnMessageReceived(msg, render_frame_host)) | 125 if (MediaWebContentsObserver::OnMessageReceived(msg, render_frame_host)) |
139 return true; | 126 return true; |
140 | 127 |
141 if (OnMediaPlayerMessageReceived(msg, render_frame_host)) | 128 if (OnMediaPlayerMessageReceived(msg, render_frame_host)) |
142 return true; | 129 return true; |
143 | 130 |
144 if (OnMediaPlayerSetCdmMessageReceived(msg, render_frame_host)) | |
145 return true; | |
146 | |
147 if (OnMediaSessionMessageReceived(msg, render_frame_host)) | 131 if (OnMediaSessionMessageReceived(msg, render_frame_host)) |
148 return true; | 132 return true; |
149 | 133 |
150 if (OnSurfaceViewManagerMessageReceived(msg, render_frame_host)) | 134 if (OnSurfaceViewManagerMessageReceived(msg, render_frame_host)) |
151 return true; | 135 return true; |
152 | 136 |
153 return false; | 137 return false; |
154 } | 138 } |
155 | 139 |
156 bool MediaWebContentsObserverAndroid::OnMediaPlayerMessageReceived( | 140 bool MediaWebContentsObserverAndroid::OnMediaPlayerMessageReceived( |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 BrowserMediaPlayerManager::OnRequestRemotePlayback) | 174 BrowserMediaPlayerManager::OnRequestRemotePlayback) |
191 IPC_MESSAGE_FORWARD( | 175 IPC_MESSAGE_FORWARD( |
192 MediaPlayerHostMsg_RequestRemotePlaybackControl, | 176 MediaPlayerHostMsg_RequestRemotePlaybackControl, |
193 GetMediaPlayerManager(render_frame_host), | 177 GetMediaPlayerManager(render_frame_host), |
194 BrowserMediaPlayerManager::OnRequestRemotePlaybackControl) | 178 BrowserMediaPlayerManager::OnRequestRemotePlaybackControl) |
195 IPC_MESSAGE_UNHANDLED(handled = false) | 179 IPC_MESSAGE_UNHANDLED(handled = false) |
196 IPC_END_MESSAGE_MAP() | 180 IPC_END_MESSAGE_MAP() |
197 return handled; | 181 return handled; |
198 } | 182 } |
199 | 183 |
200 bool MediaWebContentsObserverAndroid::OnMediaPlayerSetCdmMessageReceived( | |
201 const IPC::Message& msg, | |
202 RenderFrameHost* render_frame_host) { | |
203 bool handled = true; | |
204 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(MediaWebContentsObserverAndroid, msg, | |
205 render_frame_host) | |
206 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_SetCdm, OnSetCdm) | |
207 IPC_MESSAGE_UNHANDLED(handled = false) | |
208 IPC_END_MESSAGE_MAP() | |
209 return handled; | |
210 } | |
211 | |
212 bool MediaWebContentsObserverAndroid::OnMediaSessionMessageReceived( | 184 bool MediaWebContentsObserverAndroid::OnMediaSessionMessageReceived( |
213 const IPC::Message& msg, | 185 const IPC::Message& msg, |
214 RenderFrameHost* render_frame_host) { | 186 RenderFrameHost* render_frame_host) { |
215 bool handled = true; | 187 bool handled = true; |
216 | 188 |
217 IPC_BEGIN_MESSAGE_MAP(MediaWebContentsObserver, msg) | 189 IPC_BEGIN_MESSAGE_MAP(MediaWebContentsObserver, msg) |
218 IPC_MESSAGE_FORWARD(MediaSessionHostMsg_Activate, | 190 IPC_MESSAGE_FORWARD(MediaSessionHostMsg_Activate, |
219 GetMediaSessionManager(render_frame_host), | 191 GetMediaSessionManager(render_frame_host), |
220 BrowserMediaSessionManager::OnActivate) | 192 BrowserMediaSessionManager::OnActivate) |
221 IPC_MESSAGE_FORWARD(MediaSessionHostMsg_Deactivate, | 193 IPC_MESSAGE_FORWARD(MediaSessionHostMsg_Deactivate, |
(...skipping 17 matching lines...) Expand all Loading... |
239 GetSurfaceViewManager(render_frame_host), | 211 GetSurfaceViewManager(render_frame_host), |
240 BrowserSurfaceViewManager::OnCreateFullscreenSurface) | 212 BrowserSurfaceViewManager::OnCreateFullscreenSurface) |
241 IPC_MESSAGE_FORWARD(SurfaceViewManagerHostMsg_NaturalSizeChanged, | 213 IPC_MESSAGE_FORWARD(SurfaceViewManagerHostMsg_NaturalSizeChanged, |
242 GetSurfaceViewManager(render_frame_host), | 214 GetSurfaceViewManager(render_frame_host), |
243 BrowserSurfaceViewManager::OnNaturalSizeChanged) | 215 BrowserSurfaceViewManager::OnNaturalSizeChanged) |
244 IPC_MESSAGE_UNHANDLED(handled = false) | 216 IPC_MESSAGE_UNHANDLED(handled = false) |
245 IPC_END_MESSAGE_MAP() | 217 IPC_END_MESSAGE_MAP() |
246 return handled; | 218 return handled; |
247 } | 219 } |
248 | 220 |
249 void MediaWebContentsObserverAndroid::OnSetCdm( | |
250 RenderFrameHost* render_frame_host, | |
251 int player_id, | |
252 int cdm_id) { | |
253 media::MediaPlayerAndroid* media_player = | |
254 GetMediaPlayerManager(render_frame_host)->GetPlayer(player_id); | |
255 if (!media_player) { | |
256 NOTREACHED() << "OnSetCdm: MediaPlayer not found for " << player_id; | |
257 return; | |
258 } | |
259 | |
260 // MediaPlayerAndroid runs on the same thread as BrowserCdmManager. | |
261 BrowserCdmManager* browser_cdm_manager = | |
262 BrowserCdmManager::FromProcess(render_frame_host->GetProcess()->GetID()); | |
263 if (!browser_cdm_manager) { | |
264 NOTREACHED() << "OnSetCdm: CDM not found for " << cdm_id; | |
265 return; | |
266 } | |
267 | |
268 scoped_refptr<media::MediaKeys> cdm = | |
269 browser_cdm_manager->GetCdm(render_frame_host->GetRoutingID(), cdm_id); | |
270 if (!cdm) { | |
271 NOTREACHED() << "OnSetCdm: CDM not found for " << cdm_id; | |
272 return; | |
273 } | |
274 | |
275 // TODO(xhwang): This could possibly fail. In that case we should reject the | |
276 // promise. | |
277 media_player->SetCdm(cdm); | |
278 } | |
279 | |
280 } // namespace content | 221 } // namespace content |
OLD | NEW |