2
0

app.js 57 KB

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