2015-01-09 18:22:10 +01:00
|
|
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "libcef/browser/speech_recognition_manager_delegate.h"
|
|
|
|
|
|
|
|
#include <set>
|
|
|
|
#include <string>
|
|
|
|
|
2022-05-19 12:28:44 +02:00
|
|
|
#include "libcef/browser/thread_util.h"
|
2015-01-09 18:22:10 +01:00
|
|
|
#include "libcef/common/cef_switches.h"
|
|
|
|
|
|
|
|
#include "base/command_line.h"
|
2023-01-30 18:43:54 +01:00
|
|
|
#include "base/functional/bind.h"
|
2018-10-02 14:14:11 +02:00
|
|
|
#include "content/public/browser/browser_task_traits.h"
|
2015-01-09 18:22:10 +01:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
|
|
|
#include "content/public/browser/notification_observer.h"
|
|
|
|
#include "content/public/browser/notification_registrar.h"
|
|
|
|
#include "content/public/browser/notification_source.h"
|
|
|
|
#include "content/public/browser/notification_types.h"
|
|
|
|
#include "content/public/browser/render_process_host.h"
|
|
|
|
#include "content/public/browser/render_view_host.h"
|
|
|
|
#include "content/public/browser/speech_recognition_manager.h"
|
|
|
|
#include "content/public/browser/speech_recognition_session_context.h"
|
|
|
|
#include "content/public/browser/web_contents.h"
|
|
|
|
|
|
|
|
using content::BrowserThread;
|
|
|
|
using content::SpeechRecognitionManager;
|
|
|
|
using content::WebContents;
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefSpeechRecognitionManagerDelegate ::CefSpeechRecognitionManagerDelegate() {
|
2015-01-09 18:22:10 +01:00
|
|
|
const base::CommandLine* command_line =
|
|
|
|
base::CommandLine::ForCurrentProcess();
|
|
|
|
filter_profanities_ =
|
|
|
|
command_line->HasSwitch(switches::kEnableProfanityFilter);
|
|
|
|
}
|
|
|
|
|
2024-01-20 23:48:57 +01:00
|
|
|
CefSpeechRecognitionManagerDelegate ::~CefSpeechRecognitionManagerDelegate() =
|
|
|
|
default;
|
2015-01-09 18:22:10 +01:00
|
|
|
|
2018-04-19 17:44:42 +02:00
|
|
|
void CefSpeechRecognitionManagerDelegate::OnRecognitionStart(int session_id) {}
|
2015-01-09 18:22:10 +01:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefSpeechRecognitionManagerDelegate::OnAudioStart(int session_id) {}
|
2015-01-09 18:22:10 +01:00
|
|
|
|
|
|
|
void CefSpeechRecognitionManagerDelegate::OnEnvironmentEstimationComplete(
|
2017-05-17 11:29:28 +02:00
|
|
|
int session_id) {}
|
2015-01-09 18:22:10 +01:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefSpeechRecognitionManagerDelegate::OnSoundStart(int session_id) {}
|
2015-01-09 18:22:10 +01:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefSpeechRecognitionManagerDelegate::OnSoundEnd(int session_id) {}
|
2015-01-09 18:22:10 +01:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefSpeechRecognitionManagerDelegate::OnAudioEnd(int session_id) {}
|
2015-01-09 18:22:10 +01:00
|
|
|
|
|
|
|
void CefSpeechRecognitionManagerDelegate::OnRecognitionResults(
|
2017-05-17 11:29:28 +02:00
|
|
|
int session_id,
|
2018-06-19 00:08:20 +02:00
|
|
|
const std::vector<blink::mojom::SpeechRecognitionResultPtr>& result) {}
|
2015-01-09 18:22:10 +01:00
|
|
|
|
|
|
|
void CefSpeechRecognitionManagerDelegate::OnRecognitionError(
|
2017-05-17 11:29:28 +02:00
|
|
|
int session_id,
|
2018-06-19 00:08:20 +02:00
|
|
|
const blink::mojom::SpeechRecognitionError& error) {}
|
2015-01-09 18:22:10 +01:00
|
|
|
|
|
|
|
void CefSpeechRecognitionManagerDelegate::OnAudioLevelsChange(
|
2017-05-17 11:29:28 +02:00
|
|
|
int session_id,
|
|
|
|
float volume,
|
|
|
|
float noise_volume) {}
|
2015-01-09 18:22:10 +01:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefSpeechRecognitionManagerDelegate::OnRecognitionEnd(int session_id) {}
|
2015-01-09 18:22:10 +01:00
|
|
|
|
|
|
|
void CefSpeechRecognitionManagerDelegate::CheckRecognitionIsAllowed(
|
|
|
|
int session_id,
|
2017-07-27 01:19:27 +02:00
|
|
|
base::OnceCallback<void(bool ask_user, bool is_allowed)> callback) {
|
2015-01-09 18:22:10 +01:00
|
|
|
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
|
|
|
|
|
|
|
const content::SpeechRecognitionSessionContext& context =
|
|
|
|
SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id);
|
|
|
|
|
|
|
|
// Make sure that initiators properly set the |render_process_id| field.
|
|
|
|
DCHECK_NE(context.render_process_id, 0);
|
|
|
|
|
2022-05-19 12:28:44 +02:00
|
|
|
CEF_POST_TASK(CEF_IOT, base::BindOnce(std::move(callback), false, true));
|
2015-01-09 18:22:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
content::SpeechRecognitionEventListener*
|
|
|
|
CefSpeechRecognitionManagerDelegate::GetEventListener() {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefSpeechRecognitionManagerDelegate::FilterProfanities(
|
|
|
|
int render_process_id) {
|
|
|
|
return filter_profanities_;
|
|
|
|
}
|