Skip to content

fix: remove user-origin stylesheets in removeInsertedCSS() - #55538

Merged
MarshallOfSound merged 2 commits into
45-x-yfrom
trop/45-x-y-bp-fix-remove-user-origin-stylesheets-in-removeinsertedcss--1793475571738
Oct 31, 2026
Merged

MarshallOfSound merged 2 commits into
45-x-yfrom
trop/45-x-y-bp-fix-remove-user-origin-stylesheets-in-removeinsertedcss--1793475571738

Conversation

@trop

@trop trop Bot commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

Backport of #55510

See that PR for details.

Notes: Fixed removeInsertedCSS() not removing cssOrigin: 'user' stylesheets.

trop Bot and others added 2 commits October 31, 2026 19:39
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>
@trop trop Bot added 45-x-y backport This is a backport PR semver/patch backwards-compatible bug fixes labels Oct 31, 2026

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 a user: 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.cc and electron_api_service_impl.cc. The return type still matches String16 key in api.mojom, and the new files are listed in filenames.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 webFrame with 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.

@MarshallOfSound
MarshallOfSound enabled auto-merge (squash) October 31, 2026 19:47
@MarshallOfSound
MarshallOfSound merged commit 898db71 into 45-x-y Oct 31, 2026
90 checks passed
@MarshallOfSound
MarshallOfSound deleted the trop/45-x-y-bp-fix-remove-user-origin-stylesheets-in-removeinsertedcss--1793475571738 branch October 31, 2026 20:37
@release-clerk

release-clerk Bot commented Oct 31, 2026

Copy link
Copy Markdown

Release Notes Persisted

Fixed removeInsertedCSS() not removing cssOrigin: 'user' stylesheets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

45-x-y backport This is a backport PR semver/patch backwards-compatible bug fixes

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant