Commit Graph

11309 Commits

Author SHA1 Message Date
Jonas Jenwald
1c814e208e Prevent getPDFFileNameFromURL from breaking if the url parameter is not a string 2018-09-30 12:28:59 +02:00
Jonas Jenwald
6da78bcc3f Update {PDFLinkService, PDFDocumentProperties}.setDocument to make the "url" parameter optional
This way the resetting of `PDFLinkService`/`PDFDocumentProperties` instances, as is done in `PDFViewerApplication.close`, only requires passing in *one* `null` argument instead of two.
2018-09-30 12:28:56 +02:00
Jonas Jenwald
d6f4d2ff33 Add a Symbol polyfill, using core-js, to allow using for...of loops
https://github.com/zloirock/core-js#ecmascript-symbol
2018-09-29 16:05:00 +02:00
Jonas Jenwald
435ec6a0d5 Use the Font Loading API in MOZCENTRAL builds, and GENERIC builds for Firefox version 63 and above (issue 9945) 2018-09-29 16:05:00 +02:00
Jonas Jenwald
05b021bcce Refactor the FontLoader into proper, build-specific, ES6 classes
Also changes `var` to `let`/`const` in code already touched in the patch, and makes use of template strings in a few spots.
2018-09-29 16:05:00 +02:00
Jonas Jenwald
45d6651976 Refactor unused Date.now() calls in FontLoader.queueLoadingCallback
The `started` timestamp is completely usused, and the `end` timestamp is currently[1] being used essentially like a boolean value.
Hence this code can be simplified to use an actual boolean value instead, which avoids potentially hundreds (or even thousands) of unnecessary `Date.now()` calls.

---
[1] Looking briefly at the history of this code, I cannot tell if the timestamps themselves were ever used for anything (except for tracking "boolean" state).
2018-09-29 15:57:04 +02:00
Jonas Jenwald
ad3e937816 Replace the Font.loading property with, the already existing, Font.missingFile property
The `Font.loading` property is only ever used *once* in the code, whereas `Font.missingFile` is more widely used. Furthermore the name `loading` feels, at least to me, slight less clear than `missingFile`. Finally, note that these two properties are the inverse of each other.
2018-09-29 15:57:04 +02:00
Jonas Jenwald
caf90ff6ee Convert FontFaceObject to an ES6 class
Also changes `var` to `let`/`const` in code already touched in the patch, and makes use of template strings in a few spots.
2018-09-29 15:57:04 +02:00
Tim van der Meij
b40fb3814a
Merge pull request #10111 from Snuffleupagus/rm-substr
Replace `String.prototype.substr()` occurrences with `String.prototype.substring()`
2018-09-29 15:50:41 +02:00
Jonas Jenwald
842e9206c0 Replace String.prototype.substr() occurrences with String.prototype.substring()
As outlined in https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr, which refers to the ECMA-262 specification, using the `substr` function is advised against.

Hence this PR, which replaces all remaining `substr` occurrences with `substring` instead. Please refer to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr#Syntax respectively https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring#Syntax for the differences between the two functions.

