diff --git a/web/firefoxcom.js b/web/firefoxcom.js index 881919820e9a1..51b7376cbaa96 100644 --- a/web/firefoxcom.js +++ b/web/firefoxcom.js @@ -329,10 +329,6 @@ class MLManager { this.altTextLearnMoreUrl = altTextLearnMoreUrl; this.enableAltTextModelDownload = enableAltTextModelDownload; this.enableGuessAltText = enableGuessAltText; - - if (enableAltTextModelDownload) { - this.#loadAltTextEngine(false); - } } async isEnabledFor(name) { @@ -356,6 +352,12 @@ class MLManager { ]); } + async loadModel(name) { + if (name === "altText" && this.enableAltTextModelDownload) { + await this.#loadAltTextEngine(false); + } + } + async downloadModel(name) { if (name !== "altText") { return null; diff --git a/web/genericcom.js b/web/genericcom.js index 0d1b58b9566ef..4abde7e8ad980 100644 --- a/web/genericcom.js +++ b/web/genericcom.js @@ -88,6 +88,8 @@ class FakeMLManager { return null; } + async loadModel(_name) {} + async downloadModel(_name) { // Simulate downloading the model but with progress. // The progress can be seen in the new alt-text dialog. diff --git a/web/pdf_viewer.js b/web/pdf_viewer.js index 43089d007add6..5faa1d3734bda 100644 --- a/web/pdf_viewer.js +++ b/web/pdf_viewer.js @@ -906,6 +906,9 @@ class PDFViewer { uiManager: this.#annotationEditorUIManager, }); if (mode !== AnnotationEditorType.NONE) { + if (mode === AnnotationEditorType.STAMP) { + this.#mlManager?.loadModel("altText"); + } this.#annotationEditorUIManager.updateMode(mode); } } else { @@ -2311,6 +2314,9 @@ class PDFViewer { if (!this.pdfDocument) { return; } + if (mode === AnnotationEditorType.STAMP) { + this.#mlManager?.loadModel("altText"); + } const { eventBus } = this; const updater = () => {