/* 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, DEFAULT_SCALE_VALUE, getActiveOrFocusedElement, isValidRotation, isValidScrollMode, isValidSpreadMode, normalizeWheelEventDirection, parseQueryString, ProgressBar, RendererType, RenderingStates, ScrollMode, SidebarView, SpreadMode, TextLayerMode, } from "./ui_utils.js"; import { AnnotationEditorType, build, createPromiseCapability, getDocument, getFilenameFromUrl, getPdfFilenameFromUrl, GlobalWorkerOptions, InvalidPDFException, isDataScheme, isPdfFile, loadScript, MissingPDFException, OPS, PDFWorker, shadow, UnexpectedResponseException, version, } from "pdfjs-lib"; import { AppOptions, OptionKind } from "./app_options.js"; import { AutomationEventBus, EventBus } from "./event_utils.js"; import { CursorTool, PDFCursorTools } from "./pdf_cursor_tools.js"; import { LinkTarget, PDFLinkService } from "./pdf_link_service.js"; import { AnnotationEditorParams } from "./annotation_editor_params.js"; import { OverlayManager } from "./overlay_manager.js"; import { PasswordPrompt } from "./password_prompt.js"; import { PDFAttachmentViewer } from "./pdf_attachment_viewer.js"; import { PDFDocumentProperties } from "./pdf_document_properties.js"; import { PDFFindBar } from "./pdf_find_bar.js"; import { PDFFindController } from "./pdf_find_controller.js"; import { PDFHistory } from "./pdf_history.js"; import { PDFLayerViewer } from "./pdf_layer_viewer.js"; import { PDFOutlineViewer } from "./pdf_outline_viewer.js"; import { PDFPresentationMode } from "./pdf_presentation_mode.js"; import { PDFRenderingQueue } from "./pdf_rendering_queue.js"; import { PDFScriptingManager } from "./pdf_scripting_manager.js"; import { PDFSidebar } from "./pdf_sidebar.js"; import { PDFSidebarResizer } from "./pdf_sidebar_resizer.js"; import { PDFThumbnailViewer } from "./pdf_thumbnail_viewer.js"; import { PDFViewer } from "./pdf_viewer.js"; import { SecondaryToolbar } from "./secondary_toolbar.js"; import { Toolbar } from "./toolbar.js"; import { ViewHistory } from "./view_history.js"; const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000; // ms 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 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"); } } const PDFViewerApplication = { initialBookmark: document.location.hash.substring(1), _initializedCapability: createPromiseCapability(), 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 {PDFSidebarResizer} */ pdfSidebarResizer: 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, _PDFBug: null, _hasAnnotationEditors: false, _title: document.title, _printAnnotationStoragePromise: null, // Called once when the document is loaded. async initialize(appConfig) { this.preferences = this.externalServices.createPreferences(); this.appConfig = appConfig; await this._readPreferences(); await this._parseHashParameters(); 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