Commit Graph

12038 Commits

Author SHA1 Message Date
Jonas Jenwald
e24050fa13 [api-minor] Move the ReadableStream polyfill to the global scope
Note that most (reasonably) modern browsers have supported this for a while now, see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream#Browser_compatibility

By moving the polyfill into `src/shared/compatibility.js` we can thus get rid of the need to manually export/import `ReadableStream` and simply use it directly instead.

The only change here which *could* possibly lead to a difference in behavior is in the `isFetchSupported` function. Previously we attempted to check for the existence of a global `ReadableStream` implementation, which could now pass (assuming obviously that the preceding checks also succeeded).
However I'm not sure if that's a problem, since the previous check only confirmed the existence of a native `ReadableStream` implementation and not that it actually worked correctly. Finally it *could* just as well have been a globally registered polyfill from an application embedding the PDF.js library.
2019-12-11 19:02:37 +01:00
Tim van der Meij
af4ba75f68
Merge pull request #11398 from Snuffleupagus/issue-5887
Attempt to improve the `PDFDocument` error message for empty files (issue 5887)
2019-12-09 22:08:08 +01:00
Jonas Jenwald
b00835f589 Attempt to improve the PDFDocument error message for empty files (issue 5887)
Given that the error in question is surfaced on the API-side, this patch makes the following changes:
 - Updates the wording such that it'll hopefully be slightly easier for users to understand.
 - Changes the plain `Error` to an `InvalidPDFException` instead, since that should work better with the existing Error handling.
 - Adds a unit-test which loads an empty PDF document (and also improves a pre-existing `InvalidPDFException` message and its test-case).
2019-12-09 15:45:50 +01:00
Tim van der Meij
a6db045789
Merge pull request #11387 from Snuffleupagus/issue-11385
Handle corrupt ASCII85Decode inline images with truncated EOD markers (issue 11385)
2019-12-08 20:27:46 +01:00
Tim van der Meij
16778118f6
Merge pull request #11391 from Snuffleupagus/globalThis
Replace `globalScope` with the standard `globalThis` property instead
2019-12-08 20:23:19 +01:00
Jonas Jenwald
71d61e4c6f Re-factor getMainThreadWorkerMessageHandler to support arbitrary global scopes, rather than only window 2019-12-08 20:19:04 +01:00
Jonas Jenwald
a8fc306b6e Replace globalScope with the standard globalThis property instead
Please see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis and note that most (reasonably) modern browsers have supported this for a while now, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis#Browser_compatibility

Since ESLint doesn't support this new global yet, it was added to the `globals` list in the top-level configuration file to prevent issues.

Finally, for older browsers a polyfill was added in `ssrc/shared/compatibility.js`.
2019-12-08 20:19:02 +01:00
Tim van der Meij
07212bf5f2
Merge pull request #11390 from Snuffleupagus/checkFirstPage-await-cleanup
Ensure that `PDFDocument.checkFirstPage` waits for cleanup to complete (PR 10392 follow-up)
2019-12-08 20:13:00 +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
Tim van der Meij
3d549f12fa
Merge pull request #11382 from Snuffleupagus/pr-10217-follow-up
Fix an incorrect condition in `BaseViewer.isPageVisible` (PR 10217 follow-up)
2019-12-08 19:52:48 +01:00
Jonas Jenwald
a02122e984 Ensure that PDFDocument.checkFirstPage waits for cleanup to complete (PR 10392 follow-up)
Given how this method is currently used there shouldn't be any fonts loaded at the point in time where it's called, but it does seem like a bad idea to assume that that's always going to be the case. Since `PDFDocument.checkFirstPage` is already asynchronous, it's easy enough to simply await `Catalog.cleanup` here.

