Skip to content

Make the restricted-mode lock icon a keyboard-reachable button - #19808

Merged
gtritchie merged 4 commits into
mainfrom
bugfix/trust-lock-button
Nov 25, 2026
Merged

gtritchie merged 4 commits into
mainfrom
bugfix/trust-lock-button

Conversation

@gtritchie

@gtritchie gtritchie commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Fixes #19801.

The Restricted Mode lock icon in the main toolbar was a <div> with a click handler. It wasn't a Tab or arrow-key stop, and screen readers announced only its title.

  • The lock is now a native <button> named "Restricted Mode: review project trust". Its existing title ("startup files were not executed for this project") becomes the button's description. The SVG is aria-hidden.
  • The 0.7 opacity now applies to the SVG instead of the button, so the focus ring isn't dimmed.
  • Reopening the trust dialog from the lock used the trust status from session startup. After you declined an undecided project, it still asked "Do you trust this project?". TrustPresenter now remembers the decline and shows "This project is restricted" when the dialog is reopened.

Tested in a dev server: the main toolbar's arrow keys reach the lock, Enter and Space open the dialog, and focus returns to the lock after "Keep restricted". Declining "Do you trust this project?" and then reopening from the lock shows "This project is restricted".

The lock was a div with a click handler: not a Tab or arrow-key stop
in the main toolbar, and announced only by its title. It is now a
native button named "Restricted Mode: review project trust", keeping
the title as its description. The 0.7 opacity moves from the button to
its SVG so the focus ring isn't dimmed.

Addresses #19801.
Reopening the trust dialog from the lock icon used the trust request
from session startup. After declining an undecided project, it still
showed "Do you trust this project?" instead of "This project is
restricted". A successful revoke now records the untrusted status,
and deferred init refreshes the cached trust request after a restart.

Addresses #19801.
Workbench already merges deferred-init data into SessionInfo, so the
setTrustRequest call in TrustPresenter.onDeferredInitCompleted did
nothing. That merge also replaced the recorded decline with the
server's startup status ("unknown"; revokeTrust doesn't update it)
when the user declined before deferred init arrived. The presenter
now keeps the decline itself and passes it to the dialog opened from
the lock icon. lastTrustStatus_ still tracks the server's status, so
a late deferred init doesn't reopen the dialog.

Addresses #19801.
@gtritchie gtritchie added this to the 2026.12 (Parrot Balsam) milestone Nov 25, 2026
@gtritchie

gtritchie commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

Review findings I chose not to act on:

From a Claude Code /code-review:

  • Screen readers say "Restricted Mode" twice. The button's name is "Restricted Mode: review project trust", and its title, which screen readers read as the description, also starts with "Restricted Mode:". I left it: the name is what Restricted-mode lock icon in the main toolbar can't be reached by keyboard or identified by screen readers #19801 asked for, and the title is also the visible hover text.
  • No element ID on the lock button. The reviewer suggested an ElementIds constant so Playwright tests don't have to select by a translated label. No e2e test is planned for this button; one can be added with a test.

From roborev:

  • The remembered decline isn't cleared when R restarts. After a decline, TrustPresenter keeps trustDeclined_ for as long as the page is loaded. To hit the problem you'd decline, then change trust outside the dialog (the internal .rs.trust.reset(), or from another session on the same project), restart R without reloading the page, and reopen the dialog from the lock. You'd then see "This project is restricted" instead of "Do you trust this project?". Both dialogs offer "Trust this project", so the cost is the wording. Clearing the decline correctly would mean telling a late deferred init in the same session apart from a new session's, or making the server keep its in-memory trust status current when trust changes mid-session. That's more than this edge case is worth.

Two other findings were fixed on this branch: reopening the dialog after a decline used the startup status (ae0d072), and a decline made before deferred init was overwritten by it (8bf7d9c).

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Four findings: two minor issues with the new trustDeclined_ flag, and two pre-existing issues. Nothing blocking. The button conversion, its accessible name, the 24px target, and toolbar arrow-key navigation look correct.

