<!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>[238661] 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/238661">238661</a></dd>
<dt>Author</dt> <dd>wenson_hsieh@apple.com</dd>
<dt>Date</dt> <dd>2018-11-28 21:25:07 -0800 (Wed, 28 Nov 2018)</dd>
</dl>

<h3>Log Message</h3>
<pre>[iOSMac] Dropping text selections from web content into editable elements crashes the web process
https://bugs.webkit.org/show_bug.cgi?id=192113
<rdar://problem/46323701>

Reviewed by Ryosuke Niwa.

Source/WebCore:

In iOSMac, registering invalid UTIs on NSItemProvider when starting a drag or handling a drop does not work.
Since iOS writes and reads only "Apple Web Archive pasteboard type" (a.k.a. `WebArchivePboardType`) during drag
and drop as well as copy and paste, we fail to read or write any web archive data, and subsequently fall back to
reading RTF or flat RTFD, both of which are not supported in iOSMac, since UIFoundation links against the
system's macOS WebKit stack.

To fix this, we add support for reading and writing com.apple.webarchive (`kUTTypeWebArchive`) on iOS, so that
WebKit-based iOSMac applications can understand web archive data from the host running macOS, and the host can
also understand web archive data written by the iOSMac app. Additionally, don't allow reading RTF and flat RTFD
as web content in iOSMac. (Note that writing RTF and flat RTFD is still safe, since it does not depend on
UIFoundation.framework but rather `WebCore::HTMLConverter`).

Test: DragAndDropTests.ModernWebArchiveType

* editing/cocoa/WebContentReaderCocoa.mm:
(WebCore::createFragment):

Additionally make sure that we never call into UIFoundation's NSAttributedString to markup conversion codepath
by making `createFragment` an empty stub on iOSMac.

* platform/ios/PasteboardIOS.mm:
(WebCore::supportedImageTypes):
(WebCore::isTypeAllowedByReadingPolicy):
(WebCore::Pasteboard::readPasteboardWebContentDataForType):
(WebCore::Pasteboard::supportedWebContentPasteboardTypes):
* platform/ios/PlatformPasteboardIOS.mm:
(WebCore::PlatformPasteboard::write):

Tools:

