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/audio_output_authorization_handler .h" | 5 #include "content/browser/renderer_host/media/audio_output_authorization_handler .h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/task_runner_util.h" | 8 #include "base/task_runner_util.h" |
9 #include "content/browser/bad_message.h" | 9 #include "content/browser/bad_message.h" |
10 #include "content/browser/renderer_host/media/audio_input_device_manager.h" | 10 #include "content/browser/renderer_host/media/audio_input_device_manager.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 | 67 |
68 void AudioOutputAuthorizationHandler::RequestDeviceAuthorization( | 68 void AudioOutputAuthorizationHandler::RequestDeviceAuthorization( |
69 int render_frame_id, | 69 int render_frame_id, |
70 int session_id, | 70 int session_id, |
71 const std::string& device_id, | 71 const std::string& device_id, |
72 const url::Origin& security_origin, | 72 const url::Origin& security_origin, |
73 AuthorizationCompletedCallback cb) const { | 73 AuthorizationCompletedCallback cb) const { |
74 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 74 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
75 | 75 |
76 if (!IsValidDeviceId(device_id)) { | 76 if (!IsValidDeviceId(device_id)) { |
77 cb.Run(media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND, false, | 77 std::move(cb).Run(media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND, false, |
78 media::AudioParameters::UnavailableDeviceParams(), std::string()); | 78 media::AudioParameters::UnavailableDeviceParams(), |
79 std::string()); | |
79 return; | 80 return; |
80 } | 81 } |
81 | 82 |
82 // If |session_id| should be used for output device selection and such an | 83 // If |session_id| should be used for output device selection and such an |
83 // output device is found, reuse the input device permissions. | 84 // output device is found, reuse the input device permissions. |
84 if (media::AudioDeviceDescription::UseSessionIdToSelectDevice(session_id, | 85 if (media::AudioDeviceDescription::UseSessionIdToSelectDevice(session_id, |
85 device_id)) { | 86 device_id)) { |
86 const StreamDeviceInfo* info = | 87 const StreamDeviceInfo* info = |
87 media_stream_manager_->audio_input_device_manager() | 88 media_stream_manager_->audio_input_device_manager() |
88 ->GetOpenedDeviceInfoById(session_id); | 89 ->GetOpenedDeviceInfoById(session_id); |
(...skipping 18 matching lines...) Expand all Loading... | |
107 | 108 |
108 if (media::AudioDeviceDescription::IsDefaultDevice(device_id)) { | 109 if (media::AudioDeviceDescription::IsDefaultDevice(device_id)) { |
109 // Default device doesn't need authorization. | 110 // Default device doesn't need authorization. |
110 AccessChecked(std::move(cb), device_id, security_origin, true); | 111 AccessChecked(std::move(cb), device_id, security_origin, true); |
111 return; | 112 return; |
112 } | 113 } |
113 | 114 |
114 // Check security origin if nondefault device is requested. | 115 // Check security origin if nondefault device is requested. |
115 if (!MediaStreamManager::IsOriginAllowed(render_process_id_, | 116 if (!MediaStreamManager::IsOriginAllowed(render_process_id_, |
116 security_origin)) { | 117 security_origin)) { |
117 cb.Run(media::OUTPUT_DEVICE_STATUS_ERROR_NOT_AUTHORIZED, false, | 118 std::move(cb).Run(media::OUTPUT_DEVICE_STATUS_ERROR_NOT_AUTHORIZED, false, |
118 media::AudioParameters::UnavailableDeviceParams(), std::string()); | 119 media::AudioParameters::UnavailableDeviceParams(), |
120 std::string()); | |
119 bad_message::ReceivedBadMessage(render_process_id_, | 121 bad_message::ReceivedBadMessage(render_process_id_, |
120 bad_message::AOAH_UNAUTHORIZED_URL); | 122 bad_message::AOAH_UNAUTHORIZED_URL); |
121 return; | 123 return; |
122 } | 124 } |
123 | 125 |
124 // Check that MediaStream device permissions have been granted for | 126 // Check that MediaStream device permissions have been granted for |
125 // nondefault devices. | 127 // nondefault devices. |
126 permission_checker_->CheckPermission( | 128 permission_checker_->CheckPermission( |
127 MEDIA_DEVICE_TYPE_AUDIO_OUTPUT, render_process_id_, render_frame_id, | 129 MEDIA_DEVICE_TYPE_AUDIO_OUTPUT, render_process_id_, render_frame_id, |
128 security_origin, | 130 security_origin, |
129 base::Bind(&AudioOutputAuthorizationHandler::AccessChecked, | 131 base::BindOnce(&AudioOutputAuthorizationHandler::AccessChecked, |
130 weak_factory_.GetWeakPtr(), std::move(cb), device_id, | 132 weak_factory_.GetWeakPtr(), std::move(cb), device_id, |
131 security_origin)); | 133 security_origin)); |
132 } | 134 } |
133 | 135 |
134 void AudioOutputAuthorizationHandler::AccessChecked( | 136 void AudioOutputAuthorizationHandler::AccessChecked( |
135 AuthorizationCompletedCallback cb, | 137 AuthorizationCompletedCallback cb, |
136 const std::string& device_id, | 138 const std::string& device_id, |
137 const url::Origin& security_origin, | 139 const url::Origin& security_origin, |
138 bool has_access) const { | 140 bool has_access) const { |
139 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 141 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
140 | 142 |
141 if (!has_access) { | 143 if (!has_access) { |
142 cb.Run(media::OUTPUT_DEVICE_STATUS_ERROR_NOT_AUTHORIZED, false, | 144 std::move(cb).Run(media::OUTPUT_DEVICE_STATUS_ERROR_NOT_AUTHORIZED, false, |
143 media::AudioParameters::UnavailableDeviceParams(), std::string()); | 145 media::AudioParameters::UnavailableDeviceParams(), |
146 std::string()); | |
144 return; | 147 return; |
145 } | 148 } |
146 | 149 |
147 // For default device, read output parameters directly. Nondefault | 150 // For default device, read output parameters directly. Nondefault |
148 // devices require translation first. | 151 // devices require translation first. |
149 if (media::AudioDeviceDescription::IsDefaultDevice(device_id)) { | 152 if (media::AudioDeviceDescription::IsDefaultDevice(device_id)) { |
150 GetDeviceParameters(std::move(cb), | 153 GetDeviceParameters(std::move(cb), |
151 media::AudioDeviceDescription::kDefaultDeviceId); | 154 media::AudioDeviceDescription::kDefaultDeviceId); |
152 } else { | 155 return; |
153 MediaDevicesManager::BoolDeviceTypes devices_to_enumerate; | |
154 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT] = true; | |
155 media_stream_manager_->media_devices_manager()->EnumerateDevices( | |
156 devices_to_enumerate, | |
157 base::Bind(&AudioOutputAuthorizationHandler::TranslateDeviceID, | |
158 weak_factory_.GetWeakPtr(), std::move(cb), device_id, | |
159 security_origin)); | |
160 } | 156 } |
157 MediaDevicesManager::BoolDeviceTypes devices_to_enumerate; | |
158 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT] = true; | |
159 media_stream_manager_->media_devices_manager()->EnumerateDevices( | |
160 devices_to_enumerate, | |
161 base::Bind(&AudioOutputAuthorizationHandler::TranslateDeviceID, | |
o1ka
2017/05/10 08:03:02
Once?
Max Morin
2017/05/10 10:39:59
This would require messing around with MediaDevice
| |
162 weak_factory_.GetWeakPtr(), base::Passed(&cb), device_id, | |
163 security_origin)); | |
161 } | 164 } |
162 | 165 |
163 void AudioOutputAuthorizationHandler::TranslateDeviceID( | 166 void AudioOutputAuthorizationHandler::TranslateDeviceID( |
164 AuthorizationCompletedCallback cb, | 167 AuthorizationCompletedCallback cb, |
165 const std::string& device_id, | 168 const std::string& device_id, |
166 const url::Origin& security_origin, | 169 const url::Origin& security_origin, |
167 const MediaDeviceEnumeration& enumeration) const { | 170 const MediaDeviceEnumeration& enumeration) const { |
168 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 171 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
169 DCHECK(!media::AudioDeviceDescription::IsDefaultDevice(device_id)); | 172 DCHECK(!media::AudioDeviceDescription::IsDefaultDevice(device_id)); |
170 for (const MediaDeviceInfo& device_info : | 173 for (const MediaDeviceInfo& device_info : |
171 enumeration[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT]) { | 174 enumeration[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT]) { |
172 if (content::DoesMediaDeviceIDMatchHMAC(salt_, security_origin, device_id, | 175 if (content::DoesMediaDeviceIDMatchHMAC(salt_, security_origin, device_id, |
173 device_info.device_id)) { | 176 device_info.device_id)) { |
174 GetDeviceParameters(std::move(cb), device_info.device_id); | 177 GetDeviceParameters(std::move(cb), device_info.device_id); |
175 return; | 178 return; |
176 } | 179 } |
177 } | 180 } |
178 cb.Run(media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND, false, | 181 std::move(cb).Run(media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND, false, |
179 media::AudioParameters::UnavailableDeviceParams(), std::string()); | 182 media::AudioParameters::UnavailableDeviceParams(), |
183 std::string()); | |
180 } | 184 } |
181 | 185 |
182 void AudioOutputAuthorizationHandler::GetDeviceParameters( | 186 void AudioOutputAuthorizationHandler::GetDeviceParameters( |
183 AuthorizationCompletedCallback cb, | 187 AuthorizationCompletedCallback cb, |
184 const std::string& raw_device_id) const { | 188 const std::string& raw_device_id) const { |
185 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 189 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
186 DCHECK(!raw_device_id.empty()); | 190 DCHECK(!raw_device_id.empty()); |
187 audio_system_->GetOutputStreamParameters( | 191 audio_system_->GetOutputStreamParameters( |
188 raw_device_id, | 192 raw_device_id, |
189 base::Bind(&AudioOutputAuthorizationHandler::DeviceParametersReceived, | 193 base::BindOnce(&AudioOutputAuthorizationHandler::DeviceParametersReceived, |
190 weak_factory_.GetWeakPtr(), std::move(cb), false, | 194 weak_factory_.GetWeakPtr(), std::move(cb), false, |
191 raw_device_id)); | 195 raw_device_id)); |
192 } | 196 } |
193 | 197 |
194 void AudioOutputAuthorizationHandler::DeviceParametersReceived( | 198 void AudioOutputAuthorizationHandler::DeviceParametersReceived( |
195 AuthorizationCompletedCallback cb, | 199 AuthorizationCompletedCallback cb, |
196 bool should_send_id, | 200 bool should_send_id, |
197 const std::string& raw_device_id, | 201 const std::string& raw_device_id, |
198 const media::AudioParameters& output_params) const { | 202 const media::AudioParameters& output_params) const { |
199 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 203 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
200 DCHECK(!raw_device_id.empty()); | 204 DCHECK(!raw_device_id.empty()); |
201 | 205 |
202 cb.Run(media::OUTPUT_DEVICE_STATUS_OK, should_send_id, | 206 std::move(cb).Run(media::OUTPUT_DEVICE_STATUS_OK, should_send_id, |
203 output_params.IsValid() ? output_params | 207 output_params.IsValid() |
204 : TryToFixAudioParameters(output_params), | 208 ? output_params |
205 raw_device_id); | 209 : TryToFixAudioParameters(output_params), |
210 raw_device_id); | |
206 } | 211 } |
207 | 212 |
208 } // namespace content | 213 } // namespace content |
OLD | NEW |