chromium/chrome/browser/speech/extension_api/tts_engine_extension_api.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#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  // BUILDFLAG(IS_CHROMEOS_ASH)

#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "chrome/browser/speech/tts_client_lacros.h"
#endif  // BUILDFLAG(IS_CHROMEOS_LACROS)

EventRouter;
Extension;
ExtensionSystem;

constants;

namespace tts_engine_events {
const char kOnSpeak[] =;
const char kOnSpeakWithAudioStream[] =;
const char kOnStop[] =;
const char kOnPause[] =;
const char kOnResume[] =;
}  // namespace tts_engine_events

namespace {

// An extension preference to keep track of the TTS voices that a
// TTS engine extension makes available.
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) {}

// Get the voices for an extension, checking the preferences first
// (in case the extension has ever called UpdateVoices in the past),
// and the manifest second.
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) {
  // Currently only Select-to-speak and its settings page can use Enhanced
  // Network voices.
  if (source_url.host() != extension_misc::kSelectToSpeakExtensionId &&
      source_url != chrome::GetOSSettingsUrl(
                        chromeos::settings::mojom::kSelectToSpeakSubpagePath))
    return false;

  // Check if these voices are disallowed by policy.
  if (!profile->GetPrefs()->GetBoolean(
          ash::prefs::
              kAccessibilityEnhancedNetworkVoicesInSelectToSpeakAllowed)) {
    return false;
  }

  // Return true if they were enabled by the user.
  return profile->GetPrefs()->GetBoolean(
      ash::prefs::kAccessibilitySelectToSpeakEnhancedNetworkVoices);
}

#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

}  // namespace

#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() {}