Commit Graph

373 Commits

Author SHA1 Message Date
Jonas Jenwald
8a2320bd18 Use modern JavaScript more in the extensions/firefox/tools/l10n.js file
- Introduce optional chaining in a few spots.
 - Use more logical OR assignment in the code.
2023-07-22 10:12:43 +02:00
Jonas Jenwald
25cb4883e9 Enable the ESLint no-var rule in the extensions/firefox/ folder
This was done automatically, using the `gulp lint --fix` command.
2023-07-22 10:05:37 +02:00
Jonas Jenwald
a650fcd634 [ESM] Convert the external/importL10n-folder to use standard modules 2023-07-08 09:36:32 +02:00
Jonas Jenwald
fee850737b Enable the unicorn/prefer-optional-catch-binding ESLint plugin rule
According to MDN this format is available in all browsers/environments that we currently support, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch#browser_compatibility

Please also see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-optional-catch-binding.md
2023-06-12 11:46:11 +02:00
Calixte Denizet
5f5256b4c4 ESMify some modules for m-c (bug 1824610) 2023-03-27 12:01:31 +02:00
Jonas Jenwald
1fc09f0235 Enable the unicorn/prefer-string-replace-all ESLint plugin rule
Note that the `replaceAll` method still requires that a *global* regular expression is used, however by using this method it's immediately obvious when looking at the code that all occurrences will be replaced; please see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll#parameters

Please find additional details at https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-string-replace-all.md
2023-03-23 12:57:10 +01:00
Jonas Jenwald
63708a1a5b Remove the extensions/firefox/README.mozilla file (bug 1778567 follow-up)
With the changes made in [bug 1778567](https://bugzilla.mozilla.org/show_bug.cgi?id=1778567), it no longer seems correct to overwrite the mozilla-central file.
2022-08-09 13:13:39 +02:00
Jonas Jenwald
48c64c6c8d Bug 1757527 - Slightly reduce (repeated) message passing overhead when localizing the PDF Viewer 2022-03-10 10:20:34 +01:00
Jonas Jenwald
56e1d7746a Re-factor the default preferences generation to support build targets (PR 10548)
Originally the default preferences where simply placed in a JSON-file, checked into the repository, which over time became impractical, annoying, and error-prone to maintain; please see PR 10548.
While that improved the overall situation a fair bit, it however inherited one quite unfortunate property of the old JSON-based solution[1]: It's still not possible for *different* build targets to specify their *own* default preference values.

With some preferences, such as e.g. `enableScripting`, it's not inconceivable that you'd want to (at least) support build-specific default preference values. Currently that's not really possible, which is why this PR re-factors the default preferences generation to support this.

---
[1] This fact isn't really clear from the `AppOptions` implementation, unless you're familiar with the `gulpfile.js` code, which could lead to some confusion for those new to this part of the code-base.
2021-03-20 11:50:48 +01:00
Jonas Jenwald
5b5061afa8 Enable the ESLint no-var rule globally
A significant portion of the code-base has now been converted to use `let`/`const`, rather than `var`, hence it should be possible to simply enable the ESLint `no-var` rule globally.
This way we can ensure that new code won't accidentally use `var`, and it also removes the need to manually enable the rule in various folders.

Obviously it makes sense to continue the efforts to replace `var`, but that should probably happen on a file and/or folder basis.

Please note that this patch excludes the following code:
 - The `extensions/` folder, since that seemed easiest for now (and I don't know exactly what the support situation is for the Chromium-extension).

 - The entire `external/` folder is ignored, since most of it's currently excluded from linting.
   For the code that isn't imported from elsewhere (and should be ignored), we should probably (at some point) bring the code up to the same linting/formatting standard as the rest of the code-base.

 - Various files in the `test/` folder are ignored, as necessary, since the way that a lot of this code is loaded will require some care (or perhaps larger re-factoring) when removing `var` usage.
2021-03-13 16:12:53 +01:00
Jonas Jenwald
426945b480 Update Prettier to version 2.0
Please note that these changes were done automatically, using `gulp lint --fix`.

Given that the major version number was increased, there's a fair number of (primarily whitespace) changes; please see https://prettier.io/blog/2020/03/21/2.0.0.html
In order to reduce the size of these changes somewhat, this patch maintains the old "arrowParens" style for now (once mozilla-central updates Prettier we can simply choose the same formatting, assuming it will differ here).
2020-04-14 12:28:14 +02: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
b663cec383 [Firefox] Stop fetching the chrome.properties files during gulp importl10n (PR 9566 follow-up)
With the removal of the (standalone) Firefox building code in PR 9566 (a year and a half ago), these files are now completely unused in the GitHub repository[1].
Hence it doesn't really seem necessary to keep fetching them with `gulp importl10n`, and the existing files in the `l10n` folder can also be removed (thanks to version control, they're easy enough to restore should the need ever arise).

The patch also allows an additional simplification, for the `gulp locale` and `gulp mozcentral` commands, since it's now possible to stop writing `l10n` files to the `extensions/firefox/` folder and instead just copy them similar to other build targets.

---
[1] They're obviously still used in `mozilla-central`, for fallback messages displayed through `PdfStreamConverter.jsm`, but that doesn't make it necessary to keep them *here* as far as I'm concerned.
2019-10-17 12:27:11 +02:00
Jonas Jenwald
8a057dcf90 [Firefox] Stop building the metadata.inc/chrome.manifest.inc files during gulp locale (PR 9566 follow-up)
With the removal of the (standalone) Firefox building code in PR 9566 (a year and a half ago), these files are now completely unused.
Hence it doesn't really make sense to keep building them as part of `gulp locale`, and the existing files in the `l10n` folder can also be removed (thanks to version control, they're easy enough to restore should the need ever arise).
2019-10-17 11:49:30 +02:00
Jonas Jenwald
d63da81e7c Update the eslint-plugin-mozilla to the latest version (PR 10905 follow-up)
This required adding a number of additional dependencies, based on https://dxr.mozilla.org/mozilla-central/rev/4aed8e10318f38571712350856bf9e61c5f84e1f/tools/lint/eslint/eslint-plugin-mozilla/package.json#32-37

