Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1135)

Unified Diff: chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_private_api.cc

Issue 2801853005: Create a private API for controlling WebRTC's AEC3 (Closed)
Patch Set: After grunell's second round of comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_private_api.cc
diff --git a/chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_private_api.cc b/chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_private_api.cc
index baf803d0bb7d4bdabe86ab932f74c27d6af63844..76fb27d079953a8b050bae3d340c7b25b176026c 100644
--- a/chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_private_api.cc
+++ b/chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_private_api.cc
@@ -4,12 +4,14 @@
#include "chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_private_api.h"
+#include <memory>
#include <utility>
#include <vector>
#include "base/lazy_instance.h"
#include "base/memory/ptr_util.h"
#include "base/strings/string_number_conversions.h"
+#include "base/strings/stringprintf.h"
#include "base/task_runner_util.h"
#include "chrome/browser/extensions/api/tabs/tabs_constants.h"
#include "chrome/browser/extensions/extension_tab_util.h"
@@ -217,6 +219,45 @@ std::string WebrtcAudioPrivateFunction::device_id_salt() const {
return device_id_salt_;
}
+// TODO(hlundin): Stolen from WebrtcLoggingPrivateFunction. Maybe consolidate?
+content::RenderProcessHost* WebrtcAudioPrivateFunction::RphFromRequest(
+ const RequestInfo& request,
+ const std::string& security_origin) {
+ // If |guest_process_id| is defined, directly use this id to find the
+ // corresponding RenderProcessHost.
+ 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.
+ return content::RenderProcessHost::FromID(*request.guest_process_id);
+
+ // Otherwise, use the |tab_id|. If there's no |tab_id| and no
+ // |guest_process_id|, we can't look up the RenderProcessHost.
+ if (!request.tab_id.get()) {
+ error_ = "No tab ID or guest process ID specified.";
+ return nullptr;
+ }
+
+ int tab_id = *request.tab_id;
+ content::WebContents* contents = nullptr;
+ if (!ExtensionTabUtil::GetTabById(tab_id, GetProfile(), true, nullptr,
+ nullptr, &contents, nullptr)) {
+ 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
+ extensions::tabs_constants::kTabNotFoundError,
+ base::IntToString(tab_id));
+ return nullptr;
+ }
+ 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.
+ error_ = "Web contents for tab not found.";
+ return nullptr;
+ }
+ GURL expected_origin = contents->GetLastCommittedURL().GetOrigin();
+ 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.
+ error_ = base::StringPrintf(
+ "Invalid security origin. Expected=%s, actual=%s",
+ expected_origin.spec().c_str(), security_origin.c_str());
+ return nullptr;
+ }
+ return contents->GetRenderProcessHost();
+}
+
bool WebrtcAudioPrivateGetSinksFunction::RunAsync() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
@@ -504,4 +545,31 @@ void WebrtcAudioPrivateGetAssociatedSinkFunction::OnHMACCalculated(
SendResponse(true);
}
+WebrtcAudioPrivateSetAudioExperimentsFunction::
+ WebrtcAudioPrivateSetAudioExperimentsFunction() {}
+
+WebrtcAudioPrivateSetAudioExperimentsFunction::
+ ~WebrtcAudioPrivateSetAudioExperimentsFunction() {}
+
+bool WebrtcAudioPrivateSetAudioExperimentsFunction::RunAsync() {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ std::unique_ptr<wap::SetAudioExperiments::Params> params(
+ wap::SetAudioExperiments::Params::Create(*args_));
+ EXTENSION_FUNCTION_VALIDATE(params.get());
+
+ if (params->audio_experiments.enable_aec3.get()) {
+ content::RenderProcessHost* host =
+ RphFromRequest(params->request, params->security_origin);
+ if (!host) {
+ SendResponse(false);
+ return false;
+ }
+
+ host->SetEchoCanceller3(*params->audio_experiments.enable_aec3);
+ }
+
+ SendResponse(true);
+ return true;
+}
+
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698