зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1837078 - Do not get language id payload if the page is hidden; r=nordzilla
This also removes some dead code around clearing the language tag, and properly lists the required events for the TranslationsChild. I guess that code was never even running, and I tests it manually after removing it. Differential Revision: https://phabricator.services.mozilla.com/D180885
This commit is contained in:
Родитель
abbfd0718a
Коммит
cd6641f7ba
|
@ -20,24 +20,25 @@ export class TranslationsChild extends JSWindowActorChild {
|
|||
*/
|
||||
innerWindowId = null;
|
||||
isDestroyed = false;
|
||||
#areLangTagsReported = false;
|
||||
#isPageHidden = false;
|
||||
#wasTranslationsEngineCreated = false;
|
||||
|
||||
handleEvent(event) {
|
||||
switch (event.type) {
|
||||
case "DOMContentLoaded":
|
||||
this.innerWindowId = this.contentWindow.windowGlobalChild.innerWindowId;
|
||||
this.innerWindowId =
|
||||
this.contentWindow?.windowGlobalChild.innerWindowId;
|
||||
if (!this.#isRestrictedPage()) {
|
||||
this.#areLangTagsReported = true;
|
||||
this.sendAsyncMessage("Translations:ReportLangTags", {
|
||||
documentElementLang: this.document.documentElement.lang,
|
||||
});
|
||||
}
|
||||
break;
|
||||
case "pageshow":
|
||||
this.#isPageHidden = false;
|
||||
break;
|
||||
case "pagehide":
|
||||
if (this.#areLangTagsReported) {
|
||||
this.sendAsyncMessage("Translations:ClearLangTags");
|
||||
}
|
||||
this.#isPageHidden = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -47,6 +48,9 @@ export class TranslationsChild extends JSWindowActorChild {
|
|||
* about:* pages will not be translated.
|
||||
*/
|
||||
#isRestrictedPage() {
|
||||
if (!this.contentWindow?.location) {
|
||||
return true;
|
||||
}
|
||||
const { href } = this.contentWindow.location;
|
||||
// Keep this logic up to date with TranslationsParent.isRestrictedPage.
|
||||
return !(
|
||||
|
@ -141,9 +145,12 @@ export class TranslationsChild extends JSWindowActorChild {
|
|||
}
|
||||
|
||||
createLanguageIdEngine() {
|
||||
return lazy.LanguageIdEngine.getOrCreate(() =>
|
||||
this.sendQuery("Translations:GetLanguageIdEnginePayload")
|
||||
);
|
||||
return lazy.LanguageIdEngine.getOrCreate(() => {
|
||||
if (this.#isPageHidden) {
|
||||
throw new Error("The page was already hidden.");
|
||||
}
|
||||
return this.sendQuery("Translations:GetLanguageIdEnginePayload");
|
||||
});
|
||||
}
|
||||
|
||||
createTranslationsEngine(fromLanguage, toLanguage) {
|
||||
|
|
|
@ -456,10 +456,6 @@ export class TranslationsParent extends JSWindowActorParent {
|
|||
case "Translations:GetPreferredLanguages": {
|
||||
return TranslationsParent.getPreferredLanguages();
|
||||
}
|
||||
case "Translations:ClearLangTags": {
|
||||
this.languageState.detectedLanguages = null;
|
||||
return undefined;
|
||||
}
|
||||
case "Translations:ReportLangTags": {
|
||||
const { documentElementLang, href } = data;
|
||||
const detectedLanguages = await this.getDetectedLanguages(
|
||||
|
|
|
@ -489,9 +489,8 @@ let JSWINDOWACTORS = {
|
|||
child: {
|
||||
esModuleURI: "resource://gre/actors/TranslationsChild.sys.mjs",
|
||||
events: {
|
||||
pagehide: {},
|
||||
pageshow: {},
|
||||
DOMHeadElementParsed: {},
|
||||
DOMDocElementInserted: {},
|
||||
DOMContentLoaded: {},
|
||||
},
|
||||
},
|
||||
|
|
Загрузка…
Ссылка в новой задаче