Merge pull request #18484 from calixteman/bug1909310

Add a pref to know if the alt-text must be automatically generated (bug 1909310)
This commit is contained in:
calixteman 2024-07-23 10:02:03 +02:00 committed by GitHub
commit 33493301b3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 21 additions and 12 deletions

View file

@ -55,6 +55,10 @@
"type": "boolean", "type": "boolean",
"default": false "default": false
}, },
"enableGuessAltText": {
"type": "boolean",
"default": true
},
"altTextLearnMoreUrl": { "altTextLearnMoreUrl": {
"type": "string", "type": "string",
"default": "" "default": ""

View file

@ -205,10 +205,10 @@ const PDFViewerApplication = {
if (mode) { if (mode) {
document.documentElement.classList.add(mode); document.documentElement.classList.add(mode);
} }
} else { } else if (AppOptions.get("enableAltText")) {
// We want to load the image-to-text AI engine as soon as possible. // We want to load the image-to-text AI engine as soon as possible.
this.mlManager = new MLManager({ this.mlManager = new MLManager({
enableAltText: AppOptions.get("enableAltText"), enableGuessAltText: AppOptions.get("enableGuessAltText"),
altTextLearnMoreUrl: AppOptions.get("altTextLearnMoreUrl"), altTextLearnMoreUrl: AppOptions.get("altTextLearnMoreUrl"),
}); });
} }
@ -376,14 +376,14 @@ const PDFViewerApplication = {
let eventBus; let eventBus;
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) { if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
eventBus = eventBus = AppOptions.eventBus = new FirefoxEventBus(
AppOptions.eventBus = AppOptions.get("allowedGlobalEvents"),
this.mlManager.eventBus = externalServices,
new FirefoxEventBus( AppOptions.get("isInAutomation")
AppOptions.get("allowedGlobalEvents"), );
externalServices, if (this.mlManager) {
AppOptions.get("isInAutomation") this.mlManager.eventBus = eventBus;
); }
} else { } else {
eventBus = new EventBus(); eventBus = new EventBus();
} }

View file

@ -187,6 +187,11 @@ const defaultOptions = {
value: false, value: false,
kind: OptionKind.VIEWER + OptionKind.PREFERENCE, kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
}, },
enableGuessAltText: {
/** @type {boolean} */
value: true,
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
},
enableHighlightEditor: { enableHighlightEditor: {
// We'll probably want to make some experiments before enabling this // We'll probably want to make some experiments before enabling this
// in Firefox release, but it has to be temporary. // in Firefox release, but it has to be temporary.

View file

@ -328,8 +328,8 @@ class MLManager {
return FirefoxCom.requestAsync("mlGuess", data); return FirefoxCom.requestAsync("mlGuess", data);
} }
enable({ altTextLearnMoreUrl, enableAltText, listenToProgress }) { enable({ altTextLearnMoreUrl, enableGuessAltText, listenToProgress }) {
if (enableAltText) { if (enableGuessAltText) {
this.#loadAltTextEngine(listenToProgress); this.#loadAltTextEngine(listenToProgress);
} }
// The `altTextLearnMoreUrl` is used to provide a link to the user to learn // The `altTextLearnMoreUrl` is used to provide a link to the user to learn