Skip to content

Commit 401506d

Browse files
[Attachment Support] Create attachment elements when dropping files on iOS
https://bugs.webkit.org/show_bug.cgi?id=181192 <rdar://problem/36280945> Reviewed by Tim Horton. Source/WebCore: Implements support for dropping data as attachment elements on iOS. See comments below for more detail. Tests: WKAttachmentTests.InsertDroppedRichAndPlainTextFilesAsAttachments WKAttachmentTests.InsertDroppedZipArchiveAsAttachment WKAttachmentTests.InsertDroppedItemProvidersInOrder * WebCore.xcodeproj/project.pbxproj: * editing/WebContentReader.cpp: (WebCore::WebContentReader::ensureFragment): Add a new helper to create the WebContentReader's fragment, if it hasn't already been created. * editing/WebContentReader.h: * editing/cocoa/WebContentReaderCocoa.mm: (WebCore::WebContentReader::readFilePaths): Rename readFilenames to readFilePaths (which better reflects its parameters, which are file paths). Also, move the implementation of readFilePaths to shared iOS/macOS code in WebContentReaderCocoa, and remove the stub implementation on iOS. There's a bit of code here that I kept macOS-only which deals with inserting file paths as plain text in editable areas, but it's unclear to me why and if WebKit clients currently find this useful, so I left a FIXME to investigate removing this altogether. Code for handling this plain text insertion of file paths on Mac was introduced in r67403. * editing/ios/WebContentReaderIOS.mm: (WebCore::WebContentReader::readFilenames): Deleted. * editing/mac/WebContentReaderMac.mm: (WebCore::WebContentReader::readFilenames): Deleted. * page/mac/DragControllerMac.mm: (WebCore::DragController::updateSupportedTypeIdentifiersForDragHandlingMethod const): Teach DragController to accept all types conforming to "public.item" and "public.content" on iOS, only when attachment elements are enabled. This allows us to load content from item providers that we otherwise would not have loaded, since we now have the ability to fall back to attachment element insertion if the type is not have a default representation using standard web content. * platform/Pasteboard.h: * platform/PasteboardItemInfo.h: Added. (WebCore::PasteboardItemInfo::encode const): (WebCore::PasteboardItemInfo::decode): Add PasteboardItemInfo, a struct that describes an item on the pasteboard. Also, implement encoding and decoding support for PasteboardItemInfo. So far, the item info only describes file information about the pasteboard item, and flags indicating whether the item prefers attachment or inline presentation. * platform/PasteboardStrategy.h: Replace getFilenamesForDataInteraction with informationForItemAtIndex. Instead of returning all of the file paths associated with any item on the pasteboard, fetch a PasteboardItemInfo at a given item index, which includes information about the file path as well as some other metadata we'll need when deciding how to read pasteboard contents as a document fragment. * platform/PlatformPasteboard.h: * platform/cocoa/PasteboardCocoa.mm: (WebCore::Pasteboard::read): * platform/ios/AbstractPasteboard.h: * platform/ios/PasteboardIOS.mm: (WebCore::Pasteboard::read): (WebCore::Pasteboard::readRespectingUTIFidelities): Teach the iOS Pasteboard to read web content using attachment elements, if enabled. There are two scenarios in which we would want to insert an attachment element: (1) The item provider uses a preferred presentation style of attachment, in which case we bail out of trying to handle the drop using the default mechanisms, and simply insert it as an attachment. We need this to deal with the case where we drop text or HTML files from the Files app, so that we don't try and insert the contents of the text or HTML as inline web content. (2) The item provider doesn't have a preferred attachment presentation style, but there's nothing WebKit would otherwise do with the dropped content, so insert an attachment element as a fallback. Examples where this is relevant are dropping a PDF or ZIP archive without attachment presentation style explicitly set. We first check if we fall into case (1). If so, we can bail early by inserting an attachment; otherwise, we proceed normally and see if we can read the contents of the drop as web content. If, at the end of default drop handling, we don't still have a way to represent the dropped content, enter case (2). (WebCore::Pasteboard::readFilePaths): (WebCore::Pasteboard::readFilenames): Deleted. Rename readFilenames to readFilePaths, and reimplement it using informationForItemAtIndex. * platform/ios/PlatformPasteboardIOS.mm: (WebCore::pasteboardItemPresentationStyle): (WebCore::PlatformPasteboard::informationForItemAtIndex): (WebCore::PlatformPasteboard::filenamesForDataInteraction): Deleted. Implement informationForItemAtIndex and remove filenamesForDataInteraction. As before, we ask the pasteboard (i.e. WebItemProviderPasteboard) for information about dropped file URLs. This time, we limit this to a single file, so we don't end up creating multiple attachment elements for each representation of a single item provider. See below for -preferredFileUploadURLAtIndex:fileType: for more detail. * platform/ios/WebItemProviderPasteboard.h: * platform/ios/WebItemProviderPasteboard.mm: (-[WebItemProviderLoadResult initWithItemProvider:typesToLoad:]): (-[WebItemProviderLoadResult canBeRepresentedAsFileUpload]): Remove this synthesized instance variable and instead just check the item provider's preferredPresentationStyle. (-[WebItemProviderLoadResult description]): Add a verbose -description to the load result object. Useful for debugging what was content was loaded from an item provider on drop. (-[WebItemProviderPasteboard preferredFileUploadURLAtIndex:fileType:]): Return the highest fidelity loaded type identifier for a given item. (-[WebItemProviderPasteboard allDroppedFileURLs]): (-[WebItemProviderPasteboard typeIdentifiersToLoadForRegisteredTypeIdentfiers:]): Prefer flat RTFD to RTFD. In the case where attachments are enabled and we're accepting all types of content using attachment elements as a fallback representation, if the source writes attributed strings to the pasteboard with com.apple.rtfd at a higher fidelity than com.apple.flat-rtfd, we'll end up loading only com.apple.rtfd and dropping the text as an attachment element because we cannot convert the dropped content to markup. Instead, if flat RTFD is present in the item provider, always prefer that over RTFD so that dropping as regular web content isn't overridden when attachment elements are enabled. (-[WebItemProviderPasteboard doAfterLoadingProvidedContentIntoFileURLs:synchronousTimeout:]): (-[WebItemProviderPasteboard droppedFileURLs]): Deleted. * platform/mac/DragDataMac.mm: (WebCore::DragData::containsCompatibleContent const): DragData::containsCompatibleContent should be true when attachment elements are enabled, and there are files we can drop as attachment elements. * platform/mac/PasteboardMac.mm: (WebCore::Pasteboard::read): (WebCore::Pasteboard::readFilePaths): (WebCore::Pasteboard::readFilenames): Deleted. Source/WebKit: Make some minor adjustments for changes to the pasteboard in WebCore. See WebCore/ChangeLog for more detail. Teaches WebPasteboardProxy et. al. to plumb PasteboardItemInfo from the UI process to the web process via the new `InformationForItemAtIndex` codepath. * UIProcess/Cocoa/WebPasteboardProxyCocoa.mm: (WebKit::WebPasteboardProxy::informationForItemAtIndex): (WebKit::WebPasteboardProxy::getFilenamesForDataInteraction): Deleted. * UIProcess/WebPasteboardProxy.h: * UIProcess/WebPasteboardProxy.messages.in: * WebProcess/WebCoreSupport/WebPlatformStrategies.cpp: (WebKit::WebPlatformStrategies::informationForItemAtIndex): (WebKit::WebPlatformStrategies::getFilenamesForDataInteraction): Deleted. * WebProcess/WebCoreSupport/WebPlatformStrategies.h: Source/WebKitLegacy/mac: Make some minor adjustments for changes to the pasteboard in WebCore. See WebCore/ChangeLog for more detail. * WebCoreSupport/WebPlatformStrategies.h: * WebCoreSupport/WebPlatformStrategies.mm: (WebPlatformStrategies::informationForItemAtIndex): (WebPlatformStrategies::getFilenamesForDataInteraction): Deleted. Tools: Adds 3 new API tests to exercise different use cases of dropping content as attachment elements when the runtime switch is enabled. See below for more details. * TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm: (-[NSItemProvider registerData:type:]): (platformCopyPNG): (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/ios/DataInteractionTests.mm: Fix some currently failing iOS drag and drop tests. In this case, there's no reason RTFD should appear in the source item provider when dragging rich text *without* attachments, so this should have been a check for just kUTTypeRTF instead. (TestWebKitAPI::TEST): Tests a few cases of inserting attachment elements via drop: 1. We should distinguish between drops containing rich/plain text files from just dropping rich/plain text. Instead of inserting the contents as inline web content, this should generate attachment elements. 2. Test the fallback mechanism for inserting attachment elements. If the preferred presentation style is not explicitly set, but there's nothing WebKit would otherwise do with the dropped content, then we should fall back to inserting the content as an attachment. 3. Test that if multiple attachments and inline item providers are present, WebKit will respect the order in which they were inserted by the source (as opposed to, for instance, putting all of the attachments in front or at the end). * TestWebKitAPI/cocoa/TestWKWebView.h: * TestWebKitAPI/cocoa/TestWKWebView.mm: (-[TestWKWebView objectByEvaluatingJavaScript:]): Add a helper method to return an object that represents the result of evaluating some given script, and rewrite -stringByEvaluatingJavaScript to just turn around and call this. (-[TestWKWebView stringByEvaluatingJavaScript:]): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@226396 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 026ee04 commit 401506d