@Override
public void onResponseReceived(VoidResponse response)
{
trustDeclined_ = true;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

trustDeclined_ is set only when the revoke_trust response comes back, but by then the dialog has closed and focus is back on the lock. If the lock is activated before the response arrives (for example, Enter held down on "Don't trust": Enter clicks a native button and auto-repeats), the dialog reopens asking "Do you trust this project?". The window is short. Setting the flag when the decline is chosen, before calling revokeTrust, and clearing it in onError would close it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 8bba893: trustDeclined_ is now set when the decline is chosen, before revokeTrust, and cleared in onError. Tested on a dev server by clicking the lock right after "No", before the response came back. The dialog showed "This project is restricted".


// The server's trust request keeps the status this session started with,
// so a decline is remembered here for reopening the dialog from the lock.
private boolean trustDeclined_;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Nothing clears trustDeclined_, and Restart R (ApplicationQuit.onRestartR fires SuspendAndRestartEvent) doesn't reload the page, so the flag can outlive the state it describes.

To reproduce: decline from the startup dialog, run .rs.trust.reset(), then Restart R. The new session reports unknown, and trustStatusChanged is false, so no dialog opens on its own. Clicking the lock shows the restricted variant, whose "Keep restricted" records nothing (TrustRequestDialog.java:226 skips dontTrustOperation_). Before this change the lock would have asked the undecided question.

It takes an internal function to trigger, so it's minor. Clearing the flag in onDeferredInitCompleted when a trust_request arrives would handle it, or see the comment on line 145.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Leaving this one. It needs the internal .rs.trust.reset() (or a trust change from another session) followed by Restart R. The symptom is the restricted wording instead of the undecided one, and both dialogs still offer "Trust this project". Clearing the flag in onDeferredInitCompleted would bring back the race fixed in 8bf7d9c: a decline made before the same session's deferred init would be overwritten by its stale "unknown".

@@ -139,7 +145,10 @@ void onShowTrustRequestDialog()
session_.getSessionInfo().getTrustRequest();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Pre-existing, but it's the root cause behind #19801: the lock reads the trust request captured at page load (session info is set only in Application.java at startup), while onDeferredInitCompleted receives fresh trust_request data after every Restart R and uses it only for the automatic dialog.

trustDeclined_ covers declines made in this dialog, but not others. For example: open an undecided project, run .rs.trust.revoke() in the console (or decline from another session on the same project), then Restart R. The automatic dialog correctly says "This project is restricted". After "Keep restricted", clicking the lock asks "Do you trust this project?" again, and its risky-files list is also the one from page load.

Keeping the latest deferred-init trust_request and reading it here would fix both paths and make trustDeclined_ unnecessary.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Session info is updated after a restart too. Workbench.onDeferredInitCompleted calls session_.updateSessionInfo(event.getData()), which Object.assigns each deferred-init payload into session info, trust_request (and its risky files) included. So the lock reads the latest session's trust request. I checked your example on a dev server. I opened an undecided project and dismissed its dialog with Escape, so no decline was recorded. Then I ran .rs.trust.revoke(); .rs.api.restartSession(). The page didn't reload. The automatic dialog said "This project is restricted", and so did the lock afterwards.

The gap trustDeclined_ covers is narrower: revokeTrust doesn't update the session's in-memory status, so session info keeps "unknown" until the next session's deferred init. No change here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You're right, I missed updateSessionInfo: Workbench.onDeferredInitCompleted merges each deferred-init payload into session info, so the lock reads the current session's trust request. Withdrawn; no change needed.

trustOperation_ = trustOperation;
dontTrustOperation_ = dontTrustOperation;
isUntrusted_ = "untrusted".equals(status);
isUntrusted_ = TrustRequestEvent.STATUS_UNTRUSTED.equals(status);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Pre-existing: status_ (assigned at line 52, declared at line 281) is never read; only isUntrusted_ is used. It could go while you're in here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Removed in 8bba893.

Holding Enter on "No" could reopen the dialog from the lock before
revoke_trust responded, so it asked "Do you trust this project?"
again. The decline is now recorded when chosen and undone on error.
Also removes TrustRequestDialog's unused status_ field.

Addresses #19801.
@github-actions

Copy link
Copy Markdown

RStudio E2E - all platforms

All tests passed!

#################### 100% pass rate

Passed Failed Skipped Flaky
5825 0 254 1
Platform ✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
✅ auth-teardown 4 0 16 0
✅ desktop-linux 1456 0 49 1
✅ desktop-macos 1464 0 43 0
✅ desktop-windows 1452 0 60 0
✅ server-linux 1401 0 54 0
✅ setup 48 0 32 0

View report online


All platforms - commit 8bba8932dd9e1b4877b6c6f184ed8732fa63fc7e - Run #2514

@gtritchie
gtritchie merged commit 6b0f315 into main Nov 25, 2026
55 checks passed
@gtritchie
gtritchie deleted the bugfix/trust-lock-button branch November 25, 2026 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Restricted-mode lock icon in the main toolbar can't be reached by keyboard or identified by screen readers

1 participant