Commit Graph

12477 Commits

Author SHA1 Message Date
Tim van der Meij
fd80bc8178
Merge pull request #11890 from Snuffleupagus/eslint-7
Update ESLint to version 7
2020-05-11 23:11:08 +02:00
Jonas Jenwald
9118cea9f7 Enable the ESLint default-case-last rule, and tweak the existing use-isnan rule
These changes were made possible by ESLint version 7, and neither of these rules required any code changes.

Please find additional details about the ESLint rules at https://eslint.org/docs/rules/default-case-last and https://eslint.org/docs/rules/use-isnan
2020-05-10 11:33:44 +02:00
Jonas Jenwald
f8bff283f3 Update ESLint to version 7
Please see https://eslint.org/blog/2020/05/eslint-v7.0.0-released for a list of notable changes.
2020-05-10 11:32:46 +02:00
Tim van der Meij
1ee63dc465
Merge pull request #11889 from Snuffleupagus/_parsedAnnotations-move-catch
Handle errors individually for each annotation in the `_parsedAnnotations` getter
2020-05-10 00:22:13 +02:00
Jonas Jenwald
73636e052a Handle errors individually for each annotation in the _parsedAnnotations getter
While working on PR 11872, it occurred to me that it probably wouldn't be a bad idea to change the `_parsedAnnotations` getter to handle errors individually for each annotation. This way, one broken/corrupt annotation won't prevent the rest of them from being e.g. fetched through the API.
2020-05-09 12:33:39 +02:00
Tim van der Meij
7823d593f9
Merge pull request #11880 from Snuffleupagus/issue-11875
Attempt to respect the "zoom" hash parameter, even when the "nameddest" parameter is present (issue 11875)
2020-05-08 23:42:12 +02:00
Tim van der Meij
bf2ce760f0
Merge pull request #11873 from Snuffleupagus/eslint-assert
Use the ESLint `no-restricted-syntax` rule to ensure that `assert` is always called with two arguments
2020-05-08 00:01:30 +02:00
Tim van der Meij
9c341cfec6
Merge pull request #11879 from Snuffleupagus/eslint-grouped-accessor-pairs
Enable the ESLint `grouped-accessor-pairs` rule
2020-05-07 23:53:26 +02:00
Jonas Jenwald
af1bb04662 Attempt to respect the "zoom" hash parameter, even when the "nameddest" parameter is present (issue 11875)
Given that the `PDFLinkService.setHash` method itself if completely synchronous, moving the handling of "nameddest" to occur last *shouldn't* cause any problems (famous last words).
This way the destination will still override any previous parameter, such as e.g. the "page", as expected. Furthermore, given that the `PDFLinkService.navigateTo` method is asynchronous that should provide additional guarantees that the "nameddest" parameter is always respected.

As sort-of expected, this fairly innocent looking change also required some tweaks in the `PDFHistory` to prevent dummy history entires upon document load (only an issue when both "page" *and* "nameddest" parameters are provided in the hash).
2020-05-07 13:53:07 +02:00
Jonas Jenwald
744af9eeb8 Enable the ESLint grouped-accessor-pairs rule
This rule complements the existing `accessor-pairs` nicely, and ensures that a getter/setter pair is always consistently ordered.

Please find additional details about this rule at https://eslint.org/docs/rules/grouped-accessor-pairs
2020-05-07 11:43:19 +02:00
Jonas Jenwald
e1f340a0c2 Use the ESLint no-restricted-syntax rule to ensure that assert is always called with two arguments
Having `assert` calls without a message string isn't very helpful when debugging, and it turns out that it's easy enough to make use of ESLint to enforce better `assert` call-sites.
In a couple of cases the `assert` calls were changed to "regular" throwing of errors instead, since that seemed more appropriate.

