Commit Graph

10209 Commits

Author SHA1 Message Date
Tim van der Meij
46481eb2bf Merge pull request #8892 from Snuffleupagus/es6-genericcom-genericl10n
Replace `var` with `let` in `web/genericcom` and `web/genericl10n`
2017-09-10 16:06:22 +02:00
Jonas Jenwald
1d78935f3e Replace var with let in web/genericcom and web/genericl10n 2017-09-10 13:09:26 +02:00
Jonas Jenwald
aaff3385ee ES6-ify the code in web/firefoxcom.js
These changes consists mainly of replacing `var` with `let`/`const`, and finally converting the `DownloadManager` to a proper class.
2017-09-10 12:51:33 +02:00
Tim van der Meij
320779e6ed Merge pull request #8691 from timvandermeij/square-circle-annotations
Implement support for square and circle annotations
2017-09-09 22:56:54 +02:00
Tim van der Meij
c04f9d6098
Implement reference tests for square and circle annotations 2017-09-09 21:36:28 +02:00
Tim van der Meij
44c116ac49
Implement support for circle annotations 2017-09-09 21:36:27 +02:00
Tim van der Meij
cace2e9047
Implement support for square annotations 2017-09-09 21:36:27 +02:00
Tim van der Meij
f7fd1db52f
Introduce DOMSVGFactory
This patch provides a new unit tested factory for creating SVG
containers and elements. This code is duplicated twice in the
codebase, but with upcoming changes this would need to be duplicated
even more. Moreover, consolidating this code in one factory allows
us to replace it easily for e.g., supporting Node.js. Therefore, move
this to a central place and update/ES6-ify the related code.

Finally, we replace `setAttributeNS` with `setAttribute` because no
namespace is provided.
2017-09-09 21:36:27 +02:00
Tim van der Meij
437e9cb056 Merge pull request #8865 from Snuffleupagus/hide-unsupported-LinkAnnotation
Hide unsupported `LinkAnnotation`s (issue 3897)
2017-09-09 19:07:43 +02:00
Tim van der Meij
e6d05be41a Merge pull request #8868 from Snuffleupagus/save-rotation
Store the rotation in the `ViewHistory`/`PDFHistory` (issue 5927)
2017-09-09 16:33:28 +02:00
Tim van der Meij
bd3f16bffd Merge pull request #8889 from Snuffleupagus/more-Number-isInteger
Replace `value === (value | 0)` checks with `Number.isInteger(value)`
2017-09-09 15:24:23 +02:00
Jonas Jenwald
30b7a0f093 Replace value === (value | 0) checks with Number.isInteger(value) in the web/ folder
Rather than doing what (at first) may seem like a fairly obscure comparison, using `Number.isInteger` will clearly indicate the intent of the code.
2017-09-09 14:12:52 +02:00
Jonas Jenwald
8686baede5 Replace value === (value | 0) checks with Number.isInteger(value) in the src/ folder
Rather than doing what (at first) may seem like a fairly obscure comparison, using `Number.isInteger` will clearly indicate the intent of the code.
2017-09-09 14:12:52 +02:00
Jonas Jenwald
e135c03123 Store the rotation in the PDFHistory 2017-09-09 11:27:05 +02:00
Jonas Jenwald
44d5138d0f Store the rotation in the ViewHistory (issue 5927) 2017-09-09 11:27:05 +02:00
Jonas Jenwald
5565a6f8bf Slightly refactor the pages rotation handling code in the viewer
This changes both `PDFViewer` and `PDFThumbnailViewer` to return early in the `pagesRotation` setters if the rotation doesn't change.
It also fixes an existing issue, in `PDFViewer`, that would cause errors if the rotation changes *before* the scale has been set to a non-default value.

Finally, in preparation for subsequent patches, it also refactors the rotation code in `web/app.js` to update the thumbnails and trigger rendering with the new `rotationchanging` event.
2017-09-09 11:27:05 +02:00
Tim van der Meij
c8b5ba277a Merge pull request #8885 from Snuffleupagus/PDFHistory-followup
Address a couple of edge-cases in the new `PDFHistory` implementation (PR 8775 follow-up)
2017-09-08 23:10:45 +02:00
Tim van der Meij
d1089a285d Merge pull request #8877 from timvandermeij/button-widget-annotation-style
Provide `checked` styles for button widget annotations
2017-09-08 22:50:17 +02:00
Jonas Jenwald
938dffb06b Reduce the value of UPDATE_VIEWAREA_TIMEOUT and simplify the 'popstate' event handler to avoid subtle bugs
When testing the new `PDFHistory` implementation in practice, I felt that the current value of `UPDATE_VIEWAREA_TIMEOUT` is too large to be truly useful.
The purpose of the timeout is to attempt to address (the PDF.js part of) https://bugzilla.mozilla.org/show_bug.cgi?id=1153393, and it's currently fairly easy for the user e.g. close the browser before the timeout had a change to finish.

Obviously, the timeout is a best-effort solution, but with the current value of `UPDATE_VIEWAREA_TIMEOUT` it's not as useful as one would want.
Please note that lowering it shouldn't be a problem, since it still prevents the browser history from updating at *every* 'updateviewarea' event or during (quick) scrolling, which is all that's really needed to not impact the UX negatively.

---

Furthermore, with this lower timeout, we can also simplify the part of the 'popstate' event handler that attempted to update the browser history with the current position before moving back. In most cases, the current position will now already exist in the history, and this *greatly* decreases the complexity of this code path.

The main impetus for this change though, is that I unfortunately found that given the asynchronous nature of updating the browser history, there is some *edge* cases where that code could cause history corruption.
In practice, the user could thus get "stuck" at a particular history entry and not be able to move back. I haven't got any reliable STR for this, since it's so difficult to trigger, but it involved navigating around in a document such that a number of destinations are added to the browser history and then changing the rotation before going back/forward in the history.

Rather that attempting to patch this code, and making it even more difficult to understand than it already is or adding more asynchronous behaviour, by far the easiest solution is to remove it and simply rely on the (lowered) `UPDATE_VIEWAREA_TIMEOUT` instead.
2017-09-07 21:02:25 +02:00
Jonas Jenwald
b7c4d788ed Prevent a temporary position from being added to the history while a destination is scrolled into view
Since e.g. zooming can occur when navigating to a new destionation, ensure that a resulting 'updateviewarea' event doesn't trigger adding of a *temporary* position to the browser history at a bad time.
2017-09-07 16:25:01 +02:00
Jonas Jenwald
077195d8ce Ensure that the PDFHistory._updateViewareaTimeout is always reset when the history is updated 2017-09-07 11:37:23 +02:00
Tim van der Meij
2a77f8b041
Provide checked styles for button widget annotations
Fixes #8875.
2017-09-07 00:25:45 +02:00
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