Commit Graph

12366 Commits

Author SHA1 Message Date
Tim van der Meij
7ed71a0d7c
Merge pull request #11771 from Snuffleupagus/issue-11762
Fail early, in modern `GENERIC` builds, if certain required browser functionality is missing (issue 11762)
2020-04-01 22:05:19 +02:00
Jonas Jenwald
710704508c Fail early, in modern GENERIC builds, if certain required browser functionality is missing (issue 11762)
With two kind of builds now being produced, with/without translation/polyfills, it's unfortunately somewhat easy for users to accidentally pick the wrong one.

In the case where a user would attempt to use a modern build of PDF.js in an older browser, such as e.g. IE11, the failure would be immediate when the code is loaded (given the use of unsupported ECMAScript features).
However in some browsers/environments, in particular Node.js, a modern PDF.js build may load correctly and thus *appear* to function, only to fail for e.g. certain API calls. To hopefully lessen the support burden, and to try and improve things overall, this patch adds checks to ensure that a modern build of PDF.js cannot be used in browsers/environments which lack native support for critical functionality (such as e.g. `ReadableStream`). Hence we'll fail early, with an error message telling users to pick an ES5-compatible build instead.

To ensure that we actually test things better especially w.r.t. usage of the PDF.js library in Node.js environments, the `gulp npm-test` task as used by Node.js/Travis was changed (back) to test an ES5-compatible build.
(Since the bots still test the code as-is, without transpilation/polyfills, this shouldn't really be a problem as far as I can tell.)
As part of these changes there's now both `gulp lib` and `gulp lib-es5` build targets, similar to e.g. the generic builds, which thanks to some re-factoring only required adding a small amount of code.

*Please note:* While it's probably too early to tell if this will be a widespread issue, it's possible that this is the sort of patch that *may* warrant being `git cherry-pick`ed onto the current beta version (v2.4.456).
2020-04-01 19:42:48 +02:00
Tim van der Meij
ce1727626c
Merge pull request #11655 from Snuffleupagus/rm-getGlobalEventBus
[api-minor] Remove the `getGlobalEventBus` viewer functionality, and the `eventBusDispatchToDOM` option/preference (PR 11631 follow-up)
2020-03-31 00:17:30 +02:00
Tim van der Meij
35c9f8de38
Merge pull request #11767 from Snuffleupagus/issue-11766
Replace the RTL images with CSS transforms of the standard images (issue 11766)
2020-03-30 23:53:49 +02:00
Jonas Jenwald
63efe61245 Replace the RTL images with CSS transforms of the standard images (issue 11766)
This avoids unnecessary duplication of many images, thus reducing the size of PDF.js image resources slightly.

Note that since the images should only be flipped horizontally, this required specifying the horizontal/vertical scaling separately for the hiDPI-images.
2020-03-30 22:47:49 +02:00
Jonas Jenwald
664b79abe0 [api-minor] Remove the eventBusDispatchToDOM option/preference, and thus the general ability to dispatch "viewer components" events to the DOM
This functionality was only added to the default viewer for backwards compatibility and to support the various PDF viewer tests in mozilla-central, with the intention to eventually remove it completely.
While the different mozilla-central tests cannot be *easily* converted from DOM events, it's however possible to limit that functionality to only MOZCENTRAL builds *and* when tests are running.

Rather than depending of the re-dispatching of internal events to the DOM, the default viewer can instead be used in e.g. the following way:
```javascript
document.addEventListener("webviewerloaded", function() {
  PDFViewerApplication.initializedPromise.then(function() {
    // The viewer has now been initialized, and its properties can be accessed.

    PDFViewerApplication.eventBus.on("pagerendered", function(event) {
      console.log("Has rendered page number: " + event.pageNumber);
    });
  });
});
```
2020-03-29 12:24:46 +02:00
Jonas Jenwald
7fd5f2dd61 [api-minor] Remove the getGlobalEventBus viewer functionality (PR 11631 follow-up)
The correct/intended way of working with the "viewer components" is by providing an `EventBus` instance upon initialization, and the `getGlobalEventBus` was only added for backwards compatibility.
Note, for example, that using `getGlobalEventBus` doesn't really work at all well with a use-case where there's *multiple* `PDFViewer` instances on a one page, since it may then be difficult/impossible to tell which viewer a particular event originated from.

All of the "viewer components" examples have been previously updated, such that there's no longer any code/examples which relies on the now removed `getGlobalEventBus` functionality.
2020-03-29 12:20:23 +02:00
Tim van der Meij
c12ea21c14
Merge pull request #11755 from Snuffleupagus/rm-fonts-sizes-encoding
Remove the unused `sizes` and `encoding` properties on `Font` instances
2020-03-27 21:44:16 +01:00
Jonas Jenwald
14c999e3ee Remove the unused sizes and encoding properties on Font instances
The `sizes` property doesn't appear to have been used ever since the code was first split into main/worker-threads, which is so many years ago that I wasn't able to easily find exactly in which PR/commit it became unused.

The `encoding` property is always assigned the `properties.baseEncoding` value, however the `PartialEvaluator` doesn't actually compute/set that value any more. Again it was difficult to determine when it became unused, but it's been that way for years.
2020-03-27 10:12:01 +01:00
Tim van der Meij
fa4b431091
Merge pull request #11745 from Snuffleupagus/eslint-no-shadow
Enable the ESLint `no-shadow` rule
2020-03-25 22:48:07 +01:00
Tim van der Meij
ff0f9fd018
Merge pull request #11747 from gdh1995/fix-removing-wheel
Add `passive: false` when removing wheel listeners
2020-03-25 22:37:41 +01:00
Tim van der Meij
8745286dc1
Merge pull request #11646 from Snuffleupagus/_setDocumentAllowFetchPages
Ensure that automatic printing still works when the viewer and/or its pages are hidden (bug 1618621, bug 1618955)
2020-03-25 22:27:19 +01:00
gdh1995
a527eb8c92 Add passive: false when removing wheel listeners
Code of listening `wheel` event uses `{passive: false}`,
while this argument will be treated as `true` before Firefox 49,
accordin to https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Browser_compatibility .

This commit adds it when removing wheel listeners,
so that such listeners can be really removed.
2020-03-25 22:42:27 +08:00
Jonas Jenwald
fdfcde2b40 Remove a spurious console.log from the ChromiumBrowser function in test/webbrowser.js file
This looks entirely like something which was left-over from debugging, and that line hasn't been touched since PR 4515, especially considering that the corresponding branch in `FirefoxBrowser` doesn't print anything.
2020-03-25 11:57:12 +01:00
Jonas Jenwald
dcb16af968 Whitelist closure related cases to address the remaining no-shadow linting errors
Given the way that "classes" were previously implemented in PDF.js, using regular functions and closures, there's a fair number of false positives when the `no-shadow` ESLint rule was enabled.

Note that while *some* of these `eslint-disable` statements can be removed if/when the relevant code is converted to proper `class`es, we'll probably never be able to get rid of all of them given our naming/coding conventions (however I don't really see this being a problem).
2020-03-25 11:57:12 +01:00
Jonas Jenwald
1d2f787d6a Enable the ESLint no-shadow rule
This rule is *not* currently enabled in mozilla-central, but it appears commented out[1] in the ESLint definition file; see https://searchfox.org/mozilla-central/rev/c80fa7258c935223fe319c5345b58eae85d4c6ae/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js#238-239

