Repository navigation
fix: remove user-origin stylesheets in removeInsertedCSS() - #55538
Conversation
Both removal paths called WebDocument::RemoveInsertedStyleSheet without an origin, so Blink only looked in its author-origin list and a sheet inserted with cssOrigin: 'user' stayed applied. The key does not record its origin, so remove it from both the author and user lists. Keys are unique and removing an unknown key is a no-op in Blink. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KX1hkNiiBq2fQEsXWusxpm Co-authored-by: Claude <noreply@anthropic.com>
Instead of removing a key from both Blink's author and user lists,
record the origin in the key that insertCSS() returns. Blink's keys are
decimal counters, so user-origin keys get a "user:" prefix that cannot
collide with one, and author-origin keys are returned unchanged.
Removal decodes the prefix and makes a single RemoveInsertedStyleSheet
call. Both renderer paths share the helper in inserted_css.{h,cc}.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KX1hkNiiBq2fQEsXWusxpm
Co-authored-by: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
I reviewed this backport from a standalone clone and didn't find any bugs. A human should still check it, because it calls a two-argument WebDocument::RemoveInsertedStyleSheet(key, origin) that I can't see from here. No patch in this repo adds it. Can you confirm the pinned Chromium on this branch has it?
What was reviewed:
shell/renderer/inserted_css.{h,cc}: user-origin keys get auser:prefix. Remove strips the prefix and picks the origin from it. Author keys are returned unchanged, so existing keys still work.- Both callers use the new helpers:
electron_api_web_frame.ccandelectron_api_service_impl.cc. The return type still matchesString16 keyinapi.mojom, and the new files are listed infilenames.gni. - The new specs use vitest matchers and await each result before asserting. They cover user-only removal, user and author sheets removed independently, and
webFramewith both origins.
Extended reasoning...
The change adds a small renderer-only helper, shell/renderer/inserted_css.{h,cc}. The webFrame and webContents insert/remove paths now go through it, and the key returned to JS for cssOrigin: 'user' changes to user:<n>. It touches no IPC validation, contextBridge or webPreferences code. The new specs cover removal for both origins through both APIs. I deferred rather than approved because the fix depends on a Blink RemoveInsertedStyleSheet overload that takes an origin. That upstream API can't be seen in this checkout, and no Chromium patch here adds it.
|
Release Notes Persisted
|
Backport of #55510
See that PR for details.
Notes: Fixed
removeInsertedCSS()not removingcssOrigin: 'user'stylesheets.