Add a test to verify that, when dropping an item with both "com.apple.webarchive" and "public.utf8-plain-text"
representations, the higher fidelity web archive data is used when handling the drop.

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

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreeditingcocoaWebContentReaderCocoamm">trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformiosPasteboardIOSmm">trunk/Source/WebCore/platform/ios/PasteboardIOS.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformiosPlatformPasteboardIOSmm">trunk/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKitCocoaDragAndDropTestsmm">trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DragAndDropTests.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (238660 => 238661)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2018-11-29 04:39:45 UTC (rev 238660)
+++ trunk/Source/WebCore/ChangeLog      2018-11-29 05:25:07 UTC (rev 238661)
</span><span class="lines">@@ -1,3 +1,39 @@
</span><ins>+2018-11-28  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [iOSMac] Dropping text selections from web content into editable elements crashes the web process
+        https://bugs.webkit.org/show_bug.cgi?id=192113
+        <rdar://problem/46323701>
+
+        Reviewed by Ryosuke Niwa.
+
+        In iOSMac, registering invalid UTIs on NSItemProvider when starting a drag or handling a drop does not work.
+        Since iOS writes and reads only "Apple Web Archive pasteboard type" (a.k.a. `WebArchivePboardType`) during drag
+        and drop as well as copy and paste, we fail to read or write any web archive data, and subsequently fall back to
+        reading RTF or flat RTFD, both of which are not supported in iOSMac, since UIFoundation links against the
+        system's macOS WebKit stack.
+
+        To fix this, we add support for reading and writing com.apple.webarchive (`kUTTypeWebArchive`) on iOS, so that
+        WebKit-based iOSMac applications can understand web archive data from the host running macOS, and the host can
+        also understand web archive data written by the iOSMac app. Additionally, don't allow reading RTF and flat RTFD
+        as web content in iOSMac. (Note that writing RTF and flat RTFD is still safe, since it does not depend on
+        UIFoundation.framework but rather `WebCore::HTMLConverter`).
+
+        Test: DragAndDropTests.ModernWebArchiveType
+
+        * editing/cocoa/WebContentReaderCocoa.mm:
+        (WebCore::createFragment):
+
+        Additionally make sure that we never call into UIFoundation's NSAttributedString to markup conversion codepath
+        by making `createFragment` an empty stub on iOSMac.
+
+        * platform/ios/PasteboardIOS.mm:
+        (WebCore::supportedImageTypes):
+        (WebCore::isTypeAllowedByReadingPolicy):
+        (WebCore::Pasteboard::readPasteboardWebContentDataForType):
+        (WebCore::Pasteboard::supportedWebContentPasteboardTypes):
+        * platform/ios/PlatformPasteboardIOS.mm:
+        (WebCore::PlatformPasteboard::write):
+
</ins><span class="cx"> 2018-11-28  Commit Queue  <commit-queue@webkit.org>
</span><span class="cx"> 
</span><span class="cx">         Unreviewed, rolling out r238653 and r238656.
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingcocoaWebContentReaderCocoamm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm (238660 => 238661)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm      2018-11-29 04:39:45 UTC (rev 238660)
+++ trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm 2018-11-29 05:25:07 UTC (rev 238661)
</span><span class="lines">@@ -85,8 +85,15 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><del>-#if (PLATFORM(IOS_FAMILY) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300)
</del><ins>+#if PLATFORM(IOSMAC)
</ins><span class="cx"> 
</span><ins>+static FragmentAndResources createFragment(Frame&, NSAttributedString *)
+{
+    return { };
+}
+
+#elif (PLATFORM(IOS_FAMILY) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300)
+
</ins><span class="cx"> static NSDictionary *attributesForAttributedStringConversion()
</span><span class="cx"> {
</span><span class="cx">     // This function needs to be kept in sync with identically named one in WebKitLegacy, which is used on older OS versions.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformiosPasteboardIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/ios/PasteboardIOS.mm (238660 => 238661)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/ios/PasteboardIOS.mm       2018-11-29 04:39:45 UTC (rev 238660)
+++ trunk/Source/WebCore/platform/ios/PasteboardIOS.mm  2018-11-29 05:25:07 UTC (rev 238661)
</span><span class="lines">@@ -168,7 +168,7 @@
</span><span class="cx"> 
</span><span class="cx"> static NSArray* supportedImageTypes()
</span><span class="cx"> {
</span><del>-    return @[(id)kUTTypePNG, (id)kUTTypeTIFF, (id)kUTTypeJPEG, (id)kUTTypeGIF];
</del><ins>+    return @[(__bridge NSString *)kUTTypePNG, (__bridge NSString *)kUTTypeTIFF, (__bridge NSString *)kUTTypeJPEG, (__bridge NSString *)kUTTypeGIF];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static bool isTypeAllowedByReadingPolicy(NSString *type, WebContentReadingPolicy policy)
</span><span class="lines">@@ -175,21 +175,22 @@
</span><span class="cx"> {
</span><span class="cx">     return policy == WebContentReadingPolicy::AnyType
</span><span class="cx">         || [type isEqualToString:WebArchivePboardType]
</span><del>-        || [type isEqualToString:(NSString *)kUTTypeHTML]
-        || [type isEqualToString:(NSString *)kUTTypeRTF]
-        || [type isEqualToString:(NSString *)kUTTypeFlatRTFD];
</del><ins>+        || [type isEqualToString:(__bridge NSString *)kUTTypeWebArchive]
+        || [type isEqualToString:(__bridge NSString *)kUTTypeHTML]
+        || [type isEqualToString:(__bridge NSString *)kUTTypeRTF]
+        || [type isEqualToString:(__bridge NSString *)kUTTypeFlatRTFD];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> Pasteboard::ReaderResult Pasteboard::readPasteboardWebContentDataForType(PasteboardWebContentReader& reader, PasteboardStrategy& strategy, NSString *type, int itemIndex)
</span><span class="cx"> {
</span><del>-    if ([type isEqualToString:WebArchivePboardType]) {
-        auto buffer = strategy.readBufferFromPasteboard(itemIndex, WebArchivePboardType, m_pasteboardName);
</del><ins>+    if ([type isEqualToString:WebArchivePboardType] || [type isEqualToString:(__bridge NSString *)kUTTypeWebArchive]) {
+        auto buffer = strategy.readBufferFromPasteboard(itemIndex, type, m_pasteboardName);
</ins><span class="cx">         if (m_changeCount != changeCount())
</span><span class="cx">             return ReaderResult::PasteboardWasChangedExternally;
</span><span class="cx">         return buffer && reader.readWebArchive(*buffer) ? ReaderResult::ReadType : ReaderResult::DidNotReadType;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    if ([type isEqualToString:(NSString *)kUTTypeHTML]) {
</del><ins>+    if ([type isEqualToString:(__bridge NSString *)kUTTypeHTML]) {
</ins><span class="cx">         String htmlString = strategy.readStringFromPasteboard(itemIndex, kUTTypeHTML, m_pasteboardName);
</span><span class="cx">         if (m_changeCount != changeCount())
</span><span class="cx">             return ReaderResult::PasteboardWasChangedExternally;
</span><span class="lines">@@ -196,7 +197,8 @@
</span><span class="cx">         return !htmlString.isNull() && reader.readHTML(htmlString) ? ReaderResult::ReadType : ReaderResult::DidNotReadType;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    if ([type isEqualToString:(NSString *)kUTTypeFlatRTFD]) {
</del><ins>+#if !PLATFORM(IOSMAC)
+    if ([type isEqualToString:(__bridge NSString *)kUTTypeFlatRTFD]) {
</ins><span class="cx">         RefPtr<SharedBuffer> buffer = strategy.readBufferFromPasteboard(itemIndex, kUTTypeFlatRTFD, m_pasteboardName);
</span><span class="cx">         if (m_changeCount != changeCount())
</span><span class="cx">             return ReaderResult::PasteboardWasChangedExternally;
</span><span class="lines">@@ -203,12 +205,13 @@
</span><span class="cx">         return buffer && reader.readRTFD(*buffer) ? ReaderResult::ReadType : ReaderResult::DidNotReadType;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    if ([type isEqualToString:(NSString *)kUTTypeRTF]) {
</del><ins>+    if ([type isEqualToString:(__bridge NSString *)kUTTypeRTF]) {
</ins><span class="cx">         RefPtr<SharedBuffer> buffer = strategy.readBufferFromPasteboard(itemIndex, kUTTypeRTF, m_pasteboardName);
</span><span class="cx">         if (m_changeCount != changeCount())
</span><span class="cx">             return ReaderResult::PasteboardWasChangedExternally;
</span><span class="cx">         return buffer && reader.readRTF(*buffer) ? ReaderResult::ReadType : ReaderResult::DidNotReadType;
</span><span class="cx">     }
</span><ins>+#endif // !PLATFORM(IOSMAC)
</ins><span class="cx"> 
</span><span class="cx">     if ([supportedImageTypes() containsObject:type]) {
</span><span class="cx">         RefPtr<SharedBuffer> buffer = strategy.readBufferFromPasteboard(itemIndex, type, m_pasteboardName);
</span><span class="lines">@@ -217,7 +220,7 @@
</span><span class="cx">         return buffer && reader.readImage(buffer.releaseNonNull(), type) ? ReaderResult::ReadType : ReaderResult::DidNotReadType;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    if ([type isEqualToString:(NSString *)kUTTypeURL]) {
</del><ins>+    if ([type isEqualToString:(__bridge NSString *)kUTTypeURL]) {
</ins><span class="cx">         String title;
</span><span class="cx">         URL url = strategy.readURLFromPasteboard(itemIndex, m_pasteboardName, title);
</span><span class="cx">         if (m_changeCount != changeCount())
</span><span class="lines">@@ -225,7 +228,7 @@
</span><span class="cx">         return !url.isNull() && reader.readURL(url, title) ? ReaderResult::ReadType : ReaderResult::DidNotReadType;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    if (UTTypeConformsTo((CFStringRef)type, kUTTypePlainText)) {
</del><ins>+    if (UTTypeConformsTo((__bridge CFStringRef)type, kUTTypePlainText)) {
</ins><span class="cx">         String string = strategy.readStringFromPasteboard(itemIndex, kUTTypePlainText, m_pasteboardName);
</span><span class="cx">         if (m_changeCount != changeCount())
</span><span class="cx">             return ReaderResult::PasteboardWasChangedExternally;
</span><span class="lines">@@ -232,7 +235,7 @@
</span><span class="cx">         return !string.isNull() && reader.readPlainText(string) ? ReaderResult::ReadType : ReaderResult::DidNotReadType;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    if (UTTypeConformsTo((CFStringRef)type, kUTTypeText)) {
</del><ins>+    if (UTTypeConformsTo((__bridge CFStringRef)type, kUTTypeText)) {
</ins><span class="cx">         String string = strategy.readStringFromPasteboard(itemIndex, kUTTypeText, m_pasteboardName);
</span><span class="cx">         if (m_changeCount != changeCount())
</span><span class="cx">             return ReaderResult::PasteboardWasChangedExternally;
</span><span class="lines">@@ -321,7 +324,23 @@
</span><span class="cx"> 
</span><span class="cx"> NSArray *Pasteboard::supportedWebContentPasteboardTypes()
</span><span class="cx"> {
</span><del>-    return @[(id)WebArchivePboardType, (id)kUTTypeFlatRTFD, (id)kUTTypeRTF, (id)kUTTypeHTML, (id)kUTTypePNG, (id)kUTTypeTIFF, (id)kUTTypeJPEG, (id)kUTTypeGIF, (id)kUTTypeURL, (id)kUTTypeText];
</del><ins>+    return @[
+#if !PLATFORM(IOSMAC)
+        WebArchivePboardType,
+#endif
+        (__bridge NSString *)kUTTypeWebArchive,
+#if !PLATFORM(IOSMAC)
+        (__bridge NSString *)kUTTypeFlatRTFD,
+        (__bridge NSString *)kUTTypeRTF,
+#endif
+        (__bridge NSString *)kUTTypeHTML,
+        (__bridge NSString *)kUTTypePNG,
+        (__bridge NSString *)kUTTypeTIFF,
+        (__bridge NSString *)kUTTypeJPEG,
+        (__bridge NSString *)kUTTypeGIF,
+        (__bridge NSString *)kUTTypeURL,
+        (__bridge NSString *)kUTTypeText
+    ];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> NSArray *Pasteboard::supportedFileUploadPasteboardTypes()
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformiosPlatformPasteboardIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm (238660 => 238661)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm       2018-11-29 04:39:45 UTC (rev 238660)
+++ trunk/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm  2018-11-29 05:25:07 UTC (rev 238661)
</span><span class="lines">@@ -350,14 +350,21 @@
</span><span class="cx"> {
</span><span class="cx">     auto representationsToRegister = adoptNS([[WebItemProviderRegistrationInfoList alloc] init]);
</span><span class="cx"> 
</span><ins>+#if !PLATFORM(IOSMAC)
</ins><span class="cx">     [representationsToRegister addData:[webIOSPastePboardType dataUsingEncoding:NSUTF8StringEncoding] forType:webIOSPastePboardType];
</span><ins>+#endif
</ins><span class="cx"> 
</span><span class="cx">     ASSERT(content.clientTypes.size() == content.clientData.size());
</span><span class="cx">     for (size_t i = 0, size = content.clientTypes.size(); i < size; ++i)
</span><span class="cx">         [representationsToRegister addData:content.clientData[i]->createNSData().get() forType:content.clientTypes[i]];
</span><span class="cx"> 
</span><del>-    if (content.dataInWebArchiveFormat)
-        [representationsToRegister addData:content.dataInWebArchiveFormat->createNSData().get() forType:WebArchivePboardType];
</del><ins>+    if (content.dataInWebArchiveFormat) {
+        auto webArchiveData = content.dataInWebArchiveFormat->createNSData();
+#if !PLATFORM(IOSMAC)
+        [representationsToRegister addData:webArchiveData.get() forType:WebArchivePboardType];
+#endif
+        [representationsToRegister addData:webArchiveData.get() forType:(__bridge NSString *)kUTTypeWebArchive];
+    }
</ins><span class="cx"> 
</span><span class="cx">     if (content.dataInAttributedStringFormat) {
</span><span class="cx">         NSAttributedString *attributedString = unarchivedObjectOfClassesFromData([NSSet setWithObject:[NSAttributedString class]], content.dataInAttributedStringFormat->createNSData().get());
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (238660 => 238661)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog    2018-11-29 04:39:45 UTC (rev 238660)
+++ trunk/Tools/ChangeLog       2018-11-29 05:25:07 UTC (rev 238661)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2018-11-28  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [iOSMac] Dropping text selections from web content into editable elements crashes the web process
+        https://bugs.webkit.org/show_bug.cgi?id=192113
+        <rdar://problem/46323701>
+
+        Reviewed by Ryosuke Niwa.
+
+        Add a test to verify that, when dropping an item with both "com.apple.webarchive" and "public.utf8-plain-text"
+        representations, the higher fidelity web archive data is used when handling the drop.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/DragAndDropTests.mm:
+
</ins><span class="cx"> 2018-11-28  Aakash Jain  <aakash_jain@apple.com>
</span><span class="cx"> 
</span><span class="cx">         [ews-app] Fetch bugs from Bugzilla and submit to Buildbot
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKitCocoaDragAndDropTestsmm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DragAndDropTests.mm (238660 => 238661)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DragAndDropTests.mm  2018-11-29 04:39:45 UTC (rev 238660)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DragAndDropTests.mm     2018-11-29 05:25:07 UTC (rev 238661)
</span><span class="lines">@@ -25,12 +25,52 @@
</span><span class="cx"> 
</span><span class="cx"> #import "config.h"
</span><span class="cx"> 
</span><ins>+#if WK_API_ENABLED && ENABLE(DRAG_SUPPORT)
+
</ins><span class="cx"> #import "DragAndDropSimulator.h"
</span><span class="cx"> #import "PlatformUtilities.h"
</span><span class="cx"> #import <WebKit/WKPreferencesPrivate.h>
</span><ins>+#import <WebKit/WebArchive.h>
</ins><span class="cx"> 
</span><del>-#if WK_API_ENABLED && ENABLE(DRAG_SUPPORT)
</del><ins>+#if PLATFORM(IOS_FAMILY)
+#import <MobileCoreServices/MobileCoreServices.h>
+#endif
</ins><span class="cx"> 
</span><ins>+TEST(DragAndDropTests, ModernWebArchiveType)
+{
+    NSData *markupData = [@"<strong><i>Hello world</i></strong>" dataUsingEncoding:NSUTF8StringEncoding];
+    auto mainResource = adoptNS([[WebResource alloc] initWithData:markupData URL:[NSURL URLWithString:@"foo.html"] MIMEType:@"text/html" textEncodingName:@"utf-8" frameName:nil]);
+    auto archive = adoptNS([[WebArchive alloc] initWithMainResource:mainResource.get() subresources:@[ ] subframeArchives:@[ ]]);
+    NSString *webArchiveType = (__bridge NSString *)kUTTypeWebArchive;
+
+    auto simulator = adoptNS([[DragAndDropSimulator alloc] initWithWebViewFrame:CGRectMake(0, 0, 320, 500)]);
+    auto webView = [simulator webView];
+    [webView synchronouslyLoadHTMLString:@"<meta name='viewport' content='width=device-width'><body style='width: 100%; height: 100%;' contenteditable>"];
+#if PLATFORM(MAC)
+    NSPasteboard *pasteboard = [NSPasteboard pasteboardWithUniqueName];
+    [pasteboard declareTypes:@[webArchiveType, (__bridge NSString *)kUTTypeUTF8PlainText] owner:nil];
+    [pasteboard setData:[archive data] forType:webArchiveType];
+    [pasteboard setData:[@"Hello world" dataUsingEncoding:NSUTF8StringEncoding] forType:(__bridge NSString *)kUTTypeUTF8PlainText];
+    [simulator setExternalDragPasteboard:pasteboard];
+#else
+    auto item = adoptNS([[NSItemProvider alloc] init]);
+    [item registerDataRepresentationForTypeIdentifier:webArchiveType visibility:NSItemProviderRepresentationVisibilityAll loadHandler:[&] (void (^completionHandler)(NSData *, NSError *)) -> NSProgress * {
+        completionHandler([archive data], nil);
+        return nil;
+    }];
+    [item registerDataRepresentationForTypeIdentifier:(__bridge NSString *)kUTTypeUTF8PlainText visibility:NSItemProviderRepresentationVisibilityAll loadHandler:[&] (void (^completionHandler)(NSData *, NSError *)) -> NSProgress * {
+        completionHandler([@"Hello world" dataUsingEncoding:NSUTF8StringEncoding], nil);
+        return nil;
+    }];
+    [simulator setExternalItemProviders:@[ item.get() ]];
+#endif
+    [simulator runFrom:CGPointMake(0, 0) to:CGPointMake(50, 50)];
+    [webView stringByEvaluatingJavaScript:@"document.body.focus(); getSelection().setBaseAndExtent(document.body, 0, document.body, 1)"];
+    EXPECT_WK_STREQ("Hello world", [webView stringByEvaluatingJavaScript:@"document.body.textContent"]);
+    EXPECT_TRUE([webView stringByEvaluatingJavaScript:@"document.queryCommandState('bold')"].boolValue);
+    EXPECT_TRUE([webView stringByEvaluatingJavaScript:@"document.queryCommandState('italic')"].boolValue);
+}
+
</ins><span class="cx"> TEST(DragAndDropTests, DragImageLocationForLinkInSubframe)
</span><span class="cx"> {
</span><span class="cx">     auto simulator = adoptNS([[DragAndDropSimulator alloc] initWithWebViewFrame:CGRectMake(0, 0, 400, 400)]);
</span></span></pre>
</div>
</div>

</body>
</html>