// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module translate.mojom;
import "mojo/public/mojom/base/file.mojom";
import "mojo/public/mojom/base/time.mojom";
import "mojo/public/mojom/base/string16.mojom";
import "url/mojom/url.mojom";
enum TranslateError {
NONE,
NETWORK,
INITIALIZATION_ERROR,
UNKNOWN_LANGUAGE,
UNSUPPORTED_LANGUAGE,
IDENTICAL_LANGUAGES,
TRANSLATION_ERROR,
TRANSLATION_TIMEOUT,
UNEXPECTED_SCRIPT_ERROR,
BAD_ORIGIN,
SCRIPT_LOAD_ERROR,
TRANSLATE_ERROR_MAX,
};
// This struct is populated by a TranslateAgent to inform the browser about the
// result of the language detection model. Corresponds to
// LanguageDetectionDetails defined in language_detection_details.h.
struct LanguageDetectionDetails {
// All the elements in this section are used for making decisions related to
// page translation.
//
// The URL corresponding to the main frame that had its language detected.
// Used by the TranslateDriver to determine if the page is eligible for
// translation.
url.mojom.Url url;
// The calculated language based on the language detection model's prediction
// and reliability, content language, and the page language attribute. Used to
// determine if the page should be considered for translation.
string adopted_language;
// Whether no translate was specified within HTML tag to prevent
// initiating a translation for the corresponding page load. If true,
// the page content should not be translated.
bool has_notranslate;
// All the elements below are used only for debugging and metrics purposes,
// e.g., translate-internals.
//
// Whether language detection has been run on the page; only true if page
// content was captured.
bool has_run_lang_detection;
// The time at which language the language detection was performed. Used only
// for debugging.
mojo_base.mojom.Time time;
// The intended language of the audience of the content as specified by the
// HTTP header. Used only for debugging.
string content_language;
// The language predicted by the model based on the text of the page. Used
// only for debugging.
string model_detected_language;
// Whether the language prediction from the model is considered reliable
// for use, i.e., if the model's score is above a set threshold. Used
// only for debugging.
bool is_model_reliable;
// The language of the document specified by the HTML lang attribute.
// Used only for debugging.
string html_root_language;
// The content of the page that language detection has be executed on.
// Used only for debugging.
mojo_base.mojom.String16 contents;
// The relability score of the language prediction made by the detection
// model, the units of the score depends on the model but generally higher is
// better. Used only for debugging and metrics.
float model_reliability_score;
// The version of the language detection model used to predict
// the language of the page. Used only for debugging.
string detection_model_version;
};
// Handles language translation. This is used by the browser process to
// direct a renderer to translate the language of a frame (or revert a previous
// translation of the contents of a frame).
interface TranslateAgent {
// Requests that the frame be translated from |source_lang| to
// |target_lang|.
//
// If a Translate request is already in progress with a matching
// |target_lang|, this request will respond with |cancelled| set
// to |true|.
//
// If a Translate request is already in progress with a different
// |target_lang|, that request will respond with |cancelled| set
// to |true| and this request will proceed normally.
//
// If |cancelled| is |true| all other response values should be
// ignored.
TranslateFrame(string translate_script, string source_lang,
string target_lang)
=> (bool cancelled, string original_lang, string translated_lang,
TranslateError error);
// Requests that the frame be reverted to its original language with
// no translation applied.
RevertTranslation();
};
// Reports when page is ready for translation. This is used by the
// renderer of a main frame to report its detected language to the
// browser process and provides the translation interface back to itself.
interface ContentTranslateDriver {
// Notification that a new page is ready to translate,
// and the language for it has been determined.
RegisterPage(pending_remote<TranslateAgent> translate_agent,
LanguageDetectionDetails details, bool translation_critiera_met);
};