app.js 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591
  1. /* Copyright 2017 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. 'use strict';
  16. Object.defineProperty(exports, "__esModule", {
  17. value: true
  18. });
  19. exports.PDFPrintServiceFactory = exports.DefaultExternalServices = exports.PDFViewerApplication = undefined;
  20. var _ui_utils = require('./ui_utils');
  21. var _pdfjs = require('./pdfjs');
  22. var _pdf_cursor_tools = require('./pdf_cursor_tools');
  23. var _pdf_rendering_queue = require('./pdf_rendering_queue');
  24. var _pdf_sidebar = require('./pdf_sidebar');
  25. var _pdf_viewer = require('./pdf_viewer');
  26. var _dom_events = require('./dom_events');
  27. var _overlay_manager = require('./overlay_manager');
  28. var _password_prompt = require('./password_prompt');
  29. var _pdf_attachment_viewer = require('./pdf_attachment_viewer');
  30. var _pdf_document_properties = require('./pdf_document_properties');
  31. var _pdf_find_bar = require('./pdf_find_bar');
  32. var _pdf_find_controller = require('./pdf_find_controller');
  33. var _pdf_history = require('./pdf_history');
  34. var _pdf_link_service = require('./pdf_link_service');
  35. var _pdf_outline_viewer = require('./pdf_outline_viewer');
  36. var _pdf_presentation_mode = require('./pdf_presentation_mode');
  37. var _pdf_thumbnail_viewer = require('./pdf_thumbnail_viewer');
  38. var _secondary_toolbar = require('./secondary_toolbar');
  39. var _toolbar = require('./toolbar');
  40. var _view_history = require('./view_history');
  41. var DEFAULT_SCALE_DELTA = 1.1;
  42. var DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000;
  43. function configure(PDFJS) {
  44. PDFJS.imageResourcesPath = './images/';
  45. PDFJS.workerSrc = '../build/pdf.worker.js';
  46. PDFJS.cMapUrl = '../web/cmaps/';
  47. PDFJS.cMapPacked = true;
  48. }
  49. var DefaultExternalServices = {
  50. updateFindControlState: function updateFindControlState(data) {},
  51. initPassiveLoading: function initPassiveLoading(callbacks) {},
  52. fallback: function fallback(data, callback) {},
  53. reportTelemetry: function reportTelemetry(data) {},
  54. createDownloadManager: function createDownloadManager() {
  55. throw new Error('Not implemented: createDownloadManager');
  56. },
  57. createPreferences: function createPreferences() {
  58. throw new Error('Not implemented: createPreferences');
  59. },
  60. supportsIntegratedFind: false,
  61. supportsDocumentFonts: true,
  62. supportsDocumentColors: true,
  63. supportedMouseWheelZoomModifierKeys: {
  64. ctrlKey: true,
  65. metaKey: true
  66. }
  67. };
  68. var PDFViewerApplication = {
  69. initialBookmark: document.location.hash.substring(1),
  70. initialDestination: null,
  71. initialized: false,
  72. fellback: false,
  73. appConfig: null,
  74. pdfDocument: null,
  75. pdfLoadingTask: null,
  76. printService: null,
  77. pdfViewer: null,
  78. pdfThumbnailViewer: null,
  79. pdfRenderingQueue: null,
  80. pdfPresentationMode: null,
  81. pdfDocumentProperties: null,
  82. pdfLinkService: null,
  83. pdfHistory: null,
  84. pdfSidebar: null,
  85. pdfOutlineViewer: null,
  86. pdfAttachmentViewer: null,
  87. pdfCursorTools: null,
  88. store: null,
  89. downloadManager: null,
  90. overlayManager: null,
  91. preferences: null,
  92. toolbar: null,
  93. secondaryToolbar: null,
  94. eventBus: null,
  95. pageRotation: 0,
  96. isInitialViewSet: false,
  97. viewerPrefs: {
  98. sidebarViewOnLoad: _pdf_sidebar.SidebarView.NONE,
  99. pdfBugEnabled: false,
  100. showPreviousViewOnLoad: true,
  101. defaultZoomValue: '',
  102. disablePageLabels: false,
  103. renderer: 'canvas',
  104. enhanceTextSelection: false,
  105. renderInteractiveForms: false,
  106. enablePrintAutoRotate: false
  107. },
  108. isViewerEmbedded: window.parent !== window,
  109. url: '',
  110. baseUrl: '',
  111. externalServices: DefaultExternalServices,
  112. initialize: function pdfViewInitialize(appConfig) {
  113. var _this = this;
  114. this.preferences = this.externalServices.createPreferences();
  115. configure(_pdfjs.PDFJS);
  116. this.appConfig = appConfig;
  117. return this._readPreferences().then(function () {
  118. return _this._initializeViewerComponents();
  119. }).then(function () {
  120. _this.bindEvents();
  121. _this.bindWindowEvents();
  122. _ui_utils.localized.then(function () {
  123. _this.eventBus.dispatch('localized');
  124. });
  125. if (_this.isViewerEmbedded && !_pdfjs.PDFJS.isExternalLinkTargetSet()) {
  126. _pdfjs.PDFJS.externalLinkTarget = _pdfjs.PDFJS.LinkTarget.TOP;
  127. }
  128. _this.initialized = true;
  129. });
  130. },
  131. _readPreferences: function _readPreferences() {
  132. var preferences = this.preferences,
  133. viewerPrefs = this.viewerPrefs;
  134. return Promise.all([preferences.get('enableWebGL').then(function resolved(value) {
  135. _pdfjs.PDFJS.disableWebGL = !value;
  136. }), preferences.get('sidebarViewOnLoad').then(function resolved(value) {
  137. viewerPrefs['sidebarViewOnLoad'] = value;
  138. }), preferences.get('pdfBugEnabled').then(function resolved(value) {
  139. viewerPrefs['pdfBugEnabled'] = value;
  140. }), preferences.get('showPreviousViewOnLoad').then(function resolved(value) {
  141. viewerPrefs['showPreviousViewOnLoad'] = value;
  142. }), preferences.get('defaultZoomValue').then(function resolved(value) {
  143. viewerPrefs['defaultZoomValue'] = value;
  144. }), preferences.get('enhanceTextSelection').then(function resolved(value) {
  145. viewerPrefs['enhanceTextSelection'] = value;
  146. }), preferences.get('disableTextLayer').then(function resolved(value) {
  147. if (_pdfjs.PDFJS.disableTextLayer === true) {
  148. return;
  149. }
  150. _pdfjs.PDFJS.disableTextLayer = value;
  151. }), preferences.get('disableRange').then(function resolved(value) {
  152. if (_pdfjs.PDFJS.disableRange === true) {
  153. return;
  154. }
  155. _pdfjs.PDFJS.disableRange = value;
  156. }), preferences.get('disableStream').then(function resolved(value) {
  157. if (_pdfjs.PDFJS.disableStream === true) {
  158. return;
  159. }
  160. _pdfjs.PDFJS.disableStream = value;
  161. }), preferences.get('disableAutoFetch').then(function resolved(value) {
  162. _pdfjs.PDFJS.disableAutoFetch = value;
  163. }), preferences.get('disableFontFace').then(function resolved(value) {
  164. if (_pdfjs.PDFJS.disableFontFace === true) {
  165. return;
  166. }
  167. _pdfjs.PDFJS.disableFontFace = value;
  168. }), preferences.get('useOnlyCssZoom').then(function resolved(value) {
  169. _pdfjs.PDFJS.useOnlyCssZoom = value;
  170. }), preferences.get('externalLinkTarget').then(function resolved(value) {
  171. if (_pdfjs.PDFJS.isExternalLinkTargetSet()) {
  172. return;
  173. }
  174. _pdfjs.PDFJS.externalLinkTarget = value;
  175. }), preferences.get('renderer').then(function resolved(value) {
  176. viewerPrefs['renderer'] = value;
  177. }), preferences.get('renderInteractiveForms').then(function resolved(value) {
  178. viewerPrefs['renderInteractiveForms'] = value;
  179. }), preferences.get('disablePageLabels').then(function resolved(value) {
  180. viewerPrefs['disablePageLabels'] = value;
  181. }), preferences.get('enablePrintAutoRotate').then(function resolved(value) {
  182. viewerPrefs['enablePrintAutoRotate'] = value;
  183. })]).catch(function (reason) {});
  184. },
  185. _initializeViewerComponents: function _initializeViewerComponents() {
  186. var _this2 = this;
  187. var appConfig = this.appConfig;
  188. return new Promise(function (resolve, reject) {
  189. _this2.overlayManager = new _overlay_manager.OverlayManager();
  190. var eventBus = appConfig.eventBus || (0, _dom_events.getGlobalEventBus)();
  191. _this2.eventBus = eventBus;
  192. var pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  193. pdfRenderingQueue.onIdle = _this2.cleanup.bind(_this2);
  194. _this2.pdfRenderingQueue = pdfRenderingQueue;
  195. var pdfLinkService = new _pdf_link_service.PDFLinkService({ eventBus: eventBus });
  196. _this2.pdfLinkService = pdfLinkService;
  197. var downloadManager = _this2.externalServices.createDownloadManager();
  198. _this2.downloadManager = downloadManager;
  199. var container = appConfig.mainContainer;
  200. var viewer = appConfig.viewerContainer;
  201. _this2.pdfViewer = new _pdf_viewer.PDFViewer({
  202. container: container,
  203. viewer: viewer,
  204. eventBus: eventBus,
  205. renderingQueue: pdfRenderingQueue,
  206. linkService: pdfLinkService,
  207. downloadManager: downloadManager,
  208. renderer: _this2.viewerPrefs['renderer'],
  209. enhanceTextSelection: _this2.viewerPrefs['enhanceTextSelection'],
  210. renderInteractiveForms: _this2.viewerPrefs['renderInteractiveForms'],
  211. enablePrintAutoRotate: _this2.viewerPrefs['enablePrintAutoRotate']
  212. });
  213. pdfRenderingQueue.setViewer(_this2.pdfViewer);
  214. pdfLinkService.setViewer(_this2.pdfViewer);
  215. var thumbnailContainer = appConfig.sidebar.thumbnailView;
  216. _this2.pdfThumbnailViewer = new _pdf_thumbnail_viewer.PDFThumbnailViewer({
  217. container: thumbnailContainer,
  218. renderingQueue: pdfRenderingQueue,
  219. linkService: pdfLinkService
  220. });
  221. pdfRenderingQueue.setThumbnailViewer(_this2.pdfThumbnailViewer);
  222. _this2.pdfHistory = new _pdf_history.PDFHistory({
  223. linkService: pdfLinkService,
  224. eventBus: eventBus
  225. });
  226. pdfLinkService.setHistory(_this2.pdfHistory);
  227. _this2.findController = new _pdf_find_controller.PDFFindController({ pdfViewer: _this2.pdfViewer });
  228. _this2.findController.onUpdateResultsCount = function (matchCount) {
  229. if (_this2.supportsIntegratedFind) {
  230. return;
  231. }
  232. _this2.findBar.updateResultsCount(matchCount);
  233. };
  234. _this2.findController.onUpdateState = function (state, previous, matchCount) {
  235. if (_this2.supportsIntegratedFind) {
  236. _this2.externalServices.updateFindControlState({
  237. result: state,
  238. findPrevious: previous
  239. });
  240. } else {
  241. _this2.findBar.updateUIState(state, previous, matchCount);
  242. }
  243. };
  244. _this2.pdfViewer.setFindController(_this2.findController);
  245. var findBarConfig = Object.create(appConfig.findBar);
  246. findBarConfig.findController = _this2.findController;
  247. findBarConfig.eventBus = eventBus;
  248. _this2.findBar = new _pdf_find_bar.PDFFindBar(findBarConfig);
  249. _this2.pdfDocumentProperties = new _pdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, _this2.overlayManager);
  250. _this2.pdfCursorTools = new _pdf_cursor_tools.PDFCursorTools({
  251. container: container,
  252. eventBus: eventBus,
  253. preferences: _this2.preferences
  254. });
  255. _this2.toolbar = new _toolbar.Toolbar(appConfig.toolbar, container, eventBus);
  256. _this2.secondaryToolbar = new _secondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, container, eventBus);
  257. if (_this2.supportsFullscreen) {
  258. _this2.pdfPresentationMode = new _pdf_presentation_mode.PDFPresentationMode({
  259. container: container,
  260. viewer: viewer,
  261. pdfViewer: _this2.pdfViewer,
  262. eventBus: eventBus,
  263. contextMenuItems: appConfig.fullscreen
  264. });
  265. }
  266. _this2.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, _this2.overlayManager);
  267. _this2.pdfOutlineViewer = new _pdf_outline_viewer.PDFOutlineViewer({
  268. container: appConfig.sidebar.outlineView,
  269. eventBus: eventBus,
  270. linkService: pdfLinkService
  271. });
  272. _this2.pdfAttachmentViewer = new _pdf_attachment_viewer.PDFAttachmentViewer({
  273. container: appConfig.sidebar.attachmentsView,
  274. eventBus: eventBus,
  275. downloadManager: downloadManager
  276. });
  277. var sidebarConfig = Object.create(appConfig.sidebar);
  278. sidebarConfig.pdfViewer = _this2.pdfViewer;
  279. sidebarConfig.pdfThumbnailViewer = _this2.pdfThumbnailViewer;
  280. sidebarConfig.pdfOutlineViewer = _this2.pdfOutlineViewer;
  281. sidebarConfig.eventBus = eventBus;
  282. _this2.pdfSidebar = new _pdf_sidebar.PDFSidebar(sidebarConfig);
  283. _this2.pdfSidebar.onToggled = _this2.forceRendering.bind(_this2);
  284. resolve(undefined);
  285. });
  286. },
  287. run: function pdfViewRun(config) {
  288. this.initialize(config).then(webViewerInitialized);
  289. },
  290. zoomIn: function pdfViewZoomIn(ticks) {
  291. var newScale = this.pdfViewer.currentScale;
  292. do {
  293. newScale = (newScale * DEFAULT_SCALE_DELTA).toFixed(2);
  294. newScale = Math.ceil(newScale * 10) / 10;
  295. newScale = Math.min(_ui_utils.MAX_SCALE, newScale);
  296. } while (--ticks > 0 && newScale < _ui_utils.MAX_SCALE);
  297. this.pdfViewer.currentScaleValue = newScale;
  298. },
  299. zoomOut: function pdfViewZoomOut(ticks) {
  300. var newScale = this.pdfViewer.currentScale;
  301. do {
  302. newScale = (newScale / DEFAULT_SCALE_DELTA).toFixed(2);
  303. newScale = Math.floor(newScale * 10) / 10;
  304. newScale = Math.max(_ui_utils.MIN_SCALE, newScale);
  305. } while (--ticks > 0 && newScale > _ui_utils.MIN_SCALE);
  306. this.pdfViewer.currentScaleValue = newScale;
  307. },
  308. get pagesCount() {
  309. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  310. },
  311. set page(val) {
  312. this.pdfViewer.currentPageNumber = val;
  313. },
  314. get page() {
  315. return this.pdfViewer.currentPageNumber;
  316. },
  317. get printing() {
  318. return !!this.printService;
  319. },
  320. get supportsPrinting() {
  321. return PDFPrintServiceFactory.instance.supportsPrinting;
  322. },
  323. get supportsFullscreen() {
  324. var support;
  325. var doc = document.documentElement;
  326. support = !!(doc.requestFullscreen || doc.mozRequestFullScreen || doc.webkitRequestFullScreen || doc.msRequestFullscreen);
  327. if (document.fullscreenEnabled === false || document.mozFullScreenEnabled === false || document.webkitFullscreenEnabled === false || document.msFullscreenEnabled === false) {
  328. support = false;
  329. }
  330. if (support && _pdfjs.PDFJS.disableFullscreen === true) {
  331. support = false;
  332. }
  333. return (0, _pdfjs.shadow)(this, 'supportsFullscreen', support);
  334. },
  335. get supportsIntegratedFind() {
  336. return this.externalServices.supportsIntegratedFind;
  337. },
  338. get supportsDocumentFonts() {
  339. return this.externalServices.supportsDocumentFonts;
  340. },
  341. get supportsDocumentColors() {
  342. return this.externalServices.supportsDocumentColors;
  343. },
  344. get loadingBar() {
  345. var bar = new _ui_utils.ProgressBar('#loadingBar', {});
  346. return (0, _pdfjs.shadow)(this, 'loadingBar', bar);
  347. },
  348. get supportedMouseWheelZoomModifierKeys() {
  349. return this.externalServices.supportedMouseWheelZoomModifierKeys;
  350. },
  351. initPassiveLoading: function pdfViewInitPassiveLoading() {
  352. throw new Error('Not implemented: initPassiveLoading');
  353. },
  354. setTitleUsingUrl: function pdfViewSetTitleUsingUrl(url) {
  355. this.url = url;
  356. this.baseUrl = url.split('#')[0];
  357. var title = (0, _ui_utils.getPDFFileNameFromURL)(url, '');
  358. if (!title) {
  359. try {
  360. title = decodeURIComponent((0, _pdfjs.getFilenameFromUrl)(url)) || url;
  361. } catch (e) {
  362. title = url;
  363. }
  364. }
  365. this.setTitle(title);
  366. },
  367. setTitle: function pdfViewSetTitle(title) {
  368. if (this.isViewerEmbedded) {
  369. return;
  370. }
  371. document.title = title;
  372. },
  373. close: function pdfViewClose() {
  374. var errorWrapper = this.appConfig.errorWrapper.container;
  375. errorWrapper.setAttribute('hidden', 'true');
  376. if (!this.pdfLoadingTask) {
  377. return Promise.resolve();
  378. }
  379. var promise = this.pdfLoadingTask.destroy();
  380. this.pdfLoadingTask = null;
  381. if (this.pdfDocument) {
  382. this.pdfDocument = null;
  383. this.pdfThumbnailViewer.setDocument(null);
  384. this.pdfViewer.setDocument(null);
  385. this.pdfLinkService.setDocument(null, null);
  386. this.pdfDocumentProperties.setDocument(null, null);
  387. }
  388. this.store = null;
  389. this.isInitialViewSet = false;
  390. this.pdfSidebar.reset();
  391. this.pdfOutlineViewer.reset();
  392. this.pdfAttachmentViewer.reset();
  393. this.findController.reset();
  394. this.findBar.reset();
  395. this.toolbar.reset();
  396. this.secondaryToolbar.reset();
  397. if (typeof PDFBug !== 'undefined') {
  398. PDFBug.cleanup();
  399. }
  400. return promise;
  401. },
  402. open: function open(file, args) {
  403. var _this3 = this;
  404. if (arguments.length > 2 || typeof args === 'number') {
  405. return Promise.reject(new Error('Call of open() with obsolete signature.'));
  406. }
  407. if (this.pdfLoadingTask) {
  408. return this.close().then(function () {
  409. _this3.preferences.reload();
  410. return _this3.open(file, args);
  411. });
  412. }
  413. var parameters = Object.create(null),
  414. scale = void 0;
  415. if (typeof file === 'string') {
  416. this.setTitleUsingUrl(file);
  417. parameters.url = file;
  418. } else if (file && 'byteLength' in file) {
  419. parameters.data = file;
  420. } else if (file.url && file.originalUrl) {
  421. this.setTitleUsingUrl(file.originalUrl);
  422. parameters.url = file.url;
  423. }
  424. if (args) {
  425. for (var prop in args) {
  426. parameters[prop] = args[prop];
  427. }
  428. if (args.scale) {
  429. scale = args.scale;
  430. }
  431. if (args.length) {
  432. this.pdfDocumentProperties.setFileSize(args.length);
  433. }
  434. }
  435. this.downloadComplete = false;
  436. var loadingTask = (0, _pdfjs.getDocument)(parameters);
  437. this.pdfLoadingTask = loadingTask;
  438. loadingTask.onPassword = function (updateCallback, reason) {
  439. _this3.passwordPrompt.setUpdateCallback(updateCallback, reason);
  440. _this3.passwordPrompt.open();
  441. };
  442. loadingTask.onProgress = function (_ref) {
  443. var loaded = _ref.loaded,
  444. total = _ref.total;
  445. _this3.progress(loaded / total);
  446. };
  447. loadingTask.onUnsupportedFeature = this.fallback.bind(this);
  448. return loadingTask.promise.then(function (pdfDocument) {
  449. _this3.load(pdfDocument, scale);
  450. }, function (exception) {
  451. var message = exception && exception.message;
  452. var loadingErrorMessage = _ui_utils.mozL10n.get('loading_error', null, 'An error occurred while loading the PDF.');
  453. if (exception instanceof _pdfjs.InvalidPDFException) {
  454. loadingErrorMessage = _ui_utils.mozL10n.get('invalid_file_error', null, 'Invalid or corrupted PDF file.');
  455. } else if (exception instanceof _pdfjs.MissingPDFException) {
  456. loadingErrorMessage = _ui_utils.mozL10n.get('missing_file_error', null, 'Missing PDF file.');
  457. } else if (exception instanceof _pdfjs.UnexpectedResponseException) {
  458. loadingErrorMessage = _ui_utils.mozL10n.get('unexpected_response_error', null, 'Unexpected server response.');
  459. }
  460. _this3.error(loadingErrorMessage, { message: message });
  461. throw new Error(loadingErrorMessage);
  462. });
  463. },
  464. download: function pdfViewDownload() {
  465. function downloadByUrl() {
  466. downloadManager.downloadUrl(url, filename);
  467. }
  468. var url = this.baseUrl;
  469. var filename = (0, _ui_utils.getPDFFileNameFromURL)(this.url);
  470. var downloadManager = this.downloadManager;
  471. downloadManager.onerror = function (err) {
  472. PDFViewerApplication.error('PDF failed to download.');
  473. };
  474. if (!this.pdfDocument) {
  475. downloadByUrl();
  476. return;
  477. }
  478. if (!this.downloadComplete) {
  479. downloadByUrl();
  480. return;
  481. }
  482. this.pdfDocument.getData().then(function getDataSuccess(data) {
  483. var blob = (0, _pdfjs.createBlob)(data, 'application/pdf');
  484. downloadManager.download(blob, url, filename);
  485. }, downloadByUrl).then(null, downloadByUrl);
  486. },
  487. fallback: function pdfViewFallback(featureId) {},
  488. error: function pdfViewError(message, moreInfo) {
  489. var moreInfoText = _ui_utils.mozL10n.get('error_version_info', {
  490. version: _pdfjs.version || '?',
  491. build: _pdfjs.build || '?'
  492. }, 'PDF.js v{{version}} (build: {{build}})') + '\n';
  493. if (moreInfo) {
  494. moreInfoText += _ui_utils.mozL10n.get('error_message', { message: moreInfo.message }, 'Message: {{message}}');
  495. if (moreInfo.stack) {
  496. moreInfoText += '\n' + _ui_utils.mozL10n.get('error_stack', { stack: moreInfo.stack }, 'Stack: {{stack}}');
  497. } else {
  498. if (moreInfo.filename) {
  499. moreInfoText += '\n' + _ui_utils.mozL10n.get('error_file', { file: moreInfo.filename }, 'File: {{file}}');
  500. }
  501. if (moreInfo.lineNumber) {
  502. moreInfoText += '\n' + _ui_utils.mozL10n.get('error_line', { line: moreInfo.lineNumber }, 'Line: {{line}}');
  503. }
  504. }
  505. }
  506. var errorWrapperConfig = this.appConfig.errorWrapper;
  507. var errorWrapper = errorWrapperConfig.container;
  508. errorWrapper.removeAttribute('hidden');
  509. var errorMessage = errorWrapperConfig.errorMessage;
  510. errorMessage.textContent = message;
  511. var closeButton = errorWrapperConfig.closeButton;
  512. closeButton.onclick = function () {
  513. errorWrapper.setAttribute('hidden', 'true');
  514. };
  515. var errorMoreInfo = errorWrapperConfig.errorMoreInfo;
  516. var moreInfoButton = errorWrapperConfig.moreInfoButton;
  517. var lessInfoButton = errorWrapperConfig.lessInfoButton;
  518. moreInfoButton.onclick = function () {
  519. errorMoreInfo.removeAttribute('hidden');
  520. moreInfoButton.setAttribute('hidden', 'true');
  521. lessInfoButton.removeAttribute('hidden');
  522. errorMoreInfo.style.height = errorMoreInfo.scrollHeight + 'px';
  523. };
  524. lessInfoButton.onclick = function () {
  525. errorMoreInfo.setAttribute('hidden', 'true');
  526. moreInfoButton.removeAttribute('hidden');
  527. lessInfoButton.setAttribute('hidden', 'true');
  528. };
  529. moreInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  530. lessInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  531. closeButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  532. moreInfoButton.removeAttribute('hidden');
  533. lessInfoButton.setAttribute('hidden', 'true');
  534. errorMoreInfo.value = moreInfoText;
  535. },
  536. progress: function pdfViewProgress(level) {
  537. var _this4 = this;
  538. var percent = Math.round(level * 100);
  539. if (percent > this.loadingBar.percent || isNaN(percent)) {
  540. this.loadingBar.percent = percent;
  541. if (_pdfjs.PDFJS.disableAutoFetch && percent) {
  542. if (this.disableAutoFetchLoadingBarTimeout) {
  543. clearTimeout(this.disableAutoFetchLoadingBarTimeout);
  544. this.disableAutoFetchLoadingBarTimeout = null;
  545. }
  546. this.loadingBar.show();
  547. this.disableAutoFetchLoadingBarTimeout = setTimeout(function () {
  548. _this4.loadingBar.hide();
  549. _this4.disableAutoFetchLoadingBarTimeout = null;
  550. }, DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
  551. }
  552. }
  553. },
  554. load: function load(pdfDocument, scale) {
  555. var _this5 = this;
  556. scale = scale || _ui_utils.UNKNOWN_SCALE;
  557. this.pdfDocument = pdfDocument;
  558. pdfDocument.getDownloadInfo().then(function () {
  559. _this5.downloadComplete = true;
  560. _this5.loadingBar.hide();
  561. firstPagePromise.then(function () {
  562. _this5.eventBus.dispatch('documentload', { source: _this5 });
  563. });
  564. });
  565. this.toolbar.setPagesCount(pdfDocument.numPages, false);
  566. this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
  567. var id = this.documentFingerprint = pdfDocument.fingerprint;
  568. var store = this.store = new _view_history.ViewHistory(id);
  569. var baseDocumentUrl = void 0;
  570. baseDocumentUrl = null;
  571. this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
  572. this.pdfDocumentProperties.setDocument(pdfDocument, this.url);
  573. var pdfViewer = this.pdfViewer;
  574. pdfViewer.currentScale = scale;
  575. pdfViewer.setDocument(pdfDocument);
  576. var firstPagePromise = pdfViewer.firstPagePromise;
  577. var pagesPromise = pdfViewer.pagesPromise;
  578. var onePageRendered = pdfViewer.onePageRendered;
  579. this.pageRotation = 0;
  580. var pdfThumbnailViewer = this.pdfThumbnailViewer;
  581. pdfThumbnailViewer.setDocument(pdfDocument);
  582. firstPagePromise.then(function (pdfPage) {
  583. _this5.loadingBar.setWidth(_this5.appConfig.viewerContainer);
  584. if (!_pdfjs.PDFJS.disableHistory && !_this5.isViewerEmbedded) {
  585. if (!_this5.viewerPrefs['showPreviousViewOnLoad']) {
  586. _this5.pdfHistory.clearHistoryState();
  587. }
  588. _this5.pdfHistory.initialize(_this5.documentFingerprint);
  589. if (_this5.pdfHistory.initialDestination) {
  590. _this5.initialDestination = _this5.pdfHistory.initialDestination;
  591. } else if (_this5.pdfHistory.initialBookmark) {
  592. _this5.initialBookmark = _this5.pdfHistory.initialBookmark;
  593. }
  594. }
  595. var initialParams = {
  596. destination: _this5.initialDestination,
  597. bookmark: _this5.initialBookmark,
  598. hash: null
  599. };
  600. var storedHash = _this5.viewerPrefs['defaultZoomValue'] ? 'zoom=' + _this5.viewerPrefs['defaultZoomValue'] : null;
  601. var sidebarView = _this5.viewerPrefs['sidebarViewOnLoad'];
  602. new Promise(function (resolve, reject) {
  603. if (!_this5.viewerPrefs['showPreviousViewOnLoad']) {
  604. resolve();
  605. return;
  606. }
  607. store.getMultiple({
  608. exists: false,
  609. page: '1',
  610. zoom: _ui_utils.DEFAULT_SCALE_VALUE,
  611. scrollLeft: '0',
  612. scrollTop: '0',
  613. sidebarView: _pdf_sidebar.SidebarView.NONE
  614. }).then(function (values) {
  615. if (!values.exists) {
  616. resolve();
  617. return;
  618. }
  619. storedHash = 'page=' + values.page + '&zoom=' + (_this5.viewerPrefs['defaultZoomValue'] || values.zoom) + ',' + values.scrollLeft + ',' + values.scrollTop;
  620. sidebarView = _this5.viewerPrefs['sidebarViewOnLoad'] || values.sidebarView | 0;
  621. resolve();
  622. }).catch(function () {
  623. resolve();
  624. });
  625. }).then(function () {
  626. _this5.setInitialView(storedHash, {
  627. sidebarView: sidebarView,
  628. scale: scale
  629. });
  630. initialParams.hash = storedHash;
  631. if (!_this5.isViewerEmbedded) {
  632. _this5.pdfViewer.focus();
  633. }
  634. return pagesPromise;
  635. }).then(function () {
  636. if (!initialParams.destination && !initialParams.bookmark && !initialParams.hash) {
  637. return;
  638. }
  639. if (_this5.hasEqualPageSizes) {
  640. return;
  641. }
  642. _this5.initialDestination = initialParams.destination;
  643. _this5.initialBookmark = initialParams.bookmark;
  644. _this5.pdfViewer.currentScaleValue = _this5.pdfViewer.currentScaleValue;
  645. _this5.setInitialView(initialParams.hash);
  646. });
  647. });
  648. pdfDocument.getPageLabels().then(function (labels) {
  649. if (!labels || _this5.viewerPrefs['disablePageLabels']) {
  650. return;
  651. }
  652. var i = 0,
  653. numLabels = labels.length;
  654. if (numLabels !== _this5.pagesCount) {
  655. console.error('The number of Page Labels does not match ' + 'the number of pages in the document.');
  656. return;
  657. }
  658. while (i < numLabels && labels[i] === (i + 1).toString()) {
  659. i++;
  660. }
  661. if (i === numLabels) {
  662. return;
  663. }
  664. pdfViewer.setPageLabels(labels);
  665. pdfThumbnailViewer.setPageLabels(labels);
  666. _this5.toolbar.setPagesCount(pdfDocument.numPages, true);
  667. _this5.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  668. });
  669. pagesPromise.then(function () {
  670. if (!_this5.supportsPrinting) {
  671. return;
  672. }
  673. pdfDocument.getJavaScript().then(function (javaScript) {
  674. if (javaScript.length) {
  675. console.warn('Warning: JavaScript is not supported');
  676. _this5.fallback(_pdfjs.UNSUPPORTED_FEATURES.javaScript);
  677. }
  678. var regex = /\bprint\s*\(/;
  679. for (var i = 0, ii = javaScript.length; i < ii; i++) {
  680. var js = javaScript[i];
  681. if (js && regex.test(js)) {
  682. setTimeout(function () {
  683. window.print();
  684. });
  685. return;
  686. }
  687. }
  688. });
  689. });
  690. Promise.all([onePageRendered, _ui_utils.animationStarted]).then(function () {
  691. pdfDocument.getOutline().then(function (outline) {
  692. _this5.pdfOutlineViewer.render({ outline: outline });
  693. });
  694. pdfDocument.getAttachments().then(function (attachments) {
  695. _this5.pdfAttachmentViewer.render({ attachments: attachments });
  696. });
  697. });
  698. pdfDocument.getMetadata().then(function (_ref2) {
  699. var info = _ref2.info,
  700. metadata = _ref2.metadata;
  701. _this5.documentInfo = info;
  702. _this5.metadata = metadata;
  703. console.log('PDF ' + pdfDocument.fingerprint + ' [' + info.PDFFormatVersion + ' ' + (info.Producer || '-').trim() + ' / ' + (info.Creator || '-').trim() + ']' + ' (PDF.js: ' + (_pdfjs.version || '-') + (!_pdfjs.PDFJS.disableWebGL ? ' [WebGL]' : '') + ')');
  704. var pdfTitle = void 0;
  705. if (metadata && metadata.has('dc:title')) {
  706. var title = metadata.get('dc:title');
  707. if (title !== 'Untitled') {
  708. pdfTitle = title;
  709. }
  710. }
  711. if (!pdfTitle && info && info['Title']) {
  712. pdfTitle = info['Title'];
  713. }
  714. if (pdfTitle) {
  715. _this5.setTitle(pdfTitle + ' - ' + document.title);
  716. }
  717. if (info.IsAcroFormPresent) {
  718. console.warn('Warning: AcroForm/XFA is not supported');
  719. _this5.fallback(_pdfjs.UNSUPPORTED_FEATURES.forms);
  720. }
  721. });
  722. },
  723. setInitialView: function setInitialView(storedHash) {
  724. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  725. var _options$scale = options.scale,
  726. scale = _options$scale === undefined ? 0 : _options$scale,
  727. _options$sidebarView = options.sidebarView,
  728. sidebarView = _options$sidebarView === undefined ? _pdf_sidebar.SidebarView.NONE : _options$sidebarView;
  729. this.isInitialViewSet = true;
  730. this.pdfSidebar.setInitialView(sidebarView);
  731. if (this.initialDestination) {
  732. this.pdfLinkService.navigateTo(this.initialDestination);
  733. this.initialDestination = null;
  734. } else if (this.initialBookmark) {
  735. this.pdfLinkService.setHash(this.initialBookmark);
  736. this.pdfHistory.push({ hash: this.initialBookmark }, true);
  737. this.initialBookmark = null;
  738. } else if (storedHash) {
  739. this.pdfLinkService.setHash(storedHash);
  740. } else if (scale) {
  741. this.pdfViewer.currentScaleValue = scale;
  742. this.page = 1;
  743. }
  744. this.toolbar.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
  745. this.secondaryToolbar.setPageNumber(this.pdfViewer.currentPageNumber);
  746. if (!this.pdfViewer.currentScaleValue) {
  747. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  748. }
  749. },
  750. cleanup: function pdfViewCleanup() {
  751. if (!this.pdfDocument) {
  752. return;
  753. }
  754. this.pdfViewer.cleanup();
  755. this.pdfThumbnailViewer.cleanup();
  756. if (this.pdfViewer.renderer !== _ui_utils.RendererType.SVG) {
  757. this.pdfDocument.cleanup();
  758. }
  759. },
  760. forceRendering: function pdfViewForceRendering() {
  761. this.pdfRenderingQueue.printing = this.printing;
  762. this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar.isThumbnailViewVisible;
  763. this.pdfRenderingQueue.renderHighestPriority();
  764. },
  765. beforePrint: function pdfViewSetupBeforePrint() {
  766. if (this.printService) {
  767. return;
  768. }
  769. if (!this.supportsPrinting) {
  770. var printMessage = _ui_utils.mozL10n.get('printing_not_supported', null, 'Warning: Printing is not fully supported by this browser.');
  771. this.error(printMessage);
  772. return;
  773. }
  774. if (!this.pdfViewer.pageViewsReady) {
  775. var notReadyMessage = _ui_utils.mozL10n.get('printing_not_ready', null, 'Warning: The PDF is not fully loaded for printing.');
  776. window.alert(notReadyMessage);
  777. return;
  778. }
  779. var pagesOverview = this.pdfViewer.getPagesOverview();
  780. var printContainer = this.appConfig.printContainer;
  781. var printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer);
  782. this.printService = printService;
  783. this.forceRendering();
  784. printService.layout();
  785. },
  786. get hasEqualPageSizes() {
  787. var firstPage = this.pdfViewer.getPageView(0);
  788. for (var i = 1, ii = this.pagesCount; i < ii; ++i) {
  789. var pageView = this.pdfViewer.getPageView(i);
  790. if (pageView.width !== firstPage.width || pageView.height !== firstPage.height) {
  791. return false;
  792. }
  793. }
  794. return true;
  795. },
  796. afterPrint: function pdfViewSetupAfterPrint() {
  797. if (this.printService) {
  798. this.printService.destroy();
  799. this.printService = null;
  800. }
  801. this.forceRendering();
  802. },
  803. rotatePages: function pdfViewRotatePages(delta) {
  804. var pageNumber = this.page;
  805. this.pageRotation = (this.pageRotation + 360 + delta) % 360;
  806. this.pdfViewer.pagesRotation = this.pageRotation;
  807. this.pdfThumbnailViewer.pagesRotation = this.pageRotation;
  808. this.forceRendering();
  809. this.pdfViewer.currentPageNumber = pageNumber;
  810. },
  811. requestPresentationMode: function pdfViewRequestPresentationMode() {
  812. if (!this.pdfPresentationMode) {
  813. return;
  814. }
  815. this.pdfPresentationMode.request();
  816. },
  817. bindEvents: function pdfViewBindEvents() {
  818. var eventBus = this.eventBus;
  819. eventBus.on('resize', webViewerResize);
  820. eventBus.on('hashchange', webViewerHashchange);
  821. eventBus.on('beforeprint', this.beforePrint.bind(this));
  822. eventBus.on('afterprint', this.afterPrint.bind(this));
  823. eventBus.on('pagerendered', webViewerPageRendered);
  824. eventBus.on('textlayerrendered', webViewerTextLayerRendered);
  825. eventBus.on('updateviewarea', webViewerUpdateViewarea);
  826. eventBus.on('pagechanging', webViewerPageChanging);
  827. eventBus.on('scalechanging', webViewerScaleChanging);
  828. eventBus.on('sidebarviewchanged', webViewerSidebarViewChanged);
  829. eventBus.on('pagemode', webViewerPageMode);
  830. eventBus.on('namedaction', webViewerNamedAction);
  831. eventBus.on('presentationmodechanged', webViewerPresentationModeChanged);
  832. eventBus.on('presentationmode', webViewerPresentationMode);
  833. eventBus.on('openfile', webViewerOpenFile);
  834. eventBus.on('print', webViewerPrint);
  835. eventBus.on('download', webViewerDownload);
  836. eventBus.on('firstpage', webViewerFirstPage);
  837. eventBus.on('lastpage', webViewerLastPage);
  838. eventBus.on('nextpage', webViewerNextPage);
  839. eventBus.on('previouspage', webViewerPreviousPage);
  840. eventBus.on('zoomin', webViewerZoomIn);
  841. eventBus.on('zoomout', webViewerZoomOut);
  842. eventBus.on('pagenumberchanged', webViewerPageNumberChanged);
  843. eventBus.on('scalechanged', webViewerScaleChanged);
  844. eventBus.on('rotatecw', webViewerRotateCw);
  845. eventBus.on('rotateccw', webViewerRotateCcw);
  846. eventBus.on('documentproperties', webViewerDocumentProperties);
  847. eventBus.on('find', webViewerFind);
  848. eventBus.on('findfromurlhash', webViewerFindFromUrlHash);
  849. eventBus.on('fileinputchange', webViewerFileInputChange);
  850. },
  851. bindWindowEvents: function pdfViewBindWindowEvents() {
  852. var eventBus = this.eventBus;
  853. window.addEventListener('wheel', webViewerWheel);
  854. window.addEventListener('click', webViewerClick);
  855. window.addEventListener('keydown', webViewerKeyDown);
  856. window.addEventListener('resize', function windowResize() {
  857. eventBus.dispatch('resize');
  858. });
  859. window.addEventListener('hashchange', function windowHashChange() {
  860. eventBus.dispatch('hashchange', { hash: document.location.hash.substring(1) });
  861. });
  862. window.addEventListener('beforeprint', function windowBeforePrint() {
  863. eventBus.dispatch('beforeprint');
  864. });
  865. window.addEventListener('afterprint', function windowAfterPrint() {
  866. eventBus.dispatch('afterprint');
  867. });
  868. window.addEventListener('change', function windowChange(evt) {
  869. var files = evt.target.files;
  870. if (!files || files.length === 0) {
  871. return;
  872. }
  873. eventBus.dispatch('fileinputchange', { fileInput: evt.target });
  874. });
  875. }
  876. };
  877. var validateFileURL;
  878. {
  879. var HOSTED_VIEWER_ORIGINS = ['null', 'http://mozilla.github.io', 'https://mozilla.github.io'];
  880. validateFileURL = function validateFileURL(file) {
  881. try {
  882. var viewerOrigin = new URL(window.location.href).origin || 'null';
  883. if (HOSTED_VIEWER_ORIGINS.indexOf(viewerOrigin) >= 0) {
  884. return;
  885. }
  886. var fileOrigin = new URL(file, window.location.href).origin;
  887. if (fileOrigin !== viewerOrigin) {
  888. throw new Error('file origin does not match viewer\'s');
  889. }
  890. } catch (e) {
  891. var message = e && e.message;
  892. var loadingErrorMessage = _ui_utils.mozL10n.get('loading_error', null, 'An error occurred while loading the PDF.');
  893. var moreInfo = { message: message };
  894. PDFViewerApplication.error(loadingErrorMessage, moreInfo);
  895. throw e;
  896. }
  897. };
  898. }
  899. function loadAndEnablePDFBug(enabledTabs) {
  900. return new Promise(function (resolve, reject) {
  901. var appConfig = PDFViewerApplication.appConfig;
  902. var script = document.createElement('script');
  903. script.src = appConfig.debuggerScriptPath;
  904. script.onload = function () {
  905. PDFBug.enable(enabledTabs);
  906. PDFBug.init({
  907. PDFJS: _pdfjs.PDFJS,
  908. OPS: _pdfjs.OPS
  909. }, appConfig.mainContainer);
  910. resolve();
  911. };
  912. script.onerror = function () {
  913. reject(new Error('Cannot load debugger at ' + script.src));
  914. };
  915. (document.getElementsByTagName('head')[0] || document.body).appendChild(script);
  916. });
  917. }
  918. function webViewerInitialized() {
  919. var appConfig = PDFViewerApplication.appConfig;
  920. var file;
  921. var queryString = document.location.search.substring(1);
  922. var params = (0, _ui_utils.parseQueryString)(queryString);
  923. file = 'file' in params ? params.file : appConfig.defaultUrl;
  924. validateFileURL(file);
  925. var waitForBeforeOpening = [];
  926. var fileInput = document.createElement('input');
  927. fileInput.id = appConfig.openFileInputName;
  928. fileInput.className = 'fileInput';
  929. fileInput.setAttribute('type', 'file');
  930. fileInput.oncontextmenu = _ui_utils.noContextMenuHandler;
  931. document.body.appendChild(fileInput);
  932. if (!window.File || !window.FileReader || !window.FileList || !window.Blob) {
  933. appConfig.toolbar.openFile.setAttribute('hidden', 'true');
  934. appConfig.secondaryToolbar.openFileButton.setAttribute('hidden', 'true');
  935. } else {
  936. fileInput.value = null;
  937. }
  938. if (PDFViewerApplication.viewerPrefs['pdfBugEnabled']) {
  939. var hash = document.location.hash.substring(1);
  940. var hashParams = (0, _ui_utils.parseQueryString)(hash);
  941. if ('disableworker' in hashParams) {
  942. _pdfjs.PDFJS.disableWorker = hashParams['disableworker'] === 'true';
  943. }
  944. if ('disablerange' in hashParams) {
  945. _pdfjs.PDFJS.disableRange = hashParams['disablerange'] === 'true';
  946. }
  947. if ('disablestream' in hashParams) {
  948. _pdfjs.PDFJS.disableStream = hashParams['disablestream'] === 'true';
  949. }
  950. if ('disableautofetch' in hashParams) {
  951. _pdfjs.PDFJS.disableAutoFetch = hashParams['disableautofetch'] === 'true';
  952. }
  953. if ('disablefontface' in hashParams) {
  954. _pdfjs.PDFJS.disableFontFace = hashParams['disablefontface'] === 'true';
  955. }
  956. if ('disablehistory' in hashParams) {
  957. _pdfjs.PDFJS.disableHistory = hashParams['disablehistory'] === 'true';
  958. }
  959. if ('webgl' in hashParams) {
  960. _pdfjs.PDFJS.disableWebGL = hashParams['webgl'] !== 'true';
  961. }
  962. if ('useonlycsszoom' in hashParams) {
  963. _pdfjs.PDFJS.useOnlyCssZoom = hashParams['useonlycsszoom'] === 'true';
  964. }
  965. if ('verbosity' in hashParams) {
  966. _pdfjs.PDFJS.verbosity = hashParams['verbosity'] | 0;
  967. }
  968. if ('ignorecurrentpositiononzoom' in hashParams) {
  969. _pdfjs.PDFJS.ignoreCurrentPositionOnZoom = hashParams['ignorecurrentpositiononzoom'] === 'true';
  970. }
  971. if ('locale' in hashParams) {
  972. _pdfjs.PDFJS.locale = hashParams['locale'];
  973. }
  974. if ('textlayer' in hashParams) {
  975. switch (hashParams['textlayer']) {
  976. case 'off':
  977. _pdfjs.PDFJS.disableTextLayer = true;
  978. break;
  979. case 'visible':
  980. case 'shadow':
  981. case 'hover':
  982. var viewer = appConfig.viewerContainer;
  983. viewer.classList.add('textLayer-' + hashParams['textlayer']);
  984. break;
  985. }
  986. }
  987. if ('pdfbug' in hashParams) {
  988. _pdfjs.PDFJS.pdfBug = true;
  989. var pdfBug = hashParams['pdfbug'];
  990. var enabled = pdfBug.split(',');
  991. waitForBeforeOpening.push(loadAndEnablePDFBug(enabled));
  992. }
  993. }
  994. _ui_utils.mozL10n.setLanguage(_pdfjs.PDFJS.locale);
  995. if (!PDFViewerApplication.supportsPrinting) {
  996. appConfig.toolbar.print.classList.add('hidden');
  997. appConfig.secondaryToolbar.printButton.classList.add('hidden');
  998. }
  999. if (!PDFViewerApplication.supportsFullscreen) {
  1000. appConfig.toolbar.presentationModeButton.classList.add('hidden');
  1001. appConfig.secondaryToolbar.presentationModeButton.classList.add('hidden');
  1002. }
  1003. if (PDFViewerApplication.supportsIntegratedFind) {
  1004. appConfig.toolbar.viewFind.classList.add('hidden');
  1005. }
  1006. appConfig.sidebar.mainContainer.addEventListener('transitionend', function (e) {
  1007. if (e.target === this) {
  1008. PDFViewerApplication.eventBus.dispatch('resize');
  1009. }
  1010. }, true);
  1011. appConfig.sidebar.toggleButton.addEventListener('click', function () {
  1012. PDFViewerApplication.pdfSidebar.toggle();
  1013. });
  1014. Promise.all(waitForBeforeOpening).then(function () {
  1015. webViewerOpenFileViaURL(file);
  1016. }).catch(function (reason) {
  1017. PDFViewerApplication.error(_ui_utils.mozL10n.get('loading_error', null, 'An error occurred while opening.'), reason);
  1018. });
  1019. }
  1020. var webViewerOpenFileViaURL;
  1021. {
  1022. webViewerOpenFileViaURL = function webViewerOpenFileViaURL(file) {
  1023. if (file && file.lastIndexOf('file:', 0) === 0) {
  1024. PDFViewerApplication.setTitleUsingUrl(file);
  1025. var xhr = new XMLHttpRequest();
  1026. xhr.onload = function () {
  1027. PDFViewerApplication.open(new Uint8Array(xhr.response));
  1028. };
  1029. try {
  1030. xhr.open('GET', file);
  1031. xhr.responseType = 'arraybuffer';
  1032. xhr.send();
  1033. } catch (e) {
  1034. PDFViewerApplication.error(_ui_utils.mozL10n.get('loading_error', null, 'An error occurred while loading the PDF.'), e);
  1035. }
  1036. return;
  1037. }
  1038. if (file) {
  1039. PDFViewerApplication.open(file);
  1040. }
  1041. };
  1042. }
  1043. function webViewerPageRendered(e) {
  1044. var pageNumber = e.pageNumber;
  1045. var pageIndex = pageNumber - 1;
  1046. var pageView = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
  1047. if (pageNumber === PDFViewerApplication.page) {
  1048. PDFViewerApplication.toolbar.updateLoadingIndicatorState(false);
  1049. }
  1050. if (!pageView) {
  1051. return;
  1052. }
  1053. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  1054. var thumbnailView = PDFViewerApplication.pdfThumbnailViewer.getThumbnail(pageIndex);
  1055. thumbnailView.setImage(pageView);
  1056. }
  1057. if (_pdfjs.PDFJS.pdfBug && Stats.enabled && pageView.stats) {
  1058. Stats.add(pageNumber, pageView.stats);
  1059. }
  1060. if (pageView.error) {
  1061. PDFViewerApplication.error(_ui_utils.mozL10n.get('rendering_error', null, 'An error occurred while rendering the page.'), pageView.error);
  1062. }
  1063. }
  1064. function webViewerTextLayerRendered(e) {}
  1065. function webViewerPageMode(e) {
  1066. var mode = e.mode,
  1067. view;
  1068. switch (mode) {
  1069. case 'thumbs':
  1070. view = _pdf_sidebar.SidebarView.THUMBS;
  1071. break;
  1072. case 'bookmarks':
  1073. case 'outline':
  1074. view = _pdf_sidebar.SidebarView.OUTLINE;
  1075. break;
  1076. case 'attachments':
  1077. view = _pdf_sidebar.SidebarView.ATTACHMENTS;
  1078. break;
  1079. case 'none':
  1080. view = _pdf_sidebar.SidebarView.NONE;
  1081. break;
  1082. default:
  1083. console.error('Invalid "pagemode" hash parameter: ' + mode);
  1084. return;
  1085. }
  1086. PDFViewerApplication.pdfSidebar.switchView(view, true);
  1087. }
  1088. function webViewerNamedAction(e) {
  1089. var action = e.action;
  1090. switch (action) {
  1091. case 'GoToPage':
  1092. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  1093. break;
  1094. case 'Find':
  1095. if (!PDFViewerApplication.supportsIntegratedFind) {
  1096. PDFViewerApplication.findBar.toggle();
  1097. }
  1098. break;
  1099. }
  1100. }
  1101. function webViewerPresentationModeChanged(e) {
  1102. var active = e.active;
  1103. var switchInProgress = e.switchInProgress;
  1104. PDFViewerApplication.pdfViewer.presentationModeState = switchInProgress ? _pdf_viewer.PresentationModeState.CHANGING : active ? _pdf_viewer.PresentationModeState.FULLSCREEN : _pdf_viewer.PresentationModeState.NORMAL;
  1105. }
  1106. function webViewerSidebarViewChanged(evt) {
  1107. PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = PDFViewerApplication.pdfSidebar.isThumbnailViewVisible;
  1108. var store = PDFViewerApplication.store;
  1109. if (store && PDFViewerApplication.isInitialViewSet) {
  1110. store.set('sidebarView', evt.view).catch(function () {});
  1111. }
  1112. }
  1113. function webViewerUpdateViewarea(evt) {
  1114. var location = evt.location,
  1115. store = PDFViewerApplication.store;
  1116. if (store && PDFViewerApplication.isInitialViewSet) {
  1117. store.setMultiple({
  1118. 'exists': true,
  1119. 'page': location.pageNumber,
  1120. 'zoom': location.scale,
  1121. 'scrollLeft': location.left,
  1122. 'scrollTop': location.top
  1123. }).catch(function () {});
  1124. }
  1125. var href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
  1126. PDFViewerApplication.appConfig.toolbar.viewBookmark.href = href;
  1127. PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
  1128. PDFViewerApplication.pdfHistory.updateCurrentBookmark(location.pdfOpenParams, location.pageNumber);
  1129. var currentPage = PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1);
  1130. var loading = currentPage.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED;
  1131. PDFViewerApplication.toolbar.updateLoadingIndicatorState(loading);
  1132. }
  1133. function webViewerResize() {
  1134. var currentScaleValue = PDFViewerApplication.pdfViewer.currentScaleValue;
  1135. if (currentScaleValue === 'auto' || currentScaleValue === 'page-fit' || currentScaleValue === 'page-width') {
  1136. PDFViewerApplication.pdfViewer.currentScaleValue = currentScaleValue;
  1137. } else if (!currentScaleValue) {
  1138. PDFViewerApplication.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  1139. }
  1140. PDFViewerApplication.pdfViewer.update();
  1141. }
  1142. function webViewerHashchange(e) {
  1143. if (PDFViewerApplication.pdfHistory.isHashChangeUnlocked) {
  1144. var hash = e.hash;
  1145. if (!hash) {
  1146. return;
  1147. }
  1148. if (!PDFViewerApplication.isInitialViewSet) {
  1149. PDFViewerApplication.initialBookmark = hash;
  1150. } else {
  1151. PDFViewerApplication.pdfLinkService.setHash(hash);
  1152. }
  1153. }
  1154. }
  1155. var webViewerFileInputChange;
  1156. {
  1157. webViewerFileInputChange = function webViewerFileInputChange(e) {
  1158. var file = e.fileInput.files[0];
  1159. if (!_pdfjs.PDFJS.disableCreateObjectURL && typeof URL !== 'undefined' && URL.createObjectURL) {
  1160. PDFViewerApplication.open(URL.createObjectURL(file));
  1161. } else {
  1162. var fileReader = new FileReader();
  1163. fileReader.onload = function webViewerChangeFileReaderOnload(evt) {
  1164. var buffer = evt.target.result;
  1165. var uint8Array = new Uint8Array(buffer);
  1166. PDFViewerApplication.open(uint8Array);
  1167. };
  1168. fileReader.readAsArrayBuffer(file);
  1169. }
  1170. PDFViewerApplication.setTitleUsingUrl(file.name);
  1171. var appConfig = PDFViewerApplication.appConfig;
  1172. appConfig.toolbar.viewBookmark.setAttribute('hidden', 'true');
  1173. appConfig.secondaryToolbar.viewBookmarkButton.setAttribute('hidden', 'true');
  1174. appConfig.toolbar.download.setAttribute('hidden', 'true');
  1175. appConfig.secondaryToolbar.downloadButton.setAttribute('hidden', 'true');
  1176. };
  1177. }
  1178. function webViewerPresentationMode() {
  1179. PDFViewerApplication.requestPresentationMode();
  1180. }
  1181. function webViewerOpenFile() {
  1182. var openFileInputName = PDFViewerApplication.appConfig.openFileInputName;
  1183. document.getElementById(openFileInputName).click();
  1184. }
  1185. function webViewerPrint() {
  1186. window.print();
  1187. }
  1188. function webViewerDownload() {
  1189. PDFViewerApplication.download();
  1190. }
  1191. function webViewerFirstPage() {
  1192. if (PDFViewerApplication.pdfDocument) {
  1193. PDFViewerApplication.page = 1;
  1194. }
  1195. }
  1196. function webViewerLastPage() {
  1197. if (PDFViewerApplication.pdfDocument) {
  1198. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  1199. }
  1200. }
  1201. function webViewerNextPage() {
  1202. PDFViewerApplication.page++;
  1203. }
  1204. function webViewerPreviousPage() {
  1205. PDFViewerApplication.page--;
  1206. }
  1207. function webViewerZoomIn() {
  1208. PDFViewerApplication.zoomIn();
  1209. }
  1210. function webViewerZoomOut() {
  1211. PDFViewerApplication.zoomOut();
  1212. }
  1213. function webViewerPageNumberChanged(e) {
  1214. var pdfViewer = PDFViewerApplication.pdfViewer;
  1215. pdfViewer.currentPageLabel = e.value;
  1216. if (e.value !== pdfViewer.currentPageNumber.toString() && e.value !== pdfViewer.currentPageLabel) {
  1217. PDFViewerApplication.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  1218. }
  1219. }
  1220. function webViewerScaleChanged(e) {
  1221. PDFViewerApplication.pdfViewer.currentScaleValue = e.value;
  1222. }
  1223. function webViewerRotateCw() {
  1224. PDFViewerApplication.rotatePages(90);
  1225. }
  1226. function webViewerRotateCcw() {
  1227. PDFViewerApplication.rotatePages(-90);
  1228. }
  1229. function webViewerDocumentProperties() {
  1230. PDFViewerApplication.pdfDocumentProperties.open();
  1231. }
  1232. function webViewerFind(e) {
  1233. PDFViewerApplication.findController.executeCommand('find' + e.type, {
  1234. query: e.query,
  1235. phraseSearch: e.phraseSearch,
  1236. caseSensitive: e.caseSensitive,
  1237. highlightAll: e.highlightAll,
  1238. findPrevious: e.findPrevious
  1239. });
  1240. }
  1241. function webViewerFindFromUrlHash(e) {
  1242. PDFViewerApplication.findController.executeCommand('find', {
  1243. query: e.query,
  1244. phraseSearch: e.phraseSearch,
  1245. caseSensitive: false,
  1246. highlightAll: true,
  1247. findPrevious: false
  1248. });
  1249. }
  1250. function webViewerScaleChanging(e) {
  1251. PDFViewerApplication.toolbar.setPageScale(e.presetValue, e.scale);
  1252. PDFViewerApplication.pdfViewer.update();
  1253. }
  1254. function webViewerPageChanging(e) {
  1255. var page = e.pageNumber;
  1256. PDFViewerApplication.toolbar.setPageNumber(page, e.pageLabel || null);
  1257. PDFViewerApplication.secondaryToolbar.setPageNumber(page);
  1258. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  1259. PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(page);
  1260. }
  1261. if (_pdfjs.PDFJS.pdfBug && Stats.enabled) {
  1262. var pageView = PDFViewerApplication.pdfViewer.getPageView(page - 1);
  1263. if (pageView.stats) {
  1264. Stats.add(page, pageView.stats);
  1265. }
  1266. }
  1267. }
  1268. var zoomDisabled = false,
  1269. zoomDisabledTimeout;
  1270. function webViewerWheel(evt) {
  1271. var pdfViewer = PDFViewerApplication.pdfViewer;
  1272. if (pdfViewer.isInPresentationMode) {
  1273. return;
  1274. }
  1275. if (evt.ctrlKey || evt.metaKey) {
  1276. var support = PDFViewerApplication.supportedMouseWheelZoomModifierKeys;
  1277. if (evt.ctrlKey && !support.ctrlKey || evt.metaKey && !support.metaKey) {
  1278. return;
  1279. }
  1280. evt.preventDefault();
  1281. if (zoomDisabled) {
  1282. return;
  1283. }
  1284. var previousScale = pdfViewer.currentScale;
  1285. var delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
  1286. var MOUSE_WHEEL_DELTA_PER_PAGE_SCALE = 3.0;
  1287. var ticks = delta * MOUSE_WHEEL_DELTA_PER_PAGE_SCALE;
  1288. if (ticks < 0) {
  1289. PDFViewerApplication.zoomOut(-ticks);
  1290. } else {
  1291. PDFViewerApplication.zoomIn(ticks);
  1292. }
  1293. var currentScale = pdfViewer.currentScale;
  1294. if (previousScale !== currentScale) {
  1295. var scaleCorrectionFactor = currentScale / previousScale - 1;
  1296. var rect = pdfViewer.container.getBoundingClientRect();
  1297. var dx = evt.clientX - rect.left;
  1298. var dy = evt.clientY - rect.top;
  1299. pdfViewer.container.scrollLeft += dx * scaleCorrectionFactor;
  1300. pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
  1301. }
  1302. } else {
  1303. zoomDisabled = true;
  1304. clearTimeout(zoomDisabledTimeout);
  1305. zoomDisabledTimeout = setTimeout(function () {
  1306. zoomDisabled = false;
  1307. }, 1000);
  1308. }
  1309. }
  1310. function webViewerClick(evt) {
  1311. if (!PDFViewerApplication.secondaryToolbar.isOpen) {
  1312. return;
  1313. }
  1314. var appConfig = PDFViewerApplication.appConfig;
  1315. if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar.toggleButton) {
  1316. PDFViewerApplication.secondaryToolbar.close();
  1317. }
  1318. }
  1319. function webViewerKeyDown(evt) {
  1320. if (PDFViewerApplication.overlayManager.active) {
  1321. return;
  1322. }
  1323. var handled = false,
  1324. ensureViewerFocused = false;
  1325. var cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
  1326. var pdfViewer = PDFViewerApplication.pdfViewer;
  1327. var isViewerInPresentationMode = pdfViewer && pdfViewer.isInPresentationMode;
  1328. if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
  1329. switch (evt.keyCode) {
  1330. case 70:
  1331. if (!PDFViewerApplication.supportsIntegratedFind) {
  1332. PDFViewerApplication.findBar.open();
  1333. handled = true;
  1334. }
  1335. break;
  1336. case 71:
  1337. if (!PDFViewerApplication.supportsIntegratedFind) {
  1338. var findState = PDFViewerApplication.findController.state;
  1339. if (findState) {
  1340. PDFViewerApplication.findController.executeCommand('findagain', {
  1341. query: findState.query,
  1342. phraseSearch: findState.phraseSearch,
  1343. caseSensitive: findState.caseSensitive,
  1344. highlightAll: findState.highlightAll,
  1345. findPrevious: cmd === 5 || cmd === 12
  1346. });
  1347. }
  1348. handled = true;
  1349. }
  1350. break;
  1351. case 61:
  1352. case 107:
  1353. case 187:
  1354. case 171:
  1355. if (!isViewerInPresentationMode) {
  1356. PDFViewerApplication.zoomIn();
  1357. }
  1358. handled = true;
  1359. break;
  1360. case 173:
  1361. case 109:
  1362. case 189:
  1363. if (!isViewerInPresentationMode) {
  1364. PDFViewerApplication.zoomOut();
  1365. }
  1366. handled = true;
  1367. break;
  1368. case 48:
  1369. case 96:
  1370. if (!isViewerInPresentationMode) {
  1371. setTimeout(function () {
  1372. pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  1373. });
  1374. handled = false;
  1375. }
  1376. break;
  1377. case 38:
  1378. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  1379. PDFViewerApplication.page = 1;
  1380. handled = true;
  1381. ensureViewerFocused = true;
  1382. }
  1383. break;
  1384. case 40:
  1385. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  1386. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  1387. handled = true;
  1388. ensureViewerFocused = true;
  1389. }
  1390. break;
  1391. }
  1392. }
  1393. if (cmd === 1 || cmd === 8) {
  1394. switch (evt.keyCode) {
  1395. case 83:
  1396. PDFViewerApplication.download();
  1397. handled = true;
  1398. break;
  1399. }
  1400. }
  1401. if (cmd === 3 || cmd === 10) {
  1402. switch (evt.keyCode) {
  1403. case 80:
  1404. PDFViewerApplication.requestPresentationMode();
  1405. handled = true;
  1406. break;
  1407. case 71:
  1408. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  1409. handled = true;
  1410. break;
  1411. }
  1412. }
  1413. if (handled) {
  1414. if (ensureViewerFocused && !isViewerInPresentationMode) {
  1415. pdfViewer.focus();
  1416. }
  1417. evt.preventDefault();
  1418. return;
  1419. }
  1420. var curElement = document.activeElement || document.querySelector(':focus');
  1421. var curElementTagName = curElement && curElement.tagName.toUpperCase();
  1422. if (curElementTagName === 'INPUT' || curElementTagName === 'TEXTAREA' || curElementTagName === 'SELECT') {
  1423. if (evt.keyCode !== 27) {
  1424. return;
  1425. }
  1426. }
  1427. if (cmd === 0) {
  1428. switch (evt.keyCode) {
  1429. case 38:
  1430. case 33:
  1431. case 8:
  1432. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== 'page-fit') {
  1433. break;
  1434. }
  1435. case 37:
  1436. if (pdfViewer.isHorizontalScrollbarEnabled) {
  1437. break;
  1438. }
  1439. case 75:
  1440. case 80:
  1441. if (PDFViewerApplication.page > 1) {
  1442. PDFViewerApplication.page--;
  1443. }
  1444. handled = true;
  1445. break;
  1446. case 27:
  1447. if (PDFViewerApplication.secondaryToolbar.isOpen) {
  1448. PDFViewerApplication.secondaryToolbar.close();
  1449. handled = true;
  1450. }
  1451. if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar.opened) {
  1452. PDFViewerApplication.findBar.close();
  1453. handled = true;
  1454. }
  1455. break;
  1456. case 40:
  1457. case 34:
  1458. case 32:
  1459. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== 'page-fit') {
  1460. break;
  1461. }
  1462. case 39:
  1463. if (pdfViewer.isHorizontalScrollbarEnabled) {
  1464. break;
  1465. }
  1466. case 74:
  1467. case 78:
  1468. if (PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  1469. PDFViewerApplication.page++;
  1470. }
  1471. handled = true;
  1472. break;
  1473. case 36:
  1474. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  1475. PDFViewerApplication.page = 1;
  1476. handled = true;
  1477. ensureViewerFocused = true;
  1478. }
  1479. break;
  1480. case 35:
  1481. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  1482. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  1483. handled = true;
  1484. ensureViewerFocused = true;
  1485. }
  1486. break;
  1487. case 83:
  1488. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.SELECT);
  1489. break;
  1490. case 72:
  1491. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.HAND);
  1492. break;
  1493. case 82:
  1494. PDFViewerApplication.rotatePages(90);
  1495. break;
  1496. }
  1497. }
  1498. if (cmd === 4) {
  1499. switch (evt.keyCode) {
  1500. case 32:
  1501. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== 'page-fit') {
  1502. break;
  1503. }
  1504. if (PDFViewerApplication.page > 1) {
  1505. PDFViewerApplication.page--;
  1506. }
  1507. handled = true;
  1508. break;
  1509. case 82:
  1510. PDFViewerApplication.rotatePages(-90);
  1511. break;
  1512. }
  1513. }
  1514. if (!handled && !isViewerInPresentationMode) {
  1515. if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== 'BUTTON') {
  1516. ensureViewerFocused = true;
  1517. }
  1518. }
  1519. if (cmd === 2) {
  1520. switch (evt.keyCode) {
  1521. case 37:
  1522. if (isViewerInPresentationMode) {
  1523. PDFViewerApplication.pdfHistory.back();
  1524. handled = true;
  1525. }
  1526. break;
  1527. case 39:
  1528. if (isViewerInPresentationMode) {
  1529. PDFViewerApplication.pdfHistory.forward();
  1530. handled = true;
  1531. }
  1532. break;
  1533. }
  1534. }
  1535. if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
  1536. pdfViewer.focus();
  1537. }
  1538. if (handled) {
  1539. evt.preventDefault();
  1540. }
  1541. }
  1542. _ui_utils.localized.then(function webViewerLocalized() {
  1543. document.getElementsByTagName('html')[0].dir = _ui_utils.mozL10n.getDirection();
  1544. });
  1545. var PDFPrintServiceFactory = {
  1546. instance: {
  1547. supportsPrinting: false,
  1548. createPrintService: function createPrintService() {
  1549. throw new Error('Not implemented: createPrintService');
  1550. }
  1551. }
  1552. };
  1553. exports.PDFViewerApplication = PDFViewerApplication;
  1554. exports.DefaultExternalServices = DefaultExternalServices;
  1555. exports.PDFPrintServiceFactory = PDFPrintServiceFactory;