/* Copyright 2012 Mozilla Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { animationStarted, apiPageLayoutToViewerModes, apiPageModeToSidebarView, AutoPrintRegExp, CursorTool, DEFAULT_SCALE_VALUE, getActiveOrFocusedElement, isValidRotation, isValidScrollMode, isValidSpreadMode, normalizeWheelEventDirection, parseQueryString, ProgressBar, RenderingStates, ScrollMode, SidebarView, SpreadMode, TextLayerMode, } from "./ui_utils.js"; import { AnnotationEditorType, build, FeatureTest, getDocument, getFilenameFromUrl, getPdfFilenameFromUrl, GlobalWorkerOptions, InvalidPDFException, isDataScheme, isPdfFile, loadScript, MissingPDFException, PDFWorker, PromiseCapability, shadow, UnexpectedResponseException, version, } from "pdfjs-lib"; import { AppOptions, OptionKind } from "./app_options.js"; import { AutomationEventBus, EventBus } from "./event_utils.js"; import { LinkTarget, PDFLinkService } from "./pdf_link_service.js"; import { AnnotationEditorParams } from "web-annotation_editor_params"; import { OverlayManager } from "./overlay_manager.js"; import { PasswordPrompt } from "./password_prompt.js"; import { PDFAttachmentViewer } from "web-pdf_attachment_viewer"; import { PDFCursorTools } from "web-pdf_cursor_tools"; import { PDFDocumentProperties } from "web-pdf_document_properties"; import { PDFFindBar } from "web-pdf_find_bar"; import { PDFFindController } from "./pdf_find_controller.js"; import { PDFHistory } from "./pdf_history.js"; import { PDFLayerViewer } from "web-pdf_layer_viewer"; import { PDFOutlineViewer } from "web-pdf_outline_viewer"; import { PDFPresentationMode } from "web-pdf_presentation_mode"; import { PDFRenderingQueue } from "./pdf_rendering_queue.js"; import { PDFScriptingManager } from "./pdf_scripting_manager.js"; import { PDFSidebar } from "web-pdf_sidebar"; import { PDFThumbnailViewer } from "web-pdf_thumbnail_viewer"; import { PDFViewer } from "./pdf_viewer.js"; import { SecondaryToolbar } from "web-secondary_toolbar"; import { Toolbar } from "web-toolbar"; import { ViewHistory } from "./view_history.js"; const FORCE_PAGES_LOADED_TIMEOUT = 10000; // ms const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000; // ms const ViewOnLoad = { UNKNOWN: -1, PREVIOUS: 0, // Default value. INITIAL: 1, }; const ViewerCssTheme = { AUTOMATIC: 0, // Default value. LIGHT: 1, DARK: 2, }; class DefaultExternalServices { constructor() { throw new Error("Cannot initialize DefaultExternalServices."); } static updateFindControlState(data) {} static updateFindMatchesCount(data) {} static initPassiveLoading(callbacks) {} static reportTelemetry(data) {} static createDownloadManager() { throw new Error("Not implemented: createDownloadManager"); } static createPreferences() { throw new Error("Not implemented: createPreferences"); } static createL10n(options) { throw new Error("Not implemented: createL10n"); } static createScripting(options) { throw new Error("Not implemented: createScripting"); } static get supportsPinchToZoom() { return shadow(this, "supportsPinchToZoom", true); } static get supportsIntegratedFind() { return shadow(this, "supportsIntegratedFind", false); } static get supportsDocumentFonts() { return shadow(this, "supportsDocumentFonts", true); } static get supportedMouseWheelZoomModifierKeys() { return shadow(this, "supportedMouseWheelZoomModifierKeys", { ctrlKey: true, metaKey: true, }); } static get isInAutomation() { return shadow(this, "isInAutomation", false); } static updateEditorStates(data) { throw new Error("Not implemented: updateEditorStates"); } static get canvasMaxAreaInBytes() { return shadow(this, "canvasMaxAreaInBytes", -1); } static getNimbusExperimentData() { return shadow(this, "getNimbusExperimentData", Promise.resolve(null)); } } const PDFViewerApplication = { initialBookmark: document.location.hash.substring(1), _initializedCapability: new PromiseCapability(), appConfig: null, pdfDocument: null, pdfLoadingTask: null, printService: null, /** @type {PDFViewer} */ pdfViewer: null, /** @type {PDFThumbnailViewer} */ pdfThumbnailViewer: null, /** @type {PDFRenderingQueue} */ pdfRenderingQueue: null, /** @type {PDFPresentationMode} */ pdfPresentationMode: null, /** @type {PDFDocumentProperties} */ pdfDocumentProperties: null, /** @type {PDFLinkService} */ pdfLinkService: null, /** @type {PDFHistory} */ pdfHistory: null, /** @type {PDFSidebar} */ pdfSidebar: null, /** @type {PDFOutlineViewer} */ pdfOutlineViewer: null, /** @type {PDFAttachmentViewer} */ pdfAttachmentViewer: null, /** @type {PDFLayerViewer} */ pdfLayerViewer: null, /** @type {PDFCursorTools} */ pdfCursorTools: null, /** @type {PDFScriptingManager} */ pdfScriptingManager: null, /** @type {ViewHistory} */ store: null, /** @type {DownloadManager} */ downloadManager: null, /** @type {OverlayManager} */ overlayManager: null, /** @type {Preferences} */ preferences: null, /** @type {Toolbar} */ toolbar: null, /** @type {SecondaryToolbar} */ secondaryToolbar: null, /** @type {EventBus} */ eventBus: null, /** @type {IL10n} */ l10n: null, /** @type {AnnotationEditorParams} */ annotationEditorParams: null, isInitialViewSet: false, downloadComplete: false, isViewerEmbedded: window.parent !== window, url: "", baseUrl: "", _downloadUrl: "", externalServices: DefaultExternalServices, _boundEvents: Object.create(null), documentInfo: null, metadata: null, _contentDispositionFilename: null, _contentLength: null, _saveInProgress: false, _wheelUnusedTicks: 0, _wheelUnusedFactor: 1, _touchUnusedTicks: 0, _touchUnusedFactor: 1, _PDFBug: null, _hasAnnotationEditors: false, _title: document.title, _printAnnotationStoragePromise: null, _touchInfo: null, _isCtrlKeyDown: false, _nimbusDataPromise: null, // Called once when the document is loaded. async initialize(appConfig) { this.preferences = this.externalServices.createPreferences(); this.appConfig = appConfig; if ( typeof PDFJSDev === "undefined" ? window.isGECKOVIEW : PDFJSDev.test("GECKOVIEW") ) { this._nimbusDataPromise = this.externalServices.getNimbusExperimentData(); } await this._initializeOptions(); this._forceCssTheme(); await this._initializeL10n(); if ( this.isViewerEmbedded && AppOptions.get("externalLinkTarget") === LinkTarget.NONE ) { // Prevent external links from "replacing" the viewer, // when it's embedded in e.g. an