(The patch also makes a tiny simplification in a loop in `Catalog.cleanup`.)
2019-12-07 12:31:41 +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
5c0336872e Handle corrupt ASCII85Decode inline images with truncated EOD markers (issue 11385)
In the PDF document in question, there's an ASCII85Decode inline image where the '>' part of EOD (end-of-data) marker is missing; hence the PDF document is corrupt.
2019-12-05 15:53:18 +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
Tim van der Meij
514b500a6c
Merge pull request #11374 from Snuffleupagus/set-first-pdfPage
Set the first `pdfPage` immediately in `{BaseViewer, PDFThumbnailViewer}.setDocument`
2019-12-01 13:34:36 +01:00
Tim van der Meij
ded56f2fe4
Merge pull request #11373 from Snuffleupagus/fetch-cacheMap-rm-has
Slightly simplify the XRef cache lookup in `XRef.fetch`
2019-12-01 13:23:53 +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
c3b1c8f857 Slightly simplify the XRef cache lookup in XRef.fetch
Note that the XRef cache will only hold objects returned through `Parser.getObj`, and indirectly via `Lexer.getObj`. Since neither of those methods will ever return `undefined`, we can simply `assert` that when inserting objects into the cache and thus get rid of one function call when doing cache lookups.

Obviously this won't have a huge effect on performance, however `XRef.fetch` is usually called *a lot* in larger documents and this patch thus cannot hurt.
2019-11-30 22:41:53 +01:00
Tim van der Meij
62ec8109b5
Merge pull request #11370 from Snuffleupagus/fetchCompressed-isStream
Stop caching Streams in `XRef.fetchCompressed`
2019-11-30 14:56:47 +01:00
Jonas Jenwald
168c6aecae Stop caching Streams in XRef.fetchCompressed
I'm slightly surprised that this hasn't actually caused any (known) bugs, but that may be more luck than anything else since it fortunately doesn't seem common for Streams to be defined inside of an 'ObjStm'.[1]

Note that in the `XRef.fetchUncompressed` method we're *not* caching Streams, and that for very good reasons too.

 - Streams, especially the `DecodeStream` ones, can become *very* large once read. Hence caching them really isn't a good idea simply because of the (potential) memory impact of doing so.

 - Attempting to read from the *same* Stream more than once won't work, unless it's `reset` in between, since using any method such as e.g. `getBytes` always starts at the current data position.

 - Given that even the `src/core/` code is now fairly asynchronous, see e.g. the `PartialEvaluator`, it's generally impossible to assert that any one Stream isn't being accessed "concurrently" by e.g. different `getOperatorList` calls. Hence `reset`-ing a cached Streams isn't going to work in the general case.

All in all, I cannot understand why it'd ever be correct to cache Streams in the `XRef.fetchCompressed` method.

---
[1] One example where that happens is the `issue3115r.pdf` file in the test-suite, where the streams in question are not actually used for anything within the PDF.js code.
2019-11-30 10:21:08 +01:00
Jonas Jenwald
06412a557b Slighthly re-factor XRef.fetchCompressed
- Change all occurences of `var` to `let`/`const`.

 - Initialize the (temporary) Arrays with the correct sizes upfront.

 - Inline the `isCmd` check. Obviously this won't make a huge difference, but given that the check is only relevant for corrupt documents it cannot hurt.
