summaryrefslogtreecommitdiffstats
path: root/browser/components/translations/content/fullPageTranslationsPanel.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:34:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:34:50 +0000
commitdef92d1b8e9d373e2f6f27c366d578d97d8960c6 (patch)
tree2ef34b9ad8bb9a9220e05d60352558b15f513894 /browser/components/translations/content/fullPageTranslationsPanel.js
parentAdding debian version 125.0.3-1. (diff)
downloadfirefox-def92d1b8e9d373e2f6f27c366d578d97d8960c6.tar.xz
firefox-def92d1b8e9d373e2f6f27c366d578d97d8960c6.zip
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/translations/content/fullPageTranslationsPanel.js')
-rw-r--r--browser/components/translations/content/fullPageTranslationsPanel.js91
1 files changed, 43 insertions, 48 deletions
diff --git a/browser/components/translations/content/fullPageTranslationsPanel.js b/browser/components/translations/content/fullPageTranslationsPanel.js
index 2e35440160..eddd3566f1 100644
--- a/browser/components/translations/content/fullPageTranslationsPanel.js
+++ b/browser/components/translations/content/fullPageTranslationsPanel.js
@@ -188,12 +188,19 @@ class CheckboxPageAction {
}
/**
- * This singleton class controls the Translations popup panel.
+ * This singleton class controls the FullPageTranslations panel.
*
* This component is a `/browser` component, and the actor is a `/toolkit` actor, so care
* must be taken to keep the presentation (this component) from the state management
* (the Translations actor). This class reacts to state changes coming from the
* Translations actor.
+ *
+ * A global instance of this class is created once per top ChromeWindow and is initialized
+ * when the new window is created.
+ *
+ * See the comment above TranslationsParent for more details.
+ *
+ * @see TranslationsParent
*/
var FullPageTranslationsPanel = new (class {
/** @type {Console?} */
@@ -374,21 +381,6 @@ var FullPageTranslationsPanel = new (class {
}
/**
- * @returns {TranslationsParent}
- */
- #getTranslationsActor() {
- const actor =
- gBrowser.selectedBrowser.browsingContext.currentWindowGlobal.getActor(
- "Translations"
- );
-
- if (!actor) {
- throw new Error("Unable to get the TranslationsParent");
- }
- return actor;
- }
-
- /**
* Fetches the language tags for the document and the user and caches the results
* Use `#getCachedDetectedLanguages` when the lang tags do not need to be re-fetched.
* This requires a bit of work to do, so prefer the cached version when possible.
@@ -396,8 +388,9 @@ var FullPageTranslationsPanel = new (class {
* @returns {Promise<LangTags>}
*/
async #fetchDetectedLanguages() {
- this.detectedLanguages =
- await this.#getTranslationsActor().getDetectedLanguages();
+ this.detectedLanguages = await TranslationsParent.getTranslationsActor(
+ gBrowser.selectedBrowser
+ ).getDetectedLanguages();
return this.detectedLanguages;
}
@@ -421,11 +414,7 @@ var FullPageTranslationsPanel = new (class {
*/
async #ensureLangListsBuilt() {
try {
- await TranslationsPanelShared.ensureLangListsBuilt(
- document,
- this.elements.panel,
- gBrowser.selectedBrowser.innerWindowID
- );
+ await TranslationsPanelShared.ensureLangListsBuilt(document, this);
} catch (error) {
this.console?.error(error);
}
@@ -438,7 +427,9 @@ var FullPageTranslationsPanel = new (class {
* @param {TranslationsLanguageState} languageState
*/
#updateViewFromTranslationStatus(
- languageState = this.#getTranslationsActor().languageState
+ languageState = TranslationsParent.getTranslationsActor(
+ gBrowser.selectedBrowser
+ ).languageState
) {
const { translateButton, toMenuList, fromMenuList, header, cancelButton } =
this.elements;
@@ -553,7 +544,7 @@ var FullPageTranslationsPanel = new (class {
// Unconditionally hide the intro text in case the panel is re-shown.
intro.hidden = true;
- if (TranslationsPanelShared.getLangListsInitState(panel) === "error") {
+ if (TranslationsPanelShared.getLangListsInitState(this) === "error") {
// There was an error, display it in the view rather than the language
// dropdowns.
const { cancelButton, errorHintAction } = this.elements;
@@ -722,8 +713,9 @@ var FullPageTranslationsPanel = new (class {
const neverTranslateSiteMenuItems = panel.ownerDocument.querySelectorAll(
".never-translate-site-menuitem"
);
- const neverTranslateSite =
- await this.#getTranslationsActor().shouldNeverTranslateSite();
+ const neverTranslateSite = await TranslationsParent.getTranslationsActor(
+ gBrowser.selectedBrowser
+ ).shouldNeverTranslateSite();
for (const menuitem of neverTranslateSiteMenuItems) {
menuitem.setAttribute("checked", neverTranslateSite ? "true" : "false");
@@ -801,7 +793,9 @@ var FullPageTranslationsPanel = new (class {
async #showRevisitView({ fromLanguage, toLanguage }) {
const { fromMenuList, toMenuList, intro } = this.elements;
if (!this.#isShowingDefaultView()) {
- await this.#showDefaultView(this.#getTranslationsActor());
+ await this.#showDefaultView(
+ TranslationsParent.getTranslationsActor(gBrowser.selectedBrowser)
+ );
}
intro.hidden = true;
fromMenuList.value = fromLanguage;
@@ -897,7 +891,7 @@ var FullPageTranslationsPanel = new (class {
PanelMultiView.hidePopup(panel);
await this.#showDefaultView(
- this.#getTranslationsActor(),
+ TranslationsParent.getTranslationsActor(gBrowser.selectedBrowser),
true /* force this view to be shown */
);
@@ -1119,8 +1113,10 @@ var FullPageTranslationsPanel = new (class {
const { button } = this.buttonElements;
- const { requestedTranslationPair, locationChangeId } =
- this.#getTranslationsActor().languageState;
+ const { requestedTranslationPair } =
+ TranslationsParent.getTranslationsActor(
+ gBrowser.selectedBrowser
+ ).languageState;
// Store this value because it gets modified when #showDefaultView is called below.
const isFirstUserInteraction = !this._hasShownPanel;
@@ -1132,7 +1128,9 @@ var FullPageTranslationsPanel = new (class {
this.console?.error(error);
});
} else {
- await this.#showDefaultView(this.#getTranslationsActor()).catch(error => {
+ await this.#showDefaultView(
+ TranslationsParent.getTranslationsActor(gBrowser.selectedBrowser)
+ ).catch(error => {
this.console?.error(error);
});
}
@@ -1145,16 +1143,6 @@ var FullPageTranslationsPanel = 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);
await this.#openPanelPopup(targetButton, {
@@ -1173,7 +1161,9 @@ var FullPageTranslationsPanel = new (class {
*/
#isTranslationsActive() {
const { requestedTranslationPair } =
- this.#getTranslationsActor().languageState;
+ TranslationsParent.getTranslationsActor(
+ gBrowser.selectedBrowser
+ ).languageState;
return requestedTranslationPair !== null;
}
@@ -1183,7 +1173,9 @@ var FullPageTranslationsPanel = new (class {
async onTranslate() {
PanelMultiView.hidePopup(this.elements.panel);
- const actor = this.#getTranslationsActor();
+ const actor = TranslationsParent.getTranslationsActor(
+ gBrowser.selectedBrowser
+ );
actor.translate(
this.elements.fromMenuList.value,
this.elements.toMenuList.value,
@@ -1205,7 +1197,7 @@ var FullPageTranslationsPanel = new (class {
this.#updateSettingsMenuLanguageCheckboxStates();
this.#updateSettingsMenuSiteCheckboxStates();
const popup = button.ownerDocument.getElementById(
- "translations-panel-settings-menupopup"
+ "full-page-translations-panel-settings-menupopup"
);
popup.openPopup(button, "after_end");
}
@@ -1331,8 +1323,9 @@ var FullPageTranslationsPanel = new (class {
*/
async onNeverTranslateSite() {
const pageAction = this.getCheckboxPageActionFor().neverTranslateSite();
- const toggledOn =
- await this.#getTranslationsActor().toggleNeverTranslateSitePermissions();
+ const toggledOn = await TranslationsParent.getTranslationsActor(
+ gBrowser.selectedBrowser
+ ).toggleNeverTranslateSitePermissions();
TranslationsParent.telemetry().panel().onNeverTranslateSite(toggledOn);
this.#updateSettingsMenuSiteCheckboxStates();
await this.#doPageAction(pageAction);
@@ -1349,7 +1342,9 @@ var FullPageTranslationsPanel = new (class {
throw new Error("Expected to have a document language tag.");
}
- this.#getTranslationsActor().restorePage(docLangTag);
+ TranslationsParent.getTranslationsActor(
+ gBrowser.selectedBrowser
+ ).restorePage(docLangTag);
}
/**