Commit Graph

2473 Commits

Author SHA1 Message Date
Jonas Jenwald
1fab637247 Prevent if (!state || false) { in the output, in PDFHistory._popState, for e.g. MOZCENTRAL builds
By re-ordering the condition, which includes a `PDFJSDev` check, we can avoid meaningless output in the built files.
2019-12-13 10:38:39 +01:00
Jonas Jenwald
c5f2f870cb Move the parseCurrentHash helper function into PDFHistory
Looking at the `parseCurrentHash` function again it's now difficult for me to understand *what* I was thinking, since having a helper function that needs to be manually passed a `linkService` reference just looks weird.
2019-12-13 10:38:39 +01:00
Jonas Jenwald
d621899d50 Add a reset method to the PDFHistory implementation
This patch addresses a couple of smaller issues with the `PDFHistory` class:
 - Most, if not all, other viewer components can be reset in one way or another, and there's no good reason for the `PDFHistory` implementation to be different here.

 - Currently it's (technically) possible to keep adding entries to the browser history, via the `PDFHistory` instance, even after the document has been closed. That obviously makes no sense, and is caused by the lack of a `reset` method.

 - The internal `this._isPagesLoaded` property was never actually reset, which would lead to it being temporarily wrong when a new document was opened in the default viewer.
2019-12-13 10:38:39 +01:00
Tim van der Meij
7b503c8923
Merge pull request #11388 from Snuffleupagus/rm-PDFPresentationMode-viewer-option
Remove the `viewer` option from the `PDFPresentationMode` constructor
2019-12-08 19:55:43 +01:00
Jonas Jenwald
1c466b4648 Remove the viewer option from the PDFPresentationMode constructor
The `viewer` option was *only* used for checking that a document is loaded in `PDFPresentationMode.request`, however that's just as easy to do by simply utilizing `BaseViewer.pagesCount` instead and this way we can also avoid the DOM lookup.
2019-12-06 00:20:56 +01:00
Jonas Jenwald
06b1f619c6 Fix an incorrect condition in BaseViewer.isPageVisible (PR 10217 follow-up)
This was a blatant oversight in PR 10217, since there's obviously no `this.pageNumber` property anywhere in the `BaseViewer`. Luckily this shouldn't have caused any bugs, since the only call-site is also validating the `pageNumber` (but correctly that time).
2019-12-04 13:38:07 +01:00
Jonas Jenwald
6732df6aae Set the first pdfPage immediately in {BaseViewer, PDFThumbnailViewer}.setDocument
*This patch is simple enough that I almost feel like I'm overlooking some trivial reason why this would be a bad idea.*

Note how in `{BaseViewer, PDFThumbnailViewer}.setDocument` we're always getting the *first* `pdfPage` in order to initialize all pages/thumbnails.
However, once that's done the first `pdfPage` is simply ignored and rendering of the first page thus requires calling `PDFDocumentProxy.getPage` yet again. (And in the `BaseViewer` case, it's even done once more after `onePageRenderedCapability` is resolved.)

All in all, I cannot see why we cannot just immediately set the first `pdfPage` and thus avoid an early round-trip to the API in the `_ensurePdfPageLoaded` method before rendering can begin.
2019-12-01 12:39:55 +01:00
Jonas Jenwald
a965662184 Enable the getter-return, no-dupe-else-if, and no-setter-return ESLint rules
All of these rules can help catch errors during development. Please note that only `getter-return` required a few changes, which was limited to disabling the rule in a couple of spots; please find additional details about these rules at:
 - https://eslint.org/docs/rules/getter-return
 - https://eslint.org/docs/rules/no-dupe-else-if
 - https://eslint.org/docs/rules/no-setter-return
2019-11-23 11:40:30 +01:00
Jonas Jenwald
e09310d7a4 Remove document.attachEvent code from web/pdf_print_service.js since it's only necessary for old IE versions
This code was originally added to support IE10 (and below), however with those browsers *explicitly* unsupported since PDF.js version `2.0` this code is now dead.
2019-11-22 13:46:44 +01:00
Jonas Jenwald
0f73758222 Convert {BaseViewer, PDFThumbnailViewer}._pagesRequests from an Array to a WeakMap
Obviously the `_pagesRequests` functionality is *mainly* used when `disableAutoFetch` is set, but it will also be used during ranged/streamed loading of documents.
However, the `_pagesRequests` property is currently an Array which seems a bit strange:

 - Arrays are zero-indexed, but the first element will never actually be set in the code.
 - The `_pagesRequests` Array is never cleared, unless a new document is loaded, and once the `PDFDocumentProxy.getPage` call has resolved/rejected the element is just replaced by `null`.
 - Unless the document is browsed *in order* the resulting `_pagesRequests` Array can also be arbitrarily sparse.

