/* 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, AutoPrintRegExp, DEFAULT_SCALE_VALUE, getGlobalEventBus, getPDFFileNameFromURL, isValidRotation, isValidScrollMode, isValidSpreadMode, MAX_SCALE, MIN_SCALE, noContextMenuHandler, normalizeWheelEventDelta, parseQueryString, PresentationModeState, ProgressBar, RendererType, ScrollMode, SpreadMode, TextLayerMode, } from "./ui_utils"; import { AppOptions, OptionKind } from "./app_options"; import { build, createObjectURL, getDocument, getFilenameFromUrl, GlobalWorkerOptions, InvalidPDFException, LinkTarget, loadScript, MissingPDFException, OPS, PDFWorker, shadow, UnexpectedResponseException, UNSUPPORTED_FEATURES, version, } from "pdfjs-lib"; import { CursorTool, PDFCursorTools } from "./pdf_cursor_tools"; import { PDFRenderingQueue, RenderingStates } from "./pdf_rendering_queue"; import { PDFSidebar, SidebarView } from "./pdf_sidebar"; import { OverlayManager } from "./overlay_manager"; import { PasswordPrompt } from "./password_prompt"; import { PDFAttachmentViewer } from "./pdf_attachment_viewer"; import { PDFDocumentProperties } from "./pdf_document_properties"; import { PDFFindBar } from "./pdf_find_bar"; import { PDFFindController } from "./pdf_find_controller"; import { PDFHistory } from "./pdf_history"; import { PDFLinkService } from "./pdf_link_service"; import { PDFOutlineViewer } from "./pdf_outline_viewer"; import { PDFPresentationMode } from "./pdf_presentation_mode"; import { PDFSidebarResizer } from "./pdf_sidebar_resizer"; import { PDFThumbnailViewer } from "./pdf_thumbnail_viewer"; import { PDFViewer } from "./pdf_viewer"; import { SecondaryToolbar } from "./secondary_toolbar"; import { Toolbar } from "./toolbar"; import { ViewHistory } from "./view_history"; 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 ViewOnLoad = { UNKNOWN: -1, PREVIOUS: 0, // Default value. INITIAL: 1, }; const DefaultExternalServices = { updateFindControlState(data) {}, updateFindMatchesCount(data) {}, initPassiveLoading(callbacks) {}, fallback(data, callback) {}, reportTelemetry(data) {}, createDownloadManager(options) { throw new Error("Not implemented: createDownloadManager"); }, createPreferences() { throw new Error("Not implemented: createPreferences"); }, createL10n(options) { throw new Error("Not implemented: createL10n"); }, supportsIntegratedFind: false, supportsDocumentFonts: true, supportsDocumentColors: true, supportedMouseWheelZoomModifierKeys: { ctrlKey: true, metaKey: true, }, }; const PDFViewerApplication = { initialBookmark: document.location.hash.substring(1), initialized: false, 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 {PDFCursorTools} */ pdfCursorTools: 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: {}, contentDispositionFilename: 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(); 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