Commit Graph

12127 Commits

Author SHA1 Message Date
Jonas Jenwald
34e7d42ce6 Add helper functions to reduce unnecessary duplication when fetching l10n messages in PDFThumbnailView 2020-01-11 14:28:29 +01:00
Jonas Jenwald
16a94412e4 Remove the unused id properties from page and thumbnail canvas/image DOM elements (issue 11499)
As described in the issue, having a DOM element with `id=page2` (or any other number) will automatically cause that element to become linkable through the URL hash. That's currently leading to some confusing and outright wrong behaviour, since it obviously only works for pages that have been loaded and rendered.

For PDF documents the only officially supported way to reference a particular page through the URL hash is using the `#page=2` format, which also works for all pages regardless if they're loaded or not.

As far as I can tell there's nothing in the PDF.js default viewer that actually depends on the page/thumbnail `id` at this point in time, hence why I believe that this removal ought to be safe.
Just as a pre-caution this patch adds an `aria-label` to the page canvas, similar to the thumbnail canvas/image, to at least keep this information in the DOM.
2020-01-11 14:11:47 +01:00
Tim van der Meij
4729fdc0e9
Merge pull request #11488 from Snuffleupagus/web-no-nested-ternary
Enable the `no-nested-ternary` ESLint rule in the `web/` directory
2020-01-08 23:19:26 +01:00
Jonas Jenwald
1ceffac9c5 Enable the no-nested-ternary ESLint rule in the web/ directory
This rule is already enabled in mozilla-central, and helps avoid some confusing formatting[1], see https://searchfox.org/mozilla-central/rev/a92ed79b0bc746159fc31af1586adbfa9e45e264/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js#209-210

Since some cases may not be aren't entirely straightforward to convert, and some we probably don't want to change either[2], this patch is limited to the `web/` directory as a proof-of-concept.

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

---
[1] One example with *three* ternary statements: 93aa613db7/src/core/fonts.js (L2623-L2630)

[2] One example that should be whitelisted: 93aa613db7/src/core/jbig2.js (L82-L92)
2020-01-08 11:56:10 +01:00
Tim van der Meij
93aa613db7
Merge pull request #11465 from Snuffleupagus/import-file-extension
Ensure that all `import` and `require` statements, in the entire code-base, have a `.js` file extension
2020-01-06 23:24:43 +01:00
Tim van der Meij
3772e30f9e
Merge pull request #11474 from Snuffleupagus/pdfjs-dist-rm-dependencies
[api-minor] Remove the Webpack-only npm dependencies from `pdfjs-dist` (PR 11418 follow-up)
2020-01-06 23:07:53 +01:00
Tim van der Meij
049a464372
Merge pull request #11466 from Snuffleupagus/telemetry-generator-parsing
[Firefox] Slightly simplify how the generator is determined, when sending telemetry data from the viewer
2020-01-06 22:55:30 +01:00
Tim van der Meij
f0999d271c
Merge pull request #11472 from Snuffleupagus/license_header_year
Update the year in the `license_header` files
2020-01-06 22:48:09 +01:00
Jonas Jenwald
a0cf67d52f [api-minor] Remove the Webpack-only npm dependencies from pdfjs-dist (PR 11418 follow-up)
Currently *all* users of `pdfjs-dist` are forced to install the `webpack` and `worker-loader` packages, despite the fact that they are *only* relevant if the `webpack.js` file is being used (with a custom Webpack build).
This really doesn't seem great, especially since those packages are the only remaining dependencies in the `pdfjs-dist` library, and it thus seem more reasonable overall that Webpack users handle those dependencies themselves.

To prevent unnecessarily cryptic runtime failures, when people update to newer `pdfjs-dist` versions, the `webpack.js` file was updated to explicitly check for the existence of the `worker-loader` package and error otherwise.
Furthermore, note that `webpack` was only listed as a dependency because of the `worker-loader` package itself (see issue 9248).

Obviously these changes may not be seen as great by Webpack users who rely on `pdfjs-dist`, since it forces them to handle the dependencies themselves, however it should improve things considerably for "general" users of `pdfjs-dist` by not burdening them with unnecessary dependencies.
These sort of changes are also in line with other recent changes, see PR 11418, which removed built-in fake worker loader code for specific JS builders/bundlers/frameworks. This work was prompted not only by a desire to simplify/clean-up old code, but also to lessen future support burden since the PDF.js contributors cannot be assumed to be experts in various JS bundlers.
2020-01-05 20:35:19 +01:00
Jonas Jenwald
94f084958a Update the year in the license_header files 2020-01-05 12:14:03 +01:00
Jonas Jenwald
36881e3770 Ensure that all import and require statements, in the entire code-base, have a .js file extension
In order to eventually get rid of SystemJS and start using native `import`s instead, we'll need to provide "complete" file identifiers since otherwise there'll be MIME type errors when attempting to use `import`.
2020-01-04 13:01:43 +01:00
Jonas Jenwald
299ba44bb9 [Firefox] Slightly simplify how the generator is determined, when sending telemetry data from the viewer
When working on PR 11463 I couldn't help thinking that the `Array.prototype.some` callback function, used when determining the generator, was somewhat difficult to read with its partly unused and strangely named parameters.
2020-01-02 23:29:00 +01:00
Rob Wu
b833f84307
Merge pull request #11463 from Snuffleupagus/bug-1606566
[Firefox] Ensure that telemetry will be correctly recorded even when the PDF header is missing (bug 1606566)
2020-01-01 23:02:42 +01:00
Jonas Jenwald
bee941b0d2 [Firefox] Ensure that telemetry will be correctly recorded even when the PDF header is missing (bug 1606566)
As suggested in the bug we'll now always fallback to "other", which should be fine considering that that value is listed in the histogram definition; see https://searchfox.org/mozilla-central/rev/331f0c3b25089c9a16be65f4dc8c601aeaac8cc4/toolkit/components/telemetry/Histograms.json#9097-9106

Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1606566
2020-01-01 22:23:11 +01:00
Tim van der Meij
10716aab59
Merge pull request #11447 from timvandermeij/css-color-simplifications
Convert all non-RGBA colors to RGBA colors
2020-01-01 15:37:49 +01:00
Tim van der Meij
e3c0181357
Convert all six-digit HEX colors to RGBA colors 2020-01-01 14:52:37 +01:00
Tim van der Meij
403a994556
Convert all three-digit HEX colors to RGBA colors 2020-01-01 14:52:37 +01:00
Tim van der Meij
d002637405
Convert all named colors to RGBA colors 2020-01-01 14:48:56 +01:00
Tim van der Meij
2c2fc36c54
Normalize all RGBA colors
This is not only useful to have one format for consistency, but also to
be able to quickly search for colors for e.g., finding duplicates or
when tweaking the CSS for custom deployments.
2020-01-01 14:48:55 +01:00
Tim van der Meij
dd1c8a9149
Convert all RGB colors to RGBA colors 2020-01-01 14:48:55 +01:00
Tim van der Meij
3717dcdf57
Convert all HSLA colors to RGBA colors 2020-01-01 14:48:55 +01:00
Tim van der Meij
0bdb1ab202
Convert all HSL colors to RGBA colors 2019-12-28 20:54:57 +01:00
Tim van der Meij
3b44861197
Merge pull request #11455 from Snuffleupagus/update-packages
Update `npm` packages and l10n files
2019-12-28 20:35:44 +01:00
Jonas Jenwald
cac953f5a9 Update l10n files 2019-12-28 20:00:03 +01:00
Jonas Jenwald
05129deb00 Update npm packages 2019-12-28 19:57:25 +01:00
Tim van der Meij
a0fe7a77d6
Merge pull request #11454 from Snuffleupagus/move-SegoeUISymbol
Move the SegoeUISymbol font to the `getNonStdFontMap` (PR 8698 follow-up)
2019-12-28 13:37:36 +01:00
Jonas Jenwald
f8ab8c4d3a Move the SegoeUISymbol font to the getNonStdFontMap (PR 8698 follow-up)
For reasons that I now cannot even begin to understand, the non-standard SegoeUISymbol font was placed in the `getStdFontMap`. That honestly makes no sense, hence this patch which does what I *should* have done from the start.
2019-12-28 11:02:49 +01:00
Tim van der Meij
47ab4b839f
Merge pull request #11450 from Snuffleupagus/eslint-web-prefer-const
Enable the ESLint `prefer-const` rule in the `web/` directory
2019-12-27 12:12:51 +01:00
Jonas Jenwald
d9a5d50664 Fix remaining linting errors, from enabling the prefer-const ESLint rule in the web/ directory
This covers the handful of cases that the `--fix` command couldn't deal with, and the changes aren't just fixing the linting errors but attempt to slightly improve the relevant code.
2019-12-27 01:03:58 +01:00
Jonas Jenwald
5d14e68bec Enable the ESLint prefer-const rule in the web/ directory
Please find additional details about the ESLint rule at https://eslint.org/docs/rules/prefer-const

Note that this patch is generated automatically, by using the ESLint `--fix` argument, and will thus require some additional clean-up (which is done separately).
2019-12-27 01:03:58 +01:00
Tim van der Meij
9c767e3875
Merge pull request #11449 from Snuffleupagus/AutoPrintRegExp
Move the regular expression, used with auto printing in the viewer, to `web/ui_utils.js` and also use it in the API unit-tests
2019-12-27 00:53:51 +01:00
Jonas Jenwald
d9d856020f Move the regular expression, used with auto printing in the viewer, to web/ui_utils.js and also use it in the API unit-tests
Rather than having a copy of this regular expression in the `test/unit/api_spec.js` file, with a comment about keeping it up-to-date with the code in the viewer (note the incorrect file reference as well), we can just import it instead to simplify all of this.
2019-12-27 00:38:28 +01:00
Tim van der Meij
db8fcdf34a
Merge pull request #11445 from timvandermeij/openaction-print-unit-test
Include a unit test for OpenAction dictionaries without `Type` entries (PR 11443 follow-up)
2019-12-27 00:19:42 +01:00
Tim van der Meij
dfe42a5ca4
Include a unit test for OpenAction dictionaries without Type entries (PR 11443 follow-up)
The original issue did not contain a (reduced) test case that we could
include and linked test cases are not ideal for unit tests, so the
original PR could only be verified manually.

I found this a bit unfortunate considering that the print data is
exposed through the API, so I thought about how we could have an
automated test and managed to create a reduced test case with the
OpenAction dictionary from the file in the original issue.

Therefore, this commit includes a unit test for parsing OpenAction
dictionaries without `Type` entries. I verified that this PDF file
behaves the same as the original one, i.e., no print dialog is shown for
older viewers and the print dialog is shown for the most recent viewer.
2019-12-27 00:05:51 +01:00
Tim van der Meij
81af207428
Merge pull request #11446 from Snuffleupagus/prettier
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
2019-12-26 23:35:56 +01:00
Jonas Jenwald
a63f7ad486 Fix the linting errors, from the Prettier auto-formatting, that ESLint --fix couldn't handle
This patch makes the follow changes:
 - Remove no longer necessary inline `// eslint-disable-...` comments.
 - Fix `// eslint-disable-...` comments that Prettier moved down, thus causing new linting errors.
 - Concatenate strings which now fit on just one line.
 - Fix comments that are now too long.
 - Finally, and most importantly, adjust comments that Prettier moved down, since the new positions often is confusing or outright wrong.
2019-12-26 12:35:12 +01:00
Jonas Jenwald
de36b2aaba Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).

Prettier is being used for a couple of reasons:

 - To be consistent with `mozilla-central`, where Prettier is already in use across the tree.

 - To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.

Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.

*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.

(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-26 12:34:24 +01:00
Jonas Jenwald
8ec1dfde49 Add // prettier-ignore comments to prevent re-formatting of certain data structures
There's a fair number of (primarily) `Array`s/`TypedArray`s whose formatting we don't want disturb, since in many cases that would lead to the code becoming much more difficult to read and/or break existing inline comments.

*Please note:* It may be a good idea to look through these cases individually, and possibly re-write some of the them (especially the `String` ones) to reduce the need for all of these ignore commands.
2019-12-26 00:14:03 +01:00
Tim van der Meij
c3a1c67950
Merge pull request #11443 from Snuffleupagus/issue-11442
Support OpenAction dictionaries without `Type` entries when parsing `Print` actions (issue 11442)
2019-12-24 23:17:37 +01:00
Tim van der Meij
11b56ad0f7
Merge pull request #11423 from Snuffleupagus/bug-1605526
Ignore Metadata entries with incorrectly encoded characters, when setting the viewer title (bug 1605526)
2019-12-24 22:44:31 +01:00
Tim van der Meij
c54bdab4aa
Merge pull request #11432 from wojtekmaj/preferences-const
Use const in perferences.js
2019-12-24 19:43:42 +01:00
Tim van der Meij
0f641e66cc
Merge pull request #11433 from wojtekmaj/pdf-thumbnail-viewer-const
Use const in pdf_thumbnail_viewer.js
2019-12-24 19:31:34 +01:00
Jonas Jenwald
70e3345cb4 Support OpenAction dictionaries without Type entries when parsing Print actions (issue 11442)
The PDF generator didn't bother including the `Type` entry in the OpenAction dictionary, hence we skipped parsing the `Print` action.
2019-12-24 10:41:33 +01:00
Tim van der Meij
1a708d8993
Merge pull request #11430 from wojtekmaj/text-layer-builder-const
Use const in text_layer_builder.js
2019-12-24 00:09:51 +01:00
Tim van der Meij
a6188a5c98
Merge pull request #11431 from wojtekmaj/secondary-toolbar-const
Use const in secondary_toolbar.js
2019-12-24 00:03:58 +01:00
Tim van der Meij
bcf8ae3527
Merge pull request #11437 from wojtekmaj/create-headers
Extract & use createHeaders helper
2019-12-23 23:55:34 +01:00
Tim van der Meij
32c3434c31
Merge pull request #11440 from Snuffleupagus/stats-pdfBug-tweak-test
Tweak the "gets page stats after rendering page, with `pdfBug` set" unit-test to remove an intermittent failure on Travis
2019-12-23 23:44:55 +01:00
Tim van der Meij
934d7cbc23
Merge pull request #11436 from wojtekmaj/npm-audit-fix
Update webpack-stream to fix vulnerabiliy reported by npm and dedupe Webpack
2019-12-23 23:41:25 +01:00
Jonas Jenwald
b4d95f3763 Tweak the "gets page stats after rendering page, with pdfBug set" unit-test to remove an intermittent failure on Travis
I recently noticed a couple of intermittent failures on Travis, hence this patch which changes the expectation to be identical to the 'Page Request' check in the preceding test-case.
2019-12-23 23:07:02 +01:00
Tim van der Meij
b5281e56c8
Merge pull request #11429 from wojtekmaj/toolbar-const
Use const in toolbar.js
2019-12-23 22:42:06 +01:00