All in all, I don't believe that an Array is an appropriate data structure to use for this purpose.
2019-11-21 09:38:37 +01:00
Tim van der Meij
ef1cd11908
Merge pull request #11338 from Snuffleupagus/toolbar-buttons-init
Reduce duplication when registering event listeners for the `Toolbar` buttons, and other small clean-up
2019-11-19 23:59:14 +01:00
Jonas Jenwald
0b0bf71ad0 Ensure that attempting to print with disableAutoFetch set will fail gracefully (issue 11339)
This patch simply restores the behaviour that existed prior to PR 7697, since I cannot imagine that that was changed other than by pure accident.
As mentioned by a comment in `BaseViewer.setDocument`: "Printing is semi-broken with auto fetch disabled.", and note that since triggering of printing is a synchronous operation there's generally no easy way to load the missing data.

https://github.com/mozilla/pdf.js/pull/7697/files#diff-529d1853ee1bba753a0fcb40ea778723L1114-L1118
2019-11-19 12:13:15 +01:00
Jonas Jenwald
07473e9e2a Inline the Toolbar._localized method in the 'localized' event handler
Considering just how small/simple this code is, it doesn't seem necessary to have a separate method for it (even more so when there's only one call-site).
2019-11-17 14:17:47 +01:00
Jonas Jenwald
eaa2e216f4 Use for...of in a couple of loops in web/toolbar.js and web/secondary_toolbar.js 2019-11-17 13:59:28 +01:00
Jonas Jenwald
3edaebbded Reduce duplication when registering event listeners for the Toolbar buttons
This uses the same kind of format as is being used in the `SecondaryToolbar` class.
2019-11-17 13:55:29 +01:00
Jonas Jenwald
878432784c [PDFHistory] Move the IE11 pushState/replaceState work-around to src/shared/compatibility.js (PR 10461 follow-up)
I've always disliked the solution in PR 10461, since it required changes to the `PDFHistory` code itself to deal with a bug in IE11.
Now that IE11 support is limited, it seems reasonable to remove these `pushState`/`replaceState` hacks from the main code-base and simply use polyfills instead.
2019-11-11 17:48:04 +01:00
Jonas Jenwald
2817121bc1 Convert globalScope and isNodeJS to proper modules
Slightly unrelated to the rest of the patch, but this also removes an out-of-place `globals` definition from the `web/viewer.js` file.
2019-11-10 16:44:29 +01:00
Jonas Jenwald
eedd449cb4 Remove some unused require statements, used when loading fake workers, in non-PRODUCTION mode
The code in question is *only* relevant in non-`PRODUCTION` mode, i.e. the *development* version of the viewer run with `gulp server`, and has been completely unused at least since SystemJS was added.
I really cannot see any reason to keep this, since it's code which first of all isn't shipping and secondly isn't even being used in the development viewer.
2019-10-31 12:08:07 +01:00
siarhei.zdabnou
fea102b235 border & box-shadow duplications removed 2019-10-22 14:25:42 +02:00
Jonas Jenwald
ce816eed8e Attempt to reduce resource usage, by not eagerly fetching all pages, for long/large documents
For *very* long/large documents fetching all pages on load may cause quite bad performance, both memory and CPU wise. In order to at least slightly alleviate this, we can let the viewer treat these kind of documents[1] as if `disableAutoFetch` were set.

---
[1] One example of a really bad case is https://bugzilla.mozilla.org/show_bug.cgi?id=1588435, which this patch should at least help somewhat. In general, for these cases, we'd probably need to implement switching between `PDFViewer`/`PDFSinglePageViewer` (as already tracked on GitHub) and use the latter for these kind of long documents.
2019-10-20 13:21:36 +02:00
Jonas Jenwald
d67a5d395c Avoid handling keyboard shortcuts for contentEditable DOM elements (issue 7156)
The issue has been open for years now, and has even been marked with `5-good-beginner-bug` for *months*, without any movement.
Considering just how simple the suggested solution is, I'm submitting this patch just to close out a long-standing issue.
2019-10-16 16:50:43 +02:00
Jonas Jenwald
f964cbc961 Tweak the isIOS check, in web/viewer_compatibility, to attempt to support newer Safari versions (issue 11245)
Obviously userAgent checks aren't that great, since it's very easy to spoof, but it probably doesn't hurt to attempt to extend this (since it's limited to `GENERIC` builds).
Besides, anyone using the default viewer can always set the `maxCanvasPixels` option to a value of their choosing.
2019-10-15 17:22:28 +02:00
Tim van der Meij
ca3a58f93a
Consistently use @returns for returned data types in JSDoc comments
Sometimes we also used `@return`, but `@returns` is what the JSDoc
documentation recommends. Even though `@return` works as an alias, it's
good to use the recommended syntax and to be consistent within the
project.
2019-10-13 13:58:17 +02:00
Tim van der Meij
8b4ae6f3eb
Consistently use @type for getter data types in JSDoc comments
Sometimes we also used `@return` or `@returns`, but `@type` is what
the JSDoc documentation recommends. This also improves the documentation
because before this commit the types were not shown and now they are.
2019-10-13 13:58:17 +02:00
Tim van der Meij
f4daafc077
Consistently use square brackets for optional parameters in JSDoc comments
Square brackets are recommended to indicate optional parameters. Using
them helps for automatically generating correct documentation.
2019-10-13 13:58:17 +02:00
Tim van der Meij
efd331daa1
Consistently use string for string data types in JSDoc comments
Sometimes we also used `String`, but `string` is the what the JSDoc
documentation recommends.
2019-10-13 13:58:17 +02:00
Tim van der Meij
e75991b49e
Consistently use number for numeric data types in JSDoc comments
Sometimes we also used `Number` and `integer`, but `number` is what
the JSDoc documentation recommends.
2019-10-13 13:58:13 +02:00
Jonas Jenwald
32d16ab5f6 [PDFSidebarResizer] Re-factor the resize event listener to improve readability
I've absolutely no idea why I wrote the code that way originally, since the nested `if`s are not really helping readability one bit.
Hence this patch which changes things to use early `return`s instead, to help readability.
2019-10-03 12:24:19 +02:00
Jonas Jenwald
9e4552d792 [PDFSidebarResizer] Refactor the clamping in _updateWidth
Rather than manually clamping the `width` here, we can just `export` an already existing helper function from `ui_utils.js` instead.

(Hopefully it will eventually be possible to replace this helper function with a native `Math.clamp` function, given that there exists a "Stage 1 Proposal" for adding such a thing to the ECMAScript specification.)
2019-10-03 12:03:45 +02:00
Jonas Jenwald
c1cfe2881b [PDFSidebarResizer] Skip the CSS.supports checks for MOZCENTRAL builds
Since CSS variable support cannot be disabled any more in Firefox, the run-time checks are of no using for MOZCENTRAL builds.
2019-10-03 11:55:13 +02:00
Jonas Jenwald
b822356c03 Enable a couple of return related ESLint rules
Please find additional details at:
 - https://eslint.org/docs/rules/no-return-await
 - https://eslint.org/docs/rules/no-useless-return
2019-09-20 14:30:03 +02:00
Tim van der Meij
1f5ebfbf0c
Replace our URL polyfill with the one from core-js
`core-js` polyfills have proven to be of good quality and using them
prevents us from having to maintain them ourselves.
2019-09-19 14:09:51 +02:00
Jonas Jenwald
e7baf2ab61 Prevent "offsetParent is not set -- cannot scroll" errors when the viewer loads in e.g. a hidden <iframe>
Besides avoiding errors during loading, this also ensures that the document will be correctly scrolled/zoomed into view once the viewer becomes visible.
This "new" behaviour was always intended, see PR 2613, however various re-factoring over the years seem to have broken this (and I'm probably at least somewhat responsible for that).
2019-09-08 14:13:50 +02:00
Jonas Jenwald
7dea3f9389 [api-minor] Remove the postMessageTransfers parameter, and thus the ability to manually disable transferring of data, from the API
By transfering, rather than copying, `ArrayBuffer`s between the main- and worker-threads, you can avoid unnecessary allocations by only having *one* copy of the same data.
Hence manually setting `postMessageTransfers: false`, when calling `getDocument`, is a performance footgun[1] which will do nothing but waste memory.

Given that every reasonably modern browser supports `postMessage` transfers[2], I really don't see why it should be possible to force-disable this functionality.
Looking at the browser support, for `postMessage` transfers[2], it's highly unlikely that PDF.js is even usable in browsers without it. However, the feature testing of `postMessage` transfers is kept for the time being just to err on the safe side.

---
[1] This is somewhat similar to the, now removed, `disableWorker` parameter which also provided API users a much too simple way of reducing performance.

[2] See e.g. https://developer.mozilla.org/en-US/docs/Web/API/MessagePort/postMessage#Browser_compatibility and https://developer.mozilla.org/en-US/docs/Web/API/Transferable#Browser_compatibility
2019-09-05 13:09:54 +02:00
Priestch
000780d27e Use shorthand method signature for afterPrint in web/app.js 2019-08-24 18:26:25 +08:00
Brendan Dahl
98e989116c Add a way to disable external links. 2019-08-21 11:20:41 -07:00
Jonas Jenwald
446ce88f81 Remove the non-PRODUCTION only 'disablebcmaps' hash parameter
This was added in PR 4470, but doesn't appear to have been used since.
While it's certainly easy to understand how this was helpful during development of that PR, actually providing this hash parameter isn't going to work anymore given that the original CMap files were also removed from the repository.

I suppose that the hash parameter *could* be useful if you'd attempt to update the BCMap files, however that hasn't been attempted even once in over *five* years time. Furthermore, at this point using the `AppOptions` directly in that situation should also work fine.

All in all, this seems like a piece of old and unused code which we can simply remove now.
2019-08-10 15:40:33 +02:00
Jonas Jenwald
04a3dc65e4 Move the sidebar toggleButton event listener into PDFSidebar
This is consistent with other functionality, such as e.g. `SecondaryToolbar` and `PDFFindBar`.
2019-08-10 15:38:33 +02:00
Brendan Dahl
e1aed05c44
Merge pull request #11049 from brendandahl/telem-add-time
Add page rendered timestamp to telemetry.
2019-08-06 11:53:08 -07:00
Brendan Dahl
47077f8de9 Add page rendered timestamp to telemetry. 2019-08-06 09:46:33 -07:00
Jonas Jenwald
9acaaf5126 Use more compact keys in PDFLinkService._pagesRefCache
By using the same internal formatting here as in the `Ref.toString` method, in `src/core/primitives.js`, all cache-keys will become at least two bytes shorter (and most three bytes shorter).
Obviously this won't have a huge effect on memory since there's only one cache entry per page, but it nonetheless seems wasteful to use longer keys than strictly required.
2019-08-05 18:06:32 +02:00
Tim van der Meij
e0b38bed3c
Merge pull request #11029 from brendandahl/pdfjs-telemetry-update
[api-minor] Update telemetry to use 'categorical' histograms.
2019-08-02 00:11:02 +02:00
Brendan Dahl
31d71808e7 [api-minor] Update telemetry to use 'categorical' histograms.
Firefox telemetry supports using string labels now. Convert our integers
that we used for categories to just use strings.

The upstream work will happen in:
https://bugzilla.mozilla.org/show_bug.cgi?id=1566882
2019-08-01 09:51:02 -07:00
Jonas Jenwald
cb1394c13d Ensure that the loading indicator, in the pageNumber input, is hidden when the viewer is closed
Currently the indicator may remain visible even after the document has been closed, which seems weird given that no page is either visible nor rendering :-)
2019-08-01 16:30:33 +02:00
Tim van der Meij
9b72089886
Merge pull request #11003 from Snuffleupagus/webViewerWheel-supportedKeys
Ensure that setting the `zoomDisabledTimeout` isn't skipped, regardless of the supported zoom keys, when handling mouse wheel events (PR 7097 follow-up)
2019-07-23 22:28:36 +02:00
Jonas Jenwald
1eed5b7235 Ensure that setting the zoomDisabledTimeout isn't skipped, regardless of the supported zoom keys, when handling mouse wheel events (PR 7097 follow-up)
*Possible follow-up:* It probably wouldn't hurt to try and shorten the `supportedMouseWheelZoomModifierKeys` name a bit, but I'm not attempting that here since it'd also require updating `PdfStreamConverter.jsm` in mozilla-central in order to be consistent.
2019-07-23 17:42:12 +02:00
Jonas Jenwald
46b61ff12e Avoid creating a PDFFindBar instance, in the Firefox built-in viewer, when not actually necessary
This is similar to how `PDFPresentationMode` isn't used when the Fullscreen API isn't supported.
2019-07-23 07:51:14 +02:00
Jonas Jenwald
53a854bb0a Remove an unnecessary PDFDocumentProperties.setFileSize call, relevant for the Firefox built-in viewer, and use the "normal" code-path in PDFViewerApplication.open instead
Since calling `getDocument` with a `PDFDataRangeTransport` argument will always unconditionally override a manually provided `length` argument, see a1a667809f/src/display/api.js (L390-L394), this patch should thus be safe.
2019-07-21 11:38:17 +02:00
Jonas Jenwald
ba2c042a75 Add the docBaseUrl API parameter to AppOptions in the viewer
This unfortunately required a bit of special handling, to correctly deal with the various extension builds.
2019-07-20 13:39:34 +02:00
Tim van der Meij
acef5bfd16
Merge pull request #10979 from Snuffleupagus/firefox-zoomreset
[Firefox] Re-factor the 'zoomreset' message handling in the viewer (PR 10652 follow-up)
2019-07-19 22:42:07 +02:00