Since this, implicitly, enabled "prettier"[1] for the `extensions/firefox` directory a couple of small code changes were necessary as well.

---
[1] Generally speaking I'm wondering if that name is deliberately ironic, since the style it enforces is often times extremely weird and ugly :-P
2019-09-07 12:52:37 +02:00
Jonas Jenwald
0f0650f426 Generate the default_preferences.json file from AppOptions
Currently any editing of the preferences require updates in *three* separate files, which isn't a great developer experience to say the least.

This has annoyed me sufficiently to write this patch, which moves the definition of all preferences into `AppOptions` and adds a new `gulp` task to generate the `default_preferences.json` file for the builds where it's needed.
2019-02-14 20:40:34 +01:00
Jonas Jenwald
249b199ff1 Stop bundling the ReadableStream polyfill in MOZCENTRAL builds (PR 10470 follow-up)
Based on the discussion in https://bugzilla.mozilla.org/show_bug.cgi?id=1521413, this patch simply removes the `ReadableStream` polyfill completely from MOZCENTRAL builds.

With this patch, the size of the `gulp mozcentral` build target is thus further reduced (building on PR 10470):

|       | `build/mozcentral`
|-------|-------------------
|master |   3 339 666
|patch  |   3 209 572
2019-01-23 20:33:20 +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
Brendan Dahl
a7a034d803
Merge pull request #9566 from brendandahl/remove-ff-ext
Remove the Firefox extension building code.
2018-04-03 13:45:38 -07:00
Wojciech Maj
ea2850e9a7 Fix typos 2018-04-01 23:20:41 +02:00
Brendan Dahl
121e43685f Remove the Firefox extension building code.
Firefox no longer supports this legacy extension and it is a pain to
sync changes from here and mozilla central.
2018-03-30 16:27:50 -07:00
Jonas Jenwald
76250b923f [Firefox addon] Refactor bundling of the default_preferences.json file 2018-03-16 16:46:57 +01:00
Jonas Jenwald
8b2c46dce7 Upstream the changes from: Bug 888600 - Move ContentFrameMessageManager to WebIDL. Part 6: Mark some IDL interfaces as non-scriptable. r=bz.
Please see:
https://bugzilla.mozilla.org/show_bug.cgi?id=888600
https://hg.mozilla.org/mozilla-central/rev/83c87140dc3d
2018-02-28 11:00:55 +01:00
Jonas Jenwald
a30c184f1f Upstream the changes from: Bug 1440284 - change this.EXPORTED_SYMBOLS back to var EXPORTED_SYMBOLS in JS modules, r=mccr8.
Please see:
https://bugzilla.mozilla.org/show_bug.cgi?id=1440284
https://hg.mozilla.org/mozilla-central/rev/b599a95ce057

