chromium/components/translate/content/renderer/translate_agent.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.

#include "components/translate/content/renderer/translate_agent.h"

#include <stddef.h>

#include <string>
#include <utility>

#include "base/check_op.h"
#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/functional/bind.h"
#include "base/json/string_escape.h"
#include "base/location.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/histogram_macros_local.h"
#include "base/no_destructor.h"
#include "base/notreached.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/trace_event/trace_event.h"
#include "components/language_detection/content/renderer/language_detection_agent.h"
#include "components/language_detection/core/language_detection_provider.h"
#include "components/translate/content/renderer/isolated_world_util.h"
#include "components/translate/core/common/translate_constants.h"
#include "components/translate/core/common/translate_metrics.h"
#include "components/translate/core/common/translate_util.h"
#include "components/translate/core/language_detection/language_detection_model.h"
#include "components/translate/core/language_detection/language_detection_util.h"
#include "content/public/common/content_constants.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/url_constants.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_thread.h"
#include "third_party/blink/public/platform/browser_interface_broker_proxy.h"
#include "third_party/blink/public/platform/scheduler/web_agent_group_scheduler.h"
#include "third_party/blink/public/web/web_document.h"
#include "third_party/blink/public/web/web_language_detection_details.h"
#include "third_party/blink/public/web/web_local_frame.h"
#include "third_party/blink/public/web/web_script_source.h"
#include "url/gurl.h"
#include "url/url_constants.h"
#include "v8/include/v8.h"

WebDocument;
WebLanguageDetectionDetails;
WebLocalFrame;
WebScriptSource;
WebString;
WebVector;

namespace {

// The delay in milliseconds that we'll wait before checking to see if the
// translate library injected in the page is ready.
const int kTranslateInitCheckDelayMs =;

// The maximum number of times we'll check to see if the translate library
// injected in the page is ready.
const int kMaxTranslateInitCheckAttempts =;

// The delay we wait in milliseconds before checking whether the translation has
// finished.
const int kTranslateStatusCheckDelayMs =;

// Language name passed to the Translate element for it to detect the language.
const char kAutoDetectionLanguage[] =;

// The current CLD model version.
constexpr char kCLDModelVersion[] =;

// Returns the language detection model that is shared across the RenderFrames
// in the renderer.
translate::LanguageDetectionModel& GetLanguageDetectionModel() {}

// Returns if the language detection should be overridden so that a default
// result is returned immediately.
bool ShouldOverrideLanguageDetectionForTesting() {}

}  // namespace

namespace translate {

////////////////////////////////////////////////////////////////////////////////
// TranslateAgent, public:
TranslateAgent::TranslateAgent(content::RenderFrame* render_frame, int world_id)
    :{}

TranslateAgent::~TranslateAgent() {}

void TranslateAgent::SeedLanguageDetectionModelForTesting(
    base::File model_file) {}

void TranslateAgent::PrepareForUrl(const GURL& url) {}

void TranslateAgent::PageCaptured(
    scoped_refptr<const base::RefCountedString16> contents) {}

void TranslateAgent::RenewPageRegistration() {}

void TranslateAgent::CancelPendingTranslation() {}

////////////////////////////////////////////////////////////////////////////////
// TranslateAgent, protected:
bool TranslateAgent::IsTranslateLibAvailable() {}

bool TranslateAgent::IsTranslateLibReady() {}

bool TranslateAgent::HasTranslationFinished() {}

bool TranslateAgent::HasTranslationFailed() {}

int64_t TranslateAgent::GetErrorCode() {}

bool TranslateAgent::StartTranslation() {}

std::string TranslateAgent::GetPageSourceLanguage() {}

base::TimeDelta TranslateAgent::AdjustDelay(int delay_in_milliseconds) {}

void TranslateAgent::ExecuteScript(const std::string& script) {}

bool TranslateAgent::ExecuteScriptAndGetBoolResult(const std::string& script,
                                                   bool fallback) {}

std::string TranslateAgent::ExecuteScriptAndGetStringResult(
    const std::string& script) {}

double TranslateAgent::ExecuteScriptAndGetDoubleResult(
    const std::string& script) {}

int64_t TranslateAgent::ExecuteScriptAndGetIntegerResult(
    const std::string& script) {}

// mojom::TranslateAgent implementations.
void TranslateAgent::TranslateFrame(const std::string& translate_script,
                                    const std::string& source_lang,
                                    const std::string& target_lang,
                                    TranslateFrameCallback callback) {}

void TranslateAgent::RevertTranslation() {}

////////////////////////////////////////////////////////////////////////////////
// TranslateAgent, private:
void TranslateAgent::CheckTranslateStatus() {}

void TranslateAgent::TranslatePageImpl(int count) {}

void TranslateAgent::NotifyBrowserTranslationFailed(TranslateErrors error) {}

const mojo::Remote<mojom::ContentTranslateDriver>&
TranslateAgent::GetTranslateHandler() {}

void TranslateAgent::ResetPage() {}

void TranslateAgent::OnDestruct() {}

/* static */
std::string TranslateAgent::BuildTranslationScript(
    const std::string& source_lang,
    const std::string& target_lang) {}

}  // namespace translate