<!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>[213176] 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/213176">213176</a></dd>
<dt>Author</dt> <dd>wenson_hsieh@apple.com</dd>
<dt>Date</dt> <dd>2017-02-28 14:11:07 -0800 (Tue, 28 Feb 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>Data interaction should support attachment elements
https://bugs.webkit.org/show_bug.cgi?id=168916
&lt;rdar://problem/30664519&gt;

Reviewed by Ryosuke Niwa.

Source/WebCore:

Teaches DragController to recognize and initiate dragging on attachment elements, and also adds a new
convenience method to the WebItemProviderPasteboard for block enumeration of available UIItemProviders. Covered
by a new API test: DataInteractionTests.AttachmentElementItemProviders.

* page/DragController.cpp:
(WebCore::DragController::draggableElement):
(WebCore::DragController::startDrag):
* platform/ios/WebItemProviderPasteboard.h:
* platform/ios/WebItemProviderPasteboard.mm:
(-[WebItemProviderPasteboard enumerateItemProvidersWithBlock:]):

Source/WebKit2:

Teaches WKContentView to recognize attachment elements as data interactive content, and add an internal hook to
adjust the list of item providers before initiating data interaction.

* Platform/spi/ios/UIKitSPI.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _adjustedDataInteractionItemProviders:]):
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView pointIsInDataInteractionContent:]):

Tools:

