| 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 <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "content/browser/bad_message.h" | 12 #include "content/browser/bad_message.h" |
| 13 #include "content/browser/renderer_host/media/media_stream_manager.h" | 13 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 14 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" | |
| 15 #include "content/common/media/media_devices.h" | 14 #include "content/common/media/media_devices.h" |
| 16 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/media_device_id.h" | 16 #include "content/public/browser/media_device_id.h" |
| 18 #include "content/public/browser/render_frame_host.h" | 17 #include "content/public/browser/render_frame_host.h" |
| 19 #include "content/public/browser/resource_context.h" | 18 #include "content/public/browser/resource_context.h" |
| 20 #include "content/public/common/media_stream_request.h" | 19 #include "content/public/common/media_stream_request.h" |
| 21 #include "mojo/public/cpp/bindings/strong_binding.h" | 20 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 22 #include "services/service_manager/public/cpp/interface_provider.h" | 21 #include "services/service_manager/public/cpp/interface_provider.h" |
| 23 #include "url/origin.h" | 22 #include "url/origin.h" |
| 24 | 23 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 42 } | 41 } |
| 43 | 42 |
| 44 } // namespace | 43 } // namespace |
| 45 | 44 |
| 46 // static | 45 // static |
| 47 void MediaDevicesDispatcherHost::Create( | 46 void MediaDevicesDispatcherHost::Create( |
| 48 int render_process_id, | 47 int render_process_id, |
| 49 int routing_id, | 48 int routing_id, |
| 50 const std::string& device_id_salt, | 49 const std::string& device_id_salt, |
| 51 MediaStreamManager* media_stream_manager, | 50 MediaStreamManager* media_stream_manager, |
| 52 bool use_fake_ui, | |
| 53 ::mojom::MediaDevicesDispatcherHostRequest request) { | 51 ::mojom::MediaDevicesDispatcherHostRequest request) { |
| 54 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 52 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 55 mojo::MakeStrongBinding(base::MakeUnique<MediaDevicesDispatcherHost>( | 53 mojo::MakeStrongBinding( |
| 56 render_process_id, routing_id, device_id_salt, | 54 base::MakeUnique<MediaDevicesDispatcherHost>( |
| 57 media_stream_manager, use_fake_ui), | 55 render_process_id, routing_id, device_id_salt, media_stream_manager), |
| 58 std::move(request)); | 56 std::move(request)); |
| 59 } | 57 } |
| 60 | 58 |
| 61 MediaDevicesDispatcherHost::MediaDevicesDispatcherHost( | 59 MediaDevicesDispatcherHost::MediaDevicesDispatcherHost( |
| 62 int render_process_id, | 60 int render_process_id, |
| 63 int routing_id, | 61 int routing_id, |
| 64 const std::string& device_id_salt, | 62 const std::string& device_id_salt, |
| 65 MediaStreamManager* media_stream_manager, | 63 MediaStreamManager* media_stream_manager) |
| 66 bool use_fake_ui) | |
| 67 : render_process_id_(render_process_id), | 64 : render_process_id_(render_process_id), |
| 68 routing_id_(routing_id), | 65 routing_id_(routing_id), |
| 69 device_id_salt_(device_id_salt), | 66 device_id_salt_(device_id_salt), |
| 70 group_id_salt_(ResourceContext::CreateRandomMediaDeviceIDSalt()), | 67 group_id_salt_(ResourceContext::CreateRandomMediaDeviceIDSalt()), |
| 71 media_stream_manager_(media_stream_manager), | 68 media_stream_manager_(media_stream_manager), |
| 72 use_fake_ui_(use_fake_ui), | |
| 73 weak_factory_(this) { | 69 weak_factory_(this) { |
| 74 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 70 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 75 } | 71 } |
| 76 | 72 |
| 77 MediaDevicesDispatcherHost::~MediaDevicesDispatcherHost() { | 73 MediaDevicesDispatcherHost::~MediaDevicesDispatcherHost() { |
| 78 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 74 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 79 } | 75 } |
| 80 | 76 |
| 81 void MediaDevicesDispatcherHost::EnumerateDevices( | 77 void MediaDevicesDispatcherHost::EnumerateDevices( |
| 82 bool request_audio_input, | 78 bool request_audio_input, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 97 bad_message::ReceivedBadMessage(render_process_id_, | 93 bad_message::ReceivedBadMessage(render_process_id_, |
| 98 bad_message::MDDH_UNAUTHORIZED_ORIGIN); | 94 bad_message::MDDH_UNAUTHORIZED_ORIGIN); |
| 99 return; | 95 return; |
| 100 } | 96 } |
| 101 | 97 |
| 102 MediaDevicesManager::BoolDeviceTypes devices_to_enumerate; | 98 MediaDevicesManager::BoolDeviceTypes devices_to_enumerate; |
| 103 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_INPUT] = request_audio_input; | 99 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_INPUT] = request_audio_input; |
| 104 devices_to_enumerate[MEDIA_DEVICE_TYPE_VIDEO_INPUT] = request_video_input; | 100 devices_to_enumerate[MEDIA_DEVICE_TYPE_VIDEO_INPUT] = request_video_input; |
| 105 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT] = request_audio_output; | 101 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT] = request_audio_output; |
| 106 | 102 |
| 107 bool request_audio = request_audio_input || request_audio_output; | 103 permission_checker_.CheckPermissions( |
| 108 CheckAccess(request_audio, request_video_input, security_origin, | 104 devices_to_enumerate, render_process_id_, routing_id_, security_origin, |
| 109 base::Bind(&MediaDevicesDispatcherHost::DoEnumerateDevices, | 105 base::Bind(&MediaDevicesDispatcherHost::DoEnumerateDevices, |
| 110 weak_factory_.GetWeakPtr(), devices_to_enumerate, | 106 weak_factory_.GetWeakPtr(), devices_to_enumerate, |
| 111 security_origin, client_callback)); | 107 security_origin, client_callback)); |
| 112 } | 108 } |
| 113 | 109 |
| 114 void MediaDevicesDispatcherHost::CheckAccess( | 110 void MediaDevicesDispatcherHost::SetPermissionChecker( |
| 115 bool check_audio, | 111 const MediaDevicesPermissionChecker& permission_checker) { |
| 116 bool check_video_input, | |
| 117 const url::Origin& security_origin, | |
| 118 const AccessCheckedCallback& callback) { | |
| 119 DCHECK(check_audio || check_video_input); | |
| 120 std::unique_ptr<MediaStreamUIProxy> ui_proxy = GetUIProxy(); | |
| 121 if (check_audio) { | |
| 122 ui_proxy->CheckAccess( | |
| 123 security_origin, MEDIA_DEVICE_AUDIO_CAPTURE, render_process_id_, | |
| 124 routing_id_, | |
| 125 base::Bind(&MediaDevicesDispatcherHost::AudioAccessChecked, | |
| 126 weak_factory_.GetWeakPtr(), base::Passed(&ui_proxy), | |
| 127 check_video_input, security_origin, callback)); | |
| 128 return; | |
| 129 } | |
| 130 | |
| 131 DCHECK(check_video_input); | |
| 132 ui_proxy->CheckAccess( | |
| 133 security_origin, MEDIA_DEVICE_VIDEO_CAPTURE, render_process_id_, | |
| 134 routing_id_, | |
| 135 base::Bind(&MediaDevicesDispatcherHost::VideoAccessChecked, | |
| 136 weak_factory_.GetWeakPtr(), base::Passed(&ui_proxy), | |
| 137 false /* has_audio_permission */, callback)); | |
| 138 } | |
| 139 | |
| 140 void MediaDevicesDispatcherHost::AudioAccessChecked( | |
| 141 std::unique_ptr<MediaStreamUIProxy> ui_proxy, | |
| 142 bool check_video_permission, | |
| 143 const url::Origin& security_origin, | |
| 144 const AccessCheckedCallback& callback, | |
| 145 bool has_audio_permission) { | |
| 146 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 112 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 147 if (check_video_permission) { | 113 permission_checker_ = permission_checker; |
| 148 ui_proxy->CheckAccess( | |
| 149 security_origin, MEDIA_DEVICE_VIDEO_CAPTURE, render_process_id_, | |
| 150 routing_id_, | |
| 151 base::Bind(&MediaDevicesDispatcherHost::VideoAccessChecked, | |
| 152 weak_factory_.GetWeakPtr(), base::Passed(&ui_proxy), | |
| 153 has_audio_permission, callback)); | |
| 154 return; | |
| 155 } | |
| 156 | |
| 157 MediaDevicesManager::BoolDeviceTypes permissions; | |
| 158 permissions[MEDIA_DEVICE_TYPE_AUDIO_INPUT] = has_audio_permission; | |
| 159 permissions[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT] = has_audio_permission; | |
| 160 callback.Run(permissions); | |
| 161 } | |
| 162 | |
| 163 void MediaDevicesDispatcherHost::VideoAccessChecked( | |
| 164 std::unique_ptr<MediaStreamUIProxy> ui_proxy, | |
| 165 bool has_audio_permission, | |
| 166 const AccessCheckedCallback& callback, | |
| 167 bool has_video_permission) { | |
| 168 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 169 MediaDevicesManager::BoolDeviceTypes permissions; | |
| 170 permissions[MEDIA_DEVICE_TYPE_AUDIO_INPUT] = has_audio_permission; | |
| 171 permissions[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT] = has_audio_permission; | |
| 172 permissions[MEDIA_DEVICE_TYPE_VIDEO_INPUT] = has_video_permission; | |
| 173 callback.Run(permissions); | |
| 174 } | 114 } |
| 175 | 115 |
| 176 void MediaDevicesDispatcherHost::DoEnumerateDevices( | 116 void MediaDevicesDispatcherHost::DoEnumerateDevices( |
| 177 const MediaDevicesManager::BoolDeviceTypes& requested_types, | 117 const MediaDevicesManager::BoolDeviceTypes& requested_types, |
| 178 const url::Origin& security_origin, | 118 const url::Origin& security_origin, |
| 179 const EnumerateDevicesCallback& client_callback, | 119 const EnumerateDevicesCallback& client_callback, |
| 180 const MediaDevicesManager::BoolDeviceTypes& has_permissions) { | 120 const MediaDevicesManager::BoolDeviceTypes& has_permissions) { |
| 181 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 121 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 182 media_stream_manager_->media_devices_manager()->EnumerateDevices( | 122 media_stream_manager_->media_devices_manager()->EnumerateDevices( |
| 183 requested_types, | 123 requested_types, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 200 | 140 |
| 201 for (const auto& device_info : enumeration[i]) { | 141 for (const auto& device_info : enumeration[i]) { |
| 202 result[i].push_back(TranslateDeviceInfo(has_permissions[i], | 142 result[i].push_back(TranslateDeviceInfo(has_permissions[i], |
| 203 device_id_salt_, group_id_salt_, | 143 device_id_salt_, group_id_salt_, |
| 204 security_origin, device_info)); | 144 security_origin, device_info)); |
| 205 } | 145 } |
| 206 } | 146 } |
| 207 client_callback.Run(result); | 147 client_callback.Run(result); |
| 208 } | 148 } |
| 209 | 149 |
| 210 std::unique_ptr<MediaStreamUIProxy> MediaDevicesDispatcherHost::GetUIProxy() { | |
| 211 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 212 if (use_fake_ui_) { | |
| 213 return fake_ui_proxy_ ? std::move(fake_ui_proxy_) | |
| 214 : base::MakeUnique<FakeMediaStreamUIProxy>(); | |
| 215 } | |
| 216 return MediaStreamUIProxy::Create(); | |
| 217 } | |
| 218 | |
| 219 void MediaDevicesDispatcherHost::SetFakeUIProxyForTesting( | |
| 220 std::unique_ptr<MediaStreamUIProxy> fake_ui_proxy) { | |
| 221 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 222 if (use_fake_ui_) | |
| 223 fake_ui_proxy_ = std::move(fake_ui_proxy); | |
| 224 } | |
| 225 | |
| 226 } // namespace content | 150 } // namespace content |
| OLD | NEW |