Note that in most cases in the code-base there's only one argument passed to `substr`, and those require no other changes except replacing "substr" with "substring". For the other cases, the `substr(start, length)` calls are changed to `substring(start, start + length)` instead.
2018-09-28 11:41:07 +02:00
Jonas Jenwald
f29b4d1116 Clear all find highlights when the findbar is closed (issue 7468)
Please note that this will require a `mozilla-central` follow-up patch, in order for this to work in the built-in Firefox PDF viewer as well.
2018-09-26 10:20:45 +02:00
Jonas Jenwald
1eaa3b8a08 Dispatch a 'pagecancelled' event, in PDFPageView.cancelRendering, when rendering is cancelled
Also, the patch updates `TextLayerBuilder` to use the new 'pagecancelled' event for (future) event removal purposes.
2018-09-23 22:34:39 +02:00
Tim van der Meij
54d6c2436c
Merge pull request #10095 from timvandermeij/updates
Update packages and translations
2018-09-21 15:40:26 +02:00
Tim van der Meij
3c9e25b839
Update translations 2018-09-21 15:26:10 +02:00
Tim van der Meij
2c710eda3e
Update packages 2018-09-21 15:16:30 +02:00
Tim van der Meij
ad6ab88fdf
Merge pull request #10090 from Snuffleupagus/pr-10019-followup
Ensure that all event properties are included, even if no (internal) listeners are registered, when re-dispatching events to the DOM (PR 10019 follow-up)
2018-09-21 14:43:55 +02:00
Jonas Jenwald
39776168a2 Add EventBus unit-tests to ensure that the (optional) argument handling works correctly 2018-09-21 14:31:35 +02:00
Jonas Jenwald
f317a2cb40 Ensure that the DOM event listeners are removed at the end of the relevant EventBus unit-tests, to prevent the tests from interfering with each other 2018-09-20 23:12:01 +02:00
Jonas Jenwald
250e55b0d9 Ensure that all event properties are included, even if no (internal) listeners are registered, when re-dispatching events to the DOM (PR 10019 follow-up) 2018-09-20 22:43:44 +02:00
Tim van der Meij
0e41eb1620
Merge pull request #10078 from timvandermeij/l10n-fix
Improve plural support for the matches counter
2018-09-16 15:25:30 +02:00
Tim van der Meij
f711dbc011
Improve plural support for the matches counter 2018-09-16 14:23:06 +02:00
Tim van der Meij
a85ee3616e
Merge pull request #10071 from Snuffleupagus/matchesCount-FirefoxCom-forward
Enable forwarding, in `FirefoxCom`, of the matchesCount to the browser findbar (bug 1062025)
2018-09-16 14:10:47 +02:00
Jonas Jenwald
06b9455263 Hard-code the MOZCENTRAL build to use the [other] plural forms of the matcheCount strings, to prevent errors for PDF files embedded in iframe/object tags
The built-in PDF Viewer (in Firefox) cannot use the browser findbar when PDF files are embedded in e.g. iframe/object tags, and the PDF.js findbar (i.e. `PDFFindBar`) will thus be used instead in those cases.
This is slightly problematic, since the `MOZCENTRAL` version of the viewer uses a special, slimmed down, version of the `l10n.js` file that doesn't (currently) support plural forms. To prevent the matchesCounter from breaking completely in this edge-case, temporarily hard-code the plural form to use the default `[other]` version of the locale strings.
2018-09-15 23:45:38 +02:00
Jonas Jenwald
be7fdf148c Further ensure that PDFFindController._requestMatchesCount won't return broken data (PR 10052 follow-up)
This prevents the findbar from intermittently displaying `0 of {number} matches`, which *could* theoretically happen for large and/or slow loading documents.
2018-09-15 23:45:38 +02:00
Jonas Jenwald
fafd8819bc Enable forwarding, in FirefoxCom, of the matchesCount to the browser findbar (bug 1062025)
This depends on https://bugzilla.mozilla.org/show_bug.cgi?id=1062025 landing in `mozilla-central` first, since https://searchfox.org/mozilla-central/rev/37663bb87004167184de6f2afa6b05875eb0528e/browser/extensions/pdfjs/content/PdfStreamConverter.jsm#719,740 would otherwise throw for the unknown event name.
2018-09-15 23:45:38 +02:00
Tim van der Meij
ed32f6a082
Merge pull request #10066 from timvandermeij/find-controller
Refactor the find controller
2018-09-15 20:38:08 +02:00
Tim van der Meij
d0b5aa0869
Merge pull request #10070 from Snuffleupagus/matchesCount-plural
Attempt to support plural forms in the matches counter of the findbar (issue 10067)
2018-09-13 22:42:13 +02:00
Brendan Dahl
ae7dcae27e Fix abbreviation. 2018-09-13 13:10:38 -07:00
Tim van der Meij
67e1e39f99
Move scrolling the selected match into view from the find controller to the text layer builder
The find controller should only coordinate finding a string in the
document and should not be responsible for presenting the matches to the
user. The text layer builder already contains the logic to render the
matches in the viewer, so it should also take care of scrolling the
selected match into view.
2018-09-13 22:06:01 +02:00
Tim van der Meij
ede414554e
Change let to const where possible in the find controller
Doing so clearly indicates which variables are read-only and may not be
mutated, which helps readability and prevents subtle issues.
2018-09-13 22:06:00 +02:00
Tim van der Meij
38c9f5fc24
Mark all private members as such in the find controller
Moreover, use getters for all members that are only being read.
2018-09-13 22:05:41 +02:00
Jonas Jenwald
6c4157acd9 Attempt to support plural forms in the matches counter of the findbar (issue 10067)
Based on a quick look at https://github.com/fabi1cazenave/webL10n/#pluralization, it seems that supporting plural forms shouldn't be as difficult as I first thought it might be.
2018-09-13 13:50:51 +02:00
Brendan Dahl
6adeabbb66 Add Glyph & Cog's XPDF copyright/license information. 2018-09-12 13:59:56 -07:00
Tim van der Meij
29683d40a5
Merge pull request #10063 from Snuffleupagus/JPEG-isSourcePDF-assert
Slightly improve the `isSourcePDF` parameter handling in `JpegImage` (PR 10031 follow-up)
2018-09-12 14:56:42 +02:00
Jonas Jenwald
5181172498 Slightly improve the isSourcePDF parameter handling in JpegImage (PR 10031 follow-up)
Currently there's only a single spot in the code-base where `JpegImage.getData` is called, however it nonetheless seem like a good idea to ensure during tests that the `isSourcePDF` parameter is correctly set. (Especially considering that the PDF use-cases will break without it.)

