Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In order to simplify m-c code, move some in pdf.js #12689

Merged
merged 1 commit into from
Dec 17, 2020

Conversation

calixteman
Copy link
Contributor

@calixteman calixteman commented Dec 3, 2020

  • move set/clear|Timeout/Interval and crackURL code in pdf.js
  • remove the "backdoor" in the proxy (used to dispatch event) and so return the dispatch function in the initializer
  • remove listeners if an error occured during sandbox initialization
  • add support for alert and prompt in the sandbox
  • add a function to eval in the global scope

@calixteman calixteman force-pushed the mv_stuff_from_mc branch 2 times, most recently from b96f54d to f028c88 Compare December 4, 2020 14:31
@calixteman calixteman force-pushed the mv_stuff_from_mc branch 6 times, most recently from 3358fe2 to 40a5b73 Compare December 6, 2020 13:46
@Snuffleupagus
Copy link
Collaborator

Why is this removing the destroySandbox-functionality, since I cannot imagine that it'll actually work correctly in the general case?

Please keep in mind that the GENERIC default viewer supports opening more than one document, and I'd thus expect that you need a unique scripting-instance for each document (the same way that basically everything in the default viewer is document specific); see PR #12695 which tries to improve a number of things related to both pdf.sandbox.js building and how it's used in the viewer.

@calixteman calixteman force-pushed the mv_stuff_from_mc branch 2 times, most recently from 9d8fb6b to d530836 Compare December 6, 2020 16:59
Copy link
Contributor

@brendandahl brendandahl left a comment

Choose a reason for hiding this comment

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

I did a quick skim and seems reasonable. I'll let @Rob--W review the parts he suggested.

@Rob--W
Copy link
Member

Rob--W commented Dec 8, 2020

Why is this removing the destroySandbox-functionality, since I cannot imagine that it'll actually work correctly in the general case?

Please keep in mind that the GENERIC default viewer supports opening more than one document, and I'd thus expect that you need a unique scripting-instance for each document (the same way that basically everything in the default viewer is document specific); see PR #12695 which tries to improve a number of things related to both pdf.sandbox.js building and how it's used in the viewer.

I pointed out that the sandbox destruction logic wasn't called, at https://phabricator.services.mozilla.com/D91746?id=370264#inline-555164 with the ending note:

Make this sandbox destruction part of the window. There is already an unload listener, you could call destroySandbox from there (in addition to any other existing calls in PDF.js code).

By this, I meant to call it at least twice: as part of the privileged unload handler (which always runs), and as usual from the destruction logic in PDF.js. @Snuffleupagus has already fixed the latter in #12695, so what remains is only on the m-c side (and also there already).

Copy link
Member

@Rob--W Rob--W left a comment

Choose a reason for hiding this comment

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

It took a while to review this because the patch is very large, with many more changes than strictly needed to provide the sandboxing functionality. The review was further complicated by the lack of documentation and references to relevant sources.

To support my review task, I composed the following list of locations that are relevant to the feature that I was asked to review (a sandbox mechanism). I also reviewed the other code since examples of actual usage is a good verification of the effectiveness of the API surrounding the sandbox.

There is no clear authorative reference for JavaScript in PDFs. The following are available (with an incomplete changelog).

The last published reference is from 5 years ago, so they may be out of date. Interestingly, Chrome's PDF implementation has a README that references the 2007 implementation, at https://source.chromium.org/chromium/chromium/src/+/master:third_party/pdfium/fxjs/README;l=40;drc=d9d3ed281f87f706ecc442c7902abfa8ef5c4928

Could you also add a README.md to the scripting_api repository, to allow other readers to know what you're using as the definition of the API, and how everything fits together?

gulpfile.js Outdated Show resolved Hide resolved
src/scripting_api/initialization.js Outdated Show resolved Hide resolved
src/scripting_api/initialization.js Outdated Show resolved Hide resolved
src/scripting_api/util.js Outdated Show resolved Hide resolved
web/firefoxcom.js Outdated Show resolved Hide resolved
src/scripting_api/extra.js Outdated Show resolved Hide resolved
src/scripting_api/extra.js Outdated Show resolved Hide resolved
src/scripting_api/extra.js Outdated Show resolved Hide resolved
src/pdf.sandbox.js Outdated Show resolved Hide resolved
src/pdf.sandbox.js Outdated Show resolved Hide resolved
@calixteman calixteman force-pushed the mv_stuff_from_mc branch 3 times, most recently from 68764a7 to 1504cc9 Compare December 14, 2020 15:33
Copy link
Member