34 files changed

+669
-101
lines changed

Source/WebCore/ChangeLog

+136
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,139 @@
1+
2018-01-03 Wenson Hsieh <[email protected]>
2+
3+
[Attachment Support] Create attachment elements when dropping files on iOS
4+
https://bugs.webkit.org/show_bug.cgi?id=181192
5+
<rdar://problem/36280945>
6+
7+
Reviewed by Tim Horton.
8+
9+
Implements support for dropping data as attachment elements on iOS. See comments below for more detail.
10+
11+
Tests: WKAttachmentTests.InsertDroppedRichAndPlainTextFilesAsAttachments
12+
WKAttachmentTests.InsertDroppedZipArchiveAsAttachment
13+
WKAttachmentTests.InsertDroppedItemProvidersInOrder
14+
15+
* WebCore.xcodeproj/project.pbxproj:
16+
* editing/WebContentReader.cpp:
17+
(WebCore::WebContentReader::ensureFragment):
18+
19+
Add a new helper to create the WebContentReader's fragment, if it hasn't already been created.
20+
21+
* editing/WebContentReader.h:
22+
* editing/cocoa/WebContentReaderCocoa.mm:
23+
(WebCore::WebContentReader::readFilePaths):
24+
25+
Rename readFilenames to readFilePaths (which better reflects its parameters, which are file paths). Also, move
26+
the implementation of readFilePaths to shared iOS/macOS code in WebContentReaderCocoa, and remove the stub
27+
implementation on iOS.
28+
29+
There's a bit of code here that I kept macOS-only which deals with inserting file paths as plain text in
30+
editable areas, but it's unclear to me why and if WebKit clients currently find this useful, so I left a FIXME
31+
to investigate removing this altogether. Code for handling this plain text insertion of file paths on Mac was
32+
introduced in r67403.
33+
34+
* editing/ios/WebContentReaderIOS.mm:
35+
(WebCore::WebContentReader::readFilenames): Deleted.
36+
* editing/mac/WebContentReaderMac.mm:
37+
(WebCore::WebContentReader::readFilenames): Deleted.
38+
* page/mac/DragControllerMac.mm:
39+
(WebCore::DragController::updateSupportedTypeIdentifiersForDragHandlingMethod const):
40+
41+
Teach DragController to accept all types conforming to "public.item" and "public.content" on iOS, only when
42+
attachment elements are enabled. This allows us to load content from item providers that we otherwise would not
43+
have loaded, since we now have the ability to fall back to attachment element insertion if the type is not have
44+
a default representation using standard web content.
45+
46+
* platform/Pasteboard.h:
47+
* platform/PasteboardItemInfo.h: Added.
48+
(WebCore::PasteboardItemInfo::encode const):
49+
(WebCore::PasteboardItemInfo::decode):
50+
51+
Add PasteboardItemInfo, a struct that describes an item on the pasteboard. Also, implement encoding and decoding
52+
support for PasteboardItemInfo. So far, the item info only describes file information about the pasteboard item,
53+
and flags indicating whether the item prefers attachment or inline presentation.
54+
55+
* platform/PasteboardStrategy.h:
56+
57+
Replace getFilenamesForDataInteraction with informationForItemAtIndex. Instead of returning all of the file
58+
paths associated with any item on the pasteboard, fetch a PasteboardItemInfo at a given item index, which
59+
includes information about the file path as well as some other metadata we'll need when deciding how to read
60+
pasteboard contents as a document fragment.
61+
62+
* platform/PlatformPasteboard.h:
63+
* platform/cocoa/PasteboardCocoa.mm:
64+
(WebCore::Pasteboard::read):
65+
* platform/ios/AbstractPasteboard.h:
66+
* platform/ios/PasteboardIOS.mm:
67+
(WebCore::Pasteboard::read):
68+
(WebCore::Pasteboard::readRespectingUTIFidelities):
69+
70+
Teach the iOS Pasteboard to read web content using attachment elements, if enabled. There are two scenarios in
71+
which we would want to insert an attachment element:
72+
(1) The item provider uses a preferred presentation style of attachment, in which case we bail out of trying to
73+
handle the drop using the default mechanisms, and simply insert it as an attachment. We need this to deal
74+
with the case where we drop text or HTML files from the Files app, so that we don't try and insert the
75+
contents of the text or HTML as inline web content.
76+
(2) The item provider doesn't have a preferred attachment presentation style, but there's nothing WebKit would
77+
otherwise do with the dropped content, so insert an attachment element as a fallback. Examples where this is
78+
relevant are dropping a PDF or ZIP archive without attachment presentation style explicitly set.
79+
We first check if we fall into case (1). If so, we can bail early by inserting an attachment; otherwise, we
80+
proceed normally and see if we can read the contents of the drop as web content. If, at the end of default drop
81+
handling, we don't still have a way to represent the dropped content, enter case (2).
82+
83+
(WebCore::Pasteboard::readFilePaths):
84+
(WebCore::Pasteboard::readFilenames): Deleted.
85+
86+
Rename readFilenames to readFilePaths, and reimplement it using informationForItemAtIndex.
87+
88+
* platform/ios/PlatformPasteboardIOS.mm:
89+
(WebCore::pasteboardItemPresentationStyle):
90+
(WebCore::PlatformPasteboard::informationForItemAtIndex):
91+
(WebCore::PlatformPasteboard::filenamesForDataInteraction): Deleted.
92+
93+
Implement informationForItemAtIndex and remove filenamesForDataInteraction. As before, we ask the pasteboard
94+
(i.e. WebItemProviderPasteboard) for information about dropped file URLs. This time, we limit this to a single
95+
file, so we don't end up creating multiple attachment elements for each representation of a single item
96+
provider. See below for -preferredFileUploadURLAtIndex:fileType: for more detail.
97+
98+
* platform/ios/WebItemProviderPasteboard.h:
99+
* platform/ios/WebItemProviderPasteboard.mm:
100+
(-[WebItemProviderLoadResult initWithItemProvider:typesToLoad:]):
101+
(-[WebItemProviderLoadResult canBeRepresentedAsFileUpload]):
102+
103+
Remove this synthesized instance variable and instead just check the item provider's preferredPresentationStyle.
104+
105+
(-[WebItemProviderLoadResult description]):
106+
107+
Add a verbose -description to the load result object. Useful for debugging what was content was loaded from an
108+
item provider on drop.
109+
110+
(-[WebItemProviderPasteboard preferredFileUploadURLAtIndex:fileType:]):
111+
112+
Return the highest fidelity loaded type identifier for a given item.
113+
114+
(-[WebItemProviderPasteboard allDroppedFileURLs]):
115+
(-[WebItemProviderPasteboard typeIdentifiersToLoadForRegisteredTypeIdentfiers:]):
116+
117+
Prefer flat RTFD to RTFD. In the case where attachments are enabled and we're accepting all types of content
118+
using attachment elements as a fallback representation, if the source writes attributed strings to the
119+
pasteboard with com.apple.rtfd at a higher fidelity than com.apple.flat-rtfd, we'll end up loading only
120+
com.apple.rtfd and dropping the text as an attachment element because we cannot convert the dropped content to
121+
markup. Instead, if flat RTFD is present in the item provider, always prefer that over RTFD so that dropping as
122+
regular web content isn't overridden when attachment elements are enabled.
123+
124+
(-[WebItemProviderPasteboard doAfterLoadingProvidedContentIntoFileURLs:synchronousTimeout:]):
125+
(-[WebItemProviderPasteboard droppedFileURLs]): Deleted.
126+
* platform/mac/DragDataMac.mm:
127+
(WebCore::DragData::containsCompatibleContent const):
128+
129+
DragData::containsCompatibleContent should be true when attachment elements are enabled, and there are files we
130+
can drop as attachment elements.
131+
132+
* platform/mac/PasteboardMac.mm:
133+
(WebCore::Pasteboard::read):
134+
(WebCore::Pasteboard::readFilePaths):
135+
(WebCore::Pasteboard::readFilenames): Deleted.
136+
1137
2018-01-03 Ting-Wei Lan <[email protected]>
2138

