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 base::Bind(&AudioOutputAuthorizationHandler::AccessChecked, | 130 base::BindOnce(&AudioOutputAuthorizationHandler::AccessChecked, |
129 weak_factory_.GetWeakPtr(), std::move(cb), device_id, | 131 weak_factory_.GetWeakPtr(), std::move(cb), device_id, |
130 security_origin)); | 132 security_origin)); |
131 } | 133 } |
132 | 134 |
133 void AudioOutputAuthorizationHandler::AccessChecked( | 135 void AudioOutputAuthorizationHandler::AccessChecked( |
134 AuthorizationCompletedCallback cb, | 136 AuthorizationCompletedCallback cb, |
135 const std::string& device_id, | 137 const std::string& device_id, |
136 const url::Origin& security_origin, | 138 const url::Origin& security_origin, |
137 bool has_access) const { | 139 bool has_access) const { |
138 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 140 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
139 | 141 |
140 if (!has_access) { | 142 if (!has_access) { |
141 cb.Run(media::OUTPUT_DEVICE_STATUS_ERROR_NOT_AUTHORIZED, false, | 143 std::move(cb).Run(media::OUTPUT_DEVICE_STATUS_ERROR_NOT_AUTHORIZED, false, |
142 media::AudioParameters::UnavailableDeviceParams(), std::string()); | 144 media::AudioParameters::UnavailableDeviceParams(), |
| 145 std::string()); |
143 return; | 146 return; |
144 } | 147 } |
145 | 148 |
146 // For default device, read output parameters directly. Nondefault | 149 // For default device, read output parameters directly. Nondefault |
147 // devices require translation first. | 150 // devices require translation first. |
148 if (media::AudioDeviceDescription::IsDefaultDevice(device_id)) { | 151 if (media::AudioDeviceDescription::IsDefaultDevice(device_id)) { |
149 GetDeviceParameters(std::move(cb), | 152 GetDeviceParameters(std::move(cb), |
150 media::AudioDeviceDescription::kDefaultDeviceId); | 153 media::AudioDeviceDescription::kDefaultDeviceId); |
151 } else { | 154 return; |
152 MediaDevicesManager::BoolDeviceTypes devices_to_enumerate; | |
153 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT] = true; | |
154 media_stream_manager_->media_devices_manager()->EnumerateDevices( | |
155 devices_to_enumerate, | |
156 base::Bind(&AudioOutputAuthorizationHandler::TranslateDeviceID, | |
157 weak_factory_.GetWeakPtr(), std::move(cb), device_id, | |
158 security_origin)); | |
159 } | 155 } |
| 156 MediaDevicesManager::BoolDeviceTypes devices_to_enumerate; |
| 157 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT] = true; |
| 158 media_stream_manager_->media_devices_manager()->EnumerateDevices( |
| 159 devices_to_enumerate, |
| 160 base::Bind(&AudioOutputAuthorizationHandler::TranslateDeviceID, |
| 161 weak_factory_.GetWeakPtr(), base::Passed(&cb), device_id, |
| 162 security_origin)); |
160 } | 163 } |
161 | 164 |
162 void AudioOutputAuthorizationHandler::TranslateDeviceID( | 165 void AudioOutputAuthorizationHandler::TranslateDeviceID( |
163 AuthorizationCompletedCallback cb, | 166 AuthorizationCompletedCallback cb, |
164 const std::string& device_id, | 167 const std::string& device_id, |
165 const url::Origin& security_origin, | 168 const url::Origin& security_origin, |
166 const MediaDeviceEnumeration& enumeration) const { | 169 const MediaDeviceEnumeration& enumeration) const { |
167 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 170 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
168 DCHECK(!media::AudioDeviceDescription::IsDefaultDevice(device_id)); | 171 DCHECK(!media::AudioDeviceDescription::IsDefaultDevice(device_id)); |
169 for (const MediaDeviceInfo& device_info : | 172 for (const MediaDeviceInfo& device_info : |
170 enumeration[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT]) { | 173 enumeration[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT]) { |
171 if (content::DoesMediaDeviceIDMatchHMAC(salt_, security_origin, device_id, | 174 if (content::DoesMediaDeviceIDMatchHMAC(salt_, security_origin, device_id, |
172 device_info.device_id)) { | 175 device_info.device_id)) { |
173 GetDeviceParameters(std::move(cb), device_info.device_id); | 176 GetDeviceParameters(std::move(cb), device_info.device_id); |
174 return; | 177 return; |
175 } | 178 } |
176 } | 179 } |
177 cb.Run(media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND, false, | 180 std::move(cb).Run(media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND, false, |
178 media::AudioParameters::UnavailableDeviceParams(), std::string()); | 181 media::AudioParameters::UnavailableDeviceParams(), |
| 182 std::string()); |
179 } | 183 } |
180 | 184 |
181 void AudioOutputAuthorizationHandler::GetDeviceParameters( | 185 void AudioOutputAuthorizationHandler::GetDeviceParameters( |
182 AuthorizationCompletedCallback cb, | 186 AuthorizationCompletedCallback cb, |
183 const std::string& raw_device_id) const { | 187 const std::string& raw_device_id) const { |
184 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 188 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
185 DCHECK(!raw_device_id.empty()); | 189 DCHECK(!raw_device_id.empty()); |
186 audio_system_->GetOutputStreamParameters( | 190 audio_system_->GetOutputStreamParameters( |
187 raw_device_id, | 191 raw_device_id, |
188 base::Bind(&AudioOutputAuthorizationHandler::DeviceParametersReceived, | 192 base::BindOnce(&AudioOutputAuthorizationHandler::DeviceParametersReceived, |
189 weak_factory_.GetWeakPtr(), std::move(cb), false, | 193 weak_factory_.GetWeakPtr(), std::move(cb), false, |
190 raw_device_id)); | 194 raw_device_id)); |
191 } | 195 } |
192 | 196 |
193 void AudioOutputAuthorizationHandler::DeviceParametersReceived( | 197 void AudioOutputAuthorizationHandler::DeviceParametersReceived( |
194 AuthorizationCompletedCallback cb, | 198 AuthorizationCompletedCallback cb, |
195 bool should_send_id, | 199 bool should_send_id, |
196 const std::string& raw_device_id, | 200 const std::string& raw_device_id, |
197 const media::AudioParameters& output_params) const { | 201 const media::AudioParameters& output_params) const { |
198 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 202 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
199 DCHECK(!raw_device_id.empty()); | 203 DCHECK(!raw_device_id.empty()); |
200 | 204 |
201 cb.Run(media::OUTPUT_DEVICE_STATUS_OK, should_send_id, | 205 std::move(cb).Run(media::OUTPUT_DEVICE_STATUS_OK, should_send_id, |
202 output_params.IsValid() ? output_params | 206 output_params.IsValid() |
203 : TryToFixAudioParameters(output_params), | 207 ? output_params |
204 raw_device_id); | 208 : TryToFixAudioParameters(output_params), |
| 209 raw_device_id); |
205 } | 210 } |
206 | 211 |
207 } // namespace content | 212 } // namespace content |
OLD | NEW |