| 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_device_description.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 #include "url/gurl.h" |
| 25 #include "url/origin.h" |
| 24 | 26 |
| 25 namespace extensions { | 27 namespace extensions { |
| 26 | 28 |
| 27 using content::BrowserThread; | 29 using content::BrowserThread; |
| 28 using content::RenderProcessHost; | 30 using content::RenderProcessHost; |
| 29 using media::AudioDeviceNames; | 31 using media::AudioDeviceNames; |
| 30 using media::AudioManager; | 32 using media::AudioManager; |
| 31 | 33 |
| 32 namespace wap = api::webrtc_audio_private; | 34 namespace wap = api::webrtc_audio_private; |
| 33 | 35 |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 193 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 192 | 194 |
| 193 // We don't hash the default device name, and we always return | 195 // We don't hash the default device name, and we always return |
| 194 // "default" for the default device. There is code in SetActiveSink | 196 // "default" for the default device. There is code in SetActiveSink |
| 195 // that transforms "default" to the empty string, and code in | 197 // that transforms "default" to the empty string, and code in |
| 196 // GetActiveSink that ensures we return "default" if we get the | 198 // GetActiveSink that ensures we return "default" if we get the |
| 197 // empty string as the current device ID. | 199 // empty string as the current device ID. |
| 198 if (media::AudioDeviceDescription::IsDefaultDevice(raw_id)) | 200 if (media::AudioDeviceDescription::IsDefaultDevice(raw_id)) |
| 199 return media::AudioDeviceDescription::kDefaultDeviceId; | 201 return media::AudioDeviceDescription::kDefaultDeviceId; |
| 200 | 202 |
| 201 GURL security_origin(source_url().GetOrigin()); | 203 url::Origin security_origin(source_url().GetOrigin()); |
| 202 return content::GetHMACForMediaDeviceID(device_id_salt(), security_origin, | 204 return content::GetHMACForMediaDeviceID(device_id_salt(), security_origin, |
| 203 raw_id); | 205 raw_id); |
| 204 } | 206 } |
| 205 | 207 |
| 206 void WebrtcAudioPrivateFunction::InitDeviceIDSalt() { | 208 void WebrtcAudioPrivateFunction::InitDeviceIDSalt() { |
| 207 device_id_salt_ = GetProfile()->GetResourceContext()->GetMediaDeviceIDSalt(); | 209 device_id_salt_ = GetProfile()->GetResourceContext()->GetMediaDeviceIDSalt(); |
| 208 } | 210 } |
| 209 | 211 |
| 210 const content::ResourceContext::SaltCallback& | 212 const content::ResourceContext::SaltCallback& |
| 211 WebrtcAudioPrivateFunction::device_id_salt() const { | 213 WebrtcAudioPrivateFunction::device_id_salt() const { |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 FROM_HERE, | 441 FROM_HERE, |
| 440 base::Bind(&WebrtcAudioPrivateGetAssociatedSinkFunction:: | 442 base::Bind(&WebrtcAudioPrivateGetAssociatedSinkFunction:: |
| 441 GetRawSourceIDOnIOThread, | 443 GetRawSourceIDOnIOThread, |
| 442 this)); | 444 this)); |
| 443 } | 445 } |
| 444 | 446 |
| 445 void | 447 void |
| 446 WebrtcAudioPrivateGetAssociatedSinkFunction::GetRawSourceIDOnIOThread() { | 448 WebrtcAudioPrivateGetAssociatedSinkFunction::GetRawSourceIDOnIOThread() { |
| 447 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 449 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 448 | 450 |
| 449 GURL security_origin(params_->security_origin); | 451 url::Origin security_origin(GURL(params_->security_origin)); |
| 450 std::string source_id_in_origin(params_->source_id_in_origin); | 452 std::string source_id_in_origin(params_->source_id_in_origin); |
| 451 | 453 |
| 452 // Find the raw source ID for source_id_in_origin. | 454 // Find the raw source ID for source_id_in_origin. |
| 453 std::string raw_source_id; | 455 std::string raw_source_id; |
| 454 for (AudioDeviceNames::const_iterator it = source_devices_.begin(); | 456 for (AudioDeviceNames::const_iterator it = source_devices_.begin(); |
| 455 it != source_devices_.end(); | 457 it != source_devices_.end(); |
| 456 ++it) { | 458 ++it) { |
| 457 const std::string& id = it->unique_id; | 459 const std::string& id = it->unique_id; |
| 458 if (content::DoesMediaDeviceIDMatchHMAC(device_id_salt(), security_origin, | 460 if (content::DoesMediaDeviceIDMatchHMAC(device_id_salt(), security_origin, |
| 459 source_id_in_origin, id)) { | 461 source_id_in_origin, id)) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 results_.reset(wap::GetAssociatedSink::Results::Create("").release()); | 498 results_.reset(wap::GetAssociatedSink::Results::Create("").release()); |
| 497 } else { | 499 } else { |
| 498 results_.reset( | 500 results_.reset( |
| 499 wap::GetAssociatedSink::Results::Create(associated_sink_id).release()); | 501 wap::GetAssociatedSink::Results::Create(associated_sink_id).release()); |
| 500 } | 502 } |
| 501 | 503 |
| 502 SendResponse(true); | 504 SendResponse(true); |
| 503 } | 505 } |
| 504 | 506 |
| 505 } // namespace extensions | 507 } // namespace extensions |
| OLD | NEW |