<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[260865] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/260865">260865</a></dd>
<dt>Author</dt> <dd>wenson_hsieh@apple.com</dd>
<dt>Date</dt> <dd>2020-04-28 22:16:23 -0700 (Tue, 28 Apr 2020)</dd>
</dl>

<h3>Log Message</h3>
<pre>[Text manipulation] Add a userInfo dictionary to _WKTextManipulationToken
https://bugs.webkit.org/show_bug.cgi?id=211151
<rdar://problem/62329534>

Reviewed by Darin Adler.

Source/WebCore:

Add an extensible mechanism for the text manipulation controller to send additional
metadata for each text manipulation token through to the WebKit client, for debugging
purposes.

Test: TextManipulation.StartTextManipulationExtractsUserInfo

* editing/TextManipulationController.cpp:
(WebCore::tokenInfo):
(WebCore::TextManipulationController::observeParagraphs):
* editing/TextManipulationController.h:

Add TextManipulationTokenInfo, and add an optional TextManipulationTokenInfo member to
TextManipulationToken. For now, just send over the document URL, element tag name, and
the value of the role attribute.

(WebCore::TextManipulationController::ManipulationTokenInfo::encode const):
(WebCore::TextManipulationController::ManipulationTokenInfo::decode):
(WebCore::TextManipulationController::ManipulationToken::encode const):
(WebCore::TextManipulationController::ManipulationToken::decode):

Source/WebKit:

* UIProcess/API/Cocoa/WKWebView.mm:
(createUserInfo):
(-[WKWebView _startTextManipulationsWithConfiguration:completion:]):
(-[WKWebView _completeTextManipulation:completion:]):
(-[WKWebView _completeTextManipulationForItems:completion:]):
* UIProcess/API/Cocoa/_WKTextManipulationToken.h:
* UIProcess/API/Cocoa/_WKTextManipulationToken.mm:
(-[_WKTextManipulationToken setUserInfo:]):
(-[_WKTextManipulationToken userInfo]):

Add a new `userInfo` dictionary to `_WKTextManipulationToken`, which contains several named
`NSString` keys.

(-[_WKTextManipulationToken isEqualToTextManipulationToken:includingContentEquality:]):
(-[_WKTextManipulationToken _descriptionPreservingPrivacy:]):

Tools:

Add a new API test to check the userInfo dictionary on text manipulation tokens.

* TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreeditingTextManipulationControllercpp">trunk/Source/WebCore/editing/TextManipulationController.cpp</a></li>
<li><a href="#trunkSourceWebCoreeditingTextManipulationControllerh">trunk/Source/WebCore/editing/TextManipulationController.h</a></li>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitUIProcessAPICocoaWKWebViewmm">trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm</a></li>
<li><a href="#trunkSourceWebKitUIProcessAPICocoa_WKTextManipulationTokenh">trunk/Source/WebKit/UIProcess/API/Cocoa/_WKTextManipulationToken.h</a></li>
<li><a href="#trunkSourceWebKitUIProcessAPICocoa_WKTextManipulationTokenmm">trunk/Source/WebKit/UIProcess/API/Cocoa/_WKTextManipulationToken.mm</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKitCocoaTextManipulationmm">trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (260864 => 260865)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2020-04-29 04:26:12 UTC (rev 260864)
+++ trunk/Source/WebCore/ChangeLog      2020-04-29 05:16:23 UTC (rev 260865)
</span><span class="lines">@@ -1,3 +1,31 @@
</span><ins>+2020-04-28  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [Text manipulation] Add a userInfo dictionary to _WKTextManipulationToken
+        https://bugs.webkit.org/show_bug.cgi?id=211151
+        <rdar://problem/62329534>
+
+        Reviewed by Darin Adler.
+
+        Add an extensible mechanism for the text manipulation controller to send additional
+        metadata for each text manipulation token through to the WebKit client, for debugging
+        purposes.
+
+        Test: TextManipulation.StartTextManipulationExtractsUserInfo
+
+        * editing/TextManipulationController.cpp:
+        (WebCore::tokenInfo):
+        (WebCore::TextManipulationController::observeParagraphs):
+        * editing/TextManipulationController.h:
+
+        Add TextManipulationTokenInfo, and add an optional TextManipulationTokenInfo member to
+        TextManipulationToken. For now, just send over the document URL, element tag name, and
+        the value of the role attribute.
+
+        (WebCore::TextManipulationController::ManipulationTokenInfo::encode const):
+        (WebCore::TextManipulationController::ManipulationTokenInfo::decode):
+        (WebCore::TextManipulationController::ManipulationToken::encode const):
+        (WebCore::TextManipulationController::ManipulationToken::decode):
+
</ins><span class="cx"> 2020-04-28  Simon Fraser  <simon.fraser@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Update the xcfilelists.
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingTextManipulationControllercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/TextManipulationController.cpp (260864 => 260865)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/TextManipulationController.cpp      2020-04-29 04:26:12 UTC (rev 260864)
+++ trunk/Source/WebCore/editing/TextManipulationController.cpp 2020-04-29 05:16:23 UTC (rev 260865)
</span><span class="lines">@@ -258,6 +258,21 @@
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static Optional<TextManipulationController::ManipulationTokenInfo> tokenInfo(Node* node)
+{
+    if (!node)
+        return WTF::nullopt;
+
+    TextManipulationController::ManipulationTokenInfo result;
+    result.documentURL = node->document().url();
+    if (auto element = is<Element>(node) ? makeRefPtr(downcast<Element>(*node)) : makeRefPtr(node->parentElement())) {
+        result.tagName = element->tagName();
+        if (element->hasAttributeWithoutSynchronization(HTMLNames::roleAttr))
+            result.roleAttribute = element->attributeWithoutSynchronization(HTMLNames::roleAttr);
+    }
+    return result;
+}
+
</ins><span class="cx"> void TextManipulationController::observeParagraphs(const Position& start, const Position& end)
</span><span class="cx"> {
</span><span class="cx">     if (start.isNull() || end.isNull())
</span><span class="lines">@@ -321,13 +336,13 @@
</span><span class="cx">                 auto& currentElement = downcast<Element>(*content.node);
</span><span class="cx">                 if (!content.isTextContent && canPerformTextManipulationByReplacingEntireTextContent(currentElement)) {
</span><span class="cx">                     addItem(ManipulationItemData { Position(), Position(), makeWeakPtr(currentElement), nullQName(),
</span><del>-                        { ManipulationToken { m_tokenIdentifier.generate(), currentElement.textContent() } } });
</del><ins>+                        { ManipulationToken { m_tokenIdentifier.generate(), currentElement.textContent(), tokenInfo(&currentElement) } } });
</ins><span class="cx">                 }
</span><span class="cx">                 if (currentElement.hasAttributes()) {
</span><span class="cx">                     for (auto& attribute : currentElement.attributesIterator()) {
</span><span class="cx">                         if (isAttributeForTextManipulation(attribute.name())) {
</span><span class="cx">                             addItem(ManipulationItemData { Position(), Position(), makeWeakPtr(currentElement), attribute.name(),
</span><del>-                                { ManipulationToken { m_tokenIdentifier.generate(), attribute.value() } } });
</del><ins>+                                { ManipulationToken { m_tokenIdentifier.generate(), attribute.value(), tokenInfo(&currentElement) } } });
</ins><span class="cx">                         }
</span><span class="cx">                     }
</span><span class="cx">                 }
</span><span class="lines">@@ -346,7 +361,7 @@
</span><span class="cx">                 continue;
</span><span class="cx"> 
</span><span class="cx">             endOfCurrentParagraph = currentEndOfCurrentParagraph;
</span><del>-            tokensInCurrentParagraph.append(ManipulationToken { m_tokenIdentifier.generate(), "[]", true });
</del><ins>+            tokensInCurrentParagraph.append(ManipulationToken { m_tokenIdentifier.generate(), "[]", tokenInfo(content.node.get()), true });
</ins><span class="cx"> 
</span><span class="cx">             continue;
</span><span class="cx">         }
</span><span class="lines">@@ -365,7 +380,7 @@
</span><span class="cx">                 if (tokensInCurrentParagraph.isEmpty())
</span><span class="cx">                     startOfCurrentParagraph = Position(&textNode, startOfCurrentLine);
</span><span class="cx"> 
</span><del>-                tokensInCurrentParagraph.append(ManipulationToken { m_tokenIdentifier.generate(), stringUntilEndOfLine, exclusionRuleMatcher.isExcluded(content.node.get()) });
</del><ins>+                tokensInCurrentParagraph.append(ManipulationToken { m_tokenIdentifier.generate(), stringUntilEndOfLine, tokenInfo(&textNode), exclusionRuleMatcher.isExcluded(content.node.get()) });
</ins><span class="cx">             }
</span><span class="cx"> 
</span><span class="cx">             if (!tokensInCurrentParagraph.isEmpty()) {
</span><span class="lines">@@ -385,7 +400,7 @@
</span><span class="cx">                     startOfCurrentParagraph = iterator.startPosition();
</span><span class="cx">             }
</span><span class="cx">             endOfCurrentParagraph = iterator.endPosition();
</span><del>-            tokensInCurrentParagraph.append(ManipulationToken { m_tokenIdentifier.generate(), remainingText.toString(), exclusionRuleMatcher.isExcluded(content.node.get()) });
</del><ins>+            tokensInCurrentParagraph.append(ManipulationToken { m_tokenIdentifier.generate(), remainingText.toString(), tokenInfo(content.node.get()), exclusionRuleMatcher.isExcluded(content.node.get()) });
</ins><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingTextManipulationControllerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/TextManipulationController.h (260864 => 260865)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/TextManipulationController.h        2020-04-29 04:26:12 UTC (rev 260864)
+++ trunk/Source/WebCore/editing/TextManipulationController.h   2020-04-29 05:16:23 UTC (rev 260865)
</span><span class="lines">@@ -48,9 +48,19 @@
</span><span class="cx">     enum TokenIdentifierType { };
</span><span class="cx">     using TokenIdentifier = ObjectIdentifier<TokenIdentifierType>;
</span><span class="cx"> 
</span><ins>+    struct ManipulationTokenInfo {
+        String tagName;
+        String roleAttribute;
+        URL documentURL;
+
+        template<class Encoder> void encode(Encoder&) const;
+        template<class Decoder> static Optional<ManipulationTokenInfo> decode(Decoder&);
+    };
+
</ins><span class="cx">     struct ManipulationToken {
</span><span class="cx">         TokenIdentifier identifier;
</span><span class="cx">         String content;
</span><ins>+        Optional<ManipulationTokenInfo> info;
</ins><span class="cx">         bool isExcluded { false };
</span><span class="cx"> 
</span><span class="cx">         template<class Encoder> void encode(Encoder&) const;
</span><span class="lines">@@ -158,9 +168,33 @@
</span><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> template<class Encoder>
</span><ins>+void TextManipulationController::ManipulationTokenInfo::encode(Encoder& encoder) const
+{
+    encoder << tagName;
+    encoder << roleAttribute;
+    encoder << documentURL;
+}
+
+template<class Decoder>
+Optional<TextManipulationController::ManipulationTokenInfo> TextManipulationController::ManipulationTokenInfo::decode(Decoder& decoder)
+{
+    ManipulationTokenInfo result;
+    if (!decoder.decode(result.tagName))
+        return WTF::nullopt;
+
+    if (!decoder.decode(result.roleAttribute))
+        return WTF::nullopt;
+
+    if (!decoder.decode(result.documentURL))
+        return WTF::nullopt;
+
+    return result;
+}
+
+template<class Encoder>
</ins><span class="cx"> void TextManipulationController::ManipulationToken::encode(Encoder& encoder) const
</span><span class="cx"> {
</span><del>-    encoder << identifier << content << isExcluded;
</del><ins>+    encoder << identifier << content << info << isExcluded;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> template<class Decoder>
</span><span class="lines">@@ -171,6 +205,8 @@
</span><span class="cx">         return WTF::nullopt;
</span><span class="cx">     if (!decoder.decode(result.content))
</span><span class="cx">         return WTF::nullopt;
</span><ins>+    if (!decoder.decode(result.info))
+        return WTF::nullopt;
</ins><span class="cx">     if (!decoder.decode(result.isExcluded))
</span><span class="cx">         return WTF::nullopt;
</span><span class="cx">     return result;
</span></span></pre></div>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (260864 => 260865)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog    2020-04-29 04:26:12 UTC (rev 260864)
+++ trunk/Source/WebKit/ChangeLog       2020-04-29 05:16:23 UTC (rev 260865)
</span><span class="lines">@@ -1,3 +1,27 @@
</span><ins>+2020-04-28  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [Text manipulation] Add a userInfo dictionary to _WKTextManipulationToken
+        https://bugs.webkit.org/show_bug.cgi?id=211151
+        <rdar://problem/62329534>
+
+        Reviewed by Darin Adler.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (createUserInfo):
+        (-[WKWebView _startTextManipulationsWithConfiguration:completion:]):
+        (-[WKWebView _completeTextManipulation:completion:]):
+        (-[WKWebView _completeTextManipulationForItems:completion:]):
+        * UIProcess/API/Cocoa/_WKTextManipulationToken.h:
+        * UIProcess/API/Cocoa/_WKTextManipulationToken.mm:
+        (-[_WKTextManipulationToken setUserInfo:]):
+        (-[_WKTextManipulationToken userInfo]):
+
+        Add a new `userInfo` dictionary to `_WKTextManipulationToken`, which contains several named
+        `NSString` keys.
+
+        (-[_WKTextManipulationToken isEqualToTextManipulationToken:includingContentEquality:]):
+        (-[_WKTextManipulationToken _descriptionPreservingPrivacy:]):
+
</ins><span class="cx"> 2020-04-28  David Kilzer  <ddkilzer@apple.com>
</span><span class="cx"> 
</span><span class="cx">         REGRESSION (r260407): Over-release of NSGraphicsContext in WebKit::convertPlatformImageToBitmap()
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessAPICocoaWKWebViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (260864 => 260865)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm     2020-04-29 04:26:12 UTC (rev 260864)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm        2020-04-29 05:16:23 UTC (rev 260865)
</span><span class="lines">@@ -1606,6 +1606,22 @@
</span><span class="cx">     _textManipulationDelegate = delegate;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static RetainPtr<NSDictionary<NSString *, id>> createUserInfo(const Optional<WebCore::TextManipulationController::ManipulationTokenInfo>& info)
+{
+    if (!info)
+        return { };
+
+    auto result = adoptNS([[NSMutableDictionary alloc] initWithCapacity:3]);
+    if (!info->documentURL.isNull())
+        [result setObject:(NSURL *)info->documentURL forKey:_WKTextManipulationTokenUserInfoDocumentURLKey];
+    if (!info->tagName.isNull())
+        [result setObject:(NSString *)info->tagName forKey:_WKTextManipulationTokenUserInfoTagNameKey];
+    if (!info->roleAttribute.isNull())
+        [result setObject:(NSString *)info->roleAttribute forKey:_WKTextManipulationTokenUserInfoRoleAttributeKey];
+
+    return result;
+}
+
</ins><span class="cx"> - (void)_startTextManipulationsWithConfiguration:(_WKTextManipulationConfiguration *)configuration completion:(void(^)())completionHandler
</span><span class="cx"> {
</span><span class="cx">     using ExclusionRule = WebCore::TextManipulationController::ExclusionRule;
</span><span class="lines">@@ -1643,6 +1659,7 @@
</span><span class="cx">                 [wkToken setIdentifier:String::number(token.identifier.toUInt64())];
</span><span class="cx">                 [wkToken setContent:token.content];
</span><span class="cx">                 [wkToken setExcluded:token.isExcluded];
</span><ins>+                [wkToken setUserInfo:createUserInfo(token.info).get()];
</ins><span class="cx">                 return wkToken;
</span><span class="cx">             });
</span><span class="cx">             return adoptNS([[_WKTextManipulationItem alloc] initWithIdentifier:String::number(item.identifier.toUInt64()) tokens:tokens.get()]);
</span><span class="lines">@@ -1680,7 +1697,7 @@
</span><span class="cx"> 
</span><span class="cx">     Vector<WebCore::TextManipulationController::ManipulationToken> tokens;
</span><span class="cx">     for (_WKTextManipulationToken *wkToken in item.tokens)
</span><del>-        tokens.append(WebCore::TextManipulationController::ManipulationToken { coreTextManipulationTokenIdentifierFromString(wkToken.identifier), wkToken.content });
</del><ins>+        tokens.append(WebCore::TextManipulationController::ManipulationToken { coreTextManipulationTokenIdentifierFromString(wkToken.identifier), wkToken.content, WTF::nullopt });
</ins><span class="cx"> 
</span><span class="cx">     Vector<WebCore::TextManipulationController::ManipulationItem> coreItems;
</span><span class="cx">     coreItems.reserveInitialCapacity(1);
</span><span class="lines">@@ -1739,7 +1756,7 @@
</span><span class="cx">         Vector<WebCore::TextManipulationController::ManipulationToken> coreTokens;
</span><span class="cx">         coreTokens.reserveInitialCapacity(wkItem.tokens.count);
</span><span class="cx">         for (_WKTextManipulationToken *wkToken in wkItem.tokens)
</span><del>-            coreTokens.uncheckedAppend(WebCore::TextManipulationController::ManipulationToken { coreTextManipulationTokenIdentifierFromString(wkToken.identifier), wkToken.content });
</del><ins>+            coreTokens.uncheckedAppend(WebCore::TextManipulationController::ManipulationToken { coreTextManipulationTokenIdentifierFromString(wkToken.identifier), wkToken.content, WTF::nullopt });
</ins><span class="cx">         coreItems.uncheckedAppend(WebCore::TextManipulationController::ManipulationItem { coreTextManipulationItemIdentifierFromString(wkItem.identifier), WTFMove(coreTokens) });
</span><span class="cx">     }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessAPICocoa_WKTextManipulationTokenh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKTextManipulationToken.h (260864 => 260865)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKTextManipulationToken.h       2020-04-29 04:26:12 UTC (rev 260864)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKTextManipulationToken.h  2020-04-29 05:16:23 UTC (rev 260865)
</span><span class="lines">@@ -28,6 +28,10 @@
</span><span class="cx"> 
</span><span class="cx"> NS_ASSUME_NONNULL_BEGIN
</span><span class="cx"> 
</span><ins>+WK_EXTERN NSString * const _WKTextManipulationTokenUserInfoDocumentURLKey WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+WK_EXTERN NSString * const _WKTextManipulationTokenUserInfoTagNameKey WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+WK_EXTERN NSString * const _WKTextManipulationTokenUserInfoRoleAttributeKey WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+
</ins><span class="cx"> WK_CLASS_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA))
</span><span class="cx"> @interface _WKTextManipulationToken : NSObject
</span><span class="cx"> 
</span><span class="lines">@@ -38,6 +42,8 @@
</span><span class="cx"> - (BOOL)isEqualToTextManipulationToken:(nullable _WKTextManipulationToken *)otherToken includingContentEquality:(BOOL)includingContentEquality;
</span><span class="cx"> @property (nonatomic, copy, readonly) NSString *debugDescription;
</span><span class="cx"> 
</span><ins>+@property (nonatomic, nullable, copy) NSDictionary<NSString *, id> *userInfo;
+
</ins><span class="cx"> @end
</span><span class="cx"> 
</span><span class="cx"> NS_ASSUME_NONNULL_END
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessAPICocoa_WKTextManipulationTokenmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKTextManipulationToken.mm (260864 => 260865)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKTextManipulationToken.mm      2020-04-29 04:26:12 UTC (rev 260864)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKTextManipulationToken.mm 2020-04-29 05:16:23 UTC (rev 260865)
</span><span class="lines">@@ -26,8 +26,16 @@
</span><span class="cx"> #import "config.h"
</span><span class="cx"> #import "_WKTextManipulationToken.h"
</span><span class="cx"> 
</span><del>-@implementation _WKTextManipulationToken
</del><ins>+#import <wtf/RetainPtr.h>
</ins><span class="cx"> 
</span><ins>+NSString * const _WKTextManipulationTokenUserInfoDocumentURLKey = @"_WKTextManipulationTokenUserInfoDocumentURLKey";
+NSString * const _WKTextManipulationTokenUserInfoTagNameKey = @"_WKTextManipulationTokenUserInfoTagNameKey";
+NSString * const _WKTextManipulationTokenUserInfoRoleAttributeKey = @"_WKTextManipulationTokenUserInfoRoleAttributeKey";
+
+@implementation _WKTextManipulationToken {
+    RetainPtr<NSDictionary<NSString *, id>> _userInfo;
+}
+
</ins><span class="cx"> - (void)dealloc
</span><span class="cx"> {
</span><span class="cx">     [_identifier release];
</span><span class="lines">@@ -38,6 +46,19 @@
</span><span class="cx">     [super dealloc];
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (void)setUserInfo:(NSDictionary<NSString *, id> *)userInfo
+{
+    if (userInfo == _userInfo || [_userInfo isEqual:userInfo])
+        return;
+
+    _userInfo = adoptNS(userInfo.copy);
+}
+
+- (NSDictionary<NSString *, id> *)userInfo
+{
+    return _userInfo.get();
+}
+
</ins><span class="cx"> static BOOL isEqualOrBothNil(id a, id b)
</span><span class="cx"> {
</span><span class="cx">     if (a == b)
</span><span class="lines">@@ -65,8 +86,9 @@
</span><span class="cx">     BOOL equalIdentifiers = isEqualOrBothNil(self.identifier, otherToken.identifier);
</span><span class="cx">     BOOL equalExclusion = self.isExcluded == otherToken.isExcluded;
</span><span class="cx">     BOOL equalContent = !includingContentEquality || isEqualOrBothNil(self.content, otherToken.content);
</span><ins>+    BOOL equalUserInfo = isEqualOrBothNil(self.userInfo, otherToken.userInfo);
</ins><span class="cx"> 
</span><del>-    return equalIdentifiers && equalExclusion && equalContent;
</del><ins>+    return equalIdentifiers && equalExclusion && equalContent && equalUserInfo;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (NSString *)description
</span><span class="lines">@@ -85,7 +107,7 @@
</span><span class="cx">     if (preservePrivacy)
</span><span class="cx">         [description appendFormat:@"; content length = %lu", (unsigned long)self.content.length];
</span><span class="cx">     else
</span><del>-        [description appendFormat:@"; content = %@", self.content];
</del><ins>+        [description appendFormat:@"; content = %@; user info = %@", self.content, self.userInfo];
</ins><span class="cx"> 
</span><span class="cx">     [description appendString:@">"];
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (260864 => 260865)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog    2020-04-29 04:26:12 UTC (rev 260864)
+++ trunk/Tools/ChangeLog       2020-04-29 05:16:23 UTC (rev 260865)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2020-04-28  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [Text manipulation] Add a userInfo dictionary to _WKTextManipulationToken
+        https://bugs.webkit.org/show_bug.cgi?id=211151
+        <rdar://problem/62329534>
+
+        Reviewed by Darin Adler.
+
+        Add a new API test to check the userInfo dictionary on text manipulation tokens.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm:
+
</ins><span class="cx"> 2020-04-28  David Kilzer  <ddkilzer@apple.com>
</span><span class="cx"> 
</span><span class="cx">         check-webkit-style should suggest CheckedSize for Checked<size_t, RecordOverflow>
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKitCocoaTextManipulationmm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm (260864 => 260865)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm  2020-04-29 04:26:12 UTC (rev 260864)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm     2020-04-29 05:16:23 UTC (rev 260865)
</span><span class="lines">@@ -704,6 +704,59 @@
</span><span class="cx">     EXPECT_WK_STREQ("Garply", items[3].tokens[0].content);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+TEST(TextManipulation, StartTextManipulationExtractsUserInfo)
+{
+    auto delegate = adoptNS([[TextManipulationDelegate alloc] init]);
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)]);
+    [webView _setTextManipulationDelegate:delegate.get()];
+
+    [webView synchronouslyLoadHTMLString:@"<!DOCTYPE html>"
+        "<body>"
+        "    <title>This is a test</title>"
+        "    <p>First</p>"
+        "    <div role='button'>Second</div>"
+        "    <span>Third</span>"
+        "</body>"];
+
+    done = false;
+    [webView _startTextManipulationsWithConfiguration:nil completion:^{
+        done = true;
+    }];
+    TestWebKitAPI::Util::run(&done);
+
+    auto items = [delegate items];
+    EXPECT_EQ(items.count, 4UL);
+    EXPECT_EQ(items[0].tokens.count, 1UL);
+    EXPECT_EQ(items[1].tokens.count, 1UL);
+    EXPECT_EQ(items[2].tokens.count, 1UL);
+    EXPECT_EQ(items[3].tokens.count, 1UL);
+    EXPECT_WK_STREQ("This is a test", items[0].tokens[0].content);
+    EXPECT_WK_STREQ("First", items[1].tokens[0].content);
+    EXPECT_WK_STREQ("Second", items[2].tokens[0].content);
+    EXPECT_WK_STREQ("Third", items[3].tokens[0].content);
+    {
+        auto userInfo = items[0].tokens[0].userInfo;
+        EXPECT_WK_STREQ("TestWebKitAPI.resources", [(NSURL *)userInfo[_WKTextManipulationTokenUserInfoDocumentURLKey] lastPathComponent]);
+        EXPECT_WK_STREQ("TITLE", (NSString *)userInfo[_WKTextManipulationTokenUserInfoTagNameKey]);
+    }
+    {
+        auto userInfo = items[1].tokens[0].userInfo;
+        EXPECT_WK_STREQ("TestWebKitAPI.resources", [(NSURL *)userInfo[_WKTextManipulationTokenUserInfoDocumentURLKey] lastPathComponent]);
+        EXPECT_WK_STREQ("P", (NSString *)userInfo[_WKTextManipulationTokenUserInfoTagNameKey]);
+    }
+    {
+        auto userInfo = items[2].tokens[0].userInfo;
+        EXPECT_WK_STREQ("TestWebKitAPI.resources", [(NSURL *)userInfo[_WKTextManipulationTokenUserInfoDocumentURLKey] lastPathComponent]);
+        EXPECT_WK_STREQ("DIV", (NSString *)userInfo[_WKTextManipulationTokenUserInfoTagNameKey]);
+        EXPECT_WK_STREQ("button", (NSString *)userInfo[_WKTextManipulationTokenUserInfoRoleAttributeKey]);
+    }
+    {
+        auto userInfo = items[3].tokens[0].userInfo;
+        EXPECT_WK_STREQ("TestWebKitAPI.resources", [(NSURL *)userInfo[_WKTextManipulationTokenUserInfoDocumentURLKey] lastPathComponent]);
+        EXPECT_WK_STREQ("SPAN", (NSString *)userInfo[_WKTextManipulationTokenUserInfoTagNameKey]);
+    }
+}
+
</ins><span class="cx"> struct Token {
</span><span class="cx">     NSString *identifier;
</span><span class="cx">     NSString *content;
</span></span></pre>
</div>
</div>

</body>
</html>