Commit Graph

611 Commits

Author SHA1 Message Date
Jonas Jenwald
30c06849d8 Rotate landscape pages, during printing, by default in the viewer (enablePrintAutoRotate = true)
While this will perhaps not be perfect for *every* PDF document with mixed page orientation, based on the large number of bugs/issues seen over the years I'm however pretty convinced that it'll be an overall improvement in a majority of cases.

In order to improve things further, we'd probably need Firefox to support e.g. `@page` such that the viewer can provide better information to the print engine.
2021-03-19 12:39:37 +01:00
Jonas Jenwald
2d727e6e68 Enable scripting by default in the viewer (PR 13053 follow-up)
Given that https://bugzilla.mozilla.org/show_bug.cgi?id=1699219 has enabled scripting for all Firefox-channels, it seems reasonable to simply set `enableScripting = true` unconditionally in the viewer preferences/options.

For now, this patch leaves the standalone viewer-components alone (such as e.g. `BaseViewer`), and if those are used scripting will thus have to be manually enabled (see e.g. the "simpleviewer"/"singlepageviewer" examples).
2021-03-17 21:14:08 +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
4db7330677 Enable ESLint rules that no longer need to be disabled on a directory/file-basis
Given that browsers/environments without native support for both arrow functions and object shorthand properties are no longer supported in PDF.js, please refer to the compatibility information below, we can now enable a fair number of ESLint rules and also simplify/remove some `.eslintrc` files.

With the exception of the `no-alert` cases, all code changes were made automatically by using `gulp lint --fix`.

 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#browser_compatibility
2021-01-22 17:47:03 +01:00
Jonas Jenwald
40a4d53fb3 Add a new preference, viewerCssTheme, to allow forcing the use of the light/dark viewer CSS themes (issue 12290)
While this does work pretty well in my quick testing, it's *very much* a hack since as far as I can tell there's no support in the CSS specification for using e.g. a CSS variable to override a `@media (prefers-color-scheme: dark) {...}` block.