Please find additional details about the ESLint rule at https://eslint.org/docs/rules/no-restricted-syntax
2020-05-05 13:40:05 +02:00
Tim van der Meij
491904d30a
Merge pull request #11872 from Snuffleupagus/issue-11871
Gracefully handle annotation parsing errors in `Page.getOperatorList` (issue 11871)
2020-05-04 22:19:27 +02:00
Tim van der Meij
c32f145c94
Merge pull request #11863 from brendandahl/unsupported-features
Add more categories of unsupported features.
2020-05-04 22:09:13 +02:00
Brendan Dahl
b1be33c96f Add more categories of unsupported features.
Fixes #11815
2020-05-04 11:02:16 -07:00
Jonas Jenwald
4aabd063fc Gracefully handle annotation parsing errors in Page.getOperatorList (issue 11871)
This should ensure that a page will always render successfully, even if there's errors during the Annotation fetching/parsing.
Additionally the `OperatorList.addOpList` method is also adjusted to ignore invalid data, to make it slightly more robust.
2020-05-04 17:09:48 +02:00
Tim van der Meij
2711f4bc8c
Merge pull request #11869 from Snuffleupagus/gulpfile-cleanup
Various smaller clean-up in `gulpfile.js`
2020-05-03 16:14:16 +02:00
Jonas Jenwald
a9e7798ac6 Split the createBundle helper function, in gulpfile.js, into separate ones for the main/worker-thread files
All of the other *similar* helper functions only target one file per function, and there's no particular reason for this one to be different.
This patch will simplify future changes, e.g. experimenting with using `gulp watch` instead of SystemJS for the development viewer.
2020-05-03 11:34:08 +02:00
Jonas Jenwald
21495c1dd1 Remove the gulp bundle task since it's unused and doesn't really make sense
Not only is there no code depending on it now, the actual task itself doesn't even make sense as-is. Note that it uses the default `DEFINES` configuration *unaltered*, which is neither useful nor correct since the resulting build thus won't make sense without an actual built target set.
2020-05-03 11:34:02 +02:00
Tim van der Meij
d822578450
Merge pull request #11868 from Snuffleupagus/update-packages
Update packages and translations
2020-05-02 14:52:12 +02:00
Jonas Jenwald
30bd3b24c2 Update l10n files 2020-05-02 13:25:28 +02:00
Jonas Jenwald
8fac59de96 Update npm packages 2020-05-02 13:23:41 +02:00
Tim van der Meij
822939cace
Merge pull request #11864 from Snuffleupagus/rm-react-example
Remove the `create-react-app` example (issue 11729)
2020-05-01 23:52:41 +02:00
Jonas Jenwald
3dc0567a37 Remove the create-react-app example (issue 11729)
Given that none of the PDF.js contributors know React, maintaining and/or providing supporting for the example isn't really feasible unfortunately.
Even something as simple as running/testing the example becomes difficult for anyone completely unfamiliar with React, and furthermore:

 - It's very difficult to tell if the example demonstrates React best-practices, since the PDF.js contributors don't know React.

 - We also have no reasonable way of keeping the example up-to-date with changes in React.

 - The React example, in its current form, is even *hard-coding* the PDF.js version to a now unsupported version.

 - The example is currently triggering "fake worker" usage, see issue 11729, which is really *really* bad. Note that the "fake worker" functionality is *only* intended as a fallback, and it should absolutely *not* under any circumstances be advertised and certainly shouldn't be triggered in official PDF.js examples.
2020-05-01 12:42:35 +02:00
Tim van der Meij
b6f69d47b6
Merge pull request #11834 from xelan/feature/preserve-error-types
Preserve error types during translation
2020-04-28 23:47:24 +02:00
Andreas Erhard
f5fd24a61f Preserve error types during translation
By preserving the exception type, more fine-grained error handling can be performed via client-side logic (e.g. redirect to a search page if a PDF is not found, or to a ticket system in case of invalid PDF files).

The original exception is now re-thrown.

Fixes #11658
2020-04-28 09:36:30 +02:00
Tim van der Meij
8fb82e939c
Merge pull request #11853 from timvandermeij/acroform-names
Include the name for interactive form elements
2020-04-27 17:05:06 +02:00
roccobeno
371e699905
Include the name for interactive form elements
We already rendered the name for radio buttons, but it was missing for
all other interactive form elements. This commit adds that so that
values entered in form elements can be read based on the element name.
2020-04-27 16:55:35 +02:00
Tim van der Meij
d469b420a7
Merge pull request #11807 from timvandermeij/puppeteer
Introduce Puppeteer for handling browsers during tests
2020-04-27 13:39:30 +02:00
Tim van der Meij
9ebb18f505
Implement a command line flag to skip Chrome when running tests
To save time or resources during development it can be useful to run
tests only in Firefox. Previously this could be done by editing the
browser manifest file, but since that file is no longer used for
Puppeteer, this command line flag replaces it. For example, executing
`gulp unittest --noChrome` will only run the unit tests in Firefox.
2020-04-27 13:03:12 +02:00
Tim van der Meij
4834a276fd
Introduce Puppeteer for handling browsers during tests
This commit replaces our own infrastructure for handling browsers during
tests with Puppeteer. Using our own infrastructure for this had a few
downsides:

- It has proven to not always be reliable, especially when closing the
  browser, causing failures on the bots because browsers were still
  running even though they should have been stopped. Puppeteer should do
  a better job with this because it uses the browser's test built-in
  instrumentation tools for this (the devtools protocol) which our code
  didn't. This also means that we don't have to pass
  parameters/preferences to tweak browser behavior anymore.
- It requires the browsers under test to be installed on the system,
  whereas Puppeteer downloads the browsers before the test. This means
  that setup is much easier (no more manual installations and browser
  manifest files) as well as testing with different browser versions
  (since they can be provisioned on demand). Moreover, this ensures that
  contributors always run the tests in both Firefox and Chrome,
  regardless of which browsers they have installed locally.
- It's all code we have to maintain, so Puppeteer abstracts away how the
  browsers start/stop for us so we don't have to keep that code.

By default, Puppeteer only installs one browser during installation,
hence the need for a post-install script to install the second browser.
This requires `cross-env` to make passing the environment variable work
on both Linux and Windows.
2020-04-27 13:03:12 +02:00
Tim van der Meij
d86720b7dc
Identify browsers using the name instead of the path
The other testing code already uses the name of the browser as the
unique identifier, so I don't see a good reason to not use that for
identifying browsers to quit as well. Doing so simplifies the (already
somewhat complex) testing logic and ensures that we can use existing
functionality (such as the `getSession` function) to retrieve sessions.
2020-04-26 14:42:17 +02:00
Tim van der Meij
bf416db23d
Merge pull request #11847 from Snuffleupagus/move-maybeValidDimensions
Move the `maybeValidDimensions` check, used with JPEG images, to occur earlier (PR 11523 follow-up)
2020-04-26 13:39:33 +02:00
Jonas Jenwald
911c33f025 Move the maybeValidDimensions check, used with JPEG images, to occur earlier (PR 11523 follow-up)
Given that the `NativeImageDecoder.{isSupported, isDecodable}` methods require both dictionary lookups *and* ColorSpace parsing, in hindsight it actually seems more reasonable to the `JpegStream.maybeValidDimensions` checks *first*.
2020-04-26 12:07:46 +02:00
Tim van der Meij
7363308b97
Merge pull request #11845 from Snuffleupagus/less-createObjectURL
Use the native `URL.createObjectURL` method more in the `web/` folder
2020-04-24 23:12:37 +02:00
Jonas Jenwald
fd9f3d7d5e Let PDFAttachmentViewer._bindPdfLink fallback to downloading the PDF file, when opening the blobUrl fails
This is a simple work-around for https://bugzilla.mozilla.org/show_bug.cgi?id=1632644 which was caused by platform changes in Firefox. Ideally the Firefox bug should still be fixed, but these PDF.js changes seem generally useful to prevent both current and future issues here.
2020-04-24 13:27:19 +02:00
Jonas Jenwald
cd666e3a37 Use the native URL.createObjectURL method in web/pdf_attachment_viewer.js
There's no particular reason for using the PDF.js helper function `createObjectURL` here, given that the relevant code-path is already guarded by multiple "disableCreateObjectURL" option checks.
2020-04-24 11:51:08 +02:00
Jonas Jenwald
0baabf69db Use the native URL.createObjectURL method more in web/firefoxcom.js
Given that `URL.createObjectURL` is assumed to always be available in MOZCENTRAL builds, note the existing usage in the file, there's no reason to depend on the PDF.js helper function `createObjectURL` at all here.