Unfortunately this rule is, for fairly obvious reasons, impossible to `--fix` automatically (even partially) and each case thus required careful manual analysis.
Hence this ESLint rule is, by some margin, probably the most difficult one that we've enabled thus far. However, using this rule does seem like a good idea in general since allowing variable shadowing could lead to subtle (and difficult to find) bugs or at the very least confusing code.

Please find additional details about the ESLint rule at https://eslint.org/docs/rules/no-shadow

---
[1] Most likely, a very large number of lint errors have prevented this rule from being enabled thus far.
2020-03-25 11:56:05 +01:00
Tim van der Meij
475fa1f97f
Merge pull request #11744 from janpe2/cff-glyph-zero
The first glyph in CFF CIDFonts must be named 0 instead of ".notdef"
2020-03-24 23:52:21 +01:00
Tim van der Meij
292b77fe7b
Merge pull request #11707 from Snuffleupagus/issue-11694
Always prefer the PDF.js JPEG decoder for very large images, in order to reduce peak memory usage (issue 11694)
2020-03-24 23:51:31 +01:00
Tim van der Meij
f85105379e
Merge pull request #11738 from Snuffleupagus/no-shadow-src-core
Remove variable shadowing from the JavaScript files in the `src/core/` folder
2020-03-24 23:10:37 +01:00
Tim van der Meij
c54e773637
Merge pull request #11742 from Snuffleupagus/no-shadow-test-unit
Remove variable shadowing from the JavaScript files in the `test/unit/` folder
2020-03-24 22:44:23 +01:00
Jonas Jenwald
a24ad28d75 Rename BaseViewer._setDocumentViewerElement to BaseViewer._viewerElement
It was pointed out the the old name felt confusing, so let's just rename the getter since it's an internal property anyway.
2020-03-24 16:54:37 +01:00
Jonas Jenwald
c5b0b5c754 Ensure that automatic printing still works when the viewer and/or its pages are hidden (bug 1618621, bug 1618955)
Please note that this patch, on its own, won't magically fix all of these printing bugs without [bug 1618553](https://bugzilla.mozilla.org/show_bug.cgi?id=1618553) also being fixed.
(However I don't foresee that being too difficult, famous last words :-), but it will as suggested require a platform API that we can notify when the viewer is ready.)

Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1618621
Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1618955
Fixes 8208
2020-03-24 16:26:29 +01:00
Jani Pehkonen
a22c0eab48 The first glyph in CFF CIDFonts must be named 0 instead of ".notdef"
Fixes #11718 in which the `ff` ligature glyph is at index zero in a CFF font. Beacuse this is a CIDFont, glyph names are CIDs, which are integers. Thus the string `".notdef"` is not correct. The rest of the charset data is already parsed correctly as integers when the boolean argument `cid` is true.
2020-03-24 15:56:50 +02:00
Jonas Jenwald
66ee8f5acd Remove variable shadowing from the JavaScript files in the test/unit/ folder
*This is part of a series of patches that will try to split PR 11566 into smaller chunks, to make reviewing more feasible.*

Once all the code has been fixed, we'll be able to eventually enable the ESLint no-shadow rule; see https://eslint.org/docs/rules/no-shadow
2020-03-24 10:44:17 +01:00
Tim van der Meij
85838fc505
Merge pull request #11736 from Snuffleupagus/more-wheel-passive
Add `passive: false` to the `wheel` event listener used in `PDFPresentationMode` (issue 11735, PR 10765 follow-up)
2020-03-24 00:12:20 +01:00
Tim van der Meij
404d698dd2
Merge pull request #11734 from Snuffleupagus/rm-throw-methods
Remove old API methods which were previously converted to throwing (PR 11219 follow-up)
2020-03-24 00:06:02 +01:00
Jonas Jenwald
216cbca16c Remove variable shadowing from the JavaScript files in the src/core/ folder
*This is part of a series of patches that will try to split PR 11566 into smaller chunks, to make reviewing more feasible.*

Once all the code has been fixed, we'll be able to eventually enable the ESLint no-shadow rule; see https://eslint.org/docs/rules/no-shadow
2020-03-23 18:28:30 +01:00
Jonas Jenwald
59eada6972 Add passive: false to the wheel event listener used in PDFPresentationMode (issue 11735, PR 10765 follow-up) 2020-03-23 17:07:32 +01:00
Jonas Jenwald
5eabe08c74 Exclude the setPDFNetworkStreamFactory function from the built API docs
Please note that the `setPDFNetworkStreamFactory` functionality isn't exposed in the public API, i.e. not listed among the exports in the `src/pdf.js` file, and that even if it were it wouldn't really be useful considering that none of the `PDFNetworkStream`/`PDFFetchStream`/`PDFNodeStream` classes are exported either.
2020-03-23 16:41:06 +01:00
Jonas Jenwald
c3c197d87a Remove old API methods which were previously converted to throwing (PR 11219 follow-up)
These methods were deprecated already in PDF.js version `2.1.266`, see PRs 10246 and 10369, and were converted to throw `Error`s upon invocation in PDF.js version `2.4.456`, see PR 11219.
Hence it ought to be possible to remove these methods now.
2020-03-23 16:41:03 +01:00
Tim van der Meij
b86df97725
Merge pull request #11725 from Snuffleupagus/app-ViewHistory-init
Re-factor `PDFViewerApplication.load` such that `{PDFViewer, PDFThumbnailViewer}.setDocument` happens slightly earlier
2020-03-22 17:15:44 +01:00
Tim van der Meij
c551c332ec
Merge pull request #11723 from Snuffleupagus/no-shadow-src-display
Remove variable shadowing from the JavaScript files in the `src/display/` folder
2020-03-22 16:38:13 +01:00
Tim van der Meij
066ff62527
Merge pull request #11724 from Snuffleupagus/default_preferences-web-files
Only build the necessary `web/` files during the `gulp default_preferences` task
2020-03-22 16:30:56 +01:00
Tim van der Meij
f53db81c20
Merge pull request #11728 from Snuffleupagus/PDFDocumentProperties-constructor-props
Remove unnecessary checks from the `PDFDocumentProperties` constructor
2020-03-22 16:26:18 +01:00
Jonas Jenwald
d3044ac394 Remove unnecessary checks from the PDFDocumentProperties constructor
Given that none of the relevant options are marked as optional in the code/JSDocs, and that the `PDFDocumentProperties` class is specific to the default viewer (and not exposed as part of the viewer components), there's no good reason as far as I can tell for these checks.
2020-03-22 15:49:41 +01:00
Jonas Jenwald
9f70bca12c Re-factor PDFViewerApplication.load such that {PDFViewer, PDFThumbnailViewer}.setDocument happens slightly earlier
The `BaseViewer.setDocument` method in particular is necessary for rendering to start when the viewer loads, hence you obviously want that to happen as soon as possible and without any unnecessary delays.
Unfortunately *some* API calls need to be done before that, note existing comments, however the `ViewHistory` initialization (and subsequent fetching of data) in particular can be moved slightly without any adverse effects.

As part of testing I've used logging with `performance.now()` inserted in various parts of this code, and there's *obviously* no discernible changes between `master` and this patch for e.g. rendering starting in the viewer.

*Note:* The vast majority of this patch is simple indentation changes, which were forced by Prettier (and done automatically with `gulp lint --fix`).
2020-03-22 10:21:05 +01:00
Jonas Jenwald
08f9718a37 Add a bit more validation in the ViewHistory constructor
- Ensure that `database.files` actually contains an Array, rather than some arbitrary data.

 - Only try to lookup an existing entry when the `database` existed on load, since there's obviously nothing to find when `database.files = []` was set (this case is very common in the MOZCENTRAL build since `sessionStorage` is being used there).
2020-03-21 13:55:06 +01:00
Jonas Jenwald
29ee2590d4 Only build the necessary web/ files during the gulp default_preferences task
By explicitly specifying only the required `web/` files, the runtime of the gulp task is reduced by approximately 30 percent.
2020-03-21 11:34:32 +01:00
Jonas Jenwald
3539a17d2a Remove variable shadowing from the JavaScript files in the src/display/ folder
*This is part of a series of patches that will try to split PR 11566 into smaller chunks, to make reviewing more feasible.*

Once all the code has been fixed, we'll be able to eventually enable the ESLint no-shadow rule; see https://eslint.org/docs/rules/no-shadow
2020-03-20 23:09:41 +01:00
Tim van der Meij
3cebb430c2
Merge pull request #11721 from Snuffleupagus/travis-no-npm-update
Don't let Travis run `npm update` during setup
2020-03-20 21:06:45 +01:00
Tim van der Meij
6ecc9fae1c
Merge pull request #11720 from Snuffleupagus/eslint-no-unsanitized
Update the `eslint-plugin-no-unsanitized` package to the latest version
2020-03-20 21:04:24 +01:00
Tim van der Meij
ab2b2ae30b
Merge pull request #11719 from Snuffleupagus/rm-fonts-widechars
Remove the unused `wideChars` property on `Font` instances
2020-03-20 21:00:09 +01:00
Jonas Jenwald
62a9c26cda Always prefer the PDF.js JPEG decoder for very large images, in order to reduce peak memory usage (issue 11694)
When JPEG images are decoded by the browser, on the main-thread, there's a handful of short-lived copies of the image data; see c3f4690bde/src/display/api.js (L2364-L2408)
That code thus becomes quite problematic for very big JPEG images, since it increases peak memory usage a lot during decoding. In the referenced issue there's a couple of JPEG images whose dimensions are `10006 x 7088` (i.e. ~68 mega-pixels), which causes the *peak* memory usage to increase by close to `1 GB` (i.e. one giga-byte) in my testing.

By letting the PDF.js JPEG decoder, rather than the browser, handle very large images the *peak* memory usage is considerably reduced and the allocated memory also seem to be reclaimed faster.

*Please note:* This will lead to movement in some existing `eq` tests.
2020-03-20 16:37:19 +01:00
Jonas Jenwald
78b1dad2a9 Don't let Travis run npm update during setup
Letting Travis update npm packages can lead to unexpected and completely unrelated failures for any PR and/or merge, see e.g. 11719, if there's ever backwards *incompatible* changes when a package is updated.

The *exact* package versions are specified in `package-lock.json`, and they should thus be used when running tests. Note that the bots won't update npm packages, and neither should Travis as far as I'm concerned.
2020-03-20 15:45:15 +01:00
Jonas Jenwald
b02be3b268 Update the eslint-plugin-no-unsanitized package to the latest version 2020-03-20 11:25:39 +01:00
Jonas Jenwald
1cd9d5a8fd Remove the unused wideChars property on Font instances
This property was added in PR 1599 (almost eight years ago), but has been unused ever since PR 3674 (six and a half years ago).
2020-03-20 10:37:32 +01:00
Tim van der Meij
4893b14a52
Merge pull request #11717 from timvandermeij/bump
Bump versions in `pdfjs.config` and update the getting started page of the website for the new release
2020-03-19 23:14:59 +01:00
Tim van der Meij
1bca1e3823
Update the getting started page of the website for the new release 2020-03-19 23:07:45 +01:00
Tim van der Meij
a94407f983
Bump versions in pdfjs.config 2020-03-19 23:01:17 +01:00
Tim van der Meij
228a591ca3
Merge pull request #11716 from Snuffleupagus/private-PDFPageProxy-pageIndex
[api-minor] Change the pageIndex, on `PDFPageProxy` instances, to a private property
2020-03-19 22:35:29 +01:00