Commit Graph

11502 Commits

Author SHA1 Message Date
Tim van der Meij
e53877f372
Merge pull request #10392 from Snuffleupagus/checkFirstPage
Check that the first page can be successfully loaded, to try and ascertain the validity of the XRef table (issue 7496, issue 10326)
2018-12-29 15:13:19 +01:00
Jonas Jenwald
60bcce184e Check that the first page can be successfully loaded, to try and ascertain the validity of the XRef table (issue 7496, issue 10326)
For PDF documents with sufficiently broken XRef tables, it's usually quite obvious when you need to fallback to indexing the entire file. However, for certain kinds of corrupted PDF documents the XRef table will, for all intents and purposes, appear to be valid. It's not until you actually try to fetch various objects that things will start to break, which is the case in the referenced issues[1].

Since there's generally a real effort being in made PDF.js to load even corrupt PDF documents, this patch contains a suggested approach to attempt to do a bit more validation of the XRef table during the initial document loading phase.

Here the choice is made to attempt to load the *first* page, as a basic sanity check of the validity of the XRef table. Please note that attempting to load a more-or-less arbitrarily chosen object without any context of what it's supposed to be isn't a very useful, which is why this particular choice was made.
Obviously, just because the first page can be loaded successfully that doesn't guarantee that the *entire* XRef table is valid, however if even the first page fails to load you can be reasonably sure that the document is *not* valid[2].

Even though this patch won't cause any significant increase in the amount of parsing required during initial loading of the document[3], it will require loading of more data upfront which thus delays the initial `getDocument` call.
Whether or not this is a problem depends very much on what you actually measure, please consider the following examples:

```javascript
console.time('first');
getDocument(...).promise.then((pdfDocument) => {
  console.timeEnd('first');
});

console.time('second');
getDocument(...).promise.then((pdfDocument) => {
  pdfDocument.getPage(1).then((pdfPage) => { // Note: the API uses `pageNumber >= 1`, the Worker uses `pageIndex >= 0`.
    console.timeEnd('second');
  });
});
```

The first case is pretty much guaranteed to show a small regression, however the second case won't be affected at all since the Worker caches the result of `getPage` calls. Again, please remember that the second case is what matters for the standard PDF.js use-case which is why I'm hoping that this patch is deemed acceptable.

---
[1] In issue 7496, the problem is that the document is edited without the XRef table being correctly updated.
In issue 10326, the generator was sorting the XRef table according to the offsets rather than the objects.

[2] The idea of checking the first page in particular came from the "standard" use-case for the PDF.js library, i.e. the default viewer, where a failure to load the first page basically means that nothing will work; note how `{BaseViewer, PDFThumbnailViewer}.setDocument` depends completely on being able to fetch the *first* page.

[3] The only extra parsing is caused by, potentially, having to traverse *part* of the `Pages` tree to find the first page.
2018-12-29 12:47:25 +01:00
Tim van der Meij
d3868e1bd1
Merge pull request #10376 from timvandermeij/chunked-stream
Convert `src/core/chunked_stream.js` to ES6 syntax
2018-12-25 15:28:00 +01:00
Tim van der Meij
360c3d3813
Remove the unused url argument for the ChunkedStreamManager class 2018-12-24 13:14:42 +01:00
Tim van der Meij
47344197f4
Convert src/core/chunked_stream.js to ES6 syntax 2018-12-24 13:14:42 +01:00
Tim van der Meij
2e05827b87
Merge pull request #10378 from Snuffleupagus/issue-10377
Update remaining examples, and docs, to utilize current API functionality (issue 10377)
2018-12-24 13:13:10 +01:00
Jonas Jenwald
9962ab66ab Update remaining examples, and docs, to utilize current API functionality (issue 10377)
This contains a couple of changes that I missed elsewhere, sorry about that!
2018-12-24 12:33:39 +01:00
Tim van der Meij
103f4616ac
Merge pull request #10334 from Snuffleupagus/OpenAction-dest
[api-minor] Add support for OpenAction destinations (issue 10332)
2018-12-23 20:49:50 +01:00
Tim van der Meij
74461b0aa4
Merge pull request #10375 from timvandermeij/updates
Update translations and packages
2018-12-22 16:42:23 +01:00
Tim van der Meij
18bac1b4fc
Update packages 2018-12-22 16:35:34 +01:00
Tim van der Meij
11bf77aca4
Update translations 2018-12-22 15:54:42 +01:00
Tim van der Meij
98b4aff291
Merge pull request #10369 from Snuffleupagus/getViewport-signature
[api-minor] Change the `getViewport` method, on `PDFPageProxy`, to take a parameter object rather than a bunch of (randomly) ordered parameters
2018-12-22 14:56:16 +01:00
Jonas Jenwald
f0719ed565 [api-minor] Change the getViewport method, on PDFPageProxy, to take a parameter object rather than a bunch of (randomly) ordered parameters
If, as PR 10368 suggests, more parameters should be added to `getViewport` I think that it would be a mistake to not change the signature *first* to avoid needlessly unwieldy call-sites.

