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

[JS] Some functions (print, alert,...) must be called only after a user activation #15618

Merged
merged 1 commit into from
Oct 28, 2022

Conversation

calixteman
Copy link
Contributor

  • Some events, which require a user interaction, will allow those functions to be called. But after few seconds, if there are no more user interaction, it won't be possible anymore.
    The idea is to give an opportunity to the user to leave the pdf.
  • Disable print function when we're printing, the same with saving and disallow to save on open events.

Close #15614.

Comment on lines 85 to 89
if (callbackId === 0) {
this.win.clearTimeout(this.timeoutIds.get(0));
}
Copy link
Collaborator

@Snuffleupagus Snuffleupagus Oct 25, 2022

Choose a reason for hiding this comment

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

Should we have similar code in the setInterval method below?
If not, maybe add a (brief) comment to explain what's "special" about this case.

src/scripting_api/app.js Show resolved Hide resolved
src/scripting_api/doc.js Show resolved Hide resolved
Copy link
Collaborator

@Snuffleupagus Snuffleupagus left a comment

Choose a reason for hiding this comment

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

r=me, with a couple of minor comments and passing tests; thank you!

@@ -23,6 +23,7 @@ const VIEWER_TYPE = "PDF.js";
const VIEWER_VARIATION = "Full";
const VIEWER_VERSION = 21.00720099;
const FORMS_VERSION = 21.00720099;
const USERACTIVATION_CALBACKID = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Making this a constant was a good idea, but please fix the spelling :-)

Suggested change
const USERACTIVATION_CALBACKID = 0;
const USERACTIVATION_CALLBACKID = 0;

if (callbackId === 0) {
// This callbackId corresponds to the one used for userActivation.
// So here, we cancel the last userActivation.
this.win.clearTimeout(this.timeoutIds.get(0));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's avoid the additional hard-coding here:

Suggested change
this.win.clearTimeout(this.timeoutIds.get(0));
this.win.clearTimeout(this.timeoutIds.get(callbackId));

…er activation

- Some events, which require a user interaction, will allow those functions to be called.
But after few seconds, if there are no more user interaction, it won't be possible
anymore.
The idea is to give an opportunity to the user to leave the pdf.
- Disable print function when we're printing, the same with saving and disallow to save
on open events.
@calixteman
Copy link
Contributor Author

/botio unittest

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

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

Live output at: http://54.241.84.105:8877/63edac26607e263/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

Live output at: http://54.193.163.58:8877/1d286f49d78f477/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/63edac26607e263/output.txt

Total script time: 2.34 mins

  • Unit Tests: Passed

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://54.193.163.58:8877/1d286f49d78f477/output.txt

Total script time: 7.90 mins

  • Unit Tests: Passed

@calixteman
Copy link
Contributor Author

/botio integrationtest

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

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

Live output at: http://54.241.84.105:8877/460adc3fb880795/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

Live output at: http://54.193.163.58:8877/d96c1bd53512b26/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/460adc3fb880795/output.txt

Total script time: 4.13 mins

  • Integration Tests: Passed

@pdfjsbot
Copy link

From: Bot.io (Windows)


Failed

Full output at http://54.193.163.58:8877/d96c1bd53512b26/output.txt

Total script time: 12.18 mins

  • Integration Tests: FAILED

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.

Save and print loops in PDF viewer with JS in PDF.
4 participants