Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: a764f514974feefcceb1f2d05fd95dd1af8f68ea
https://github.com/WebKit/WebKit/commit/a764f514974feefcceb1f2d05fd95dd1af8f68ea
Author: Wenson Hsieh <[email protected]>
Date: 2026-08-11 (Tue, 11 Aug 2026)
Changed paths:
M Source/WebCore/editing/cocoa/EditorCocoa.mm
M Source/WebCore/editing/cocoa/NodeHTMLConverter.h
M Source/WebCore/editing/cocoa/NodeHTMLConverter.mm
M Source/WebCore/page/FrameTree.cpp
M Source/WebCore/page/FrameTree.h
M Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm
M Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm
M Tools/TestWebKitAPI/Tests/WebKit/WKWebView/SiteIsolation.mm
Log Message:
-----------
Site Isolation: copying and pasting text as attributed strings skips content
in nested cross-origin subframes
https://bugs.webkit.org/show_bug.cgi?id=321486
rdar://168703870
Reviewed by Ryosuke Niwa and Abrar Rahman Protyasha.
After the changes in 317283@main, we now include content from cross-origin
frames under the top
frame when serializing attributed string data to the pasteboard. However, this
logic is broken in
the case where there are same-origin frames nested underneath cross-origin
frames, since our current
approach of descending into RemoteFrames and asking for their contents as
attributed string doesn't
handle the case where we might need to later descend **back** into a subframe
hosted in the same
process as the main frame.
To fix this, we refactor the way in which this attributed string serialization
works to handle all
possible ways of nesting same- or cross-origin frames:
1. Serialize the selected DOM content into an attributed string. Whenever we
encounter a
`RemoteFrame`, append an object replacement character to the string, marked
with an internal
attribute representing the contents of that remote frame
(`remoteFrameIdentifierAttributeName`).
2. Serialize the contents of those remote frames. The UI process walks the
frame tree to find all
remote frames in the selection (including nested descendants) and asks each
web process for the
ones it hosts, since only the UI process knows which process hosts which
frame. The web process
containing the selection is blocked waiting on this reply, so it cannot be
asked for anything;
it serializes the frames it hosts underneath a remote frame itself.
3. Collate the attributed strings from [1] and [2] into a final, flattened
attributed string by
iteratively replacing each remote frame placeholder with its corresponding
subframe contents.
Tests:
SiteIsolation.ReadAttributedStringFromPasteboardAfterCopyWithCrossSiteIframe
SiteIsolation.ReadAttributedStringFromPasteboardAfterCopyWithNestedCrossSiteIframes
* Source/WebCore/editing/cocoa/EditorCocoa.mm:
(WebCore::selectionAsAttributedString):
(WebCore::attributedStringByReplacingRemoteFrameMarkers):
(WebCore::populateRichTextDataIfNeeded):
(WebCore::Editor::writeSelectionToPasteboard):
(WebCore::Editor::dataInRTFDFormat):
(WebCore::Editor::dataInRTFFormat):
* Source/WebCore/editing/cocoa/NodeHTMLConverter.h:
(WebCore::attributedString): Deleted.
* Source/WebCore/editing/cocoa/NodeHTMLConverter.mm:
(HTMLConverter::HTMLConverter):
(HTMLConverter::_addRemoteFrameMarker):
(HTMLConverter::_processElement):
Add placeholders to represent the contents of remote frames embedded in the
attributed string, which
are later removed (and replaced with attributed string data taken from their
respective subframes,
if we got data from them).
(WebCore::remoteFrameIdentifierAttributeName):
(WebCore::containsRemoteFrameContentMarkers):
(WebCore::attributedString):
Add an option to extract cross-origin frames as placeholders in the attributed
string (see above).
* Source/WebCore/page/FrameTree.cpp:
(WebCore::FrameTree::containsRemoteFrame const):
(WebCore::FrameTree::hasRemoteFrameAncestor const):
* Source/WebCore/page/FrameTree.h:
* Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm:
(WebKit::WebPageProxy::getAttributedStringsForRemoteFrames):
* Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm:
(WebKit::WebPage::attributedStringsForRemoteFrames):
(WebKit::WebPage::getContentsAsAttributedStringForFrames):
* Tools/TestWebKitAPI/Tests/WebKit/WKWebView/SiteIsolation.mm:
(TestWebKitAPI::(SiteIsolation,
ReadAttributedStringFromPasteboardAfterCopyWithCrossSiteIframe)):
(TestWebKitAPI::(SiteIsolation,
ReadAttributedStringFromPasteboardAfterCopyWithNestedCrossSiteIframes)):
Canonical link: https://commits.webkit.org/319010@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications