From a2fb0126815101973d41b1440ac1067136a5199e Mon Sep 17 00:00:00 2001 From: Iulian Moraru Date: Thu, 3 Aug 2023 18:46:16 +0300 Subject: [PATCH] Backed out 4 changesets (bug 1846828) for causing bc failures on browser_fullscreen-bug-1798219.js related to TranslationsParent.sys.mjs. CLOSED TREE Backed out changeset 7c3b8868096b (bug 1846828) Backed out changeset a0cd72ec2666 (bug 1846828) Backed out changeset 42eade304753 (bug 1846828) Backed out changeset d909d4b4de02 (bug 1846828) --- .../translations/content/translationsPanel.js | 70 +++++----------------- .../translations/actors/TranslationsParent.sys.mjs | 48 ++------------- 2 files changed, 19 insertions(+), 99 deletions(-) diff --git a/browser/components/translations/content/translationsPanel.js b/browser/components/translations/content/translationsPanel.js index 6a024715cdb5..7d3e5dcf7a08 100644 --- a/browser/components/translations/content/translationsPanel.js +++ b/browser/components/translations/content/translationsPanel.js @@ -194,22 +194,16 @@ var TranslationsPanel = new (class { detectedLanguages = null; /** - * Lazily get a console instance. Note that this script is loaded in very early to - * the browser loading process, and may run before the console is avialable. In - * this case the console will return as `undefined`. + * Lazily get a console instance. * - * @returns {Console | void} + * @returns {Console} */ get console() { if (!this.#console) { - try { - this.#console = console.createInstance({ - maxLogLevelPref: "browser.translations.logLevel", - prefix: "Translations", - }); - } catch { - // The console may not be initialized yet. - } + this.#console = console.createInstance({ + maxLogLevelPref: "browser.translations.logLevel", + prefix: "Translations", + }); } return this.#console; } @@ -442,7 +436,7 @@ var TranslationsPanel = new (class { // Ready to initialize. break; default: - this.console?.error("Unknown langList phase", this.#langListsPhase); + this.console.error("Unknown langList phase", this.#langListsPhase); } try { @@ -483,7 +477,7 @@ var TranslationsPanel = new (class { this.#langListsPhase = "initialized"; } catch (error) { - this.console?.error(error); + this.console.error(error); this.#langListsPhase = "error"; } } @@ -1070,39 +1064,15 @@ var TranslationsPanel = new (class { PanelMultiView.openPopup(panel, target, { position: "bottomright topright", triggerEvent: event, - }).catch(error => this.console?.error(error)); + }).catch(error => this.console.error(error)); } /** - * Keeps track of open requests to guard against race conditions. - * - * @type {Promise | null} - */ - #openPromise = null; - - /** * Opens the TranslationsPanel. * * @param {Event} event */ async open(event) { - if (this.#openPromise) { - // There is already an open event happening, do not open. - return; - } - - this.#openPromise = this.#openImpl(event); - this.#openPromise.finally(() => { - this.#openPromise = null; - }); - } - - /** - * Implementation function for opening the panel. Prefer TranslationsPanel.open. - * - * @param {Event} event - */ - async #openImpl(event) { event.stopPropagation(); if ( (event.type == "click" && event.button != 0) || @@ -1120,21 +1090,21 @@ var TranslationsPanel = new (class { const { button } = this.elements; - const { requestedTranslationPair, locationChangeId } = - this.#getTranslationsActor().languageState; + await this.#ensureLangListsBuilt(); // Store this value because it gets modified when #showDefaultView is called below. const isFirstUserInteraction = !this._hasShownPanel; - await this.#ensureLangListsBuilt(); + const { requestedTranslationPair } = + this.#getTranslationsActor().languageState; if (requestedTranslationPair) { await this.#showRevisitView(requestedTranslationPair).catch(error => { - this.console?.error(error); + this.console.error(error); }); } else { await this.#showDefaultView().catch(error => { - this.console?.error(error); + this.console.error(error); }); } @@ -1146,18 +1116,6 @@ var TranslationsPanel = new (class { ? button : this.elements.appMenuButton; - if (!TranslationsParent.isActiveLocation(locationChangeId)) { - this.console?.log(`A translation panel open request was stale.`, { - locationChangeId, - newlocationChangeId: - this.#getTranslationsActor().languageState.locationChangeId, - currentURISpec: gBrowser.currentURI.spec, - }); - return; - } - - this.console?.log(`Showing a translation panel`, gBrowser.currentURI.spec); - this.#openPanelPopup(targetButton, { event, isFirstUserInteraction }); } diff --git a/toolkit/components/translations/actors/TranslationsParent.sys.mjs b/toolkit/components/translations/actors/TranslationsParent.sys.mjs index 5160623a1d8c..72b2af0b6878 100644 --- a/toolkit/components/translations/actors/TranslationsParent.sys.mjs +++ b/toolkit/components/translations/actors/TranslationsParent.sys.mjs @@ -312,32 +312,14 @@ export class TranslationsParent extends JSWindowActorParent { if (!lazy.automaticallyPopupPref) { return; } - const { documentURI } = this.browsingContext.currentWindowGlobal; if (Cu.isInAutomation && !TranslationsParent.testAutomaticPopup) { // Do not offer translations in automation, as many tests do not expect this // behavior. - lazy.console.log( - "maybeOfferTranslations - Do not offer translations in automation.", - documentURI.spec - ); - return; - } - - if ( - !detectedLanguages.docLangTag || - !detectedLanguages.userLangTag || - !detectedLanguages.isDocLangTagSupported - ) { - lazy.console.log( - "maybeOfferTranslations - The detected languages were not supported.", - detectedLanguages - ); return; } - let host; try { - host = documentURI.host; + host = this.browsingContext.currentWindowGlobal.documentURI.host; } catch { // nsIURI.host can throw if the URI scheme doesn't have a host. In this case // do not offer a translation. @@ -345,10 +327,6 @@ export class TranslationsParent extends JSWindowActorParent { } if (TranslationsParent.#hostsOffered.has(host)) { // This host was already offered a translation. - lazy.console.log( - "maybeOfferTranslations - Host already offered a translation, so skip.", - documentURI.spec - ); return; } const browser = this.browsingContext.top.embedderElement; @@ -361,34 +339,18 @@ export class TranslationsParent extends JSWindowActorParent { if ( TranslationsParent.shouldNeverTranslateLanguage( detectedLanguages.docLangTag - ) + ) || + this.shouldNeverTranslateSite() ) { - lazy.console.log( - `maybeOfferTranslations - Should never translate language. "${detectedLanguages.docLangTag}"`, - documentURI.spec - ); - return; - } - if (this.shouldNeverTranslateSite()) { - lazy.console.log( - "maybeOfferTranslations - Should never translate site.", - documentURI.spec - ); return; } // Only offer the translation if it's still the current page. if ( - documentURI.spec === + this.browsingContext.currentWindowGlobal.documentURI.spec === this.browsingContext.topChromeWindow.gBrowser.selectedBrowser.documentURI .spec ) { - lazy.console.log( - "maybeOfferTranslations - Offering a translation", - documentURI.spec, - detectedLanguages - ); - browser.dispatchEvent( new CustomEvent("TranslationsParent:OfferTranslation", { bubbles: true, @@ -1926,7 +1888,7 @@ export class TranslationsParent extends JSWindowActorParent { isDocLangTagSupported: false, }; if (!TranslationsParent.getIsTranslationsEngineSupported()) { - return null; + return langTags; } if (documentElementLang === undefined) { -- 2.11.4.GIT