Commit Graph

31 Commits

Author SHA1 Message Date
Jonas Jenwald
e98b9b019a Break import cycles, in the viewer, for PDFViewerApplication
Currently the `web/app.js` file pulls in various build-specific dependencies, via the use of import maps, and those files in turn import from `web/app.js` thus creating undesirable import cycles.
To avoid this we instead pass in a `PDFViewerApplication`-reference, immediately after it's been created, to the relevant code.

Note that we use an ESLint plugin rule, see `import/no-cycle`, that is normally able to catch import cycles. However, in this case import maps are involved which is why this wasn't caught.
2024-02-10 23:15:57 +01:00
Jonas Jenwald
5dd25b6e80 Re-factor DefaultExternalServices into a regular class, without static methods
The `DefaultExternalServices` code, which is used to provide build-specific functionality, is very old. This results in a pattern where we first initialize `PDFViewerApplication.externalServices` and then *override* it for the different builds.

By converting `DefaultExternalServices` into a "regular" class, and leveraging import maps, we can directly initialize the correct instance depending on the build.
2024-01-27 12:07:15 +01:00
Jonas Jenwald
d1080e785a Remove the createPreferences method from DefaultExternalServices
Given the simplicity of the `createPreferences` method, we can leverage import maps to directly initialize the correct `Preferences`-instance depending on the build.
2024-01-27 11:38:42 +01:00
Jonas Jenwald
1698991ae2 Remove the createDownloadManager method from DefaultExternalServices
Given the simplicity of the `createDownloadManager` method, we can leverage import maps to directly initialize the correct `DownloadManager`-instance depending on the build.
2024-01-27 11:38:36 +01:00
Jonas Jenwald
92c15a61f1 Re-factor how the sandboxBundleSrc option is passed to PDFScriptingManager
Given that this option isn't used in the Firefox PDF Viewer, we can (ever so slightly) reduce the amount of code needed.
2023-12-09 14:29:31 +01:00
Jonas Jenwald
1f9533bae9 Re-factor the L10n-implementations to use lowercase language-codes internally
This is consistent with the implementation used in the (now removed) webL10n-library, and by only using lowercase language-codes internally in the `L10n`-implementations we should avoid future issues e.g. when users manually set the `locale`-option (in the default viewer).
2023-11-13 21:06:03 +01:00
Jonas Jenwald
eebc230cf1 [Firefox] Fetch browser preferences/options together with the viewer preferences (bug 1862192)
Currently we *synchronously* fetch a number of browser preferences/options, from the platform code, during the viewer respectively PDF document initialization paths.
This seems unnecessary, and we can re-factor the code to instead include the relevant data when fetching the regular viewer preferences.
2023-10-31 15:32:01 +01:00
Jonas Jenwald
5c14c559dd Initialize the L10n-instance as soon as possible in Firefox (PR 17115 follow-up)
Given that there's now a bit more asynchronicity in the l10n-initialization in the Firefox PDF Viewer, after PR 17115, try to limit the impact of that by moving it to occur a tiny bit earlier in the default viewer initialization.
2023-10-19 18:40:52 +02:00
Calixte Denizet
66982a2a11 [api-minor] Move to Fluent for the localization (bug 1858715)
- For the generic viewer we use @fluent/dom and @fluent/bundle
- For the builtin pdf viewer in Firefox, we set a localization url
  and then we rely on document.l10n which is a DOMLocalization object.
2023-10-19 11:20:41 +02:00
Jonas Jenwald
9369adb4bd Remove the unused DefaultExternalServices.createDownloadManager options (PR 12191 follow-up) 2022-12-03 12:52:36 +01:00
Jonas Jenwald
3274972768 Revert Preferences to their previous values, when writing to storage failed
This patch fixes an old inconsistency, when using `BasePreferences.{reset, set}`, where the internal Preference values would be kept even if writing them to storage failed.
2022-03-12 17:25:45 +01:00
Jonas Jenwald
47ff3195e4 Pass in the "sandboxBundleSrc" option when calling DefaultExternalServices.createScripting
Similar to e.g. the "locale" option, this in *only* done for those build-targets where the "sandboxBundleSrc" is actually defined.
With these changes we can remove an `AppOptions` dependency from the `web/generic_scripting.js` file, thus limiting *direct* `AppOptions` usage in the default viewer files.
2020-12-23 14:05:49 +01:00
Jonas Jenwald
6218b9a512 Re-factor/re-name the scripting getter, on the externalServices-implementations, to a createScripting method
Given that the GENERIC default viewer supports opening more than one document, and that a unique scripting-instance is now used for each document, the changes made in this patch seem appropriate.
2020-12-09 22:15:50 +01:00
Jonas Jenwald
a7230eb033 Move the GenericScripting class to its own file, such that it can be used in the Chromium-extension
While it's not entirely clear to me that it's ultimately desirable to use the `pdf.sandbox.js` in the Chromium-extension, given that the MOZCENTRAL-build uses `pdf.scripting.js` directly in a *custom* sandbox, the current state isn't that great since setting `enableScripting = true` with the Chromium-extension will currently fail completely.

Hence this patch, which should at least unbreak things for now.
2020-12-09 22:15:50 +01:00
Jonas Jenwald
7ce6634c51 Ensure that the pdf.sandbox.js scriptElement is also removed from the DOM (PR 12695 follow-up)
I completely missed this previously, but we obviously should remove the scriptElement as well to *really* clean-up everything properly.

