-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
[api-minor] JS -- Add listener for sandbox events only if there are some actions #12546
Conversation
calixteman
commented
Oct 28, 2020
- When no actions then set it to null instead of empty object
- Even if a field has no actions, it needs to listen to events from the sandbox in order to be updated if an action changes something in it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall, but I'd like to hear if it's possible to address the comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we actually delay this completely until Annotation parsing actually occurs, since in most documents there's either no annotations present or at least no JavaScript actions present!?
That'd probably reduce the overall size of this, and also simplify the implementation (especially on the viewer side). One quick idea that I had, was to simply include this property in the annotation data itself such that you'll only need to pass around the enableScripting
-value to the various viewer-components.
To illustrate my idea, perhaps something along these lines (purposely incomplete, but only to illustrate my idea):
diff --git a/src/core/annotation.js b/src/core/annotation.js
index 252e1529b..f28806726 100644
--- a/src/core/annotation.js
+++ b/src/core/annotation.js
@@ -62,13 +62,17 @@ class AnnotationFactory {
* instance.
*/
static create(xref, ref, pdfManager, idFactory) {
- return pdfManager.ensureCatalog("acroForm").then(acroForm => {
+ return Promise.all([
+ pdfManager.ensureCatalog("acroForm"),
+ pdfManager.ensureDoc("hasJSActions"),
+ ]).then(([acroForm, hasJSActions]) => {
return pdfManager.ensure(this, "_create", [
xref,
ref,
pdfManager,
idFactory,
acroForm,
+ hasJSActions,
]);
});
}
@@ -76,7 +80,14 @@ class AnnotationFactory {
/**
* @private
*/
- static _create(xref, ref, pdfManager, idFactory, acroForm) {
+ static _create(
+ xref,
+ ref,
+ pdfManager,
+ idFactory,
+ acroForm,
+ hasJSActions = false
+ ) {
const dict = xref.fetchIfRef(ref);
if (!isDict(dict)) {
return undefined;
@@ -97,6 +108,7 @@ class AnnotationFactory {
id,
pdfManager,
acroForm: acroForm instanceof Dict ? acroForm : Dict.empty,
+ hasJSActions,
};
switch (subtype) {
@@ -281,6 +293,7 @@ class Annotation {
modificationDate: this.modificationDate,
rect: this.rectangle,
subtype: params.subtype,
+ documentHasJSActions: params.hasJSActions,
};
this._fallbackFontDict = null;
diff --git a/src/display/annotation_layer.js b/src/display/annotation_layer.js
index effa122b5..4e07676fe 100644
--- a/src/display/annotation_layer.js
+++ b/src/display/annotation_layer.js
@@ -478,7 +478,8 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement {
event.target.setSelectionRange(0, 0);
});
- if (this.data.actions) {
+ // Assuming that the `enableScripting`-value is passed in:
+ if (this.enableScripting && this.data.documentHasJSActions) {
element.addEventListener("updateFromSandbox", function (event) {
const data = event.detail;
if ("value" in data) {
I think this is a very good idea: I like it, thank you. |
10d1ce7
to
10d1965
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks much better this way; I've added a few comments, after which this should be good to go (assuming all tests pass of course :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good but I'd really like to see the property comment addressed since it doesn't feel like the right place to put it.
4aeff66
to
de4b0d5
Compare
* When no actions then set it to null instead of empty object * Even if a field has no actions, it needs to listen to events from the sandbox in order to be updated if an action changes something in it.
/botio test |
From: Bot.io (Linux m4)ReceivedCommand cmd_test from @brendandahl received. Current queue size: 0 Live output at: http://54.67.70.0:8877/f4cd0e18f636d93/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_test from @brendandahl received. Current queue size: 0 Live output at: http://3.101.106.178:8877/e38ecbda1eeccf1/output.txt |
From: Bot.io (Linux m4)FailedFull output at http://54.67.70.0:8877/f4cd0e18f636d93/output.txt Total script time: 24.90 mins
Image differences available at: http://54.67.70.0:8877/f4cd0e18f636d93/reftest-analyzer.html#web=eq.log |
From: Bot.io (Windows)FailedFull output at http://3.101.106.178:8877/e38ecbda1eeccf1/output.txt Total script time: 28.28 mins
Image differences available at: http://3.101.106.178:8877/e38ecbda1eeccf1/reftest-analyzer.html#web=eq.log |
/botio-linux preview |
From: Bot.io (Linux m4)ReceivedCommand cmd_preview from @timvandermeij received. Current queue size: 0 Live output at: http://54.67.70.0:8877/4ae43562e91da07/output.txt |
From: Bot.io (Linux m4)SuccessFull output at http://54.67.70.0:8877/4ae43562e91da07/output.txt Total script time: 4.14 mins Published |
Looks good to me too now. Thank you! |