<!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>[237624] 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/237624">237624</a></dd>
<dt>Author</dt> <dd>wenson_hsieh@apple.com</dd>
<dt>Date</dt> <dd>2018-10-30 22:29:17 -0700 (Tue, 30 Oct 2018)</dd>
</dl>

<h3>Log Message</h3>
<pre>[Cocoa] Attachment dropped from one web view to another is missing its file wrapper
https://bugs.webkit.org/show_bug.cgi?id=190530
<rdar://problem/45232149>

Reviewed by Tim Horton.

Source/WebCore:

Add support for copying and pasting attachment elements across web views by encoding and adding file wrapper
data as subresources in the web archive when writing selected web content to the pasteboard, and then decoding
and creating NSFileWrappers upon reading web content.

Test: WKAttachmentTests.CopyAndPasteBetweenWebViews

* WebCore.xcodeproj/project.pbxproj:
* editing/Editor.cpp:
(WebCore::Editor::registerAttachments):
* editing/Editor.h:

Add registerAttachments(), which registers _WKAttachments in the UI process given a list of
SerializedAttachmentData. This behaves similarly to registerAttachmentIdentifiers(), but differs in that (1) it
sends serialized file wrapper data, and (2) it sends a list of serialized attachments, rather than information
about just a single attachment.

* editing/SerializedAttachmentData.h:

Introduce SerializedAttachmentData, a struct containing information needed to serialize and deserialize an
attachment. These are used both when writing attachment data to the pasteboard, and when consuming attachment
data upon paste.

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

Add a step when pasting rich content with attachments, to collect and send serialized attachments to the client.
Also, drive-by fix: don't WTFMove() the Ref here if it's still going to be used below.

* html/HTMLAttachmentElement.cpp:
(WebCore::HTMLAttachmentElement::archiveResourceURL):
* html/HTMLAttachmentElement.h:

Add a static helper function to compute a URL that represents the data for the given attachment identifier, for
use in a web archive resource.

* loader/archive/cf/LegacyWebArchive.cpp:
(WebCore::addSubresourcesForAttachmentElementsIfNecessary):

Add a helper function to create and append ArchiveResources representing attachment element data when writing
attachments to the pasteboard via web archive data.

(WebCore::LegacyWebArchive::create):
* page/EditorClient.h:
(WebCore::EditorClient::registerAttachments):
(WebCore::EditorClient::serializedAttachmentDataForIdentifiers):

Source/WebKit:

See WebCore ChangeLog for more details.

* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<SerializedAttachmentData>::encode):
(IPC::ArgumentCoder<SerializedAttachmentData>::decode):
* Shared/WebCoreArgumentCoders.h:

Add IPC encoding/decoding support for SerializedAttachmentData.

* UIProcess/API/APIAttachment.cpp:
(API::Attachment::createSerializedRepresentation const):
(API::Attachment::updateFromSerializedRepresentation):
* UIProcess/API/APIAttachment.h:
* UIProcess/API/Cocoa/APIAttachmentCocoa.mm:
(API::Attachment::createSerializedRepresentation const):

Add a method to serialize and return attachment info as a blob of data.

(API::Attachment::updateFromSerializedRepresentation):

Add a method to update the attachment, given a serialized blob of data. On Cocoa platforms, this fails
gracefully if the serialized data cannot be decoded.

* UIProcess/Cocoa/PageClientImplCocoa.h:
* UIProcess/Cocoa/PageClientImplCocoa.mm:
(WebKit::PageClientImplCocoa::allocFileWrapperInstance const):
(WebKit::PageClientImplCocoa::serializableFileWrapperClasses const):
(WebKit::PageClientImplCocoa::allocFileWrapperInstance): Deleted.

Add an additional hook to return the list of NSFileWrapper subclasses suitable for deserialization. This
array contains (at minimum) NSFileWrapper, but may additionally include a custom NSFileWrapper subclass, if
configured.

* UIProcess/PageClient.h:
(WebKit::PageClient::allocFileWrapperInstance const):
(WebKit::PageClient::serializableFileWrapperClasses const):
(WebKit::PageClient::allocFileWrapperInstance): Deleted.
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::registerAttachmentsFromSerializedData):

Registers the given serialized attachment data, creating new _WKAttachment instances if necessary. Currently,
this does not update the file wrappers of existing _WKAttachments; we should revisit this in the future to see
if we can additionally update file wrappers for existing attachments, without breaking the case where the user
copies and pastes or drags and drops attachments within a single web view and the client expects _WKAttachment
instances to be reused.

(WebKit::WebPageProxy::serializedAttachmentDataForIdentifiers):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* WebProcess/WebCoreSupport/WebEditorClient.cpp:
(WebKit::WebEditorClient::registerAttachments):
(WebKit::WebEditorClient::serializedAttachmentDataForIdentifiers):

Implement a new IPC hook to fetch an array of serialized attachment data blobs, given a list of attachment
identifiers.

* WebProcess/WebCoreSupport/WebEditorClient.h:

Tools:

Add a test to verify that copying different types of attachments and pasting in a new web view inserts
attachments in the second web view that are backed by _WKAttachment objects, whose NSFileWrappers hold data that
is equivalent to the original file wrappers used to insert attachments in the first web view.

Existing API tests verify that when copying and pasting within a single web view, the pasted attachment element
is still backed by the same NSFileWrapper instance.

* TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
(TestWebKitAPI::TEST):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebCoreeditingEditorcpp">trunk/Source/WebCore/editing/Editor.cpp</a></li>
<li><a href="#trunkSourceWebCoreeditingEditorh">trunk/Source/WebCore/editing/Editor.h</a></li>
<li><a href="#trunkSourceWebCoreeditingcocoaWebContentReaderCocoamm">trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLAttachmentElementcpp">trunk/Source/WebCore/html/HTMLAttachmentElement.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLAttachmentElementh">trunk/Source/WebCore/html/HTMLAttachmentElement.h</a></li>
<li><a href="#trunkSourceWebCoreloaderarchivecfLegacyWebArchivecpp">trunk/Source/WebCore/loader/archive/cf/LegacyWebArchive.cpp</a></li>
<li><a href="#trunkSourceWebCorepageEditorClienth">trunk/Source/WebCore/page/EditorClient.h</a></li>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitSharedWebCoreArgumentCoderscpp">trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp</a></li>
<li><a href="#trunkSourceWebKitSharedWebCoreArgumentCodersh">trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h</a></li>
<li><a href="#trunkSourceWebKitUIProcessAPIAPIAttachmentcpp">trunk/Source/WebKit/UIProcess/API/APIAttachment.cpp</a></li>
<li><a href="#trunkSourceWebKitUIProcessAPIAPIAttachmenth">trunk/Source/WebKit/UIProcess/API/APIAttachment.h</a></li>
<li><a href="#trunkSourceWebKitUIProcessAPICocoaAPIAttachmentCocoamm">trunk/Source/WebKit/UIProcess/API/Cocoa/APIAttachmentCocoa.mm</a></li>
<li><a href="#trunkSourceWebKitUIProcessCocoaPageClientImplCocoah">trunk/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.h</a></li>
<li><a href="#trunkSourceWebKitUIProcessCocoaPageClientImplCocoamm">trunk/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.mm</a></li>
<li><a href="#trunkSourceWebKitUIProcessPageClienth">trunk/Source/WebKit/UIProcess/PageClient.h</a></li>
<li><a href="#trunkSourceWebKitUIProcessWebPageProxycpp">trunk/Source/WebKit/UIProcess/WebPageProxy.cpp</a></li>
<li><a href="#trunkSourceWebKitUIProcessWebPageProxyh">trunk/Source/WebKit/UIProcess/WebPageProxy.h</a></li>
<li><a href="#trunkSourceWebKitUIProcessWebPageProxymessagesin">trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in</a></li>
<li><a href="#trunkSourceWebKitWebProcessWebCoreSupportWebEditorClientcpp">trunk/Source/WebKit/WebProcess/WebCoreSupport/WebEditorClient.cpp</a></li>
<li><a href="#trunkSourceWebKitWebProcessWebCoreSupportWebEditorClienth">trunk/Source/WebKit/WebProcess/WebCoreSupport/WebEditorClient.h</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKitCocoaWKAttachmentTestsmm">trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreeditingSerializedAttachmentDatah">trunk/Source/WebCore/editing/SerializedAttachmentData.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (237623 => 237624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2018-10-31 05:05:31 UTC (rev 237623)
+++ trunk/Source/WebCore/ChangeLog      2018-10-31 05:29:17 UTC (rev 237624)
</span><span class="lines">@@ -1,3 +1,57 @@
</span><ins>+2018-10-30  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [Cocoa] Attachment dropped from one web view to another is missing its file wrapper
+        https://bugs.webkit.org/show_bug.cgi?id=190530
+        <rdar://problem/45232149>
+
+        Reviewed by Tim Horton.
+
+        Add support for copying and pasting attachment elements across web views by encoding and adding file wrapper
+        data as subresources in the web archive when writing selected web content to the pasteboard, and then decoding
+        and creating NSFileWrappers upon reading web content.
+
+        Test: WKAttachmentTests.CopyAndPasteBetweenWebViews
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * editing/Editor.cpp:
+        (WebCore::Editor::registerAttachments):
+        * editing/Editor.h:
+
+        Add registerAttachments(), which registers _WKAttachments in the UI process given a list of
+        SerializedAttachmentData. This behaves similarly to registerAttachmentIdentifiers(), but differs in that (1) it
+        sends serialized file wrapper data, and (2) it sends a list of serialized attachments, rather than information
+        about just a single attachment.
+
+        * editing/SerializedAttachmentData.h:
+
+        Introduce SerializedAttachmentData, a struct containing information needed to serialize and deserialize an
+        attachment. These are used both when writing attachment data to the pasteboard, and when consuming attachment
+        data upon paste.
+
+        * editing/cocoa/WebContentReaderCocoa.mm:
+        (WebCore::replaceRichContentWithAttachments):
+
+        Add a step when pasting rich content with attachments, to collect and send serialized attachments to the client.
+        Also, drive-by fix: don't WTFMove() the Ref here if it's still going to be used below.
+
+        * html/HTMLAttachmentElement.cpp:
+        (WebCore::HTMLAttachmentElement::archiveResourceURL):
+        * html/HTMLAttachmentElement.h:
+
+        Add a static helper function to compute a URL that represents the data for the given attachment identifier, for
+        use in a web archive resource.
+
+        * loader/archive/cf/LegacyWebArchive.cpp:
+        (WebCore::addSubresourcesForAttachmentElementsIfNecessary):
+
+        Add a helper function to create and append ArchiveResources representing attachment element data when writing
+        attachments to the pasteboard via web archive data.
+
+        (WebCore::LegacyWebArchive::create):
+        * page/EditorClient.h:
+        (WebCore::EditorClient::registerAttachments):
+        (WebCore::EditorClient::serializedAttachmentDataForIdentifiers):
+
</ins><span class="cx"> 2018-10-30  David Kilzer  <ddkilzer@apple.com>
</span><span class="cx"> 
</span><span class="cx">         XSLTProcessor should limit max transform depth
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (237623 => 237624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj   2018-10-31 05:05:31 UTC (rev 237623)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj      2018-10-31 05:29:17 UTC (rev 237624)
</span><span class="lines">@@ -4889,6 +4889,7 @@
</span><span class="cx">          F49786881FF45FA500E060AB /* PasteboardItemInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = F49786871FF45FA500E060AB /* PasteboardItemInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">          F4BFB9851E1DDF9B00862C24 /* DumpEditingHistory.js in Copy Scripts */ = {isa = PBXBuildFile; fileRef = F48389831E1DDF2B0076B7EA /* DumpEditingHistory.js */; };
</span><span class="cx">          F4BFB9861E1DDF9B00862C24 /* EditingHistoryUtil.js in Copy Scripts */ = {isa = PBXBuildFile; fileRef = F48389841E1DDF2B0076B7EA /* EditingHistoryUtil.js */; };
</span><ins>+               F4D43D662188038B00ECECAC /* SerializedAttachmentData.h in Headers */ = {isa = PBXBuildFile; fileRef = F4D43D64218802E600ECECAC /* SerializedAttachmentData.h */; settings = {ATTRIBUTES = (Private, ); }; };
</ins><span class="cx">           F4E57EDC213F3F5F004EA98E /* FontAttributeChanges.h in Headers */ = {isa = PBXBuildFile; fileRef = F4E57EDA213F3F5F004EA98E /* FontAttributeChanges.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">          F4E57EE1213F434A004EA98E /* WebCoreNSFontManagerExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = F4E57EDF213F434A004EA98E /* WebCoreNSFontManagerExtras.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">          F50664F8157F52DC00AC226F /* FormController.h in Headers */ = {isa = PBXBuildFile; fileRef = F50664F6157F52DC00AC226F /* FormController.h */; };
</span><span class="lines">@@ -14798,6 +14799,7 @@
</span><span class="cx">          F48D2AA32159740D00C6752B /* ColorCocoa.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ColorCocoa.h; sourceTree = "<group>"; };
</span><span class="cx">          F48D2AA42159740D00C6752B /* ColorCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ColorCocoa.mm; sourceTree = "<group>"; };
</span><span class="cx">          F49786871FF45FA500E060AB /* PasteboardItemInfo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PasteboardItemInfo.h; sourceTree = "<group>"; };
</span><ins>+               F4D43D64218802E600ECECAC /* SerializedAttachmentData.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SerializedAttachmentData.h; sourceTree = "<group>"; };
</ins><span class="cx">           F4E57EDA213F3F5F004EA98E /* FontAttributeChanges.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FontAttributeChanges.h; sourceTree = "<group>"; };
</span><span class="cx">          F4E57EDF213F434A004EA98E /* WebCoreNSFontManagerExtras.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebCoreNSFontManagerExtras.h; sourceTree = "<group>"; };
</span><span class="cx">          F4E57EE0213F434A004EA98E /* WebCoreNSFontManagerExtras.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreNSFontManagerExtras.mm; sourceTree = "<group>"; };
</span><span class="lines">@@ -20621,6 +20623,7 @@
</span><span class="cx">                          93309DBB099E64910056E581 /* ReplaceSelectionCommand.h */,
</span><span class="cx">                          51405C86190B014400754F94 /* SelectionRectGatherer.cpp */,
</span><span class="cx">                          51405C87190B014400754F94 /* SelectionRectGatherer.h */,
</span><ins>+                               F4D43D64218802E600ECECAC /* SerializedAttachmentData.h */,
</ins><span class="cx">                           93309DC0099E64910056E581 /* SetNodeAttributeCommand.cpp */,
</span><span class="cx">                          93309DC1099E64910056E581 /* SetNodeAttributeCommand.h */,
</span><span class="cx">                          B8DBDB47130B0F8A00F5CDB1 /* SetSelectionCommand.cpp */,
</span><span class="lines">@@ -30704,6 +30707,7 @@
</span><span class="cx">                          415071581685067300C3C7B3 /* SelectorFilter.h in Headers */,
</span><span class="cx">                          43107BE218CC19DE00CC18E8 /* SelectorPseudoTypeMap.h in Headers */,
</span><span class="cx">                          E45322AC140CE267005A0F92 /* SelectorQuery.h in Headers */,
</span><ins>+                               F4D43D662188038B00ECECAC /* SerializedAttachmentData.h in Headers */,
</ins><span class="cx">                           E18DF33518AAF12C00773E59 /* SerializedCryptoKeyWrap.h in Headers */,
</span><span class="cx">                          077AF14018F4AE400001ED61 /* SerializedPlatformRepresentation.h in Headers */,
</span><span class="cx">                          077AF14318F4B1BB0001ED61 /* SerializedPlatformRepresentationMac.h in Headers */,
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingEditorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/Editor.cpp (237623 => 237624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/Editor.cpp  2018-10-31 05:05:31 UTC (rev 237623)
+++ trunk/Source/WebCore/editing/Editor.cpp     2018-10-31 05:29:17 UTC (rev 237624)
</span><span class="lines">@@ -85,8 +85,10 @@
</span><span class="cx"> #include "ReplaceRangeWithTextCommand.h"
</span><span class="cx"> #include "ReplaceSelectionCommand.h"
</span><span class="cx"> #include "RuntimeEnabledFeatures.h"
</span><ins>+#include "SerializedAttachmentData.h"
</ins><span class="cx"> #include "Settings.h"
</span><span class="cx"> #include "ShadowRoot.h"
</span><ins>+#include "SharedBuffer.h"
</ins><span class="cx"> #include "SimplifyMarkupCommand.h"
</span><span class="cx"> #include "SpellChecker.h"
</span><span class="cx"> #include "SpellingCorrectionCommand.h"
</span><span class="lines">@@ -4010,6 +4012,12 @@
</span><span class="cx">         client->registerAttachmentIdentifier(identifier, contentType, filePath);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void Editor::registerAttachments(Vector<SerializedAttachmentData>&& data)
+{
+    if (auto* client = this->client())
+        client->registerAttachments(WTFMove(data));
+}
+
</ins><span class="cx"> void Editor::registerAttachmentIdentifier(const String& identifier)
</span><span class="cx"> {
</span><span class="cx">     if (auto* client = this->client())
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingEditorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/Editor.h (237623 => 237624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/Editor.h    2018-10-31 05:05:31 UTC (rev 237623)
+++ trunk/Source/WebCore/editing/Editor.h       2018-10-31 05:29:17 UTC (rev 237624)
</span><span class="lines">@@ -86,6 +86,10 @@
</span><span class="cx"> struct PasteboardURL;
</span><span class="cx"> struct TextCheckingResult;
</span><span class="cx"> 
</span><ins>+#if ENABLE(ATTACHMENT_ELEMENT)
+struct SerializedAttachmentData;
+#endif
+
</ins><span class="cx"> enum EditorCommandSource { CommandFromMenuOrKeyBinding, CommandFromDOM, CommandFromDOMWithUserInterface };
</span><span class="cx"> enum EditorParagraphSeparator { EditorParagraphSeparatorIsDiv, EditorParagraphSeparatorIsP };
</span><span class="cx"> 
</span><span class="lines">@@ -509,8 +513,9 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(ATTACHMENT_ELEMENT)
</span><span class="cx">     WEBCORE_EXPORT void insertAttachment(const String& identifier, std::optional<uint64_t>&& fileSize, const String& fileName, const String& contentType);
</span><del>-    void registerAttachmentIdentifier(const String&, const String& /* contentType */, const String& /* preferredFileName */, Ref<SharedBuffer>&&);
-    void registerAttachmentIdentifier(const String&, const String& /* contentType */, const String& /* filePath */);
</del><ins>+    void registerAttachmentIdentifier(const String&, const String& contentType, const String& preferredFileName, Ref<SharedBuffer>&& fileData);
+    void registerAttachments(Vector<SerializedAttachmentData>&&);
+    void registerAttachmentIdentifier(const String&, const String& contentType, const String& filePath);
</ins><span class="cx">     void registerAttachmentIdentifier(const String&);
</span><span class="cx">     void cloneAttachmentData(const String& fromIdentifier, const String& toIdentifier);
</span><span class="cx">     void didInsertAttachmentElement(HTMLAttachmentElement&);
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingSerializedAttachmentDatahfromrev237623trunkSourceWebKitUIProcessCocoaPageClientImplCocoah"></a>
<div class="copfile"><h4>Copied: trunk/Source/WebCore/editing/SerializedAttachmentData.h (from rev 237623, trunk/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.h) (0 => 237624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/SerializedAttachmentData.h                          (rev 0)
+++ trunk/Source/WebCore/editing/SerializedAttachmentData.h     2018-10-31 05:29:17 UTC (rev 237624)
</span><span class="lines">@@ -0,0 +1,46 @@
</span><ins>+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(ATTACHMENT_ELEMENT)
+
+#include "SharedBuffer.h"
+#include <wtf/Ref.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class SharedBuffer;
+
+struct SerializedAttachmentData {
+    String identifier;
+    String mimeType;
+    Ref<SharedBuffer> data;
+};
+
+} // namespace WebKit
+
+#endif // ENABLE(ATTACHMENT_ELEMENT)
</ins></span></pre></div>
<a id="trunkSourceWebCoreeditingcocoaWebContentReaderCocoamm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm (237623 => 237624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm      2018-10-31 05:05:31 UTC (rev 237623)
+++ trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm 2018-10-31 05:29:17 UTC (rev 237624)
</span><span class="lines">@@ -51,6 +51,7 @@
</span><span class="cx"> #import "Page.h"
</span><span class="cx"> #import "PublicURLManager.h"
</span><span class="cx"> #import "RuntimeEnabledFeatures.h"
</span><ins>+#import "SerializedAttachmentData.h"
</ins><span class="cx"> #import "Settings.h"
</span><span class="cx"> #import "SocketProvider.h"
</span><span class="cx"> #import "TypedElementDescendantIterator.h"
</span><span class="lines">@@ -274,6 +275,20 @@
</span><span class="cx">             urlToResourceMap.set(url.string(), subresource.copyRef());
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    Vector<SerializedAttachmentData> serializedAttachmentData;
+    for (auto& attachment : descendantsOfType<HTMLAttachmentElement>(fragment)) {
+        auto resourceURL = HTMLAttachmentElement::archiveResourceURL(attachment.uniqueIdentifier());
+        auto resourceEntry = urlToResourceMap.find(resourceURL.string());
+        if (resourceEntry == urlToResourceMap.end())
+            continue;
+
+        auto& resource = resourceEntry->value;
+        serializedAttachmentData.append({ attachment.uniqueIdentifier(), resource->mimeType(), resource->data() });
+    }
+
+    if (!serializedAttachmentData.isEmpty())
+        frame.editor().registerAttachments(WTFMove(serializedAttachmentData));
+
</ins><span class="cx">     Vector<Ref<Element>> elementsToRemove;
</span><span class="cx">     Vector<AttachmentInsertionInfo> attachmentInsertionInfo;
</span><span class="cx">     for (auto& image : descendantsOfType<HTMLImageElement>(fragment)) {
</span><span class="lines">@@ -323,7 +338,7 @@
</span><span class="cx">             if (is<HTMLImageElement>(originalElement.get()) && contentTypeIsSuitableForInlineImageRepresentation(info.contentType)) {
</span><span class="cx">                 auto& image = downcast<HTMLImageElement>(originalElement.get());
</span><span class="cx">                 image.setAttributeWithoutSynchronization(HTMLNames::srcAttr, DOMURL::createObjectURL(*frame.document(), Blob::create(info.data, info.contentType)));
</span><del>-                image.setAttachmentElement(WTFMove(attachment));
</del><ins>+                image.setAttachmentElement(attachment.copyRef());
</ins><span class="cx">             } else {
</span><span class="cx">                 attachment->updateAttributes(info.data->size(), info.contentType, info.fileName);
</span><span class="cx">                 parent->replaceChild(attachment, WTFMove(originalElement));
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLAttachmentElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLAttachmentElement.cpp (237623 => 237624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLAttachmentElement.cpp      2018-10-31 05:05:31 UTC (rev 237623)
+++ trunk/Source/WebCore/html/HTMLAttachmentElement.cpp 2018-10-31 05:29:17 UTC (rev 237624)
</span><span class="lines">@@ -38,6 +38,7 @@
</span><span class="cx"> #include "MIMETypeRegistry.h"
</span><span class="cx"> #include "RenderAttachment.h"
</span><span class="cx"> #include "SharedBuffer.h"
</span><ins>+#include "URLParser.h"
</ins><span class="cx"> #include <pal/FileSizeFormatter.h>
</span><span class="cx"> #include <wtf/IsoMallocInlines.h>
</span><span class="cx"> #include <wtf/UUID.h>
</span><span class="lines">@@ -85,6 +86,13 @@
</span><span class="cx">     return identifier;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+URL HTMLAttachmentElement::archiveResourceURL(const String& identifier)
+{
+    auto resourceURL = URLParser("applewebdata://attachment/"_s).result();
+    resourceURL.setPath(identifier);
+    return resourceURL;
+}
+
</ins><span class="cx"> File* HTMLAttachmentElement::file() const
</span><span class="cx"> {
</span><span class="cx">     return m_file.get();
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLAttachmentElementh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLAttachmentElement.h (237623 => 237624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLAttachmentElement.h        2018-10-31 05:05:31 UTC (rev 237623)
+++ trunk/Source/WebCore/html/HTMLAttachmentElement.h   2018-10-31 05:29:17 UTC (rev 237624)
</span><span class="lines">@@ -41,6 +41,7 @@
</span><span class="cx"> public:
</span><span class="cx">     static Ref<HTMLAttachmentElement> create(const QualifiedName&, Document&);
</span><span class="cx">     static const String& getAttachmentIdentifier(HTMLImageElement&);
</span><ins>+    static URL archiveResourceURL(const String&);
</ins><span class="cx"> 
</span><span class="cx">     WEBCORE_EXPORT URL blobURL() const;
</span><span class="cx">     WEBCORE_EXPORT File* file() const;
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderarchivecfLegacyWebArchivecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/archive/cf/LegacyWebArchive.cpp (237623 => 237624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/archive/cf/LegacyWebArchive.cpp      2018-10-31 05:05:31 UTC (rev 237623)
+++ trunk/Source/WebCore/loader/archive/cf/LegacyWebArchive.cpp 2018-10-31 05:29:17 UTC (rev 237624)
</span><span class="lines">@@ -32,10 +32,13 @@
</span><span class="cx"> #include "CachedResource.h"
</span><span class="cx"> #include "Document.h"
</span><span class="cx"> #include "DocumentLoader.h"
</span><ins>+#include "Editor.h"
+#include "EditorClient.h"
</ins><span class="cx"> #include "Frame.h"
</span><span class="cx"> #include "FrameLoader.h"
</span><span class="cx"> #include "FrameSelection.h"
</span><span class="cx"> #include "FrameTree.h"
</span><ins>+#include "HTMLAttachmentElement.h"
</ins><span class="cx"> #include "HTMLFrameElement.h"
</span><span class="cx"> #include "HTMLFrameOwnerElement.h"
</span><span class="cx"> #include "HTMLIFrameElement.h"
</span><span class="lines">@@ -47,7 +50,10 @@
</span><span class="cx"> #include "MemoryCache.h"
</span><span class="cx"> #include "Page.h"
</span><span class="cx"> #include "Range.h"
</span><ins>+#include "RuntimeEnabledFeatures.h"
+#include "SerializedAttachmentData.h"
</ins><span class="cx"> #include "Settings.h"
</span><ins>+#include "SharedBuffer.h"
</ins><span class="cx"> #include "markup.h"
</span><span class="cx"> #include <wtf/ListHashSet.h>
</span><span class="cx"> #include <wtf/RetainPtr.h>
</span><span class="lines">@@ -464,6 +470,42 @@
</span><span class="cx">     return create(markupString, *frame, nodeList, nullptr);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if ENABLE(ATTACHMENT_ELEMENT)
+
+static void addSubresourcesForAttachmentElementsIfNecessary(Frame& frame, const Vector<Node*>& nodes, Vector<Ref<ArchiveResource>>& subresources)
+{
+    if (!RuntimeEnabledFeatures::sharedFeatures().attachmentElementEnabled())
+        return;
+
+    Vector<String> identifiers;
+    for (auto* node : nodes) {
+        if (!is<HTMLAttachmentElement>(node))
+            continue;
+
+        auto uniqueIdentifier = downcast<HTMLAttachmentElement>(*node).uniqueIdentifier();
+        if (uniqueIdentifier.isEmpty())
+            continue;
+
+        identifiers.append(WTFMove(uniqueIdentifier));
+    }
+
+    if (identifiers.isEmpty())
+        return;
+
+    auto* editorClient = frame.editor().client();
+    if (!editorClient)
+        return;
+
+    auto frameName = frame.tree().uniqueName();
+    for (auto& data : editorClient->serializedAttachmentDataForIdentifiers(WTFMove(identifiers))) {
+        auto resourceURL = HTMLAttachmentElement::archiveResourceURL(data.identifier);
+        if (auto resource = ArchiveResource::create(data.data.ptr(), WTFMove(resourceURL), data.mimeType, { }, frameName))
+            subresources.append(resource.releaseNonNull());
+    }
+}
+
+#endif
+
</ins><span class="cx"> RefPtr<LegacyWebArchive> LegacyWebArchive::create(const String& markupString, Frame& frame, const Vector<Node*>& nodes, WTF::Function<bool (Frame&)>&& frameFilter)
</span><span class="cx"> {
</span><span class="cx">     auto& response = frame.loader().documentLoader()->response();
</span><span class="lines">@@ -528,6 +570,10 @@
</span><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+#if ENABLE(ATTACHMENT_ELEMENT)
+    addSubresourcesForAttachmentElementsIfNecessary(frame, nodes, subresources);
+#endif
+
</ins><span class="cx">     // If we are archiving the entire page, add any link icons that we have data for.
</span><span class="cx">     if (!nodes.isEmpty() && nodes[0]->isDocumentNode()) {
</span><span class="cx">         auto* documentLoader = frame.loader().documentLoader();
</span></span></pre></div>
<a id="trunkSourceWebCorepageEditorClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/EditorClient.h (237623 => 237624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/EditorClient.h 2018-10-31 05:05:31 UTC (rev 237623)
+++ trunk/Source/WebCore/page/EditorClient.h    2018-10-31 05:29:17 UTC (rev 237624)
</span><span class="lines">@@ -27,6 +27,7 @@
</span><span class="cx"> #pragma once
</span><span class="cx"> 
</span><span class="cx"> #include "EditorInsertAction.h"
</span><ins>+#include "SerializedAttachmentData.h"
</ins><span class="cx"> #include "TextAffinity.h"
</span><span class="cx"> #include "TextChecking.h"
</span><span class="cx"> #include "UndoStep.h"
</span><span class="lines">@@ -75,11 +76,13 @@
</span><span class="cx"> #if ENABLE(ATTACHMENT_ELEMENT)
</span><span class="cx">     virtual void registerAttachmentIdentifier(const String& /* identifier */, const String& /* contentType */, const String& /* preferredFileName */, Ref<SharedBuffer>&&) { }
</span><span class="cx">     virtual void registerAttachmentIdentifier(const String& /* identifier */, const String& /* contentType */, const String& /* filePath */) { }
</span><ins>+    virtual void registerAttachments(Vector<SerializedAttachmentData>&&) { }
</ins><span class="cx">     virtual void registerAttachmentIdentifier(const String& /* identifier */) { }
</span><span class="cx">     virtual void cloneAttachmentData(const String& /* fromIdentifier */, const String& /* toIdentifier */) { }
</span><span class="cx">     virtual void didInsertAttachmentWithIdentifier(const String& /* identifier */, const String& /* source */, bool /* hasEnclosingImage */) { }
</span><span class="cx">     virtual void didRemoveAttachmentWithIdentifier(const String&) { }
</span><span class="cx">     virtual bool supportsClientSideAttachmentData() const { return false; }
</span><ins>+    virtual Vector<SerializedAttachmentData> serializedAttachmentDataForIdentifiers(const Vector<String>&) { return { }; }
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     virtual void didBeginEditing() = 0;
</span></span></pre></div>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (237623 => 237624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog    2018-10-31 05:05:31 UTC (rev 237623)
+++ trunk/Source/WebKit/ChangeLog       2018-10-31 05:29:17 UTC (rev 237624)
</span><span class="lines">@@ -1,3 +1,69 @@
</span><ins>+2018-10-30  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [Cocoa] Attachment dropped from one web view to another is missing its file wrapper
+        https://bugs.webkit.org/show_bug.cgi?id=190530
+        <rdar://problem/45232149>
+
+        Reviewed by Tim Horton.
+
+        See WebCore ChangeLog for more details.
+
+        * Shared/WebCoreArgumentCoders.cpp:
+        (IPC::ArgumentCoder<SerializedAttachmentData>::encode):
+        (IPC::ArgumentCoder<SerializedAttachmentData>::decode):
+        * Shared/WebCoreArgumentCoders.h:
+
+        Add IPC encoding/decoding support for SerializedAttachmentData.
+
+        * UIProcess/API/APIAttachment.cpp:
+        (API::Attachment::createSerializedRepresentation const):
+        (API::Attachment::updateFromSerializedRepresentation):
+        * UIProcess/API/APIAttachment.h:
+        * UIProcess/API/Cocoa/APIAttachmentCocoa.mm:
+        (API::Attachment::createSerializedRepresentation const):
+
+        Add a method to serialize and return attachment info as a blob of data.
+
+        (API::Attachment::updateFromSerializedRepresentation):
+
+        Add a method to update the attachment, given a serialized blob of data. On Cocoa platforms, this fails
+        gracefully if the serialized data cannot be decoded.
+
+        * UIProcess/Cocoa/PageClientImplCocoa.h:
+        * UIProcess/Cocoa/PageClientImplCocoa.mm:
+        (WebKit::PageClientImplCocoa::allocFileWrapperInstance const):
+        (WebKit::PageClientImplCocoa::serializableFileWrapperClasses const):
+        (WebKit::PageClientImplCocoa::allocFileWrapperInstance): Deleted.
+
+        Add an additional hook to return the list of NSFileWrapper subclasses suitable for deserialization. This
+        array contains (at minimum) NSFileWrapper, but may additionally include a custom NSFileWrapper subclass, if
+        configured.
+
+        * UIProcess/PageClient.h:
+        (WebKit::PageClient::allocFileWrapperInstance const):
+        (WebKit::PageClient::serializableFileWrapperClasses const):
+        (WebKit::PageClient::allocFileWrapperInstance): Deleted.
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::registerAttachmentsFromSerializedData):
+
+        Registers the given serialized attachment data, creating new _WKAttachment instances if necessary. Currently,
+        this does not update the file wrappers of existing _WKAttachments; we should revisit this in the future to see
+        if we can additionally update file wrappers for existing attachments, without breaking the case where the user
+        copies and pastes or drags and drops attachments within a single web view and the client expects _WKAttachment
+        instances to be reused.
+
+        (WebKit::WebPageProxy::serializedAttachmentDataForIdentifiers):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * WebProcess/WebCoreSupport/WebEditorClient.cpp:
+        (WebKit::WebEditorClient::registerAttachments):
+        (WebKit::WebEditorClient::serializedAttachmentDataForIdentifiers):
+
+        Implement a new IPC hook to fetch an array of serialized attachment data blobs, given a list of attachment
+        identifiers.
+
+        * WebProcess/WebCoreSupport/WebEditorClient.h:
+
</ins><span class="cx"> 2018-10-30  Chris Dumez  <cdumez@apple.com>
</span><span class="cx"> 
</span><span class="cx">         [PSON] View gesture snapshot gets taken down early when process-swapping
</span></span></pre></div>
<a id="trunkSourceWebKitSharedWebCoreArgumentCoderscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp (237623 => 237624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp     2018-10-31 05:05:31 UTC (rev 237623)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp        2018-10-31 05:29:17 UTC (rev 237624)
</span><span class="lines">@@ -28,6 +28,7 @@
</span><span class="cx"> 
</span><span class="cx"> #include "DataReference.h"
</span><span class="cx"> #include "ShareableBitmap.h"
</span><ins>+#include "SharedBufferDataReference.h"
</ins><span class="cx"> #include <WebCore/AuthenticationChallenge.h>
</span><span class="cx"> #include <WebCore/BlobPart.h>
</span><span class="cx"> #include <WebCore/CacheQueryOptions.h>
</span><span class="lines">@@ -69,6 +70,7 @@
</span><span class="cx"> #include <WebCore/ScrollingCoordinator.h>
</span><span class="cx"> #include <WebCore/SearchPopupMenu.h>
</span><span class="cx"> #include <WebCore/SecurityOrigin.h>
</span><ins>+#include <WebCore/SerializedAttachmentData.h>
</ins><span class="cx"> #include <WebCore/ServiceWorkerClientData.h>
</span><span class="cx"> #include <WebCore/ServiceWorkerClientIdentifier.h>
</span><span class="cx"> #include <WebCore/ServiceWorkerData.h>
</span><span class="lines">@@ -3012,4 +3014,30 @@
</span><span class="cx">     return attributes;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if ENABLE(ATTACHMENT_ELEMENT)
+
+void ArgumentCoder<SerializedAttachmentData>::encode(IPC::Encoder& encoder, const WebCore::SerializedAttachmentData& data)
+{
+    encoder << data.identifier << data.mimeType << IPC::SharedBufferDataReference { data.data.get() };
+}
+
+std::optional<SerializedAttachmentData> ArgumentCoder<WebCore::SerializedAttachmentData>::decode(IPC::Decoder& decoder)
+{
+    String identifier;
+    if (!decoder.decode(identifier))
+        return std::nullopt;
+
+    String mimeType;
+    if (!decoder.decode(mimeType))
+        return std::nullopt;
+
+    IPC::DataReference data;
+    if (!decoder.decode(data))
+        return std::nullopt;
+
+    return {{ WTFMove(identifier), WTFMove(mimeType), WebCore::SharedBuffer::create(data.data(), data.size()) }};
+}
+
+#endif // ENABLE(ATTACHMENT_ELEMENT)
+
</ins><span class="cx"> } // namespace IPC
</span></span></pre></div>
<a id="trunkSourceWebKitSharedWebCoreArgumentCodersh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h (237623 => 237624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h       2018-10-31 05:05:31 UTC (rev 237623)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h  2018-10-31 05:29:17 UTC (rev 237624)
</span><span class="lines">@@ -164,6 +164,10 @@
</span><span class="cx"> struct MediaConstraints;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#if ENABLE(ATTACHMENT_ELEMENT)
+struct SerializedAttachmentData;
+#endif
+
</ins><span class="cx"> #if ENABLE(INDEXED_DATABASE)
</span><span class="cx"> using IDBKeyPath = Variant<String, Vector<String>>;
</span><span class="cx"> #endif
</span><span class="lines">@@ -720,6 +724,15 @@
</span><span class="cx">     static std::optional<WebCore::FontAttributes> decode(Decoder&);
</span><span class="cx"> };
</span><span class="cx"> 
</span><ins>+#if ENABLE(ATTACHMENT_ELEMENT)
+
+template<> struct ArgumentCoder<WebCore::SerializedAttachmentData> {
+    static void encode(Encoder&, const WebCore::SerializedAttachmentData&);
+    static std::optional<WebCore::SerializedAttachmentData> decode(Decoder&);
+};
+
+#endif // ENABLE(ATTACHMENT_ELEMENT)
+
</ins><span class="cx"> } // namespace IPC
</span><span class="cx"> 
</span><span class="cx"> namespace WTF {
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessAPIAPIAttachmentcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/API/APIAttachment.cpp (237623 => 237624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/API/APIAttachment.cpp      2018-10-31 05:05:31 UTC (rev 237623)
+++ trunk/Source/WebKit/UIProcess/API/APIAttachment.cpp 2018-10-31 05:29:17 UTC (rev 237624)
</span><span class="lines">@@ -96,6 +96,15 @@
</span><span class="cx">     return nullptr;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+RefPtr<WebCore::SharedBuffer> Attachment::createSerializedRepresentation() const
+{
+    return nullptr;
+}
+
+void Attachment::updateFromSerializedRepresentation(Ref<WebCore::SharedBuffer>&&, const WTF::String&)
+{
+}
+
</ins><span class="cx"> #endif // !PLATFORM(COCOA)
</span><span class="cx"> 
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessAPIAPIAttachmenth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/API/APIAttachment.h (237623 => 237624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/API/APIAttachment.h        2018-10-31 05:05:31 UTC (rev 237623)
+++ trunk/Source/WebKit/UIProcess/API/APIAttachment.h   2018-10-31 05:29:17 UTC (rev 237624)
</span><span class="lines">@@ -85,6 +85,9 @@
</span><span class="cx">     void setHasEnclosingImage(bool hasEnclosingImage) { m_hasEnclosingImage = hasEnclosingImage; }
</span><span class="cx">     bool hasEnclosingImage() const { return m_hasEnclosingImage; }
</span><span class="cx"> 
</span><ins>+    RefPtr<WebCore::SharedBuffer> createSerializedRepresentation() const;
+    void updateFromSerializedRepresentation(Ref<WebCore::SharedBuffer>&&, const WTF::String& contentType);
+
</ins><span class="cx"> private:
</span><span class="cx">     explicit Attachment(const WTF::String& identifier, WebKit::WebPageProxy&);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessAPICocoaAPIAttachmentCocoamm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/APIAttachmentCocoa.mm (237623 => 237624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/API/Cocoa/APIAttachmentCocoa.mm    2018-10-31 05:05:31 UTC (rev 237623)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/APIAttachmentCocoa.mm       2018-10-31 05:29:17 UTC (rev 237624)
</span><span class="lines">@@ -26,6 +26,7 @@
</span><span class="cx"> #import "config.h"
</span><span class="cx"> #import "APIAttachment.h"
</span><span class="cx"> 
</span><ins>+#import "PageClient.h"
</ins><span class="cx"> #import <WebCore/MIMETypeRegistry.h>
</span><span class="cx"> #import <WebCore/SharedBuffer.h>
</span><span class="cx"> #if PLATFORM(IOS_FAMILY)
</span><span class="lines">@@ -33,6 +34,7 @@
</span><span class="cx"> #else
</span><span class="cx"> #import <CoreServices/CoreServices.h>
</span><span class="cx"> #endif
</span><ins>+#import <pal/spi/cocoa/NSKeyedArchiverSPI.h>
</ins><span class="cx"> 
</span><span class="cx"> namespace API {
</span><span class="cx"> 
</span><span class="lines">@@ -125,4 +127,33 @@
</span><span class="cx">     return !m_fileWrapper;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+RefPtr<WebCore::SharedBuffer> Attachment::createSerializedRepresentation() const
+{
+    if (!m_fileWrapper || !m_webPage)
+        return nullptr;
+
+    NSData *serializedData = securelyArchivedDataWithRootObject(m_fileWrapper.get());
+    if (!serializedData)
+        return nullptr;
+
+    return WebCore::SharedBuffer::create(serializedData);
+}
+
+void Attachment::updateFromSerializedRepresentation(Ref<WebCore::SharedBuffer>&& serializedRepresentation, const WTF::String& contentType)
+{
+    if (!m_webPage)
+        return;
+
+    auto serializedData = serializedRepresentation->createNSData();
+    if (!serializedData)
+        return;
+
+    NSFileWrapper *fileWrapper = unarchivedObjectOfClassesFromData(m_webPage->pageClient().serializableFileWrapperClasses(), serializedData.get());
+    if (!fileWrapper)
+        return;
+
+    setFileWrapperAndUpdateContentType(fileWrapper, contentType);
+    m_webPage->updateAttachmentAttributes(*this, [] (auto) { });
+}
+
</ins><span class="cx"> } // namespace API
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessCocoaPageClientImplCocoah"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.h (237623 => 237624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.h        2018-10-31 05:05:31 UTC (rev 237623)
+++ trunk/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.h   2018-10-31 05:29:17 UTC (rev 237624)
</span><span class="lines">@@ -45,7 +45,8 @@
</span><span class="cx"> #if ENABLE(ATTACHMENT_ELEMENT)
</span><span class="cx">     void didInsertAttachment(API::Attachment&, const String& source) final;
</span><span class="cx">     void didRemoveAttachment(API::Attachment&) final;
</span><del>-    NSFileWrapper *allocFileWrapperInstance() final;
</del><ins>+    NSFileWrapper *allocFileWrapperInstance() const final;
+    NSSet *serializableFileWrapperClasses() const final;
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> protected:
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessCocoaPageClientImplCocoamm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.mm (237623 => 237624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.mm       2018-10-31 05:05:31 UTC (rev 237623)
+++ trunk/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.mm  2018-10-31 05:29:17 UTC (rev 237624)
</span><span class="lines">@@ -66,7 +66,7 @@
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-NSFileWrapper *PageClientImplCocoa::allocFileWrapperInstance()
</del><ins>+NSFileWrapper *PageClientImplCocoa::allocFileWrapperInstance() const
</ins><span class="cx"> {
</span><span class="cx"> #if WK_API_ENABLED
</span><span class="cx">     Class cls = m_webView.configuration._attachmentFileWrapperClass ?: [NSFileWrapper self];
</span><span class="lines">@@ -76,6 +76,17 @@
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+NSSet *PageClientImplCocoa::serializableFileWrapperClasses() const
+{
+    Class defaultFileWrapperClass = NSFileWrapper.self;
+#if WK_API_ENABLED
+    Class configuredFileWrapperClass = m_webView.configuration._attachmentFileWrapperClass;
+    if (configuredFileWrapperClass && configuredFileWrapperClass != defaultFileWrapperClass)
+        return [NSSet setWithObjects:configuredFileWrapperClass, defaultFileWrapperClass, nil];
</ins><span class="cx"> #endif
</span><ins>+    return [NSSet setWithObjects:defaultFileWrapperClass, nil];
+}
+
+#endif
</ins><span class="cx">     
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessPageClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/PageClient.h (237623 => 237624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/PageClient.h       2018-10-31 05:05:31 UTC (rev 237623)
+++ trunk/Source/WebKit/UIProcess/PageClient.h  2018-10-31 05:29:17 UTC (rev 237624)
</span><span class="lines">@@ -45,6 +45,7 @@
</span><span class="cx"> 
</span><span class="cx"> OBJC_CLASS CALayer;
</span><span class="cx"> OBJC_CLASS NSFileWrapper;
</span><ins>+OBJC_CLASS NSSet;
</ins><span class="cx"> OBJC_CLASS _WKRemoteObjectRegistry;
</span><span class="cx"> 
</span><span class="cx"> #if USE(APPKIT)
</span><span class="lines">@@ -445,7 +446,8 @@
</span><span class="cx">     virtual void didInsertAttachment(API::Attachment&, const String& source) { }
</span><span class="cx">     virtual void didRemoveAttachment(API::Attachment&) { }
</span><span class="cx"> #if PLATFORM(COCOA)
</span><del>-    virtual NSFileWrapper *allocFileWrapperInstance() { return nullptr; }
</del><ins>+    virtual NSFileWrapper *allocFileWrapperInstance() const { return nullptr; }
+    virtual NSSet *serializableFileWrapperClasses() const { return nullptr; }
</ins><span class="cx"> #endif
</span><span class="cx"> #endif
</span><span class="cx"> };
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessWebPageProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (237623 => 237624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp   2018-10-31 05:05:31 UTC (rev 237623)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp      2018-10-31 05:29:17 UTC (rev 237624)
</span><span class="lines">@@ -7900,6 +7900,15 @@
</span><span class="cx">         m_attachmentIdentifierToAttachmentMap.set(identifier, ensureAttachment(identifier));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebPageProxy::registerAttachmentsFromSerializedData(Vector<WebCore::SerializedAttachmentData>&& data)
+{
+    for (auto& serializedData : data) {
+        auto identifier = WTFMove(serializedData.identifier);
+        if (!attachmentForIdentifier(identifier))
+            ensureAttachment(identifier)->updateFromSerializedRepresentation(WTFMove(serializedData.data), WTFMove(serializedData.mimeType));
+    }
+}
+
</ins><span class="cx"> void WebPageProxy::cloneAttachmentData(const String& fromIdentifier, const String& toIdentifier)
</span><span class="cx"> {
</span><span class="cx">     auto newAttachment = ensureAttachment(toIdentifier);
</span><span class="lines">@@ -7925,6 +7934,21 @@
</span><span class="cx">     m_attachmentIdentifierToAttachmentMap.clear();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebPageProxy::serializedAttachmentDataForIdentifiers(const Vector<String>& identifiers, Vector<WebCore::SerializedAttachmentData>& serializedData)
+{
+    for (auto identifier : identifiers) {
+        auto attachment = attachmentForIdentifier(identifier);
+        if (!attachment)
+            continue;
+
+        auto data = attachment->createSerializedRepresentation();
+        if (!data)
+            continue;
+
+        serializedData.append({ identifier, attachment->mimeType(), data.releaseNonNull() });
+    }
+}
+
</ins><span class="cx"> #if !PLATFORM(COCOA)
</span><span class="cx"> 
</span><span class="cx"> void WebPageProxy::platformRegisterAttachment(Ref<API::Attachment>&&, const String&, const IPC::DataReference&)
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessWebPageProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (237623 => 237624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/WebPageProxy.h     2018-10-31 05:05:31 UTC (rev 237623)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h        2018-10-31 05:29:17 UTC (rev 237624)
</span><span class="lines">@@ -231,6 +231,7 @@
</span><span class="cx"> class RemoteLayerTreeTransaction;
</span><span class="cx"> class RemoteScrollingCoordinatorProxy;
</span><span class="cx"> class SecKeyProxyStore;
</span><ins>+class SharedBufferDataReference;
</ins><span class="cx"> class UserData;
</span><span class="cx"> class ViewSnapshot;
</span><span class="cx"> class VisitedLinkStore;
</span><span class="lines">@@ -1344,6 +1345,7 @@
</span><span class="cx">     RefPtr<API::Attachment> attachmentForIdentifier(const String& identifier) const;
</span><span class="cx">     void insertAttachment(Ref<API::Attachment>&&, Function<void(CallbackBase::Error)>&&);
</span><span class="cx">     void updateAttachmentAttributes(const API::Attachment&, Function<void(CallbackBase::Error)>&&);
</span><ins>+    void serializedAttachmentDataForIdentifiers(const Vector<String>&, Vector<WebCore::SerializedAttachmentData>&);
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(APPLICATION_MANIFEST)
</span><span class="lines">@@ -1829,6 +1831,7 @@
</span><span class="cx"> #if ENABLE(ATTACHMENT_ELEMENT)
</span><span class="cx">     void registerAttachmentIdentifierFromData(const String&, const String& contentType, const String& preferredFileName, const IPC::DataReference&);
</span><span class="cx">     void registerAttachmentIdentifierFromFilePath(const String&, const String& contentType, const String& filePath);
</span><ins>+    void registerAttachmentsFromSerializedData(Vector<WebCore::SerializedAttachmentData>&&);
</ins><span class="cx">     void registerAttachmentIdentifier(const String&);
</span><span class="cx">     void cloneAttachmentData(const String& fromIdentifier, const String& toIdentifier);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessWebPageProxymessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in (237623 => 237624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in   2018-10-31 05:05:31 UTC (rev 237623)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in      2018-10-31 05:29:17 UTC (rev 237624)
</span><span class="lines">@@ -534,9 +534,11 @@
</span><span class="cx">     RegisterAttachmentIdentifierFromData(String identifier, String contentType, String preferredFileName, IPC::SharedBufferDataReference data)
</span><span class="cx">     RegisterAttachmentIdentifierFromFilePath(String identifier, String contentType, String filePath)
</span><span class="cx">     RegisterAttachmentIdentifier(String identifier)
</span><ins>+    registerAttachmentsFromSerializedData(Vector<WebCore::SerializedAttachmentData> data)
</ins><span class="cx">     CloneAttachmentData(String fromIdentifier, String toIdentifier)
</span><span class="cx">     DidInsertAttachmentWithIdentifier(String identifier, String source, bool hasEnclosingImage)
</span><span class="cx">     DidRemoveAttachmentWithIdentifier(String identifier)
</span><ins>+    SerializedAttachmentDataForIdentifiers(Vector<String> identifiers) -> (Vector<WebCore::SerializedAttachmentData> seralizedData) LegacySync
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(MAC) && ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING)
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessWebCoreSupportWebEditorClientcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebEditorClient.cpp (237623 => 237624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebEditorClient.cpp        2018-10-31 05:05:31 UTC (rev 237623)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebEditorClient.cpp   2018-10-31 05:29:17 UTC (rev 237624)
</span><span class="lines">@@ -49,6 +49,7 @@
</span><span class="cx"> #include <WebCore/KeyboardEvent.h>
</span><span class="cx"> #include <WebCore/NotImplemented.h>
</span><span class="cx"> #include <WebCore/Page.h>
</span><ins>+#include <WebCore/SerializedAttachmentData.h>
</ins><span class="cx"> #include <WebCore/SpellChecker.h>
</span><span class="cx"> #include <WebCore/StyleProperties.h>
</span><span class="cx"> #include <WebCore/TextIterator.h>
</span><span class="lines">@@ -165,6 +166,11 @@
</span><span class="cx">     m_page->send(Messages::WebPageProxy::RegisterAttachmentIdentifierFromData(identifier, contentType, preferredFileName, { data }));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebEditorClient::registerAttachments(Vector<WebCore::SerializedAttachmentData>&& data)
+{
+    m_page->send(Messages::WebPageProxy::registerAttachmentsFromSerializedData(WTFMove(data)));
+}
+
</ins><span class="cx"> void WebEditorClient::registerAttachmentIdentifier(const String& identifier, const String& contentType, const String& filePath)
</span><span class="cx"> {
</span><span class="cx">     m_page->send(Messages::WebPageProxy::RegisterAttachmentIdentifierFromFilePath(identifier, contentType, filePath));
</span><span class="lines">@@ -190,6 +196,13 @@
</span><span class="cx">     m_page->send(Messages::WebPageProxy::DidRemoveAttachmentWithIdentifier(identifier));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+Vector<SerializedAttachmentData> WebEditorClient::serializedAttachmentDataForIdentifiers(const Vector<String>& identifiers)
+{
+    Vector<WebCore::SerializedAttachmentData> serializedData;
+    m_page->sendSync(Messages::WebPageProxy::SerializedAttachmentDataForIdentifiers(identifiers), Messages::WebPageProxy::SerializedAttachmentDataForIdentifiers::Reply(serializedData));
+    return serializedData;
+}
+
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> void WebEditorClient::didApplyStyle()
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessWebCoreSupportWebEditorClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebEditorClient.h (237623 => 237624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebEditorClient.h  2018-10-31 05:05:31 UTC (rev 237623)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebEditorClient.h     2018-10-31 05:29:17 UTC (rev 237624)
</span><span class="lines">@@ -63,10 +63,12 @@
</span><span class="cx">     void registerAttachmentIdentifier(const String&, const String& contentType, const String& preferredFileName, Ref<WebCore::SharedBuffer>&&) final;
</span><span class="cx">     void registerAttachmentIdentifier(const String&, const String& contentType, const String& filePath) final;
</span><span class="cx">     void registerAttachmentIdentifier(const String&) final;
</span><ins>+    void registerAttachments(Vector<WebCore::SerializedAttachmentData>&&) final;
</ins><span class="cx">     void cloneAttachmentData(const String& fromIdentifier, const String& toIdentifier) final;
</span><span class="cx">     void didInsertAttachmentWithIdentifier(const String& identifier, const String& source, bool hasEnclosingImage) final;
</span><span class="cx">     void didRemoveAttachmentWithIdentifier(const String& identifier) final;
</span><span class="cx">     bool supportsClientSideAttachmentData() const final { return true; }
</span><ins>+    Vector<WebCore::SerializedAttachmentData> serializedAttachmentDataForIdentifiers(const Vector<String>&) final;
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     void didBeginEditing() final;
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (237623 => 237624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog    2018-10-31 05:05:31 UTC (rev 237623)
+++ trunk/Tools/ChangeLog       2018-10-31 05:29:17 UTC (rev 237624)
</span><span class="lines">@@ -1,3 +1,21 @@
</span><ins>+2018-10-30  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [Cocoa] Attachment dropped from one web view to another is missing its file wrapper
+        https://bugs.webkit.org/show_bug.cgi?id=190530
+        <rdar://problem/45232149>
+
+        Reviewed by Tim Horton.
+
+        Add a test to verify that copying different types of attachments and pasting in a new web view inserts
+        attachments in the second web view that are backed by _WKAttachment objects, whose NSFileWrappers hold data that
+        is equivalent to the original file wrappers used to insert attachments in the first web view.
+
+        Existing API tests verify that when copying and pasting within a single web view, the pasted attachment element
+        is still backed by the same NSFileWrapper instance.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
+        (TestWebKitAPI::TEST):
+
</ins><span class="cx"> 2018-10-30  Fujii Hironori  <Hironori.Fujii@sony.com>
</span><span class="cx"> 
</span><span class="cx">         [Win] Remove obsolete code for Visual Studio Express in webkitdirs.pm
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKitCocoaWKAttachmentTestsmm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm (237623 => 237624)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm 2018-10-31 05:05:31 UTC (rev 237623)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm    2018-10-31 05:29:17 UTC (rev 237624)
</span><span class="lines">@@ -1462,6 +1462,52 @@
</span><span class="cx">     EXPECT_EQ([FileWrapper self], [insertedAttachments.firstObject.info.fileWrapper class]);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+TEST(WKAttachmentTests, CopyAndPasteBetweenWebViews)
+{
+    auto file = adoptNS([[NSFileWrapper alloc] initRegularFileWithContents:testHTMLData()]);
+    [file setPreferredFilename:@"test.foobar"];
+    auto image = adoptNS([[NSFileWrapper alloc] initRegularFileWithContents:testImageData()]);
+    auto document = adoptNS([[NSFileWrapper alloc] initRegularFileWithContents:testPDFData()]);
+    auto folder = adoptNS([[NSFileWrapper alloc] initDirectoryWithFileWrappers:@{ @"image.png": image.get(), @"document.pdf": document.get() }]);
+    [folder setPreferredFilename:@"folder"];
+    auto archive = adoptNS([[NSFileWrapper alloc] initRegularFileWithContents:testZIPData()]);
+    [archive setPreferredFilename:@"archive"];
+
+    @autoreleasepool {
+        auto firstWebView = webViewForTestingAttachments();
+        [firstWebView synchronouslyInsertAttachmentWithFileWrapper:file.get() contentType:@"application/octet-stream"];
+        [firstWebView synchronouslyInsertAttachmentWithFileWrapper:folder.get() contentType:(__bridge NSString *)kUTTypeFolder];
+        [firstWebView synchronouslyInsertAttachmentWithFileWrapper:archive.get() contentType:@"application/zip"];
+        [firstWebView selectAll:nil];
+        [firstWebView _executeEditCommand:@"Copy" argument:nil completion:nil];
+    }
+
+    auto secondWebView = webViewForTestingAttachments();
+    ObserveAttachmentUpdatesForScope observer(secondWebView.get());
+    [secondWebView paste:nil];
+    [secondWebView expectElementCount:3 tagName:@"attachment"];
+    EXPECT_EQ(3U, observer.observer().inserted.count);
+
+    NSString *plainFileIdentifier = [secondWebView stringByEvaluatingJavaScript:@"document.querySelector('attachment[title^=test]').uniqueIdentifier"];
+    NSString *folderIdentifier = [secondWebView stringByEvaluatingJavaScript:@"document.querySelector('attachment[title=folder]').uniqueIdentifier"];
+    NSString *archiveIdentifier = [secondWebView stringByEvaluatingJavaScript:@"document.querySelector('attachment[title=archive]').uniqueIdentifier"];
+
+    _WKAttachmentInfo *pastedFileInfo = [secondWebView _attachmentForIdentifier:plainFileIdentifier].info;
+    _WKAttachmentInfo *pastedFolderInfo = [secondWebView _attachmentForIdentifier:folderIdentifier].info;
+    _WKAttachmentInfo *pastedArchiveInfo = [secondWebView _attachmentForIdentifier:archiveIdentifier].info;
+
+    NSDictionary<NSString *, NSFileWrapper *> *pastedFolderContents = pastedFolderInfo.fileWrapper.fileWrappers;
+    NSFileWrapper *documentFromFolder = [pastedFolderContents objectForKey:@"document.pdf"];
+    NSFileWrapper *imageFromFolder = [pastedFolderContents objectForKey:@"image.png"];
+    EXPECT_TRUE([[document regularFileContents] isEqualToData:documentFromFolder.regularFileContents]);
+    EXPECT_TRUE([[image regularFileContents] isEqualToData:imageFromFolder.regularFileContents]);
+    EXPECT_TRUE([[file regularFileContents] isEqualToData:pastedFileInfo.fileWrapper.regularFileContents]);
+    EXPECT_TRUE([[archive regularFileContents] isEqualToData:pastedArchiveInfo.fileWrapper.regularFileContents]);
+    EXPECT_WK_STREQ("application/octet-stream", pastedFileInfo.contentType);
+    EXPECT_WK_STREQ("public.directory", pastedFolderInfo.contentType);
+    EXPECT_WK_STREQ("application/zip", pastedArchiveInfo.contentType);
+}
+
</ins><span class="cx"> #pragma mark - Platform-specific tests
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(MAC)
</span></span></pre>
</div>
</div>

</body>
</html>