3139
Replace hard-coded paths in shebangs with #!/usr/bin/env

Source/WebCore/WebCore.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -4653,6 +4653,7 @@
46534653
F48223101E3869B80066FC79 /* WebItemProviderPasteboard.mm in Sources */ = {isa = PBXBuildFile; fileRef = F482230E1E3869B80066FC79 /* WebItemProviderPasteboard.mm */; };
46544654
F48223111E3869B80066FC79 /* WebItemProviderPasteboard.h in Headers */ = {isa = PBXBuildFile; fileRef = F482230F1E3869B80066FC79 /* WebItemProviderPasteboard.h */; settings = {ATTRIBUTES = (Private, ); }; };
46554655
F48223131E386E240066FC79 /* AbstractPasteboard.h in Headers */ = {isa = PBXBuildFile; fileRef = F48223121E386E240066FC79 /* AbstractPasteboard.h */; settings = {ATTRIBUTES = (Private, ); }; };
4656+
F49786881FF45FA500E060AB /* PasteboardItemInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = F49786871FF45FA500E060AB /* PasteboardItemInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
46564657
F4BFB9851E1DDF9B00862C24 /* DumpEditingHistory.js in Copy Scripts */ = {isa = PBXBuildFile; fileRef = F48389831E1DDF2B0076B7EA /* DumpEditingHistory.js */; };
46574658
F4BFB9861E1DDF9B00862C24 /* EditingHistoryUtil.js in Copy Scripts */ = {isa = PBXBuildFile; fileRef = F48389841E1DDF2B0076B7EA /* EditingHistoryUtil.js */; };
46584659
F50664F8157F52DC00AC226F /* FormController.h in Headers */ = {isa = PBXBuildFile; fileRef = F50664F6157F52DC00AC226F /* FormController.h */; };
@@ -14086,6 +14087,7 @@
1408614087
F48223121E386E240066FC79 /* AbstractPasteboard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AbstractPasteboard.h; sourceTree = "<group>"; };
1408714088
F48389831E1DDF2B0076B7EA /* DumpEditingHistory.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = DumpEditingHistory.js; path = Scripts/DumpEditingHistory.js; sourceTree = "<group>"; };
1408814089
F48389841E1DDF2B0076B7EA /* EditingHistoryUtil.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = EditingHistoryUtil.js; path = Scripts/EditingHistoryUtil.js; sourceTree = "<group>"; };
14090+
F49786871FF45FA500E060AB /* PasteboardItemInfo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PasteboardItemInfo.h; sourceTree = "<group>"; };
1408914091
F50664F5157F52DC00AC226F /* FormController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FormController.cpp; sourceTree = "<group>"; };
1409014092
F50664F6157F52DC00AC226F /* FormController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FormController.h; sourceTree = "<group>"; };
1409114093
F513A3E915FF4841001526DB /* ValidationMessageClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ValidationMessageClient.h; sourceTree = "<group>"; };
@@ -23691,6 +23693,7 @@
2369123693
4184F5151EAF059800F18BF0 /* OrientationNotifier.h */,
2369223694
2EE02A1E1F7324280006AF72 /* Pasteboard.cpp */,
2369323695
4B2708C50AF19EE40065127F /* Pasteboard.h */,
23696+
F49786871FF45FA500E060AB /* PasteboardItemInfo.h */,
2369423697
C5F765B414E1D414006C899B /* PasteboardStrategy.h */,
2369523698
1AF5E4D21E56735A004A1F01 /* PasteboardWriterData.cpp */,
2369623699
1AF5E4D31E56735A004A1F01 /* PasteboardWriterData.h */,
@@ -28690,6 +28693,7 @@
2869028693
536D5A23193E8E0C00CE4CAB /* ParsingUtilities.h in Headers */,
2869128694
F55B3DCA1251F12D003EF269 /* PasswordInputType.h in Headers */,
2869228695
4B2708C70AF19EE40065127F /* Pasteboard.h in Headers */,
28696+
F49786881FF45FA500E060AB /* PasteboardItemInfo.h in Headers */,
2869328697
C598905714E9C28000E8D18B /* PasteboardStrategy.h in Headers */,
2869428698
1AF5E4E31E5779B1004A1F01 /* PasteboardWriter.h in Headers */,
2869528699
1AF5E4D51E56735B004A1F01 /* PasteboardWriterData.h in Headers */,

