Changeset 222595 in webkit
- Timestamp:
- Sep 27, 2017, 7:29:16 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 18 added
- 60 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r222594 r222595 1 2017-09-27 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 Drag event DataTransfer has unexpected types "dyn.ah62d4..." 4 https://bugs.webkit.org/show_bug.cgi?id=172526 5 <rdar://problem/32396081> 6 7 Reviewed by Ryosuke Niwa. 8 9 Add new layout tests on Mac and iOS to test various cases of using DataTransfer.setData, DataTransfer.getData, 10 and DataTransfer.types for drag-and-drop (tests for Mac WK1 only) and copy-and-paste (all platforms). 11 12 * TestExpectations: 13 * editing/pasteboard/data-transfer-get-data-on-drop-custom-expected.txt: Added. 14 * editing/pasteboard/data-transfer-get-data-on-drop-custom.html: Added. 15 * editing/pasteboard/data-transfer-get-data-on-drop-plain-text-expected.txt: Added. 16 * editing/pasteboard/data-transfer-get-data-on-drop-plain-text.html: Added. 17 * editing/pasteboard/data-transfer-get-data-on-drop-rich-text-expected.txt: Added. 18 * editing/pasteboard/data-transfer-get-data-on-drop-rich-text.html: Added. 19 * editing/pasteboard/data-transfer-get-data-on-drop-url-expected.txt: Added. 20 * editing/pasteboard/data-transfer-get-data-on-drop-url.html: Added. 21 * editing/pasteboard/data-transfer-get-data-on-paste-custom-expected.txt: Added. 22 * editing/pasteboard/data-transfer-get-data-on-paste-custom.html: Added. 23 * editing/pasteboard/data-transfer-get-data-on-paste-plain-text-expected.txt: Added. 24 * editing/pasteboard/data-transfer-get-data-on-paste-plain-text.html: Added. 25 * editing/pasteboard/data-transfer-get-data-on-paste-rich-text-expected.txt: Added. 26 * editing/pasteboard/data-transfer-get-data-on-paste-rich-text.html: Added. 27 * platform/ios-simulator-wk1/TestExpectations: 28 29 Mark new copy and paste tests as [ Pass ], since editing/pasteboard/ is skipped by default for iOS WK1. 30 31 * platform/ios-wk1/editing/pasteboard/data-transfer-get-data-on-paste-rich-text-expected.txt: Added. 32 * platform/ios-wk2/editing/pasteboard/data-transfer-get-data-on-paste-rich-text-expected.txt: Added. 33 34 Add iOS-specific baselines. This is due to the generated HTML markup for "text/html" being slightly different 35 when pasting. 36 37 * platform/mac-wk1/TestExpectations: 38 1 39 2017-09-27 Zalan Bujtas <zalan@apple.com> 2 40 -
trunk/LayoutTests/TestExpectations
r222448 r222595 68 68 # Drag and drop via EventSender is only supported on Mac WK1 69 69 editing/pasteboard/drag-drop-href-as-text-data.html [ Skip ] 70 editing/pasteboard/data-transfer-get-data-on-drop-custom.html [ Skip ] 71 editing/pasteboard/data-transfer-get-data-on-drop-plain-text.html [ Skip ] 72 editing/pasteboard/data-transfer-get-data-on-drop-rich-text.html [ Skip ] 73 editing/pasteboard/data-transfer-get-data-on-drop-url.html [ Skip ] 70 74 71 75 # Only iOS supports QuickLook -
trunk/LayoutTests/platform/ios-simulator-wk1/TestExpectations
r222423 r222595 8 8 # Untriage pasteboard test failures 9 9 editing/pasteboard/ 10 editing/pasteboard/data-transfer-get-data-on-paste-custom.html [ Pass ] 11 editing/pasteboard/data-transfer-get-data-on-paste-plain-text.html [ Pass ] 12 editing/pasteboard/data-transfer-get-data-on-paste-rich-text.html [ Pass ] -
trunk/LayoutTests/platform/mac-wk1/TestExpectations
r222340 r222595 8 8 fast/forms/attributed-strings.html [ Pass ] 9 9 editing/pasteboard/drag-drop-href-as-text-data.html [ Pass ] 10 editing/pasteboard/data-transfer-get-data-on-drop-custom.html [ Pass ] 11 editing/pasteboard/data-transfer-get-data-on-drop-plain-text.html [ Pass ] 12 editing/pasteboard/data-transfer-get-data-on-drop-rich-text.html [ Pass ] 13 editing/pasteboard/data-transfer-get-data-on-drop-url.html [ Pass ] 10 14 11 15 #////////////////////////////////////////////////////////////////////////////////////////// -
trunk/Source/WebCore/CMakeLists.txt
r222575 r222595 2331 2331 platform/MainThreadSharedTimer.cpp 2332 2332 platform/NotImplemented.cpp 2333 platform/Pasteboard.cpp 2333 2334 platform/PasteboardWriterData.cpp 2334 2335 platform/PlatformSpeechSynthesisUtterance.cpp -
trunk/Source/WebCore/ChangeLog
r222594 r222595 1 2017-09-27 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 Drag event DataTransfer has unexpected types "dyn.ah62d4..." 4 https://bugs.webkit.org/show_bug.cgi?id=172526 5 <rdar://problem/32396081> 6 7 Reviewed by Ryosuke Niwa. 8 9 Currently, the pasteboard types we expose to web content are simply the types that appear on the platform 10 pasteboard (i.e. the general NSPasteboard on Mac, and either the general UIPasteboard or a UIDragSession's 11 NSItemProviders on iOS). This leads to DataTransfer.types exposing many private pasteboard types written by apps 12 around the system to the page, such as dynamic UTIs, CorePasteboardFlavorTypes, or the "Apple WebKit dummy 13 pasteboard type". These are not only confusing and not useful for web content (since they mostly hold values of 14 empty string anyways), but can additionally pose privacy concerns by exposing information meant only for native 15 applications to unvetted web content. 16 17 To address this problem, other browsers (e.g. Chrome and Firefox on Mac) white-list MIME types in DataTransfer's 18 list of types. By default, when dragging or copying, these are "text/plain", "text/html" and "text/uri-list". 19 However, this policy alone is insufficient, because the page may also supply its own types, in which case our 20 naive whitelist would prevent us from delivering them to the page. To address this additional constraint, both 21 Chrome and Firefox write any custom data supplied by the page to custom pasteboard UTIs 22 (org.chromium.drag-dummy-type and org.mozilla.custom-clipdata, respectively). The corresponding data is a map 23 of custom UTI => custom data supplied by the page; upon drop or paste, this mapping is consulted if the page 24 calls getData() with a custom UTI. 25 26 This patch adopts this same approach in WebKit, and introduces the com.apple.WebKit.custom-pasteboard-data UTI 27 (refer to per-method comments below for more information). These changes are covered by 18 new layout and API 28 tests, as well as existing drag-and-drop tests. 29 30 Tests: editing/pasteboard/data-transfer-get-data-on-drop-custom.html 31 editing/pasteboard/data-transfer-get-data-on-drop-plain-text.html 32 editing/pasteboard/data-transfer-get-data-on-drop-rich-text.html 33 editing/pasteboard/data-transfer-get-data-on-drop-url.html 34 editing/pasteboard/data-transfer-get-data-on-paste-custom.html 35 editing/pasteboard/data-transfer-get-data-on-paste-plain-text.html 36 editing/pasteboard/data-transfer-get-data-on-paste-rich-text.html 37 DataInteractionTests.DataTransferGetDataWhenDroppingPlainText 38 DataInteractionTests.DataTransferGetDataWhenDroppingCustomData 39 DataInteractionTests.DataTransferGetDataWhenDroppingURL 40 DataInteractionTests.DataTransferGetDataWhenDroppingImageWithFileURL 41 DataInteractionTests.DataTransferGetDataWhenDroppingRespectsPresentationStyle 42 DataInteractionTests.DataTransferSetDataCannotWritePlatformTypes 43 DataInteractionTests.DataTransferGetDataCannotReadPrivatePlatformTypes 44 UIPasteboardTests.DataTransferGetDataWhenPastingURL 45 UIPasteboardTests.DataTransferGetDataWhenPastingPlatformRepresentations 46 UIPasteboardTests.DataTransferSetDataCannotWritePlatformTypes 47 UIPasteboardTests.DataTransferGetDataCannotReadPrivatePlatformTypes 48 49 * CMakeLists.txt: 50 51 Add Pasteboard.cpp to the WebCore CMakeList. 52 53 * WebCore.xcodeproj/project.pbxproj: 54 * dom/DataTransfer.cpp: 55 (WebCore::DataTransfer::getData const): 56 (WebCore::DataTransfer::createForDragStartEvent): 57 58 Make a new static helper function to create a StaticPasteboard-backed DataTransfer when dispatching a dragstart 59 event. Any data supplied by the page will be written to the static pasteboard of this DataTransfer. 60 61 (WebCore::DataTransfer::moveDragState): 62 63 Add a new helper on DataTransfer to transfer the data required to initiate a drag from one DataTransfer to 64 another. This is used in EventHandler to transfer the contents of the temporary DataTransfer modified by the 65 page during the dragstart event over to the DataTransfer used for the rest of the drag initiation codepath, 66 which is actually connected to the platform. This includes committing the contents of the other 67 DataTransfer's StaticPasteboard to the new platform-connected Pasteboard. 68 69 (WebCore::DataTransfer::hasDragImage const): 70 * dom/DataTransfer.h: 71 * editing/cocoa/EditorCocoa.mm: 72 (WebCore::Editor::selectionInHTMLFormat): 73 (WebCore::Editor::writeSelectionToPasteboard): 74 (WebCore::Editor::writeSelection): 75 76 Write an additional HTML markup string on iOS. We already do this for Mac, but this data previously had no use 77 on iOS. This is needed for to vend the "text/html" representation to the page on iOS when pasting. 78 79 * editing/mac/EditorMac.mm: 80 (WebCore::Editor::selectionInHTMLFormat): Deleted. 81 * editing/wpe/EditorWPE.cpp: 82 (WebCore::createFragmentFromPasteboardData): 83 * page/EventHandler.cpp: 84 (WebCore::EventHandler::dispatchDragStartEventOnSourceElement): 85 86 Renamed from dispatchDragStartEvent to dispatchDragStartEventOnSourceElement. Additionally, simplified the logic 87 significantly, so that we now just check to see if the StaticPasteboard exposed to the page has any data, 88 instead of using platform-dependent logic to compare changeCounts. We can do this because StaticPasteboard is 89 guaranteed to only contain content that the page has supplied during the dragstart event, since it is empty 90 upon initialization and cannot be written to by the rest of the platform. 91 92 (WebCore::EventHandler::handleDrag): 93 94 Tweak dispatchDragStartEvent to take a DataTransfer to expose to bindings; at the call site in handleDrag, 95 create a new DataTransfer backed by a StaticPasteboard that the page may mutate over the course of the dragstart 96 event. After dispatching to the page, move the dragging information present on the drag start DataTransfer over 97 to the DragState's DataTransfer. If the drag image has not been set, compute and set the default drag image 98 element on the DragState's DataTransfer. 99 100 (WebCore::EventHandler::dispatchDragStartEvent): Deleted. 101 * page/EventHandler.h: 102 * page/Settings.cpp: 103 (WebCore::Settings::customPasteboardDataEnabled): 104 * page/Settings.h: 105 (WebCore::Settings::setCustomPasteboardDataEnabled): 106 * page/ios/EventHandlerIOS.mm: 107 (WebCore::EventHandler::createDraggingDataTransfer const): Deleted. 108 * page/mac/EventHandlerMac.mm: 109 (WebCore::EventHandler::createDraggingDataTransfer const): Deleted. 110 * page/win/EventHandlerWin.cpp: 111 (WebCore::EventHandler::createDraggingDataTransfer const): Deleted. 112 113 Remove this helper on both iOS and Mac. This only called createForDrag() before, with the addition of clearing 114 the platform pasteboard prior to returning. Now that a StaticPasteboard is used when starting a drag, we clear 115 out the platform pasteboard in platform-invariant code in EventHandler::handleDrag, so these helpers are no 116 longer useful. 117 118 * platform/Pasteboard.cpp: Added. 119 (WebCore::isSafeTypeForDOMToReadAndWrite): 120 121 Add a new helper to determine whether or not a pasteboard type is one of the standard DOM-exposed types. These 122 are "text/plain", "text/html" and "text/uri-list". 123 124 (WebCore::sharedBufferFromCustomData): 125 (WebCore::customDataFromSharedBuffer): 126 127 Add helper methods to serialize and deserialize custom data. The serialized data blob consists of: (1) 128 versioning information, (2) a dictionary mapping each custom type to a value, and (3) a full list of types 129 written by the page, in the order they were written. 130 131 * platform/Pasteboard.h: 132 133 Rename Pasteboard::readString to Pasteboard::readStringForBindings, to reflect that the string being read and 134 the given type are exposed to and from the DOM. 135 136 * platform/PasteboardStrategy.h: 137 * platform/PasteboardWriterData.h: 138 * platform/PlatformPasteboard.h: 139 * platform/StaticPasteboard.cpp: 140 141 Split m_stringContents out into m_platformData and m_customData. The former contains type-to-data entries for 142 the DOM-exposed types, while the second contains entries that don't belong in the former. 143 144 (WebCore::StaticPasteboard::hasData): 145 (WebCore::StaticPasteboard::readStringForBindings): 146 (WebCore::StaticPasteboard::writeString): 147 (WebCore::StaticPasteboard::clear): 148 (WebCore::StaticPasteboard::commitToPasteboard): 149 150 Rather than propagate each entry to the client layer one at a time, populate a new PasteboardCustomData struct 151 and send it to the client layer in one go. This new struct consists of an array of types in the order they were 152 written by the page, a dictionary of public types (types we want to write directly to the platform pasteboard) 153 and private types (custom types we want to package under our custom data blob). 154 155 (WebCore::StaticPasteboard::readString): Deleted. 156 * platform/StaticPasteboard.h: 157 * platform/glib/EventHandlerGLib.cpp: 158 (WebCore::EventHandler::createDraggingDataTransfer const): Deleted. 159 * platform/gtk/PasteboardGtk.cpp: 160 (WebCore::Pasteboard::readStringForBindings): 161 (WebCore::Pasteboard::writeCustomData): 162 (WebCore::Pasteboard::readString): Deleted. 163 * platform/gtk/PlatformPasteboardGtk.cpp: 164 (WebCore::PlatformPasteboard::typesSafeForDOMToReadAndWrite const): 165 (WebCore::PlatformPasteboard::write): 166 167 Add stub implementations for new custom pasteboard data methods. 168 169 * platform/ios/AbstractPasteboard.h: 170 * platform/ios/PasteboardIOS.mm: 171 (WebCore::Pasteboard::writeCustomData): 172 173 Add new plumbing to ship a custom data (PasteboardCustomData) struct from WebCore to the client layer. 174 175 (WebCore::cocoaTypeFromHTMLClipboardType): 176 (WebCore::readPlatformValueAsString): 177 (WebCore::Pasteboard::readStringForBindings): 178 (WebCore::Pasteboard::types): 179 180 Rewritten to ask the client layer for DOM-exposed types rather than all types, in the case where custom 181 pasteboard data is enabled in Settings. 182 183 (WebCore::Pasteboard::readString): Deleted. 184 * platform/ios/PlatformPasteboardIOS.mm: 185 (WebCore::PlatformPasteboard::bufferForType): 186 (WebCore::PlatformPasteboard::getPathnamesForType const): 187 (WebCore::PlatformPasteboard::numberOfFiles const): 188 (WebCore::PlatformPasteboard::platformPasteboardTypeForSafeTypeForDOMToReadAndWrite): 189 190 Add a new helper to map DOM-safe pasteboard types to their platform counterparts. 191 192 (WebCore::PlatformPasteboard::write): 193 (WebCore::safeTypeForDOMToReadAndWriteForPlatformType): 194 195 Add a new helper to map platform pasteboard types to their DOM-safe counterparts. 196 197 (WebCore::PlatformPasteboard::typesSafeForDOMToReadAndWrite const): 198 199 Fetch a list of DOM-exposed types. On iOS, for drag and drop, we have the additional constraint of not being 200 able to read any data before the drop happens. This is problematic, since the page needs to know the list of 201 types during 'dragover' events. To support this, we instead keep the array of types in the teamData property of 202 the generated item provider, which is immediately available, even when dragging across different apps. Note that 203 we still need to check if the pasteboard contains the full custom data blob here to handle the case where we 204 copy on Mac and perform a continuity paste on iOS, since teamData does not exist on Mac. 205 206 (WebCore::PlatformPasteboard::readString): 207 208 Tweak to account for how UIPasteboard may return data blobs when reading values. 209 210 (WebCore::PlatformPasteboard::getPathnamesForType): Deleted. 211 (WebCore::PlatformPasteboard::numberOfFiles): Deleted. 212 * platform/ios/WebItemProviderPasteboard.h: 213 * platform/ios/WebItemProviderPasteboard.mm: 214 (-[WebItemProviderRegistrationInfoList itemProvider]): 215 (+[WebItemProviderLoadResult loadResultWithItemProvider:typesToLoad:]): 216 (-[WebItemProviderLoadResult initWithItemProvider:typesToLoad:]): 217 (-[WebItemProviderLoadResult typesToLoad]): 218 (-[WebItemProviderLoadResult setFileURL:forType:]): 219 (-[WebItemProviderLoadResult itemProvider]): 220 (-[WebItemProviderPasteboard setItemProviders:]): 221 (-[WebItemProviderPasteboard dataForPasteboardType:]): 222 (-[WebItemProviderPasteboard typeIdentifiersToLoadForRegisteredTypeIdentfiers:]): 223 (-[WebItemProviderPasteboard doAfterLoadingProvidedContentIntoFileURLs:synchronousTimeout:]): 224 (+[WebItemProviderLoadResult emptyLoadResult]): Deleted. 225 (+[WebItemProviderLoadResult loadResultWithFileURLMap:presentationStyle:]): Deleted. 226 (-[WebItemProviderLoadResult initWithFileURLMap:presentationStyle:]): Deleted. 227 (-[WebItemProviderPasteboard typeIdentifierToLoadForRegisteredTypeIdentfiers:]): Deleted. 228 229 In the case of drag and drop on iOS, we cannot load any data prior to performing the drop; additionally, any 230 attempts to load data immediately after the drop is performed in the UI process will fail. This means any and 231 all data that the web process may require in the future when handling the drop must be loaded out of the item 232 providers and saved when the drop is being handled in the UI process. 233 234 Currently, we only load the highest fidelity type we can handle (or, if we don't know what we can handle, we 235 select the highest fidelity representation conforming to "public.content"). This is a problematic for supporting 236 DataTransfer.getData() on drop on iOS, because the page can ask for any of the three web-exposed types. To 237 address this, we refactor WebItemProviderPasteboard to support loading multiple representations per item being 238 dropped. At minimum, we will load anything conforming to "public.html", "public.plain-text", "public.url", and 239 the new "com.apple.WebKit.custom-pasteboard-data" so we have means to answer any question that the page could 240 ask via DataTransfer.getData(). We additonally load the highest fidelity supported (or content-conformant) type, 241 if it has not already been loaded as a result of the former. 242 243 To make this possible, we refactor WebItemProviderLoadResult to take an item provider and a list of types to 244 load. -doAfterLoadingProvidedContentIntoFileURLs:synchronousTimeout: then creates a list of load results and 245 uses each one to represent the results of loading data from its item provider (i.e. a map of UTI => file URL). 246 247 * platform/mac/PasteboardMac.mm: 248 (WebCore::Pasteboard::writeCustomData): 249 (WebCore::cocoaTypeFromHTMLClipboardType): 250 (WebCore::readPlatformValueAsString): 251 (WebCore::Pasteboard::readStringForBindings): 252 253 Change readStringForBindings (formerly, readString) so that if support for custom pasteboard data is enabled, 254 we only allow reading directly from the platform pasteboard if the given type is DOM-safe; otherwise, we consult 255 the custom data blob, if it exists. Otherwise, if support for custom pasteboard data is disabled, we fall back 256 to our current behavior. 257 258 (WebCore::Pasteboard::types): 259 (WebCore::Pasteboard::readString): Deleted. 260 * platform/mac/PlatformPasteboardMac.mm: 261 (WebCore::PlatformPasteboard::numberOfFiles const): 262 (WebCore::PlatformPasteboard::getPathnamesForType const): 263 (WebCore::PlatformPasteboard::stringForType): 264 (WebCore::safeTypeForDOMToReadAndWriteForPlatformType): 265 (WebCore::PlatformPasteboard::typesSafeForDOMToReadAndWrite const): 266 267 Add support for reading DOM-exposed types and fetching DOM-exposed data off of the pasteboard. The overall idea 268 here is similar to iOS, though implementation details vary (e.g. no item provider support). 269 270 (WebCore::PlatformPasteboard::write): 271 (WebCore::PlatformPasteboard::platformPasteboardTypeForSafeTypeForDOMToReadAndWrite): 272 (WebCore::PlatformPasteboard::numberOfFiles): Deleted. 273 (WebCore::PlatformPasteboard::getPathnamesForType): Deleted. 274 * platform/win/PasteboardWin.cpp: 275 (WebCore::Pasteboard::readStringForBindings): 276 (WebCore::Pasteboard::writeCustomData): 277 (WebCore::Pasteboard::readString): Deleted. 278 * platform/wpe/PasteboardWPE.cpp: 279 (WebCore::Pasteboard::readStringForBindings): 280 (WebCore::Pasteboard::writeCustomData): 281 (WebCore::Pasteboard::readString): Deleted. 282 * platform/wpe/PlatformPasteboardWPE.cpp: 283 (WebCore::PlatformPasteboard::typesSafeForDOMToReadAndWrite const): 284 (WebCore::PlatformPasteboard::write): 285 * testing/InternalSettings.cpp: 286 (WebCore::InternalSettings::Backup::Backup): 287 (WebCore::InternalSettings::Backup::restoreTo): 288 (WebCore::InternalSettings::setCustomPasteboardDataEnabled): 289 290 Add a new internal settings hook for layout tests to opt in to using custom pasteboard data. By default, custom 291 pasteboard data is enabled only in Safari, or on applications linked on or after certain releases of iOS and 292 macOS. 293 294 * testing/InternalSettings.h: 295 * testing/InternalSettings.idl: 296 1 297 2017-09-27 Zalan Bujtas <zalan@apple.com> 2 298 -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r222575 r222595 1341 1341 2EDF369C122C94B4002F7D4E /* FileReaderSync.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2EDF369A122C94B4002F7D4E /* FileReaderSync.cpp */; }; 1342 1342 2EDF369D122C94B4002F7D4E /* FileReaderSync.h in Headers */ = {isa = PBXBuildFile; fileRef = 2EDF369B122C94B4002F7D4E /* FileReaderSync.h */; }; 1343 2EE02A1F1F7324280006AF72 /* Pasteboard.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2EE02A1E1F7324280006AF72 /* Pasteboard.cpp */; }; 1343 1344 2EEEE55C1B66A047008E2CBC /* WheelEventDeltaFilterMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2EEEE55B1B66A047008E2CBC /* WheelEventDeltaFilterMac.mm */; }; 1344 1345 2EF1BFEA121C9F4200C27627 /* FileStream.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2EF1BFE8121C9F4200C27627 /* FileStream.cpp */; }; … … 9068 9069 2EDF369A122C94B4002F7D4E /* FileReaderSync.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FileReaderSync.cpp; sourceTree = "<group>"; }; 9069 9070 2EDF369B122C94B4002F7D4E /* FileReaderSync.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileReaderSync.h; sourceTree = "<group>"; }; 9071 2EE02A1E1F7324280006AF72 /* Pasteboard.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Pasteboard.cpp; sourceTree = "<group>"; }; 9070 9072 2EEEE55B1B66A047008E2CBC /* WheelEventDeltaFilterMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WheelEventDeltaFilterMac.mm; sourceTree = "<group>"; }; 9071 9073 2EF1BFE8121C9F4200C27627 /* FileStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FileStream.cpp; sourceTree = "<group>"; }; … … 24643 24645 98EB1F941313FE0500D0E1EA /* NotImplemented.h */, 24644 24646 4184F5151EAF059800F18BF0 /* OrientationNotifier.h */, 24647 2EE02A1E1F7324280006AF72 /* Pasteboard.cpp */, 24645 24648 4B2708C50AF19EE40065127F /* Pasteboard.h */, 24646 24649 C5F765B414E1D414006C899B /* PasteboardStrategy.h */, … … 25893 25896 BCEA4822097D93020094C9E4 /* RenderBox.cpp */, 25894 25897 BCEA4823097D93020094C9E4 /* RenderBox.h */, 25898 BCEB179B143379F50052EAE9 /* RenderBoxFragmentInfo.h */, 25895 25899 BC96DB450F3A882200573CB3 /* RenderBoxModelObject.cpp */, 25896 25900 BC96DB420F3A880E00573CB3 /* RenderBoxModelObject.h */, 25897 BCEB179B143379F50052EAE9 /* RenderBoxFragmentInfo.h */,25898 25901 BCEA4826097D93020094C9E4 /* RenderButton.cpp */, 25899 25902 BCEA4827097D93020094C9E4 /* RenderButton.h */, … … 25916 25919 53C8298B13D8D92700DE2DEB /* RenderFlexibleBox.cpp */, 25917 25920 53C8298C13D8D92700DE2DEB /* RenderFlexibleBox.h */, 25921 D70AD65513E1342B005B50B4 /* RenderFragmentContainer.cpp */, 25922 D70AD65613E1342B005B50B4 /* RenderFragmentContainer.h */, 25923 BCE93F461517C6D5008CCF74 /* RenderFragmentContainerSet.cpp */, 25924 BCE93F441517C567008CCF74 /* RenderFragmentContainerSet.h */, 25918 25925 508CCA4E13CF106B003151F3 /* RenderFragmentedFlow.cpp */, 25919 25926 508CCA4D13CF106B003151F3 /* RenderFragmentedFlow.h */, … … 25990 25997 5A574F22131DB93900471B88 /* RenderQuote.cpp */, 25991 25998 5A574F23131DB93900471B88 /* RenderQuote.h */, 25992 D70AD65513E1342B005B50B4 /* RenderFragmentContainer.cpp */,25993 D70AD65613E1342B005B50B4 /* RenderFragmentContainer.h */,25994 BCE93F461517C6D5008CCF74 /* RenderFragmentContainerSet.cpp */,25995 BCE93F441517C567008CCF74 /* RenderFragmentContainerSet.h */,25996 25999 A871DFDE0A15376B00B12A68 /* RenderReplaced.cpp */, 25997 26000 A871DFDF0A15376B00B12A68 /* RenderReplaced.h */, … … 29658 29661 BC10D76817D8EE71005E2626 /* RenderBlockFlow.h in Headers */, 29659 29662 BCEA4862097D93020094C9E4 /* RenderBox.h in Headers */, 29663 BCEB179C143379F50052EAE9 /* RenderBoxFragmentInfo.h in Headers */, 29660 29664 BC96DB430F3A880E00573CB3 /* RenderBoxModelObject.h in Headers */, 29661 BCEB179C143379F50052EAE9 /* RenderBoxFragmentInfo.h in Headers */,29662 29665 BCEA4866097D93020094C9E4 /* RenderButton.h in Headers */, 29663 29666 B56579B51824D12A00E79F23 /* RenderChildIterator.h in Headers */, … … 29673 29676 066C77310AB603FD00238CC4 /* RenderFileUploadControl.h in Headers */, 29674 29677 53C8298E13D8D92700DE2DEB /* RenderFlexibleBox.h in Headers */, 29678 D70AD65813E1342B005B50B4 /* RenderFragmentContainer.h in Headers */, 29679 BCE93F451517C567008CCF74 /* RenderFragmentContainerSet.h in Headers */, 29675 29680 508CCA4F13CF106B003151F3 /* RenderFragmentedFlow.h in Headers */, 29676 29681 A871DED30A1530C700B12A68 /* RenderFrame.h in Headers */, … … 29723 29728 B5B65874186FDE4C009C26E8 /* RenderPtr.h in Headers */, 29724 29729 5A574F25131DB93900471B88 /* RenderQuote.h in Headers */, 29725 D70AD65813E1342B005B50B4 /* RenderFragmentContainer.h in Headers */,29726 BCE93F451517C567008CCF74 /* RenderFragmentContainerSet.h in Headers */,29727 29730 A871DFE30A15376B00B12A68 /* RenderReplaced.h in Headers */, 29728 29731 BCA846D70DC67A350026C309 /* RenderReplica.h in Headers */, … … 33488 33491 57B5F7EC1E57F1E300F34F90 /* PasswordCredential.cpp in Sources */, 33489 33492 F55B3DC91251F12D003EF269 /* PasswordInputType.cpp in Sources */, 33493 2EE02A1F1F7324280006AF72 /* Pasteboard.cpp in Sources */, 33490 33494 E453901E0EAFCACA003695C8 /* PasteboardIOS.mm in Sources */, 33491 33495 4B2709830AF2E5E00065127F /* PasteboardMac.mm in Sources */, … … 33634 33638 066C77300AB603FD00238CC4 /* RenderFileUploadControl.cpp in Sources */, 33635 33639 53C8298D13D8D92700DE2DEB /* RenderFlexibleBox.cpp in Sources */, 33640 D70AD65713E1342B005B50B4 /* RenderFragmentContainer.cpp in Sources */, 33641 BCE93F471517C6D5008CCF74 /* RenderFragmentContainerSet.cpp in Sources */, 33636 33642 508CCA5013CF106B003151F3 /* RenderFragmentedFlow.cpp in Sources */, 33637 33643 A871DED40A1530C700B12A68 /* RenderFrame.cpp in Sources */, … … 33683 33689 A43BF59C1149292800C643CA /* RenderProgress.cpp in Sources */, 33684 33690 5A574F24131DB93900471B88 /* RenderQuote.cpp in Sources */, 33685 D70AD65713E1342B005B50B4 /* RenderFragmentContainer.cpp in Sources */,33686 BCE93F471517C6D5008CCF74 /* RenderFragmentContainerSet.cpp in Sources */,33687 33691 A871DFE20A15376B00B12A68 /* RenderReplaced.cpp in Sources */, 33688 33692 BCA846D60DC67A350026C309 /* RenderReplica.cpp in Sources */, -
trunk/Source/WebCore/dom/DataTransfer.cpp
r222228 r222595 141 141 #endif 142 142 143 return m_pasteboard->readString (normalizeType(type));143 return m_pasteboard->readStringForBindings(normalizeType(type)); 144 144 } 145 145 … … 256 256 { 257 257 return adoptRef(*new DataTransfer(StoreMode::ReadWrite, Pasteboard::createForDragAndDrop(), Type::DragAndDropData)); 258 } 259 260 Ref<DataTransfer> DataTransfer::createForDragStartEvent() 261 { 262 return adoptRef(*new DataTransfer(StoreMode::ReadWrite, std::make_unique<StaticPasteboard>(), Type::DragAndDropData)); 258 263 } 259 264 … … 461 466 } 462 467 468 void DataTransfer::moveDragState(Ref<DataTransfer>&& other) 469 { 470 RELEASE_ASSERT(is<StaticPasteboard>(other->pasteboard())); 471 // We clear the platform pasteboard here to ensure that the pasteboard doesn't contain any data 472 // that may have been written before starting the drag, and after ending the last drag session. 473 // After pushing the static pasteboard's contents to the platform, the pasteboard should only 474 // contain data that was in the static pasteboard. 475 m_pasteboard->clear(); 476 downcast<StaticPasteboard>(other->pasteboard()).commitToPasteboard(*m_pasteboard); 477 478 m_dropEffect = other->m_dropEffect; 479 m_effectAllowed = other->m_effectAllowed; 480 m_dragLocation = other->m_dragLocation; 481 m_dragImage = other->m_dragImage; 482 m_dragImageElement = WTFMove(other->m_dragImageElement); 483 m_dragImageLoader = WTFMove(other->m_dragImageLoader); 484 m_itemList = WTFMove(other->m_itemList); 485 m_fileList = WTFMove(other->m_fileList); 486 } 487 488 bool DataTransfer::hasDragImage() const 489 { 490 return m_dragImage || m_dragImageElement; 491 } 492 463 493 #endif // ENABLE(DRAG_SUPPORT) 464 494 -
trunk/Source/WebCore/dom/DataTransfer.h
r221907 r222595 81 81 #if ENABLE(DRAG_SUPPORT) 82 82 static Ref<DataTransfer> createForDrag(); 83 static Ref<DataTransfer> createForDragStartEvent(); 83 84 static Ref<DataTransfer> createForDrop(StoreMode, const DragData&); 84 85 … … 94 95 void updateDragImage(); 95 96 RefPtr<Element> dragImageElement() const; 97 98 void moveDragState(Ref<DataTransfer>&&); 99 bool hasDragImage() const; 96 100 #endif 97 101 -
trunk/Source/WebCore/editing/cocoa/EditorCocoa.mm
r222465 r222595 51 51 #import "WebContentReader.h" 52 52 #import "WebCoreNSURLExtras.h" 53 #import "markup.h" 53 54 #import <pal/spi/cocoa/NSAttributedStringSPI.h> 54 55 #import <wtf/BlockObjCExceptions.h> … … 144 145 } 145 146 147 String Editor::selectionInHTMLFormat() 148 { 149 if (auto range = selectedRange()) 150 return createMarkup(*range, nullptr, AnnotateForInterchange, false, ResolveNonLocalURLs); 151 return { }; 152 } 153 146 154 void Editor::writeSelectionToPasteboard(Pasteboard& pasteboard) 147 155 { … … 154 162 content.dataInRTFFormat = dataInRTFFormat(attributedString); 155 163 content.dataInAttributedStringFormat = archivedDataForAttributedString(attributedString); 156 // FIXME: Why don't we want this on iOS?157 #if PLATFORM(MAC)158 164 content.dataInHTMLFormat = selectionInHTMLFormat(); 159 #endif160 165 content.dataInStringFormat = stringSelectionForPasteboardWithImageAltText(); 161 166 client()->getClientPasteboardDataForRange(selectedRange().get(), content.clientTypes, content.clientData); … … 174 179 webContent.dataInRTFFormat = dataInRTFFormat(attributedString); 175 180 webContent.dataInAttributedStringFormat = archivedDataForAttributedString(attributedString); 176 // FIXME: Why don't we want this on iOS?177 #if PLATFORM(MAC)178 181 webContent.dataInHTMLFormat = selectionInHTMLFormat(); 179 #endif180 182 webContent.dataInStringFormat = stringSelectionForPasteboardWithImageAltText(); 181 183 client()->getClientPasteboardDataForRange(selectedRange().get(), webContent.clientTypes, webContent.clientData); -
trunk/Source/WebCore/editing/mac/EditorMac.mm
r222465 r222595 183 183 } 184 184 185 String Editor::selectionInHTMLFormat()186 {187 return createMarkup(*selectedRange(), nullptr, AnnotateForInterchange, false, ResolveNonLocalURLs);188 }189 190 185 RefPtr<SharedBuffer> Editor::imageInWebArchiveFormat(Element& imageElement) 191 186 { -
trunk/Source/WebCore/editing/wpe/EditorWPE.cpp
r216497 r222595 44 44 45 45 if (types.contains("text/html;charset=utf-8") && frame.document()) { 46 String markup = pasteboard.readString ("text/html;charset=utf-8");46 String markup = pasteboard.readStringForBindings("text/html;charset=utf-8"); 47 47 if (RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(*frame.document(), markup, emptyString(), DisallowScriptingAndPluginContent)) 48 48 return fragment; … … 54 54 if (types.contains("text/plain;charset=utf-8")) { 55 55 chosePlainText = true; 56 if (RefPtr<DocumentFragment> fragment = createFragmentFromText(range, pasteboard.readString ("text/plain;charset=utf-8")))56 if (RefPtr<DocumentFragment> fragment = createFragmentFromText(range, pasteboard.readStringForBindings("text/plain;charset=utf-8"))) 57 57 return fragment; 58 58 } -
trunk/Source/WebCore/page/EventHandler.cpp
r222392 r222595 87 87 #include "ShadowRoot.h" 88 88 #include "SpatialNavigation.h" 89 #include "StaticPasteboard.h" 89 90 #include "StyleCachedImage.h" 90 91 #include "TextEvent.h" … … 3548 3549 } 3549 3550 3550 bool EventHandler::dispatchDragStartEvent(HasNonDefaultPasteboardData& hasNonDefaultPasteboardData) 3551 { 3552 #if PLATFORM(COCOA) 3553 auto changeCountBeforeDragStart = dragState().dataTransfer->pasteboard().changeCount(); 3554 #endif 3555 3556 bool mayStartDrag = dispatchDragSrcEvent(eventNames().dragstartEvent, m_mouseDown); 3557 3558 #if PLATFORM(COCOA) 3559 hasNonDefaultPasteboardData = changeCountBeforeDragStart != dragState().dataTransfer->pasteboard().changeCount() ? HasNonDefaultPasteboardData::Yes : HasNonDefaultPasteboardData::No; 3560 #else 3561 hasNonDefaultPasteboardData = dragState().dataTransfer->pasteboard().hasData() ? HasNonDefaultPasteboardData::Yes : HasNonDefaultPasteboardData::No; 3562 #endif 3563 3564 return mayStartDrag && !m_frame.selection().selection().isInPasswordField(); 3551 bool EventHandler::dispatchDragStartEventOnSourceElement(DataTransfer& dataTransfer) 3552 { 3553 return !dispatchDragEvent(eventNames().dragstartEvent, *dragState().source, m_mouseDown, &dataTransfer) && !m_frame.selection().selection().isInPasswordField(); 3565 3554 } 3566 3555 … … 3668 3657 invalidateDataTransfer(); 3669 3658 3670 dragState().dataTransfer = createDraggingDataTransfer();3659 dragState().dataTransfer = DataTransfer::createForDrag(); 3671 3660 HasNonDefaultPasteboardData hasNonDefaultPasteboardData = HasNonDefaultPasteboardData::No; 3672 3661 3673 3662 if (dragState().shouldDispatchEvents) { 3674 // Check to see if the is a DOM based drag. If it is, get the DOM specified drag image and offset. 3675 if (dragState().type == DragSourceActionDHTML) { 3676 if (RenderObject* renderer = dragState().source->renderer()) { 3677 // FIXME: This doesn't work correctly with transforms. 3678 FloatPoint absPos = renderer->localToAbsolute(); 3679 IntSize delta = m_mouseDownPos - roundedIntPoint(absPos); 3663 auto dragStartDataTransfer = DataTransfer::createForDragStartEvent(); 3664 m_mouseDownMayStartDrag = dispatchDragStartEventOnSourceElement(dragStartDataTransfer); 3665 hasNonDefaultPasteboardData = dragStartDataTransfer->pasteboard().hasData() ? HasNonDefaultPasteboardData::Yes : HasNonDefaultPasteboardData::No; 3666 dragState().dataTransfer->moveDragState(WTFMove(dragStartDataTransfer)); 3667 3668 if (dragState().source && dragState().type == DragSourceActionDHTML && !dragState().dataTransfer->hasDragImage()) { 3669 dragState().source->document().updateStyleIfNeeded(); 3670 if (auto* renderer = dragState().source->renderer()) { 3671 auto absolutePosition = renderer->localToAbsolute(); 3672 auto delta = m_mouseDownPos - roundedIntPoint(absolutePosition); 3680 3673 dragState().dataTransfer->setDragImage(dragState().source.get(), delta.width(), delta.height()); 3681 3674 } else { 3682 // The renderer has disappeared, this can happen if the onStartDrag handler has hidden 3683 // the element in some way. In this case we just kill the drag. 3675 dispatchDragSrcEvent(eventNames().dragendEvent, event.event()); 3684 3676 m_mouseDownMayStartDrag = false; 3685 3677 invalidateDataTransfer(); 3686 3678 dragState().source = nullptr; 3687 3688 3679 return true; 3689 3680 } 3690 } 3691 3692 m_mouseDownMayStartDrag = dispatchDragStartEvent(hasNonDefaultPasteboardData); 3681 } 3693 3682 3694 3683 dragState().dataTransfer->makeInvalidForSecurity(); -
trunk/Source/WebCore/page/EventHandler.h
r222392 r222595 325 325 static DragState& dragState(); 326 326 static const Seconds TextDragDelay; 327 Ref<DataTransfer> createDraggingDataTransfer() const;328 327 #endif 329 328 … … 406 405 407 406 bool dispatchDragSrcEvent(const AtomicString& eventType, const PlatformMouseEvent&); 408 bool dispatchDragStartEvent (HasNonDefaultPasteboardData&);407 bool dispatchDragStartEventOnSourceElement(DataTransfer&); 409 408 410 409 bool dragHysteresisExceeded(const FloatPoint&) const; -
trunk/Source/WebCore/page/Settings.cpp
r222107 r222595 49 49 #include <wtf/StdLibExtras.h> 50 50 51 #if PLATFORM(COCOA) 52 #include <wtf/spi/darwin/dyldSPI.h> 53 #endif 54 51 55 #if ENABLE(MEDIA_STREAM) && USE(AVFOUNDATION) 52 56 #include "RealtimeMediaSourceCenterMac.h" … … 116 120 #endif 117 121 bool Settings::gManageAudioSession = false; 122 bool Settings::gCustomPasteboardDataEnabled = false; 118 123 119 124 // NOTEs … … 138 143 #endif 139 144 ; 145 } 146 147 bool Settings::customPasteboardDataEnabled() 148 { 149 static std::once_flag initializeCustomPasteboardDataToDefaultValue; 150 std::call_once(initializeCustomPasteboardDataToDefaultValue, [] { 151 #if PLATFORM(IOS) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110300 152 gCustomPasteboardDataEnabled = IOSApplication::isMobileSafari() || dyld_get_program_sdk_version() >= DYLD_IOS_VERSION_11_3; 153 #elif PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101304 154 // FIXME: Update this linked-on check once the correct macro is in the SDK. 155 gCustomPasteboardDataEnabled = MacApplication::isSafari() || dyld_get_program_sdk_version() > DYLD_MACOSX_VERSION_10_13; 156 #else 157 gCustomPasteboardDataEnabled = false; 158 #endif 159 }); 160 return gCustomPasteboardDataEnabled; 140 161 } 141 162 -
trunk/Source/WebCore/page/Settings.h
r218480 r222595 305 305 #endif 306 306 307 static void setCustomPasteboardDataEnabled(bool enabled) { gCustomPasteboardDataEnabled = enabled; } 308 WEBCORE_EXPORT static bool customPasteboardDataEnabled(); 309 307 310 #if ENABLE(LEGACY_ENCRYPTED_MEDIA) 308 311 void setMediaKeysStorageDirectory(const String& directory) { m_mediaKeysStorageDirectory = directory; } … … 420 423 #endif 421 424 WEBCORE_EXPORT static bool gManageAudioSession; 425 WEBCORE_EXPORT static bool gCustomPasteboardDataEnabled; 422 426 423 427 #if ENABLE(LEGACY_ENCRYPTED_MEDIA) -
trunk/Source/WebCore/page/ios/EventHandlerIOS.mm
r222392 r222595 562 562 #if ENABLE(DRAG_SUPPORT) 563 563 564 Ref<DataTransfer> EventHandler::createDraggingDataTransfer() const565 {566 Pasteboard("data interaction pasteboard").clear();567 return DataTransfer::createForDrag();568 }569 570 564 bool EventHandler::eventLoopHandleMouseDragged(const MouseEventWithHitTestResults&) 571 565 { -
trunk/Source/WebCore/page/mac/EventHandlerMac.mm
r215173 r222595 719 719 } 720 720 721 #if ENABLE(DRAG_SUPPORT)722 723 Ref<DataTransfer> EventHandler::createDraggingDataTransfer() const724 {725 // Must be done before ondragstart adds types and data to the pboard,726 // also done for security, as it erases data from the last drag.727 #pragma clang diagnostic push728 #pragma clang diagnostic ignored "-Wdeprecated-declarations"729 auto pasteboard = std::make_unique<Pasteboard>(NSDragPboard);730 #pragma clang diagnostic pop731 pasteboard->clear();732 return DataTransfer::createForDrag();733 }734 735 #endif736 737 721 bool EventHandler::tabsToAllFormControls(KeyboardEvent& event) const 738 722 { -
trunk/Source/WebCore/page/win/EventHandlerWin.cpp
r222392 r222595 92 92 } 93 93 94 #if ENABLE(DRAG_SUPPORT)95 96 Ref<DataTransfer> EventHandler::createDraggingDataTransfer() const97 {98 return DataTransfer::createForDrag();99 }100 101 #endif102 103 94 void EventHandler::focusDocumentView() 104 95 { -
trunk/Source/WebCore/platform/Pasteboard.h
r222228 r222595 28 28 #include "DragImage.h" 29 29 #include "URL.h" 30 #include <wtf/HashMap.h> 30 31 #include <wtf/Noncopyable.h> 31 32 #include <wtf/Vector.h> … … 146 147 }; 147 148 149 // FIXME: We need to ensure that the contents of sameOriginCustomData are not accessible across different origins. 150 struct PasteboardCustomData { 151 Vector<String> orderedTypes; 152 HashMap<String, String> platformData; 153 HashMap<String, String> sameOriginCustomData; 154 }; 155 156 WEBCORE_EXPORT Ref<SharedBuffer> sharedBufferFromCustomData(const PasteboardCustomData&); 157 WEBCORE_EXPORT PasteboardCustomData customDataFromSharedBuffer(const SharedBuffer&); 158 159 #if PLATFORM(COCOA) 160 const char customWebKitPasteboardDataType[] = "com.apple.WebKit.custom-pasteboard-data"; 161 #endif 162 163 bool isSafeTypeForDOMToReadAndWrite(const String& type); 164 148 165 class Pasteboard { 149 166 WTF_MAKE_NONCOPYABLE(Pasteboard); WTF_MAKE_FAST_ALLOCATED; … … 169 186 virtual bool hasData(); 170 187 virtual Vector<String> types(); 171 virtual String readString (const String& type);188 virtual String readStringForBindings(const String& type); 172 189 173 190 virtual void writeString(const String& type, const String& data); … … 232 249 #endif 233 250 251 void writeCustomData(const PasteboardCustomData&); 252 234 253 private: 235 254 #if PLATFORM(IOS) … … 245 264 #endif 246 265 266 #if PLATFORM(COCOA) 267 String readStringForPlatformType(const String&); 268 #endif 269 247 270 #if PLATFORM(GTK) 248 271 void writeToClipboard(); -
trunk/Source/WebCore/platform/PasteboardStrategy.h
r222228 r222595 38 38 struct PasteboardURL; 39 39 struct PasteboardWebContent; 40 struct PasteboardCustomData; 40 41 41 42 class PasteboardStrategy { … … 72 73 #endif 73 74 75 virtual Vector<String> typesSafeForDOMToReadAndWrite(const String& pasteboardName) = 0; 76 virtual long writeCustomData(const PasteboardCustomData&, const String& pasteboardName) = 0; 77 74 78 #if PLATFORM(GTK) 75 79 virtual void writeToClipboard(const String& pasteboardName, const SelectionData&) = 0; -
trunk/Source/WebCore/platform/PasteboardWriterData.h
r218837 r222595 56 56 RefPtr<SharedBuffer> dataInRTFFormat; 57 57 RefPtr<SharedBuffer> dataInAttributedStringFormat; 58 // FIXME: Why don't we want this on iOS?59 #if PLATFORM(MAC)60 58 String dataInHTMLFormat; 61 #endif62 59 String dataInStringFormat; 63 60 Vector<String> clientTypes; -
trunk/Source/WebCore/platform/PlatformPasteboard.h
r220865 r222595 50 50 class SharedBuffer; 51 51 class URL; 52 struct PasteboardCustomData; 52 53 struct PasteboardImage; 53 54 struct PasteboardURL; … … 65 66 WEBCORE_EXPORT static String uniqueName(); 66 67 68 WEBCORE_EXPORT static String platformPasteboardTypeForSafeTypeForDOMToReadAndWrite(const String& domType); 69 67 70 WEBCORE_EXPORT void getTypes(Vector<String>& types); 68 71 WEBCORE_EXPORT RefPtr<SharedBuffer> bufferForType(const String& pasteboardType); 69 WEBCORE_EXPORT void getPathnamesForType(Vector<String>& pathnames, const String& pasteboardType) ;72 WEBCORE_EXPORT void getPathnamesForType(Vector<String>& pathnames, const String& pasteboardType) const; 70 73 WEBCORE_EXPORT String stringForType(const String& pasteboardType); 71 74 WEBCORE_EXPORT long changeCount() const; … … 90 93 WEBCORE_EXPORT URL readURL(int index, const String& pasteboardType, String& title); 91 94 WEBCORE_EXPORT int count(); 92 WEBCORE_EXPORT int numberOfFiles(); 95 WEBCORE_EXPORT int numberOfFiles() const; 96 97 WEBCORE_EXPORT long write(const PasteboardCustomData&); 98 WEBCORE_EXPORT Vector<String> typesSafeForDOMToReadAndWrite() const; 93 99 94 100 #if PLATFORM(GTK) -
trunk/Source/WebCore/platform/StaticPasteboard.cpp
r222228 r222595 27 27 #include "StaticPasteboard.h" 28 28 29 #include "Settings.h" 30 #include "SharedBuffer.h" 31 29 32 namespace WebCore { 30 33 … … 35 38 bool StaticPasteboard::hasData() 36 39 { 37 return !m_ stringContents.isEmpty();40 return !m_platformData.isEmpty() || !m_customData.isEmpty(); 38 41 } 39 42 40 String StaticPasteboard::readString (const String& type)43 String StaticPasteboard::readStringForBindings(const String& type) 41 44 { 42 if (!m_stringContents.contains(type)) 43 return { }; 44 return m_stringContents.get(type); 45 if (m_platformData.contains(type)) 46 return m_platformData.get(type); 47 48 if (m_customData.contains(type)) 49 return m_customData.get(type); 50 51 return { }; 45 52 } 46 53 47 54 void StaticPasteboard::writeString(const String& type, const String& value) 48 55 { 49 auto result = m_stringContents.set(type, value);50 if ( result.isNewEntry)56 auto& pasteboardData = isSafeTypeForDOMToReadAndWrite(type) ? m_platformData : m_customData; 57 if (pasteboardData.set(type, value).isNewEntry) 51 58 m_types.append(type); 52 59 else { … … 59 66 void StaticPasteboard::clear() 60 67 { 61 m_stringContents.clear(); 68 m_customData.clear(); 69 m_platformData.clear(); 62 70 m_types.clear(); 63 71 } … … 65 73 void StaticPasteboard::clear(const String& type) 66 74 { 67 if (!m_ stringContents.remove(type))75 if (!m_platformData.remove(type) && !m_customData.remove(type)) 68 76 return; 69 77 m_types.removeFirst(type); … … 71 79 } 72 80 73 // FIXME: Copy the entire StaticPasteboard to UIProcess instead of writing each string.74 81 void StaticPasteboard::commitToPasteboard(Pasteboard& pasteboard) 75 82 { 76 for (auto& type : m_types) 77 pasteboard.writeString(type, m_stringContents.get(type)); 83 if (m_platformData.isEmpty() && m_customData.isEmpty()) 84 return; 85 86 if (Settings::customPasteboardDataEnabled()) { 87 pasteboard.writeCustomData({ WTFMove(m_types), WTFMove(m_platformData), WTFMove(m_customData) }); 88 return; 89 } 90 91 for (auto& entry : m_platformData) 92 pasteboard.writeString(entry.key, entry.value); 93 for (auto& entry : m_customData) 94 pasteboard.writeString(entry.key, entry.value); 78 95 } 79 96 -
trunk/Source/WebCore/platform/StaticPasteboard.h
r222228 r222595 43 43 bool hasData() final; 44 44 Vector<String> types() final { return m_types; } 45 String readString (const String& type) final;45 String readStringForBindings(const String& type) final; 46 46 47 47 void writeString(const String& type, const String& data) final; … … 68 68 private: 69 69 Vector<String> m_types; 70 HashMap<String, String> m_stringContents; 70 HashMap<String, String> m_platformData; 71 HashMap<String, String> m_customData; 71 72 }; 72 73 -
trunk/Source/WebCore/platform/glib/EventHandlerGLib.cpp
r222392 r222595 102 102 } 103 103 104 #if ENABLE(DRAG_SUPPORT)105 106 Ref<DataTransfer> EventHandler::createDraggingDataTransfer() const107 {108 return DataTransfer::createForDrag();109 }110 111 #endif112 113 104 bool EventHandler::passMousePressEventToSubframe(MouseEventWithHitTestResults& mev, Frame* subframe) 114 105 { -
trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp
r222387 r222595 286 286 } 287 287 288 String Pasteboard::readString (const String& type)288 String Pasteboard::readStringForBindings(const String& type) 289 289 { 290 290 readFromClipboard(); … … 318 318 } 319 319 320 } 320 void Pasteboard::writeCustomData(const PasteboardCustomData&) 321 { 322 } 323 324 } -
trunk/Source/WebCore/platform/gtk/PlatformPasteboardGtk.cpp
r218615 r222595 47 47 } 48 48 49 Vector<String> PlatformPasteboard::typesSafeForDOMToReadAndWrite() const 50 { 51 return { }; 49 52 } 53 54 long PlatformPasteboard::write(const PasteboardCustomData&) 55 { 56 return 0; 57 } 58 59 } -
trunk/Source/WebCore/platform/ios/AbstractPasteboard.h
r221952 r222595 44 44 45 45 - (NSArray<NSString *> *)pasteboardTypes; 46 - (NSData *)dataForPasteboardType:(NSString *)pasteboardType; 46 47 - (NSArray *)dataForPasteboardType:(NSString *)pasteboardType inItemSet:(NSIndexSet *)itemSet; 47 48 - (NSArray *)valuesForPasteboardType:(NSString *)pasteboardType inItemSet:(NSIndexSet *)itemSet; -
trunk/Source/WebCore/platform/ios/PasteboardIOS.mm
r222228 r222595 43 43 #import "NotImplemented.h" 44 44 #import "PasteboardStrategy.h" 45 #import "PlatformPasteboard.h" 45 46 #import "PlatformStrategies.h" 46 47 #import "RenderImage.h" 47 48 #import "RuntimeApplicationChecks.h" 49 #import "Settings.h" 48 50 #import "SharedBuffer.h" 49 51 #import "Text.h" … … 132 134 { 133 135 return std::make_unique<Pasteboard>(changeCountForPasteboard()); 136 } 137 138 void Pasteboard::writeCustomData(const PasteboardCustomData& data) 139 { 140 m_changeCount = platformStrategies()->pasteboardStrategy()->writeCustomData(data, m_pasteboardName); 134 141 } 135 142 … … 321 328 static RetainPtr<NSString> cocoaTypeFromHTMLClipboardType(const String& type) 322 329 { 323 // Ignore any trailing charset - JS strings are Unicode, which encapsulates the charset issue. 324 if (type == "text/plain") 325 #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000 326 return (NSString *)kUTTypePlainText; 327 #else 328 return (NSString *)kUTTypeText; 329 #endif 330 331 // Special case because UTI doesn't work with Cocoa's URL type. 332 if (type == "text/uri-list") 333 return (NSString *)kUTTypeURL; 330 if (NSString *platformType = PlatformPasteboard::platformPasteboardTypeForSafeTypeForDOMToReadAndWrite(type)) { 331 if (platformType.length) 332 return platformType; 333 } 334 334 335 335 // Try UTI now. … … 357 357 } 358 358 359 String Pasteboard::readString(const String& type)359 static String readPlatformValueAsString(const String& domType, long changeCount, const String& pasteboardName) 360 360 { 361 361 PasteboardStrategy& strategy = *platformStrategies()->pasteboardStrategy(); 362 362 363 int numberOfItems = strategy.getPasteboardItemsCount( m_pasteboardName);363 int numberOfItems = strategy.getPasteboardItemsCount(pasteboardName); 364 364 365 365 if (!numberOfItems) … … 367 367 368 368 // Grab the value off the pasteboard corresponding to the cocoaType. 369 RetainPtr<NSString> cocoaType = cocoaTypeFromHTMLClipboardType( type);369 RetainPtr<NSString> cocoaType = cocoaTypeFromHTMLClipboardType(domType); 370 370 371 371 NSString *cocoaValue = nil; … … 373 373 if ([cocoaType isEqualToString:(NSString *)kUTTypeURL]) { 374 374 String title; 375 URL url = strategy.readURLFromPasteboard(0, kUTTypeURL, m_pasteboardName, title);375 URL url = strategy.readURLFromPasteboard(0, kUTTypeURL, pasteboardName, title); 376 376 if (!url.isNull()) 377 377 cocoaValue = [(NSURL *)url absoluteString]; 378 } else if ([cocoaType isEqualToString:(NSString *)kUTType Text]) {379 String value = strategy.readStringFromPasteboard(0, kUTType Text, m_pasteboardName);378 } else if ([cocoaType isEqualToString:(NSString *)kUTTypePlainText]) { 379 String value = strategy.readStringFromPasteboard(0, kUTTypePlainText, pasteboardName); 380 380 if (!value.isNull()) 381 381 cocoaValue = [(NSString *)value precomposedStringWithCanonicalMapping]; 382 } else if (cocoaType) { 383 if (RefPtr<SharedBuffer> buffer = strategy.readBufferFromPasteboard(0, cocoaType.get(), m_pasteboardName)) 384 cocoaValue = [[[NSString alloc] initWithData:buffer->createNSData().get() encoding:NSUTF8StringEncoding] autorelease]; 385 } 382 } else if (cocoaType) 383 cocoaValue = (NSString *)strategy.readStringFromPasteboard(0, cocoaType.get(), pasteboardName); 386 384 387 385 // Enforce changeCount ourselves for security. We check after reading instead of before to be 388 386 // sure it doesn't change between our testing the change count and accessing the data. 389 if (cocoaValue && m_changeCount == changeCountForPasteboard(m_pasteboardName))387 if (cocoaValue && changeCount == changeCountForPasteboard(pasteboardName)) 390 388 return cocoaValue; 391 389 392 390 return String(); 391 } 392 393 String Pasteboard::readStringForBindings(const String& type) 394 { 395 if (!Settings::customPasteboardDataEnabled() || isSafeTypeForDOMToReadAndWrite(type)) 396 return readPlatformValueAsString(type, m_changeCount, m_pasteboardName); 397 398 if (auto buffer = platformStrategies()->pasteboardStrategy()->bufferForType(customWebKitPasteboardDataType, m_pasteboardName)) { 399 NSString *customDataValue = customDataFromSharedBuffer(*buffer).sameOriginCustomData.get(type); 400 if (customDataValue.length) 401 return customDataValue; 402 } 403 404 return { }; 393 405 } 394 406 … … 426 438 Vector<String> Pasteboard::types() 427 439 { 428 Vector<String> cocoaTypes; 429 platformStrategies()->pasteboardStrategy()->getTypes(cocoaTypes, m_pasteboardName); 440 Vector<String> types; 441 if (Settings::customPasteboardDataEnabled()) 442 types = platformStrategies()->pasteboardStrategy()->typesSafeForDOMToReadAndWrite(m_pasteboardName); 443 else 444 platformStrategies()->pasteboardStrategy()->getTypes(types, m_pasteboardName); 430 445 431 446 // Enforce changeCount ourselves for security. We check after reading instead of before to be 432 447 // sure it doesn't change between our testing the change count and accessing the data. 433 if (m_changeCount != changeCountForPasteboard(m_pasteboardName)) 434 return Vector<String>(); 448 auto changeCount = changeCountForPasteboard(m_pasteboardName); 449 if (m_changeCount != changeCount) 450 return { }; 451 452 if (Settings::customPasteboardDataEnabled()) 453 return types; 435 454 436 455 ListHashSet<String> result; 437 for (auto cocoaType : cocoaTypes)456 for (auto cocoaType : types) 438 457 addHTMLClipboardTypesForCocoaType(result, cocoaType); 439 458 -
trunk/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm
r221952 r222595 38 38 #import <UIKit/UIPasteboard.h> 39 39 #import <pal/spi/ios/UIKitSPI.h> 40 #import <wtf/ListHashSet.h> 40 41 #import <wtf/SoftLinking.h> 42 #import <wtf/text/StringHash.h> 41 43 42 44 SOFT_LINK_FRAMEWORK(UIKit) … … 82 84 } 83 85 84 RefPtr<SharedBuffer> PlatformPasteboard::bufferForType(const String&) 85 { 86 RefPtr<SharedBuffer> PlatformPasteboard::bufferForType(const String& type) 87 { 88 if (NSData *data = [m_pasteboard dataForPasteboardType:type]) 89 return SharedBuffer::create(data); 86 90 return nullptr; 87 91 } 88 92 89 void PlatformPasteboard::getPathnamesForType(Vector<String>&, const String&) 90 { 91 } 92 93 int PlatformPasteboard::numberOfFiles() 93 void PlatformPasteboard::getPathnamesForType(Vector<String>&, const String&) const 94 { 95 } 96 97 int PlatformPasteboard::numberOfFiles() const 94 98 { 95 99 return [m_pasteboard respondsToSelector:@selector(numberOfFiles)] ? [m_pasteboard numberOfFiles] : 0; … … 174 178 } 175 179 180 String PlatformPasteboard::platformPasteboardTypeForSafeTypeForDOMToReadAndWrite(const String& domType) 181 { 182 if (domType == "text/plain") 183 return kUTTypePlainText; 184 185 if (domType == "text/html") 186 return kUTTypeHTML; 187 188 if (domType == "text/uri-list") 189 return kUTTypeURL; 190 191 return { }; 192 } 193 176 194 static NSString *webIOSPastePboardType = @"iOS rich content paste pasteboard type"; 177 195 … … 274 292 if (content.dataInRTFFormat) 275 293 [representationsToRegister addData:content.dataInRTFFormat->createNSData().get() forType:(NSString *)kUTTypeRTF]; 294 295 if (!content.dataInHTMLFormat.isEmpty()) { 296 NSData *htmlAsData = [(NSString *)content.dataInHTMLFormat dataUsingEncoding:NSUTF8StringEncoding]; 297 [representationsToRegister addData:htmlAsData forType:(NSString *)kUTTypeHTML]; 298 } 276 299 277 300 if (!content.dataInStringFormat.isEmpty()) … … 397 420 } 398 421 422 static const char *safeTypeForDOMToReadAndWriteForPlatformType(const String& platformType) 423 { 424 auto cfType = platformType.createCFString(); 425 if (UTTypeConformsTo(cfType.get(), kUTTypePlainText)) 426 return ASCIILiteral("text/plain"); 427 428 if (UTTypeConformsTo(cfType.get(), kUTTypeHTML)) 429 return ASCIILiteral("text/html"); 430 431 if (UTTypeConformsTo(cfType.get(), kUTTypeURL)) 432 return ASCIILiteral("text/uri-list"); 433 434 return nullptr; 435 } 436 437 Vector<String> PlatformPasteboard::typesSafeForDOMToReadAndWrite() const 438 { 439 ListHashSet<String> domPasteboardTypes; 440 for (NSItemProvider *provider in [m_pasteboard itemProviders]) { 441 if (!provider.teamData.length) 442 continue; 443 444 id teamDataObject = [NSKeyedUnarchiver unarchiveObjectWithData:provider.teamData]; 445 if (!teamDataObject || ![teamDataObject isKindOfClass:[NSDictionary class]]) 446 continue; 447 448 id customTypes = [(NSDictionary *)teamDataObject objectForKey:@(customWebKitPasteboardDataType)]; 449 if (![customTypes isKindOfClass:[NSArray class]]) 450 continue; 451 452 for (NSString *type in customTypes) 453 domPasteboardTypes.add(type); 454 } 455 456 if (NSData *serializedCustomData = [m_pasteboard dataForPasteboardType:@(customWebKitPasteboardDataType)]) { 457 auto buffer = SharedBuffer::create(serializedCustomData); 458 for (auto& type : customDataFromSharedBuffer(buffer.get()).orderedTypes) 459 domPasteboardTypes.add(type); 460 } 461 462 for (NSString *type in [m_pasteboard pasteboardTypes]) { 463 if ([type isEqualToString:@(customWebKitPasteboardDataType)]) 464 continue; 465 466 if (isSafeTypeForDOMToReadAndWrite(type)) { 467 domPasteboardTypes.add(type); 468 continue; 469 } 470 471 if (auto* coercedType = safeTypeForDOMToReadAndWriteForPlatformType(type)) 472 domPasteboardTypes.add(String::fromUTF8(coercedType)); 473 } 474 475 Vector<String> result; 476 copyToVector(domPasteboardTypes, result); 477 return result; 478 } 479 480 long PlatformPasteboard::write(const PasteboardCustomData& data) 481 { 482 auto representationsToRegister = adoptNS([[WebItemProviderRegistrationInfoList alloc] init]); 483 [representationsToRegister setPreferredPresentationStyle:WebPreferredPresentationStyleInline]; 484 485 if (data.sameOriginCustomData.size()) { 486 if (auto serializedSharedBuffer = sharedBufferFromCustomData(data)->createNSData()) { 487 // We stash the list of supplied pasteboard types in teamData here for compatibility with drag and drop. 488 // Since the contents of item providers cannot be loaded prior to drop, but the pasteboard types are 489 // contained within the custom data blob and we need to vend them to the page when firing `dragover` 490 // events, we need an additional in-memory representation of the pasteboard types array that contains 491 // all of the custom types. We use the teamData property, available on NSItemProvider on iOS, to store 492 // this information, since the contents of teamData are immediately available prior to the drop. 493 NSMutableArray<NSString *> *typesAsNSArray = [NSMutableArray array]; 494 for (auto& type : data.orderedTypes) 495 [typesAsNSArray addObject:type]; 496 [representationsToRegister setTeamData:[NSKeyedArchiver archivedDataWithRootObject:@{ @(customWebKitPasteboardDataType) : typesAsNSArray }]]; 497 [representationsToRegister addData:serializedSharedBuffer.get() forType:@(customWebKitPasteboardDataType)]; 498 } 499 } 500 501 for (auto& type : data.orderedTypes) { 502 NSString *stringValue = data.platformData.get(type); 503 if (!stringValue.length) 504 continue; 505 506 auto cocoaType = platformPasteboardTypeForSafeTypeForDOMToReadAndWrite(type).createCFString(); 507 if (UTTypeConformsTo(cocoaType.get(), kUTTypeURL)) 508 [representationsToRegister addRepresentingObject:[NSURL URLWithString:stringValue]]; 509 else if (UTTypeConformsTo(cocoaType.get(), kUTTypePlainText)) 510 [representationsToRegister addRepresentingObject:stringValue]; 511 else 512 [representationsToRegister addData:[stringValue dataUsingEncoding:NSUTF8StringEncoding] forType:(NSString *)cocoaType.get()]; 513 } 514 515 registerItemToPasteboard(representationsToRegister.get(), m_pasteboard.get()); 516 return [m_pasteboard changeCount]; 517 } 518 399 519 int PlatformPasteboard::count() 400 520 { … … 417 537 NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:index]; 418 538 419 RetainPtr<NSArray> pasteboardItem = [m_pasteboard valuesForPasteboardType:type inItemSet:indexSet]; 420 421 if (![pasteboardItem count]) 422 return String(); 423 424 id value = [pasteboardItem objectAtIndex:0]; 539 NSArray *pasteboardValues = [m_pasteboard valuesForPasteboardType:type inItemSet:indexSet]; 540 if (!pasteboardValues.count) { 541 NSArray<NSData *> *pasteboardData = [m_pasteboard dataForPasteboardType:type inItemSet:indexSet]; 542 if (!pasteboardData.count) 543 return { }; 544 pasteboardValues = pasteboardData; 545 } 546 547 RetainPtr<id> value = [pasteboardValues objectAtIndex:0]; 548 if ([value isKindOfClass:[NSData class]]) 549 value = adoptNS([[NSString alloc] initWithData:(NSData *)value.get() encoding:NSUTF8StringEncoding]); 425 550 426 551 if (type == String(kUTTypePlainText) || type == String(kUTTypeHTML)) { 427 552 ASSERT([value isKindOfClass:[NSString class]]); 428 return [value isKindOfClass:[NSString class]] ? value : nil;553 return [value isKindOfClass:[NSString class]] ? value.get() : nil; 429 554 } 430 555 if (type == String(kUTTypeText)) { 431 556 ASSERT([value isKindOfClass:[NSString class]] || [value isKindOfClass:[NSAttributedString class]]); 432 557 if ([value isKindOfClass:[NSString class]]) 433 return value ;558 return value.get(); 434 559 if ([value isKindOfClass:[NSAttributedString class]]) 435 560 return [(NSAttributedString *)value string]; 436 561 } else if (type == String(kUTTypeURL)) { 437 ASSERT([value isKindOfClass:[NSURL class]]); 562 ASSERT([value isKindOfClass:[NSURL class]] || [value isKindOfClass:[NSString class]]); 563 if ([value isKindOfClass:[NSString class]]) 564 value = [NSURL URLWithString:value.get()]; 438 565 if ([value isKindOfClass:[NSURL class]] && allowReadingURLAtIndex((NSURL *)value, index)) 439 566 return [(NSURL *)value absoluteString]; -
trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.h
r221952 r222595 72 72 73 73 @property (nonatomic) WebPreferredPresentationStyle preferredPresentationStyle; 74 @property (nonatomic, copy) NSData *teamData; 74 75 75 76 - (NSUInteger)numberOfItems; -
trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.mm
r221952 r222595 51 51 52 52 typedef void(^ItemProviderDataLoadCompletionHandler)(NSData *, NSError *); 53 typedef NS Dictionary<NSString *, NSURL *> TypeToFileURLMap;53 typedef NSMutableDictionary<NSString *, NSURL *> TypeToFileURLMap; 54 54 55 55 @interface WebItemProviderRegistrationInfo () … … 189 189 [itemProvider setSuggestedName:self.suggestedName]; 190 190 [itemProvider setPreferredPresentationStyle:uiPreferredPresentationStyle(self.preferredPresentationStyle)]; 191 [itemProvider setTeamData:self.teamData]; 191 192 return itemProvider.autorelease(); 192 193 } … … 213 214 @interface WebItemProviderLoadResult : NSObject 214 215 215 + (instancetype)loadResultWithFileURLMap:(TypeToFileURLMap *)fileURLs presentationStyle:(UIPreferredPresentationStyle)presentationStyle; 216 + (instancetype)emptyLoadResult; 217 216 - (instancetype)initWithItemProvider:(NSItemProvider *)itemProvider typesToLoad:(NSArray<NSString *> *)typesToLoad; 218 217 - (NSURL *)fileURLForType:(NSString *)type; 218 - (void)setFileURL:(NSURL *)url forType:(NSString *)type; 219 219 @property (nonatomic, readonly) NSArray<NSURL *> *loadedFileURLs; 220 220 @property (nonatomic, readonly) NSArray<NSString *> *loadedTypeIdentifiers; 221 221 @property (nonatomic, readonly) BOOL canBeRepresentedAsFileUpload; 222 @property (nonatomic, readonly) NSItemProvider *itemProvider; 223 @property (nonatomic, readonly) NSArray<NSString *> *typesToLoad; 222 224 223 225 @end … … 225 227 @implementation WebItemProviderLoadResult { 226 228 RetainPtr<TypeToFileURLMap> _fileURLs; 227 } 228 229 + (instancetype)emptyLoadResult 230 { 231 return [[[self alloc] initWithFileURLMap:@{ } presentationStyle:UIPreferredPresentationStyleUnspecified] autorelease]; 232 } 233 234 + (instancetype)loadResultWithFileURLMap:(TypeToFileURLMap *)fileURLs presentationStyle:(UIPreferredPresentationStyle)presentationStyle 235 { 236 return [[[self alloc] initWithFileURLMap:fileURLs presentationStyle:presentationStyle] autorelease]; 237 } 238 239 - (instancetype)initWithFileURLMap:(TypeToFileURLMap *)fileURLs presentationStyle:(UIPreferredPresentationStyle)presentationStyle 229 RetainPtr<NSItemProvider> _itemProvider; 230 RetainPtr<NSArray<NSString *>> _typesToLoad; 231 } 232 233 + (instancetype)loadResultWithItemProvider:(NSItemProvider *)itemProvider typesToLoad:(NSArray<NSString *> *)typesToLoad 234 { 235 return [[[self alloc] initWithItemProvider:itemProvider typesToLoad:typesToLoad] autorelease]; 236 } 237 238 - (instancetype)initWithItemProvider:(NSItemProvider *)itemProvider typesToLoad:(NSArray<NSString *> *)typesToLoad 240 239 { 241 240 if (!(self = [super init])) 242 241 return nil; 243 242 244 _fileURLs = fileURLs; 245 _canBeRepresentedAsFileUpload = presentationStyle != UIPreferredPresentationStyleInline; 243 _fileURLs = adoptNS([[NSMutableDictionary alloc] init]); 244 _itemProvider = itemProvider; 245 _typesToLoad = typesToLoad; 246 _canBeRepresentedAsFileUpload = itemProvider.preferredPresentationStyle != UIPreferredPresentationStyleInline; 246 247 247 248 return self; 248 249 } 249 250 251 - (NSArray<NSString *> *)typesToLoad 252 { 253 return _typesToLoad.get(); 254 } 255 250 256 - (NSURL *)fileURLForType:(NSString *)type 251 257 { … … 253 259 } 254 260 261 - (void)setFileURL:(NSURL *)url forType:(NSString *)type 262 { 263 [_fileURLs setObject:url forKey:type]; 264 } 265 255 266 - (NSArray<NSURL *> *)loadedFileURLs 256 267 { … … 261 272 { 262 273 return [_fileURLs allKeys]; 274 } 275 276 - (NSItemProvider *)itemProvider 277 { 278 return _itemProvider.get(); 263 279 } 264 280 … … 344 360 _itemProviders = itemProviders; 345 361 _changeCount++; 362 363 if (!itemProviders.count) 364 _loadResults = { }; 346 365 } 347 366 … … 368 387 } 369 388 return nil; 389 } 390 391 - (NSData *)dataForPasteboardType:(NSString *)pasteboardType 392 { 393 return [self dataForPasteboardType:pasteboardType inItemSet:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, self.numberOfItems)]].firstObject; 370 394 } 371 395 … … 505 529 } 506 530 507 - (NSString *)typeIdentifierToLoadForRegisteredTypeIdentfiers:(NSArray<NSString *> *)registeredTypeIdentifiers 508 { 531 - (NSArray<NSString *> *)typeIdentifiersToLoadForRegisteredTypeIdentfiers:(NSArray<NSString *> *)registeredTypeIdentifiers 532 { 533 NSMutableSet *typesToLoad = [NSMutableSet set]; 509 534 NSString *highestFidelityContentType = nil; 535 536 // First, we want to either load the highest fidelity supported type or the highest fidelity generic content type. 510 537 for (NSString *registeredTypeIdentifier in registeredTypeIdentifiers) { 511 if (typeConformsToTypes(registeredTypeIdentifier, _supportedTypeIdentifiers.get())) 512 return registeredTypeIdentifier; 538 if (typeConformsToTypes(registeredTypeIdentifier, _supportedTypeIdentifiers.get())) { 539 [typesToLoad addObject:registeredTypeIdentifier]; 540 break; 541 } 513 542 514 543 if (!highestFidelityContentType && UTTypeConformsTo((CFStringRef)registeredTypeIdentifier, kUTTypeContent)) 515 544 highestFidelityContentType = registeredTypeIdentifier; 516 545 } 517 return highestFidelityContentType; 546 if (!typesToLoad.count && highestFidelityContentType) 547 [typesToLoad addObject:highestFidelityContentType]; 548 549 // For compatibility with DataTransfer APIs, additionally load web-exposed types. Since this is the only chance to 550 // fault in any data at all, we need to load up front any information that the page may ask for later down the line. 551 NSString *customPasteboardDataUTI = @(customWebKitPasteboardDataType); 552 for (NSString *registeredTypeIdentifier in registeredTypeIdentifiers) { 553 if ([typesToLoad containsObject:registeredTypeIdentifier]) 554 continue; 555 if ([registeredTypeIdentifier isEqualToString:customPasteboardDataUTI]) 556 [typesToLoad addObject:customPasteboardDataUTI]; 557 if (UTTypeConformsTo((CFStringRef)registeredTypeIdentifier, kUTTypeURL)) 558 [typesToLoad addObject:(NSString *)kUTTypeURL]; 559 if (UTTypeConformsTo((CFStringRef)registeredTypeIdentifier, kUTTypeHTML)) 560 [typesToLoad addObject:(NSString *)kUTTypeHTML]; 561 if (UTTypeConformsTo((CFStringRef)registeredTypeIdentifier, kUTTypePlainText)) 562 [typesToLoad addObject:(NSString *)kUTTypePlainText]; 563 } 564 565 return typesToLoad.allObjects; 518 566 } 519 567 … … 531 579 532 580 // First, figure out which item providers we want to try and load files from. 533 auto itemProvidersToLoad = adoptNS([[NSMutableArray alloc] init]); 534 auto typeIdentifiersToLoad = adoptNS([[NSMutableArray alloc] init]); 535 auto indicesOfitemProvidersToLoad = adoptNS([[NSMutableArray alloc] init]); 581 BOOL foundAnyDataToLoad = NO; 536 582 RetainPtr<WebItemProviderPasteboard> protectedSelf = self; 537 [_itemProviders enumerateObjectsUsingBlock:[protectedSelf, itemProvidersToLoad, typeIdentifiersToLoad, indicesOfitemProvidersToLoad, loadResults] (UIItemProvider *itemProvider, NSUInteger index, BOOL *) { 538 NSString *typeIdentifierToLoad = [protectedSelf typeIdentifierToLoadForRegisteredTypeIdentfiers:itemProvider.registeredTypeIdentifiers]; 539 if (typeIdentifierToLoad) { 540 [itemProvidersToLoad addObject:itemProvider]; 541 [typeIdentifiersToLoad addObject:typeIdentifierToLoad]; 542 [indicesOfitemProvidersToLoad addObject:@(index)]; 543 } 544 [loadResults addObject:[WebItemProviderLoadResult emptyLoadResult]]; 545 }]; 546 547 if (![itemProvidersToLoad count]) { 583 for (NSItemProvider *itemProvider in _itemProviders.get()) { 584 NSArray<NSString *> *typeIdentifiersToLoad = [protectedSelf typeIdentifiersToLoadForRegisteredTypeIdentfiers:itemProvider.registeredTypeIdentifiers]; 585 foundAnyDataToLoad |= typeIdentifiersToLoad.count; 586 [loadResults addObject:[WebItemProviderLoadResult loadResultWithItemProvider:itemProvider typesToLoad:typeIdentifiersToLoad]]; 587 } 588 589 if (!foundAnyDataToLoad) { 548 590 action(@[ ]); 549 591 return; … … 553 595 auto synchronousFileLoadingGroup = adoptOSObject(dispatch_group_create()); 554 596 auto fileLoadingGroup = adoptOSObject(dispatch_group_create()); 555 for (NSUInteger index = 0; index < [itemProvidersToLoad count]; ++index) { 556 RetainPtr<UIItemProvider> itemProvider = [itemProvidersToLoad objectAtIndex:index]; 557 RetainPtr<NSString> typeIdentifier = [typeIdentifiersToLoad objectAtIndex:index]; 558 NSUInteger indexInItemProviderArray = [[indicesOfitemProvidersToLoad objectAtIndex:index] unsignedIntegerValue]; 559 RetainPtr<NSString> suggestedName = [itemProvider suggestedName]; 560 auto presentationStyle = [itemProvider preferredPresentationStyle]; 561 dispatch_group_enter(fileLoadingGroup.get()); 562 dispatch_group_enter(synchronousFileLoadingGroup.get()); 563 [itemProvider loadFileRepresentationForTypeIdentifier:typeIdentifier.get() completionHandler:[synchronousFileLoadingGroup, setFileURLsLock, indexInItemProviderArray, suggestedName, typeIdentifier, loadResults, fileLoadingGroup, presentationStyle] (NSURL *url, NSError *) { 564 // After executing this completion block, UIKit removes the file at the given URL. However, we need this data to persist longer for the web content process. 565 // To address this, we hard link the given URL to a new temporary file in the temporary directory. This follows the same flow as regular file upload, in 566 // WKFileUploadPanel.mm. The temporary files are cleaned up by the system at a later time. 567 if (NSURL *destination = linkTemporaryItemProviderFilesToDropStagingDirectory(url, suggestedName.get(), typeIdentifier.get())) { 568 WebItemProviderLoadResult *loadResult = [WebItemProviderLoadResult loadResultWithFileURLMap:@{ typeIdentifier.get() : destination } presentationStyle:presentationStyle]; 569 [setFileURLsLock lock]; 570 [loadResults setObject:loadResult atIndexedSubscript:indexInItemProviderArray]; 571 [setFileURLsLock unlock]; 572 } 573 dispatch_group_leave(fileLoadingGroup.get()); 574 dispatch_group_leave(synchronousFileLoadingGroup.get()); 575 }]; 597 for (WebItemProviderLoadResult *loadResult in loadResults.get()) { 598 for (NSString *typeToLoad in loadResult.typesToLoad) { 599 dispatch_group_enter(fileLoadingGroup.get()); 600 dispatch_group_enter(synchronousFileLoadingGroup.get()); 601 [loadResult.itemProvider loadFileRepresentationForTypeIdentifier:typeToLoad completionHandler:[protectedLoadResult = retainPtr(loadResult), synchronousFileLoadingGroup, setFileURLsLock, protectedTypeToLoad = retainPtr(typeToLoad), fileLoadingGroup] (NSURL *url, NSError *) { 602 // After executing this completion block, UIKit removes the file at the given URL. However, we need this data to persist longer for the web content process. 603 // To address this, we hard link the given URL to a new temporary file in the temporary directory. This follows the same flow as regular file upload, in 604 // WKFileUploadPanel.mm. The temporary files are cleaned up by the system at a later time. 605 if (NSURL *destination = linkTemporaryItemProviderFilesToDropStagingDirectory(url, [protectedLoadResult itemProvider].suggestedName, protectedTypeToLoad.get())) { 606 [setFileURLsLock lock]; 607 [protectedLoadResult setFileURL:destination forType:protectedTypeToLoad.get()]; 608 [setFileURLsLock unlock]; 609 } 610 dispatch_group_leave(fileLoadingGroup.get()); 611 dispatch_group_leave(synchronousFileLoadingGroup.get()); 612 }]; 613 } 576 614 } 577 615 -
trunk/Source/WebCore/platform/mac/PasteboardMac.mm
r222257 r222595 44 44 #import "MIMETypeRegistry.h" 45 45 #import "PasteboardStrategy.h" 46 #import "PlatformPasteboard.h" 46 47 #import "PlatformStrategies.h" 47 48 #import "RenderImage.h" 49 #import "Settings.h" 48 50 #import "Text.h" 49 51 #import "URL.h" … … 196 198 } 197 199 200 void Pasteboard::writeCustomData(const PasteboardCustomData& data) 201 { 202 m_changeCount = platformStrategies()->pasteboardStrategy()->writeCustomData(data, m_pasteboardName); 203 } 204 198 205 void Pasteboard::writePlainText(const String& text, SmartReplaceOption smartReplaceOption) 199 206 { … … 461 468 static String cocoaTypeFromHTMLClipboardType(const String& type) 462 469 { 463 // Ignore any trailing charset - strings are already UTF-16, and the charset issue has already been dealt with. 464 if (type == "text/plain") 465 return NSStringPboardType; 466 if (type == "text/uri-list") { 467 // Special case because UTI doesn't work with Cocoa's URL type. 468 return NSURLPboardType; 470 if (NSString *platformType = PlatformPasteboard::platformPasteboardTypeForSafeTypeForDOMToReadAndWrite(type)) { 471 if (platformType.length) 472 return platformType; 469 473 } 470 474 … … 508 512 } 509 513 510 String Pasteboard::readString(const String& type)511 { 512 const String& cocoaType = cocoaTypeFromHTMLClipboardType( type);514 static String readPlatformValueAsString(const String& domType, long changeCount, const String& pasteboardName) 515 { 516 const String& cocoaType = cocoaTypeFromHTMLClipboardType(domType); 513 517 String cocoaValue; 514 518 515 519 if (cocoaType == String(NSStringPboardType)) 516 cocoaValue = [platformStrategies()->pasteboardStrategy()->stringForType(cocoaType, m_pasteboardName) precomposedStringWithCanonicalMapping];520 cocoaValue = [platformStrategies()->pasteboardStrategy()->stringForType(cocoaType, pasteboardName) precomposedStringWithCanonicalMapping]; 517 521 else if (!cocoaType.isEmpty()) 518 cocoaValue = platformStrategies()->pasteboardStrategy()->stringForType(cocoaType, m_pasteboardName);522 cocoaValue = platformStrategies()->pasteboardStrategy()->stringForType(cocoaType, pasteboardName); 519 523 520 524 // Enforce changeCount ourselves for security. We check after reading instead of before to be 521 525 // sure it doesn't change between our testing the change count and accessing the data. 522 if (!cocoaValue.isEmpty() && m_changeCount == platformStrategies()->pasteboardStrategy()->changeCount(m_pasteboardName))526 if (!cocoaValue.isEmpty() && changeCount == platformStrategies()->pasteboardStrategy()->changeCount(pasteboardName)) 523 527 return cocoaValue; 524 528 525 529 return String(); 530 } 531 532 String Pasteboard::readStringForBindings(const String& type) 533 { 534 if (!Settings::customPasteboardDataEnabled() || isSafeTypeForDOMToReadAndWrite(type)) 535 return readPlatformValueAsString(type, m_changeCount, m_pasteboardName); 536 537 if (auto buffer = platformStrategies()->pasteboardStrategy()->bufferForType(customWebKitPasteboardDataType, m_pasteboardName)) { 538 NSString *customDataValue = customDataFromSharedBuffer(*buffer).sameOriginCustomData.get(type); 539 if (customDataValue.length) 540 return customDataValue; 541 } 542 543 return { }; 526 544 } 527 545 … … 595 613 { 596 614 Vector<String> types; 597 platformStrategies()->pasteboardStrategy()->getTypes(types, m_pasteboardName); 615 if (Settings::customPasteboardDataEnabled()) 616 types = platformStrategies()->pasteboardStrategy()->typesSafeForDOMToReadAndWrite(m_pasteboardName); 617 else 618 platformStrategies()->pasteboardStrategy()->getTypes(types, m_pasteboardName); 598 619 599 620 // Enforce changeCount ourselves for security. We check after reading instead of before to be 600 621 // sure it doesn't change between our testing the change count and accessing the data. 601 622 if (m_changeCount != platformStrategies()->pasteboardStrategy()->changeCount(m_pasteboardName)) 602 return Vector<String>(); 623 return { }; 624 625 if (Settings::customPasteboardDataEnabled()) 626 return types; 603 627 604 628 ListHashSet<String> result; -
trunk/Source/WebCore/platform/mac/PlatformPasteboardMac.mm
r215686 r222595 25 25 26 26 #import "config.h" 27 #import "PlatformPasteboard.h" 28 27 29 #import "Color.h" 30 #import "Pasteboard.h" 31 #import "Settings.h" 28 32 #import "URL.h" 29 #import "PlatformPasteboard.h"30 33 #import "SharedBuffer.h" 34 #import <wtf/HashCountedSet.h> 35 #import <wtf/ListHashSet.h> 36 #import <wtf/text/StringHash.h> 31 37 32 38 namespace WebCore { … … 54 60 } 55 61 56 int PlatformPasteboard::numberOfFiles() 62 int PlatformPasteboard::numberOfFiles() const 57 63 { 58 64 Vector<String> files; … … 63 69 } 64 70 65 void PlatformPasteboard::getPathnamesForType(Vector<String>& pathnames, const String& pasteboardType) 71 void PlatformPasteboard::getPathnamesForType(Vector<String>& pathnames, const String& pasteboardType) const 66 72 { 67 73 NSArray* paths = [m_pasteboard.get() propertyListForType:pasteboardType]; … … 76 82 String PlatformPasteboard::stringForType(const String& pasteboardType) 77 83 { 78 if (pasteboardType == String(NSURLPboardType)) 79 return [[NSURL URLFromPasteboard:m_pasteboard.get()] absoluteString]; 80 81 return [m_pasteboard.get() stringForType:pasteboardType]; 84 if (pasteboardType == String(NSURLPboardType)) { 85 if (NSURL *urlFromPasteboard = [NSURL URLFromPasteboard:m_pasteboard.get()]) 86 return urlFromPasteboard.absoluteString; 87 88 URL url([NSURL URLWithString:[m_pasteboard stringForType:NSURLPboardType]]); 89 if (!url.isValid()) 90 return { }; 91 return url.string(); 92 } 93 94 return [m_pasteboard stringForType:pasteboardType]; 95 } 96 97 static const char* safeTypeForDOMToReadAndWriteForPlatformType(const String& platformType) 98 { 99 if (platformType == String(NSStringPboardType) || platformType == String(NSPasteboardTypeString)) 100 return ASCIILiteral("text/plain"); 101 102 if (platformType == String(NSURLPboardType)) 103 return ASCIILiteral("text/uri-list"); 104 105 if (platformType == String(NSHTMLPboardType)) 106 return ASCIILiteral("text/html"); 107 108 if (platformType == String(NSFilenamesPboardType) || platformType == String(NSFilesPromisePboardType)) 109 return ASCIILiteral("Files"); 110 111 return nullptr; 112 } 113 114 Vector<String> PlatformPasteboard::typesSafeForDOMToReadAndWrite() const 115 { 116 ListHashSet<String> domPasteboardTypes; 117 if (NSData *serializedCustomData = [m_pasteboard dataForType:@(customWebKitPasteboardDataType)]) { 118 auto buffer = SharedBuffer::create(serializedCustomData); 119 for (auto& type : customDataFromSharedBuffer(buffer.get()).orderedTypes) 120 domPasteboardTypes.add(type); 121 } 122 123 NSArray<NSString *> *allTypes = [m_pasteboard types]; 124 for (NSString *type in allTypes) { 125 if ([type isEqualToString:@(customWebKitPasteboardDataType)]) 126 continue; 127 128 if (isSafeTypeForDOMToReadAndWrite(type)) 129 domPasteboardTypes.add(type); 130 else if (auto* domType = safeTypeForDOMToReadAndWriteForPlatformType(type)) { 131 auto coercedType = String::fromUTF8(domType); 132 if (coercedType == "Files" && !numberOfFiles()) 133 continue; 134 domPasteboardTypes.add(WTFMove(coercedType)); 135 } 136 } 137 138 Vector<String> result; 139 copyToVector(domPasteboardTypes, result); 140 return result; 141 } 142 143 long PlatformPasteboard::write(const PasteboardCustomData& data) 144 { 145 NSMutableArray *types = [NSMutableArray array]; 146 for (auto& entry : data.platformData) 147 [types addObject:platformPasteboardTypeForSafeTypeForDOMToReadAndWrite(entry.key)]; 148 if (data.sameOriginCustomData.size()) 149 [types addObject:@(customWebKitPasteboardDataType)]; 150 151 [m_pasteboard declareTypes:types owner:nil]; 152 153 for (auto& entry : data.platformData) { 154 auto platformType = platformPasteboardTypeForSafeTypeForDOMToReadAndWrite(entry.key); 155 ASSERT(!platformType.isEmpty()); 156 if (!platformType.isEmpty()) 157 [m_pasteboard setString:entry.value forType:platformType]; 158 } 159 160 if (data.sameOriginCustomData.size()) { 161 if (auto serializedCustomData = sharedBufferFromCustomData(data)->createNSData()) 162 [m_pasteboard setData:serializedCustomData.get() forType:@(customWebKitPasteboardDataType)]; 163 } 164 165 return changeCount(); 82 166 } 83 167 … … 85 169 { 86 170 return [m_pasteboard.get() changeCount]; 171 } 172 173 String PlatformPasteboard::platformPasteboardTypeForSafeTypeForDOMToReadAndWrite(const String& domType) 174 { 175 if (domType == "text/plain") 176 return NSStringPboardType; 177 178 if (domType == "text/html") 179 return NSHTMLPboardType; 180 181 if (domType == "text/uri-list") 182 return NSURLPboardType; 183 184 return { }; 87 185 } 88 186 -
trunk/Source/WebCore/platform/win/PasteboardWin.cpp
r222228 r222595 278 278 } 279 279 280 String Pasteboard::readString (const String& type)280 String Pasteboard::readStringForBindings(const String& type) 281 281 { 282 282 if (!m_dataObject && m_dragDataMap.isEmpty()) … … 1055 1055 } 1056 1056 1057 void Pasteboard::writeCustomData(const PasteboardCustomData&) 1058 { 1059 } 1060 1057 1061 } // namespace WebCore -
trunk/Source/WebCore/platform/wpe/PasteboardWPE.cpp
r222228 r222595 57 57 } 58 58 59 String Pasteboard::readString (const String& type)59 String Pasteboard::readStringForBindings(const String& type) 60 60 { 61 61 return platformStrategies()->pasteboardStrategy()->readStringFromPasteboard(0, type); … … 123 123 } 124 124 125 void Pasteboard::writeCustomData(const PasteboardCustomData&) 126 { 127 } 128 125 129 } // namespace WebCore -
trunk/Source/WebCore/platform/wpe/PlatformPasteboardWPE.cpp
r221562 r222595 117 117 } 118 118 119 Vector<String> PlatformPasteboard::typesSafeForDOMToReadAndWrite() const 120 { 121 return { }; 122 } 123 124 long PlatformPasteboard::write(const PasteboardCustomData&) 125 { 126 return 0; 127 } 128 119 129 } // namespace WebCore -
trunk/Source/WebCore/testing/InternalSettings.cpp
r222516 r222595 115 115 , m_shouldManageAudioSessionCategory(Settings::shouldManageAudioSessionCategory()) 116 116 #endif 117 , m_customPasteboardDataEnabled(Settings::customPasteboardDataEnabled()) 117 118 { 118 119 } … … 211 212 Settings::setShouldManageAudioSessionCategory(m_shouldManageAudioSessionCategory); 212 213 #endif 214 Settings::setCustomPasteboardDataEnabled(m_customPasteboardDataEnabled); 213 215 } 214 216 … … 853 855 } 854 856 857 ExceptionOr<void> InternalSettings::setCustomPasteboardDataEnabled(bool enabled) 858 { 859 Settings::setCustomPasteboardDataEnabled(enabled); 860 return { }; 861 } 862 855 863 static InternalSettings::ForcedAccessibilityValue settingsToInternalSettingsValue(Settings::ForcedAccessibilityValue value) 856 864 { -
trunk/Source/WebCore/testing/InternalSettings.h
r221966 r222595 98 98 ExceptionOr<void> setShouldMockBoldSystemFontForAccessibility(bool); 99 99 ExceptionOr<void> setShouldManageAudioSessionCategory(bool); 100 ExceptionOr<void> setCustomPasteboardDataEnabled(bool); 100 101 101 102 enum class FrameFlatteningValue { Disabled, EnabledForNonFullScreenIFrames, FullyEnabled }; … … 205 206 bool m_shouldManageAudioSessionCategory; 206 207 #endif 208 bool m_customPasteboardDataEnabled; 207 209 }; 208 210 -
trunk/Source/WebCore/testing/InternalSettings.idl
r221966 r222595 107 107 108 108 [MayThrowException] void setShouldManageAudioSessionCategory(boolean should); 109 [MayThrowException] void setCustomPasteboardDataEnabled(boolean enabled); 109 110 }; 110 111 -
trunk/Source/WebKit/ChangeLog
r222584 r222595 1 2017-09-27 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 Drag event DataTransfer has unexpected types "dyn.ah62d4..." 4 https://bugs.webkit.org/show_bug.cgi?id=172526 5 <rdar://problem/32396081> 6 7 Reviewed by Ryosuke Niwa. 8 9 Add boilerplate plumbing and encoder/decoder support for new pasteboard codepaths. See WebCore ChangeLog for 10 more details. 11 12 * Scripts/webkit/messages.py: 13 (headers_for_type): 14 * Shared/WebCoreArgumentCoders.cpp: 15 (IPC::ArgumentCoder<PasteboardCustomData>::encode): 16 (IPC::ArgumentCoder<PasteboardCustomData>::decode): 17 18 Add encoder/decoder support for PasteboardCustomData. 19 20 (IPC::ArgumentCoder<PasteboardWebContent>::encode): 21 (IPC::ArgumentCoder<PasteboardWebContent>::decode): 22 23 Encode and decode dataInHTMLFormat. 24 25 * Shared/WebCoreArgumentCoders.h: 26 * UIProcess/Cocoa/WebPasteboardProxyCocoa.mm: 27 (WebKit::WebPasteboardProxy::typesSafeForDOMToReadAndWrite): 28 (WebKit::WebPasteboardProxy::writeCustomData): 29 * UIProcess/WebPasteboardProxy.cpp: 30 (WebKit::WebPasteboardProxy::typesSafeForDOMToReadAndWrite): 31 (WebKit::WebPasteboardProxy::writeCustomData): 32 * UIProcess/WebPasteboardProxy.h: 33 * UIProcess/WebPasteboardProxy.messages.in: 34 * WebProcess/WebCoreSupport/WebPlatformStrategies.cpp: 35 (WebKit::WebPlatformStrategies::typesSafeForDOMToReadAndWrite): 36 (WebKit::WebPlatformStrategies::writeCustomData): 37 * WebProcess/WebCoreSupport/WebPlatformStrategies.h: 38 1 39 2017-09-27 Alex Christensen <achristensen@webkit.org> 2 40 -
trunk/Source/WebKit/Scripts/webkit/messages.py
r222492 r222595 364 364 'WebCore::KeypressCommand': ['<WebCore/KeyboardEvent.h>'], 365 365 'WebCore::MediaConstraints': ['<WebCore/MediaConstraints.h>'], 366 'WebCore::PasteboardCustomData': ['<WebCore/Pasteboard.h>'], 366 367 'WebCore::PasteboardImage': ['<WebCore/Pasteboard.h>'], 367 368 'WebCore::PasteboardURL': ['<WebCore/Pasteboard.h>'], -
trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp
r222584 r222595 92 92 #endif // PLATFORM(IOS) 93 93 94 #if PLATFORM( IOS) || PLATFORM(WPE)94 #if PLATFORM(COCOA) || PLATFORM(WPE) || PLATFORM(GTK) 95 95 #include <WebCore/Pasteboard.h> 96 96 #endif … … 1579 1579 } 1580 1580 1581 void ArgumentCoder<PasteboardCustomData>::encode(Encoder& encoder, const PasteboardCustomData& data) 1582 { 1583 encoder << data.orderedTypes; 1584 encoder << data.platformData; 1585 encoder << data.sameOriginCustomData; 1586 } 1587 1588 bool ArgumentCoder<PasteboardCustomData>::decode(Decoder& decoder, PasteboardCustomData& data) 1589 { 1590 if (!decoder.decode(data.orderedTypes)) 1591 return false; 1592 1593 if (!decoder.decode(data.platformData)) 1594 return false; 1595 1596 if (!decoder.decode(data.sameOriginCustomData)) 1597 return false; 1598 1599 return true; 1600 } 1601 1581 1602 #if PLATFORM(IOS) 1582 1603 … … 1665 1686 encoder << content.canSmartCopyOrDelete; 1666 1687 encoder << content.dataInStringFormat; 1688 encoder << content.dataInHTMLFormat; 1667 1689 1668 1690 encodeSharedBuffer(encoder, content.dataInWebArchiveFormat.get()); … … 1679 1701 return false; 1680 1702 if (!decoder.decode(content.dataInStringFormat)) 1703 return false; 1704 if (!decoder.decode(content.dataInHTMLFormat)) 1681 1705 return false; 1682 1706 if (!decodeSharedBuffer(decoder, content.dataInWebArchiveFormat)) -
trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h
r222584 r222595 100 100 struct MimeClassInfo; 101 101 struct PasteboardImage; 102 struct PasteboardCustomData; 102 103 struct PasteboardURL; 103 104 struct PluginInfo; … … 426 427 #endif 427 428 429 template<> struct ArgumentCoder<WebCore::PasteboardCustomData> { 430 static void encode(Encoder&, const WebCore::PasteboardCustomData&); 431 static bool decode(Decoder&, WebCore::PasteboardCustomData&); 432 }; 433 428 434 #if USE(SOUP) 429 435 template<> struct ArgumentCoder<WebCore::SoupNetworkProxySettings> { -
trunk/Source/WebKit/UIProcess/Cocoa/WebPasteboardProxyCocoa.mm
r222080 r222595 140 140 } 141 141 142 void WebPasteboardProxy::typesSafeForDOMToReadAndWrite(const String& pasteboardName, Vector<String>& types) 143 { 144 types = PlatformPasteboard(pasteboardName).typesSafeForDOMToReadAndWrite(); 145 } 146 147 void WebPasteboardProxy::writeCustomData(const WebCore::PasteboardCustomData& data, const String& pasteboardName, uint64_t& newChangeCount) 148 { 149 newChangeCount = PlatformPasteboard(pasteboardName).write(data); 150 } 151 142 152 #if PLATFORM(IOS) 143 153 void WebPasteboardProxy::getPasteboardTypesByFidelityForItemAtIndex(uint64_t index, const String& pasteboardName, Vector<String>& types) -
trunk/Source/WebKit/UIProcess/WebPasteboardProxy.cpp
r219595 r222595 62 62 } 63 63 64 #if !PLATFORM(COCOA) 65 66 void WebPasteboardProxy::typesSafeForDOMToReadAndWrite(const String&, Vector<String>& types) 67 { 68 types = { }; 69 } 70 71 void WebPasteboardProxy::writeCustomData(const WebCore::PasteboardCustomData&, const String&, uint64_t& newChangeCount) 72 { 73 newChangeCount = 0; 74 } 75 76 #endif 77 64 78 } // namespace WebKit -
trunk/Source/WebKit/UIProcess/WebPasteboardProxy.h
r222113 r222595 33 33 namespace WebCore { 34 34 class Color; 35 struct PasteboardCustomData; 35 36 struct PasteboardImage; 36 37 struct PasteboardURL; … … 97 98 #endif 98 99 100 void writeCustomData(const WebCore::PasteboardCustomData&, const String& pasteboardName, uint64_t& newChangeCount); 101 void typesSafeForDOMToReadAndWrite(const String& pasteboardName, Vector<String>& types); 102 99 103 #if PLATFORM(GTK) 100 104 void writeToClipboard(const String& pasteboardName, const WebSelectionData&); -
trunk/Source/WebKit/UIProcess/WebPasteboardProxy.messages.in
r218343 r222595 36 36 #endif 37 37 38 WriteCustomData(struct WebCore::PasteboardCustomData data, String pasteboardName) -> (uint64_t changeCount) 39 TypesSafeForDOMToReadAndWrite(String pasteboardName) -> (Vector<String> types) 40 38 41 #if PLATFORM(COCOA) 39 42 # Pasteboard messages. -
trunk/Source/WebKit/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp
r222228 r222595 399 399 #endif // PLATFORM(WPE) 400 400 401 Vector<String> WebPlatformStrategies::typesSafeForDOMToReadAndWrite(const String& pasteboardName) 402 { 403 Vector<String> types; 404 WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::TypesSafeForDOMToReadAndWrite(pasteboardName), Messages::WebPasteboardProxy::TypesSafeForDOMToReadAndWrite::Reply(types), 0); 405 return types; 406 } 407 408 long WebPlatformStrategies::writeCustomData(const WebCore::PasteboardCustomData& data, const String& pasteboardName) 409 { 410 uint64_t newChangeCount; 411 WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::WriteCustomData(data, pasteboardName), Messages::WebPasteboardProxy::WriteCustomData::Reply(newChangeCount), 0); 412 return newChangeCount; 413 } 414 401 415 } // namespace WebKit -
trunk/Source/WebKit/WebProcess/WebCoreSupport/WebPlatformStrategies.h
r222228 r222595 97 97 void writeToPasteboard(const String& pasteboardType, const String&) override; 98 98 #endif 99 100 Vector<String> typesSafeForDOMToReadAndWrite(const String& pasteboardName) override; 101 long writeCustomData(const WebCore::PasteboardCustomData&, const String&) override; 99 102 }; 100 103 -
trunk/Source/WebKitLegacy/mac/ChangeLog
r222571 r222595 1 2017-09-27 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 Drag event DataTransfer has unexpected types "dyn.ah62d4..." 4 https://bugs.webkit.org/show_bug.cgi?id=172526 5 <rdar://problem/32396081> 6 7 Reviewed by Ryosuke Niwa. 8 9 Adjust for changes in WebCore. See WebCore ChangeLog for more details. 10 11 * WebCoreSupport/WebPlatformStrategies.h: 12 * WebCoreSupport/WebPlatformStrategies.mm: 13 (WebPlatformStrategies::webExposedTypes): 14 (WebPlatformStrategies::writeCustomData): 15 1 16 2017-09-27 Matt Lewis <jlewis3@apple.com> 2 17 -
trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebPlatformStrategies.h
r222228 r222595 33 33 struct PasteboardImage; 34 34 struct PasteboardWebContent; 35 struct PasteboardCustomData; 35 36 36 37 class WebPlatformStrategies : public WebCore::PlatformStrategies, private WebCore::CookiesStrategy, private WebCore::PasteboardStrategy { … … 80 81 WebCore::URL url(const String& pasteboardName) override; 81 82 83 long writeCustomData(const WebCore::PasteboardCustomData&, const String& pasteboardName) override; 84 Vector<String> typesSafeForDOMToReadAndWrite(const String& pasteboardName) override; 85 82 86 long addTypes(const Vector<String>& pasteboardTypes, const String& pasteboardName) override; 83 87 long setTypes(const Vector<String>& pasteboardTypes, const String& pasteboardName) override; -
trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebPlatformStrategies.mm
r222228 r222595 180 180 } 181 181 182 Vector<String> WebPlatformStrategies::typesSafeForDOMToReadAndWrite(const String& pasteboardName) 183 { 184 return PlatformPasteboard(pasteboardName).typesSafeForDOMToReadAndWrite(); 185 } 186 187 long WebPlatformStrategies::writeCustomData(const WebCore::PasteboardCustomData& data, const String& pasteboardName) 188 { 189 return PlatformPasteboard(pasteboardName).write(data); 190 } 191 182 192 #if PLATFORM(IOS) 183 193 void WebPlatformStrategies::getTypesByFidelityForItemAtIndex(Vector<String>& types, uint64_t index, const String& pasteboardName) -
trunk/Tools/ChangeLog
r222582 r222595 1 2017-09-27 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 Drag event DataTransfer has unexpected types "dyn.ah62d4..." 4 https://bugs.webkit.org/show_bug.cgi?id=172526 5 <rdar://problem/32396081> 6 7 Reviewed by Ryosuke Niwa. 8 9 Adds new API tests on iOS to cover various cases of using DataTransfer.setData, DataTransfer.getData, and 10 DataTransfer.types, as well as their interaction with platform objects (source NSItemProviders in the case of 11 drag and drop, and the general UIPasteboard for copy and paste). 12 13 * TestWebKitAPI/PlatformUtilities.h: 14 * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: 15 * TestWebKitAPI/Tests/WebKitCocoa/dump-datatransfer-types.html: Added. 16 17 Introduce a new API test harness that both drag-and-drop and copy-and-paste tests use to dump DataTransfer's 18 web-exposed types and values. 19 20 * TestWebKitAPI/Tests/ios/DataInteractionTests.mm: 21 (checkFirstTypeIsPresentAndSecondTypeIsMissing): 22 (checkJSONWithLogging): 23 (TestWebKitAPI::TEST): 24 (checkTypeIdentifierAndIsNotOtherTypeIdentifier): Deleted. 25 * TestWebKitAPI/Tests/ios/UIPasteboardTests.mm: 26 (TestWebKitAPI::checkJSONWithLogging): 27 (TestWebKitAPI::setUpWebViewForPasteboardTests): 28 (TestWebKitAPI::TEST): 29 * TestWebKitAPI/cocoa/PlatformUtilitiesCocoa.mm: 30 (TestWebKitAPI::Util::jsonMatchesExpectedValues): 31 1 32 2017-09-27 Lucas Forschler <lforschler@apple.com> 2 33 -
trunk/Tools/TestWebKitAPI/PlatformUtilities.h
r201938 r222595 37 37 #if USE(FOUNDATION) 38 38 OBJC_CLASS NSString; 39 OBJC_CLASS NSDictionary; 39 40 #endif 40 41 … … 49 50 #if USE(FOUNDATION) 50 51 std::string toSTD(NSString *); 52 bool jsonMatchesExpectedValues(NSString *jsonString, NSDictionary *expected); 51 53 #endif 52 54 -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r222505 r222595 98 98 2E7765CF16C4D81100BA2BB1 /* mainMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2E7765CE16C4D81100BA2BB1 /* mainMac.mm */; }; 99 99 2E9896151D8F093800739892 /* text-and-password-inputs.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2E9896141D8F092B00739892 /* text-and-password-inputs.html */; }; 100 2EB29D5E1F762DB90023A5F1 /* dump-datatransfer-types.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2EB29D5D1F762DA50023A5F1 /* dump-datatransfer-types.html */; }; 100 101 2ECFF5551D9B12F800B55394 /* NowPlayingControlsTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2ECFF5541D9B12F800B55394 /* NowPlayingControlsTests.mm */; }; 101 102 2EFF06C31D88621E0004BB30 /* large-video-offscreen.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2EFF06C21D8862120004BB30 /* large-video-offscreen.html */; }; … … 846 847 F4D5E4E81F0C5D38008C1A49 /* dragstart-clear-selection.html in Copy Resources */, 847 848 F4194AD11F5A320100ADD83F /* drop-targets.html in Copy Resources */, 849 2EB29D5E1F762DB90023A5F1 /* dump-datatransfer-types.html in Copy Resources */, 848 850 A155022C1E050D0300A24C57 /* duplicate-completion-handler-calls.html in Copy Resources */, 849 851 9984FACE1CFFB090008D198C /* editable-body.html in Copy Resources */, … … 1147 1149 2E7EF7AC1F266A8100DFB67C /* AppKitSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppKitSPI.h; sourceTree = "<group>"; }; 1148 1150 2E9896141D8F092B00739892 /* text-and-password-inputs.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "text-and-password-inputs.html"; sourceTree = "<group>"; }; 1151 2EB29D5D1F762DA50023A5F1 /* dump-datatransfer-types.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "dump-datatransfer-types.html"; sourceTree = "<group>"; }; 1149 1152 2ECFF5541D9B12F800B55394 /* NowPlayingControlsTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NowPlayingControlsTests.mm; sourceTree = "<group>"; }; 1150 1153 2EFF06C21D8862120004BB30 /* large-video-offscreen.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-video-offscreen.html"; sourceTree = "<group>"; }; … … 2203 2206 F4D5E4E71F0C5D27008C1A49 /* dragstart-clear-selection.html */, 2204 2207 F4194AD01F5A2EA500ADD83F /* drop-targets.html */, 2208 2EB29D5D1F762DA50023A5F1 /* dump-datatransfer-types.html */, 2205 2209 A155022B1E050BC500A24C57 /* duplicate-completion-handler-calls.html */, 2206 2210 9984FACD1CFFB038008D198C /* editable-body.html */, -
trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm
r222522 r222595 126 126 } 127 127 128 static void check TypeIdentifierAndIsNotOtherTypeIdentifier(DataInteractionSimulator *simulator, NSString *firstType, NSString *secondType)128 static void checkFirstTypeIsPresentAndSecondTypeIsMissing(DataInteractionSimulator *simulator, CFStringRef firstType, CFStringRef secondType) 129 129 { 130 130 NSArray *registeredTypes = [simulator.sourceItemProviders.firstObject registeredTypeIdentifiers]; 131 EXPECT_TRUE([registeredTypes containsObject: firstType]);132 EXPECT_FALSE([registeredTypes containsObject: secondType]);131 EXPECT_TRUE([registeredTypes containsObject:(NSString *)firstType]); 132 EXPECT_FALSE([registeredTypes containsObject:(NSString *)secondType]); 133 133 } 134 134 … … 175 175 } 176 176 177 #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 110300 178 179 static void checkJSONWithLogging(NSString *jsonString, NSDictionary *expected) 180 { 181 BOOL success = TestWebKitAPI::Util::jsonMatchesExpectedValues(jsonString, expected); 182 EXPECT_TRUE(success); 183 if (!success) 184 NSLog(@"Expected JSON: %@ to match values: %@", jsonString, expected); 185 } 186 187 #endif // __IPHONE_OS_VERSION_MIN_REQUIRED >= 110300 188 177 189 static void runTestWithTemporaryTextFile(void(^runTest)(NSURL *fileURL)) 178 190 { … … 241 253 EXPECT_TRUE([observedEventNames containsObject:DataInteractionPerformOperationEventName]); 242 254 checkSelectionRectsWithLogging(@[ makeCGRectValue(1, 201, 215, 174) ], [dataInteractionSimulator finalSelectionRects]); 243 check TypeIdentifierAndIsNotOtherTypeIdentifier(dataInteractionSimulator.get(), (NSString *)kUTTypePNG, (NSString *)kUTTypeFileURL);255 checkFirstTypeIsPresentAndSecondTypeIsMissing(dataInteractionSimulator.get(), kUTTypePNG, kUTTypeFileURL); 244 256 checkEstimatedSize(dataInteractionSimulator.get(), { 215, 174 }); 245 257 } … … 271 283 EXPECT_TRUE([observedEventNames containsObject:DataInteractionOverEventName]); 272 284 EXPECT_TRUE([observedEventNames containsObject:DataInteractionPerformOperationEventName]); 273 check TypeIdentifierAndIsNotOtherTypeIdentifier(dataInteractionSimulator.get(), (NSString *)kUTTypePNG, (NSString *)kUTTypeFileURL);285 checkFirstTypeIsPresentAndSecondTypeIsMissing(dataInteractionSimulator.get(), kUTTypePNG, kUTTypeFileURL); 274 286 checkEstimatedSize(dataInteractionSimulator.get(), { 215, 174 }); 275 287 } … … 1208 1220 [dataInteractionSimulator runFrom:CGPointMake(200, 400) to:CGPointMake(200, 150)]; 1209 1221 EXPECT_WK_STREQ("PASS", [webView stringByEvaluatingJavaScript:@"target.textContent"].UTF8String); 1210 check TypeIdentifierAndIsNotOtherTypeIdentifier(dataInteractionSimulator.get(), (NSString *)kUTTypePNG, (NSString *)kUTTypeFileURL);1222 checkFirstTypeIsPresentAndSecondTypeIsMissing(dataInteractionSimulator.get(), kUTTypePNG, kUTTypeFileURL); 1211 1223 checkEstimatedSize(dataInteractionSimulator.get(), { 2000, 2000 }); 1212 1224 } … … 1468 1480 } 1469 1481 1482 #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 110300 1483 1484 TEST(DataInteractionTests, DataTransferGetDataWhenDroppingPlainText) 1485 { 1486 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); 1487 [webView synchronouslyLoadTestPageNamed:@"dump-datatransfer-types"]; 1488 auto simulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]); 1489 1490 [webView stringByEvaluatingJavaScript:@"select(plain)"]; 1491 [simulator runFrom:CGPointMake(50, 75) to:CGPointMake(50, 375)]; 1492 checkJSONWithLogging([webView stringByEvaluatingJavaScript:@"output.value"], @{ 1493 @"dragover": @{ @"text/plain" : @"" }, 1494 @"drop": @{ @"text/plain" : @"Plain text" } 1495 }); 1496 } 1497 1498 TEST(DataInteractionTests, DataTransferGetDataWhenDroppingCustomData) 1499 { 1500 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); 1501 [webView synchronouslyLoadTestPageNamed:@"dump-datatransfer-types"]; 1502 auto simulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]); 1503 1504 [webView stringByEvaluatingJavaScript:@"select(rich)"]; 1505 [webView stringByEvaluatingJavaScript:@"writeCustomData = true"]; 1506 [simulator runFrom:CGPointMake(50, 225) to:CGPointMake(50, 375)]; 1507 checkJSONWithLogging([webView stringByEvaluatingJavaScript:@"output.value"], @{ 1508 @"dragover" : @{ 1509 @"text/plain" : @"", 1510 @"foo/plain" : @"", 1511 @"text/html" : @"", 1512 @"bar/html" : @"", 1513 @"text/uri-list" : @"", 1514 @"baz/uri-list" : @"" 1515 }, 1516 @"drop" : @{ 1517 @"text/plain" : @"ben bitdiddle", 1518 @"foo/plain" : @"eva lu ator", 1519 @"text/html" : @"<b>bold text</b>", 1520 @"bar/html" : @"<i>italic text</i>", 1521 @"text/uri-list" : @"https://www.apple.com/", 1522 @"baz/uri-list" : @"https://www.webkit.org" 1523 } 1524 }); 1525 } 1526 1527 TEST(DataInteractionTests, DataTransferGetDataWhenDroppingURL) 1528 { 1529 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); 1530 [webView synchronouslyLoadTestPageNamed:@"dump-datatransfer-types"]; 1531 auto simulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]); 1532 1533 [webView stringByEvaluatingJavaScript:@"rich.innerHTML = '<a href=\"https://www.apple.com/\">This is a link.</a>'"]; 1534 [simulator runFrom:CGPointMake(50, 225) to:CGPointMake(50, 375)]; 1535 checkJSONWithLogging([webView stringByEvaluatingJavaScript:@"output.value"], @{ 1536 @"dragover": @{ @"text/uri-list" : @"" }, 1537 @"drop": @{ @"text/uri-list" : @"https://www.apple.com/" } 1538 }); 1539 } 1540 1541 TEST(DataInteractionTests, DataTransferGetDataWhenDroppingImageWithFileURL) 1542 { 1543 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); 1544 [webView synchronouslyLoadTestPageNamed:@"dump-datatransfer-types"]; 1545 auto simulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]); 1546 1547 auto itemProvider = adoptNS([[UIItemProvider alloc] init]); 1548 NSURL *iconURL = [[NSBundle mainBundle] URLForResource:@"icon" withExtension:@"png" subdirectory:@"TestWebKitAPI.resources"]; 1549 [itemProvider registerFileRepresentationForTypeIdentifier:(NSString *)kUTTypePNG fileOptions:0 visibility:NSItemProviderRepresentationVisibilityAll loadHandler:[protectedIconURL = retainPtr(iconURL)] (FileLoadCompletionBlock completionHandler) -> NSProgress * { 1550 completionHandler(protectedIconURL.get(), NO, nil); 1551 return nil; 1552 }]; 1553 [itemProvider registerObject:iconURL visibility:UIItemProviderRepresentationOptionsVisibilityAll]; 1554 [simulator setExternalItemProviders:@[ itemProvider.get() ]]; 1555 1556 [simulator runFrom:CGPointMake(300, 375) to:CGPointMake(50, 375)]; 1557 1558 // File URLs should never be exposed directly to web content, so DataTransfer.getData should return an empty string here. 1559 checkJSONWithLogging([webView stringByEvaluatingJavaScript:@"output.value"], @{ 1560 @"dragover": @{ @"text/uri-list" : @"" }, 1561 @"drop": @{ @"text/uri-list" : @"" } 1562 }); 1563 } 1564 1565 TEST(DataInteractionTests, DataTransferGetDataWhenDroppingRespectsPresentationStyle) 1566 { 1567 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); 1568 [webView synchronouslyLoadTestPageNamed:@"dump-datatransfer-types"]; 1569 auto simulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]); 1570 1571 runTestWithTemporaryTextFile(^(NSURL *fileURL) { 1572 auto itemProvider = adoptNS([[UIItemProvider alloc] init]); 1573 [itemProvider registerFileRepresentationForTypeIdentifier:(NSString *)kUTTypeUTF8PlainText fileOptions:0 visibility:NSItemProviderRepresentationVisibilityAll loadHandler:[protectedFileURL = retainPtr(fileURL)] (FileLoadCompletionBlock completionHandler) -> NSProgress * { 1574 completionHandler(protectedFileURL.get(), NO, nil); 1575 return nil; 1576 }]; 1577 [simulator setExternalItemProviders:@[ itemProvider.get() ]]; 1578 1579 [itemProvider setPreferredPresentationStyle:UIPreferredPresentationStyleAttachment]; 1580 [simulator runFrom:CGPointMake(300, 375) to:CGPointMake(50, 375)]; 1581 checkJSONWithLogging([webView stringByEvaluatingJavaScript:@"output.value"], @{ 1582 @"dragover": @{ @"text/plain" : @"" }, 1583 @"drop": @{ @"text/plain" : @"" } 1584 }); 1585 1586 [itemProvider setPreferredPresentationStyle:UIPreferredPresentationStyleInline]; 1587 [simulator runFrom:CGPointMake(300, 375) to:CGPointMake(50, 375)]; 1588 checkJSONWithLogging([webView stringByEvaluatingJavaScript:@"output.value"], @{ 1589 @"dragover": @{ @"text/plain" : @"" }, 1590 @"drop": @{ @"text/plain" : @"This is a tiny blob of text." } 1591 }); 1592 }); 1593 } 1594 1595 TEST(DataInteractionTests, DataTransferSetDataCannotWritePlatformTypes) 1596 { 1597 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); 1598 [webView synchronouslyLoadTestPageNamed:@"dump-datatransfer-types"]; 1599 auto simulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]); 1600 1601 [webView stringByEvaluatingJavaScript:@"select(rich)"]; 1602 [webView stringByEvaluatingJavaScript:@"customData = { 'text/plain' : 'foo', 'com.adobe.pdf' : 'try and decode me!' }"]; 1603 [webView stringByEvaluatingJavaScript:@"writeCustomData = true"]; 1604 1605 [simulator runFrom:CGPointMake(50, 225) to:CGPointMake(50, 375)]; 1606 checkFirstTypeIsPresentAndSecondTypeIsMissing(simulator.get(), kUTTypeUTF8PlainText, kUTTypePDF); 1607 checkJSONWithLogging([webView stringByEvaluatingJavaScript:@"output.value"], @{ 1608 @"dragover": @{ 1609 @"text/plain": @"", 1610 @"com.adobe.pdf": @"" 1611 }, 1612 @"drop": @{ 1613 @"text/plain": @"foo", 1614 @"com.adobe.pdf": @"try and decode me!" 1615 } 1616 }); 1617 } 1618 1619 TEST(DataInteractionTests, DataTransferGetDataCannotReadPrivateArbitraryTypes) 1620 { 1621 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); 1622 [webView synchronouslyLoadTestPageNamed:@"dump-datatransfer-types"]; 1623 auto simulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]); 1624 1625 auto itemProvider = adoptNS([[UIItemProvider alloc] init]); 1626 [itemProvider registerDataRepresentationForTypeIdentifier:(NSString *)kUTTypeMP3 visibility:NSItemProviderRepresentationVisibilityAll loadHandler:^NSProgress *(DataLoadCompletionBlock completionHandler) 1627 { 1628 completionHandler([@"this is a test" dataUsingEncoding:NSUTF8StringEncoding], nil); 1629 return nil; 1630 }]; 1631 [itemProvider registerDataRepresentationForTypeIdentifier:@"org.WebKit.TestWebKitAPI.custom-pasteboard-type" visibility:NSItemProviderRepresentationVisibilityAll loadHandler:^NSProgress *(DataLoadCompletionBlock completionHandler) 1632 { 1633 completionHandler([@"this is another test" dataUsingEncoding:NSUTF8StringEncoding], nil); 1634 return nil; 1635 }]; 1636 [simulator setExternalItemProviders:@[ itemProvider.get() ]]; 1637 [itemProvider setPreferredPresentationStyle:UIPreferredPresentationStyleInline]; 1638 [simulator runFrom:CGPointMake(300, 375) to:CGPointMake(50, 375)]; 1639 checkJSONWithLogging([webView stringByEvaluatingJavaScript:@"output.value"], @{ 1640 @"dragover": @{ }, 1641 @"drop": @{ } 1642 }); 1643 } 1644 1645 #endif // __IPHONE_OS_VERSION_MIN_REQUIRED >= 110300 1646 1470 1647 } // namespace TestWebKitAPI 1471 1648 -
trunk/Tools/TestWebKitAPI/Tests/ios/UIPasteboardTests.mm
r220865 r222595 37 37 #import <wtf/SoftLinking.h> 38 38 39 typedef void (^DataLoadCompletionBlock)(NSData *, NSError *); 40 41 #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 110300 42 43 static void checkJSONWithLogging(NSString *jsonString, NSDictionary *expected) 44 { 45 BOOL success = TestWebKitAPI::Util::jsonMatchesExpectedValues(jsonString, expected); 46 EXPECT_TRUE(success); 47 if (!success) 48 NSLog(@"Expected JSON: %@ to match values: %@", jsonString, expected); 49 } 50 51 #endif // __IPHONE_OS_VERSION_MIN_REQUIRED >= 110300 52 39 53 namespace TestWebKitAPI { 40 54 … … 44 58 } 45 59 46 RetainPtr<TestWKWebView> setUpWebViewForPasteboardTests( )60 RetainPtr<TestWKWebView> setUpWebViewForPasteboardTests(NSString *pageName) 47 61 { 48 62 // UIPasteboard's type coercion codepaths only take effect when the UIApplication has been initialized. … … 57 71 preferences._javaScriptCanAccessClipboard = YES; 58 72 preferences._domPasteAllowed = YES; 59 [webView synchronouslyLoadTestPageNamed: @"rich-and-plain-text"];73 [webView synchronouslyLoadTestPageNamed:pageName]; 60 74 return webView; 61 75 } … … 63 77 TEST(UIPasteboardTests, CopyPlainTextWritesConcreteTypes) 64 78 { 65 auto webView = setUpWebViewForPasteboardTests( );79 auto webView = setUpWebViewForPasteboardTests(@"rich-and-plain-text"); 66 80 [webView stringByEvaluatingJavaScript:@"selectPlainText()"]; 67 81 [webView stringByEvaluatingJavaScript:@"document.execCommand('copy')"]; … … 73 87 TEST(UIPasteboardTests, CopyRichTextWritesConcreteTypes) 74 88 { 75 auto webView = setUpWebViewForPasteboardTests( );89 auto webView = setUpWebViewForPasteboardTests(@"rich-and-plain-text"); 76 90 [webView stringByEvaluatingJavaScript:@"selectRichText()"]; 77 91 [webView stringByEvaluatingJavaScript:@"document.execCommand('copy')"]; … … 81 95 } 82 96 83 #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 11000084 85 97 TEST(UIPasteboardTests, DoNotPastePlainTextAsURL) 86 98 { 87 auto webView = setUpWebViewForPasteboardTests( );99 auto webView = setUpWebViewForPasteboardTests(@"rich-and-plain-text"); 88 100 89 101 NSString *testString = @"[helloworld]"; … … 102 114 TEST(UIPasteboardTests, PastePlainTextAsURL) 103 115 { 104 auto webView = setUpWebViewForPasteboardTests( );116 auto webView = setUpWebViewForPasteboardTests(@"rich-and-plain-text"); 105 117 106 118 NSString *testString = @"https://www.apple.com/iphone"; … … 119 131 TEST(UIPasteboardTests, PasteURLWithPlainTextAsURL) 120 132 { 121 auto webView = setUpWebViewForPasteboardTests( );133 auto webView = setUpWebViewForPasteboardTests(@"rich-and-plain-text"); 122 134 123 135 NSString *testString = @"thisisdefinitelyaurl"; … … 134 146 } 135 147 136 #endif // __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000 148 #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 110300 149 150 TEST(UIPasteboardTests, DataTransferGetDataWhenPastingURL) 151 { 152 auto webView = setUpWebViewForPasteboardTests(@"dump-datatransfer-types"); 153 154 NSString *testURLString = @"https://www.apple.com/"; 155 [UIPasteboard generalPasteboard].URL = [NSURL URLWithString:testURLString]; 156 157 [webView stringByEvaluatingJavaScript:@"destination.focus()"]; 158 [webView stringByEvaluatingJavaScript:@"document.execCommand('paste')"]; 159 checkJSONWithLogging([webView stringByEvaluatingJavaScript:@"output.value"], @{ 160 @"paste" : @{ 161 @"text/plain" : testURLString, 162 @"text/uri-list" : testURLString 163 } 164 }); 165 } 166 167 TEST(UIPasteboardTests, DataTransferGetDataWhenPastingPlatformRepresentations) 168 { 169 auto webView = setUpWebViewForPasteboardTests(@"dump-datatransfer-types"); 170 171 // This simulates how a native app on iOS might write to the pasteboard when copying. 172 RetainPtr<NSURL> testURL = [NSURL URLWithString:@"https://www.apple.com/"]; 173 RetainPtr<NSString> testPlainTextString = @"WebKit"; 174 RetainPtr<NSString> testMarkupString = @"<a href='https://www.webkit.org/'>The WebKit Project</a>"; 175 auto itemProvider = adoptNS([[NSItemProvider alloc] init]); 176 [itemProvider registerDataRepresentationForTypeIdentifier:(NSString *)kUTTypeHTML visibility:NSItemProviderRepresentationVisibilityAll loadHandler:^NSProgress *(DataLoadCompletionBlock completionHandler) 177 { 178 completionHandler([testMarkupString dataUsingEncoding:NSUTF8StringEncoding], nil); 179 return nil; 180 }]; 181 [itemProvider registerObject:testURL.get() visibility:NSItemProviderRepresentationVisibilityAll]; 182 [itemProvider registerObject:testPlainTextString.get() visibility:NSItemProviderRepresentationVisibilityAll]; 183 184 [UIPasteboard generalPasteboard].itemProviders = @[ itemProvider.get() ]; 185 [webView stringByEvaluatingJavaScript:@"destination.focus()"]; 186 [webView stringByEvaluatingJavaScript:@"document.execCommand('paste')"]; 187 checkJSONWithLogging([webView stringByEvaluatingJavaScript:@"output.value"], @{ 188 @"paste" : @{ 189 @"text/plain" : testPlainTextString.get(), 190 @"text/uri-list" : [testURL absoluteString], 191 @"text/html" : testMarkupString.get() 192 } 193 }); 194 } 195 196 TEST(UIPasteboardTests, DataTransferSetDataCannotWritePlatformTypes) 197 { 198 auto webView = setUpWebViewForPasteboardTests(@"dump-datatransfer-types"); 199 200 [webView stringByEvaluatingJavaScript:@"customData = { 'text/plain' : '年年年', '年年年年年年' : 'test', 'com.adobe.pdf' : '🔥🔥🔥', 'text/rtf' : 'not actually rich text!' }"]; 201 [webView stringByEvaluatingJavaScript:@"writeCustomData = true"]; 202 [webView stringByEvaluatingJavaScript:@"select(rich)"]; 203 [webView stringByEvaluatingJavaScript:@"document.execCommand('copy')"]; 204 [webView stringByEvaluatingJavaScript:@"destination.focus()"]; 205 [webView stringByEvaluatingJavaScript:@"document.execCommand('paste')"]; 206 checkJSONWithLogging([webView stringByEvaluatingJavaScript:@"output.value"], @{ 207 @"paste": @{ 208 @"text/plain": @"年年年", 209 @"年年年年年年": @"test", 210 @"com.adobe.pdf": @"🔥🔥🔥", 211 @"text/rtf": @"not actually rich text!" 212 } 213 }); 214 215 // Most importantly, the system pasteboard should not contain the PDF UTI. 216 NSData *pdfData = [[UIPasteboard generalPasteboard] dataForPasteboardType:(NSString *)kUTTypePDF]; 217 EXPECT_EQ(0UL, pdfData.length); 218 219 // However, the system pasteboard should contain a plain text string. 220 EXPECT_WK_STREQ("年年年", [UIPasteboard generalPasteboard].string); 221 } 222 223 TEST(UIPasteboardTests, DataTransferGetDataCannotReadArbitraryPlatformTypes) 224 { 225 auto webView = setUpWebViewForPasteboardTests(@"dump-datatransfer-types"); 226 auto itemProvider = adoptNS([[NSItemProvider alloc] init]); 227 [itemProvider registerDataRepresentationForTypeIdentifier:(NSString *)kUTTypeMP3 visibility:NSItemProviderRepresentationVisibilityAll loadHandler:^NSProgress *(DataLoadCompletionBlock completionHandler) 228 { 229 completionHandler([@"this is a test" dataUsingEncoding:NSUTF8StringEncoding], nil); 230 return nil; 231 }]; 232 [itemProvider registerDataRepresentationForTypeIdentifier:@"org.WebKit.TestWebKitAPI.custom-pasteboard-type" visibility:NSItemProviderRepresentationVisibilityAll loadHandler:^NSProgress *(DataLoadCompletionBlock completionHandler) 233 { 234 completionHandler([@"this is another test" dataUsingEncoding:NSUTF8StringEncoding], nil); 235 return nil; 236 }]; 237 238 [webView stringByEvaluatingJavaScript:@"destination.focus()"]; 239 [webView stringByEvaluatingJavaScript:@"document.execCommand('paste')"]; 240 checkJSONWithLogging([webView stringByEvaluatingJavaScript:@"output.value"], @{ 241 @"paste": @{ } 242 }); 243 } 244 245 #endif // __IPHONE_OS_VERSION_MIN_REQUIRED >= 110300 137 246 138 247 } // namespace TestWebKitAPI -
trunk/Tools/TestWebKitAPI/cocoa/PlatformUtilitiesCocoa.mm
r201938 r222595 45 45 } 46 46 47 bool jsonMatchesExpectedValues(NSString *jsonString, NSDictionary *expected) 48 { 49 NSError *error = nil; 50 id result = [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] options:0 error:&error]; 51 if (error) 52 NSLog(@"Encountered error: %@ while serializing JSON string.", error); 53 return [expected isEqualToDictionary:result]; 54 } 55 47 56 #if WK_API_ENABLED 48 57 NSString * const TestPlugInClassNameParameter = @"TestPlugInPrincipalClassName";
Note:
See TracChangeset
for help on using the changeset viewer.