Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
documentScan: Add API handler for setOptions
This adds the data types and flow for the new documentScan.setOptions function. After the caller has opened a scanner with openScanner, they can use setOptions to configure all of the available scanner options. Each call attempts to set all provided options in order and returns a new configuration after everything has been set. Validation of constraints and value-option type matching happens on the backend, so this logic is not duplicated in the handler. In most cases, the handler just passes requests and responses directly to and from the crosapi service. The exception to this rule is that the incoming OptionSetting::Value objects have some potential confusion between long and double due to the combination of OptionValue union types, Javascript use of double for all numbers, and the auto-generated IDL handling of lists: 1. If a type union contains multiple list types, the auto-generated parsing code always attempts to populate the first list. Because a double can't be parsed into an integer, this means that double[] has to come before long[] in type signatures that accept both. This means that the C++ side will always see the as_numbers field for lists even if the caller wrote something like [1, 2, 3]. 2. If a numeric value in JS ends with .0, the extension framework parses it into an integer. This means that a caller supplying 1.0 in a value arrives on the C++ side in the as_integer field. 3. Because of Pissandshittium#2, even if the list confusion from Pissandshittium#1 is fixed, the opposite problem could happen where [1.0, 2.0, 3.0] is seen as as_integers on the C++ side. To address all of these, the handler does two types of re-mappings from OptionSetting objects coming in from JS: 1. If an OptionSetting has type TYPE_FIXED but the value is in one of the int fields, simply move the value over to the fixed field. This technically allows callers to write NN instead of NN.0, but this isn't a problem because the two values are numerically identical. 2. If an OptionSetting has type TYPE_INT but the value is in one of the fixed fields, move the value over only if it is within the range of int32_t and does not contain a non-zero fractional part. This catches the cases where the framework parses an integer value into the as_number/as_numbers field without allowing the user to silently convert other types of doubles into integer options. The same re-mapping concerns do not apply to structures that go in the other direction because the C++ code is able to correctly distinguish as_integer/as_number/as_integers/as_numbers when converting from mojom structures. Nevertheless, this change also re-orders the relevant union declarations in the IDL for consistency. Bug: b:297435721 Change-Id: Idbe5e3ad6bee8032058574f16748ad2a4fc765d1 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5096073 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Benjamin Gordon <bmgordon@chromium.org> Reviewed-by: Devlin Cronin <rdevlin.cronin@chromium.org> Cr-Commit-Position: refs/heads/main@{#1237763}
- Loading branch information