Adds a new unit test verifying that a client injected bundle is able to augment UIItemProvider data vended to
the UI process.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2Cocoa/attachment-element.html: Added.
* TestWebKitAPI/Tests/ios/DataInteractionTests.mm:
(-[CustomItemProviderWebView _adjustedDataInteractionItemProviders:]):
(TestWebKitAPI::TEST):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorepageDragControllercpp">trunk/Source/WebCore/page/DragController.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformiosWebItemProviderPasteboardh">trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.h</a></li>
<li><a href="#trunkSourceWebCoreplatformiosWebItemProviderPasteboardmm">trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.mm</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2PlatformspiiosUIKitSPIh">trunk/Source/WebKit2/Platform/spi/ios/UIKitSPI.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoaWKWebViewmm">trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoaWKWebViewPrivateh">trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWKContentViewInteractionmm">trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj">trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsiosDataInteractionTestsmm">trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkToolsTestWebKitAPITestsWebKit2Cocoaattachmentelementhtml">trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/attachment-element.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (213175 => 213176)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2017-02-28 21:56:44 UTC (rev 213175)
+++ trunk/Source/WebCore/ChangeLog        2017-02-28 22:11:07 UTC (rev 213176)
</span><span class="lines">@@ -1,3 +1,22 @@
</span><ins>+2017-02-28  Wenson Hsieh  &lt;wenson_hsieh@apple.com&gt;
+
+        Data interaction should support attachment elements
+        https://bugs.webkit.org/show_bug.cgi?id=168916
+        &lt;rdar://problem/30664519&gt;
+
+        Reviewed by Ryosuke Niwa.
+
+        Teaches DragController to recognize and initiate dragging on attachment elements, and also adds a new
+        convenience method to the WebItemProviderPasteboard for block enumeration of available UIItemProviders. Covered
+        by a new API test: DataInteractionTests.AttachmentElementItemProviders.
+
+        * page/DragController.cpp:
+        (WebCore::DragController::draggableElement):
+        (WebCore::DragController::startDrag):
+        * platform/ios/WebItemProviderPasteboard.h:
+        * platform/ios/WebItemProviderPasteboard.mm:
+        (-[WebItemProviderPasteboard enumerateItemProvidersWithBlock:]):
+
</ins><span class="cx"> 2017-02-28  Mark Lam  &lt;mark.lam@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Remove setExclusiveThread() and peers from the JSLock.
</span></span></pre></div>
<a id="trunkSourceWebCorepageDragControllercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/DragController.cpp (213175 => 213176)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/DragController.cpp        2017-02-28 21:56:44 UTC (rev 213175)
+++ trunk/Source/WebCore/page/DragController.cpp        2017-02-28 22:11:07 UTC (rev 213176)
</span><span class="lines">@@ -64,6 +64,7 @@
</span><span class="cx"> #include &quot;PlatformKeyboardEvent.h&quot;
</span><span class="cx"> #include &quot;PluginDocument.h&quot;
</span><span class="cx"> #include &quot;PluginViewBase.h&quot;
</span><ins>+#include &quot;Position.h&quot;
</ins><span class="cx"> #include &quot;RenderFileUploadControl.h&quot;
</span><span class="cx"> #include &quot;RenderImage.h&quot;
</span><span class="cx"> #include &quot;RenderView.h&quot;
</span><span class="lines">@@ -75,6 +76,7 @@
</span><span class="cx"> #include &quot;StyleProperties.h&quot;
</span><span class="cx"> #include &quot;Text.h&quot;
</span><span class="cx"> #include &quot;TextEvent.h&quot;
</span><ins>+#include &quot;VisiblePosition.h&quot;
</ins><span class="cx"> #include &quot;htmlediting.h&quot;
</span><span class="cx"> #include &quot;markup.h&quot;
</span><span class="cx"> 
</span><span class="lines">@@ -654,12 +656,20 @@
</span><span class="cx">     if (!startElement)
</span><span class="cx">         return nullptr;
</span><span class="cx"> #if ENABLE(ATTACHMENT_ELEMENT)
</span><del>-    // Unlike image elements, attachment elements are immediately selected upon mouse down,
-    // but for those elements we still want to use the single element drag behavior as long as
-    // the element is the only content of the selection.
-    const VisibleSelection&amp; selection = sourceFrame-&gt;selection().selection();
-    if (selection.isRange() &amp;&amp; is&lt;HTMLAttachmentElement&gt;(selection.start().anchorNode()) &amp;&amp; selection.start().anchorNode() == selection.end().anchorNode())
-        state.type = DragSourceActionNone;
</del><ins>+    if (is&lt;HTMLAttachmentElement&gt;(startElement)) {
+        auto selection = sourceFrame-&gt;selection().selection();
+        bool isSingleAttachmentSelection = selection.start() == Position(startElement, Position::PositionIsBeforeAnchor) &amp;&amp; selection.end() == Position(startElement, Position::PositionIsAfterAnchor);
+        bool isAttachmentElementInCurrentSelection = false;
+        if (auto selectedRange = selection.toNormalizedRange()) {
+            auto compareResult = selectedRange-&gt;compareNode(*startElement);
+            isAttachmentElementInCurrentSelection = !compareResult.hasException() &amp;&amp; compareResult.releaseReturnValue() == Range::NODE_INSIDE;
+        }
+
+        if (!isAttachmentElementInCurrentSelection || isSingleAttachmentSelection) {
+            state.type = DragSourceActionAttachment;
+            return startElement;
+        }
+    }
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     for (auto* renderer = startElement-&gt;renderer(); renderer; renderer = renderer-&gt;parent()) {
</span><span class="lines">@@ -997,11 +1007,22 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(ATTACHMENT_ELEMENT)
</span><del>-    if (!attachmentURL.isEmpty() &amp;&amp; (m_dragSourceAction &amp; DragSourceActionAttachment)) {
</del><ins>+    if (m_dragSourceAction &amp; DragSourceActionAttachment) {
</ins><span class="cx">         if (!dataTransfer.pasteboard().hasData()) {
</span><del>-            m_draggingAttachmentURL = attachmentURL;
</del><span class="cx">             selectElement(element);
</span><del>-            declareAndWriteAttachment(dataTransfer, element, attachmentURL);
</del><ins>+            if (!attachmentURL.isEmpty()) {
+                // Use the attachment URL specified by the file attribute to populate the pasteboard.
+                m_draggingAttachmentURL = attachmentURL;
+                declareAndWriteAttachment(dataTransfer, element, attachmentURL);
+            } else if (src.editor().client()) {
+#if PLATFORM(COCOA)
+                // Otherwise, if no file URL is specified, call out to the injected bundle to populate the pasteboard with data.
+                auto&amp; editor = src.editor();
+                editor.willWriteSelectionToPasteboard(src.selection().toNormalizedRange());
+                editor.writeSelectionToPasteboard(dataTransfer.pasteboard());
+                editor.didWriteSelectionToPasteboard();
+#endif
+            }
</ins><span class="cx">         }
</span><span class="cx">         
</span><span class="cx">         m_client.willPerformDragSourceAction(DragSourceActionAttachment, dragOrigin, dataTransfer);
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformiosWebItemProviderPasteboardh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.h (213175 => 213176)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.h        2017-02-28 21:56:44 UTC (rev 213175)
+++ trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.h        2017-02-28 22:11:07 UTC (rev 213176)
</span><span class="lines">@@ -45,6 +45,8 @@
</span><span class="cx"> - (void)incrementPendingOperationCount;
</span><span class="cx"> - (void)decrementPendingOperationCount;
</span><span class="cx"> 
</span><ins>+- (void)enumerateItemProvidersWithBlock:(void (^)(UIItemProvider *itemProvider, NSUInteger index, BOOL *stop))block;
+
</ins><span class="cx"> @end
</span><span class="cx"> 
</span><span class="cx"> NS_ASSUME_NONNULL_END
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformiosWebItemProviderPasteboardmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.mm (213175 => 213176)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.mm        2017-02-28 21:56:44 UTC (rev 213175)
+++ trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.mm        2017-02-28 22:11:07 UTC (rev 213176)
</span><span class="lines">@@ -248,6 +248,11 @@
</span><span class="cx">     _pendingOperationCount--;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (void)enumerateItemProvidersWithBlock:(void (^)(UIItemProvider *itemProvider, NSUInteger index, BOOL *stop))block
+{
+    [_itemProviders enumerateObjectsUsingBlock:block];
+}
+
</ins><span class="cx"> @end
</span><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(DATA_INTERACTION)
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (213175 => 213176)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2017-02-28 21:56:44 UTC (rev 213175)
+++ trunk/Source/WebKit2/ChangeLog        2017-02-28 22:11:07 UTC (rev 213176)
</span><span class="lines">@@ -1,3 +1,21 @@
</span><ins>+2017-02-28  Wenson Hsieh  &lt;wenson_hsieh@apple.com&gt;
+
+        Data interaction should support attachment elements
+        https://bugs.webkit.org/show_bug.cgi?id=168916
+        &lt;rdar://problem/30664519&gt;
+
+        Reviewed by Ryosuke Niwa.
+
+        Teaches WKContentView to recognize attachment elements as data interactive content, and add an internal hook to
+        adjust the list of item providers before initiating data interaction.
+
+        * Platform/spi/ios/UIKitSPI.h:
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _adjustedDataInteractionItemProviders:]):
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView pointIsInDataInteractionContent:]):
+
</ins><span class="cx"> 2017-02-28  Yongjun Zhang  &lt;yongjun_zhang@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Add delegate method to handle images with alternate data.
</span></span></pre></div>
<a id="trunkSourceWebKit2PlatformspiiosUIKitSPIh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Platform/spi/ios/UIKitSPI.h (213175 => 213176)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Platform/spi/ios/UIKitSPI.h        2017-02-28 21:56:44 UTC (rev 213175)
+++ trunk/Source/WebKit2/Platform/spi/ios/UIKitSPI.h        2017-02-28 22:11:07 UTC (rev 213176)
</span><span class="lines">@@ -40,6 +40,7 @@
</span><span class="cx"> #import &lt;UIKit/UIImagePickerController_Private.h&gt;
</span><span class="cx"> #import &lt;UIKit/UIImage_Private.h&gt;
</span><span class="cx"> #import &lt;UIKit/UIInterface_Private.h&gt;
</span><ins>+#import &lt;UIKit/UIItemProvider_Private.h&gt;
</ins><span class="cx"> #import &lt;UIKit/UIKeyboardImpl.h&gt;
</span><span class="cx"> #import &lt;UIKit/UIKeyboardIntl.h&gt;
</span><span class="cx"> #import &lt;UIKit/UIKeyboard_Private.h&gt;
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoaWKWebViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (213175 => 213176)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm        2017-02-28 21:56:44 UTC (rev 213175)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm        2017-02-28 22:11:07 UTC (rev 213176)
</span><span class="lines">@@ -3726,6 +3726,11 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (NSArray *)_adjustedDataInteractionItemProviders:(NSArray *)originalItemProviders
+{
+    return originalItemProviders;
+}
+
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> - (void)_didRelaunchProcess
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoaWKWebViewPrivateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h (213175 => 213176)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h        2017-02-28 21:56:44 UTC (rev 213175)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h        2017-02-28 22:11:07 UTC (rev 213176)
</span><span class="lines">@@ -188,6 +188,8 @@
</span><span class="cx"> - (void)_accessibilityRetrieveSpeakSelectionContent;
</span><span class="cx"> - (void)_accessibilityDidGetSpeakSelectionContent:(NSString *)content;
</span><span class="cx"> 
</span><ins>+- (NSArray *)_adjustedDataInteractionItemProviders:(NSArray *)originalItemProviders WK_API_AVAILABLE(ios(WK_IOS_TBA));
+
</ins><span class="cx"> #else
</span><span class="cx"> @property (readonly) NSColor *_pageExtendedBackgroundColor;
</span><span class="cx"> @property (nonatomic, setter=_setDrawsBackground:) BOOL _drawsBackground;
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWKContentViewInteractionmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm (213175 => 213176)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm        2017-02-28 21:56:44 UTC (rev 213175)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm        2017-02-28 22:11:07 UTC (rev 213176)
</span><span class="lines">@@ -1437,7 +1437,7 @@
</span><span class="cx">     InteractionInformationRequest request(roundedIntPoint(point));
</span><span class="cx">     [self ensurePositionInformationIsUpToDate:request];
</span><span class="cx"> 
</span><del>-    if (_positionInformation.isImage || _positionInformation.isLink)
</del><ins>+    if (_positionInformation.isImage || _positionInformation.isLink || _positionInformation.isAttachment)
</ins><span class="cx">         return YES;
</span><span class="cx"> 
</span><span class="cx">     return _positionInformation.hasSelectionAtPosition;
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (213175 => 213176)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2017-02-28 21:56:44 UTC (rev 213175)
+++ trunk/Tools/ChangeLog        2017-02-28 22:11:07 UTC (rev 213176)
</span><span class="lines">@@ -1,3 +1,20 @@
</span><ins>+2017-02-28  Wenson Hsieh  &lt;wenson_hsieh@apple.com&gt;
+
+        Data interaction should support attachment elements
+        https://bugs.webkit.org/show_bug.cgi?id=168916
+        &lt;rdar://problem/30664519&gt;
+
+        Reviewed by Ryosuke Niwa.
+
+        Adds a new unit test verifying that a client injected bundle is able to augment UIItemProvider data vended to
+        the UI process.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit2Cocoa/attachment-element.html: Added.
+        * TestWebKitAPI/Tests/ios/DataInteractionTests.mm:
+        (-[CustomItemProviderWebView _adjustedDataInteractionItemProviders:]):
+        (TestWebKitAPI::TEST):
+
</ins><span class="cx"> 2017-02-28  Chris Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [iOS] Throttle requestAnimationFrame to 30fps in low power mode
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (213175 => 213176)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2017-02-28 21:56:44 UTC (rev 213175)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2017-02-28 22:11:07 UTC (rev 213176)
</span><span class="lines">@@ -561,6 +561,7 @@
</span><span class="cx">                 F415086D1DA040C50044BE9B /* play-audio-on-click.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F415086C1DA040C10044BE9B /* play-audio-on-click.html */; };
</span><span class="cx">                 F42DA5161D8CEFE400336F40 /* large-input-field-focus-onload.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F42DA5151D8CEFDB00336F40 /* large-input-field-focus-onload.html */; };
</span><span class="cx">                 F47728991E4AE3C1007ABF6A /* full-page-contenteditable.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F47728981E4AE3AD007ABF6A /* full-page-contenteditable.html */; };
</span><ins>+                F4856CA31E649EA8009D7EE7 /* attachment-element.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4856CA21E6498A8009D7EE7 /* attachment-element.html */; };
</ins><span class="cx">                 F4BFA68E1E4AD08000154298 /* DragAndDropPasteboardTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4BFA68C1E4AD08000154298 /* DragAndDropPasteboardTests.mm */; };
</span><span class="cx">                 F4C2AB221DD6D95E00E06D5B /* enormous-video-with-sound.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4C2AB211DD6D94100E06D5B /* enormous-video-with-sound.html */; };
</span><span class="cx">                 F4D4F3B61E4E2BCB00BB2767 /* DataInteractionSimulator.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4D4F3B41E4E2BCB00BB2767 /* DataInteractionSimulator.mm */; };
</span><span class="lines">@@ -639,6 +640,7 @@
</span><span class="cx">                         dstPath = TestWebKitAPI.resources;
</span><span class="cx">                         dstSubfolderSpec = 7;
</span><span class="cx">                         files = (
</span><ins>+                                F4856CA31E649EA8009D7EE7 /* attachment-element.html in Copy Resources */,
</ins><span class="cx">                                 8361F1781E610B4E00759B25 /* link-with-download-attribute-with-slashes.html in Copy Resources */,
</span><span class="cx">                                 F4FA91831E61857B007B8C1D /* double-click-does-not-select-trailing-space.html in Copy Resources */,
</span><span class="cx">                                 C25CCA0D1E5141840026CB8A /* AllAhem.svg in Copy Resources */,
</span><span class="lines">@@ -1395,6 +1397,7 @@
</span><span class="cx">                 F415086C1DA040C10044BE9B /* play-audio-on-click.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = &quot;play-audio-on-click.html&quot;; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 F42DA5151D8CEFDB00336F40 /* large-input-field-focus-onload.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = &quot;large-input-field-focus-onload.html&quot;; path = &quot;Tests/WebKit2Cocoa/large-input-field-focus-onload.html&quot;; sourceTree = SOURCE_ROOT; };
</span><span class="cx">                 F47728981E4AE3AD007ABF6A /* full-page-contenteditable.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = &quot;full-page-contenteditable.html&quot;; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                F4856CA21E6498A8009D7EE7 /* attachment-element.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = &quot;attachment-element.html&quot;; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 F4BFA68C1E4AD08000154298 /* DragAndDropPasteboardTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DragAndDropPasteboardTests.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 F4C2AB211DD6D94100E06D5B /* enormous-video-with-sound.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = &quot;enormous-video-with-sound.html&quot;; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 F4D4F3B41E4E2BCB00BB2767 /* DataInteractionSimulator.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DataInteractionSimulator.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -1806,6 +1809,7 @@
</span><span class="cx">                                 51714EB31CF8C761004723C4 /* WebProcessKillIDBCleanup-2.html */,
</span><span class="cx">                                 C25CCA0A1E513F490026CB8A /* LineBreaking.html */,
</span><span class="cx">                                 C25CCA0C1E5140E50026CB8A /* AllAhem.svg */,
</span><ins>+                                F4856CA21E6498A8009D7EE7 /* attachment-element.html */,
</ins><span class="cx">                         );
</span><span class="cx">                         name = Resources;
</span><span class="cx">                         sourceTree = &quot;&lt;group&gt;&quot;;
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKit2Cocoaattachmentelementhtml"></a>
<div class="addfile"><h4>Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/attachment-element.html (0 => 213176)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/attachment-element.html                                (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/attachment-element.html        2017-02-28 22:11:07 UTC (rev 213176)
</span><span class="lines">@@ -0,0 +1,14 @@
</span><ins>+&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width&quot;&gt;
+&lt;style&gt;
+body, html {
+    padding: 0;
+    margin: 0;
+}
+
+attachment {
+    position: absolute;
+    top: 0;
+    left: 0;
+}
+&lt;/style&gt;
+&lt;attachment title=&quot;index.html&quot; type=&quot;public.html&quot; subtitle=&quot;0.1 KB&quot;&gt;&lt;/attachment&gt;
</ins></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsiosDataInteractionTestsmm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm (213175 => 213176)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm        2017-02-28 21:56:44 UTC (rev 213175)
+++ trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm        2017-02-28 22:11:07 UTC (rev 213176)
</span><span class="lines">@@ -30,8 +30,11 @@
</span><span class="cx"> #import &quot;DataInteractionSimulator.h&quot;
</span><span class="cx"> #import &quot;PlatformUtilities.h&quot;
</span><span class="cx"> #import &quot;TestWKWebView.h&quot;
</span><ins>+#import &quot;WKWebViewConfigurationExtras.h&quot;
</ins><span class="cx"> #import &lt;MobileCoreServices/MobileCoreServices.h&gt;
</span><span class="cx"> #import &lt;UIKit/UIItemProvider_Private.h&gt;
</span><ins>+#import &lt;WebKit/WKWebViewConfigurationPrivate.h&gt;
+#import &lt;WebKit/WKWebViewPrivate.h&gt;
</ins><span class="cx"> 
</span><span class="cx"> @implementation TestWKWebView (DataInteractionTests)
</span><span class="cx"> 
</span><span class="lines">@@ -47,6 +50,22 @@
</span><span class="cx"> 
</span><span class="cx"> @end
</span><span class="cx"> 
</span><ins>+@interface CustomItemProviderWebView : TestWKWebView
+@property (nonatomic) BlockPtr&lt;NSArray *(NSArray *)&gt; convertItemProvidersBlock;
+@end
+
+@implementation CustomItemProviderWebView
+
+- (NSArray *)_adjustedDataInteractionItemProviders:(NSArray *)originalItemProviders
+{
+    if (!self.convertItemProvidersBlock)
+        return [super _adjustedDataInteractionItemProviders:originalItemProviders];
+
+    return self.convertItemProvidersBlock(originalItemProviders);
+}
+
+@end
+
</ins><span class="cx"> static NSValue *makeCGRectValue(CGFloat x, CGFloat y, CGFloat width, CGFloat height)
</span><span class="cx"> {
</span><span class="cx">     return [NSValue valueWithCGRect:CGRectMake(x, y, width, height)];
</span><span class="lines">@@ -249,6 +268,33 @@
</span><span class="cx">     EXPECT_TRUE([[dataInteractionSimulator finalSelectionRects] isEqualToArray:@[ makeCGRectValue(1, 201, 215, 174) ]]);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+TEST(DataInteractionTests, AttachmentElementItemProviders)
+{
+    RetainPtr&lt;WKWebViewConfiguration&gt; configuration = [WKWebViewConfiguration testwebkitapi_configurationWithTestPlugInClassName:@&quot;BundleEditingDelegatePlugIn&quot;];
+    [configuration _setAttachmentElementEnabled:YES];
+    auto webView = adoptNS([[CustomItemProviderWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500) configuration:configuration.get()]);
+    [webView synchronouslyLoadTestPageNamed:@&quot;attachment-element&quot;];
+
+    NSString *injectedTypeIdentifier = @&quot;org.webkit.data&quot;;
+    __block RetainPtr&lt;NSString&gt; injectedString;
+    [webView setConvertItemProvidersBlock:^NSArray *(NSArray *originalItemProviders)
+    {
+        for (UIItemProvider *provider in originalItemProviders) {
+            NSData *injectedData = [provider copyDataRepresentationForTypeIdentifier:injectedTypeIdentifier error:nil];
+            if (!injectedData.length)
+                continue;
+            injectedString = adoptNS([[NSString alloc] initWithData:injectedData encoding:NSUTF8StringEncoding]);
+            break;
+        }
+        return originalItemProviders;
+    }];
+
+    auto dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
+    [dataInteractionSimulator runFrom:CGPointMake(50, 50) to:CGPointMake(50, 400)];
+
+    EXPECT_WK_STREQ(&quot;hello&quot;, [injectedString UTF8String]);
+}
+
</ins><span class="cx"> } // namespace TestWebKitAPI
</span><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(DATA_INTERACTION)
</span></span></pre>
</div>
</div>

</body>
</html>