1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-18 14:18:23 +02:00
Commit graph

210 commits

Author SHA1 Message Date
Jonas Jenwald
abcddb51e0 [api-minor] Enable enableAutoLinking by default
It's already enabled by default in Firefox, and since there's no open issues regarding auto-linking I suppose that we can attempt to enable it unconditionally.
2025-03-21 11:49:03 +01:00
Ujjwal Sharma
61ba1ea48c Enable automatic URL linking
Automatically detect links in the text content of a file and automatically
generate link annotations at the appropriate locations to achieve
automatic link detection and hyperlinking.
2025-02-05 16:56:54 +01:00
Calixte Denizet
2f828c7bf4 [Editor] (WIP) Add a new tool in order to add an handwritten signature to a pdf (bug 1942343)
This patch is adding some code in order to extract a drawing as curves from an image.
The algorithm is basically the following:
 - reduce the dimensions
 - make it gray
 - apply a bilateral filter in order to add some blurryness while keeping the edges
 - compute the histogram
 - guess what's the background color which should contain a large majority of the pixels
 - make a binary image
 - extract the contours in using the Suzuki algorithm
 - apply the Douglas-Peucker algorithm in order to reduce the number of points

The algorithm is improvable but it should work pretty well if there's a clear difference between
the background and the drawing.
In a v2 we could use a ML model in order to improve the extraction.

There's few changes related to the UI in order to make the tool usable, but they're very basic
for the moment.
2025-01-29 21:52:14 +01:00
Jonas Jenwald
6f3f3be7a3 Remove the extensions/chromium/.eslintrc file (PR 19029 follow-up)
This file became unused in PR 19029, but we apparently forgot to remove it.
2024-11-16 14:48:44 +01:00
Tim van der Meij
014ce7c1db
Merge pull request #18728 from Rob--W/crx-mv3-fallback-detect-fixup
[CRX] Fix feature detect of DNR responseHeaders option
2024-09-15 15:43:23 +02:00
Rob Wu
3170bf3f69 [CRX] Enable WebAssembly in Chrome extension
After the removal of 'unsafe-eval' CSP in #18651, WebAssembly fails to
load, resulting in issues such as seen in #18457.

Manifest Version 3 does not allow 'unsafe-eval', does accept the more
specific 'wasm-unsafe-eval' as of Chrome 103. Note that manifest.json
already sets minimum_chrome_version to 103.

This patch also adds `object-src 'self'` because it was required until
Chrome 110. As of Chrome 111, the default is `object-src 'self'` and
`object-src` is no longer required. We could drop `object-src` in the
future, but for now we need to include it to support Chrome 103 - 110.
2024-09-15 12:58:38 +02:00
Rob Wu
a91ba11185 [CRX] Fix feature detect of DNR responseHeaders option
Fix regression from #18711. `urlFilter` is a key of `condition`, not of
the `rule`. Consequently, the feature detection method failed to detect
the availability of the feature in Chrome 128+.
2024-09-10 16:05:11 +02:00
Rob Wu
9705169371 [CRX] Detect availability of DNR responseHeaders before use
Critical fix for old but recent Chrome versions; all requests are
otherwise redirected to the viewer.
2024-09-09 14:41:00 +02:00
Rob Wu
4bf7be6427 [CRX] Bump minimum_chrome_version from 88 to 103
The minimum required version is Chrome 103 because wildcard support for
web_accessible_resources[].extension_id was introduced in 103, in
c9caeb1a08

A way to broaden compatibility is to drop that key. By doing so, the
minimum required Chrome version is then 96, because of the
chrome.storage.session API (and declarativeNetRequestWithHostAccess).

Since gulpfile.js already defines "Chrome >= 98" and there is no real
point in expanding support to older versions, I'm just setting the
minimum version to 103.
2024-09-08 16:35:14 +02:00
Rob Wu
b3a0ad09ad [CRX] Add work-around for Chrome crash 2024-09-08 16:35:14 +02:00
Rob Wu
4327502bf3 [CRX] Add fallback PDF detection for Chrome 127- 2024-09-08 16:35:14 +02:00
Rob Wu
3fe256cd0d [CRX] Set manifest_version to 3
- Replace DOM-based pdfHandler.html (background page) with background.js
  (extension service worker).

