Commit Graph

12447 Commits

Author SHA1 Message Date
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
Jonas Jenwald
256aae02d2 Avoid reading the "disablePreferences"/"locale" options, when initializing the viewer, in extension builds
These two `AppOptions` are only defined in GENERIC builds, hence it's completely unnecessary to check them in the extension builds (e.g. MOZCENTRAL and CHROME).

Also, simply let the "printResolution" option be defined in all builds since it's being accessed in `web/firefox_print_service.js` as well.
2020-04-20 13:09:33 +02:00
Jonas Jenwald
695140728a [src/core/fonts.js] Improve the validateOS2Table function
Rather than creating a new `Stream` just to validate the OS/2 TrueType table, it's simpler/better to just pass in a reference to the font data and use that instead (similar to other TrueType helper functions).
2020-04-19 11:25:25 +02:00
Jonas Jenwald
033d27fc25 [src/core/fonts.js] Replace some unnecessary Stream.getUint16() calls with Stream.skip(2) instead
There's a handful of cases in the code where the intention is simply to advance the `Stream` position, but rather than only doing that the code instead fetches/computes a Uint16 value (and without using the result for anything).
2020-04-19 11:18:20 +02:00
Jonas Jenwald
4fae1ac5c4 [src/core/fonts.js] Replace some unnecessary Stream.getBytes(...) calls with Stream.skip(...) instead
There's a handful of cases in the code where the intention is simply to advance the `Stream` position, but rather than only doing that the code instead fetches the bytes in question (and without using the result for anything).
2020-04-19 11:18:15 +02:00
Tim van der Meij
49f59eb627
Merge pull request #11822 from Snuffleupagus/update-packages
Update packages and translations
2020-04-18 14:44:39 +02:00
Jonas Jenwald
cf58f787f1 Update l10n files 2020-04-18 11:11:19 +02:00
Jonas Jenwald
d67c1899b5 Update npm packages 2020-04-18 11:08:46 +02:00
Tim van der Meij
44da021012
Merge pull request #11814 from tamuratak/svg_text_vertical
Support the vertical writing mode with SVG backend.
2020-04-18 00:34:39 +02:00
Tim van der Meij
7b23476e61
Merge pull request #11818 from Snuffleupagus/eslint-dot-notation
Enable the `dot-notation` ESLint rule
2020-04-18 00:19:47 +02:00
Tim van der Meij
c1733d2bcd
Merge pull request #11819 from Snuffleupagus/decodeScan-rm-findNextFileMarker-call
[src/core/jpg.js] Remove redundant marker validation at the end of the `decodeScan` function (PR 11805 follow-up)
2020-04-18 00:10:46 +02:00
Tim van der Meij
2a292c7910
Merge pull request #11821 from timgates42/bugfix_typo_occurrences
docs: Fix simple typo, occurences -> occurrences
2020-04-18 00:04:19 +02:00
Tim Gates
8795a34563
docs: Fix simple typo, occurences -> occurrences
There is a small typo in gulpfile.js, systemjs.config.js.

Should read `occurrences` rather than `occurences`.
2020-04-18 07:53:18 +10:00
Jonas Jenwald
518d26dfb4 [src/core/jpg.js] Remove redundant marker validation at the end of the decodeScan function (PR 11805 follow-up)
With the MCU parsing changes made in PR 11805, the final marker validation is no longer necessary before the `decodeScan` function returns.
2020-04-17 15:40:02 +02:00
Jonas Jenwald
1cc3dbb694 Enable the dot-notation ESLint rule
*Please note:* These changes were done automatically, using the `gulp lint --fix` command.

This rule is already enabled in mozilla-central, see https://searchfox.org/mozilla-central/rev/567b68b8ff4b6d607ba34a6f1926873d21a7b4d7/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js#103-104

The main advantage, besides improved consistency, of this rule is that it reduces the size of the code (by 3 bytes for each case). In the PDF.js code-base there's close to 8000 instances being fixed by the `dot-notation` ESLint rule, which end up reducing the size of even the *built* files significantly; the total size of the `gulp mozcentral` build target changes from `3 247 456` to `3 224 278` bytes, which is a *reduction* of `23 178` bytes (or ~0.7%) for a completely mechanical change.

A large number of these changes affect the (large) lookup tables used on the worker-thread, but given that they are still initialized lazily I don't *think* that the new formatting this patch introduces should undo any of the improvements from PR 6915.

Please find additional details about the ESLint rule at https://eslint.org/docs/rules/dot-notation
2020-04-17 12:24:46 +02:00
Takashi Tamura
32f9cabf82 Support the vertical writing mode with SVG backend. 2020-04-17 09:01:51 +09:00
Tim van der Meij
c218e94f66
Merge pull request #11813 from AndyTeas/patch-1
Suppress browser autofill on page number
2020-04-16 23:32:58 +02:00
AndyTeas
69b3ab4c41
Suppress browser autofill on page number
What the user did:
    Open the PDF Viewer in Chrome;
    Mouse click into the “Page number” input field;

What they saw:
    A pop-up list with seemingly random numbers

What you were expecting to see:
    Nothing

