Skip to content

Comments

Bump pdf.js to 2.1.266#168

Merged
rullzer merged 5 commits intomasterfrom
bump/pdfjs-2.1.266
Mar 18, 2020
Merged

Bump pdf.js to 2.1.266#168
rullzer merged 5 commits intomasterfrom
bump/pdfjs-2.1.266

Conversation

@juliusknorr
Copy link
Member

  • 2.2.228 is not feasible yet as it comes with a different CSP issues as it would require us to bundle it with regenerator-runtime (CSP violations for unsafe-inline in [email protected] mozilla/pdf.js#11036)
  • I currently fail to get a proper webpack build up and running due to the dist packages of pdf.js only including parts of the viewer and mainly focussing on the library itself

danxuliu and others added 5 commits March 17, 2020 20:12
The example PDF ("compressed.tracemonkey-pldi-09.pdf") is not needed and
thus was not included; "templates/viewer.php" acts as "viewer.html", so
the later was not included either.

On the other hand, source maps were kept so they could be used in case
of need.

Signed-off-by: Daniel Calviño Sánchez <[email protected]>
The "viewer.php" acts as the "viewer.html" file included in the PDF.js
package. This commit updates "viewer.php" with the changes to
"viewer.html" from PDF.js 1.9.426 to 2.0.943 while respecting the
customized parts of "viewer.php" (like the close button or the "nonce"
attribute).

Signed-off-by: Daniel Calviño Sánchez <[email protected]>
The PDFViewerApplication options are no longer got from the PDFJS object
but from a helper object that holds the configuration. This object is
globally set before "PDFViewerApplication.initialize" is called, so it
can be used in the custom initialization code.

Note that despite setting "isEvalSupported" to false this does not work
out of the box with the default Nextcloud Content Security Policy. Due
to how the PDF.js library is bundled it tries to execute an "eval"
function, which is blocked by the CSP and causes the viewer to not load
the PDF file.

Signed-off-by: Daniel Calviño Sánchez <[email protected]>
The example PDF ("compressed.tracemonkey-pldi-09.pdf") is not needed and
thus was not included; "templates/viewer.php" acts as "viewer.html", so
the later was not included either.

On the other hand, source maps were kept so they could be used in case
of need.

Note that "viewer.html" did not change between v2.0.943 and v2.1.266, so
there is no need to update "templates/viewer.php".

Also note that, unlike v2.0.943, PDF.js v2.1.266 works out of the box
with Nextcloud Content Security Policy.

Signed-off-by: Julius Härtl <[email protected]>
Since v2.1.266 an event is triggered before the PDFViewerApplication is
initialized, so the hack that relied on the asynchronous calls during
the initialization to hook in is no longer needed.

However, as the event is triggered before the initialization the options
are now set before the preferences are read. As the preferences override
the options the preferences need to be disabled to be able to set
"externalLinkTarget". Disabling the preferences has no effect for the
rest of them, as they already have the same value as the default
options.

Signed-off-by: Daniel Calviño Sánchez <[email protected]>
@danxuliu danxuliu force-pushed the bump/pdfjs-2.1.266 branch from 824b04c to 85b9bdf Compare March 18, 2020 01:28
@danxuliu
Copy link
Member

I have fixed opening the links, loading the character maps, the missing close button and removed some unneeded files from the vendor folder. This should be good to go (but please test anyway ;-) ).

As an additional note, like 2.2.228, 2.0.943 can not be used either due to the CSP. It seems that 2.1.266 happens to work due to some lucky combination of how the library code is initialized 🤷‍♂️

Copy link
Member

@rullzer rullzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the trick!

@rullzer rullzer merged commit ef41f63 into master Mar 18, 2020
@delete-merged-branch delete-merged-branch bot deleted the bump/pdfjs-2.1.266 branch March 18, 2020 14:08
@rullzer
Copy link
Member

rullzer commented Mar 18, 2020

/backport to stable18

@rullzer
Copy link
Member

rullzer commented Mar 18, 2020

/backport to stable17

@backportbot-nextcloud
Copy link

backport to stable18 in #169

@backportbot-nextcloud
Copy link

backport to stable17 in #170

@rullzer
Copy link
Member

rullzer commented Mar 18, 2020

/backport to stable16

@backportbot-nextcloud
Copy link

backport to stable16 in #171

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants