| 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/memory/ptr_util.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/task_runner_util.h" | 12 #include "base/task_runner_util.h" |
| 13 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 13 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
| 14 #include "chrome/browser/extensions/extension_tab_util.h" | 14 #include "chrome/browser/extensions/extension_tab_util.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "content/public/browser/media_device_id.h" | 16 #include "content/public/browser/media_device_id.h" |
| 17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 18 #include "extensions/browser/event_router.h" | 18 #include "extensions/browser/event_router.h" |
| 19 #include "extensions/browser/extension_registry.h" | 19 #include "extensions/browser/extension_registry.h" |
| 20 #include "extensions/common/error_utils.h" | 20 #include "extensions/common/error_utils.h" |
| 21 #include "extensions/common/permissions/permissions_data.h" | 21 #include "extensions/common/permissions/permissions_data.h" |
| 22 #include "media/audio/audio_manager_base.h" | 22 #include "media/audio/audio_device_description.h" |
| 23 #include "media/audio/audio_output_controller.h" | 23 #include "media/audio/audio_output_controller.h" |
| 24 | 24 |
| 25 namespace extensions { | 25 namespace extensions { |
| 26 | 26 |
| 27 using content::BrowserThread; | 27 using content::BrowserThread; |
| 28 using content::RenderProcessHost; | 28 using content::RenderProcessHost; |
| 29 using media::AudioDeviceNames; | 29 using media::AudioDeviceNames; |
| 30 using media::AudioManager; | 30 using media::AudioManager; |
| 31 | 31 |
| 32 namespace wap = api::webrtc_audio_private; | 32 namespace wap = api::webrtc_audio_private; |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 | 188 |
| 189 std::string WebrtcAudioPrivateFunction::CalculateHMACImpl( | 189 std::string WebrtcAudioPrivateFunction::CalculateHMACImpl( |
| 190 const std::string& raw_id) { | 190 const std::string& raw_id) { |
| 191 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 191 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 192 | 192 |
| 193 // We don't hash the default device name, and we always return | 193 // We don't hash the default device name, and we always return |
| 194 // "default" for the default device. There is code in SetActiveSink | 194 // "default" for the default device. There is code in SetActiveSink |
| 195 // that transforms "default" to the empty string, and code in | 195 // that transforms "default" to the empty string, and code in |
| 196 // GetActiveSink that ensures we return "default" if we get the | 196 // GetActiveSink that ensures we return "default" if we get the |
| 197 // empty string as the current device ID. | 197 // empty string as the current device ID. |
| 198 if (raw_id.empty() || raw_id == media::AudioManagerBase::kDefaultDeviceId) | 198 if (media::AudioDeviceDescription::IsDefaultDevice(raw_id)) |
| 199 return media::AudioManagerBase::kDefaultDeviceId; | 199 return media::AudioDeviceDescription::kDefaultDeviceId; |
| 200 | 200 |
| 201 GURL security_origin(source_url().GetOrigin()); | 201 GURL security_origin(source_url().GetOrigin()); |
| 202 return content::GetHMACForMediaDeviceID(device_id_salt(), security_origin, | 202 return content::GetHMACForMediaDeviceID(device_id_salt(), security_origin, |
| 203 raw_id); | 203 raw_id); |
| 204 } | 204 } |
| 205 | 205 |
| 206 void WebrtcAudioPrivateFunction::InitDeviceIDSalt() { | 206 void WebrtcAudioPrivateFunction::InitDeviceIDSalt() { |
| 207 device_id_salt_ = GetProfile()->GetResourceContext()->GetMediaDeviceIDSalt(); | 207 device_id_salt_ = GetProfile()->GetResourceContext()->GetMediaDeviceIDSalt(); |
| 208 } | 208 } |
| 209 | 209 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 } | 290 } |
| 291 } | 291 } |
| 292 | 292 |
| 293 void WebrtcAudioPrivateGetActiveSinkFunction::OnHMACCalculated( | 293 void WebrtcAudioPrivateGetActiveSinkFunction::OnHMACCalculated( |
| 294 const std::string& hmac_id) { | 294 const std::string& hmac_id) { |
| 295 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 295 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 296 | 296 |
| 297 std::string result = hmac_id; | 297 std::string result = hmac_id; |
| 298 if (result.empty()) { | 298 if (result.empty()) { |
| 299 DVLOG(2) << "Received empty ID, replacing with default ID."; | 299 DVLOG(2) << "Received empty ID, replacing with default ID."; |
| 300 result = media::AudioManagerBase::kDefaultDeviceId; | 300 result = media::AudioDeviceDescription::kDefaultDeviceId; |
| 301 } | 301 } |
| 302 results_.reset(wap::GetActiveSink::Results::Create(result).release()); | 302 results_.reset(wap::GetActiveSink::Results::Create(result).release()); |
| 303 SendResponse(true); | 303 SendResponse(true); |
| 304 } | 304 } |
| 305 | 305 |
| 306 WebrtcAudioPrivateSetActiveSinkFunction:: | 306 WebrtcAudioPrivateSetActiveSinkFunction:: |
| 307 WebrtcAudioPrivateSetActiveSinkFunction() | 307 WebrtcAudioPrivateSetActiveSinkFunction() |
| 308 : num_remaining_sink_ids_(0) { | 308 : num_remaining_sink_ids_(0) { |
| 309 } | 309 } |
| 310 | 310 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 // function call. | 361 // function call. |
| 362 GetOutputDeviceNames(); | 362 GetOutputDeviceNames(); |
| 363 } | 363 } |
| 364 } | 364 } |
| 365 | 365 |
| 366 void WebrtcAudioPrivateSetActiveSinkFunction::OnOutputDeviceNames( | 366 void WebrtcAudioPrivateSetActiveSinkFunction::OnOutputDeviceNames( |
| 367 std::unique_ptr<AudioDeviceNames> device_names) { | 367 std::unique_ptr<AudioDeviceNames> device_names) { |
| 368 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 368 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 369 | 369 |
| 370 std::string raw_sink_id; | 370 std::string raw_sink_id; |
| 371 if (sink_id_ == media::AudioManagerBase::kDefaultDeviceId) { | 371 if (sink_id_ == media::AudioDeviceDescription::kDefaultDeviceId) { |
| 372 DVLOG(2) << "Received default ID, replacing with empty ID."; | 372 DVLOG(2) << "Received default ID, replacing with empty ID."; |
| 373 raw_sink_id = ""; | 373 raw_sink_id = ""; |
| 374 } else { | 374 } else { |
| 375 for (AudioDeviceNames::const_iterator it = device_names->begin(); | 375 for (AudioDeviceNames::const_iterator it = device_names->begin(); |
| 376 it != device_names->end(); | 376 it != device_names->end(); |
| 377 ++it) { | 377 ++it) { |
| 378 if (sink_id_ == CalculateHMACImpl(it->unique_id)) { | 378 if (sink_id_ == CalculateHMACImpl(it->unique_id)) { |
| 379 raw_sink_id = it->unique_id; | 379 raw_sink_id = it->unique_id; |
| 380 break; | 380 break; |
| 381 } | 381 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 AudioManager::Get()->GetAssociatedOutputDeviceID(raw_source_id); | 484 AudioManager::Get()->GetAssociatedOutputDeviceID(raw_source_id); |
| 485 } | 485 } |
| 486 | 486 |
| 487 CalculateHMAC(raw_sink_id); | 487 CalculateHMAC(raw_sink_id); |
| 488 } | 488 } |
| 489 | 489 |
| 490 void WebrtcAudioPrivateGetAssociatedSinkFunction::OnHMACCalculated( | 490 void WebrtcAudioPrivateGetAssociatedSinkFunction::OnHMACCalculated( |
| 491 const std::string& associated_sink_id) { | 491 const std::string& associated_sink_id) { |
| 492 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 492 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 493 | 493 |
| 494 if (associated_sink_id == media::AudioManagerBase::kDefaultDeviceId) { | 494 if (associated_sink_id == media::AudioDeviceDescription::kDefaultDeviceId) { |
| 495 DVLOG(2) << "Got default ID, replacing with empty ID."; | 495 DVLOG(2) << "Got default ID, replacing with empty ID."; |
| 496 results_.reset(wap::GetAssociatedSink::Results::Create("").release()); | 496 results_.reset(wap::GetAssociatedSink::Results::Create("").release()); |
| 497 } else { | 497 } else { |
| 498 results_.reset( | 498 results_.reset( |
| 499 wap::GetAssociatedSink::Results::Create(associated_sink_id).release()); | 499 wap::GetAssociatedSink::Results::Create(associated_sink_id).release()); |
| 500 } | 500 } |
| 501 | 501 |
| 502 SendResponse(true); | 502 SendResponse(true); |
| 503 } | 503 } |
| 504 | 504 |
| 505 } // namespace extensions | 505 } // namespace extensions |
| OLD | NEW |