/* 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. */ /* globals PDFBug, Stats */ import { animationStarted, apiPageLayoutToSpreadMode, apiPageModeToSidebarView, AutoPrintRegExp, DEFAULT_SCALE_VALUE, EventBus, getActiveOrFocusedElement, isValidRotation, isValidScrollMode, isValidSpreadMode, MAX_SCALE, MIN_SCALE, noContextMenuHandler, normalizeWheelEventDirection, parseQueryString, ProgressBar, RendererType, ScrollMode, SidebarView, SpreadMode, TextLayerMode, } from "./ui_utils.js"; import { AppOptions, compatibilityParams, OptionKind } from "./app_options.js"; import { build, createPromiseCapability, getDocument, getFilenameFromUrl, getPdfFilenameFromUrl, GlobalWorkerOptions, InvalidPDFException, isPdfFile, LinkTarget, loadScript, MissingPDFException, OPS, PDFWorker, PermissionFlag, shadow, UnexpectedResponseException, UNSUPPORTED_FEATURES, version, } from "pdfjs-lib"; import { CursorTool, PDFCursorTools } from "./pdf_cursor_tools.js"; import { PDFRenderingQueue, RenderingStates } from "./pdf_rendering_queue.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 { PDFLinkService } from "./pdf_link_service.js"; import { PDFOutlineViewer } from "./pdf_outline_viewer.js"; import { PDFPresentationMode } from "./pdf_presentation_mode.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 DEFAULT_SCALE_DELTA = 1.1; const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000; // ms const FORCE_PAGES_LOADED_TIMEOUT = 10000; // ms const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000; // ms const ENABLE_PERMISSIONS_CLASS = "enablePermissions"; const ViewOnLoad = { UNKNOWN: -1, PREVIOUS: 0, // Default value. INITIAL: 1, }; const ViewerCssTheme = { AUTOMATIC: 0, // Default value. LIGHT: 1, DARK: 2, }; // Keep these in sync with mozilla-central's Histograms.json. const KNOWN_VERSIONS = [ "1.0", "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "2.0", "2.1", "2.2", "2.3", ]; // Keep these in sync with mozilla-central's Histograms.json. const KNOWN_GENERATORS = [ "acrobat distiller", "acrobat pdfwriter", "adobe livecycle", "adobe pdf library", "adobe photoshop", "ghostscript", "tcpdf", "cairo", "dvipdfm", "dvips", "pdftex", "pdfkit", "itext", "prince", "quarkxpress", "mac os x", "microsoft", "openoffice", "oracle", "luradocument", "pdf-xchange", "antenna house", "aspose.cells", "fpdf", ]; class DefaultExternalServices { constructor() { throw new Error("Cannot initialize DefaultExternalServices."); } static updateFindControlState(data) {} static updateFindMatchesCount(data) {} static initPassiveLoading(callbacks) {} static async fallback(data) {} static reportTelemetry(data) {} static createDownloadManager(options) { 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); } } const PDFViewerApplication = { initialBookmark: document.location.hash.substring(1), _initializedCapability: createPromiseCapability(), _fellback: false, 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, isInitialViewSet: false, downloadComplete: false, isViewerEmbedded: window.parent !== window, url: "", baseUrl: "", externalServices: DefaultExternalServices, _boundEvents: Object.create(null), documentInfo: null, metadata: null, _contentDispositionFilename: null, _contentLength: null, _saveInProgress: false, _wheelUnusedTicks: 0, _idleCallbacks: new Set(), // 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