What they see is the Chrome “Autofill” feature at work – that is suggesting values that you have previously entered into number fields in forms, as possible values you may want to enter into this field.  The list has nothing to do with the PDF currently open but the user does not know this.
2020-04-16 09:49:17 +01:00
Tim van der Meij
96923eb2a6
Merge pull request #11805 from Snuffleupagus/issue-11794
Always skip over any additional, unexpected, RSTx (restart) markers in corrupt JPEG images (issue 11794)
2020-04-16 00:08:58 +02:00
Tim van der Meij
a7def05aa1
Merge pull request #11810 from Snuffleupagus/fromCodePoint-followup
A couple of small `String.fromCodePoint` improvements (PR 11698 and 11769 follow-up)
2020-04-16 00:08:16 +02:00
Tim van der Meij
b9cce0e0c1
Merge pull request #11806 from Snuffleupagus/pr-10738-followup
[api-minor] Fix the return value of `PDFDocumentProxy.getViewerPreferences` when no viewer preferences are present (PR 10738 follow-up)
2020-04-15 23:32:08 +02:00
Jonas Jenwald
44b4a74f48 A couple of small String.fromCodePoint improvements (PR 11698 and 11769 follow-up)
- Add a reduced test-case for issue 11768, to prevent future regressions.
   (Given that PR 11769 is only a work-around, rather than a proper solution, it may not be entirely accurate for the issue to be closed as fixed.)

 - Add more validation of the charCode, as found by the heuristics, in `PartialEvaluator._buildSimpleFontToUnicode` to prevent future issues.
2020-04-15 13:45:08 +02:00
Jonas Jenwald
06f6f8719f Always skip over any additional, unexpected, RSTx (restart) markers in corrupt JPEG images (issue 11794) 2020-04-14 23:27:08 +02:00
Jonas Jenwald
26cffd03b0 [src/core/jpg.js] Remove some redundant marker validation during the MCU parsing in the decodeScan function
Some of the code in `src/core/jpg.js` is fairly old, and has with time become unnecessary when the surrounding code has been updated to handle various types of JPEG corruption.
In particular the `if (!marker || marker <= 0xff00) { ... }` branch is now dead code, since:

 - The `!marker` case can no longer happen, since we would already have broken out of the loop thanks to the `!fileMarker` branch a handful of lines above.

 - The `marker <= 0xff00` case can also no longer happen, since the `findNextFileMarker` function validate markers much more thoroughly (by checking `marker >= 0xffc0 && marker <= 0xfffe`). Hence we'd again have broken out of the loop via the `!fileMarker` branch above when no valid marker was found.
2020-04-14 23:27:08 +02:00
Jonas Jenwald
746eaf3154 [api-minor] Fix the return value of PDFDocumentProxy.getViewerPreferences when no viewer preferences are present (PR 10738 follow-up)
This patch fixes yet another instalment in the never-ending series of "what the *bleep* was I thinking", by changing the `PDFDocumentProxy.getViewerPreferences` method to return `null` by default.
Not only is this method now consistent with many other API methods, for the data not present case, but it also avoids having to e.g. loop through an object to check if it's actually empty (note the old unit-test).
2020-04-14 23:25:50 +02:00
Tim van der Meij
50bc4a18e8
Merge pull request #11809 from Snuffleupagus/Prettier-2
Update Prettier to version 2.0
2020-04-14 22:57:23 +02:00
Jonas Jenwald
426945b480 Update Prettier to version 2.0
Please note that these changes were done automatically, using `gulp lint --fix`.

Given that the major version number was increased, there's a fair number of (primarily whitespace) changes; please see https://prettier.io/blog/2020/03/21/2.0.0.html
In order to reduce the size of these changes somewhat, this patch maintains the old "arrowParens" style for now (once mozilla-central updates Prettier we can simply choose the same formatting, assuming it will differ here).
2020-04-14 12:28:14 +02:00
Tim van der Meij
a4dd081d7b
Merge pull request #11800 from Snuffleupagus/rm-gitpod-README
Remove any mention of Gitpod from the README (issue 11732)
2020-04-11 18:56:35 +02:00
Jonas Jenwald
5234c22c29 Remove any mention of Gitpod from the README (issue 11732)
- Since the Gitpod contributing work-flow is, from the PDF.js project perspective, completely unsupported we don't want to mention it in such a highly visible way as the README file.

 - Since Gitpod is a commercial service, we probably want to avoid *potentially* being seen as advertising and/or endorsing it by mentioning it (somewhat prominently) in the PDF.js README file.

 - By leaving the actual Gitpod files in the repository, for now, this should thus avoid outright breaking things for any existing users.
2020-04-11 16:47:27 +02:00
Tim van der Meij
71d16686e4
Merge pull request #11799 from Snuffleupagus/allSettled
Fail early, in modern `GENERIC` builds, if certain required browser functionality is missing (PR 11771 follow-up)
2020-04-11 16:02:19 +02:00
Jonas Jenwald
ecbcde7ff3 Fail early, in modern GENERIC builds, if certain required browser functionality is missing (PR 11771 follow-up)
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, 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 additional checks to ensure that a modern build of PDF.js cannot be used in browsers/environments which lack native support for `Promise.allSettled`.[1] Hence we'll fail early, with an error message telling users to pick an ES5-compatible build instead.

*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).

---
[1] This was a fairly recent addition to the web platform, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled#Browser_compatibility
2020-04-11 13:42:03 +02:00