2019-11-30 09:49:51 +01:00
Tim van der Meij
b0aee6b1f0
Merge pull request #11363 from Snuffleupagus/fetchUncompressed-isInteger-checks
Remove the `Number.isInteger` checks from `XRef.fetchUncompressed` (PR 8857 follow-up)
2019-11-29 22:27:38 +01:00
Jonas Jenwald
725566cfea Remove the Number.isInteger checks from XRef.fetchUncompressed (PR 8857 follow-up)
Having ran the entire test-suite locally with these `Number.isInteger` checks removed, there wasn't a single test failure anywhere; see also PR 8857.
Hence everything points to this being completely unnecessary now, and by removing this code there's thus fewer function calls being made in `XRef.fetchUncompressed`.
2019-11-28 23:25:39 +01:00
Tim van der Meij
dcf998a1c1
Merge pull request #11356 from Snuffleupagus/rm-wrong-PDFDocument-comment
Remove outdated, and misleading, JSDoc comment from the `PDFDocument` class
2019-11-25 22:24:54 +01:00
Jonas Jenwald
cc76132c24 Remove outdated, and misleading, JSDoc comment from the PDFDocument class
The contents of this comment hasn't been correct for *years*, ever since the library was properly split into main/worker-threads, so it's probably high time for this to be updated.
2019-11-25 11:36:29 +01:00
Tim van der Meij
827eb64b75
Merge pull request #11354 from Snuffleupagus/eslint-more-rules
Enable the `getter-return`, `no-dupe-else-if`, and `no-setter-return` ESLint rules
2019-11-23 14:03:51 +01:00
Jonas Jenwald
1319c9f13b Update l10n files 2019-11-23 12:02:31 +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
b8f0cf0bc0 Update npm packages 2019-11-23 11:25:24 +01:00
Tim van der Meij
2feb3170bf
Merge pull request #11325 from smohtadi/custom-file-transform
Added custom file transform function
2019-11-22 23:02:34 +01:00
Tim van der Meij
79aa936f33
Merge pull request #11353 from Snuffleupagus/rm-attachEvent
Remove `document.attachEvent` code from `web/pdf_print_service.js` since it's only necessary for old IE versions
2019-11-22 22:54:55 +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
Tim van der Meij
96c595411a
Merge pull request #11350 from Snuffleupagus/_pagesRequests-WeakMap
Convert `{BaseViewer, PDFThumbnailViewer}._pagesRequests` from an Array to a WeakMap
2019-11-21 23:41:54 +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
Tim van der Meij
026121286c
Merge pull request #11346 from Snuffleupagus/pageViewsReady-printing
Ensure that attempting to print with `disableAutoFetch` set will fail gracefully (issue 11339)
2019-11-19 23:46:51 +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
Tim van der Meij
be02e67972
Merge pull request #11335 from Snuffleupagus/issue-11330
Subtract `stream.start` when getting the `startXRef` property for documents with a Linearization dictionary (issue 11330)
2019-11-16 13:56:01 +01:00
Tim van der Meij
789c2c6a7e
Merge pull request #11334 from Snuffleupagus/FlateStream-readBlock-getBytes
Use `getBytes`, rather than looping over `getByte`, in `FlateStream.prototype.readBlock`
2019-11-16 13:50:40 +01:00
Jonas Jenwald
9199b02a42 Subtract stream.start when getting the startXRef property for documents with a Linearization dictionary (issue 11330)
For documents with a Linearization dictionary the computed `startXRef` position will be relative to the raw file, rather than the actual PDF document itself (which begins with `%PDF-`).
Hence it's necessary to subtract `stream.start` in this case, since otherwise the `XRef.readXRef` method will increment the position too far resulting in parsing errors.
2019-11-16 09:29:10 +01:00
Jonas Jenwald
688d15526e Use getBytes, rather than looping over getByte, in FlateStream.prototype.readBlock
*Please note:* A a similar change was attempted in PR 5005, but it was subsequently backed out (in PR 5069) since other parts of the patch caused issues.

With these changes, it's possible to replace repeated function calls within a loop with just a single function call and subsequent assignment instead.
2019-11-15 15:45:31 +01:00
smohtadi
fe6d86fb52 added transform function
added depedencies

removed gulp-transform dependency

removed dependencies

removed gulptransform dependency
2019-11-14 14:45:00 -08:00
Tim van der Meij
f7aafcb218
Merge pull request #11317 from Snuffleupagus/update-npm-packages
Update npm packages
2019-11-12 00:14:00 +01:00
Tim van der Meij
3a05f6fe25
Merge pull request #11318 from Snuffleupagus/IE-polyfill-pushState-replaceState
[PDFHistory] Move the IE11 `pushState`/`replaceState` work-around to `src/shared/compatibility.js` (PR 10461 follow-up)
2019-11-12 00:09:27 +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
f46fd9e306 Fix (some) vulnerabilities reported by npm audit
This was done automatically, using the `npm audit fix` command.
2019-11-11 11:23:17 +01:00
Jonas Jenwald
ae4af9ab58 Update npm packages 2019-11-11 11:22:03 +01:00