Skip to content

[Site Isolation] prefers-color-scheme doesn't see color-scheme from parent frames and above#62786

Merged
webkit-commit-queue merged 1 commit into
WebKit:mainfrom
tuankiet65:eng/Site-Isolation-prefers-color-scheme-doesn-t-see-color-scheme-from-parent-frames-and-above
Apr 28, 2026
Merged

[Site Isolation] prefers-color-scheme doesn't see color-scheme from parent frames and above#62786
webkit-commit-queue merged 1 commit into
WebKit:mainfrom
tuankiet65:eng/Site-Isolation-prefers-color-scheme-doesn-t-see-color-scheme-from-parent-frames-and-above

Conversation

@tuankiet65
Copy link
Copy Markdown
Member

@tuankiet65 tuankiet65 commented Apr 15, 2026

9e45d72

[Site Isolation] prefers-color-scheme doesn't see color-scheme from parent frames and above
rdar://172229372
https://bugs.webkit.org/show_bug.cgi?id=309611

Reviewed by Simon Fraser.

310465@main makes prefers-color-scheme follow the color scheme of the embedding element,
if the document is embedded in an iframe. 310874@main adds a behavior to use the system
appearance if the parent iframe doesn't explicitly set a color-scheme. This uses
ownerRenderer() to peek at the embedding element's style, and thus won't work with Site
Isolation. This patch makes it work with Site Isolation by using RemoteFrameLayoutInfo to
broadcast the info whether the embedding element's color scheme is explicitly set or not.
This involves extending RemoteFrameLayoutInfo::ownerElementAppearance (renamed from
useDarkAppearance) to store this info.

Additionally, this patch changes the logic of prefers-color-scheme to consider ancestor
embedding elements if the immediate embedding element doesn't have an explicitly
set color-scheme, in the case of nested iframes. The preferred color scheme is taken
from the nearest ancestor embedding element with an explicitly set color-scheme.
If none exists, it falls back to the system appearance.

Tests: http/tests/css/prefers-color-scheme-in-nested-iframes-follows-system-preference.html
       imported/w3c/web-platform-tests/css/css-color-adjust/rendering/dark-color-scheme/color-scheme-iframe-preferred-nested.sub.html

* LayoutTests/TestExpectations:
* LayoutTests/http/tests/css/prefers-color-scheme-in-cross-origin-iframe-follows-system-preference-without-parent-color-scheme.html:
* LayoutTests/http/tests/css/prefers-color-scheme-in-nested-iframes-follows-system-preference-expected.txt: Added.
* LayoutTests/http/tests/css/prefers-color-scheme-in-nested-iframes-follows-system-preference.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/css-color-adjust/rendering/dark-color-scheme/color-scheme-iframe-preferred-nested.sub-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/css-color-adjust/rendering/dark-color-scheme/color-scheme-iframe-preferred-nested.sub.html: Added.
* LayoutTests/platform/mac-site-isolation/TestExpectations:
* Source/WebCore/css/query/MediaQueryFeatures.cpp:
(WebCore::MQ::Features::frameOwnerElementAncestorsUseDarkAppearance):
(WebCore::MQ::Features::prefersColorSchemeFeatureSchema):
(WebCore::MQ::Features::frameUsesDarkAppearanceForPrefersColorScheme):
* Source/WebCore/page/Frame.cpp:
(WebCore::Frame::updateFrameTreeSyncData):
* Source/WebCore/page/FrameView.h:
* Source/WebCore/page/LocalFrameView.cpp:
(WebCore::LocalFrameView::appearanceOfOwnerElementOfChildFrame const):
(WebCore::LocalFrameView::ownerElementOfChildFrameUsesDarkAppearance const): Deleted.
* Source/WebCore/page/LocalFrameView.h:
* Source/WebCore/page/Page.cpp:
(WebCore::Page::syncLocalFrameInfoToRemote):
* Source/WebCore/page/RemoteFrameLayoutInfo.h:
* Source/WebCore/page/RemoteFrameView.cpp:
(WebCore::RemoteFrameView::appearanceOfOwnerElementOfChildFrame const):
(WebCore::RemoteFrameView::ownerElementOfChildFrameUsesDarkAppearance const): Deleted.
* Source/WebCore/page/RemoteFrameView.h:
* Source/WebCore/rendering/RenderView.cpp:
(WebCore::RenderView::shouldPaintBaseBackground const):
* Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in:

Canonical link: https://commits.webkit.org/312212@main

82c17ab

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows Apple Internal
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win ✅ 🛠 ios-apple
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 ✅ 🧪 win-tests ❌ 🛠 mac-apple
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe ✅ 🛠 vision-apple
✅ 🧪 ios-wk2-wpt ✅ 🧪 api-mac-debug ✅ 🛠 gtk3-libwebrtc
✅ 🧪 api-ios ✅ 🧪 mac-wk1 ✅ 🛠 gtk
✅ 🛠 ios-safer-cpp ✅ 🧪 mac-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 vision ✅ 🧪 mac-AS-debug-wk2 loading 🧪 api-gtk
✅ 🛠 🧪 merge ✅ 🛠 vision-sim ✅ 🧪 mac-wk2-stress ✅ 🛠 playstation
✅ 🧪 vision-wk2 ✅ 🧪 mac-intel-wk2
✅ 🛠 tv ✅ 🛠 mac-safer-cpp
✅ 🛠 tv-sim
✅ 🛠 watch
✅ 🛠 watch-sim

