Chromium Code Reviews| 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/renderer_host/media/media_devices_dispatcher_host.h" | 5 #include "content/browser/renderer_host/media/media_devices_dispatcher_host.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 struct { | 34 struct { |
| 35 int width; | 35 int width; |
| 36 int height; | 36 int height; |
| 37 } const kFallbackVideoResolutions[] = {{1920, 1080}, {1280, 720}, {960, 720}, | 37 } const kFallbackVideoResolutions[] = {{1920, 1080}, {1280, 720}, {960, 720}, |
| 38 {640, 480}, {640, 360}, {320, 240}, | 38 {640, 480}, {640, 360}, {320, 240}, |
| 39 {320, 180}}; | 39 {320, 180}}; |
| 40 | 40 |
| 41 // Frame rates for sources with no support for capability enumeration. | 41 // Frame rates for sources with no support for capability enumeration. |
| 42 const int kFallbackVideoFrameRates[] = {30, 60}; | 42 const int kFallbackVideoFrameRates[] = {30, 60}; |
| 43 | 43 |
| 44 url::Origin GetOrigin(int process_id, | |
| 45 int frame_id, | |
| 46 const url::Origin& origin_for_testing) { | |
| 47 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 48 if (!origin_for_testing.unique()) | |
|
Mike West
2017/05/10 08:52:22
How do you intend to test the behavior for unique
Guido Urdaneta
2017/05/10 09:38:01
Is a base::Optional acceptable too?
Note that I re
Guido Urdaneta
2017/05/10 11:09:41
Note also that in unit tests, |frame_host| is null
| |
| 49 return origin_for_testing; | |
| 50 | |
| 51 RenderFrameHost* frame_host = RenderFrameHost::FromID(process_id, frame_id); | |
| 52 return frame_host ? frame_host->GetLastCommittedOrigin() : url::Origin(); | |
| 53 } | |
| 54 | |
| 44 MediaDeviceInfo TranslateDeviceInfo(bool has_permission, | 55 MediaDeviceInfo TranslateDeviceInfo(bool has_permission, |
| 45 const std::string& device_id_salt, | 56 const std::string& device_id_salt, |
| 46 const std::string& group_id_salt, | 57 const std::string& group_id_salt, |
| 47 const url::Origin& security_origin, | 58 const url::Origin& security_origin, |
| 48 const MediaDeviceInfo& device_info) { | 59 const MediaDeviceInfo& device_info) { |
| 49 return MediaDeviceInfo( | 60 return MediaDeviceInfo( |
| 50 GetHMACForMediaDeviceID(device_id_salt, security_origin, | 61 GetHMACForMediaDeviceID(device_id_salt, security_origin, |
| 51 device_info.device_id), | 62 device_info.device_id), |
| 52 has_permission ? device_info.label : std::string(), | 63 has_permission ? device_info.label : std::string(), |
| 53 device_info.group_id.empty() | 64 device_info.group_id.empty() |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 80 case media::MEDIA_VIDEO_FACING_ENVIRONMENT: | 91 case media::MEDIA_VIDEO_FACING_ENVIRONMENT: |
| 81 return ::mojom::FacingMode::ENVIRONMENT; | 92 return ::mojom::FacingMode::ENVIRONMENT; |
| 82 default: | 93 default: |
| 83 NOTREACHED(); | 94 NOTREACHED(); |
| 84 return ::mojom::FacingMode::NONE; | 95 return ::mojom::FacingMode::NONE; |
| 85 } | 96 } |
| 86 } | 97 } |
| 87 | 98 |
| 88 } // namespace | 99 } // namespace |
| 89 | 100 |
| 90 struct MediaDevicesDispatcherHost::SubscriptionInfo { | |
| 91 uint32_t subscription_id; | |
| 92 url::Origin security_origin; | |
| 93 }; | |
| 94 | |
| 95 // static | 101 // static |
| 96 void MediaDevicesDispatcherHost::Create( | 102 void MediaDevicesDispatcherHost::Create( |
| 97 int render_process_id, | 103 int render_process_id, |
| 98 int render_frame_id, | 104 int render_frame_id, |
| 99 const std::string& device_id_salt, | 105 const std::string& device_id_salt, |
| 100 MediaStreamManager* media_stream_manager, | 106 MediaStreamManager* media_stream_manager, |
| 101 const service_manager::BindSourceInfo& source_info, | 107 const service_manager::BindSourceInfo& source_info, |
| 102 ::mojom::MediaDevicesDispatcherHostRequest request) { | 108 ::mojom::MediaDevicesDispatcherHostRequest request) { |
| 103 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 109 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 104 mojo::MakeStrongBinding(base::MakeUnique<MediaDevicesDispatcherHost>( | 110 mojo::MakeStrongBinding(base::MakeUnique<MediaDevicesDispatcherHost>( |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 135 ->UnsubscribeDeviceChangeNotifications( | 141 ->UnsubscribeDeviceChangeNotifications( |
| 136 static_cast<MediaDeviceType>(i), this); | 142 static_cast<MediaDeviceType>(i), this); |
| 137 } | 143 } |
| 138 } | 144 } |
| 139 } | 145 } |
| 140 | 146 |
| 141 void MediaDevicesDispatcherHost::EnumerateDevices( | 147 void MediaDevicesDispatcherHost::EnumerateDevices( |
| 142 bool request_audio_input, | 148 bool request_audio_input, |
| 143 bool request_video_input, | 149 bool request_video_input, |
| 144 bool request_audio_output, | 150 bool request_audio_output, |
| 145 const url::Origin& security_origin, | |
| 146 EnumerateDevicesCallback client_callback) { | 151 EnumerateDevicesCallback client_callback) { |
| 147 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 152 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 148 | 153 |
| 149 if (!request_audio_input && !request_video_input && !request_audio_output) { | 154 if (!request_audio_input && !request_video_input && !request_audio_output) { |
| 150 bad_message::ReceivedBadMessage( | 155 bad_message::ReceivedBadMessage( |
| 151 render_process_id_, bad_message::MDDH_INVALID_DEVICE_TYPE_REQUEST); | 156 render_process_id_, bad_message::MDDH_INVALID_DEVICE_TYPE_REQUEST); |
| 152 return; | 157 return; |
| 153 } | 158 } |
| 154 | 159 |
| 155 // Ignore requests from unique origins, but do not crash the renderer. | |
| 156 if (security_origin.unique()) | |
| 157 return; | |
| 158 | |
| 159 if (!MediaStreamManager::IsOriginAllowed(render_process_id_, | |
| 160 security_origin)) { | |
| 161 bad_message::ReceivedBadMessage(render_process_id_, | |
| 162 bad_message::MDDH_UNAUTHORIZED_ORIGIN); | |
| 163 return; | |
| 164 } | |
| 165 | |
| 166 MediaDevicesManager::BoolDeviceTypes devices_to_enumerate; | 160 MediaDevicesManager::BoolDeviceTypes devices_to_enumerate; |
| 167 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_INPUT] = request_audio_input; | 161 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_INPUT] = request_audio_input; |
| 168 devices_to_enumerate[MEDIA_DEVICE_TYPE_VIDEO_INPUT] = request_video_input; | 162 devices_to_enumerate[MEDIA_DEVICE_TYPE_VIDEO_INPUT] = request_video_input; |
| 169 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT] = request_audio_output; | 163 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT] = request_audio_output; |
| 170 | 164 |
| 171 permission_checker_->CheckPermissions( | 165 base::PostTaskAndReplyWithResult( |
| 172 devices_to_enumerate, render_process_id_, render_frame_id_, | 166 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI).get(), FROM_HERE, |
| 173 security_origin, | 167 base::Bind(GetOrigin, render_process_id_, render_frame_id_, |
| 174 base::Bind(&MediaDevicesDispatcherHost::DoEnumerateDevices, | 168 security_origin_for_testing_), |
| 175 weak_factory_.GetWeakPtr(), devices_to_enumerate, | 169 base::Bind( |
| 176 security_origin, base::Passed(&client_callback))); | 170 &MediaDevicesDispatcherHost::CheckPermissionsForEnumerateDevices, |
| 171 weak_factory_.GetWeakPtr(), devices_to_enumerate, | |
| 172 base::Passed(&client_callback))); | |
| 177 } | 173 } |
| 178 | 174 |
| 179 void MediaDevicesDispatcherHost::GetVideoInputCapabilities( | 175 void MediaDevicesDispatcherHost::GetVideoInputCapabilities( |
| 180 const url::Origin& security_origin, | |
| 181 GetVideoInputCapabilitiesCallback client_callback) { | 176 GetVideoInputCapabilitiesCallback client_callback) { |
| 182 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 177 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 183 // Return no capabilities for unique origins, but do not crash the renderer. | 178 base::PostTaskAndReplyWithResult( |
| 184 if (security_origin.unique()) { | 179 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI).get(), FROM_HERE, |
| 185 std::move(client_callback) | 180 base::Bind(GetOrigin, render_process_id_, render_frame_id_, |
| 186 .Run(std::vector<::mojom::VideoInputDeviceCapabilitiesPtr>()); | 181 security_origin_for_testing_), |
| 187 return; | 182 base::Bind(&MediaDevicesDispatcherHost::GetDefaultVideoInputDeviceID, |
| 188 } | 183 weak_factory_.GetWeakPtr(), base::Passed(&client_callback))); |
| 189 | |
| 190 if (!MediaStreamManager::IsOriginAllowed(render_process_id_, | |
| 191 security_origin)) { | |
| 192 bad_message::ReceivedBadMessage(render_process_id_, | |
| 193 bad_message::MDDH_UNAUTHORIZED_ORIGIN); | |
| 194 return; | |
| 195 } | |
| 196 | |
| 197 GetDefaultMediaDeviceID( | |
| 198 MEDIA_DEVICE_TYPE_VIDEO_INPUT, render_process_id_, render_frame_id_, | |
| 199 base::Bind(&MediaDevicesDispatcherHost::GotDefaultVideoInputDeviceID, | |
| 200 weak_factory_.GetWeakPtr(), security_origin, | |
| 201 base::Passed(&client_callback))); | |
| 202 } | 184 } |
| 203 | 185 |
| 204 void MediaDevicesDispatcherHost::SubscribeDeviceChangeNotifications( | 186 void MediaDevicesDispatcherHost::SubscribeDeviceChangeNotifications( |
| 205 MediaDeviceType type, | 187 MediaDeviceType type, |
| 206 uint32_t subscription_id, | 188 uint32_t subscription_id) { |
| 207 const url::Origin& security_origin) { | |
| 208 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 189 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 209 DCHECK(IsValidMediaDeviceType(type)); | 190 DCHECK(IsValidMediaDeviceType(type)); |
| 210 // Ignore requests from unique origins, but do not crash the renderer. | 191 auto it = |
| 211 if (security_origin.unique()) | 192 std::find(device_change_subscriptions_[type].begin(), |
| 212 return; | 193 device_change_subscriptions_[type].end(), subscription_id); |
| 213 | |
| 214 if (!MediaStreamManager::IsOriginAllowed(render_process_id_, | |
| 215 security_origin)) { | |
| 216 bad_message::ReceivedBadMessage(render_process_id_, | |
| 217 bad_message::MDDH_UNAUTHORIZED_ORIGIN); | |
| 218 return; | |
| 219 } | |
| 220 | |
| 221 auto it = std::find_if(device_change_subscriptions_[type].begin(), | |
| 222 device_change_subscriptions_[type].end(), | |
| 223 [subscription_id](const SubscriptionInfo& info) { | |
| 224 return info.subscription_id == subscription_id; | |
| 225 }); | |
| 226 | |
| 227 if (it != device_change_subscriptions_[type].end()) { | 194 if (it != device_change_subscriptions_[type].end()) { |
| 228 bad_message::ReceivedBadMessage( | 195 bad_message::ReceivedBadMessage( |
| 229 render_process_id_, bad_message::MDDH_INVALID_SUBSCRIPTION_REQUEST); | 196 render_process_id_, bad_message::MDDH_INVALID_SUBSCRIPTION_REQUEST); |
| 230 return; | 197 return; |
| 231 } | 198 } |
| 232 | 199 |
| 233 if (device_change_subscriptions_[type].empty()) { | 200 if (device_change_subscriptions_[type].empty()) { |
| 234 media_stream_manager_->media_devices_manager() | 201 media_stream_manager_->media_devices_manager() |
| 235 ->SubscribeDeviceChangeNotifications(type, this); | 202 ->SubscribeDeviceChangeNotifications(type, this); |
| 236 } | 203 } |
| 237 | 204 |
| 238 device_change_subscriptions_[type].push_back( | 205 device_change_subscriptions_[type].push_back(subscription_id); |
| 239 SubscriptionInfo{subscription_id, security_origin}); | |
| 240 } | 206 } |
| 241 | 207 |
| 242 void MediaDevicesDispatcherHost::UnsubscribeDeviceChangeNotifications( | 208 void MediaDevicesDispatcherHost::UnsubscribeDeviceChangeNotifications( |
| 243 MediaDeviceType type, | 209 MediaDeviceType type, |
| 244 uint32_t subscription_id) { | 210 uint32_t subscription_id) { |
| 245 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 211 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 246 DCHECK(IsValidMediaDeviceType(type)); | 212 DCHECK(IsValidMediaDeviceType(type)); |
| 247 auto it = std::find_if(device_change_subscriptions_[type].begin(), | 213 auto it = |
| 248 device_change_subscriptions_[type].end(), | 214 std::find(device_change_subscriptions_[type].begin(), |
| 249 [subscription_id](const SubscriptionInfo& info) { | 215 device_change_subscriptions_[type].end(), subscription_id); |
| 250 return info.subscription_id == subscription_id; | |
| 251 }); | |
| 252 | |
| 253 // Ignore invalid unsubscription requests. | 216 // Ignore invalid unsubscription requests. |
| 254 if (it == device_change_subscriptions_[type].end()) | 217 if (it == device_change_subscriptions_[type].end()) |
| 255 return; | 218 return; |
| 256 | 219 |
| 257 device_change_subscriptions_[type].erase(it); | 220 device_change_subscriptions_[type].erase(it); |
| 258 if (device_change_subscriptions_[type].empty()) { | 221 if (device_change_subscriptions_[type].empty()) { |
| 259 media_stream_manager_->media_devices_manager() | 222 media_stream_manager_->media_devices_manager() |
| 260 ->UnsubscribeDeviceChangeNotifications(type, this); | 223 ->UnsubscribeDeviceChangeNotifications(type, this); |
| 261 } | 224 } |
| 262 } | 225 } |
| 263 | 226 |
| 264 void MediaDevicesDispatcherHost::OnDevicesChanged( | 227 void MediaDevicesDispatcherHost::OnDevicesChanged( |
| 265 MediaDeviceType type, | 228 MediaDeviceType type, |
| 266 const MediaDeviceInfoArray& device_infos) { | 229 const MediaDeviceInfoArray& device_infos) { |
| 267 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 230 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 268 DCHECK(IsValidMediaDeviceType(type)); | 231 DCHECK(IsValidMediaDeviceType(type)); |
| 232 std::vector<uint32_t> subscriptions = device_change_subscriptions_[type]; | |
| 269 BrowserThread::PostTask( | 233 BrowserThread::PostTask( |
| 270 BrowserThread::UI, FROM_HERE, | 234 BrowserThread::UI, FROM_HERE, |
| 271 base::Bind(&MediaDevicesDispatcherHost::NotifyDeviceChangeOnUIThread, | 235 base::BindOnce(&MediaDevicesDispatcherHost::NotifyDeviceChangeOnUIThread, |
| 272 weak_factory_.GetWeakPtr(), device_change_subscriptions_[type], | 236 weak_factory_.GetWeakPtr(), std::move(subscriptions), type, |
| 273 type, device_infos)); | 237 device_infos)); |
| 274 } | 238 } |
| 275 | 239 |
| 276 void MediaDevicesDispatcherHost::NotifyDeviceChangeOnUIThread( | 240 void MediaDevicesDispatcherHost::NotifyDeviceChangeOnUIThread( |
| 277 const std::vector<SubscriptionInfo>& subscriptions, | 241 const std::vector<uint32_t>& subscriptions, |
| 278 MediaDeviceType type, | 242 MediaDeviceType type, |
| 279 const MediaDeviceInfoArray& device_infos) { | 243 const MediaDeviceInfoArray& device_infos) { |
| 280 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 244 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 281 DCHECK(IsValidMediaDeviceType(type)); | 245 DCHECK(IsValidMediaDeviceType(type)); |
| 282 | 246 |
| 283 ::mojom::MediaDevicesListenerPtr media_devices_listener; | 247 ::mojom::MediaDevicesListenerPtr media_devices_listener; |
| 248 url::Origin security_origin; | |
| 284 if (device_change_listener_) { | 249 if (device_change_listener_) { |
| 285 media_devices_listener = std::move(device_change_listener_); | 250 media_devices_listener = std::move(device_change_listener_); |
| 286 } else { | 251 } else { |
| 287 RenderFrameHost* render_frame_host = | 252 RenderFrameHost* render_frame_host = |
| 288 RenderFrameHost::FromID(render_process_id_, render_frame_id_); | 253 RenderFrameHost::FromID(render_process_id_, render_frame_id_); |
| 289 if (!render_frame_host) | 254 if (!render_frame_host) |
| 290 return; | 255 return; |
| 291 | 256 |
| 292 render_frame_host->GetRemoteInterfaces()->GetInterface( | 257 render_frame_host->GetRemoteInterfaces()->GetInterface( |
| 293 mojo::MakeRequest(&media_devices_listener)); | 258 mojo::MakeRequest(&media_devices_listener)); |
| 294 if (!media_devices_listener) | 259 if (!media_devices_listener) |
| 295 return; | 260 return; |
| 261 | |
| 262 security_origin = render_frame_host->GetLastCommittedOrigin(); | |
| 296 } | 263 } |
| 297 | 264 |
| 298 for (const auto& subscription : subscriptions) { | 265 for (uint32_t subscription_id : subscriptions) { |
| 299 bool has_permission = permission_checker_->CheckPermissionOnUIThread( | 266 bool has_permission = permission_checker_->CheckPermissionOnUIThread( |
| 300 type, render_process_id_, render_frame_id_, | 267 type, render_process_id_, render_frame_id_); |
| 301 subscription.security_origin); | |
| 302 media_devices_listener->OnDevicesChanged( | 268 media_devices_listener->OnDevicesChanged( |
| 303 type, subscription.subscription_id, | 269 type, subscription_id, |
| 304 TranslateMediaDeviceInfoArray( | 270 TranslateMediaDeviceInfoArray(has_permission, device_id_salt_, |
| 305 has_permission, device_id_salt_, group_id_salt_, | 271 group_id_salt_, security_origin, |
| 306 subscription.security_origin, device_infos)); | 272 device_infos)); |
| 307 } | 273 } |
| 308 } | 274 } |
| 309 | 275 |
| 310 void MediaDevicesDispatcherHost::SetPermissionChecker( | 276 void MediaDevicesDispatcherHost::SetPermissionChecker( |
| 311 std::unique_ptr<MediaDevicesPermissionChecker> permission_checker) { | 277 std::unique_ptr<MediaDevicesPermissionChecker> permission_checker) { |
| 312 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 278 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 313 DCHECK(permission_checker); | 279 DCHECK(permission_checker); |
| 314 permission_checker_ = std::move(permission_checker); | 280 permission_checker_ = std::move(permission_checker); |
| 315 } | 281 } |
| 316 | 282 |
| 317 void MediaDevicesDispatcherHost::SetDeviceChangeListenerForTesting( | 283 void MediaDevicesDispatcherHost::SetDeviceChangeListenerForTesting( |
| 318 ::mojom::MediaDevicesListenerPtr listener) { | 284 ::mojom::MediaDevicesListenerPtr listener) { |
| 319 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 285 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 320 device_change_listener_ = std::move(listener); | 286 device_change_listener_ = std::move(listener); |
| 321 } | 287 } |
| 322 | 288 |
| 289 void MediaDevicesDispatcherHost::SetSecurityOriginForTesting( | |
| 290 const url::Origin& origin) { | |
| 291 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 292 security_origin_for_testing_ = origin; | |
| 293 } | |
| 294 | |
| 295 void MediaDevicesDispatcherHost::CheckPermissionsForEnumerateDevices( | |
| 296 const MediaDevicesManager::BoolDeviceTypes& requested_types, | |
| 297 EnumerateDevicesCallback client_callback, | |
| 298 const url::Origin& security_origin) { | |
| 299 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 300 permission_checker_->CheckPermissions( | |
| 301 requested_types, render_process_id_, render_frame_id_, | |
| 302 base::Bind(&MediaDevicesDispatcherHost::DoEnumerateDevices, | |
| 303 weak_factory_.GetWeakPtr(), requested_types, | |
| 304 base::Passed(&client_callback), security_origin)); | |
| 305 } | |
| 306 | |
| 323 void MediaDevicesDispatcherHost::DoEnumerateDevices( | 307 void MediaDevicesDispatcherHost::DoEnumerateDevices( |
| 324 const MediaDevicesManager::BoolDeviceTypes& requested_types, | 308 const MediaDevicesManager::BoolDeviceTypes& requested_types, |
| 309 EnumerateDevicesCallback client_callback, | |
| 325 const url::Origin& security_origin, | 310 const url::Origin& security_origin, |
| 326 EnumerateDevicesCallback client_callback, | |
| 327 const MediaDevicesManager::BoolDeviceTypes& has_permissions) { | 311 const MediaDevicesManager::BoolDeviceTypes& has_permissions) { |
| 328 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 312 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 329 media_stream_manager_->media_devices_manager()->EnumerateDevices( | 313 media_stream_manager_->media_devices_manager()->EnumerateDevices( |
| 330 requested_types, | 314 requested_types, |
| 331 base::Bind(&MediaDevicesDispatcherHost::DevicesEnumerated, | 315 base::Bind(&MediaDevicesDispatcherHost::DevicesEnumerated, |
| 332 weak_factory_.GetWeakPtr(), requested_types, security_origin, | 316 weak_factory_.GetWeakPtr(), requested_types, |
| 333 base::Passed(&client_callback), has_permissions)); | 317 base::Passed(&client_callback), security_origin, |
| 318 has_permissions)); | |
| 334 } | 319 } |
| 335 | 320 |
| 336 void MediaDevicesDispatcherHost::DevicesEnumerated( | 321 void MediaDevicesDispatcherHost::DevicesEnumerated( |
| 337 const MediaDevicesManager::BoolDeviceTypes& requested_types, | 322 const MediaDevicesManager::BoolDeviceTypes& requested_types, |
| 323 EnumerateDevicesCallback client_callback, | |
| 338 const url::Origin& security_origin, | 324 const url::Origin& security_origin, |
| 339 EnumerateDevicesCallback client_callback, | |
| 340 const MediaDevicesManager::BoolDeviceTypes& has_permissions, | 325 const MediaDevicesManager::BoolDeviceTypes& has_permissions, |
| 341 const MediaDeviceEnumeration& enumeration) { | 326 const MediaDeviceEnumeration& enumeration) { |
| 342 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 327 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 343 std::vector<std::vector<MediaDeviceInfo>> result(NUM_MEDIA_DEVICE_TYPES); | 328 std::vector<std::vector<MediaDeviceInfo>> result(NUM_MEDIA_DEVICE_TYPES); |
| 344 for (size_t i = 0; i < NUM_MEDIA_DEVICE_TYPES; ++i) { | 329 for (size_t i = 0; i < NUM_MEDIA_DEVICE_TYPES; ++i) { |
| 345 if (!requested_types[i]) | 330 if (!requested_types[i]) |
| 346 continue; | 331 continue; |
| 347 | 332 |
| 348 for (const auto& device_info : enumeration[i]) { | 333 for (const auto& device_info : enumeration[i]) { |
| 349 result[i].push_back(TranslateDeviceInfo(has_permissions[i], | 334 result[i].push_back(TranslateDeviceInfo(has_permissions[i], |
| 350 device_id_salt_, group_id_salt_, | 335 device_id_salt_, group_id_salt_, |
| 351 security_origin, device_info)); | 336 security_origin, device_info)); |
| 352 } | 337 } |
| 353 } | 338 } |
| 354 std::move(client_callback).Run(result); | 339 std::move(client_callback).Run(result); |
| 355 } | 340 } |
| 356 | 341 |
| 342 void MediaDevicesDispatcherHost::GetDefaultVideoInputDeviceID( | |
| 343 GetVideoInputCapabilitiesCallback client_callback, | |
| 344 const url::Origin& security_origin) { | |
| 345 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 346 GetDefaultMediaDeviceID( | |
| 347 MEDIA_DEVICE_TYPE_VIDEO_INPUT, render_process_id_, render_frame_id_, | |
| 348 base::Bind(&MediaDevicesDispatcherHost::GotDefaultVideoInputDeviceID, | |
| 349 weak_factory_.GetWeakPtr(), base::Passed(&client_callback), | |
| 350 security_origin)); | |
| 351 } | |
| 352 | |
| 357 void MediaDevicesDispatcherHost::GotDefaultVideoInputDeviceID( | 353 void MediaDevicesDispatcherHost::GotDefaultVideoInputDeviceID( |
| 354 GetVideoInputCapabilitiesCallback client_callback, | |
| 358 const url::Origin& security_origin, | 355 const url::Origin& security_origin, |
| 359 GetVideoInputCapabilitiesCallback client_callback, | |
| 360 const std::string& default_device_id) { | 356 const std::string& default_device_id) { |
| 361 MediaDevicesManager::BoolDeviceTypes devices_to_enumerate; | 357 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 362 devices_to_enumerate[MEDIA_DEVICE_TYPE_VIDEO_INPUT] = true; | |
| 363 media_stream_manager_->video_capture_manager()->EnumerateDevices( | 358 media_stream_manager_->video_capture_manager()->EnumerateDevices( |
| 364 base::Bind(&MediaDevicesDispatcherHost::FinalizeGetVideoInputCapabilities, | 359 base::Bind(&MediaDevicesDispatcherHost::FinalizeGetVideoInputCapabilities, |
| 365 weak_factory_.GetWeakPtr(), security_origin, | 360 weak_factory_.GetWeakPtr(), base::Passed(&client_callback), |
| 366 base::Passed(&client_callback), default_device_id)); | 361 security_origin, default_device_id)); |
| 367 } | 362 } |
| 368 | 363 |
| 369 void MediaDevicesDispatcherHost::FinalizeGetVideoInputCapabilities( | 364 void MediaDevicesDispatcherHost::FinalizeGetVideoInputCapabilities( |
| 365 GetVideoInputCapabilitiesCallback client_callback, | |
| 370 const url::Origin& security_origin, | 366 const url::Origin& security_origin, |
| 371 GetVideoInputCapabilitiesCallback client_callback, | |
| 372 const std::string& default_device_id, | 367 const std::string& default_device_id, |
| 373 const media::VideoCaptureDeviceDescriptors& device_descriptors) { | 368 const media::VideoCaptureDeviceDescriptors& device_descriptors) { |
| 374 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 369 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 375 std::vector<::mojom::VideoInputDeviceCapabilitiesPtr> | 370 std::vector<::mojom::VideoInputDeviceCapabilitiesPtr> |
| 376 video_input_capabilities; | 371 video_input_capabilities; |
| 377 for (const auto& descriptor : device_descriptors) { | 372 for (const auto& descriptor : device_descriptors) { |
| 378 std::string hmac_device_id = GetHMACForMediaDeviceID( | 373 std::string hmac_device_id = GetHMACForMediaDeviceID( |
| 379 device_id_salt_, security_origin, descriptor.device_id); | 374 device_id_salt_, security_origin, descriptor.device_id); |
| 380 ::mojom::VideoInputDeviceCapabilitiesPtr capabilities = | 375 ::mojom::VideoInputDeviceCapabilitiesPtr capabilities = |
| 381 ::mojom::VideoInputDeviceCapabilities::New(); | 376 ::mojom::VideoInputDeviceCapabilities::New(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 425 formats.push_back(format.value()); | 420 formats.push_back(format.value()); |
| 426 return formats; | 421 return formats; |
| 427 } | 422 } |
| 428 | 423 |
| 429 media_stream_manager_->video_capture_manager()->GetDeviceSupportedFormats( | 424 media_stream_manager_->video_capture_manager()->GetDeviceSupportedFormats( |
| 430 device_id, &formats); | 425 device_id, &formats); |
| 431 return formats; | 426 return formats; |
| 432 } | 427 } |
| 433 | 428 |
| 434 } // namespace content | 429 } // namespace content |
| OLD | NEW |