2
0

app.js 57 KB

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