Given that there's multiple existing usages of `loadScript` in the code-base, the safest/quickest solution seemed to be to have call-sites opt-in to remove the scriptElement using a new parameter.
2020-12-09 22:15:47 +01:00
Jonas Jenwald
b2dfb55136 Re-factor the scripting getter in GENERIC-builds, since using the same sandbox for *multiple* PDF documents seems highly questionable
Similar to the previous patch, the GENERIC default viewer is capable of opening more than *one* PDF document and we should ensure that we handle that case correctly.
2020-12-06 14:21:49 +01:00
Jonas Jenwald
c39f1aedb2 Re-implement working dev-sandbox/watch-dev-sandbox gulp-tasks
Compared to the, previously removed, `sandbox`/`watch-sandbox` gulp-tasks, these ones should work even when run against an non-existent/empty `build`-folder.

Also, to ensure that the development viewer actually works out-of-the-box, `gulp server` will now also include `gulp watch-dev-sandbox` to remove the need to *manually* invoke the build-tasks.

Finally, this patch also removes the `web/devcom.js` file since it shouldn't actually be needed, assuming that the "sandbox"-loading code in the `web/genericcom.js` file is actually *correctly* implemented.
2020-12-05 23:04:34 +01:00
Calixte Denizet
c7974e9996 JS -- Add a sandbox based on quickjs
* quickjs-eval.js has been generated using https://github.com/mozilla/pdf.js.quickjs/
 * lazy load of sandbox code
 * Rewrite tests to use the sandbox
 * Add a task `watch-sandbox` which update bundle pdf.sandbox.js on change in the sandbox code
2020-11-19 13:40:46 +01:00
Jonas Jenwald
a177afc206 Fix some static static analyzer warnings (issue 11965)
This fixes only those warnings, as reported by https://lgtm.com/projects/g/mozilla/pdf.js?mode=list, that make sense (as far as I'm concerned).

Hence this patch leaves the following things unaddressed:
 - The "recommendation"-category, since it only complains about unused variables. However, note that all of those cases are purposely included and that there's thus ESLint-disable comments added to explictly allow them.
 - The "warning"-category, which still contains two complaints. However, as far as I can tell, they are both false positives.

Given first of all the false positives of the LGTM static analyzer, and secondly that we'd need to add (essentially duplicated) disable-comments for the unused variable cases, it's not entirely clear to me if we actually want to work towards including LGTM in the PDF.js project (e.g. running alongside Travis) or if we should just close issue 11965.
2020-11-01 12:08:38 +01:00
Jonas Jenwald
1b87b1c384 Re-factor the various ExternalServices, used in the default viewer, to classes with static methods
This seems nicer overall, since it's now a bit clearer that the various build targets *extend* the default implementation.
2020-01-15 14:26:47 +01:00
Jonas Jenwald
36881e3770 Ensure that all import and require statements, in the entire code-base, have a .js file extension
In order to eventually get rid of SystemJS and start using native `import`s instead, we'll need to provide "complete" file identifiers since otherwise there'll be MIME type errors when attempting to use `import`.
2020-01-04 13:01:43 +01:00
Jonas Jenwald
5d14e68bec Enable the ESLint prefer-const rule in the web/ directory
Please find additional details about the ESLint rule at https://eslint.org/docs/rules/prefer-const

Note that this patch is generated automatically, by using the ESLint `--fix` argument, and will thus require some additional clean-up (which is done separately).
2019-12-27 01:03:58 +01:00
Jonas Jenwald
de36b2aaba Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).

Prettier is being used for a couple of reasons:

 - To be consistent with `mozilla-central`, where Prettier is already in use across the tree.

 - To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.

Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.

*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.

(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-26 12:34:24 +01:00
Jonas Jenwald
233b3274bf Refactor the Preferences classes to utilize async methods rather than manually returning Promises 2018-09-03 09:52:36 +02:00
Jonas Jenwald
1d03ad0060 Move the disableCreateObjectURL option from the global PDFJS object and into getDocument instead 2018-03-01 18:11:17 +01:00
Jonas Jenwald
81c550903f Move various viewer components options from PDFJS/PDFViewerApplication.viewerPrefs and into AppOptions instead 2018-03-01 18:11:16 +01:00
Jonas Jenwald
74ffd1d865 Pass in the PDFJS.locale option to ExternalServices.createL10n
This allows us to remove an otherwise unnecessary `PDFJS` dependency from the `web/genericcom.js` file.
2018-02-13 16:56:56 +01:00
Jonas Jenwald
1d78935f3e Replace var with let in web/genericcom and web/genericl10n 2017-09-10 13:09:26 +02:00
Yury Delendik
5438ce9b98 Wraps mozL10n to async calls; splits firefox and generic l10n libs. 2017-05-31 09:22:25 -05:00
Jonas Jenwald
c5f9193777 Convert the Preferences to an ES6 class 2017-04-23 21:14:58 +02:00
Jonas Jenwald
594e8c05ef Refactor the DownloadManager initialization in GENERIC/CHROME builds again (PR 8203 follow-up)
In the first commit in PR 8203, I changed how the `DownloadManager` was included/initialized in `GENERIC`/`CHROME` builds.
The change was prompted by the fact that you cannot have conditional `import`s with ES6 modules, and I wanted to avoid bundling the general `DownloadManager` into the various Firefox specific build targets.

What I completely missed though, is that the new code meant that `download_manager.js` will now be pulling in the *entire* viewer (through `app.js`).
This is a *really* stupid mistake on my part, since it causes the `dist/build/pdf_viewer.js` used with the viewer components to now include basically the entire default viewer.

The simplest solution that I could come up with, is to add a `genericcom.js` file (similar to the `firefoxcom.js`/`chromecom.js` files) which will be responsible for importing/initializing the `DownloadManager`.
2017-04-17 13:34:30 +02:00