Source/WebCore/editing/WebContentReader.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131

3232
namespace WebCore {
3333

34+
DocumentFragment& WebContentReader::ensureFragment()
35+
{
36+
ASSERT(frame.document());
37+
if (!fragment)
38+
fragment = frame.document()->createDocumentFragment();
39+
return *fragment;
40+
}
41+
3442
void WebContentReader::addFragment(Ref<DocumentFragment>&& newFragment)
3543
{
3644
if (!fragment)

Source/WebCore/editing/WebContentReader.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,13 @@ class WebContentReader final : public FrameWebContentReader {
6363
{
6464
}
6565

66+
DocumentFragment& ensureFragment();
6667
void addFragment(Ref<DocumentFragment>&&);
6768

6869
private:
6970
#if PLATFORM(COCOA)
7071
bool readWebArchive(SharedBuffer&) override;
71-
bool readFilenames(const Vector<String>&) override;
72+
bool readFilePaths(const Vector<String>&) override;
7273
bool readHTML(const String&) override;
7374
bool readRTFD(SharedBuffer&) override;
7475
bool readRTF(SharedBuffer&) override;
@@ -90,7 +91,7 @@ class WebContentMarkupReader final : public FrameWebContentReader {
9091
private:
9192
#if PLATFORM(COCOA)
9293
bool readWebArchive(SharedBuffer&) override;
93-
bool readFilenames(const Vector<String>&) override { return false; }
94+
bool readFilePaths(const Vector<String>&) override { return false; }
9495
bool readHTML(const String&) override;
9596
bool readRTFD(SharedBuffer&) override;
9697
bool readRTF(SharedBuffer&) override;

Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm

+30
Original file line numberDiff line numberDiff line change
@@ -596,4 +596,34 @@ static String stripMicrosoftPrefix(const String& string)
596596
return fragment;
597597
}
598598

599+
bool WebContentReader::readFilePaths(const Vector<String>& paths)
600+
{
601+
if (paths.isEmpty() || !frame.document())
602+
return false;
603+
604+
auto& document = *frame.document();
605+
bool readAnyFilePath = false;
606+
for (auto& path : paths) {
607+
#if ENABLE(ATTACHMENT_ELEMENT)
608+
if (RuntimeEnabledFeatures::sharedFeatures().attachmentElementEnabled()) {
609+
auto attachment = HTMLAttachmentElement::create(HTMLNames::attachmentTag, document);
610+
attachment->setUniqueIdentifier(createCanonicalUUIDString());
611+
attachment->setFile(File::create(path), HTMLAttachmentElement::UpdateDisplayAttributes::Yes);
612+
ensureFragment().appendChild(attachment);
613+
readAnyFilePath = true;
614+
continue;
615+
}
616+
#endif
617+
#if PLATFORM(MAC)
618+
// FIXME: Does (and should) any macOS client depend on inserting file paths as plain text in web content?
619+
// If not, we should just remove this.
620+
auto paragraph = createDefaultParagraphElement(document);
621+
paragraph->appendChild(document.createTextNode(userVisibleString([NSURL fileURLWithPath:path])));
622+
ensureFragment().appendChild(paragraph);
623+
readAnyFilePath = true;
624+
#endif
625+
}
626+
return readAnyFilePath;
627+
}
628+
599629
}

Source/WebCore/editing/ios/WebContentReaderIOS.mm

-5
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@
4747

4848
namespace WebCore {
4949

50-
bool WebContentReader::readFilenames(const Vector<String>&)
51-
{
52-
return false;
53-
}
54-
5550
bool WebContentReader::readURL(const URL& url, const String& title)
5651
{
5752
if (url.isEmpty())

Source/WebCore/editing/mac/WebContentReaderMac.mm

-34
Original file line numberDiff line numberDiff line change
@@ -38,49 +38,15 @@
3838
#import "FrameLoader.h"
3939
#import "FrameLoaderClient.h"
4040
#import "HTMLAnchorElement.h"
41-
#import "HTMLAttachmentElement.h"
4241
#import "HTMLNames.h"
4342
#import "LegacyWebArchive.h"
44-
#import "MIMETypeRegistry.h"
45-
#import "RuntimeEnabledFeatures.h"
4643
#import "Settings.h"
4744
#import "Text.h"
4845
#import "WebCoreNSURLExtras.h"
4946
#import "markup.h"
50-
#import <wtf/UUID.h>
5147

5248
namespace WebCore {
5349

54-
bool WebContentReader::readFilenames(const Vector<String>& paths)
55-
{
56-
if (paths.isEmpty())
57-
return false;
58-
59-
if (!frame.document())
60-
return false;
61-
Document& document = *frame.document();
62-
63-
fragment = document.createDocumentFragment();
64-
65-
for (auto& text : paths) {
66-
#if ENABLE(ATTACHMENT_ELEMENT)
67-
if (RuntimeEnabledFeatures::sharedFeatures().attachmentElementEnabled()) {
68-
auto attachment = HTMLAttachmentElement::create(HTMLNames::attachmentTag, document);
69-
attachment->setUniqueIdentifier(createCanonicalUUIDString());
70-
attachment->setFile(File::create([NSURL fileURLWithPath:text].path), HTMLAttachmentElement::UpdateDisplayAttributes::Yes);
71-
fragment->appendChild(attachment);
72-
continue;
73-
}
74-
#else
75-
auto paragraph = createDefaultParagraphElement(document);
76-
paragraph->appendChild(document.createTextNode(userVisibleString([NSURL fileURLWithPath:text])));
77-
fragment->appendChild(paragraph);
78-
#endif
79-
}
80-
81-
return true;
82-
}
83-
8450
bool WebContentReader::readURL(const URL& url, const String& title)
8551
{
8652
if (url.string().isEmpty())

Source/WebCore/page/mac/DragControllerMac.mm

+9-2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#import "PasteboardStrategy.h"
4646
#import "PlatformStrategies.h"
4747
#import "Range.h"
48+
#import "RuntimeEnabledFeatures.h"
4849

4950
#if ENABLE(DATA_INTERACTION)
5051
#import <MobileCoreServices/MobileCoreServices.h>
@@ -125,8 +126,14 @@
125126
supportedTypes.append(kUTTypePlainText);
126127
break;
127128
case DragHandlingMethod::EditRichText:
128-
for (NSString *type in Pasteboard::supportedWebContentPasteboardTypes())
129-
supportedTypes.append(type);
129+
if (RuntimeEnabledFeatures::sharedFeatures().attachmentElementEnabled()) {
130+
supportedTypes.append(WebArchivePboardType);
131+
supportedTypes.append(kUTTypeContent);
132+
supportedTypes.append(kUTTypeItem);
133+
} else {
134+
for (NSString *type in Pasteboard::supportedWebContentPasteboardTypes())
135+
supportedTypes.append(type);
136+
}
130137
break;
131138
default:
132139
for (NSString *type in Pasteboard::supportedFileUploadPasteboardTypes())

Source/WebCore/platform/Pasteboard.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#pragma once
2727

2828
#include "DragImage.h"
29+
#include "PasteboardItemInfo.h"
2930
#include "URL.h"
3031
#include <wtf/HashMap.h>
3132
#include <wtf/ListHashSet.h>
@@ -134,7 +135,7 @@ class PasteboardWebContentReader {
134135

135136
#if PLATFORM(COCOA)
136137
virtual bool readWebArchive(SharedBuffer&) = 0;
137-
virtual bool readFilenames(const Vector<String>&) = 0;
138+
virtual bool readFilePaths(const Vector<String>&) = 0;
138139
virtual bool readHTML(const String&) = 0;
139140
virtual bool readRTFD(SharedBuffer&) = 0;
140141
virtual bool readRTF(SharedBuffer&) = 0;
@@ -290,7 +291,7 @@ class Pasteboard {
290291
#endif
291292

292293
#if PLATFORM(COCOA)
293-
Vector<String> readFilenames();
294+
Vector<String> readFilePaths();
294295
String readPlatformValueAsString(const String& domType, long changeCount, const String& pasteboardName);
295296
static void addHTMLClipboardTypesForCocoaType(ListHashSet<String>& resultTypes, const String& cocoaType);
296297
String readStringForPlatformType(const String&);

0 commit comments

Comments
 (0)