The solution implemented here is thus to *edit* the viewer CSS, by either removing the entire `@media ...` block in light-mode or by ensuring that its rules become *unconditionally* applied in dark-mode.
To simplify the overall implementation, since all of this does seem like somewhat of an edge-case, the `viewerCssTheme` preference will *only* be read during viewer initialization. (Similar to many other existing preferences, a reload is thus required when changing it.)
2020-11-16 21:13:13 +01:00
Calixte Denizet
e76a96892a JS - Add the basic architecture to be able to execute embedded js 2020-10-21 19:00:56 +02:00
Jonas Jenwald
8aa2718d22 Re-format all web/*.css files using Stylelint/Prettier
This was done automatically, using `gulp lint --fix`.
2020-08-30 21:49:08 +02:00
Jonas Jenwald
7b5a540a52 Add (basic) support for Stylelint, to allow linting of CSS files
This is *similar* to the existing linting for JavaScript files, but covers CSS files instead.
While there's a lot of rules that could potentially be used, the main advantage of using Stylelint is that it has Prettier integration which means that we can automatically enforce a *consistent* style for our CSS files as well.

As a proof of concept, this patch is purposely limited to:
 - Adding a simple rule, here `block-no-empty` is chosen; see https://stylelint.io/user-guide/rules/block-no-empty
 - Adding Prettier integration, to unify the style of our CSS files.

Please find additional information at https://stylelint.io/
2020-08-30 21:48:35 +02:00
Brendan Dahl
da62be0685 Enable renderInteractiveForms by default. 2020-08-12 10:28:27 -07:00
Aki Sasaki
04db9d902f ignore isFirstPagePortrait in getPagesOverview
The current behavior for `getPagesOverview` assumes we want to only
auto-rotate if:

- `enablePrintAutoRotate` is `true`
- `isFirstPagePortrait !== isPortraitOrientation(size)`

This second check is what is breaking #9297. The two PDFs linked have a
landscape orientation first page, as well as subsequent pages. Since
`false === false`, we print portrait.

Let's drop the comparison with `isFirstPagePortrait`, and print
landscape if `!isPortraitOrientation(size)`.

Fixes #9297.
2020-07-17 08:22:04 -07:00
Wojciech Maj
78970bbbe1
Replace non-inclusive "whitelist" term with "allowlist" 2020-06-29 17:15:14 +02: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
8521f70157 Add a new pdfjs.enablePermissions preference, off by default, to allow the PDF documents to disable copying in the viewer (bug 792816)
*Please note:* Most of the necessary API work was done in PR 10033, and the only remaining thing to do here was to implement it in the viewer.

The new preference should thus allow e.g. enterprise users to disable copying in the viewer, for PDF documents whose permissions specify that.

In order to simplify things the "copy"-permission was implemented using CSS, as suggested in https://bugzilla.mozilla.org/show_bug.cgi?id=792816#c55, which should hopefully suffice.[1]
The advantage of this approach, as opposed to e.g. disabling the `textLayer` completely, is first of all that it ensures that searching still works correctly even in copy-protected documents. Secondly this also greatly simplifies the overall implementation, since it doesn't require a lot of code for something that's disabled by default.

---
[1] As the discussion in the bug shows, this kind of copy-protection is not very strong and is also generally easy to remove/circumvent in various ways. Hence a simple solution, targeting "regular"-users rather than "power"-users is hopefully deemed acceptable here.
2020-04-08 18:20:47 +02:00
Jonas Jenwald
664b79abe0 [api-minor] Remove the eventBusDispatchToDOM option/preference, and thus the general ability to dispatch "viewer components" events to the DOM
This functionality was only added to the default viewer for backwards compatibility and to support the various PDF viewer tests in mozilla-central, with the intention to eventually remove it completely.
While the different mozilla-central tests cannot be *easily* converted from DOM events, it's however possible to limit that functionality to only MOZCENTRAL builds *and* when tests are running.

Rather than depending of the re-dispatching of internal events to the DOM, the default viewer can instead be used in e.g. the following way:
```javascript
document.addEventListener("webviewerloaded", function() {
  PDFViewerApplication.initializedPromise.then(function() {
    // The viewer has now been initialized, and its properties can be accessed.

    PDFViewerApplication.eventBus.on("pagerendered", function(event) {
      console.log("Has rendered page number: " + event.pageNumber);
    });
  });
});
```
2020-03-29 12:24:46 +02:00
Jonas Jenwald
03f5dd2cf2 Add a ignoreDestinationZoom option/preference to allow users to preserve the current zoom level when navigating to internal destinations (issue 5064, 11606) 2020-02-27 08:42:50 +01:00
Jonas Jenwald
c591826f3b Enable the no-nested-ternary ESLint rule (PR 11488 follow-up)
This rule is already enabled in mozilla-central, and helps avoid some confusing formatting, see https://searchfox.org/mozilla-central/rev/9e45d74b956be046e5021a746b0c8912f1c27318/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js#209-210

With the recent introduction of Prettier some of the existing nested ternary statements became even more difficult to read, since any possibly helpful indentation was removed.
This particular ESLint rule wasn't entirely straightforward to enable, and I do recognize that there's a certain amount of subjectivity in the changes being made. Generally, the changes in this patch fall into three categories:
 - Cases where a value is only clamped to a certain range (the easiest ones to update).
 - Cases where the values involved are "simple", such as Numbers and Strings, which are re-factored to initialize the variable with the *default* value and only update it when necessary by using `if`/`else if` statements.
 - Cases with more complex and/or larger values, such as TypedArrays, which are re-factored to let the variable be (implicitly) undefined and where all values are then set through `if`/`else if`/`else` statements.

Please find additional details about the ESLint rule at https://eslint.org/docs/rules/no-nested-ternary
2020-01-14 17:49:39 +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
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
Tim van der Meij
ca3a58f93a
Consistently use @returns for returned data types in JSDoc comments
Sometimes we also used `@return`, but `@returns` is what the JSDoc
documentation recommends. Even though `@return` works as an alias, it's
good to use the recommended syntax and to be consistent within the
project.
2019-10-13 13:58:17 +02:00
Tim van der Meij
efd331daa1
Consistently use string for string data types in JSDoc comments
Sometimes we also used `String`, but `string` is the what the JSDoc
documentation recommends.
2019-10-13 13:58:17 +02:00
Rob Wu
501e0b3db7 [CRX] Ignore auto-generated <embed> from Chrome
Fixes #11137
2019-09-11 15:56:02 +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
Rob Wu
32c1a1d329 [CRX] Preserve referrer in Chrome 72+
Fixes #10645
2019-05-29 11:28:38 +02:00
Jonas Jenwald
173fbef05b Enable the consistent-return ESLint rule
This rule is already enabled in mozilla-central, and helps ensure more consistent functions/methods, see https://searchfox.org/mozilla-central/rev/b9da45f63cb567244933c77b2c7e827a057d3f9b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js#119-120

Please see https://eslint.org/docs/rules/consistent-return for additional information.
2019-05-11 14:27:21 +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
2b4709d1a8 [Chrome extension] Add missing "type" entry for the viewOnLoad preference in the preferences_schema.json file (PR 10502 follow-up)
Fixes 10538
2019-02-11 10:56:43 +01:00
Jonas Jenwald
4d4c98d1eb Attempt to migrate the old showPreviousViewOnLoad/disablePageMode preferences to the new viewOnLoad preference
This patch ignores the recently added `disableOpenActionDestination` preference, since the latest PDF.js version found on the "Chrome Web Store" doesn't include it.
2019-02-02 10:21:18 +01:00
Jonas Jenwald
6806248030 Modify a number of the viewer preferences, whose current default value is 0, such that they behave as expected with the view history
The intention with preferences such as `sidebarViewOnLoad`/`scrollModeOnLoad`/`spreadModeOnLoad` were always that they should be able to *unconditionally* override their view history counterparts.
Due to the way that these preferences were initially implemented[1], trying to e.g. force the sidebar to remain hidden on load cannot be guaranteed[2]. The reason for this is the use of "enumeration values" containing zero, which in hindsight was an unfortunate choice on my part.
At this point it's also not as simple as just re-numbering the affected structures, since that would wreak havoc on existing (modified) preferences. The only reasonable solution that I was able to come up with was to change the *default* values of the preferences themselves, but not their actual values or the meaning thereof.

As part of the refactoring, the `disablePageMode` preference was combined with the *adjusted* `sidebarViewOnLoad` one, to hopefully reduce confusion by not tracking related state separately.

Additionally, the `showPreviousViewOnLoad` and `disableOpenActionDestination` preferences were combined into a *new* `viewOnLoad` enumeration preference, to further avoid tracking related state separately.
2019-02-02 10:21:18 +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
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
Jonas Jenwald
a7e70a50f5 Add OpenAction destination support, off by default, to the viewer
Given that it's really not clear to me if this is actually desired functionality in the default viewer, and considering that it doesn't fit in *great* with the way that `PDFHistory` is initialized, this feature is currently off by default[1].

---
[1] It's controlled with the `disableOpenActionDestination` Preference/AppOption.
2018-12-19 11:45:17 +01:00
Jonas Jenwald
0b1f41c5b3 Add general support for re-dispatching events, on EventBus instances, to the DOM
This patch is the first step to be able to eventually get rid of the `attachDOMEventsToEventBus` function, by allowing `EventBus` instances to simply re-dispatch most[1] events to the DOM.
Note that the re-dispatching is purposely implemented to occur *after* all registered `EventBus` listeners have been serviced, to prevent the ordering issues that necessitated the duplicated page/scale-change events.

The DOM events are currently necessary for the `mozilla-central` tests, see https://hg.mozilla.org/mozilla-central/file/tip/browser/extensions/pdfjs/test, and perhaps also for custom deployments of the PDF.js default viewer.

Once this have landed, and been successfully uplifted to `mozilla-central`, I intent to submit a patch to update the test-code to utilize the new preference. This will thus, eventually, make it possible to remove the `attachDOMEventsToEventBus` functionality.

*Please note:* I've successfully ran all `mozilla-central` tests locally, with these patches applied.

---
[1] The exception being events that originated on the `window` or `document`, since those are already globally available anyway.
2018-08-30 17:28:12 +02:00
Jonas Jenwald
36b683ca55 Provide custom messages for the no-restricted-globals ESLint rule, and refactor the .eslintrc files (PR 9868 follow-up)
Without providing useful (custom) error messages for the `no-restricted-globals` rule, see https://eslint.org/docs/rules/no-restricted-globals, it's quite likely that the rule will be incorrectly disabled rather than the required globals being imported as intended.

To reduced duplication of the `no-restricted-globals` rule in multiple `.eslintrc` files, it's instead moved to the top-level `.eslintrc` file and disabled as needed on a folder/file basis outside of `/src` and `/web`.
2018-07-23 14:10:13 +02:00
Brendan Dahl
7892122201
Merge pull request #9595 from Rob--W/crx-ftp-file
Disable ftp support in Chrome 59+, add file chooser at file
2018-06-15 14:48:19 -07:00
Ryan Hendrickson
d7c051e807 Add preferences for default scroll/spread modes
This commit adds `scrollModeOnLoad` and `spreadModeOnLoad` preferences
that control the default viewer state when opening a new document for
the first time.

This commit also contains a minor refactoring of some of the option UI
rendering code in extensions/chromium/options/options.js, as I couldn't
bear creating two more functions nearly identical to the four that
already existed.
2018-05-14 23:10:33 -04: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
Rob Wu
df516c0a52 [CRX] Stop intercepting ftp in Chrome 59+
The extension cannot easily fetch data from ftp:-resources any more
in Chrome 59+. So don't intercept such URLs.
2018-03-21 15:44:31 +01: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
Rob Wu
94a49fa048 [CRX] Make textLayerMode pref visible and add migration logic
In a1cfa5f4d7, the textLayerMode
preference was introduced, to replace the disableTextLayer and
enhanceTextSelection preferences.

As a result, the text selection preference was no longer visible
in Chrome (because preferences are only rendered by default for
boolean preferences, not for enumerations).

This commit adds the necessary bits to
extensions/chromium/options/options.{html,js}
so that the textLayerMode preference can be changed again.

Also, migration logic has been added to move over preferences
from the old to the new names:
- In web/chromecom.js, the logic is added to translate
  preferences that were set by an administrator (it is read-only,
  so this layer is unavoidable).
- In extensions/chromium/options/migration.js, similar logic is
  added, except in this case the preference storage is writable,
  so this migration logic happens only once.

The "enhanced text selection" mode is still experimental, so it
has been marked as experimental to signal that there may be bugs.
The list of tasks that block promotion to stable is at #7584.
2018-02-22 14:39:58 +01:00
Rob Wu
fc83ce1aae [CRX] Restore migration logic for managed enableHandToolOnLoad pref
This partially reverts df0836b9b8.
The entry in preferences_schema.json is restored because that is
required to make managed preferences visible to the extension code.

The default key is still removed from default_preferences.json,
because this change only concerns the Chrome extension, not the
other parts of PDF.js. To account for the missing key, the
deprecated key was added back in chromecom.js

The key needs to be restored in preferences_schema.json too,
because that's the only way to make managed preferences visible.

I'm using `Object.assign`, which was introduced in Chrome 45,
so the preference module will break in Chrome 45 and earlier.
This is fine, because we do not support Chrome before 49.
2018-02-18 11:56:27 +01:00
Tim van der Meij
538dda1096
Merge pull request #9479 from Snuffleupagus/refactor-viewer-options
[api-major] Refactor viewer components initialization to reduce their dependency on the global `PDFJS` object
2018-02-14 22:47:33 +01:00
Jonas Jenwald
a1cfa5f4d7 Replace the disableTextLayer and enhanceTextSelection options/preferences with a single textLayerMode option/preference
Rather than having two different (but connected) options for the textLayer, I think that it makes sense to try and unify this. For example: currently if `disableTextLayer === true`, then the value of `enhanceTextSelection` is simply ignored.

Since PDF.js version `2.0` already won't be backwards compatible in lots of ways, I don't think that we need to worry about migrating existing preferences here.
2018-02-13 16:56:54 +01:00
Jonas Jenwald
90ab9bafff Remove the actual enableHandToolOnLoad preference (PR 9040 follow-up)
This should have been removed as part of PR 9040, but was simply overlooked.
2018-02-13 09:36:53 +01:00
Jonas Jenwald
1cf116ab88 Enable the mozilla/use-includes-instead-of-indexOf ESLint rule globally
This rule is available from https://www.npmjs.com/package/eslint-plugin-mozilla, and is enforced in mozilla-central. Note that we have the necessary `Array`/`String` polyfills and that most cases have already been fixed, see PRs 9032 and 9434.
2018-02-10 23:24:50 +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
Rob Wu
352389c0c6 [CRX] Expose some headers to fetch requests 2018-02-06 15:06: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
Rob Wu
7268f4ec1b [CRX] Add comment about ftp compatibility 2018-01-26 15:54:35 +01:00
Rob Wu
838573abd4 [CRX] Clean up file/ftp handler
Merge ftp and file handler now their implementations are identical.
Remove redundant comment (the referenced Chrome bug has been fixed
a long time ago - https://crbug.com/302548 ).
2018-01-26 15:54:35 +01:00
Rob Wu
85378fc982 [CRX] Remove feature-detect.js
All detected features were introduced in Chrome 35.
We don't support Chrome 34 and earlier, so drop the legacy code.
2018-01-26 15:54:35 +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
Jonas Jenwald
20d6286cce Add support for, the API property, PageMode in the viewer (issue 8657)
Note that the PageMode, as specified in the API, will only be honoured when either: the user hasn't set the `sidebarViewOnLoad` preference to a non-default value, or a non-default `sidebarView` entry doesn't exist in the view history, or the "pagemode" hash parameter is included in the URL.

Since this is new functionality, the patch also includes a preference (`disablePageMode`), to make it easy to opt-out of this functionality if the user/implementor so wishes.
2017-07-19 16:58:25 +02:00
Rob Wu
19549bb7d6 [CRX] Integrate cursorToolOnLoad pref + migration logic
Add UI for the cursorToolOnLoad pref in the UI of the Chrome extension.

Add logic to migrate the enableHandToolOnLoad pref to cursorToolOnLoad.
For past values in the mutable extension storage area:
1. If enableHandToolOnLoad=true, save cursorToolOnLoad=1.
2. Remove enableHandToolOnLoad.

For the managed extension storage, which is immutable since it is based
on administrative policies, use the following logic:
1. If enableHandToolOnLoad=true and cursorToolOnLoad=0 (default).
   set cursorToolOnLoad=0 and assume enableHandToolOnLoad=false.
2. As usual, managed preferences can (and will) be overridden by the user.

The first migration logic is in extensions/chromium/options/migration.js
and can be removed after a few months / less than many years.

The second migration logic is in web/chromecom.js, and should be kept
around for a long while (many years).

The need for this migration logic arises from the change by:
https://github.com/mozilla/pdf.js/pull/7635
2017-07-15 01:50:15 +02:00
Nimesh Solanki
e004b3cfab update inconsistent names 2017-07-11 00:57:39 +05:30
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
36c2791296 Unify handling of various cursor tools, e.g. the current Hand Tool and a possible future Zoom Tool, in a new PDFCursorTools module
With the current way that the `HandTool` is implemented, if someone would try to also add a Zoom tool (as issue 1260 asks for) that probably wouldn't work very well given that you'd then have two cursor tools which may not play nice together.
Hence this patch, which attempts to refactor things so that it should be simpler to add e.g. a Zoom tool as well (given that that issue is marked as "good-beginner-bug", and I'm not sure if that really applies considering the current state of the code).

Note that I personally have no interest in implementing a Zoom tool (similar to Adobe Reader) since I wouldn't use it, but I figured that it can't hurt to make this code a bit more future proof.
2017-05-22 00:51:01 +02: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
Tim van der Meij
60c232bc8c Merge pull request #8353 from Snuffleupagus/eslint_object-shorthand
Enable the `object-shorthand` ESLint rule
2017-04-30 21:23:57 +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
7560f12a17 Enable the object-shorthand ESLint rule
Please see http://eslint.org/docs/rules/object-shorthand.

Unfortunately, based on commit 9276d1dcd9, it seems that we still need to maintain compatibility with old Node.js versions, hence certain files/directories that are executed in Node.js are currently exempt from this rule.

Furthermore, since the files specific to the Chromium extension are not run through Babel, the `/extensions/chromium/` directory is also exempt from this rule.
2017-04-30 11:13: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
Georg Fritzsche
4e8cd2b7d3 Rename PdfJsTelemetry-addon.jsm to PdfJsTelemetry-stub.jsm
And remove unused linting comments.
2017-04-12 13:11:04 +02:00
Georg Fritzsche
788fe1f810 Stub out Firefox addon Telemetry wrapper
We are planning to remove the addon histogram APIs from Firefox
Telemetry.
The easy solution here is to just stub out all calls that use them.
2017-04-05 14:17:31 +07:00
Yury Delendik
a2ddf2f9ca Merge pull request #8218 from amccreight/no-sync
Split pdfjschildbootstrap.js to avoid sync IPC
2017-04-03 17:37:22 -05:00
Andrew McCreight
071951d787 Lazily load NetUtil.jsm in PdfStreamConverter.jsm.
This is one step towards not loading NetUtil.jsm at startup in a clean
profile.
2017-04-03 10:33:57 -07:00
Andrew McCreight
740e1ab450 Skip PdfJs.enabled check in bootstrap-enabled.
If we only invoke the bootstrap-enabled script when PdfJs.enabled is
true, then we don't need to check it again in the script.

This avoids a sync IPC call to the parent process.

It also keeps PdfJs.jsm from importing PdfjsContentUtils.jsm in the
child process until it is actually needed, which is one steps towards
not loading it until it is really needed.
2017-03-31 13:22:39 -07:00
Andrew McCreight
d804881151 Split bootstrap script.
pdfjschildbootstrap.js will always be run, but
pdfjschildbootstrap-enabled.js will only be run if PdfJs.enabled is
true. This will let us avoid some work in the child process in the
next patch.

This will need to be landed in the mozilla-central repository at the
same time as a change to nsBrowserGlue.js. See bug 1352218.
2017-03-31 13:22:39 -07:00
Yury Delendik
25873e92f0 Enable babel translation to enable ES module support. 2017-03-27 07:25:09 -05:00
Jonas Jenwald
ebae24cacc Upstream the changes from bug 1345294 - nsIPrefBranch should have methods to get/set unicode strings
Note that in order to not break compatibility for the Firefox addon, the preprocessor is used.

Re: [bug 1345294](https://bugzilla.mozilla.org/show_bug.cgi?id=1345294) and also [this commit](https://hg.mozilla.org/mozilla-central/rev/5a8192a650e9).
2017-03-20 07:36:36 +01:00
Jonas Jenwald
a7c19d9cbb Adjust the yoda ESLint rule to apply to inequalities as well
I happened to notice that some inequalities had the wrong order, and was surprised since I thought that the `yoda` rule should have caught that.
However, reading http://eslint.org/docs/rules/yoda#options a bit more closely than previously, it's quite obvious that the `onlyEquality` option does *exactly* what its name suggests. Hence I think that it makes sense to adjust the options such that only ranges are allowed instead.
2017-03-19 13:27:14 +01:00
Tim van der Meij
cf73f4bc2d Merge pull request #8024 from Rob--W/issue-6643-pdf-attachment-in-pdfjs
Open PDF attachments in the viewer instead of an unconditional download
2017-02-18 21:52:29 +01:00
Tim van der Meij
573236e3ad Merge pull request #8043 from Rob--W/issue6696-auto-rotate-page
Allow automatic print rotation via the enablePrintAutoRotate preference
2017-02-08 23:57:28 +01:00
Rob Wu
ece44d36e8 Allow automatic print rotation via enablePrintAutoRotate 2017-02-08 12:39:24 +01:00
Jonas Jenwald
b898a453f0 [Firefox addon] Remove the unused MOZ_CENTRAL constant
The last (and only) usage of `MOZ_CENTRAL` was removed in PR 3036, so it's been unused for almost four years now.
If we need to have different code-paths for `FIREFOX`/`MOZCENTRAL` builds, the preprocessor should (and has) been used instead.
2017-02-04 17:51:40 +01:00
Rob Wu
d9f90d595d [CRX] Recognize blob and data-URLs in the router
When a blob or data-URL is opened with the extension, viewer.html
rewrites the URL. But when the viewer is refreshed (e.g. F5), Chrome
would fail to display the viewer because the extension router was not
set up to recognize such URLs.

Now it is.
2017-02-04 01:20:17 +01:00