#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "chrome/browser/speech/extension_api/tts_engine_extension_api.h"
#include <stddef.h>
#include <string>
#include <utility>
#include <vector>
#include "base/no_destructor.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/speech/extension_api/tts_extension_api.h"
#include "chrome/browser/speech/extension_api/tts_extension_api_constants.h"
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/common/extensions/api/speech/tts_engine_manifest_handler.h"
#include "chrome/common/extensions/extension_constants.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/tts_controller.h"
#include "content/public/browser/tts_platform.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/process_manager.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_set.h"
#include "net/base/network_change_notifier.h"
#include "third_party/blink/public/mojom/devtools/console_message.mojom.h"
#include "ui/base/l10n/l10n_util.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "ash/constants/ash_pref_names.h"
#include "ash/webui/settings/public/constants/routes.mojom.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "chrome/browser/speech/tts_client_lacros.h"
#endif
EventRouter;
Extension;
ExtensionSystem;
constants;
namespace tts_engine_events {
const char kOnSpeak[] = …;
const char kOnSpeakWithAudioStream[] = …;
const char kOnStop[] = …;
const char kOnPause[] = …;
const char kOnResume[] = …;
}
namespace {
const char kPrefTtsVoices[] = …;
void WarnIfMissingPauseOrResumeListener(Profile* profile,
EventRouter* event_router,
std::string extension_id) { … }
std::unique_ptr<std::vector<extensions::TtsVoice>>
ValidateAndConvertToTtsVoiceVector(const extensions::Extension* extension,
const base::Value::List& voices_data,
bool return_after_first_error,
const char** error) { … }
std::unique_ptr<std::vector<extensions::TtsVoice>> GetVoicesInternal(
content::BrowserContext* context,
const extensions::Extension* extension) { … }
bool GetTtsEventType(const std::string event_type_string,
content::TtsEventType* event_type) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
bool CanUseEnhancedNetworkVoices(const GURL& source_url, Profile* profile) {
if (source_url.host() != extension_misc::kSelectToSpeakExtensionId &&
source_url != chrome::GetOSSettingsUrl(
chromeos::settings::mojom::kSelectToSpeakSubpagePath))
return false;
if (!profile->GetPrefs()->GetBoolean(
ash::prefs::
kAccessibilityEnhancedNetworkVoicesInSelectToSpeakAllowed)) {
return false;
}
return profile->GetPrefs()->GetBoolean(
ash::prefs::kAccessibilitySelectToSpeakEnhancedNetworkVoices);
}
#endif
}
#if !BUILDFLAG(IS_CHROMEOS_ASH)
TtsExtensionEngine* TtsExtensionEngine::GetInstance() { … }
#endif
TtsExtensionEngine::TtsExtensionEngine() = default;
TtsExtensionEngine::~TtsExtensionEngine() = default;
void TtsExtensionEngine::GetVoices(
content::BrowserContext* browser_context,
const GURL& source_url,
std::vector<content::VoiceData>* out_voices) { … }
void TtsExtensionEngine::Speak(content::TtsUtterance* utterance,
const content::VoiceData& voice) { … }
void TtsExtensionEngine::Stop(content::TtsUtterance* utterance) { … }
void TtsExtensionEngine::Stop(content::BrowserContext* browser_context,
const std::string& engine_id) { … }
void TtsExtensionEngine::Pause(content::TtsUtterance* utterance) { … }
void TtsExtensionEngine::Pause(content::BrowserContext* browser_context,
const std::string& engine_id) { … }
void TtsExtensionEngine::Resume(content::TtsUtterance* utterance) { … }
void TtsExtensionEngine::Resume(content::BrowserContext* browser_context,
const std::string& engine_id) { … }
void TtsExtensionEngine::LoadBuiltInTtsEngine(
content::BrowserContext* browser_context) { … }
bool TtsExtensionEngine::IsBuiltInTtsEngineInitialized(
content::BrowserContext* browser_context) { … }
base::Value::List TtsExtensionEngine::BuildSpeakArgs(
content::TtsUtterance* utterance,
const content::VoiceData& voice) { … }
ExtensionFunction::ResponseAction
ExtensionTtsEngineUpdateVoicesFunction::Run() { … }
ExtensionFunction::ResponseAction
ExtensionTtsEngineSendTtsEventFunction::Run() { … }
ExtensionFunction::ResponseAction
ExtensionTtsEngineSendTtsAudioFunction::Run() { … }