/* 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, noContextMenuHandler, normalizeWheelEventDirection, parseQueryString, ProgressBar, RendererType, RenderingStates, ScrollMode, SidebarView, SpreadMode, TextLayerMode, } from './ui_utils.js' import { AnnotationEditorType, build, createPromiseCapability, getDocument, getFilenameFromUrl, getPdfFilenameFromUrl, GlobalWorkerOptions, InvalidPDFException, isPdfFile, loadScript, MissingPDFException, OPS, PDFWorker, shadow, UnexpectedResponseException, UNSUPPORTED_FEATURES, version, } from './pdfjs' 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' import { Constants } from '../../constants' import { GenericExternalServices } from './genericcom' import { getPdfInstance, hlPDFRect } from '../anno' 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, } // 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 PDFViewerApplication { constructor (pdfId) { this.pdfId = pdfId this.initialBookmark = document.location.hash.substring(1) this._initializedCapability = createPromiseCapability() this.appConfig = null this.pdfDocument = null this.pdfLoadingTask = null this.printService = null /** @type {PDFViewer} */ this.pdfViewer = null /** @type {PDFThumbnailViewer} */ this.pdfThumbnailViewer = null /** @type {PDFRenderingQueue} */ this.pdfRenderingQueue = null /** @type {PDFPresentationMode} */ this.pdfPresentationMode = null /** @type {PDFDocumentProperties} */ this.pdfDocumentProperties = null /** @type {PDFLinkService} */ this.pdfLinkService = null /** @type {PDFHistory} */ this.pdfHistory = null /** @type {PDFSidebar} */ this.pdfSidebar = null /** @type {PDFSidebarResizer} */ this.pdfSidebarResizer = null /** @type {PDFOutlineViewer} */ this.pdfOutlineViewer = null /** @type {PDFAttachmentViewer} */ this.pdfAttachmentViewer = null /** @type {PDFLayerViewer} */ this.pdfLayerViewer = null /** @type {PDFCursorTools} */ this.pdfCursorTools = null /** @type {PDFScriptingManager} */ this.pdfScriptingManager = null /** @type {ViewHistory} */ this.store = null /** @type {DownloadManager} */ this.downloadManager = null /** @type {OverlayManager} */ this.overlayManager = null /** @type {Preferences} */ this.preferences = null /** @type {Toolbar} */ this.toolbar = null /** @type {SecondaryToolbar} */ this.secondaryToolbar = null /** @type {EventBus} */ this.eventBus = null /** @type {IL10n} */ this.l10n = null /** @type {AnnotationEditorParams} */ this.annotationEditorParams = null this.isInitialViewSet = false this.downloadComplete = false this.isViewerEmbedded = window.parent !== window this.url = '' this.baseUrl = '' this._downloadUrl = '' this.externalServices = GenericExternalServices this._boundEvents = Object.create(null) this.documentInfo = null this.metadata = null this._contentDispositionFilename = null this._contentLength = null this._saveInProgress = false this._docStats = null this._wheelUnusedTicks = 0 this._PDFBug = null this._hasAnnotationEditors = false this._title = document.title this._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() if ( this.isViewerEmbedded && AppOptions.get('externalLinkTarget') === LinkTarget.NONE ) { // Prevent external links from "replacing" the viewer, // when it's embedded in e.g. an