diff options
Diffstat (limited to 'toolkit/components/pdfjs/content/web/viewer-geckoview.mjs')
-rw-r--r-- | toolkit/components/pdfjs/content/web/viewer-geckoview.mjs | 114 |
1 files changed, 60 insertions, 54 deletions
diff --git a/toolkit/components/pdfjs/content/web/viewer-geckoview.mjs b/toolkit/components/pdfjs/content/web/viewer-geckoview.mjs index 866c4a405a..c309f8cf12 100644 --- a/toolkit/components/pdfjs/content/web/viewer-geckoview.mjs +++ b/toolkit/components/pdfjs/content/web/viewer-geckoview.mjs @@ -529,7 +529,6 @@ function toggleExpandedBtn(button, toggle, view = null) { } ;// CONCATENATED MODULE: ./web/app_options.js -const compatibilityParams = Object.create(null); const OptionKind = { BROWSER: 0x01, VIEWER: 0x02, @@ -772,11 +771,8 @@ class AppOptions { constructor() { throw new Error("Cannot initialize AppOptions."); } - static getCompat(name) { - return compatibilityParams[name] ?? undefined; - } static get(name) { - return userOptions[name] ?? compatibilityParams[name] ?? defaultOptions[name]?.value ?? undefined; + return userOptions[name] ?? defaultOptions[name]?.value ?? undefined; } static getAll(kind = null, defaultOnly = false) { const options = Object.create(null); @@ -785,7 +781,7 @@ class AppOptions { if (kind && !(kind & defaultOption.kind)) { continue; } - options[name] = defaultOnly ? defaultOption.value : userOptions[name] ?? compatibilityParams[name] ?? defaultOption.value; + options[name] = defaultOnly ? defaultOption.value : userOptions[name] ?? defaultOption.value; } return options; } @@ -1252,7 +1248,6 @@ const { PDFWorker, PermissionFlag, PixelsPerInch, - PromiseCapability, RenderingCancelledException, renderTextLayer, setLayerDimensions, @@ -1270,35 +1265,38 @@ const WaitOnType = { EVENT: "event", TIMEOUT: "timeout" }; -function waitOnEventOrTimeout({ +async function waitOnEventOrTimeout({ target, name, delay = 0 }) { - return new Promise(function (resolve, reject) { - if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) { - throw new Error("waitOnEventOrTimeout - invalid parameters."); - } - function handler(type) { - if (target instanceof EventBus) { - target._off(name, eventHandler); - } else { - target.removeEventListener(name, eventHandler); - } - if (timeout) { - clearTimeout(timeout); - } - resolve(type); - } - const eventHandler = handler.bind(null, WaitOnType.EVENT); + if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) { + throw new Error("waitOnEventOrTimeout - invalid parameters."); + } + const { + promise, + resolve + } = Promise.withResolvers(); + function handler(type) { if (target instanceof EventBus) { - target._on(name, eventHandler); + target._off(name, eventHandler); } else { - target.addEventListener(name, eventHandler); + target.removeEventListener(name, eventHandler); } - const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT); - const timeout = setTimeout(timeoutHandler, delay); - }); + if (timeout) { + clearTimeout(timeout); + } + resolve(type); + } + const eventHandler = handler.bind(null, WaitOnType.EVENT); + if (target instanceof EventBus) { + target._on(name, eventHandler); + } else { + target.addEventListener(name, eventHandler); + } + const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT); + const timeout = setTimeout(timeoutHandler, delay); + return promise; } class EventBus { #listeners = Object.create(null); @@ -2200,10 +2198,8 @@ class PasswordPrompt { this.dialog.addEventListener("close", this.#cancel.bind(this)); } async open() { - if (this.#activeCapability) { - await this.#activeCapability.promise; - } - this.#activeCapability = new PromiseCapability(); + await this.#activeCapability?.promise; + this.#activeCapability = Promise.withResolvers(); try { await this.overlayManager.open(this.dialog); } catch (ex) { @@ -2326,7 +2322,6 @@ function getNormalizeWithNFKC() { ;// CONCATENATED MODULE: ./web/pdf_find_controller.js - const FindState = { FOUND: 0, NOT_FOUND: 1, @@ -2664,7 +2659,7 @@ class PDFFindController { this._dirtyMatch = false; clearTimeout(this._findTimeout); this._findTimeout = null; - this._firstPageCapability = new PromiseCapability(); + this._firstPageCapability = Promise.withResolvers(); } get #query() { const { @@ -2827,14 +2822,17 @@ class PDFFindController { if (this._extractTextPromises.length > 0) { return; } - let promise = Promise.resolve(); + let deferred = Promise.resolve(); const textOptions = { disableNormalization: true }; for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) { - const extractTextCapability = new PromiseCapability(); - this._extractTextPromises[i] = extractTextCapability.promise; - promise = promise.then(() => { + const { + promise, + resolve + } = Promise.withResolvers(); + this._extractTextPromises[i] = promise; + deferred = deferred.then(() => { return this._pdfDocument.getPage(i + 1).then(pdfPage => pdfPage.getTextContent(textOptions)).then(textContent => { const strBuf = []; for (const textItem of textContent.items) { @@ -2844,13 +2842,13 @@ class PDFFindController { } } [this._pageContents[i], this._pageDiffs[i], this._hasDiacritics[i]] = normalize(strBuf.join("")); - extractTextCapability.resolve(); + resolve(); }, reason => { console.error(`Unable to get text content for page ${i + 1}`, reason); this._pageContents[i] = ""; this._pageDiffs[i] = null; this._hasDiacritics[i] = false; - extractTextCapability.resolve(); + resolve(); }); }); } @@ -3982,7 +3980,7 @@ class PDFScriptingManager { return; } await this.#willPrintCapability?.promise; - this.#willPrintCapability = new PromiseCapability(); + this.#willPrintCapability = Promise.withResolvers(); try { await this.#scripting.dispatchEventInSandbox({ id: "doc", @@ -4111,7 +4109,7 @@ class PDFScriptingManager { const pdfDocument = this.#pdfDocument, visitedPages = this._visitedPages; if (initialize) { - this.#closeCapability = new PromiseCapability(); + this.#closeCapability = Promise.withResolvers(); } if (!this.#closeCapability) { return; @@ -4161,7 +4159,7 @@ class PDFScriptingManager { }); } #initScripting() { - this.#destroyCapability = new PromiseCapability(); + this.#destroyCapability = Promise.withResolvers(); if (this.#scripting) { throw new Error("#initScripting: Scripting already exists."); } @@ -5116,7 +5114,7 @@ class PDFPageView { this.#textLayerMode = options.textLayerMode ?? TextLayerMode.ENABLE; this.#annotationMode = options.annotationMode ?? AnnotationMode.ENABLE_FORMS; this.imageResourcesPath = options.imageResourcesPath || ""; - this.maxCanvasPixels = options.maxCanvasPixels ?? (AppOptions.getCompat("maxCanvasPixels") || 2 ** 25); + this.maxCanvasPixels = options.maxCanvasPixels ?? AppOptions.get("maxCanvasPixels"); this.pageColors = options.pageColors || null; this.eventBus = options.eventBus; this.renderingQueue = options.renderingQueue; @@ -5922,7 +5920,7 @@ class PDFViewer { #scaleTimeoutId = null; #textLayerMode = TextLayerMode.ENABLE; constructor(options) { - const viewerVersion = "4.1.342"; + const viewerVersion = "4.1.379"; if (version !== viewerVersion) { throw new Error(`The API version "${version}" does not match the Viewer version "${viewerVersion}".`); } @@ -5977,7 +5975,7 @@ class PDFViewer { return new Set(this.#buffer); } get pageViewsReady() { - return this._pagesCapability.settled && this._pages.every(pageView => pageView?.pdfPage); + return this._pages.every(pageView => pageView?.pdfPage); } get renderForms() { return this.#annotationMode === AnnotationMode.ENABLE_FORMS; @@ -6280,7 +6278,7 @@ class PDFViewer { }; this.eventBus._on("pagerender", this._onBeforeDraw); this._onAfterDraw = evt => { - if (evt.cssTransform || this._onePageRenderedCapability.settled) { + if (evt.cssTransform) { return; } this._onePageRenderedCapability.resolve({ @@ -6452,9 +6450,9 @@ class PDFViewer { this._location = null; this._pagesRotation = 0; this._optionalContentConfigPromise = null; - this._firstPageCapability = new PromiseCapability(); - this._onePageRenderedCapability = new PromiseCapability(); - this._pagesCapability = new PromiseCapability(); + this._firstPageCapability = Promise.withResolvers(); + this._onePageRenderedCapability = Promise.withResolvers(); + this._pagesCapability = Promise.withResolvers(); this._scrollMode = ScrollMode.VERTICAL; this._previousScrollMode = ScrollMode.UNKNOWN; this._spreadMode = SpreadMode.NONE; @@ -7475,7 +7473,10 @@ const ViewOnLoad = { }; const PDFViewerApplication = { initialBookmark: document.location.hash.substring(1), - _initializedCapability: new PromiseCapability(), + _initializedCapability: { + ...Promise.withResolvers(), + settled: false + }, appConfig: null, pdfDocument: null, pdfLoadingTask: null, @@ -7550,6 +7551,7 @@ const PDFViewerApplication = { await this._initializeViewerComponents(); this.bindEvents(); this.bindWindowEvents(); + this._initializedCapability.settled = true; this._initializedCapability.resolve(); }, async _parseHashParams() { @@ -8608,6 +8610,10 @@ const PDFViewerApplication = { mediaQueryList.addEventListener("change", addWindowResolutionChange, { once: true }); + _boundEvents.removeWindowResolutionChange ||= function () { + mediaQueryList.removeEventListener("change", addWindowResolutionChange); + _boundEvents.removeWindowResolutionChange = null; + }; } addWindowResolutionChange(); _boundEvents.windowResize = () => { @@ -9531,8 +9537,8 @@ function webViewerReportTelemetry({ -const pdfjsVersion = "4.1.342"; -const pdfjsBuild = "e384df6f1"; +const pdfjsVersion = "4.1.379"; +const pdfjsBuild = "017e49244"; const AppConstants = null; window.PDFViewerApplication = PDFViewerApplication; window.PDFViewerApplicationConstants = AppConstants; |