For consistency, the patch also updates the `PdfJsTelemetry-stub.jsm` file.
2018-02-26 17:44:48 +01:00
Jonas Jenwald
68077f61f1 Upstream the changes from: Bug 792808 - Change PdfStreamConverter.jsm to import and instantiate XHRs from global properties rather than using Cc.createInstance(Ci.nsIXMLHttpRequest); r=mossop
Please see:
https://bugzilla.mozilla.org/show_bug.cgi?id=792808
https://hg.mozilla.org/mozilla-central/rev/56f9de9da69a

Fixes 9499.
2018-02-26 17:34:04 +01:00
Jonas Jenwald
59028bac42 Upstream the changes from: Bug 1432992 - Remove definitions of Ci, Cr, Cc, and Cu
Please see:
 - https://bugzilla.mozilla.org/show_bug.cgi?id=1432992
 - https://hg.mozilla.org/integration/autoland/rev/b38d59f71915
2018-02-09 12:49:02 +01:00
Jonas Jenwald
77135a2bc4 [Firefox addon] Adjust the minVersion numbers in install.rdf and update.rdf
After the latest update of the minimum supported Firefox version, the development addon is no longer being signed. Hence this patch attempts to address that, by pinning the `minVersion` to a specific version number instead.

*Please note:* The version numbers were taken from https://addons.mozilla.org/en-US/firefox/pages/appversions/, so it ought to have worked.
2018-02-05 13:56:34 +01:00
Tim van der Meij
db9f71fe6b
Merge pull request #9433 from Snuffleupagus/addon-minimum-nightly
[Firefox addon] Change the minimum supported version to Firefox Nightly, and remove no longer needed fallback code
2018-02-04 16:24:39 +01:00
Jonas Jenwald
712090eff8 Upstream the changes from: Bug 1339461 - Convert foo.indexOf(...) == -1 to foo.includes() and implement an eslint rule to enforce this
Yet another case where PDF.js code was modified in `mozilla-central` without the changes happening in the GitHub repo first; *sigh*.
If we don't upstream at least the changes in `extensions/firefox/`, any future update of PDF.js in `mozilla-central` will be blocked.

Please see:
 - https://bugzilla.mozilla.org/show_bug.cgi?id=1339461
 - https://hg.mozilla.org/mozilla-central/rev/d5a5ad1dbbf2
2018-02-04 14:59:27 +01:00
Jonas Jenwald
986c8b56ca Update the eslint-plugin-mozilla package to the latest version
With the updated compatibility for the addon, we can thus remove a few no longer needed exceptions from `extensions/firefox/.eslintrc`.
2018-02-04 14:07:18 +01:00
Jonas Jenwald
4db49b6613 Upstream the changes from: Bug 1431533 - Add ChromeUtils helpers for lazy module import
Please see:
 - https://bugzilla.mozilla.org/show_bug.cgi?id=1431533
 - https://hg.mozilla.org/mozilla-central/rev/e6a7b5e11ba8
 - https://groups.google.com/forum/#!topic/mozilla.dev.platform/xQaTdsrbd-g
2018-02-04 14:07:18 +01:00
Jonas Jenwald
08b2e25ac1 [Firefox addon] Remove no longer needed fallback code for older versions of Firefox 2018-02-04 14:07:18 +01:00
Jonas Jenwald
d1ffd61093 [Firefox addon] Change the minimum supported version to (the current) Firefox Nightly release
At this point in time, trying to keep the development addon compatible with prior Firefox versions is already quite difficult and will become even harder very soon.

