Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 06048ae563649413a3a23b7b1793d0fa879dc124
      
https://github.com/WebKit/WebKit/commit/06048ae563649413a3a23b7b1793d0fa879dc124
  Author: Wenson Hsieh <[email protected]>
  Date:   2026-02-05 (Thu, 05 Feb 2026)

  Changed paths:
    A 
LayoutTests/fast/text-extraction/debug-text-extraction-lightweight-discretionary-expected.txt
    A 
LayoutTests/fast/text-extraction/debug-text-extraction-lightweight-discretionary.html
    M Source/WebCore/page/text-extraction/TextExtraction.cpp
    M Source/WebCore/page/text-extraction/TextExtraction.h
    M Source/WebCore/page/text-extraction/TextExtractionTypes.cpp
    M Source/WebCore/page/text-extraction/TextExtractionTypes.h
    M Source/WebKit/Scripts/webkit/messages.py
    M Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in
    M Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
    M Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h
    M Source/WebKit/UIProcess/API/Cocoa/_WKTextExtraction.h
    M Source/WebKit/UIProcess/API/Cocoa/_WKTextExtraction.mm
    M Source/WebKit/UIProcess/WebFrameProxy.cpp
    M Source/WebKit/UIProcess/WebFrameProxy.h
    M Source/WebKit/WebProcess/WebPage/WebFrame.cpp
    M Source/WebKit/WebProcess/WebPage/WebFrame.h
    M Source/WebKit/WebProcess/WebPage/WebFrame.messages.in
    M Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl
    M Tools/TestRunnerShared/UIScriptContext/UIScriptController.h
    M Tools/TestRunnerShared/UIScriptContext/UIScriptControllerShared.cpp
    M Tools/WebKitTestRunner/cocoa/UIScriptControllerCocoa.mm

  Log Message:
  -----------
  [AutoFill Debugging] Add a way to enforce paragraph word limit only if the 
total amount of visible text is large
https://bugs.webkit.org/show_bug.cgi?id=307023
rdar://169675190

Reviewed by Abrar Rahman Protyasha and Aditya Keerthi.

Add support for a `maxWordsPerParagraphPolicy` property on the text extraction 
configuration, which
determines when `maxWordsPerParagraph` should be applied. The supported values 
are `.always` (the
current behavior) and `.discretionary`, which leaves the decision up to the 
engine.

When `.discretionary` is set, we'll currently only enforce the word limit if 
the total size of the
document is "small" (arbitrarily set to under ~4k characters of visible text).

Test: fast/text-extraction/debug-text-extraction-lightweight-discretionary.html

* 
LayoutTests/fast/text-extraction/debug-text-extraction-lightweight-discretionary-expected.txt:
 Added.
* 
LayoutTests/fast/text-extraction/debug-text-extraction-lightweight-discretionary.html:
 Added.

Add a layout test that passes `discretionary` for the max word limit policy, 
and verifies that we
don't end up truncating any text in this test case.

* Source/WebCore/page/text-extraction/TextExtraction.cpp:
(WebCore::TextExtraction::extractItemData):
(WebCore::TextExtraction::extractRecursive):
(WebCore::TextExtraction::extractItem):

Increment the total length of all visible text items encountered while 
recursively collecting text
extraction items.

* Source/WebCore/page/text-extraction/TextExtraction.h:
* Source/WebCore/page/text-extraction/TextExtractionTypes.cpp:
(WebCore::TextExtraction::collateRecursive):
(WebCore::TextExtraction::collatePageResults):
(WebCore::TextExtraction::collateItemsRecursive): Deleted.
(WebCore::TextExtraction::collatePageItems): Deleted.
* Source/WebCore/page/text-extraction/TextExtractionTypes.h:

Refactor `TextExtraction::extractItem` to return a `TextExtraction::Result` 
instead of an `Item`.
The `Result` struct is just a basic wrapper around an `Item` and some metadata 
(which currently only
includes the character count of all extracted visible text). In the future, 
this could include more
information, such as any data detector results or general information about the 
DOM or meta tags.

* Source/WebKit/Scripts/webkit/messages.py:
(headers_for_type):
* Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in:
* Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView 
_extractDebugTextWithConfigurationWithoutUpdatingFilterRules:assertionScope:completionHandler:]):
(-[WKWebView _requestTextExtractionInternal:completion:]):
(-[WKWebView _requestTextExtraction:completionHandler:]):
* Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h:
* Source/WebKit/UIProcess/API/Cocoa/_WKTextExtraction.h:
* Source/WebKit/UIProcess/API/Cocoa/_WKTextExtraction.mm:
(-[_WKTextExtractionConfiguration _initForOnlyVisibleText:]):

Add the new policy flag.

* Source/WebKit/UIProcess/WebFrameProxy.cpp:
(WebKit::WebFrameProxy::requestTextExtraction):
* Source/WebKit/UIProcess/WebFrameProxy.h:
* Source/WebKit/WebProcess/WebPage/WebFrame.cpp:
(WebKit::WebFrame::requestTextExtraction):
* Source/WebKit/WebProcess/WebPage/WebFrame.h:
* Source/WebKit/WebProcess/WebPage/WebFrame.messages.in:

Make `requestTextExtraction` return a `Result` instead of an `Item` (see above).

* Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
* Tools/TestRunnerShared/UIScriptContext/UIScriptController.h:
* Tools/TestRunnerShared/UIScriptContext/UIScriptControllerShared.cpp:
(WTR::toTextExtractionTestOptions):
* Tools/WebKitTestRunner/cocoa/UIScriptControllerCocoa.mm:
(WTR::createTextExtractionConfiguration):

Make it possible for layout tests to set the new policy property.

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



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to