Commit Graph

10212 Commits

Author SHA1 Message Date
Jonas Jenwald
0d58bb5512 Temporarily add the current position to the browser history when the viewer is idle
This patch attempts to address an issue in the old `PDFHistory` implementation, where the current position wouldn't be correctly saved when the browser was closed.
In theory this *should* already be working, however as the discussion in https://bugzilla.mozilla.org/show_bug.cgi?id=1153393 showed, it seems that both `pagehide` and `beforeunload` arrive to late to successfully update the history during closing.

Hence a timeout is used to *temporarily* add the current position to the browser history when the viewer is idle.
Note that we need to take care not to update the browser history too often, since that would render the viewer more or unusable. Furthermore, if the timeout is *too* long it may end up effectively disable this whole functionality.

The `UPDATE_VIEWAREA_TIMEOUT` constant is thus a heuristic value, which we may need to tweak taking the above into account.
2017-08-30 19:45:13 +02:00
Jonas Jenwald
133d06e9a4 Re-write PDFHistory from scratch
This patch completely re-implements `PDFHistory` to get rid of various bugs currently present, and to hopefully make maintenance slightly easier. Most of the interface is similar to the existing one, but it should be somewhat simplified.

The new implementation should be more robust against failure, compared to the old one. Previously, it was too easy to end up in a state which basically caused the browser history to lock-up, preventing the user from navigating back/forward. (In the new implementation, the browser history should not be updated rather than breaking if things go wrong.)

Given that the code has to deal with various edge-cases, it's still not as simple as I would have liked, but it should now be somewhat easier to deal with.
The main source of complication in the code is actually that we allow the user to change the hash of a already loaded document (we'll no longer try to navigate back-and-forth in this case, since the next commit contains a workaround).

In the new code, there's also *a lot* more comments (perhaps too many?) to attempt to explain the logic. This is something that the old implementation was serverly lacking, which is a one of the reasons why it was so difficult to maintain.

One particular thing to note is that the new code uses the `pagehide` event rather than `beforeunload`, since the latter seems to be a bad idea based on https://bugzilla.mozilla.org/show_bug.cgi?id=1336763.
2017-08-30 19:45:13 +02:00
Jonas Jenwald
388851e37b Add a isDestsEqual helper function, to allow comparing explicit destinations, in pdf_history.js 2017-08-30 19:45:13 +02:00
Jonas Jenwald
0c4985546a Add a waitOnEventOrTimeout helper function that allows waiting for an event or a timeout, whichever occurs first 2017-08-30 19:45:13 +02:00
Jonas Jenwald
28ce3b6185 Rip out the current implementation of PDFHistory
The current implementation of `PDFHistory` contains a number of smaller bugs, which are *very* difficult to address without breaking other parts of its code.
Possibly the main issue with the current implementation, is that I wrote it quite some time ago, and at the time my understanding of the various edge-cases the code has to deal with was quite limited.
Currently `PDFHistory` may, despite most of those cases being fixed, in certain edge-cases lock-up the browser history, essentially preventing the user from navigating back/forward.

Hence rather than trying to iterate on `PDFHistory` to make it better, the only viable approach is unfortunately rip it out in its entirety and re-write it from scratch.
2017-08-30 19:45:13 +02:00
Yury Delendik
2656825432 Merge pull request #8845 from yurydelendik/fix-autofetch
Fixes autofetch and firefox nightly fetch streams
2017-08-30 11:28:42 -05:00
Yury Delendik
bad3203fda Merge pull request #8768 from mukulmishra18/fetch_stream
Adds fetch stream logic for networking part of PDF.js
2017-08-30 11:27:48 -05:00
Yury Delendik
cd95b426c7 Disables fetch when ReadableStream is not available. 2017-08-30 10:53:59 -05:00
Yury Delendik
3cff7da0e7 Fixes fetch and node behavior when disableAutoFetch adn disableStream is used. 2017-08-30 10:53:38 -05:00
Mukul Mishra
3516a59384 Adds fetch stream logic for networking part of PDF.js 2017-08-29 22:56:48 +05:30
Tim van der Meij
d734b3d1d6 Merge pull request #8835 from Snuffleupagus/viewer-firefox-error-message
Ensure that `PDFViewerApplication.error` outputs proper messages in FIREFOX/MOZCENTRAL builds
2017-08-28 22:51:29 +02:00
Jonas Jenwald
b7fcaff07c Update l10n files 2017-08-28 14:30:27 +02:00
Jonas Jenwald
028d7c0950 Ensure that PDFViewerApplication.error outputs proper messages in FIREFOX/MOZCENTRAL builds
*It appears that this accidentally broke with PR 8394.*

Currently, the following will be printed in the console:
```
An error occurred while loading the PDF.
[object Promise],[object Promise]
```

With this patch we'll again get proper output, e.g. something with this format:
```
An error occurred while loading the PDF.
PDF.js v? (build: ?)
Message: unknown encryption method
```
2017-08-28 13:49:40 +02:00
Tim van der Meij
f54dfc63dc Merge pull request #8831 from Snuffleupagus/uglify-es
Update the `gulp minified` command to use uglify-es
2017-08-27 19:09:22 +02:00
Tim van der Meij
7c7ba9a2ad Merge pull request #8829 from Snuffleupagus/issue-8823
Attempt to improve the `EI` detection heuristics, for inline images, in streams containing `NUL` bytes (issue 8823)
2017-08-27 17:18:23 +02:00
Jonas Jenwald
70e80322da Update the gulp minified command to use uglify-es
By updating to uglify-es, rather than uglify-js, the minifier *itself* now supports ES6 code. This means that it's now possible to minify code built with `PDFJS_NEXT = true` set, i.e. with Babel transpilation disabled, which wasn't the case previously.

Note that uglify-es is based on the API of uglify-js v3, which differs from the one that we previously used.
Of particular importance is the fact that it's no longer possible to provide a path to a file for minification, but one must instead directly provide the source of the file.

For more information, please see https://github.com/mishoo/UglifyJS2/tree/harmony
2017-08-27 15:31:04 +02:00
Jonas Jenwald
49b8cd5a6a Attempt to improve the EI detection heuristics, for inline images, in streams containing NUL bytes (issue 8823)
Since this patch will now treat (some) `NUL` bytes as "ASCII", the number of `followingBytes` checked are thus increased to (hopefully) reduce the risk of introducing new false positives.

Fixes 8823.
2017-08-27 12:48:28 +02:00
Tim van der Meij
7787987a4b
Update webpack and webpack-stream to the latest version
Aside from being up-to-date, this may improve build time/size.
2017-08-27 01:07:51 +02:00
Tim van der Meij
2512eccbf0
Implement getOperatorList method in the WidgetAnnotation class to
avoid duplication in subclasses
2017-08-27 01:02:41 +02:00
Tim van der Meij
4f02857394
Let the two annotation factories use static methods
This corresponds to how other factories are implemented.
2017-08-27 01:02:40 +02:00
Tim van der Meij
af10f8b586
Convert src/display/annotation_layer.js to ES6 syntax 2017-08-27 01:02:40 +02:00
Tim van der Meij
24d741d045
Convert src/core/annotation.js to ES6 syntax 2017-08-27 00:53:45 +02:00
Rob Wu
7cc7260634 Merge pull request #8796 from timvandermeij/svg-text-rise
Implement text rise for the SVG back-end
2017-08-26 19:02:51 +02:00
Rob Wu
a0eed974a3 Merge pull request #8825 from Snuffleupagus/simpleDest-dictionary
Account for broken outlines/annotations, where the destination dictionary contains an invalid `/Dest` entry
2017-08-26 18:40:45 +02:00
Jonas Jenwald
42f2d36d1f Account for broken outlines/annotations, where the destination dictionary contains an invalid /Dest entry
According to the specification, see http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf#page=377, a `Dest` entry in an outline item should *not* contain a dictionary.
Unsurprisingly there's PDF generators that completely ignore this, treating is an `A` entry instead.

The patch also adds a little bit more validation code in `Catalog.parseDestDictionary`.
2017-08-26 17:38:15 +02:00
Tim van der Meij
bd85bda0a6 Merge pull request #8826 from Snuffleupagus/eslint_for-direction
Enable the `for-direction` ESLint rule
2017-08-26 15:26:01 +02:00
Jonas Jenwald
0e2618fdbc Enable the for-direction ESLint rule
See https://eslint.org/docs/rules/for-direction; helps avoid typos that would cause infinite `for` loops.

Also, updates `eslint` and `eslint-plugin-mozilla` to the latest available versions.
2017-08-26 11:31:07 +02:00
Tim van der Meij
798e46da97 Merge pull request #8821 from Snuffleupagus/issue-8798-reduced-test
Replace the test-case for issue 8798 with a reduced one (PR 8800 follow-up)
2017-08-26 00:00:45 +02:00
Tim van der Meij
26c4536964 Merge pull request #8820 from Snuffleupagus/viewer-open-rm-scale
Remove the ability to pass a `scale` parameter in the (optional) `args` object parameter of `PDFViewerApplication.open(file, args)`
2017-08-25 00:45:35 +02:00
Tim van der Meij
d368a5baed Merge pull request #8817 from mukulmishra18/intermittent-error
Set this.isCancelled in close method of streamSink.
2017-08-25 00:31:44 +02:00
Tim van der Meij
5f372cdae3 Merge pull request #8819 from Snuffleupagus/getting_started-rm-compatibility
Remove any mention of `compatibility.js` from the "Getting Started" docs (issue 8818)
2017-08-24 22:50:43 +02:00
Jonas Jenwald
88167b5e38 Merge pull request #8824 from Snuffleupagus/bug-1393476
Prevent an infinite loop in `XRef.readXRef` by keeping track of already parsed tables (bug 1393476)
2017-08-24 22:13:48 +02:00
Jonas Jenwald
4660cf8238 Prevent an infinite loop in XRef.readXRef by keeping track of already parsed tables (bug 1393476)
With this patch, not only is the infinite loop prevented, but we're also able to actually render the file (which e.g. Adobe Reader isn't able to).

Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1393476.
2017-08-24 19:18:08 +02:00
Yury Delendik
f1819f4d36 Merge pull request #8822 from yurydelendik/disable-fs-in-dist
Disable node libs in pdfjs-dist package.json
2017-08-24 11:36:00 -05:00
Yury Delendik
e82811adb4 Merge pull request #8712 from mukulmishra18/node_stream
Adds node.js logic for networking tasks for PDF.js
2017-08-24 11:35:29 -05:00
Yury Delendik
4e6ae18f19 Disable node libs in pdfjs-dist package.json 2017-08-24 10:57:18 -05:00
Jonas Jenwald
4891b9c7e0 Replace the test-case for issue 8798 with a reduced one (PR 8800 follow-up)
*Re: issue 8798 and PR 8800.*

