#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 {
const int kTranslateInitCheckDelayMs = …;
const int kMaxTranslateInitCheckAttempts = …;
const int kTranslateStatusCheckDelayMs = …;
const char kAutoDetectionLanguage[] = …;
constexpr char kCLDModelVersion[] = …;
translate::LanguageDetectionModel& GetLanguageDetectionModel() { … }
bool ShouldOverrideLanguageDetectionForTesting() { … }
}
namespace translate {
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() { … }
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) { … }
void TranslateAgent::TranslateFrame(const std::string& translate_script,
const std::string& source_lang,
const std::string& target_lang,
TranslateFrameCallback callback) { … }
void TranslateAgent::RevertTranslation() { … }
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() { … }
std::string TranslateAgent::BuildTranslationScript(
const std::string& source_lang,
const std::string& target_lang) { … }
}