A script can trigger some events on its own, e.g. a timer, or focus an
element under the pointer or the keyboard, hence the viewer has to decide
by itself whether an action comes from the user.
The events caused by a trusted user gesture (Action, Mouse Down and Mouse
Up) and the Open event, which may only print, get a one-time token. The
host keeps it out of the sandbox and attaches it to the commands sent
while the event is handled. The annotation actions which print, save,
download or follow a link are checked the same way, and only one of them
is honored per gesture. A gesture is ignored when the keyboard activates
an element focused by a script, or when it follows a layout change made
by a script too closely.
Nothing coming from the sandbox can be trusted: it grants itself a user
activation for any event, and a script can trigger some events on its own
(e.g. a timer calling setFocus).
Hence the host only shows a dialog, once, while handling an event for
which the viewer allows it: the ones caused by the user, Open, and the
print/save ones. A focus change requested by a script no longer counts
as a user activation.
Disable saving while running the WillPrint actions, as for WillSave: they
run right before saving a document flattened for printing, so a SaveAs
action would start another save.
Replace the Proxy wrapping the fields with private fields and methods,
which simplifies the code: the obj/wrapped pairs, the Proxy handler and
the PDFObject base class are gone. The doc and the event dispatcher use
helpers defined in a static block for the few field internals they need.
The fields share a prototype with the methods and accessors of Field,
instead of getting bound methods from the Proxy. As in Acrobat, a field
method can't be called without its field as `this`, nor be overwritten.
The Proxy wrapping the fields no longer sends every assigned property to
the view nor copies it to the descendant fields. Instead, the setters of
the properties used by the view update the widgets and the descendants,
and the built-in properties of a non-terminal field are accessors
forwarding their value to the descendants.
Hence, as in Acrobat, a custom property stays on the field it's set on,
and nothing is sent for a rejected radio button value or a property
unknown to the view. The event dispatcher and the doc set values without
sending them, and the messages no longer contain a null `siblings`.
The Doc object uses private class members. initSandbox and the event
dispatcher reach the few methods they need through helpers defined in a
static block, and a field gets callbacks, instead of the Doc instance,
to get its terminal children and to report errors.
The doc.info target has a null prototype, so that an info key such as
`constructor` doesn't give an Object.prototype member.
The app object is no longer wrapped in a Proxy: it uses private class
members and, like the helper objects, looks like a plain object with
bound methods. initSandbox calls the timer callback through a helper
defined in a static block.
The timers use the Map, WeakMap and FinalizationRegistry methods
captured before any script runs, so that a script can't redefine them
to get the timer internals, e.g. to forge the data of a timeout handle
and cancel the user activation expiry.
The event dispatcher uses private class members, and the events are
plain objects tagged as `Event` instead of Event class instances, so
that, as for the other scripting objects, `event.constructor` is
`Object` rather than an implementation class.
The event dispatcher and the map from widget ids to fields are created
in initSandbox instead of the App constructor, and the user activation
state is shared by the app, the doc and the event dispatcher, so that
they don't access each other's internals anymore.
The doc seen by the scripts (field.doc, app.activeDocs, and the source
and target of the doc and page events) is now the global object, which
already has the doc properties, instead of a Proxy on the Doc instance.
The color, console, util, app.fs and app.thermometer objects are no
longer wrapped in a Proxy: they use private class members and, like the
print params, they look like plain objects whose prototype has the
methods, bound to them, and the accessors of their class. The AForm
helpers use private members too.
app.fs, app.thermometer and the print params are created with their
owner instead of on first use, and Function.prototype.toString shows the
API functions as native ones.
GenericScripting returns before WillSave actions run, so saving could miss
their field changes. Wait for WillSaveFinished before saving, even when
an action throws.
It fixes#22212.
Cover global constants, grouped button updates, prototype extensions,
detached methods, descendant field properties, ResetForm events,
list box multipleSelection updates, unparsable dates on document open,
and added color enumeration.
Avoid passing unknown handles to FinalizationRegistry.unregister.
Clearing a handle that its timeout callback had set to null previously
threw and stopped the script.
Use each handle as its unregister token to remove its finalizer on
explicit cancellation.
When the default value was "Off", the checkbox override returned whether the
checkbox was currently unchecked instead of comparing the default value with
the widget's export value.
The current widget ID is always set, even when nothing is checked (e.g. a
radio group whose value is "Off", or a checkbox without a value), so
isBoxChecked returned true for an unchecked widget.
Handle thrown null values and failures in string conversion or stack
access. Report field errors through the document, since fields without
widgets have no send callback.
This prevents error reporting from skipping subsequent actions, field
formatting, and OpenAction.
PR #15822 added an OpenAction call in _initActions while retaining the
call in _dispatchDocEvent, causing it to run twice on document open.
Remove the initialization call so OpenAction runs once, after formatting.
Compare export values with data.value because _value is still null during
construction. This fixes isBoxChecked and action selection when a later
widget is initially selected, plus the "Off" toggle in two-button groups.
For such numbers `Math.trunc` returns -0, hence the sign was lost when using the "f" conversion; e.g. `util.printf("%.2f", -0.5)` returned "0.50".
This also affected the `AFNumber_Format` and `AFPercent_Format` functions.
The 160F-2019.pdf ESC integration test now expects "-0,69": field 471R
(T.21) is computed as T.TOTREM - T.COTDED - N.10 - ..., so typing 0.69314
in N.10 (436R) makes it negative, and the old expectation only passed
because the sign was lost.
When the array given to `resetForm` contains the name of a non-terminal
field, only that field was reset, so its terminal descendants kept their
values. It's the sandbox counterpart of #22014.
Walk the `_kidIds` of the collected fields and add every descendant
before resetting them.
It flags the regexes whose search is quadratic in the input length, like
the autolinker and XFA-path ones fixed recently.
The three existing offenders: `\s*` matched the CSS indentation but also
the line terminators that make `^` match with the `m` flag (the
preprocessed CSS is unchanged), `(\d+)` made every digit of a number a
candidate start position, and `/T.*$/` could fail on the `$` and
backtrack since `.` doesn't match a line terminator.
In PR 12569 the `_actions` class-field was changed from an Object into a Map, with *most* of the code updated to reflect that.
However, in the `setAction` method it's still treated as an Object which means that any added script will simply be ignored. Most likely that part of the scripting-implementation isn't being used, since this code has been "wrong" for close to six years now.
We support having hours/minutes numbers with one or two digits for strings like "1:30:31" but
if the format is for example Hm, then "12" is really ambiguous.
So the idea is to match the longest string as possible.
This commit fixes a number of missing cleanup steps in the unit tests
that kept state alive for longer than necessary:
- the loading tasks were not all being destroyed;
- the find controllers were not being reset;
- the state set in `beforeAll`/`beforeEach` was not all being nulled in
the correspoding `afterAll`/`afterEach` blocks.
Combined this resulted in a steady increase in memory usage of the test
process as the tests ran, climbing up to ~1.5 GB. After this patch the
memory usage remains stable at ~800 MB.
The date was create in UTC+0 and then amended in using set-Month/Date which take into account
the user timezone.
With this patch we build all the date in the user timezone.