Additionally, in `JpegImage._getLinearizedBlockData`, the code can be made a tiny bit more efficient by checking the value of `isSourcePDF` *first* to avoid useless checks (for the default PDF use-cases).
2018-09-12 11:30:59 +02:00
Tim van der Meij
a859f0eafd
Remove unnecessary startedTextExtraction member variable from the find controller
The find controller already has quite a lot of state to maintain. We can
avoid keeping track of this member variable because when the find
controller is reset, so is the extract text promises array. Therefore,
we can just check if that array contains items or not to determine if
text extraction already started.

Moreover, there is no need to reset the `pageContents` array since the
`reset` method already takes care of that.
2018-09-11 21:19:55 +02:00
Tim van der Meij
21d959bb82
Remove unused member variable hadMatch from the find controller
It's only being assigned, but not read anymore.
2018-09-11 21:19:41 +02:00
Tim van der Meij
9c764da8af
Merge pull request #10061 from timvandermeij/unit-testing
Implement unit tests for the `isSameOrigin` and `createValidAbsoluteUrl` utility functions and use the `const` keyword for constants in `src/shared/util.js`
2018-09-11 16:31:02 +02:00
Tim van der Meij
bf13c8a50b
Use the const keyword for constants in src/shared/util.js
Moreover, move general constants to the top of the file, i.e., those
that are not closely tied to a function in the file.
2018-09-11 16:17:45 +02:00
Tim van der Meij
99de25d6cc
Implement unit tests for the isSameOrigin and createValidAbsoluteUrl utility functions
Moreover, mark the `isValidProtocol` function as private since it's only
used in the utilities file and is not (meant to be) exported.
2018-09-11 16:17:45 +02:00
Tim van der Meij
a789368b7a
Merge pull request #10060 from Snuffleupagus/matchesCount-invalid
Ensure that `PDFFindController._requestMatchesCount` won't return broken data when searching starts (PR 10052 follow-up)
2018-09-11 15:40:41 +02:00
Jonas Jenwald
0a4c326650 Ensure that PDFFindController._requestMatchesCount won't return broken data when searching starts (PR 10052 follow-up)
This is an unfortunate oversight on my part, which I stumbled upon when (locally) testing the `mozilla-central` follow-up patch necessary to enable the matches counter in the built-in PDF viewer.
2018-09-11 14:38:02 +02:00
Tim van der Meij
bf368f3a32
Merge pull request #10056 from Snuffleupagus/matchesCount-viewer-close
[Regression] Ensure that `PDFFindBar.updateResultsCount` doesn't throw when the viewer is closed, by providing proper default values
2018-09-11 00:27:55 +02:00
Jonas Jenwald
11c8e33ed1 [Regression] Ensure that PDFFindBar.updateResultsCount doesn't throw when the viewer is closed, by providing proper default values
The error can be reproduced by opening any file in the viewer, and then running `PDFViewerApplication.close()` in the console.
2018-09-10 16:02:44 +02:00
Tim van der Meij
bc5111d152
Merge pull request #10028 from Snuffleupagus/entireWord
Add initial support for "Whole words" searching in the viewer
2018-09-10 13:01:24 +02:00
Jonas Jenwald
b4edcce296 Remove unused findStatusIcon property from PDFFindBar instances
The property is intended to contain a reference to a DOM element, which not only is nowhere to be found *now* but appears to never have existed in the first place.
2018-09-10 11:59:30 +02:00
Jonas Jenwald
6d804d657f Add initial support for "Whole words" searching in the viewer
As outlined in https://bugzilla.mozilla.org/show_bug.cgi?id=1282759 the internal Firefox name for the feature is `entireWord`, hence that name is used here as well for consistency (with "Whole words" being limited to the UI).

Given existing limitations of the PDF.js search functionality, e.g. the existing problems of searching across "new lines", there's some edge-cases where "Whole words" searching will ignore (valid) results.
However, considering that this is a pre-existing issue related to the way that the find controller joins text-content together, that shouldn't have to block this new feature in my opionion.

*Please note:* In order to enable this feature in the `MOZCENTRAL` version, a small follow-up patch for [PdfjsChromeUtils.jsm](https://hg.mozilla.org/mozilla-central/file/tip/browser/extensions/pdfjs/content/PdfjsChromeUtils.jsm) will be required once this has landed in `mozilla-central`.
2018-09-10 11:59:29 +02:00
Tim van der Meij
53c37d3b45
Merge pull request #10055 from timvandermeij/translation
Translate the new find match count strings to Dutch
2018-09-09 20:29:41 +02:00
Tim van der Meij
04dfbb91fb
Translate the new find match count strings to Dutch 2018-09-09 20:23:07 +02:00
Tim van der Meij
38baaea8f4
Merge pull request #10052 from Snuffleupagus/matchesCount
Display the index of the currently active search result in the matches counter of the findbar (issue 6993, bug 1062025)
2018-09-09 19:56:03 +02:00