@tuankiet65 tuankiet65 requested a review from cdumez as a code owner April 15, 2026 00:50
@tuankiet65 tuankiet65 self-assigned this Apr 15, 2026
@tuankiet65 tuankiet65 added the Layout and Rendering For bugs with layout and rendering of Web pages. label Apr 15, 2026
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Apr 15, 2026
@tuankiet65 tuankiet65 removed the merging-blocked Applied to prevent a change from being merged label Apr 15, 2026
@tuankiet65 tuankiet65 force-pushed the eng/Site-Isolation-prefers-color-scheme-doesn-t-see-color-scheme-from-parent-frames-and-above branch from b40b4bf to 88f2c5e Compare April 15, 2026 01:08
@tuankiet65 tuankiet65 force-pushed the eng/Site-Isolation-prefers-color-scheme-doesn-t-see-color-scheme-from-parent-frames-and-above branch from 88f2c5e to 692adb1 Compare April 15, 2026 23:42
@tuankiet65 tuankiet65 requested a review from smfr April 15, 2026 23:44
@tuankiet65 tuankiet65 force-pushed the eng/Site-Isolation-prefers-color-scheme-doesn-t-see-color-scheme-from-parent-frames-and-above branch from 692adb1 to 85c81e2 Compare April 23, 2026 23:18
Comment thread Source/WebCore/css/query/MediaQueryFeatures.cpp Outdated
Comment thread Source/WebCore/css/query/MediaQueryFeatures.cpp Outdated
@tuankiet65 tuankiet65 force-pushed the eng/Site-Isolation-prefers-color-scheme-doesn-t-see-color-scheme-from-parent-frames-and-above branch from 85c81e2 to 82c17ab Compare April 27, 2026 19:32
@tuankiet65 tuankiet65 added the merge-queue Applied to send a pull request to merge-queue label Apr 28, 2026
…arent frames and above

rdar://172229372
https://bugs.webkit.org/show_bug.cgi?id=309611

Reviewed by Simon Fraser.

310465@main makes prefers-color-scheme follow the color scheme of the embedding element,
if the document is embedded in an iframe. 310874@main adds a behavior to use the system
appearance if the parent iframe doesn't explicitly set a color-scheme. This uses
ownerRenderer() to peek at the embedding element's style, and thus won't work with Site
Isolation. This patch makes it work with Site Isolation by using RemoteFrameLayoutInfo to
broadcast the info whether the embedding element's color scheme is explicitly set or not.
This involves extending RemoteFrameLayoutInfo::ownerElementAppearance (renamed from
useDarkAppearance) to store this info.

Additionally, this patch changes the logic of prefers-color-scheme to consider ancestor
embedding elements if the immediate embedding element doesn't have an explicitly
set color-scheme, in the case of nested iframes. The preferred color scheme is taken
from the nearest ancestor embedding element with an explicitly set color-scheme.
If none exists, it falls back to the system appearance.

Tests: http/tests/css/prefers-color-scheme-in-nested-iframes-follows-system-preference.html
       imported/w3c/web-platform-tests/css/css-color-adjust/rendering/dark-color-scheme/color-scheme-iframe-preferred-nested.sub.html

* LayoutTests/TestExpectations:
* LayoutTests/http/tests/css/prefers-color-scheme-in-cross-origin-iframe-follows-system-preference-without-parent-color-scheme.html:
* LayoutTests/http/tests/css/prefers-color-scheme-in-nested-iframes-follows-system-preference-expected.txt: Added.
* LayoutTests/http/tests/css/prefers-color-scheme-in-nested-iframes-follows-system-preference.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/css-color-adjust/rendering/dark-color-scheme/color-scheme-iframe-preferred-nested.sub-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/css-color-adjust/rendering/dark-color-scheme/color-scheme-iframe-preferred-nested.sub.html: Added.
* LayoutTests/platform/mac-site-isolation/TestExpectations:
* Source/WebCore/css/query/MediaQueryFeatures.cpp:
(WebCore::MQ::Features::frameOwnerElementAncestorsUseDarkAppearance):
(WebCore::MQ::Features::prefersColorSchemeFeatureSchema):
(WebCore::MQ::Features::frameUsesDarkAppearanceForPrefersColorScheme):
* Source/WebCore/page/Frame.cpp:
(WebCore::Frame::updateFrameTreeSyncData):
* Source/WebCore/page/FrameView.h:
* Source/WebCore/page/LocalFrameView.cpp:
(WebCore::LocalFrameView::appearanceOfOwnerElementOfChildFrame const):
(WebCore::LocalFrameView::ownerElementOfChildFrameUsesDarkAppearance const): Deleted.
* Source/WebCore/page/LocalFrameView.h:
* Source/WebCore/page/Page.cpp:
(WebCore::Page::syncLocalFrameInfoToRemote):
* Source/WebCore/page/RemoteFrameLayoutInfo.h:
* Source/WebCore/page/RemoteFrameView.cpp:
(WebCore::RemoteFrameView::appearanceOfOwnerElementOfChildFrame const):
(WebCore::RemoteFrameView::ownerElementOfChildFrameUsesDarkAppearance const): Deleted.
* Source/WebCore/page/RemoteFrameView.h:
* Source/WebCore/rendering/RenderView.cpp:
(WebCore::RenderView::shouldPaintBaseBackground const):
* Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in:

Canonical link: https://commits.webkit.org/312212@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/Site-Isolation-prefers-color-scheme-doesn-t-see-color-scheme-from-parent-frames-and-above branch from 82c17ab to 9e45d72 Compare April 28, 2026 17:35
@webkit-commit-queue
Copy link
Copy Markdown
Collaborator

Committed 312212@main (9e45d72): https://commits.webkit.org/312212@main

Reviewed commits have been landed. Closing PR #62786 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 9e45d72 into WebKit:main Apr 28, 2026
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Layout and Rendering For bugs with layout and rendering of Web pages.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants