Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: b7f73eb8a257afa72ba6adec0ebb0bb19017eaad
https://github.com/WebKit/WebKit/commit/b7f73eb8a257afa72ba6adec0ebb0bb19017eaad
Author: Wenson Hsieh <[email protected]>
Date: 2025-10-04 (Sat, 04 Oct 2025)
Changed paths:
M LayoutTests/fast/text-extraction/debug-text-extraction-basic-expected.txt
M Source/WebKit/Shared/Extensions/WebExtensionSQLiteStatement.h
A Source/WebKit/Shared/TextExtractionToStringConversion.cpp
A Source/WebKit/Shared/TextExtractionToStringConversion.h
M Source/WebKit/Sources.txt
M Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
M Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h
M Source/WebKit/UIProcess/API/Cocoa/_WKTextExtraction.swift
M Source/WebKit/UIProcess/API/Cocoa/_WKTextExtractionInternal.h
M Source/WebKit/UIProcess/Cocoa/TextExtraction/WKTextExtractionUtilities.h
M Source/WebKit/UIProcess/Cocoa/TextExtraction/WKTextExtractionUtilities.mm
M Source/WebKit/WebKit.xcodeproj/project.pbxproj
Log Message:
-----------
[AutoFill Debugging] Refactor debug text extraction to work with non-Cocoa
ports
https://bugs.webkit.org/show_bug.cgi?id=300135
rdar://161919662
Reviewed by Abrar Rahman Protyasha.
This patch moves logic to convert a `WebCore::TextExtraction::Item` into a
hierarchical debug text
representation out of platform-specific Swift/ObjC code in
`_WKTextExtraction.swift` and
`WKTextExtractionUtilities.mm`, and into a new
`TextExtractionToStringConversion.cpp`, which is
platform agnostic.
This also allows us to skip the conversion from `WebCore::TextExtraction::Item`
to a tree of
`WKTextExtractionItem` Objective-C objects for the purposes of extracting
`-_debugText:`, and
instead directly convert from `WebCore::TextExtraction::Item` to a string
representation.
Note that this new helper file is in `Source/WebKit/Shared`, so that it can be
invoked from within
the web process if necessary, in a subsequent patch. For now, this helper is
only invoked from the
UI process.
No change in behavior (beyond the lack of trailing newline in the output
below); see below for more
details.
* LayoutTests/fast/text-extraction/debug-text-extraction-basic-expected.txt:
Rebaseline a layout test; the debug text extraction no longer has a trailing
newline with the new
way of aggregating text results per line.
* Source/WebKit/Shared/Extensions/WebExtensionSQLiteStatement.h:
* Source/WebKit/Shared/TextExtractionToStringConversion.cpp: Added.
(WebKit::TextExtractionAggregator::TextExtractionAggregator):
(WebKit::TextExtractionAggregator::~TextExtractionAggregator):
Create a new RAII object to encapsulate the debug text conversion lifecycle.
This is necessary
because `TextExtraction::Item` itself is just a struct (not ref-counted) that's
passed back in the
completion handler of `WebPageProxy::requestTextExtraction`, but when
recursively converting these
text extraction results, we may need to perform asynchronous filtering
operations to verify that
(e.g.) text content in extracted text items represent user-visible text, and the
`TextExtractionFilter`'s classifier considers the text valid. This was
previously not necessary,
because we took advantage of the fact that we first converted
`TextExtraction::Item` to ObjC objects
which we just retained while performing async filtering (and whose text we
could mutate as needed).
This is created with the overall completion handler, which is invoked in the
destructor. See
`convertToText` below for the usage.
(WebKit::TextExtractionAggregator::create):
(WebKit::TextExtractionAggregator::addResult):
Add a helper method to add results (give a line number, indentation level and
comma-separated
components) to the final text extraction. Importantly, note that these results
don't necessary come
in in order by line number, due to the fact that extraction for text nodes may
involve additional
async validation.
(WebKit::TextExtractionAggregator::advanceToNextLine):
Add a helper method to advance to the next line (i.e. claiming the next line
number) when dumping
text for a new item in the extraction result tree.
(WebKit::commaSeparatedString):
(WebKit::escapeString):
(WebKit::eventListenerTypesToStringArray):
Migrate several helper methods over from `_WKTextExtraction.swift`.
(WebKit::partsForItem):
(WebKit::addPartsForText):
(WebKit::addPartsForItem):
(WebKit::addTextRepresentationRecursive):
Implement the bulk of the algorithm here. This recursively traverses extraction
results, adding
results to the `aggregator` in the process. This takes an async filtering
callback (which returns a
`NativePromise`) which applies to all extracted text items. While any of these
promises is pending,
the `aggregator` will be kept alive.
(WebKit::convertToText):
* Source/WebKit/Shared/TextExtractionToStringConversion.h: Copied from
Source/WebKit/UIProcess/Cocoa/TextExtraction/WKTextExtractionUtilities.h.
(WebKit::convertToText):
* Source/WebKit/Sources.txt:
* Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _activeNativeMenuItemTitles]):
Make this return a list of item titles, now that we no longer use
`WKTextExtractionPopupMenu`.
(-[WKWebView _debugTextWithConfiguration:completionHandler:]):
Reimplement this in terms of `-_requestTextExtractionInternal:completion:`;
instead of getting a
`WKTextExtractionResult` and converting that into a text representation, we now
go directly from
`TextExtraction::Item` to `NSString *`.
We also reimplement the async filtering logic here (i.e. passing text through
`WebKit::TextExtractionFilter` and `-_validateText:`) using the
`TextExtractionFilterCallback` in
`convertToText`, which allows us to delete the now-unused helpers to
recursively filter out text in
the ObjC extraction result tree, in `WKTextExtractionUtilities.mm`.
(-[WKWebView _requestTextExtractionInternal:completion:]):
Pull common logic to obtain an `TextExtraction::Item` out into a separate
helper method.
(-[WKWebView _requestTextExtraction:completionHandler:]):
(-[WKWebView _validateText:inNode:completionHandler:]):
(-[WKWebView _popupMenuForTextExtractionResults]): Deleted.
Remove `WKTextExtractionPopupMenu` entirely, now that debug text extraction no
longer depends on
producing a `WKTextExtractionResult` and asking it for a text representation.
* Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h:
* Source/WebKit/UIProcess/API/Cocoa/_WKTextExtraction.swift:
(WKTextExtractionEventListenerTypes.description): Deleted.
(eventListenerTypesAsArray(_:)): Deleted.
(String.escaped): Deleted.
(WKTextExtractionItem.textRepresentationRecursive(_:)): Deleted.
(WKTextExtractionItem.textRepresentationParts): Deleted.
(WKTextExtractionContainerItem.textRepresentationParts): Deleted.
(WKTextExtractionContentEditableItem.textRepresentationParts): Deleted.
(WKTextExtractionTextFormControlItem.textRepresentationParts): Deleted.
(WKTextExtractionLinkItem.textRepresentationParts): Deleted.
(WKTextExtractionTextItem.textRepresentationParts): Deleted.
(WKTextExtractionScrollableItem.textRepresentationParts): Deleted.
(WKTextExtractionSelectItem.textRepresentationParts): Deleted.
(WKTextExtractionImageItem.textRepresentationParts): Deleted.
(WKTextExtractionPopupMenu.textRepresentation): Deleted.
(WKTextExtractionResult.textRepresentation): Deleted.
Delete now-unused code (see `TextExtractionToStringConversion.cpp` above).
* Source/WebKit/UIProcess/API/Cocoa/_WKTextExtractionInternal.h:
* Source/WebKit/UIProcess/Cocoa/TextExtraction/WKTextExtractionUtilities.h:
* Source/WebKit/UIProcess/Cocoa/TextExtraction/WKTextExtractionUtilities.mm:
(WebKit::filterTextRecursive): Deleted.
(WebKit::filterText): Deleted.
Moved into `WKWebView.mm` (see above).
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:
Canonical link: https://commits.webkit.org/301002@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes