On the web, a plug-in being installed ran its start function and
vc_manifest on the page, and a filter ran on the page for its whole
budget, so a slow or looping module froze the tab for up to a minute
(five for a heavy filter), and Cancel could not stop it.
- A second wasm, apps/vectorcraft-plugin-worker, is built by Trunk as a
worker (data-type="worker" with data-loader-shim in index.html). The
page starts one worker for each check and each run, and terminates it
on Cancel, when the document or the plug-in changes, and 5 s past the
run's time budget, also while a dialog is open. Each worker's inbox
holds its latest progress report and at most 8 other messages.
- crates/plugins/src/worker.rs holds the messages and the worker's
side. Runs can pause at each vc_call (Plugin::begin_run and
resume_run), which the desktop's synchronous calls now use too.
- Install Plug-in... and File > Open check a module in a worker first;
the page then loads it with Plugin::load_checked, which runs none of
its code.
- A filter that calls commands sends each call to the page. The session
holds the run's undo step open and refuses other edits with "a
plug-in is running: cancel it or wait for it to finish" until the run
ends; the progress window shows at once with Cancel only.
- On the web every filter and plug-in command started from the menus
or their dialogs runs in a worker, and the dialogs have no Preview.
A plug-in command applies as itself, one undo step named after it.
Commands that automation runs directly still run where they are
called and return their result.
- packaging/web: the worker files carry no hash, so the sample cache
rules make only the hashed app files immutable.
A plug-in that went on calling after a failed `vc_call` still had each
later call made on the document, although the run fails and is undone
at its end. After the run's first failed call, `vc_call` now returns
`-11` (CALL_NO_CONTEXT) and the host makes no further call; the run
still fails with the first call's reason.
vc_call returning -11 (from the start function, or in a run that can't make
calls) now fails the run like every other code, so a plug-in that ignores
it can't report success for a call that never ran. Calls are allowed once
the module has loaded, so a start-function call gets -11 instead of
trapping.
A filter at plug-in API level 2 with the new `commands` permission names
the commands it may run in its manifest's `commandAllowlist` and runs
them with `env.vc_call`, reading each result with `env.vc_call_result`.
Each call runs through Session::execute on the run's document and sees
what earlier calls changed; the calls and the filter's output are one
undo step, and a run that fails, is cancelled or makes a failed call
leaves the documents, their history and the session state the commands
change as they were.
Commands that touch files, the clipboard, preferences, the view,
scripts, actions, plug-ins, open documents or the undo history are never
callable, and every other command must be listed as allowed in
cmd/plugin_call/reviewed.rs, so a new command is refused until placed.
Calls are capped at 1,000 a run, 8 MiB a call and 64 MiB a run, and each
costs instructions from the run's budget. plugin.install refuses a
manifest that lists a refused command and reports unknown ids;
plugin.inspect lists both, and the approval dialog lists the commands.
Refs #2186