- Adjust logic of background scripts to account for the fact that the
  scripts can execute repeatedly during a browser session. Primarily,
  register relevant extension event handlers at the top level and use
  in-memory storage.session API to keep track of initialization state.

- Extension URL router: replace blocking webRequest with the service
  worker-specific "fetch" event.

- PDF detection: replace blocking webRequest with declarativeNetRequest.
  This requires Chrome 128+. The next commit will add a fallback for
  earlier Chrome versions.
2024-09-08 16:35:13 +02:00
Rob Wu
7017d8246b [CRX] Replace localStorage in telemetry logic
In MV3, the background script is a service worker. localStorage is not
supported in service workers. Switch to storage.local instead.

Data migration is not implemented because it is not needed due to the
privacy-friendly design of the telemetry: In practice the data is reset
about every 4 weeks, when the major version of Chrome is updated.
2024-09-08 16:35:13 +02:00
Rob Wu
bc4890d4d4 [CRX] Remove restoretab.js logic
restoretab.js was added in https://github.com/mozilla/pdf.js/pull/6233
with the purpose of restoring lost tabs when Chrome closes all extension
tabs when it reloads the extension. This forced reload can happen when
the user toggles the "Allow access to file URLs" option.

This logic does not work any more, and since the use of localStorage is
a blocker in migrating to MV3, this patch just drops the logic.
2024-09-08 16:35:13 +02:00
Rob Wu
23bc46d51a [CRX] Replace deprecated extension.getURL with runtime.getURL 2024-09-08 16:35:13 +02:00
Rob Wu
b23829fc60 [CRX] Drop chrome_style from manifest.json
MV3 does not support chrome_style in options_ui. Remove it and replace
it with the minimal amount of styles that still has some spacing around
the individual settings for readability.
2024-09-08 16:35:13 +02:00
Rob Wu
bd3d993180 [CRX] Use DNR instead of webRequest in preserve-referer
webRequestBlocking is unavailable in MV3. Non-blocking webRequest can
still be used to detect the Referer, but we have to use
declarativeNetRequest to change the Referer header as needed.
2024-09-08 16:35:13 +02:00
Rob Wu
1d545382a3 [CRX] Remove obsolete extension API calls
These work arounds are no longer relevant to the latest Chrome versions.
2024-08-25 22:03:38 +02:00
Rob Wu
683b511f20 [CRX] Remove obsolete manifest features
In preparation for migrating the Chrome extension to Manifest Version 3,
this patch removes parts of the manifest that are obsolete and/or
unsupported in MV3.

Remove ftp mentions: ftp was dropped from 6 years ago, in Chrome 59.

Remove file_browser_handlers: does not work on Chrome OS according to
https://github.com/mozilla/pdf.js/issues/14161 . MV3 replacement needs
a different manifest key and logic, which will be added later.

Remove content_security_policy: MV3 does not support unsafe-eval CSP,
and PDF.js does not require it. This may result in a mild performance
degradation in PDFs that contain PostScript.

Remove page_action logic: When this logic was originally introduced,
Chrome showed page action buttons in the address bar, which enabled
the extension to display the button on specific PDF viewer tabs only.
In Chrome 49 (2016), pageActions were dropped from the address bar and
put in an UI area that is hidden by default. The user can pin the button
to be unconditionally visible on the toolbar, which is distracting.
Because the UX is no longer serving the original needs, this patch
removes page_action from the manifest.
2024-08-25 20:34:03 +02:00
Jonas Jenwald
b9f5e78e15 Remove the enableHighlightEditor preference
This was enabled by default in Firefox 126, see [bug 1867513](https://bugzilla.mozilla.org/show_bug.cgi?id=1867513), so hopefully we should be able to remove the option/preference now.
2024-08-10 16:00:31 +02:00
Tim van der Meij
be93d530de
Remove the eslint-plugin-mozilla dependency
We only used two rules from the plugin which can both easily be replaced
nowadays:

- `mozilla/avoid-removeChild` is equal to the already active
  `unicorn/prefer-dom-node-remove` rule; please see [1] and [2].
- `mozilla/import-globals` is mostly obsolete nowadays ever since we
  removed the Firefox extension code from this repository and we
  eliminated most globals usage. The three remaining occurrences can be
  replaced with explicit `/* globals */` comments that we already use
  elsewhere, which overall is also more consistent.

[1] https://firefox-source-docs.mozilla.org/code-quality/lint/linters/eslint-plugin-mozilla/rules/avoid-removeChild.html
[2] https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-dom-node-remove.md
2024-08-08 19:51:20 +02:00
Calixte Denizet
32d09276f0 [Editor] Add a new dialog for alt-text settings (bug 1909604)
This patch adds a new entry in the secondary menu in order to open a dialog to let the user:
 - disables the alt-text generation thanks to a ML model;
 - deletes the alt-text model downloaded in Firefox;
 - disabled the new alt-text flow.
2024-08-01 21:34:50 +02:00
Tim van der Meij
f1f58bbe67
Give all HTML button elements a type
The HTML button elements we use are all regular buttons that don't
submit form data to a server. According to
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#notes
those buttons should all have their type set to `button` explicitly, but
we only do that a handful of them. This commit fixes the issue by
consistently giving all our buttons the `button` type.

Co-authored-by: Calixte Denizet <calixte.denizet@gmail.com>
2024-07-30 18:49:18 +02:00
Calixte Denizet
042183b89b Add a pref to know if the alt-text must be automatically generated (bug 1909310) 2024-07-22 23:10:25 +02:00
Calixte Denizet
5860c7bcc9 Add a pref containing the url for the sumo page about alt text (bug 1909097) 2024-07-21 16:55:26 +02:00
Calixte Denizet
dfccc8ffd9 [Editor] Add an option to use the new 'add an image' flow (bug 1907207)
UX team designed in a new flow we'll implement soon and we want to be able to
make an experiment to be able to compare current flow vs the new one.
2024-07-12 16:28:48 +02:00
Calixte Denizet
0fba6e570e [Editor] Change the enableML pref for enableAltText (bug 1905923)
We want to use this pref to make a Nimbus experiment in the next weeks.
2024-07-05 21:01:12 +02:00
Calixte Denizet
74cbfbd09f [Editor] Remove the option enableStamp 2024-07-04 22:01:35 +02:00
Calixte Denizet
52a06e64f6 Only disable HWA in m-c build and for local dev
This way, we keep pdf.js working as before except for Firefox.
2024-06-16 12:14:33 +02:00
Calixte Denizet
ff6180a4c9 Add an option to enable/disable hardware acceleration (bug 1902012) 2024-06-12 18:41:07 +02:00
Calixte Denizet
b4267cd294 [Editor] Add a floating button close to the selected text to highlight it (bug 1867742)
For now keep this feature behind a pref in order to make some experiments before
deciding to enable it.
2024-03-12 15:06:46 +01:00
Calixte Denizet
46416bb131 [Editor] Add the possibility to query some ML stuff to guess an alt text for an image
It's only for an experimental purpose.
2024-02-20 21:29:33 +01:00
Calixte Denizet
bcc95460b6 Revert "Remove the enableStampEditor preference" (bug 1879588)
This reverts commit e820688510.
2024-02-09 18:21:21 +01:00
Jonas Jenwald
363dce6744 Use a limit, in more places, when splitting strings
This should be a *tiny* bit more efficient, since it avoids parsing substrings that we don't care about.

*Please note:* I cannot find an ESLint rule to enforce this automatically.
2024-02-02 13:10:52 +01:00
Calixte Denizet
29de9bdce6 Format json files in using prettier 2024-01-16 19:40:25 +01:00
Calixte Denizet
ff23d37fa2 [Editor] Add a color picker with predefined colors for highlighting text (bug 1866434)
The doorhanger for highlighting has a basic color picker composed of 5 predefined colors
to set the default color to use.
These colors can be changed thanks to a preference for now but it's something which could
be changed in the Firefox settings in the future.
Each highlight has in its own toolbar a color picker to just change its color.
The different color pickers are so similar (modulo few differences in their styles) that
this patch introduces a new class ColorPicker which provides a color picker component
which could be reused in future editors.
All in all, a large part of this patch is dedicated to color picker itself and its style
and the rest is almost a matter of wiring the component.
2023-12-05 23:27:22 +01:00
Calixte Denizet
1ea6293923 [Editor] Add a new editor to highlight some text in a pdf (bug 1866119)
This patch is first big step for the new highlight feature.
Few patches will follow in order to conform to the specs UX/UI gave us.
2023-11-28 14:21:53 +01:00
Calixte Denizet
53101b379b Restore the option to set light/dark mode for chromium and generic builds 2023-11-18 21:32:25 +01:00
Jonas Jenwald
d46578e959 Remove the viewerCssTheme-option, since it's partially broken
The `viewerCssTheme`-implementation has always been somewhat hacky, and now it's also *partially* broken ever since we've started using CSS nesting.
Trying to support nested media queries would thus require a lot more parsing of the CSS rules, which seems inefficient and thus generally undesirable.[1]

As discussed on Matrix, let's try to remove the `viewerCssTheme`-option and see if there's any (significant) fallout from this.

---
[1] If this option is brought back, it seems to me that it (in Firefox) should probably be set through the platform-code that handles theming.
2023-11-04 09:19:01 +01:00
Jonas Jenwald
e820688510 Remove the enableStampEditor preference 2023-10-19 15:45:07 +02:00
Jonas Jenwald
66645d30cc Remove the useOnlyCssZoom preference
*Please note:* This only removes the preference itself, however both the viewer-option and the actual implementation is still available.

The `useOnlyCssZoom` functionality was only ever used, by default, in the PDF Viewer for the B2G/FirefoxOS project (which was abandoned years ago). Given that CSS-only zooming can easily make the document look blurry even at low zoom levels, this functionality was only intended for low-powered mobile devices.
Hence it seems reasonable to remove the `useOnlyCssZoom` preference now, since neither the default viewer nor the GeckoView-specific viewer uses this functionality.
2023-07-23 11:20:36 +02:00
Tim van der Meij
42edc4d895
Merge pull request #16630 from Rob--W/crx-url-hash-init
Correct recognition of fragments at document load
2023-07-08 14:05:33 +02:00
Tim van der Meij
1567d022d9
Merge pull request #16631 from Rob--W/crx-remove-old-chrome-compat-code
[CRX] Drop code supporting ancient Chrome versions
2023-07-08 14:02:30 +02:00
Calixte Denizet
37bd78c707 [Editor] Add a basic stamp editor (bug 1790255)
For now it allows to add a stamp annotation with an image selected from the file system.
2023-07-06 11:27:50 +02:00
Rob Wu
70db938fe7 [CRX] Drop code supporting ancient Chrome versions 2023-07-02 17:23:18 +02:00
Rob Wu
f2753d6220 [CRX] Avoid encoding the fragment in file key
Semantically, it is more correct to encode the fragment in the URL
instead of the URL-encoded `file` query parameter. This shouldn't matter
in practice, because `rewriteUrlClosure` in `chromecom.js` decodes the
`file` parameter and restores the fragment. However, as #16625 shows,
there was a case where this did not work as expected.
2023-07-02 15:31:35 +02:00
erm1116
fcf38f6ae9 fix: use node.insertBefore for adding embed element 2023-06-30 22:38:59 +09:00
Rob Wu
1f29baad22 Set minimum_chrome_version to 88
Set minimum_chrome_version to 88 to not distribute an incompatible
version of the extension to older Chrome versions.

See https://github.com/mozilla/pdf.js/issues/13669#issuecomment-1510485564
2023-06-25 14:19:50 +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
663007a5c7 Only redraw after zooming is finished (bug 1661253)
Right now, the visible pages are redrawn for each scale change.
Consequently, zooming with mouse wheel or in pinching can be pretty janky
(even on a desktop machine but with a hdpi screen).
So the main idea in this patch is to draw the visible pages only once zooming
is finished.
2022-12-26 18:13:17 +01:00