Commit Graph

10237 Commits

Author SHA1 Message Date
Jonas Jenwald
39a77c76ad Assign a dummy value to the docBaseUrl API parameter in non-PRODUCTION mode
This ensures that relative links are displayed when using the viewer in `gulp server` mode, in an effort to aid development/debugging.
2017-09-06 12:59:28 +02:00
Jonas Jenwald
7115e136e4 Hide unsupported LinkAnnotations (issue 3897)
Rather than displaying links that does *nothing* when clicked, it probably makes more sense to simply not render them instead. Especially since it turns out that, at least at this point in time, this is *very* easy to both implement and test.

Fixes 3897.
2017-09-06 12:52:56 +02:00
Jani Pehkonen
86020396cb Fix color of image masks inside uncolored patterns 2017-09-06 13:41:48 +03:00
Yury Delendik
9b14f8ea2a Merge pull request #8866 from Snuffleupagus/fix-non-HTTP-validateResponseStatus
Correctly validate the response status for non-HTTP fetch requests (PR 8768 follow-up)
2017-09-05 12:47:44 -05:00
Jonas Jenwald
4edd4fba76 Merge pull request #8874 from zztoy/HelloWorldExampleFix
Fix the helloworld example by setting the PDFNetworkStream class (PR 8712 follow-up)
2017-09-05 18:54:47 +02:00
FAREAST\wenxh
585cd933b7 Fix the helloworld example by setting the PDFNetworkStream class (PR 8712 follow-up) 2017-09-06 00:47:35 +08:00
Jonas Jenwald
41415ba0a2 Correctly validate the response status for non-HTTP fetch requests (PR 8768 follow-up)
It seems that the status check, for non-HTTP loads, causes the default viewer to *refuse* to open local PDF files.

***STR:***
 1. Make sure that fetch support is enabled in the browser. In Firefox Nightly, set `dom.streams.enabled = true` and `javascript.options.streams = true` in `about:config`.
 2. Open https://mozilla.github.io/pdf.js/web/viewer.html.
 3. Click on the "Open file" button, and open a new PDF file.

***ER:***
 A new PDF file should open in the viewer.

***AR:***
 The PDF file fails to open, with an error message of the following format:
`Message: Unexpected server response (200) while retrieving PDF "blob:https://mozilla.github.io/a4fc455f-bc05-45b5-b6aa-2ecff3cb45ce".`
2017-09-05 17:07:44 +02:00
Jonas Jenwald
cd25a51abe Update l10n files 2017-09-04 11:33:04 +02:00
Tim van der Meij
1c9af00bee Merge pull request #8775 from Snuffleupagus/rewrite-PDFHistory-2
Re-write `PDFHistory` from scratch
2017-09-03 20:38:59 +02:00
Tim van der Meij
336d26dd13 Merge pull request #8864 from Snuffleupagus/rm-isArray
Replace the `isArray` helper function with the native `Array.isArray` function
2017-09-01 23:08:44 +02:00
Jonas Jenwald
cfb4955a92 Replace the isArray helper function with the native Array.isArray function
*Follow-up to PR 8813.*
2017-09-01 20:27:13 +02:00
Jonas Jenwald
22ade754cc Merge pull request #8862 from Snuffleupagus/rm-isInt
Replace the `isInt` helper function with the native `Number.isInteger` function
2017-09-01 19:56:48 +02:00
Jonas Jenwald
11408da340 Replace the isInt helper function with the native Number.isInteger function
*Follow-up to PR 8643.*
2017-09-01 16:52:50 +02:00
Jonas Jenwald
066fea9c8b Merge pull request #8859 from yurydelendik/issue-8858
Revert PDFPageView.pdfPage reset.
2017-09-01 00:05:37 +02:00
Yury Delendik
47c28643d6 Revert PDFPageView.pdfPage reset. 2017-08-31 16:49:01 -05:00
Tim van der Meij
d332f62d60 Merge pull request #8857 from Snuffleupagus/fetchUncompressed-type-checks
Avoid some redundant type checks in `XRef.fetchUncompressed`
2017-08-31 23:33:02 +02:00
Tim van der Meij
51be27853f Merge pull request #8847 from Snuffleupagus/AnnotationElement-isRenderable-regression
Correct the default value for `isRenderable` in the `AnnotationElement` constructor, to fix breaking errors when rendering unsupported annotations
2017-08-31 22:08:10 +02:00
Jonas Jenwald
772a5412a4 Avoid some redundant type checks in XRef.fetchUncompressed
When looking briefly at using `Number.isInteger`/`Number.isNan` rather than `isInt`/`isNaN`, I noticed that there's a couple of not entirely straightforward cases to consider.

