Commit Graph

11529 Commits

Author SHA1 Message Date
Jani Pehkonen
26121177ab Implement Decode entry in Indexed images 2019-01-22 22:51:04 +02:00
Brendan Dahl
d614cabfa0
Merge pull request #10480 from Snuffleupagus/debugger-FontInspector
[Regression] Fix the `FontInspector` in the PDFBug debugging tools
2019-01-22 10:02:58 -08:00
Jonas Jenwald
6a4dae927c [Regression] Fix the FontInspector in the PDFBug debugging tools
The `FontInspector` was completely broken by PR 10197, and trying to select a particular font (using the checkboxes) or clicking on a piece of text currently does nothing.
2019-01-22 13:22:36 +01:00
Tim van der Meij
f26129de26
Merge pull request #10474 from timvandermeij/updates
Update translations and packages
2019-01-20 16:40:25 +01:00
Tim van der Meij
810dbeb4e5
Update packages 2019-01-20 16:34:24 +01:00
Tim van der Meij
a84541b271
Update translations 2019-01-20 16:32:35 +01:00
Tim van der Meij
78eb73004f
Merge pull request #10473 from Snuffleupagus/array-from
Add an `Array.from` polyfill, using core-js, and remove some compatibility hacks from the `src/display/content_disposition.js` file
2019-01-20 14:41:39 +01:00
Jonas Jenwald
01d624f6a0 Add an Array.from polyfill, using core-js, and remove some compatibility hacks from the src/display/content_disposition.js file 2019-01-20 08:49:20 +01:00
Tim van der Meij
66acc7397f
Merge pull request #10470 from Snuffleupagus/mozcentral-streams
Try to, completely, avoid loading the `ReadableStream` polyfill in MOZCENTRAL builds
2019-01-19 21:22:18 +01:00
Tim van der Meij
a908702fad
Merge pull request #10471 from timvandermeij/metadata-unit-test
Implement a unit test for metadata parsing to ensure that it's not vulnerable to the billion laughs attack
2019-01-19 20:45:00 +01:00
Tim van der Meij
c4fe4087d3
Implement a unit test for metadata parsing to ensure that it's not vulnerable to the billion laughs attack 2019-01-19 19:54:08 +01:00
Tim van der Meij
269168d053
Merge pull request #10467 from Snuffleupagus/less-indexOf
Convert some usage of `indexOf` to `startsWith`/`includes` where applicable
2019-01-19 15:23:37 +01:00
Jonas Jenwald
480110625a Try to, completely, avoid loading the ReadableStream polyfill in MOZCENTRAL builds
With https://bugzilla.mozilla.org/show_bug.cgi?id=1505122 landing in Firefox 65, the native `ReadableStream` implementation is now enabled by default in Firefox.

Obviously it would be nice to simply stop bundling the polyfill in MOZCENTRAL builds altogether, however given that it's still possible to disable[1] `ReadableStream` this is probably not a good idea just yet.
Nonetheless, now that native support is available, it seems unnecessary (and wasteful) to keep bundling the polyfill twice[2] in MOZCENTRAL builds. Hence this patch, which contains a suggest approach for packing the polyfill in a *separate* file which is then *only* loaded if/when needed.

With this patch, the size of the `gulp mozcentral` build target is thus reduced accordingly:

|       | `build/mozcentral`
|-------|-------------------
|master |   3 461 089
|patch  |   3 340 268

Besides the PDF.js files taking up less space in Firefox this way, the additional benefit is that there's (by default) less code that needs to be loaded and parsed when the PDF Viewer is used which also cannot hurt.

---
[1] In `about:config`, by toggling the `javascript.options.streams` preference.

[2] Once in the `build/pdf.js` file, and once in the `build/pdf.worker.js` file.
2019-01-19 09:05:01 +01:00
Tim van der Meij
1bb5ca0588
Merge pull request #10466 from Snuffleupagus/BaseViewer-update
Move/refactor the code in the `BaseViewer.update` method to reduce duplication in the extending classes
2019-01-19 00:04:31 +01:00
Jonas Jenwald
24a688d6c6 Convert some usage of indexOf to startsWith/includes where applicable
In many cases in the code you don't actually care about the index itself, but rather just want to know if something exists in a String/Array or if a String starts in a particular way. With modern JavaScript functionality, it's thus possible to remove a number of existing `indexOf` cases.
2019-01-18 17:57:41 +01:00
Jonas Jenwald
343f488daa Move/refactor the code in the BaseViewer.update method to reduce duplication in the extending classes
Since most of the important rendering code is already (almost) identical between `PDFViewer.update` and `PDFSinglePageViewer.update`, it's possible to further reduce duplication by moving the code into `BaseViewer.update` instead.
2019-01-18 15:06:21 +01:00
Tim van der Meij
cdbc33ba06
Merge pull request #10457 from Snuffleupagus/metadata-tests
When parsing Metadata, attempt to remove "junk" before the first tag (PR 10398 follow-up)
2019-01-16 23:03:39 +01:00
Tim van der Meij
697b3d2f49
Merge pull request #10461 from Snuffleupagus/pr-10423
Avoid setting incorrect document URLs, in IE 11, when the browser history is updated (PR 10423 follow-up)
2019-01-16 22:51:50 +01:00
Tim van der Meij
f711df583a
Merge pull request #10462 from Snuffleupagus/pr-10152
Tweak the `DOMTokenList.toggle` polyfill (issue 10460)
2019-01-16 22:44:20 +01:00
Jonas Jenwald
68ad3e8e9d Tweak the DOMTokenList.toggle polyfill (issue 10460) 2019-01-16 20:15:44 +01:00
Jonas Jenwald
ffe798137f Avoid setting incorrect document URLs, in IE 11, when the browser history is updated (PR 10423 follow-up)
Apparently in IE 11 when `history.{pushState, replaceState}` is called, there's actually a difference between not providing the *third* argument vs providing it set implicitly to `undefined`. It appears that in IE 11 it's actually being stringified, rather than ignored, which seems completely wrong (obviously other browsers aren't affected, so no surprises there).

This is yet another reason why I think the feature itself was a really bad idea, since it now requires extra/duplicated code just to prevent weird/incorrect URL behaviour in crappy browsers.
2019-01-16 19:26:44 +01:00
Jonas Jenwald
9f45f8dfda When parsing Metadata, attempt to remove "junk" before the first tag (PR 10398 follow-up)
This will allow the Metadata to be successfully extracted from the PDF file in issue 10395.
Furthermore, this patch also fixes a bug in `Metadata.get` which causes the method to return `null` rather than an empty string or zero (since either ought to be allowed).
2019-01-16 12:44:27 +01:00
Jonas Jenwald
5d90224409 Add a unit-test for issue 10395 (PR 10398 follow-up) 2019-01-16 11:30:36 +01:00
Tim van der Meij
5cb00b7967
Merge pull request #10443 from Snuffleupagus/getVisibleElements-fixes
Prevent `TypeError: views[index] is undefined` being throw in `getVisibleElements` when the viewer, or all pages, are hidden
2019-01-13 15:41:48 +01:00
Tim van der Meij
5efc902fb8
Merge pull request #10447 from timvandermeij/bad-request
Handle malformed URIs as bad requests in the development webserver
2019-01-13 15:09:17 +01:00
Tim van der Meij
6279fc601a
Handle malformed URIs as bad requests in the development webserver
Fixes #10445 (found by Dhiraj Mishra).
2019-01-13 14:57:20 +01:00
Jonas Jenwald
b2235ec9c4 Add a unit-test to check that the sortByVisibility parameter, in getVisibleElements, works correctly 2019-01-13 11:34:38 +01:00
Jonas Jenwald
9743708a24 Prevent TypeError: views[index] is undefined being throw in getVisibleElements when the viewer, or all pages, are hidden
Previously a couple of different attempts at fixing this problem has been rejected, given how *crucial* this code is for the correct function of the viewer, since no one has thus far provided any evidence that the problem actually affects the default viewer[1] nor an example using the viewer components directly (without another library on top).
The fact that none of the prior patches contained even a *simple* unit-test probably contributed to the unwillingness of a reviewer to sign off on the suggested changes.

However, it turns out that it's possible to create a reduced test-case, using the default viewer, that demonstrates the error[2]. Since this utilizes a hidden `<iframe>`, please note that this error will thus affect Firefox as well.
Note that while errors are thrown when the hidden `<iframe>` loads, the default viewer doesn't break completely since rendering does start working once the `<iframe>` becomes visible (although the errors do break the initial Toolbar state).

Before making any changes here, I carefully read through not just the immediately relevant code but also the rendering code in the viewer (given it's dependence on `getVisibleElements`). After concluding that the changes should be safe in general, the default viewer was tested without any issues found. (The above being much easier with significant prior experience of working with the viewer code.)
Finally the patch also adds new unit-tests, one of which explicitly triggers the relevant code-path and will thus fail with the current `master` branch.

This patch also makes `PDFViewerApplication` slightly more robust against errors during document opening, to ensure that viewer/document initialization always completes as expected.
Please keep in mind that even though this patch prevents an error in `getVisibleElements`, it's still not possible to set the initial position/zoom level/sidebar view etc. when the viewer is hidden since rendering and scrolling is completely dependent[3] on being able to actually access the DOM elements.

---
[1] And hence the PDF Viewer that's built-in to Firefox.

[2] Copy the HTML code below and save it as `iframe.html`, and place the file in the `web/` folder. Then start the server, with `gulp server`, and navigate to http://localhost:8888/web/iframe.html

```html
<!DOCTYPE html>
<html>
  <head>
    <title>Iframe test</title>

    <script>
      window.onload = function() {
        const button = document.getElementById('button1');
        const frame = document.getElementById('frame1');

        button.addEventListener('click', function(evt) {
          frame.hidden = !frame.hidden;
        });
      };
    </script>
  </head>

  <body>
    <button id="button1">Toggle iframe</button>
    <br>
    <iframe id="frame1" width="800" height="600" src="http://localhost:8888/web/viewer.html" hidden="true"></iframe>
  </body>
</html>
```

[3] This is an old, pre-exisiting, issue that's not relevant to this patch as such (and it's already being tracked elsewhere).
2019-01-13 11:34:24 +01:00
Jonas Jenwald
ae59be181b Clean-up variable definitions in getVisibleElements
With modern JavaScript supporting block-scoped variables, it's no longer necessary to have large numbers of top-level variable definitions (especially when all variables are, implicitly, set to `undefined`).

Besides moving variable definintions, a number of them are also converted to `const` to help ensure that they cannot be *accidentally* modified in the code.
Finally, the `views.length` calculation is now cached *once* rather than being re-computed multiple times.
2019-01-13 11:34:11 +01:00
Tim van der Meij
35415b935c
Merge pull request #10444 from timvandermeij/rm-log
Remove left-over console log from the find controller unit tests
2019-01-12 22:28:38 +01:00
Tim van der Meij
ed918bad21
Remove left-over console log from the find controller unit tests 2019-01-12 22:27:40 +01:00
Tim van der Meij
a37ea16013
Merge pull request #10425 from timvandermeij/find-controller-unit-tests
Write more unit tests for the find controller
2019-01-12 22:20:53 +01:00
Tim van der Meij
b1cef896f4
Write more unit tests for the find controller
Fixes #7356.
2019-01-12 22:17:46 +01:00
Jonas Jenwald
b531fc4106 Avoid truncating inline images, where the data and the "EI" marker is glued together (issue 10388) (#10436)
Thanks to the *excellent* debugging done by @janpe2, this was easy to fix!
2019-01-12 20:31:23 +01:00
Tim van der Meij
eb7cd884ed
Merge pull request #10441 from Snuffleupagus/indexObjects-more-nested-obj
Handle more cases of corrupt PDF files with missing 'endobj' operators, where the "obj" string is immediately followed by the dictionary (PR 9288 follow-up)
2019-01-12 20:02:09 +01:00
Jonas Jenwald
d4a3858ed5 Handle more cases of corrupt PDF files with missing 'endobj' operators, where the "obj" string is immediately followed by the dictionary (PR 9288 follow-up) 2019-01-10 17:55:28 +01:00
Tim van der Meij
e4d2a1604e
Merge pull request #10423 from Snuffleupagus/historyUpdateUrl
Add support for updating the document hash, off by default, when the browser history is updated (issue 5753)
2019-01-06 20:18:12 +01:00
Jonas Jenwald
358cd0c096 Add a few more String polyfills (startsWith, endsWith, padStart, padEnd) 2019-01-06 20:10:55 +01:00
Jonas Jenwald
4773bf6fcb Add support for updating the document hash, off by default, when the browser history is updated (issue 5753)
This is *really* the best that we can do here, since other proposed solutions would interfere with (and break) the painstakingly implemented browsing history that's present in the default viewer.

I'm still not convinced that this is a good idea in general, but this patch implements it in a way where it is possible to toggle[1] for users that wish to have this feature. In particular, there's a couple of reasons why I'm not finding this feature necessary/great:
 - It's already possible to easily obtain the current hash, by simply clicking on the `viewBookmark` button at any time.
 - Hash changes requires a bit of special handling[2], i.e. extra code, to prevent issues when the browser history is traversed (see `PDFHistory._popState`). Currently this is only necessary when the user has manually changed the hash, with this patch it will always be the case (assuming the feature is active).
 - It's not always possible to change the URL when updating the browser history. For example: In the Firefox built-in viewer, the URL cannot be modified for local files (i.e. those using the `file://` protocol).
This leads to inconsistent behaviour, and may in some cases even result in errors being thrown and the history thus not updating, if the browser prevents changes to the URL during `pushState`/`replaceState` calls.

---
[1] Using the `historyUpdateUrl` viewer preference.

[2] This depends, to a great extent, on browsers always firing `popstate` events *before* `hashchange` events, which may or may not actually be guaranteed.
2019-01-06 20:09:02 +01:00
Tim van der Meij
af31b980b0
Merge pull request #10424 from Snuffleupagus/issue-6847
Accept non-matching document fingerprints, in `PDFHistory`, when the viewer is reloaded (issue 6847)
2019-01-06 19:08:03 +01:00
Jonas Jenwald
d46715210a Accept non-matching document fingerprints, in PDFHistory, when the viewer is reloaded (issue 6847)
This should hopefully be sufficient to address issue 6847, and given the limited impact of the code changes I'm not completely sure if this would need to be controlled by a preference!?

Initially my intention was to try and provide some (slightly more detailed) implementation suggestions in the issue, but having looked briefly at doing that it would essentially have amounted to actually writing the code anyway. (Especially considering that the recent questions seemed to more-or-less ignore the information already provided in the first post.)

Finally, note that since `performance.navigation.type` is marked as deprecated, a slightly different approach was choosen instead.
2019-01-06 17:02:39 +01:00
Tim van der Meij
968a153180
Merge pull request #10422 from timvandermeij/es6
Convert more files in `src/core` to ES6 syntax
2019-01-06 15:06:57 +01:00
Tim van der Meij
f162fed6b9
Convert src/core/charsets.js and src/core/standard_fonts.js to ES6 syntax
Moreover, include the "no var" ESLint comment to
`src/core/annotation.js` and `src/core/ps_parser.js` since they are
already converted.
2019-01-06 15:04:01 +01:00
Tim van der Meij
3b637e71d4
Convert src/core/arithmetic_decoder.js to ES6 syntax 2019-01-06 15:04:01 +01:00
Tim van der Meij
c967eab8b1
Merge pull request #10421 from timvandermeij/fix
Switch to HTTPS for the license link on the website
2019-01-05 15:36:39 +01:00
Tim van der Meij
be3defdd94
Switch to HTTPS for the license link on the website
Moreover, fix a small oversight in how the file tree is rendered.
2019-01-05 15:35:17 +01:00
Tim van der Meij
7307c60407
Merge pull request #10420 from timvandermeij/misc
Update translations/packages and improve documentation
2019-01-05 15:27:06 +01:00
Tim van der Meij
61dcc41a3c
Clarify that gulp dist-install should be used for the AcroForms example
Fixes #10333.
2019-01-05 15:20:50 +01:00
Tim van der Meij
f32dcbc089
Improve the file layout overview on the website
Mention only the relevant files/folders and update the overview to match
the current file trees.

Fixes #10384.
2019-01-05 15:20:50 +01:00
Tim van der Meij
ca04a397bb
Update packages 2019-01-05 14:27:47 +01:00