Furthermore this patch also changes `DownloadManager.downloadData` to actually revoke the `blobUrl` after downloading has completed, which is similar to the existing code in `DownloadManager.download`.
2020-04-24 11:29:33 +02:00
Tim van der Meij
cd2878755b
Merge pull request #11844 from Snuffleupagus/API-release-font-data
[api-minor] Immediately release the `font.data` property once the font been attached to the DOM (PR 11777 follow-up)
2020-04-24 00:11:25 +02:00
Tim van der Meij
e23d5f6022
Merge pull request #11837 from Snuffleupagus/webviewerloaded-top
Always attempt to dispatch the "webviewerloaded" event at the embedding `document` (PR 10318 follow-up, issue 11829)
2020-04-23 23:56:50 +02:00
Jonas Jenwald
c355f91d2e [api-minor] Immediately release the font.data property once the font been attached to the DOM (PR 11777 follow-up)
*This patch implements https://github.com/mozilla/pdf.js/pull/11777#issuecomment-609741348*

This extends the work from PR 11773 and 11777 further, by immediately releasing the `font.data` property once the font been attached to the DOM. By not unnecessarily holding onto this data on the main-thread, we'll thus reduce the memory usage of fonts even further (especially beneficial in longer documents with composite fonts).

The new behaviour is controlled by the recently added `fontExtraProperties` API option (adding a new option just for this patch didn't seem necessary), since there's one edge-case in the SVG renderer where the `font.data` property is necessary (see the `pdf2svg` example).

Note that while the default viewer does run clean-up with an idle timeout, that timeout will be reset whenever rendering occurs *or* when scrolling happens in the viewer. In practice this means that unless the user doesn't interact with the viewer in *any* way during an extended period of time, currently set to 30 seconds, the `PDFDocumentProxy.cleanup` method will never be called and font resources will thus not be cleaned-up.
2020-04-23 13:04:57 +02:00
Tim van der Meij
c8feea6990
Merge pull request #11835 from Snuffleupagus/PageViewport-rotation-validation
[api-minor] Change `PageViewport` to throw when the `rotation` is not a multiple of 90 degrees
2020-04-22 23:49:13 +02:00
Tim van der Meij
6ec42061a0
Merge pull request #11831 from Snuffleupagus/Travis-Node-LTS
Use Node LTS releases to fix Travis CI builds (issue 10790)
2020-04-22 23:45:43 +02:00
Jonas Jenwald
479173ce45 Always attempt to dispatch the "webviewerloaded" event at the embedding document (PR 10318 follow-up, issue 11829)
This is necessary in order to support cases where the default viewer is embedded in a *dynamically* created <iframe> element.

In order to also support a use-case where there's *multiple* <iframe> elements (containing default viewers) on the same page, the "webviewerloaded" event now includes a `source` detail parameter such that it's possible to associate an event with the relevant DOM element.
2020-04-22 22:52:20 +02:00
Jonas Jenwald
cdc60402f6 [api-minor] Change PageViewport to throw when the rotation is not a multiple of 90 degrees
As evident from the code, `PageViewport` only supports[1] `rotation` values which are a multiple of 90 degrees. Besides it being somewhat difficult to imagine meaningful use-cases for a non-multiple of 90 degrees `rotation`, the code also becomes both simpler and more efficient by not having to consider arbitrary `rotation` values.

However, any invalid rotation will *silently* fallback to assume zero `rotation` which probably isn't great for e.g. `PDFPageProxy.getViewport` in the API. Hence this patch, which will now enforce that only valid `rotation` values are accepted.

---
[1] As far as I can tell, from looking through the history, nothing else has ever been supported either.
2020-04-22 15:19:13 +02:00
Jonas Jenwald
0874b49302 Use Node LTS releases to fix Travis CI builds (issue 10790)
Hopefully we don't need the *latest* Node.js releases for the unit-tests to work on Travis, and by using "long-term support" releases instead we should be able to avoid these types of sudden failures in the future as well.
2020-04-22 00:06:27 +02:00
Tim van der Meij
571f287983
Merge pull request #11825 from Snuffleupagus/extensions-viewer-less-AppOptions-lookup
Avoid reading the "disablePreferences"/"locale" options, when initializing the viewer, in extension builds
2020-04-21 23:31:52 +02:00
Tim van der Meij
a13db5d91a
Merge pull request #11823 from Snuffleupagus/validateOS2Table-improvement
[src/core/fonts.js] Improve the `validateOS2Table` function and other code
2020-04-21 00:20:46 +02:00
Tim van der Meij
f243f0564e
Merge pull request #11826 from Snuffleupagus/issue-11657
Change the "download" keyboard shortcut (Ctrl+S) handling, in GENERIC/CHROME builds, to utilize the `EventBus` (issue 11657); add a new "openfile" keyboard shortcut (Ctrl+O), in GENERIC builds
2020-04-21 00:15:14 +02:00
Jonas Jenwald
5733d9dd24 Add a new "openfile" keyboard shortcut (Ctrl+O), in GENERIC builds
Somewhat surprisingly, despite the GENERIC viewer implementing "openfile" support, there's never been a keyboard shortcut available. Similar to the previous patch, this utilizes the `EventBus` for consistency with the `Toolbar`/`SecondaryToolbar` buttons.

*Please note:* This patch should NOT be construed as carte blanche to simply convert all of the code in `webViewerKeyDown`, or elsewhere, to make use of the `EventBus` instead of direct function calls.
Any further changes, along the lines in this patch, would need to be evaluated on a case-by-case basis to determine if they are actually wanted, given that many/most existing cases in `webViewerKeyDown` should already be *indirectly* observable through the `EventBus` instance.
2020-04-20 17:15:44 +02:00
Jonas Jenwald
a8a22283c3 Change the "download" keyboard shortcut (Ctrl+S) handling, in GENERIC/CHROME builds, to utilize the EventBus (issue 11657)
This improves the consistency of the "download" handling, in the default viewer, such that the `Toolbar`/`SecondaryToolbar` buttons *and* the keyboard shortcut are now handled in the same way (using the `EventBus`).

Given that the "download" keyboard shortcut handling is limited to GENERIC/CHROME builds and that the issue does raise a valid point about only being able to observe *some* downloads, these changes seem acceptable in this particular case.

Finally the pre-processor condition is adjusted to *explicitly*, rather than implicitly, list the affected build targets.

*Please note:* This patch should NOT be construed as carte blanche to simply convert all of the code in `webViewerKeyDown`, or elsewhere, to make use of the `EventBus` instead of direct function calls.
Any further changes, along the lines in this patch, would need to be evaluated on a case-by-case basis to determine if they are actually wanted, given that many/most existing cases in `webViewerKeyDown` should already be *indirectly* observable through the `EventBus` instance.
2020-04-20 17:11:30 +02:00