To not break any existing code and third-party use-cases, this is obviously implemented with a deprecation warning *and* with a working fallback[1] for the old method signature.

---
[1] This is limited to `GENERIC` builds, which should be sufficient.
2018-12-21 11:55:20 +01:00
Jonas Jenwald
a7e70a50f5 Add OpenAction destination support, off by default, to the viewer
Given that it's really not clear to me if this is actually desired functionality in the default viewer, and considering that it doesn't fit in *great* with the way that `PDFHistory` is initialized, this feature is currently off by default[1].

---
[1] It's controlled with the `disableOpenActionDestination` Preference/AppOption.
2018-12-19 11:45:17 +01:00
Jonas Jenwald
b05f053287 [api-minor] Add support for OpenAction destinations (issue 10332)
Note that the OpenAction dictionary may contain other information besides just a destination array, e.g. instructions for auto-printing[1].
Given first of all that an arbitrary `Dict` cannot be sent from the Worker (since cloning would fail), and second of all that the data obviously needs to be validated, this patch purposely only adds support for fetching a destination from the OpenAction entry[2].

---
[1] This information is, currently in PDF.js, being included through the `getJavaScript` API method.

[2] This significantly reduces the complexity of the implementation, which seems fine for now. If there's ever need for other kinds of OpenAction to be fetched, additional API methods could/should be implemented as necessary (could e.g. follow the `getOpenActionWhatever` naming scheme).
2018-12-19 11:45:16 +01:00
Jonas Jenwald
ba2edeae18 [api-minor] Add support, in getMetadata, for custom information dictionary entries (issue 5970, issue 10344) (#10346)
The custom entries, provided that they exist *and* that their types are safe to include, are exposed through a new `Custom` infoDict entry to clearly separate them from the standard ones.

Fixes 5970.
Fixes 10344.
2018-12-18 23:26:02 +01:00
Thiago da Silva
811c8803b3 Fix small visual quirk in thumbnail viewer 2018-12-18 22:48:26 +01:00
Tim van der Meij
417c234c1c
Merge pull request #10266 from timvandermeij/gulp-4
Upgrade to Gulp 4
2018-12-17 17:00:51 +01:00
Tim van der Meij
fa85f86298
Upgrade to Gulp 4
This required the following changes in the Gulpfile:

- Defining a series of tasks is no longer done with arrays, but with the
  `gulp.series` function. The `web` target is refactored to use a
  smaller number of tasks to prevent tasks from running multiple times.
- Getting all tasks must now be done through the task registry.
- Tasks that don't return anything must call `done` upon completion.

Moreover, this upgrade allows us to use the latest Node.js on Travis CI
again.
2018-12-17 16:20:13 +01:00
Tim van der Meij
bc465695d5
Merge pull request #10358 from tsilvap/toggle-sidebar-keybinding
Add keyboard shortcut to toggle sidebar (F4, same as Adobe Reader).
2018-12-16 20:38:13 +01:00
Thiago da Silva
2abea7d7c2 Add keyboard shortcut to toggle sidebar 2018-12-16 13:00:15 -02:00
Tim van der Meij
e716038b12
Merge pull request #10356 from brendandahl/icon-dpi
Use high DPI icons on semi-high DPI screens.
2018-12-15 15:11:40 +01:00
Brendan Dahl
826893e6f4 Use high DPI icons on semi-high DPI screens.
The icons looks really fuzzy on a machine with a device pixel ratio of
1.5. Using the 2x icons looks much better.
2018-12-14 16:27:38 -08:00
Tim van der Meij
74934db910
Merge pull request #10354 from Snuffleupagus/TESTING-no-sourceMaps
Disable source-map generation when running tests
2018-12-13 23:05:04 +01:00
Jonas Jenwald
b60ea67a11 Disable source-map generation when running tests
This should save, a little bit of, time/resources on the bots since source-maps aren't used for anything during testing.
2018-12-13 17:41:27 +01:00
Tim van der Meij
fc607e35de
Merge pull request #10350 from Snuffleupagus/sig-fieldValue-null
Ignore the `fieldValue` for Signature annotations, since they're currently unsupported (issue 10374)
2018-12-12 23:01:53 +01:00
Tim van der Meij
c13a426eed
Merge pull request #10351 from Snuffleupagus/tab-switch-no-wheel-zoom
Attempt to ignore mouse wheel zooming during tab switches (bug 1503412)
2018-12-12 22:50:11 +01:00
Jonas Jenwald
437fb8a8a7 Ignore the fieldValue for Signature annotations, since they're currently unsupported (issue 10374)
Given that Signature (Widget) annotations are currently not supported, since they cannot be validated, simply ignoring the `fieldValue` seems OK for now considering that attempting to blindly include unparsed/unvalidated data isn't very useful.

Fixes 10347.
2018-12-12 18:01:43 +01:00
Jonas Jenwald
5d594885de Attempt to ignore mouse wheel zooming during tab switches (bug 1503412)
This patch re-factors, and extends, the already existing `zoomDisabledTimeout` used during mouse wheel zooming.
Unfortunately I haven't got the required hardware to actually test this patch, but there's a decent chance that it will fix, or at least reduce, the problems reported in https://bugzilla.mozilla.org/show_bug.cgi?id=1503412.
2018-12-12 13:46:47 +01:00
Tim van der Meij
cad0e61262
Merge pull request #10337 from wojtekmaj/turn-on-eslint-in-examples
Turn on ESLint in examples
2018-12-11 23:44:54 +01:00
Tim van der Meij
d9bf3d320f
Merge pull request #10295 from wojtekmaj/eslint-plugin-mozilla-update
Update eslint-plugin-mozilla to ^1.0.1
2018-12-11 23:35:43 +01:00
Wojciech Maj
9e3f7ac7fa Manually fix remaining ESLint errors 2018-12-11 15:23:26 +01:00
Wojciech Maj
ef1f255649 ESLint --fix 2018-12-11 15:23:26 +01:00
Wojciech Maj
80d7ff4912 Turn on ESLint in examples directory, apply examples-specific exceptions 2018-12-11 15:23:26 +01:00
Wojciech Maj
e70a22a854 Update eslint-plugin-mozilla to ^1.0.1 2018-12-11 12:14:06 +01:00
Tim van der Meij
2f4c7e01f5
Merge pull request #10304 from april/master
Add protection against directory traversal attacks
2018-12-10 23:18:30 +01:00
April King
64cb8c6b98
Add protection against directory traversal attacks 2018-12-10 12:59:04 -06:00
Tim van der Meij
45c0197465
Merge pull request #10330 from janpe2/svg-line-width-zero
Handle line width of zero in SVG
2018-12-07 23:34:27 +01:00
Tim van der Meij
5b8c51c1bf
Merge pull request #10340 from Snuffleupagus/history-tryPushCurrentPosition-viewer-modes
Tweak the `PDFHistory._tryPushCurrentPosition` method to work better with the different Scroll/Spread viewer modes
2018-12-07 23:18:00 +01:00
Jonas Jenwald
89e479dd6c Tweak the PDFHistory._tryPushCurrentPosition method to work better with the different Scroll/Spread viewer modes
Given that a larger number of pages may now be visible at once, and importantly that their layout may be non-vertical, one of the conditions should be tweaked to not accidentally miss cases where a page is still visible.

Please note: This patch is based on code-inspection, and the only ill effect occurring without it would be a couple of (near) duplicate history entries in some *rare* edge-cases.
2018-12-07 15:06:58 +01:00
Jani Pehkonen
ddabeb0645 Handle line width of zero in SVG 2018-12-04 16:05:32 +02:00
Tim van der Meij
9a1e51af24
Merge pull request #10323 from Snuffleupagus/unittestcli
Test the code as-is, in Node.js/Travis, rather than its Babel translated version
2018-12-02 14:56:06 +01:00
Jonas Jenwald
08584efdfe Test the code as-is, in Node.js/Travis, rather than its Babel translated version
This patch does three things:

 - Updates the `gulp unittestcli` command, using `gulp lint` as a guide, such that it can be run locally on Windows without any modifications.

 - Updates the `gulp lib` command to support disabling of Babel through the `SKIP_BABEL` environment variable. Note that all other build targets support this mode, and there's no good reason for `lib` to be any different here.

 - Updates the `npm test` command, used in Node.js/Travis, to test the code as-is test. Since modern Node.js versions seem to have no problems with ES6 compatible code in general, we should just test the source code as-is instead (similar to the tests running on the regular bots).
2018-12-02 10:15:27 +01:00
Tim van der Meij
4ff3435517
Merge pull request #10322 from felipeaugustox/patch-1
Remove unuseful variable
2018-12-01 14:44:57 +01:00
Felipe augusto
1a75647a27
Remove unuseful variable
Variable is declared, but never used.
2018-12-01 01:44:18 -02:00
Tim van der Meij
c91f437eaa
Merge pull request #10318 from Snuffleupagus/disablePreferences
In `GENERIC` builds, dispatch a "webviewerloaded" event (from the `webViewerLoad` function) before initializing the viewer
2018-11-30 22:40:10 +01:00
Jonas Jenwald
0dc995c7e0 In GENERIC builds, dispatch a "webviewerloaded" event (from the webViewerLoad function) before initializing the viewer
With the removal of the global `PDFJS` object, in PDF.js version `2.0`, the viewer options are no longer as easily accessible as they previously were (and issues have been filed about this).
In particular, since the viewer files aren't necessarily loaded *immediately*, this means that `PDFViewerApplication`/`PDFViewerApplicationOptions` aren't necessarily available directly. By dispatching an event once all viewer files are loaded but *before* the viewer initialization has run, setting `AppOptions` during load (in custom implementations of the default viewer) should hopefully become a little bit easier[1].

---
[1] In hindsight, this should probably have been implemented when the global `PDFJS` object was removed...
2018-11-30 10:04:30 +01:00
Jonas Jenwald
d9743e462d Replace the OVERRIDES list in PDFViewerApplication._readPreferences with a disablePreferences, in GENERIC builds, `AppOption instead
Rather than having a (somewhat) randomly choosen list of Preferences which `AppOptions` are allowed to override, it makes much more sense to simply add an AppOption to allow custom implementations to ignore Preferences altogether (it's also inline with the AppOption that allows the `ViewHistory` to be bypassed on load).
2018-11-29 11:46:40 +01:00
Tim van der Meij
1cb7cc9bf4
Merge pull request #10300 from timvandermeij/updates-followup
Include forgotten changes after Wintersmith update
2018-11-24 21:54:00 +01:00
Tim van der Meij
e15a9797e3
Include forgotten changes after Wintersmith update
This should have been part of the previous commit that updated the
Wintersmith dependency. Markdown support is no longer included in Pug
itself and should be done by a transformer instead.
2018-11-24 21:39:54 +01:00