Please keep in mind that since Firefox 57, only WebExtensions are allowed/possible to install. The only exceptions are Firefox Nightly, with the `xpinstall.signatures.required` preference[1] set to `false`, and the (as of this writing) current ESR release.[2]

With the current compatibility situation, we thus need to effectively support both Nightly *and* ESR in the addon, while trying to keep up with current/upcoming changes in `mozilla-central`. With old addons no longer being officially supported, the amount of old code being removed/refactored is now increasing quite quickly.

*Please note:* The changes proposed here was to a large extent prompted by bugs such as:
 - https://bugzilla.mozilla.org/show_bug.cgi?id=1431533 (already landed)
 - https://bugzilla.mozilla.org/show_bug.cgi?id=767640 (already landed)
 - https://bugzilla.mozilla.org/show_bug.cgi?id=1432992 (still open)

Upstreaming all of those changes for the `MOZCENTRAL` version of PDF.js, while also keeping the Firefox addon running in older versions of the browser, would quickly become non-trivial.
Since we're using the ruleset from `eslint-plugin-mozilla` for the addon files, which is enforced in `mozilla-central`, we must ensure that the neccessary changes are upstreamed to the PDF.js repo such that the `mozilla-central` version of PDF.js can still be updated without failures.

Trying to feature detect, for the `FIREFOX` build target, some of the changes in the referenced bugs would probably become both quite messy and (not to mention) difficult. E.g. with the upcoming and automatically defined `Cc, Ci, Cu, Cr` variables, any sort of feature detection might be tricky since those need to be defined in the global scope of the files in question.

Finally, given the amount of effort that we'd now need to spend to even attempt to keep the Firefox addon compatible, I just don't think it's worth the effort any more. Especially since the number of people that have, thus far, been doing this work is *very* low and those resources would be better spend elsewhere.
Unfortunately, this probably means that the development addon will no longer be compatible with release versions of Seamonkey. However the README has already mentioned, for quite some time, that support isn't guaranteed.

*In closing:* For all of the reasons mentioned above, I thus propose that we reduce the maintenance burden of the Firefox addon by only supporting the current Firefox Nightly.

---

[1] While the preference exists, and can be toggled, its value is ignored in non-Nightly versions of Firefox.

[2] There's unbranded builds of e.g. the release/beta versions of Firefox, where old and non-WebExtensions addons can be installed. However those builds can probably be assumed to be officially unsupported, and thus not recommended for users.
2018-02-04 14:07:17 +01:00
Jonas Jenwald
2db75a2a3a Update the ESLint dependencies, and also tweak the no-multiple-empty-lines rules
Since multiple empty lines is virtually unused in the code-base, and the few cases that do exist look like "typos", let's enforce greater consistency here; please see https://eslint.org/docs/rules/no-multiple-empty-lines.
2018-01-03 13:32:57 +01:00
Mark Banner
63c6157bdf Switch to using mozilla/recommended configuration for extensions/firefox. 2017-12-08 18:58:48 +00:00
Jonas Jenwald
b15de69c52 [Firefox addon] Temporarily disable the ESLint semi rule, around the DEFAULT_PREFERENCES declaration, to prevent mozilla-central test errors
While this doesn't actually fix the underlying issue, it should prevent the ESLint errors and thus make future PDF.js updates easier.
Compared to updating (and testing) the preprocessor, this seems like a reasonable workaround given its simplicity.
2017-12-05 20:52:39 +01:00
Mark Banner
3065197cc4 Update eslint-plugin-mozilla, and enable mozilla/use-services rule. 2017-11-24 16:58:36 +00:00
Brendan Dahl
61dd7d1c3a Accumulate streamed PDF data into array of buffers. 2017-11-08 20:32:29 -08:00
Doug Thayer
0f9f0f8a9b Cache PdfJs's enabled setting for delayed init
See Bug 1389443 for more information. This allows us to register
PdfJs without waiting for file IO in nsHandlerService to finish.
Once that file IO is finished, we can set everything up properly
and double-check the registration.
2017-08-22 12:20:58 -07:00
Brendan Dahl
5834ef6ff2 Bug 1353029 - Pass PdfJs.enabled into child on change. 2017-06-05 11:38:40 -07:00
Jonas Jenwald
4f48c8198c Fix inconsistent spacing and trailing commas in objects in extensions/ files, so we can enable the comma-dangle and object-curly-spacing ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing

Given that we currently have quite inconsistent object formatting, fixing this in in one big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.

Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.

```diff
diff --git a/extensions/firefox/content/PdfStreamConverter.jsm b/extensions/firefox/content/PdfStreamConverter.jsm
index ea91a71a..0d59dad1 100644
--- a/extensions/firefox/content/PdfStreamConverter.jsm
+++ b/extensions/firefox/content/PdfStreamConverter.jsm
@@ -773,7 +773,8 @@ class RequestListener {
         response = function sendResponse(aResponse) {
           try {
             var listener = doc.createEvent("CustomEvent");
-            let detail = Cu.cloneInto({ response: aResponse, }, doc.defaultView);
+            let detail = Cu.cloneInto({ response: aResponse, },
+                                      doc.defaultView);
             listener.initCustomEvent("pdf.js.response", true, false, detail);
             return message.dispatchEvent(listener);
           } catch (e) {
```
2017-06-01 13:25:24 +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
cbba74f474 Revert "Upstream changes from: Bug 1319111 - Expose result principal URL ("final channel URL") on LoadInfo, convert current consumers of LOAD_REPLACE" 2017-05-18 12:08:05 +02:00
Mark Banner
2e9ae50a3a Use eslint-plugin-mozilla and the webextensions environment to avoid defining globals in each file. 2017-05-17 10:30:46 +01:00
Honza Bambas :mayhemer
20aa8d74e9 Upstream changes from: Bug 1319111 - Expose result principal URL ("final channel URL") on LoadInfo, convert current consumers of LOAD_REPLACE
This is a downstream change introduced in [1]. That mozilla bug is adding a new property to channel's loadinfo object (nsILoadInfo) that protocol handlers has to set on channels when originalURI on the result channel is set to a different URI than the channel has been created for.

Existence of the new property on nsILoadInfo depends on landing [1].

[1] https://bugzilla.mozilla.org/show_bug.cgi?id=1319111
2017-05-07 21:38:10 +02:00
Jonas Jenwald
8e976d7110 [Firefox addon] Replace a bind(this) statement with an arrow function in PdfStreamConverter.jsm (issue 8343)
Please note that I used the addon debugger to set a breakpoint in the `unload` function, in order to ensure that `this` still correctly refers to the `FindEventManager` scope.
2017-04-30 13:26:34 +02:00
Jonas Jenwald
b3582ccbad Add the commit hash to the README.mozilla file (issue 8347) 2017-04-27 23:01:22 +02:00
Jonas Jenwald
3b59169ffc [Firefox addon] Upstream changes from: Bug 1346616 - Migrate callsites that are retrieving requested locale from pref, to use LocaleService::GetRequestedLocales
With [bug 1346616](https://bugzilla.mozilla.org/show_bug.cgi?id=1346616) and [this commit](https://hg.mozilla.org/mozilla-central/rev/39a903b099a6#l7.2), it's apparently no longer recommended to check the `general.useragent.locale` pref directly, but instead the `Services.locale.getRequestedLocale()` function should be used.

In this case, it's at least really easy to feature detect this properly :-)
2017-04-18 23:34:48 +02:00
Jonas Jenwald
cf87c9bba2 [Firefox addon] Upstream changes from: Bug 1356569 - Remove optional trailing parameters (issue 8310)
In https://bugzilla.mozilla.org/show_bug.cgi?id=1355216, the *third* parameter of `Services.obs.addObserver` was made optional.
However, omitting it in Firefox versions *without* that patch causes failures that completely prevents the addon from working (it won't even load).

As far as I can tell, there isn't *any* way to detect ahead of time if the third parameter can be safely omitted, hence we're forced to fallback to manually checking the version number :-(

*Note:* Since the `PdfJs.jsm` file is only used in the `MOZCENTRAL` build, we at least don't need to add any compatibility hacks there.
2017-04-18 20:51:17 +02:00
Tim van der Meij
e7a3ea29aa
Firefox extension: remove unused preference cleanup from bootstrap.js
The comment for the removal has been added three years ago, so we can
safely remove this now.
2017-04-14 23:49:01 +02:00