Chromium Code Reviews| 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 <memory> | |
| 7 #include <utility> | 8 #include <utility> |
| 8 #include <vector> | 9 #include <vector> |
| 9 | 10 |
| 10 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 11 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 12 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/stringprintf.h" | |
| 13 #include "base/task_runner_util.h" | 15 #include "base/task_runner_util.h" |
| 14 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 16 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
| 15 #include "chrome/browser/extensions/extension_tab_util.h" | 17 #include "chrome/browser/extensions/extension_tab_util.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 17 #include "content/public/browser/media_device_id.h" | 19 #include "content/public/browser/media_device_id.h" |
| 18 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 19 #include "extensions/browser/event_router.h" | 21 #include "extensions/browser/event_router.h" |
| 20 #include "extensions/browser/extension_registry.h" | 22 #include "extensions/browser/extension_registry.h" |
| 21 #include "extensions/common/error_utils.h" | 23 #include "extensions/common/error_utils.h" |
| 22 #include "extensions/common/permissions/permissions_data.h" | 24 #include "extensions/common/permissions/permissions_data.h" |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 } | 212 } |
| 211 | 213 |
| 212 void WebrtcAudioPrivateFunction::InitDeviceIDSalt() { | 214 void WebrtcAudioPrivateFunction::InitDeviceIDSalt() { |
| 213 device_id_salt_ = GetProfile()->GetResourceContext()->GetMediaDeviceIDSalt(); | 215 device_id_salt_ = GetProfile()->GetResourceContext()->GetMediaDeviceIDSalt(); |
| 214 } | 216 } |
| 215 | 217 |
| 216 std::string WebrtcAudioPrivateFunction::device_id_salt() const { | 218 std::string WebrtcAudioPrivateFunction::device_id_salt() const { |
| 217 return device_id_salt_; | 219 return device_id_salt_; |
| 218 } | 220 } |
| 219 | 221 |
| 222 // TODO(hlundin): Stolen from WebrtcLoggingPrivateFunction. Maybe consolidate? | |
| 223 content::RenderProcessHost* WebrtcAudioPrivateFunction::RphFromRequest( | |
| 224 const RequestInfo& request, | |
| 225 const std::string& security_origin) { | |
| 226 // If |guest_process_id| is defined, directly use this id to find the | |
| 227 // corresponding RenderProcessHost. | |
| 228 if (request.guest_process_id.get()) | |
|
Devlin
2017/04/10 21:34:24
nit: no need for .get() (same for below)
hlundin-chromium
2017/04/11 09:19:37
Done.
| |
| 229 return content::RenderProcessHost::FromID(*request.guest_process_id); | |
| 230 | |
| 231 // Otherwise, use the |tab_id|. If there's no |tab_id| and no | |
| 232 // |guest_process_id|, we can't look up the RenderProcessHost. | |
| 233 if (!request.tab_id.get()) { | |
| 234 error_ = "No tab ID or guest process ID specified."; | |
| 235 return nullptr; | |
| 236 } | |
| 237 | |
| 238 int tab_id = *request.tab_id; | |
| 239 content::WebContents* contents = nullptr; | |
| 240 if (!ExtensionTabUtil::GetTabById(tab_id, GetProfile(), true, nullptr, | |
| 241 nullptr, &contents, nullptr)) { | |
| 242 error_ = extensions::ErrorUtils::FormatErrorMessage( | |
|
Devlin
2017/04/10 21:34:24
GetTabById() will populate this error for you if y
hlundin-chromium
2017/04/11 09:19:37
Iiuc, this is only true for the version of GetTabB
| |
| 243 extensions::tabs_constants::kTabNotFoundError, | |
| 244 base::IntToString(tab_id)); | |
| 245 return nullptr; | |
| 246 } | |
| 247 if (!contents) { | |
|
Devlin
2017/04/10 21:34:25
This should never happen if GetTabById() succeeds.
Henrik Grunell
2017/04/11 06:49:39
Good to know, thanks. Henrik L, remove this block
hlundin-chromium
2017/04/11 09:19:37
Done.
| |
| 248 error_ = "Web contents for tab not found."; | |
| 249 return nullptr; | |
| 250 } | |
| 251 GURL expected_origin = contents->GetLastCommittedURL().GetOrigin(); | |
| 252 if (expected_origin.spec() != security_origin) { | |
|
Devlin
2017/04/10 21:34:24
Using strings to compare origins is scary for lots
Henrik Grunell
2017/04/11 06:49:39
Exactly which way do you suggest to compare? Origi
hlundin-chromium
2017/04/11 09:19:37
I filed a bug and added to the TODO.
| |
| 253 error_ = base::StringPrintf( | |
| 254 "Invalid security origin. Expected=%s, actual=%s", | |
| 255 expected_origin.spec().c_str(), security_origin.c_str()); | |
| 256 return nullptr; | |
| 257 } | |
| 258 return contents->GetRenderProcessHost(); | |
| 259 } | |
| 260 | |
| 220 bool WebrtcAudioPrivateGetSinksFunction::RunAsync() { | 261 bool WebrtcAudioPrivateGetSinksFunction::RunAsync() { |
| 221 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 262 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 222 | 263 |
| 223 InitDeviceIDSalt(); | 264 InitDeviceIDSalt(); |
| 224 GetOutputDeviceDescriptions(); | 265 GetOutputDeviceDescriptions(); |
| 225 | 266 |
| 226 return true; | 267 return true; |
| 227 } | 268 } |
| 228 | 269 |
| 229 void WebrtcAudioPrivateGetSinksFunction::OnOutputDeviceDescriptions( | 270 void WebrtcAudioPrivateGetSinksFunction::OnOutputDeviceDescriptions( |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 497 if (associated_sink_id == media::AudioDeviceDescription::kDefaultDeviceId) { | 538 if (associated_sink_id == media::AudioDeviceDescription::kDefaultDeviceId) { |
| 498 DVLOG(2) << "Got default ID, replacing with empty ID."; | 539 DVLOG(2) << "Got default ID, replacing with empty ID."; |
| 499 results_ = wap::GetAssociatedSink::Results::Create(""); | 540 results_ = wap::GetAssociatedSink::Results::Create(""); |
| 500 } else { | 541 } else { |
| 501 results_ = wap::GetAssociatedSink::Results::Create(associated_sink_id); | 542 results_ = wap::GetAssociatedSink::Results::Create(associated_sink_id); |
| 502 } | 543 } |
| 503 | 544 |
| 504 SendResponse(true); | 545 SendResponse(true); |
| 505 } | 546 } |
| 506 | 547 |
| 548 WebrtcAudioPrivateSetAudioExperimentsFunction:: | |
| 549 WebrtcAudioPrivateSetAudioExperimentsFunction() {} | |
| 550 | |
| 551 WebrtcAudioPrivateSetAudioExperimentsFunction:: | |
| 552 ~WebrtcAudioPrivateSetAudioExperimentsFunction() {} | |
| 553 | |
| 554 bool WebrtcAudioPrivateSetAudioExperimentsFunction::RunAsync() { | |
| 555 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 556 std::unique_ptr<wap::SetAudioExperiments::Params> params( | |
| 557 wap::SetAudioExperiments::Params::Create(*args_)); | |
| 558 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
| 559 | |
| 560 if (params->audio_experiments.enable_aec3.get()) { | |
| 561 content::RenderProcessHost* host = | |
| 562 RphFromRequest(params->request, params->security_origin); | |
| 563 if (!host) { | |
| 564 SendResponse(false); | |
| 565 return false; | |
| 566 } | |
| 567 | |
| 568 host->SetEchoCanceller3(*params->audio_experiments.enable_aec3); | |
| 569 } | |
| 570 | |
| 571 SendResponse(true); | |
| 572 return true; | |
| 573 } | |
| 574 | |
| 507 } // namespace extensions | 575 } // namespace extensions |
| OLD | NEW |