|
| 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 | + |
1 | 137 | 2018-01-03 Ting-Wei Lan < [email protected]>
|
2 | 138 |
|
3 | 139 | Replace hard-coded paths in shebangs with #!/usr/bin/env
|
|
0 commit comments