At first I really couldn't understand why `parseInt` is being used like it is in `XRef.fetchUncompressed`, since the `num` and `gen` properties of an object reference should *always* be integers.
However, doing a bit of code archaeology pointed to PR 4348, and it thus seem that this was a very deliberate change. Since I didn't want to inadvertently introduce any regressions, I've kept the `parseInt` calls intact but moved them to occur *only* when actually necessary.[1]

Secondly, I noticed that there's a redundant `isCmd` check for an edge-case of broken operators. Since we're throwing a `FormatError` if `obj3` isn't a command, we don't need to repeat that check.

In practice, this patch could perhaps be considered as a micro-optimization, but considering that `XRef.fetchUncompressed` can be called *many* thousand times when loading larger PDF documents these changes at least cannot hurt.

---
[1] I even ran all tests locally, with an added `assert(Number.isInteger(obj1) && Number.isInteger(obj2));` check, and everything passed with flying colours.
However, since it appears that this was in fact necessary at one point, one possible explanation is that the failing test-case(s) have now been replaced by reduced ones.
2017-08-31 16:49:04 +02:00
Yury Delendik
47789b51c3 Merge pull request #8855 from Rob--W/fetch-withCredentials-fix-default
Add test for withCredentials option
2017-08-31 08:45:22 -05:00
Rob Wu
73273ccbe9 Add test for withCredentials option 2017-08-31 14:30:00 +02:00
Rob Wu
0430e99d16 Merge pull request #8848 from Snuffleupagus/fetch-credentials
Correctly set the `credentials` of a fetch request, when the `withCredentials` parameter was passed to `getDocument`
2017-08-31 14:12:06 +02:00
Jonas Jenwald
84fe442b35 Correctly set the credentials of a fetch request, when the withCredentials parameter was passed to getDocument
Skimming through https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#Sending_a_request_with_credentials_included, it looks to me like the `credentials` option was accidentally inverted.
2017-08-31 09:20:05 +02:00
Jonas Jenwald
87fc9bafea Correct the default value for isRenderable in the AnnotationElement constructor, to fix breaking errors when rendering unsupported annotations
*This regressed in PR 8828.*

When attempting to open e.g. http://mirrors.ctan.org/macros/latex/contrib/pdfcomment/doc/example.pdf, the annotation layers are now missing since `Error: Abstract method `AnnotationElement.render` called` is thrown multiple times.
2017-08-31 08:47:36 +02:00
Tim van der Meij
a4cc85fc5f Merge pull request #8828 from timvandermeij/es6-annotations
Improve the annotation code by converting to ES6 syntax and removing duplicate code
2017-08-31 00:02:07 +02:00
Jonas Jenwald
0ac1fba2f9 Prevent PDFHistory._tryPushCurrentPosition() from effectively becoming a no-op if the document hash contains an invalid/non-existent destination
By using the (heuristic) `POSITION_UPDATED_THRESHOLD` constant, we can ensure that the current document position will be added to the browser history when a sufficiently "large" number of `updateviewarea` events have been dispatched.
2017-08-30 19:45:13 +02:00
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