@Rob--W Rob--W left a comment

Choose a reason for hiding this comment

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

I looked closely at the interaction of the sandbox and quickjs, a bit at the timer, but didn't look at the rest in detail. Since there is already something actionable, I'm returning it for review now.

src/scripting_api/app.js Show resolved Hide resolved
src/scripting_api/app.js Show resolved Hide resolved
src/pdf.sandbox.external.js Outdated Show resolved Hide resolved
src/pdf.sandbox.external.js Show resolved Hide resolved
src/pdf.sandbox.js Outdated Show resolved Hide resolved
src/pdf.sandbox.js Outdated Show resolved Hide resolved
src/pdf.sandbox.js Outdated Show resolved Hide resolved
src/pdf.sandbox.js Outdated Show resolved Hide resolved
src/pdf.sandbox.js Outdated Show resolved Hide resolved
Copy link
Member

@Rob--W Rob--W left a comment

Choose a reason for hiding this comment

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

It's getting in a good shape. I do have a few comments, but the overall structure looks sane sane.

src/pdf.sandbox.external.js Outdated Show resolved Hide resolved
src/pdf.sandbox.external.js Outdated Show resolved Hide resolved
src/pdf.sandbox.external.js Outdated Show resolved Hide resolved
src/pdf.sandbox.external.js Outdated Show resolved Hide resolved
src/pdf.sandbox.external.js Outdated Show resolved Hide resolved
src/scripting_api/initialization.js Outdated Show resolved Hide resolved
src/pdf.sandbox.external.js Outdated Show resolved Hide resolved
src/pdf.sandbox.js Show resolved Hide resolved
src/pdf.sandbox.external.js Outdated Show resolved Hide resolved
src/pdf.sandbox.js Outdated Show resolved Hide resolved
Copy link
Member

@Rob--W Rob--W left a comment

Choose a reason for hiding this comment

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

r+ with comments addressed.

src/pdf.sandbox.external.js Outdated Show resolved Hide resolved
src/pdf.sandbox.js Outdated Show resolved Hide resolved
src/pdf.sandbox.js Outdated Show resolved Hide resolved
web/app.js Outdated Show resolved Hide resolved
src/pdf.sandbox.external.js Outdated Show resolved Hide resolved
src/pdf.sandbox.js Outdated Show resolved Hide resolved
src/pdf.sandbox.external.js Outdated Show resolved Hide resolved
 * move set/clear|Timeout/Interval and crackURL code in pdf.js
 * remove the "backdoor" in the proxy (used to dispatch event) and so return the dispatch function in the initializer
 * remove listeners if an error occured during sandbox initialization
 * add support for alert and prompt in the sandbox
 * add a function to eval in the global scope
@calixteman
Copy link
Contributor Author

/botio test

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_test from @calixteman received. Current queue size: 0

Live output at: http://54.67.70.0:8877/50347eb15a009eb/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_test from @calixteman received. Current queue size: 0

Live output at: http://3.101.106.178:8877/128f561af7695f6/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Failed

Full output at http://54.67.70.0:8877/50347eb15a009eb/output.txt

Total script time: 25.78 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Integration Tests: Passed
  • Regression tests: FAILED

Image differences available at: http://54.67.70.0:8877/50347eb15a009eb/reftest-analyzer.html#web=eq.log

@pdfjsbot
Copy link

From: Bot.io (Windows)


Failed

Full output at http://3.101.106.178:8877/128f561af7695f6/output.txt

Total script time: 27.18 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Integration Tests: Passed
  • Regression tests: FAILED

Image differences available at: http://3.101.106.178:8877/128f561af7695f6/reftest-analyzer.html#web=eq.log

@calixteman calixteman merged commit c366390 into mozilla:master Dec 17, 2020
@nmtigor nmtigor mentioned this pull request Sep 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants