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> |
| 11 | 11 |
| 12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "content/browser/bad_message.h" | 14 #include "content/browser/bad_message.h" |
| 15 #include "content/browser/media/media_devices_util.h" | |
| 15 #include "content/browser/renderer_host/media/media_stream_manager.h" | 16 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 17 #include "content/browser/renderer_host/media/video_capture_manager.h" | |
| 16 #include "content/common/media/media_devices.h" | 18 #include "content/common/media/media_devices.h" |
| 17 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/media_device_id.h" | 20 #include "content/public/browser/media_device_id.h" |
| 19 #include "content/public/browser/render_frame_host.h" | 21 #include "content/public/browser/render_frame_host.h" |
| 20 #include "content/public/browser/resource_context.h" | 22 #include "content/public/browser/resource_context.h" |
| 21 #include "content/public/common/media_stream_request.h" | 23 #include "content/public/common/media_stream_request.h" |
| 22 #include "mojo/public/cpp/bindings/strong_binding.h" | 24 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 23 #include "services/service_manager/public/cpp/interface_provider.h" | 25 #include "services/service_manager/public/cpp/interface_provider.h" |
| 24 #include "url/origin.h" | 26 #include "url/origin.h" |
| 25 | 27 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT] = request_audio_output; | 142 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT] = request_audio_output; |
| 141 | 143 |
| 142 permission_checker_->CheckPermissions( | 144 permission_checker_->CheckPermissions( |
| 143 devices_to_enumerate, render_process_id_, render_frame_id_, | 145 devices_to_enumerate, render_process_id_, render_frame_id_, |
| 144 security_origin, | 146 security_origin, |
| 145 base::Bind(&MediaDevicesDispatcherHost::DoEnumerateDevices, | 147 base::Bind(&MediaDevicesDispatcherHost::DoEnumerateDevices, |
| 146 weak_factory_.GetWeakPtr(), devices_to_enumerate, | 148 weak_factory_.GetWeakPtr(), devices_to_enumerate, |
| 147 security_origin, client_callback)); | 149 security_origin, client_callback)); |
| 148 } | 150 } |
| 149 | 151 |
| 152 void MediaDevicesDispatcherHost::GetVideoInputCapabilities( | |
| 153 const url::Origin& security_origin, | |
| 154 const GetVideoInputCapabilitiesCallback& client_callback) { | |
| 155 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 156 if (!MediaStreamManager::IsOriginAllowed(render_process_id_, | |
| 157 security_origin)) { | |
| 158 bad_message::ReceivedBadMessage(render_process_id_, | |
|
dcheng
2017/01/20 07:56:50
Hmm. +rockot... do you forsee replacing bad_messag
Guido Urdaneta
2017/01/20 12:40:58
Should I make this change or was this a question f
dcheng
2017/01/20 18:28:29
This is a question for +rockot, I'm trying to unde
Ken Rockot(use gerrit already)
2017/01/20 18:34:36
Yes, I think we should replace ReceivedBadMessage
| |
| 159 bad_message::MDDH_UNAUTHORIZED_ORIGIN); | |
| 160 return; | |
| 161 } | |
| 162 | |
| 163 GetDefaultMediaDeviceID( | |
| 164 MEDIA_DEVICE_TYPE_VIDEO_INPUT, render_process_id_, render_frame_id_, | |
| 165 base::Bind(&MediaDevicesDispatcherHost::GotDefaultVideoInputDeviceID, | |
| 166 weak_factory_.GetWeakPtr(), security_origin, client_callback)); | |
| 167 } | |
| 168 | |
| 150 void MediaDevicesDispatcherHost::SubscribeDeviceChangeNotifications( | 169 void MediaDevicesDispatcherHost::SubscribeDeviceChangeNotifications( |
| 151 MediaDeviceType type, | 170 MediaDeviceType type, |
| 152 uint32_t subscription_id, | 171 uint32_t subscription_id, |
| 153 const url::Origin& security_origin) { | 172 const url::Origin& security_origin) { |
| 154 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 173 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 155 DCHECK(IsValidMediaDeviceType(type)); | 174 DCHECK(IsValidMediaDeviceType(type)); |
| 156 if (!MediaStreamManager::IsOriginAllowed(render_process_id_, | 175 if (!MediaStreamManager::IsOriginAllowed(render_process_id_, |
| 157 security_origin)) { | 176 security_origin)) { |
| 158 bad_message::ReceivedBadMessage(render_process_id_, | 177 bad_message::ReceivedBadMessage(render_process_id_, |
| 159 bad_message::MDDH_UNAUTHORIZED_ORIGIN); | 178 bad_message::MDDH_UNAUTHORIZED_ORIGIN); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 | 310 |
| 292 for (const auto& device_info : enumeration[i]) { | 311 for (const auto& device_info : enumeration[i]) { |
| 293 result[i].push_back(TranslateDeviceInfo(has_permissions[i], | 312 result[i].push_back(TranslateDeviceInfo(has_permissions[i], |
| 294 device_id_salt_, group_id_salt_, | 313 device_id_salt_, group_id_salt_, |
| 295 security_origin, device_info)); | 314 security_origin, device_info)); |
| 296 } | 315 } |
| 297 } | 316 } |
| 298 client_callback.Run(result); | 317 client_callback.Run(result); |
| 299 } | 318 } |
| 300 | 319 |
| 320 void MediaDevicesDispatcherHost::GotDefaultVideoInputDeviceID( | |
| 321 const url::Origin& security_origin, | |
| 322 const GetVideoInputCapabilitiesCallback& client_callback, | |
| 323 const std::string& default_device_id) { | |
| 324 MediaDevicesManager::BoolDeviceTypes devices_to_enumerate; | |
| 325 devices_to_enumerate[MEDIA_DEVICE_TYPE_VIDEO_INPUT] = true; | |
| 326 media_stream_manager_->media_devices_manager()->EnumerateDevices( | |
| 327 devices_to_enumerate, | |
| 328 base::Bind(&MediaDevicesDispatcherHost::FinalizeGetVideoInputCapabilities, | |
| 329 weak_factory_.GetWeakPtr(), security_origin, client_callback, | |
| 330 default_device_id)); | |
| 331 } | |
| 332 | |
| 333 void MediaDevicesDispatcherHost::FinalizeGetVideoInputCapabilities( | |
| 334 const url::Origin& security_origin, | |
| 335 const GetVideoInputCapabilitiesCallback& client_callback, | |
| 336 const std::string& default_device_id, | |
| 337 const MediaDeviceEnumeration& enumeration) { | |
| 338 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 339 std::vector<::mojom::VideoInputDeviceCapabilitiesPtr> | |
| 340 video_input_capabilities; | |
| 341 for (const auto& device_info : enumeration[MEDIA_DEVICE_TYPE_VIDEO_INPUT]) { | |
| 342 MediaDeviceInfo translated_info = TranslateDeviceInfo( | |
| 343 true, device_id_salt_, group_id_salt_, security_origin, device_info); | |
| 344 | |
| 345 ::mojom::VideoInputDeviceCapabilitiesPtr capabilities = | |
| 346 ::mojom::VideoInputDeviceCapabilities::New(); | |
| 347 capabilities->device_id = std::move(translated_info.device_id); | |
|
dcheng
2017/01/20 18:28:29
FWIW, this should normally be typemapped... that b
| |
| 348 capabilities->formats = GetVideoInputFormats(device_info.device_id); | |
| 349 capabilities->facing_mode = ::mojom::FacingMode::UNKNOWN; | |
| 350 #if defined(OS_ANDROID) | |
| 351 // On Android, the facing mode is available as part of the label. | |
| 352 // TODO(guidou): Update this code once an API is available to get the | |
| 353 // facing mode in all platforms. See http://crbug.com/672856. | |
| 354 if (device_info.label.find("facing front") != std::string::npos) | |
| 355 capabilities->facing_mode = ::mojom::FacingMode::USER; | |
| 356 else if (device_info.label.find("facing back") != std::string::npos) | |
| 357 capabilities->facing_mode = ::mojom::FacingMode::ENVIRONMENT; | |
| 358 #endif | |
| 359 if (device_info.device_id == default_device_id) { | |
| 360 video_input_capabilities.insert(video_input_capabilities.begin(), | |
| 361 std::move(capabilities)); | |
| 362 } else { | |
| 363 video_input_capabilities.push_back(std::move(capabilities)); | |
| 364 } | |
| 365 } | |
| 366 | |
| 367 client_callback.Run(std::move(video_input_capabilities)); | |
| 368 } | |
| 369 | |
| 370 media::VideoCaptureFormats MediaDevicesDispatcherHost::GetVideoInputFormats( | |
| 371 const std::string& device_id) { | |
| 372 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 373 media::VideoCaptureFormats formats; | |
| 374 media_stream_manager_->video_capture_manager()->GetDeviceFormatsInUse( | |
| 375 MEDIA_DEVICE_VIDEO_CAPTURE, device_id, &formats); | |
| 376 if (!formats.empty()) | |
| 377 return formats; | |
| 378 | |
| 379 media_stream_manager_->video_capture_manager()->GetDeviceSupportedFormats( | |
| 380 device_id, &formats); | |
| 381 return formats; | |
| 382 } | |
| 383 | |
| 301 } // namespace content | 384 } // namespace content |
| OLD | NEW |