| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_privat
e_api.h" | 5 #include "chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_privat
e_api.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/task_runner_util.h" | 12 #include "base/task_runner_util.h" |
| 12 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 13 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
| 13 #include "chrome/browser/extensions/extension_tab_util.h" | 14 #include "chrome/browser/extensions/extension_tab_util.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 15 #include "content/public/browser/media_device_id.h" | 16 #include "content/public/browser/media_device_id.h" |
| 16 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 17 #include "extensions/browser/event_router.h" | 18 #include "extensions/browser/event_router.h" |
| 18 #include "extensions/browser/extension_registry.h" | 19 #include "extensions/browser/extension_registry.h" |
| 19 #include "extensions/common/error_utils.h" | 20 #include "extensions/common/error_utils.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 | 86 |
| 86 EventRouter* router = EventRouter::Get(browser_context_); | 87 EventRouter* router = EventRouter::Get(browser_context_); |
| 87 if (!router || !router->HasEventListener(kEventName)) | 88 if (!router || !router->HasEventListener(kEventName)) |
| 88 return; | 89 return; |
| 89 | 90 |
| 90 for (const scoped_refptr<const extensions::Extension>& extension : | 91 for (const scoped_refptr<const extensions::Extension>& extension : |
| 91 ExtensionRegistry::Get(browser_context_)->enabled_extensions()) { | 92 ExtensionRegistry::Get(browser_context_)->enabled_extensions()) { |
| 92 const std::string& extension_id = extension->id(); | 93 const std::string& extension_id = extension->id(); |
| 93 if (router->ExtensionHasEventListener(extension_id, kEventName) && | 94 if (router->ExtensionHasEventListener(extension_id, kEventName) && |
| 94 extension->permissions_data()->HasAPIPermission("webrtcAudioPrivate")) { | 95 extension->permissions_data()->HasAPIPermission("webrtcAudioPrivate")) { |
| 95 scoped_ptr<Event> event( | 96 std::unique_ptr<Event> event( |
| 96 new Event(events::WEBRTC_AUDIO_PRIVATE_ON_SINKS_CHANGED, kEventName, | 97 new Event(events::WEBRTC_AUDIO_PRIVATE_ON_SINKS_CHANGED, kEventName, |
| 97 make_scoped_ptr(new base::ListValue()))); | 98 base::WrapUnique(new base::ListValue()))); |
| 98 router->DispatchEventToExtension(extension_id, std::move(event)); | 99 router->DispatchEventToExtension(extension_id, std::move(event)); |
| 99 } | 100 } |
| 100 } | 101 } |
| 101 } | 102 } |
| 102 | 103 |
| 103 WebrtcAudioPrivateFunction::WebrtcAudioPrivateFunction() {} | 104 WebrtcAudioPrivateFunction::WebrtcAudioPrivateFunction() {} |
| 104 | 105 |
| 105 WebrtcAudioPrivateFunction::~WebrtcAudioPrivateFunction() { | 106 WebrtcAudioPrivateFunction::~WebrtcAudioPrivateFunction() { |
| 106 } | 107 } |
| 107 | 108 |
| 108 void WebrtcAudioPrivateFunction::GetOutputDeviceNames() { | 109 void WebrtcAudioPrivateFunction::GetOutputDeviceNames() { |
| 109 scoped_refptr<base::SingleThreadTaskRunner> audio_manager_runner = | 110 scoped_refptr<base::SingleThreadTaskRunner> audio_manager_runner = |
| 110 AudioManager::Get()->GetTaskRunner(); | 111 AudioManager::Get()->GetTaskRunner(); |
| 111 if (!audio_manager_runner->BelongsToCurrentThread()) { | 112 if (!audio_manager_runner->BelongsToCurrentThread()) { |
| 112 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 113 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 113 audio_manager_runner->PostTask( | 114 audio_manager_runner->PostTask( |
| 114 FROM_HERE, | 115 FROM_HERE, |
| 115 base::Bind(&WebrtcAudioPrivateFunction::GetOutputDeviceNames, this)); | 116 base::Bind(&WebrtcAudioPrivateFunction::GetOutputDeviceNames, this)); |
| 116 return; | 117 return; |
| 117 } | 118 } |
| 118 | 119 |
| 119 scoped_ptr<AudioDeviceNames> device_names(new AudioDeviceNames); | 120 std::unique_ptr<AudioDeviceNames> device_names(new AudioDeviceNames); |
| 120 AudioManager::Get()->GetAudioOutputDeviceNames(device_names.get()); | 121 AudioManager::Get()->GetAudioOutputDeviceNames(device_names.get()); |
| 121 | 122 |
| 122 BrowserThread::PostTask( | 123 BrowserThread::PostTask( |
| 123 BrowserThread::IO, FROM_HERE, | 124 BrowserThread::IO, FROM_HERE, |
| 124 base::Bind(&WebrtcAudioPrivateFunction::OnOutputDeviceNames, this, | 125 base::Bind(&WebrtcAudioPrivateFunction::OnOutputDeviceNames, this, |
| 125 base::Passed(&device_names))); | 126 base::Passed(&device_names))); |
| 126 } | 127 } |
| 127 | 128 |
| 128 void WebrtcAudioPrivateFunction::OnOutputDeviceNames( | 129 void WebrtcAudioPrivateFunction::OnOutputDeviceNames( |
| 129 scoped_ptr<AudioDeviceNames> device_names) { | 130 std::unique_ptr<AudioDeviceNames> device_names) { |
| 130 NOTREACHED(); | 131 NOTREACHED(); |
| 131 } | 132 } |
| 132 | 133 |
| 133 bool WebrtcAudioPrivateFunction::GetControllerList(const RequestInfo& request) { | 134 bool WebrtcAudioPrivateFunction::GetControllerList(const RequestInfo& request) { |
| 134 content::RenderProcessHost* rph = nullptr; | 135 content::RenderProcessHost* rph = nullptr; |
| 135 | 136 |
| 136 // If |guest_process_id| is defined, directly use this id to find the | 137 // If |guest_process_id| is defined, directly use this id to find the |
| 137 // corresponding RenderProcessHost. | 138 // corresponding RenderProcessHost. |
| 138 if (request.guest_process_id.get()) { | 139 if (request.guest_process_id.get()) { |
| 139 rph = content::RenderProcessHost::FromID(*request.guest_process_id.get()); | 140 rph = content::RenderProcessHost::FromID(*request.guest_process_id.get()); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 bool WebrtcAudioPrivateGetSinksFunction::RunAsync() { | 216 bool WebrtcAudioPrivateGetSinksFunction::RunAsync() { |
| 216 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 217 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 217 | 218 |
| 218 InitDeviceIDSalt(); | 219 InitDeviceIDSalt(); |
| 219 GetOutputDeviceNames(); | 220 GetOutputDeviceNames(); |
| 220 | 221 |
| 221 return true; | 222 return true; |
| 222 } | 223 } |
| 223 | 224 |
| 224 void WebrtcAudioPrivateGetSinksFunction::OnOutputDeviceNames( | 225 void WebrtcAudioPrivateGetSinksFunction::OnOutputDeviceNames( |
| 225 scoped_ptr<AudioDeviceNames> raw_ids) { | 226 std::unique_ptr<AudioDeviceNames> raw_ids) { |
| 226 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 227 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 227 | 228 |
| 228 std::vector<wap::SinkInfo> results; | 229 std::vector<wap::SinkInfo> results; |
| 229 for (const media::AudioDeviceName& name : *raw_ids) { | 230 for (const media::AudioDeviceName& name : *raw_ids) { |
| 230 wap::SinkInfo info; | 231 wap::SinkInfo info; |
| 231 info.sink_id = CalculateHMACImpl(name.unique_id); | 232 info.sink_id = CalculateHMACImpl(name.unique_id); |
| 232 info.sink_label = name.device_name; | 233 info.sink_label = name.device_name; |
| 233 // TODO(joi): Add other parameters. | 234 // TODO(joi): Add other parameters. |
| 234 results.push_back(std::move(info)); | 235 results.push_back(std::move(info)); |
| 235 } | 236 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 251 } | 252 } |
| 252 | 253 |
| 253 void WebrtcAudioPrivateGetSinksFunction::DoneOnUIThread() { | 254 void WebrtcAudioPrivateGetSinksFunction::DoneOnUIThread() { |
| 254 SendResponse(true); | 255 SendResponse(true); |
| 255 } | 256 } |
| 256 | 257 |
| 257 bool WebrtcAudioPrivateGetActiveSinkFunction::RunAsync() { | 258 bool WebrtcAudioPrivateGetActiveSinkFunction::RunAsync() { |
| 258 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 259 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 259 InitDeviceIDSalt(); | 260 InitDeviceIDSalt(); |
| 260 | 261 |
| 261 scoped_ptr<wap::GetActiveSink::Params> params( | 262 std::unique_ptr<wap::GetActiveSink::Params> params( |
| 262 wap::GetActiveSink::Params::Create(*args_)); | 263 wap::GetActiveSink::Params::Create(*args_)); |
| 263 EXTENSION_FUNCTION_VALIDATE(params.get()); | 264 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 264 | 265 |
| 265 return GetControllerList(params->request); | 266 return GetControllerList(params->request); |
| 266 } | 267 } |
| 267 | 268 |
| 268 void WebrtcAudioPrivateGetActiveSinkFunction::OnControllerList( | 269 void WebrtcAudioPrivateGetActiveSinkFunction::OnControllerList( |
| 269 const RenderProcessHost::AudioOutputControllerList& controllers) { | 270 const RenderProcessHost::AudioOutputControllerList& controllers) { |
| 270 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 271 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 271 | 272 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 WebrtcAudioPrivateSetActiveSinkFunction() | 307 WebrtcAudioPrivateSetActiveSinkFunction() |
| 307 : num_remaining_sink_ids_(0) { | 308 : num_remaining_sink_ids_(0) { |
| 308 } | 309 } |
| 309 | 310 |
| 310 WebrtcAudioPrivateSetActiveSinkFunction:: | 311 WebrtcAudioPrivateSetActiveSinkFunction:: |
| 311 ~WebrtcAudioPrivateSetActiveSinkFunction() { | 312 ~WebrtcAudioPrivateSetActiveSinkFunction() { |
| 312 } | 313 } |
| 313 | 314 |
| 314 bool WebrtcAudioPrivateSetActiveSinkFunction::RunAsync() { | 315 bool WebrtcAudioPrivateSetActiveSinkFunction::RunAsync() { |
| 315 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 316 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 316 scoped_ptr<wap::SetActiveSink::Params> params( | 317 std::unique_ptr<wap::SetActiveSink::Params> params( |
| 317 wap::SetActiveSink::Params::Create(*args_)); | 318 wap::SetActiveSink::Params::Create(*args_)); |
| 318 EXTENSION_FUNCTION_VALIDATE(params.get()); | 319 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 319 | 320 |
| 320 InitDeviceIDSalt(); | 321 InitDeviceIDSalt(); |
| 321 | 322 |
| 322 if (params->request.guest_process_id.get()) { | 323 if (params->request.guest_process_id.get()) { |
| 323 request_info_.guest_process_id.reset( | 324 request_info_.guest_process_id.reset( |
| 324 new int(*params->request.guest_process_id.get())); | 325 new int(*params->request.guest_process_id.get())); |
| 325 } else if (params->request.tab_id.get()) { | 326 } else if (params->request.tab_id.get()) { |
| 326 request_info_.tab_id.reset(new int(*params->request.tab_id.get())); | 327 request_info_.tab_id.reset(new int(*params->request.tab_id.get())); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 356 SendResponse(false); | 357 SendResponse(false); |
| 357 } else { | 358 } else { |
| 358 // We need to get the output device names, and calculate the HMAC | 359 // We need to get the output device names, and calculate the HMAC |
| 359 // for each, to find the raw ID for the ID provided to this API | 360 // for each, to find the raw ID for the ID provided to this API |
| 360 // function call. | 361 // function call. |
| 361 GetOutputDeviceNames(); | 362 GetOutputDeviceNames(); |
| 362 } | 363 } |
| 363 } | 364 } |
| 364 | 365 |
| 365 void WebrtcAudioPrivateSetActiveSinkFunction::OnOutputDeviceNames( | 366 void WebrtcAudioPrivateSetActiveSinkFunction::OnOutputDeviceNames( |
| 366 scoped_ptr<AudioDeviceNames> device_names) { | 367 std::unique_ptr<AudioDeviceNames> device_names) { |
| 367 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 368 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 368 | 369 |
| 369 std::string raw_sink_id; | 370 std::string raw_sink_id; |
| 370 if (sink_id_ == media::AudioManagerBase::kDefaultDeviceId) { | 371 if (sink_id_ == media::AudioManagerBase::kDefaultDeviceId) { |
| 371 DVLOG(2) << "Received default ID, replacing with empty ID."; | 372 DVLOG(2) << "Received default ID, replacing with empty ID."; |
| 372 raw_sink_id = ""; | 373 raw_sink_id = ""; |
| 373 } else { | 374 } else { |
| 374 for (AudioDeviceNames::const_iterator it = device_names->begin(); | 375 for (AudioDeviceNames::const_iterator it = device_names->begin(); |
| 375 it != device_names->end(); | 376 it != device_names->end(); |
| 376 ++it) { | 377 ++it) { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 results_.reset(wap::GetAssociatedSink::Results::Create("").release()); | 496 results_.reset(wap::GetAssociatedSink::Results::Create("").release()); |
| 496 } else { | 497 } else { |
| 497 results_.reset( | 498 results_.reset( |
| 498 wap::GetAssociatedSink::Results::Create(associated_sink_id).release()); | 499 wap::GetAssociatedSink::Results::Create(associated_sink_id).release()); |
| 499 } | 500 } |
| 500 | 501 |
| 501 SendResponse(true); | 502 SendResponse(true); |
| 502 } | 503 } |
| 503 | 504 |
| 504 } // namespace extensions | 505 } // namespace extensions |
| OLD | NEW |