Name Description Size
icons
translations-document.sys.mjs @typedef {object} Lazy @property {typeof setTimeout} setTimeout @property {typeof clearTimeout} clearTimeout @property {typeof console} console @property {typeof import("chrome://global/content/translations/TranslationsUtils.mjs").TranslationsUtils} TranslationsUtils 96471
translations-engine.sys.mjs This file lives in the translation engine's process and is in charge of managing the lifecycle of the translations engines. This process is a singleton Web Content process that can be created and destroyed as needed. The goal of the code in this file is to be as unprivileged as possible, which should unlock Bug 1813789, which will make this file fully unprivileged. Each translation needs an engine for that specific language pair. This engine is kept around as long as the CACHE_TIMEOUT_MS, after this if some keepAlive event does not happen, the engine is destroyed. An engine may be destroyed even when a page is still open and may need translations in the future. This is handled gracefully by creating new engines and MessagePorts on the fly. The engine communicates directly with the content page via a MessagePort. Each end of the port is transfered from the parent process to the content process, and this engine process. This port is transitory, and may be closed at any time. Only when a translation has been requested once (which is initiated by the parent process) can the content process re-request translation ports. This ensures a rogue content process only has the capabilities to perform tasks that the parent process has given it. The messaging flow can get a little convoluted to handle all of the correctness cases, but ideally communication passes through the message port as much as possible. There are many scenarios such as: - Translation pages becoming idle - Tab changing causing "pageshow" and "pagehide" visibility changes - Translation actor destruction (this can happen long after the page has been navigated away from, but is still alive in the page history) - Error states - Engine Process being graceful shut down (no engines left) - Engine Process being killed by the OS. The following is a diagram that attempts to illustrate the structure of the processes and the communication channels that exist between them. ┌─────────────────────────────────────────────────────────────┐ │ PARENT PROCESS │ │ │ │ [TranslationsParent] ←────→ [TranslationsEngineParent] │ │ ↑ ↑ │ └──────────────────│────────────────────────────────────│─────┘ │ JSWindowActor IPC calls │ JSProcessActor IPC calls │ │ ┌──────────────────│────────┐ ┌─────│─────────────────────────────┐ │ CONTENT PROCESS │ │ │ │ ENGINE PROCESS │ │ │ │ │ ↓ │ │ [french.html] │ │ │ [TranslationsEngineChild] │ │ ↕ ↓ │ │ ↕ │ │ [TranslationsChild] │ │ [translations-engine.sys.mjs] │ │ └──TranslationsDocument │ │ ├── "fr to en" engine │ │ └──port1 « ═══════════ MessageChannel ════ » │ └── port2 │ │ │ │ └── "de to en" engine (idle) │ └───────────────────────────┘ └───────────────────────────────────┘ 24520
translations-engine.worker.js @typedef {import("../translations").Bergamot} Bergamot @typedef {import("../translations").TranslationModelPayload} TranslationModelPayload @typedef {import("../translations").LanguageTranslationModelFiles} LanguageTranslationModelFiles 27584
translations.css Provide defaults for when this page is viewed in "toolkit". 4202
translations.html 2835
translations.mjs global AT_getSupportedLanguages, AT_log, AT_getScriptDirection, AT_logError, AT_createTranslationsPort, AT_isHtmlTranslation, AT_isTranslationEngineSupported, AT_identifyLanguage, AT_telemetry 26529
Translator.mjs @typedef {typeof import("../translations")} Translations 8525