Big thanks to @THausherr for providing the test-case.
2017-08-24 17:43:05 +02:00
Jonas Jenwald
870a8f6c35 Remove the ability to pass a scale parameter in the (optional) args object parameter of PDFViewerApplication.open(file, args)
Since the very early days of the viewer, it's been possible to pass in a `scale` when opening a PDF file. However, most of the time it was/is actually being ignored, which limits its usefulness considerably.

In older versions of the viewer, if a document hash was present (i.e. `PDFViewerApplication.initialBookmark` being set) or if the document existed in the `ViewHistory`, the `scale` passed to `PDFViewerApplication.open` would thus always be ignored.
In addition to the above, in the current viewer there's even more cases where the `scale` parameter will be ignored: if a (valid) browser history entry exists on document load, or if the `defaultZoomValue` preference is set to a non-default value.
Hence the result is that in most situation, a `scale` passed to `PDFViewerApplication.open` will be completely ignored.

A much better, not to mention supported, way of setting the initial scale is by using the `defaultZoomLevel` preference. In comparision, this also has the advantage of being used in situations where the `scale` would be ignored.

All in all this leads to the current situation where we have code which is essentially dead, since no part of the viewer (by default) relies on it.
To clean up this code, and to avoid having to pass (basically) unused parameters around, I'd thus like to remove the ability to pass a `scale` to `PDFViewerApplication.open`.
2017-08-24 13:14:00 +02:00
Jonas Jenwald
b048b65e7b Remove any mention of compatibility.js from the "Getting Started" docs (issue 8818)
*With PR 8102, `compatibility.js` is now bundled directly into `pdf.js` and `pdf.worker.js`.*

Fixes 8818.
2017-08-24 13:08:55 +02:00
Mukul Mishra
efad0c7a40 Set this.isCancelled in close method of streamSink. 2017-08-24 13:51:27 +05:30
Mukul Mishra
d16709f5e4 Adds tests for node_stream 2017-08-24 12:46:44 +05:30
Tim van der Meij
e9ba54940d Merge pull request #8800 from Snuffleupagus/issue-8798
Try to recover if we reach the end of the stream when searching for the `EI` marker of an inline image (issue 8798)
2017-08-23 23:47:51 +02:00
Brendan Dahl
23a4174163 Merge pull request #8810 from squarewave/master
Cache PdfJs's enabled setting for delayed init
2017-08-23 10:36:03 -07:00
Jonas Jenwald
6433fc8644 Merge pull request #8813 from yurydelendik/loopback-isarray
Use Array.isArray in the LoopbackPort.
2017-08-23 17:38:29 +02:00
Yury Delendik
438c0b28f2 Use Array.isArray in the LoopbackPort. 2017-08-23 09:25:25 -05:00
Mukul Mishra
18ede8c65d Adds http support to node_stream logic 2017-08-23 14:08:41 +05:30
Mukul Mishra
ed78b23ff2 Adds node.js logic for networking tasks for PDF.js 2017-08-23 14:06:43 +05:30
Jonas Jenwald
cb10c03d0a Merge pull request #8812 from yurydelendik/central-global
Moves global scope out of shared/util.
2017-08-23 09:36:13 +02:00
Yury Delendik
57bc3296f4 Moves global scope out of shared/util. 2017-08-22 18:20:52 -05:00
Tim van der Meij
cfc052a515
Implement text rise for the SVG back-end
The property and the setter for text rise were already present, but they
were never used or called. This patch completes the implementation by
calling the setter when the operator is encountered and by using the
text rise value when rendering text.
2017-08-23 00:34:39 +02:00