Changeset 222656 in webkit
- Timestamp:
- Sep 29, 2017, 11:46:51 AM (8 years ago)
- Location:
- trunk
- Files:
-
- 9 added
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/CMakeLists.txt
r222595 r222656 1800 1800 editing/VisibleUnits.cpp 1801 1801 editing/WebContentReader.cpp 1802 editing/WebCorePasteboardFileReader.cpp 1802 1803 editing/WrapContentsInDummySpanCommand.cpp 1803 1804 editing/markup.cpp -
trunk/Source/WebCore/ChangeLog
r222654 r222656 1 2017-09-28 Ryosuke Niwa <rniwa@webkit.org> 2 3 Image pasting is not working on tineye.com / gmail.com / GitHub.com due to lack of support for DataTransfer.items 4 https://bugs.webkit.org/show_bug.cgi?id=170449 5 <rdar://problem/31432525> 6 7 Reviewed by Wenson Hsieh. 8 9 The bug was caused by image types in NSPasteboard or UIPasteboard not being treated as file items in dataTransfer. 10 Because there is no Web API to get binary data out of dataTransfer unlike text data, we need to treat any image 11 data as files even if they're entirely in the memory. 12 13 This patch introduces the notion of pasteboard types to be treated as files and expose them on dataTransfer.files 14 as well as dataTransfer.items of type "file". Because in-memory images are stored as TIFF in macOS and websites 15 don't typically support image/tiff, we convert all such in-memory TIFF images into PNG images ourselves for 16 a better web compatibility. This is done inside read(PasteboardFileReader&) in PasteboardCocoa.mm. 17 18 Note that PasteboardFileReader cannot directly have RefPtr<File> as a member variable as code in WebCore/platform 19 including Pasteboard code is not supposed to depend on WebCore types. WebCorePasteboardFileReader, a subclass of 20 PasteboardFileReader was introduced to resolve this reverse dependency. 21 22 In addition, this patch removes the restriction on dataTransfer.items that it only includes files of the supported 23 MIME types. This was unwarranted since 1. we don't have any restriction on what an user can drag & drop into a web 24 page via input element so there is no security benefit in this, and 2. the user should be able to copy & paste 25 whatever file he/she desires regardless of the MIME type on websites like Google Drive. 26 27 Tests: PasteImage 28 29 * CMakeLists.txt: 30 * WebCore.xcodeproj/project.pbxproj: 31 * WebCore/PlatformMac.cmake: 32 * dom/DataTransfer.cpp: 33 (WebCore::DataTransfer::types const): Now excludes image/gif, image/png, image/jpeg, and image/tiff. 34 (WebCore::DataTransfer::files const): Add fake files we create for in-memory images but only when there are no real 35 files in the pasteboard since it's expensive to copy image data across UI/Web processes to create a blob URL. 36 * dom/DataTransferItemList.cpp: 37 (WebCore::DataTransferItemList::ensureItems const): Just expose every file type. If the user had decided to paste 38 a file, it's okay for the page to access that file regardless of whether it's a zip file, JPEG image, etc... 39 * editing/WebCorePasteboardFileReader.cpp: 40 (WebCorePasteboardFileReader::~WebCorePasteboardFileReader): 41 (WebCorePasteboardFileReader::read): 42 * editing/WebCorePasteboardFileReader.h: 43 (WebCorePasteboardFileReader): 44 * platform/Pasteboard.cpp: 45 (WebCore::PasteboardImage::PasteboardImage): Moved from platform specific translation units. 46 (WebCore::PasteboardImage::~PasteboardImage): Ditto. 47 * platform/Pasteboard.h: 48 (PasteboardFileReader): Added. 49 (* platform/StaticPasteboard.h: 50 (StaticPasteboard::typesForBindings): Added. 51 (StaticPasteboard::typesTreatedAsFiles): Added. Returns an empty list we don't support the web content writing image 52 files into pasteboard at the moment. 53 * platform/cocoa/PasteboardCocoa.mm: Added. 54 (WebCore::PasteboardWebContent::PasteboardWebContent): Moved from PasteboardMac.mm and PasteboardIOS.mm. 55 (WebCore::PasteboardWebContent::~PasteboardWebContent): 56 (WebCore::cocoaTypeToImageType): Added. 57 (WebCore::imageTypeToMIMEType): Added. Pretends to have image/png when the Cocoa type is image/tiff since most of 58 websites don't support image/tiff. 59 (WebCore::imageTypeToFakeFilename): Added. 60 (WebCore::mimeTypeToImageType): Added. 61 (WebCore::Pasteboard::shouldTreatCocoaTypeAsFile): Added. Pasteboard::typesForBindings excludes the type for which 62 this function returns true. 63 (WebCore::Pasteboard::typesTreatedAsFiles): Returns the list of all in-memory image types in the pasteboard. 64 (WebCore::Pasteboard::read): Added. On macOS, we convert TIFF to PNG for web compatibility. We don't do this rather 65 memory intensive coercion on iOS where most of apps like Photos put PNG file into the pasteboard in the first place. 66 * platform/gtk/PasteboardGtk.cpp: 67 (WebCore::PasteboardImage::PasteboardImage): Deleted. 68 (WebCore::PasteboardImage::~PasteboardImage): Deleted. 69 (WebCore::Pasteboard::read): 70 (WebCore::Pasteboard::typesForBindings): Renamed from types. 71 (WebCore::Pasteboard::typesTreatedAsFiles): 72 * platform/ios/PasteboardIOS.mm: 73 (WebCore::addHTMLClipboardTypesForCocoaType): 74 (WebCore::Pasteboard::typesForBindings): 75 (WebCore::PasteboardWebContent::PasteboardWebContent): Deleted. 76 (WebCore::PasteboardWebContent::~PasteboardWebContent): Deleted. 77 (WebCore::PasteboardImage::PasteboardImage): Deleted. 78 (WebCore::PasteboardImage::~PasteboardImage): Deleted. 79 (WebCore::Pasteboard::types): Deleted. 80 * platform/ios/PlatformPasteboardIOS.mm: 81 (WebCore::safeTypeForDOMToReadAndWriteForPlatformType): Add "Files" to dataTransfer.types when there is an in-memory 82 image type in the pasteboard. 83 * platform/mac/PasteboardMac.mm: 84 (WebCore::PasteboardWebContent::PasteboardWebContent): Deleted. 85 (WebCore::PasteboardWebContent::~PasteboardWebContent): Deleted. 86 (WebCore::PasteboardImage::PasteboardImage): Deleted. 87 (WebCore::PasteboardImage::~PasteboardImage): Deleted. 88 (WebCore::addHTMLClipboardTypesForCocoaType): Moved the check for the legacy NeXT plain text check here. Also add 89 "Files" to dataTransfer.types when there is an in-memory image type in the pasteboard. 90 (WebCore::Pasteboard::typesForBindings): Renamed from types. 91 * platform/mac/PlatformPasteboardMac.mm: 92 (WebCore::safeTypeForDOMToReadAndWriteForPlatformType): Ditto to add "Files". 93 * platform/win/PasteboardWin.cpp: 94 (WebCore::Pasteboard::typesForBindings): Renamed from types. 95 (WebCore::Pasteboard::typesTreatedAsFiles): 96 (WebCore::Pasteboard::read): 97 * platform/wpe/PasteboardWPE.cpp: 98 (WebCore::Pasteboard::typesForBindings): Renamed from types. 99 (WebCore::Pasteboard::typesTreatedAsFiles): 100 (WebCore::Pasteboard::read): 101 1 102 2017-09-29 Wenson Hsieh <wenson_hsieh@apple.com> 2 103 -
trunk/Source/WebCore/PlatformMac.cmake
r222592 r222656 322 322 platform/cocoa/NetworkExtensionContentFilter.mm 323 323 platform/cocoa/ParentalControlsContentFilter.mm 324 platform/cocoa/PasteboardCocoa.mm 324 325 platform/cocoa/RuntimeApplicationChecksCocoa.mm 325 326 platform/cocoa/ScrollController.mm -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r222647 r222656 4346 4346 9BDA64D71B975CE5009C4387 /* JSShadowRoot.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9B6BC9601B975966005AE1F0 /* JSShadowRoot.cpp */; }; 4347 4347 9BDA64D81B975CF2009C4387 /* JSShadowRoot.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B6BC9611B975966005AE1F0 /* JSShadowRoot.h */; }; 4348 9BDD18271F7E05F400E8E577 /* WebCorePasteboardFileReader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9BDD18261F7E05F400E8E577 /* WebCorePasteboardFileReader.cpp */; }; 4348 4349 9BE6710B1D5AEB2100345514 /* JSCustomElementRegistry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9BE671091D5AEB0400345514 /* JSCustomElementRegistry.cpp */; }; 4349 4350 9BE6710C1D5AEB2500345514 /* JSCustomElementRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = 9BE6710A1D5AEB0400345514 /* JSCustomElementRegistry.h */; }; 4351 9BED2CB11F7CC06200666018 /* PasteboardCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9BED2CAF1F7CC06200666018 /* PasteboardCocoa.mm */; }; 4350 4352 9BF9A8801648DD2F001C6B23 /* JSHTMLFormControlsCollection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9BF9A87E1648DD2F001C6B23 /* JSHTMLFormControlsCollection.cpp */; }; 4351 4353 9BF9A8811648DD2F001C6B23 /* JSHTMLFormControlsCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = 9BF9A87F1648DD2F001C6B23 /* JSHTMLFormControlsCollection.h */; }; … … 12789 12791 9BD4E9191C462CFC005065BC /* CustomElementRegistry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomElementRegistry.h; sourceTree = "<group>"; }; 12790 12792 9BD8A95918BEFC7600987E9A /* CollectionIndexCache.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CollectionIndexCache.cpp; sourceTree = "<group>"; }; 12793 9BDD18251F7E059900E8E577 /* WebCorePasteboardFileReader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebCorePasteboardFileReader.h; sourceTree = "<group>"; }; 12794 9BDD18261F7E05F400E8E577 /* WebCorePasteboardFileReader.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebCorePasteboardFileReader.cpp; sourceTree = "<group>"; }; 12791 12795 9BE671091D5AEB0400345514 /* JSCustomElementRegistry.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCustomElementRegistry.cpp; sourceTree = "<group>"; }; 12792 12796 9BE6710A1D5AEB0400345514 /* JSCustomElementRegistry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSCustomElementRegistry.h; sourceTree = "<group>"; }; 12797 9BED2CAF1F7CC06200666018 /* PasteboardCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = PasteboardCocoa.mm; sourceTree = "<group>"; }; 12793 12798 9BF433761F67619B00E1FD71 /* WebContentReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebContentReader.h; sourceTree = "<group>"; }; 12794 12799 9BF9A87E1648DD2F001C6B23 /* JSHTMLFormControlsCollection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLFormControlsCollection.cpp; sourceTree = "<group>"; }; … … 20602 20607 9B6116491F6A593300E923B8 /* WebContentReader.cpp */, 20603 20608 9BF433761F67619B00E1FD71 /* WebContentReader.h */, 20609 9BDD18261F7E05F400E8E577 /* WebCorePasteboardFileReader.cpp */, 20610 9BDD18251F7E059900E8E577 /* WebCorePasteboardFileReader.h */, 20604 20611 93309DD4099E64910056E581 /* WrapContentsInDummySpanCommand.cpp */, 20605 20612 93309DD5099E64910056E581 /* WrapContentsInDummySpanCommand.h */, … … 21774 21781 A18890AD1AA13F250026C301 /* ParentalControlsContentFilter.h */, 21775 21782 A18890AC1AA13F250026C301 /* ParentalControlsContentFilter.mm */, 21783 9BED2CAF1F7CC06200666018 /* PasteboardCocoa.mm */, 21776 21784 52B0D4BD1C57FD1E0077CE53 /* PlatformView.h */, 21777 21785 CDA29A081CBD99F400901CCF /* PlaybackSessionInterface.h */, … … 33490 33498 F55B3DC91251F12D003EF269 /* PasswordInputType.cpp in Sources */, 33491 33499 2EE02A1F1F7324280006AF72 /* Pasteboard.cpp in Sources */, 33500 9BED2CB11F7CC06200666018 /* PasteboardCocoa.mm in Sources */, 33492 33501 E453901E0EAFCACA003695C8 /* PasteboardIOS.mm in Sources */, 33493 33502 4B2709830AF2E5E00065127F /* PasteboardMac.mm in Sources */, … … 34427 34436 CD225C0B1C46FBF400140761 /* WebCoreNSURLSession.mm in Sources */, 34428 34437 B50F5B810E96CD9900AD71A6 /* WebCoreObjCExtras.mm in Sources */, 34438 9BDD18271F7E05F400E8E577 /* WebCorePasteboardFileReader.cpp in Sources */, 34429 34439 E180810E16FCECDF00B80D07 /* WebCoreResourceHandleAsDelegate.mm in Sources */, 34430 34440 E152551616FD2350003D7ADB /* WebCoreResourceHandleAsOperationQueueDelegate.mm in Sources */, -
trunk/Source/WebCore/dom/DataTransfer.cpp
r222595 r222656 39 39 #include "Pasteboard.h" 40 40 #include "StaticPasteboard.h" 41 #include "WebCorePasteboardFileReader.h" 41 42 42 43 namespace WebCore { … … 172 173 return { }; 173 174 174 return m_pasteboard->types ();175 return m_pasteboard->typesForBindings(); 175 176 } 176 177 … … 196 197 for (auto& filename : m_pasteboard->readFilenames()) 197 198 m_fileList->append(File::create(filename)); 199 if (m_fileList->isEmpty()) { 200 for (auto& type : m_pasteboard->typesTreatedAsFiles()) { 201 WebCorePasteboardFileReader reader(type); 202 m_pasteboard->read(reader); 203 if (reader.file) 204 m_fileList->append(reader.file.releaseNonNull()); 205 } 206 } 198 207 } 199 208 return *m_fileList; -
trunk/Source/WebCore/dom/DataTransferItemList.cpp
r222422 r222656 132 132 } 133 133 134 for (auto& file : m_dataTransfer.files().files()) { 135 auto type = File::contentTypeForFile(file->path()).convertToASCIILowercase(); 136 if (isSupportedType(type) || file->isDirectory()) 137 items.append(DataTransferItem::create(m_weakPtrFactory.createWeakPtr(*const_cast<DataTransferItemList*>(this)), type, file.copyRef())); 138 } 134 for (auto& file : m_dataTransfer.files().files()) 135 items.append(DataTransferItem::create(m_weakPtrFactory.createWeakPtr(*const_cast<DataTransferItemList*>(this)), file->type(), file.copyRef())); 139 136 140 137 m_items = WTFMove(items); -
trunk/Source/WebCore/editing/wpe/EditorWPE.cpp
r222595 r222656 39 39 chosePlainText = false; 40 40 41 Vector<String> types = pasteboard.types ();41 Vector<String> types = pasteboard.typesForBindings(); 42 42 if (types.isEmpty()) 43 43 return nullptr; -
trunk/Source/WebCore/platform/Pasteboard.cpp
r222595 r222656 35 35 36 36 namespace WebCore { 37 38 // Making this non-inline so that WebKit 2's decoding doesn't have to include Image.h. 39 PasteboardImage::PasteboardImage() = default; 40 PasteboardImage::~PasteboardImage() = default; 37 41 38 42 bool isSafeTypeForDOMToReadAndWrite(const String& type) -
trunk/Source/WebCore/platform/Pasteboard.h
r222595 r222656 67 67 68 68 struct PasteboardWebContent { 69 #if !(PLATFORM(GTK) || PLATFORM(WIN) || PLATFORM(WPE))69 #if PLATFORM(COCOA) 70 70 WEBCORE_EXPORT PasteboardWebContent(); 71 71 WEBCORE_EXPORT ~PasteboardWebContent(); … … 147 147 }; 148 148 149 struct PasteboardFileReader { 150 PasteboardFileReader(const String& type) 151 : type(type) 152 { } 153 virtual ~PasteboardFileReader() = default; 154 155 virtual void read(const String&, Ref<SharedBuffer>&&) = 0; 156 157 const String type; 158 }; 159 149 160 // FIXME: We need to ensure that the contents of sameOriginCustomData are not accessible across different origins. 150 161 struct PasteboardCustomData { … … 185 196 186 197 virtual bool hasData(); 187 virtual Vector<String> types(); 198 virtual Vector<String> typesForBindings(); 199 virtual Vector<String> typesTreatedAsFiles(); 188 200 virtual String readStringForBindings(const String& type); 189 201 … … 194 206 virtual void read(PasteboardPlainText&); 195 207 virtual void read(PasteboardWebContentReader&); 208 virtual void read(PasteboardFileReader&); 196 209 197 210 virtual void write(const PasteboardURL&); … … 235 248 explicit Pasteboard(const String& pasteboardName); 236 249 250 static bool shouldTreatCocoaTypeAsFile(const String&); 237 251 WEBCORE_EXPORT static NSArray *supportedFileUploadPasteboardTypes(); 238 252 const String& name() const { return m_pasteboardName; } -
trunk/Source/WebCore/platform/StaticPasteboard.h
r222595 r222656 42 42 43 43 bool hasData() final; 44 Vector<String> types() final { return m_types; } 44 Vector<String> typesForBindings() final { return m_types; } 45 Vector<String> typesTreatedAsFiles() final { return { }; } 45 46 String readStringForBindings(const String& type) final; 46 47 -
trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp
r222595 r222656 64 64 #endif 65 65 66 // Making this non-inline so that WebKit 2's decoding doesn't have to include Image.h.67 PasteboardImage::PasteboardImage()68 {69 }70 71 PasteboardImage::~PasteboardImage()72 {73 }74 75 66 Pasteboard::Pasteboard(SelectionData& selectionData) 76 67 : m_selectionData(selectionData) … … 252 243 } 253 244 245 void Pasteboard::read(PasteboardFileReader&) 246 { 247 } 248 254 249 bool Pasteboard::hasData() 255 250 { … … 258 253 } 259 254 260 Vector<String> Pasteboard::types ()255 Vector<String> Pasteboard::typesForBindings() 261 256 { 262 257 readFromClipboard(); … … 284 279 285 280 return types; 281 } 282 283 Vector<String> Pasteboard::typesTreatedAsFiles() 284 { 285 return { }; 286 286 } 287 287 -
trunk/Source/WebCore/platform/ios/PasteboardIOS.mm
r222595 r222656 99 99 WEBCORE_EXPORT NSString *WebArchivePboardType = @"Apple Web Archive pasteboard type"; 100 100 101 // Making this non-inline so that WebKit 2's decoding doesn't have to include SharedBuffer.h.102 PasteboardWebContent::PasteboardWebContent()103 {104 }105 106 PasteboardWebContent::~PasteboardWebContent()107 {108 }109 110 // Making this non-inline so that WebKit 2's decoding doesn't have to include Image.h.111 PasteboardImage::PasteboardImage()112 {113 }114 115 PasteboardImage::~PasteboardImage()116 {117 }118 119 101 Pasteboard::Pasteboard() 120 102 : m_changeCount(0) … … 418 400 return; 419 401 } 402 if (Pasteboard::shouldTreatCocoaTypeAsFile(cocoaType)) { 403 resultTypes.add(ASCIILiteral("Files")); 404 return; 405 } 420 406 String utiType = utiTypeFromCocoaType(cocoaType); 421 407 if (!utiType.isEmpty()) { … … 436 422 } 437 423 438 Vector<String> Pasteboard::types ()424 Vector<String> Pasteboard::typesForBindings() 439 425 { 440 426 Vector<String> types; -
trunk/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm
r222597 r222656 432 432 return ASCIILiteral("text/uri-list"); 433 433 434 if (Pasteboard::shouldTreatCocoaTypeAsFile(platformType)) 435 return ASCIILiteral("Files"); 436 434 437 return nullptr; 435 438 } -
trunk/Source/WebCore/platform/mac/PasteboardMac.mm
r222595 r222656 71 71 const char WebURLsWithTitlesPboardType[] = "WebURLsWithTitlesPboardType"; 72 72 73 // Making this non-inline so that WebKit 2's decoding doesn't have to include SharedBuffer.h.74 PasteboardWebContent::PasteboardWebContent()75 {76 }77 78 PasteboardWebContent::~PasteboardWebContent()79 {80 }81 82 // Making this non-inline so that WebKit 2's decoding doesn't have to include Image.h.83 PasteboardImage::PasteboardImage()84 {85 }86 87 PasteboardImage::~PasteboardImage()88 {89 }90 91 73 static const Vector<String> writableTypesForURL() 92 74 { … … 555 537 static void addHTMLClipboardTypesForCocoaType(ListHashSet<String>& resultTypes, const String& cocoaType, const String& pasteboardName) 556 538 { 539 if (cocoaType == "NeXT plain ascii pasteboard type") 540 return; // Skip this ancient type that gets auto-supplied by some system conversion. 541 557 542 // UTI may not do these right, so make sure we get the right, predictable result 558 543 if (cocoaType == String(NSStringPboardType) || cocoaType == String(NSPasteboardTypeString)) { … … 574 559 return; 575 560 } 561 if (Pasteboard::shouldTreatCocoaTypeAsFile(cocoaType)) { 562 resultTypes.add(ASCIILiteral("Files")); 563 return; 564 } 576 565 String utiType = utiTypeFromCocoaType(cocoaType); 577 566 if (!utiType.isEmpty()) { … … 610 599 } 611 600 612 Vector<String> Pasteboard::types ()601 Vector<String> Pasteboard::typesForBindings() 613 602 { 614 603 Vector<String> types; … … 627 616 628 617 ListHashSet<String> result; 629 // FIXME: This loop could be split into two stages. One which adds all the HTML5 specified types 630 // and a second which adds all the extra types from the cocoa clipboard (which is Mac-only behavior). 631 for (size_t i = 0; i < types.size(); i++) { 632 if (types[i] == "NeXT plain ascii pasteboard type") 633 continue; // skip this ancient type that gets auto-supplied by some system conversion 634 635 addHTMLClipboardTypesForCocoaType(result, types[i], m_pasteboardName); 636 } 618 for (auto& cocoaType : types) 619 addHTMLClipboardTypesForCocoaType(result, cocoaType, m_pasteboardName); 637 620 638 621 copyToVector(result, types); -
trunk/Source/WebCore/platform/mac/PlatformPasteboardMac.mm
r222595 r222656 106 106 return ASCIILiteral("text/html"); 107 107 108 if (platformType == String(NSFilenamesPboardType) || platformType == String(NSFilesPromisePboardType) )108 if (platformType == String(NSFilenamesPboardType) || platformType == String(NSFilesPromisePboardType) || Pasteboard::shouldTreatCocoaTypeAsFile(platformType)) 109 109 return ASCIILiteral("Files"); 110 110 -
trunk/Source/WebCore/platform/win/PasteboardWin.cpp
r222595 r222656 244 244 } 245 245 246 Vector<String> Pasteboard::types ()246 Vector<String> Pasteboard::typesForBindings() 247 247 { 248 248 ListHashSet<String> results; … … 276 276 copyToVector(results, vector); 277 277 return vector; 278 } 279 280 Vector<String> Pasteboard::typesTreatedAsFiles() 281 { 282 return { }; 278 283 } 279 284 … … 1051 1056 } 1052 1057 1058 void Pasteboard::read(PasteboardFileReader&) 1059 { 1060 } 1061 1053 1062 void Pasteboard::write(const PasteboardImage&) 1054 1063 { -
trunk/Source/WebCore/platform/wpe/PasteboardWPE.cpp
r222595 r222656 50 50 } 51 51 52 Vector<String> Pasteboard::types ()52 Vector<String> Pasteboard::typesForBindings() 53 53 { 54 54 Vector<String> types; 55 55 platformStrategies()->pasteboardStrategy()->getTypes(types); 56 56 return types; 57 } 58 59 Vector<String> Pasteboard::typesTreatedAsFiles() 60 { 61 return { }; 57 62 } 58 63 … … 83 88 { 84 89 notImplemented(); 90 } 91 92 void Pasteboard::read(PasteboardFileReader&) 93 { 85 94 } 86 95 -
trunk/Source/WebKit/ChangeLog
r222654 r222656 1 2017-09-28 Ryosuke Niwa <rniwa@webkit.org> 2 3 Image pasting is not working on tineye.com / gmail.com / GitHub.com due to lack of support for DataTransfer.items 4 https://bugs.webkit.org/show_bug.cgi?id=170449 5 <rdar://problem/31432525> 6 7 Reviewed by Wenson Hsieh. 8 9 Add sandbox extensions for files in the pasteboard to make copying & pasting image files work. 10 This is what we do for drag & drop but we should consider adding a mechanism to rekoke the extension in the future. 11 12 * UIProcess/Cocoa/WebPasteboardProxyCocoa.mm: 13 (WebKit::WebPasteboardProxy::getPasteboardPathnamesForType): Add sandbox extensions to the pasted files. 14 * UIProcess/WebPasteboardProxy.h: 15 * UIProcess/WebPasteboardProxy.messages.in: 16 * WebProcess/WebCoreSupport/WebPlatformStrategies.cpp: 17 (WebKit::WebPlatformStrategies::getPathnamesForType): Consume the sandbox tokens sent by the UI process permanently 18 since WebCore will now create File objects for these pasted files. 19 1 20 2017-09-29 Wenson Hsieh <wenson_hsieh@apple.com> 2 21 -
trunk/Source/WebKit/UIProcess/Cocoa/WebPasteboardProxyCocoa.mm
r222595 r222656 26 26 #import "config.h" 27 27 #import "WebPasteboardProxy.h" 28 29 #import "SandboxExtension.h" 28 30 #import "WebProcessProxy.h" 29 30 31 #import <WebCore/Color.h> 31 32 #import <WebCore/PlatformPasteboard.h> … … 42 43 } 43 44 44 void WebPasteboardProxy::getPasteboardPathnamesForType(const String& pasteboardName, const String& pasteboardType, Vector<String>& pathnames) 45 { 46 PlatformPasteboard(pasteboardName).getPathnamesForType(pathnames, pasteboardType); 45 void WebPasteboardProxy::getPasteboardPathnamesForType(IPC::Connection& connection, const String& pasteboardName, const String& pasteboardType, 46 Vector<String>& pathnames, SandboxExtension::HandleArray& sandboxExtensions) 47 { 48 for (auto* webProcessProxy : m_webProcessProxyList) { 49 if (!webProcessProxy->hasConnection(connection)) 50 continue; 51 52 PlatformPasteboard(pasteboardName).getPathnamesForType(pathnames, pasteboardType); 53 54 #if PLATFORM(MAC) 55 // On iOS, files are copied into app's container upon paste. 56 sandboxExtensions.allocate(pathnames.size()); 57 for (size_t i = 0; i < pathnames.size(); i++) { 58 auto& filename = pathnames[i]; 59 if (![[NSFileManager defaultManager] fileExistsAtPath:filename]) 60 continue; 61 SandboxExtension::createHandle(filename, SandboxExtension::Type::ReadOnly, sandboxExtensions[i]); 62 } 63 #endif 64 } 47 65 } 48 66 -
trunk/Source/WebKit/UIProcess/WebPasteboardProxy.h
r222595 r222656 27 27 28 28 #include "MessageReceiver.h" 29 #include "SandboxExtension.h" 29 30 #include "SharedMemory.h" 30 31 #include <wtf/Forward.h> … … 83 84 void getNumberOfFiles(const String& pasteboardName, uint64_t& numberOfFiles); 84 85 void getPasteboardTypes(const String& pasteboardName, Vector<String>& pasteboardTypes); 85 void getPasteboardPathnamesForType( const String& pasteboardName, const String& pasteboardType, Vector<String>& pathnames);86 void getPasteboardPathnamesForType(IPC::Connection&, const String& pasteboardName, const String& pasteboardType, Vector<String>& pathnames, SandboxExtension::HandleArray&); 86 87 void getPasteboardStringForType(const String& pasteboardName, const String& pasteboardType, String&); 87 88 void getPasteboardBufferForType(const String& pasteboardName, const String& pasteboardType, SharedMemory::Handle&, uint64_t& size); -
trunk/Source/WebKit/UIProcess/WebPasteboardProxy.messages.in
r222595 r222656 43 43 GetNumberOfFiles(String pasteboardName) -> (uint64_t numberOfFiles) 44 44 GetPasteboardTypes(String pasteboardName) -> (Vector<String> types) 45 GetPasteboardPathnamesForType(String pasteboardName, String pasteboardType) -> (Vector<String> pathnames )45 GetPasteboardPathnamesForType(String pasteboardName, String pasteboardType) -> (Vector<String> pathnames, WebKit::SandboxExtension::HandleArray sandboxExtensions) WantsConnection 46 46 GetPasteboardStringForType(String pasteboardName, String pasteboardType) -> (String string) 47 47 GetPasteboardBufferForType(String pasteboardName, String pasteboardType) -> (WebKit::SharedMemory::Handle handle, uint64_t size) -
trunk/Source/WebKit/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp
r222595 r222656 193 193 void WebPlatformStrategies::getPathnamesForType(Vector<String>& pathnames, const String& pasteboardType, const String& pasteboardName) 194 194 { 195 WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::GetPasteboardPathnamesForType(pasteboardName, pasteboardType), Messages::WebPasteboardProxy::GetPasteboardPathnamesForType::Reply(pathnames), 0); 195 SandboxExtension::HandleArray sandboxExtensionsHandleArray; 196 WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::GetPasteboardPathnamesForType(pasteboardName, pasteboardType), 197 Messages::WebPasteboardProxy::GetPasteboardPathnamesForType::Reply(pathnames, sandboxExtensionsHandleArray), 0); 198 ASSERT(pathnames.size() == sandboxExtensionsHandleArray.size()); 199 for (size_t i = 0; i < sandboxExtensionsHandleArray.size(); i++) { 200 if (RefPtr<SandboxExtension> extension = SandboxExtension::create(sandboxExtensionsHandleArray[i])) 201 extension->consumePermanently(); 202 } 196 203 } 197 204 -
trunk/Tools/ChangeLog
r222654 r222656 1 2017-09-28 Ryosuke Niwa <rniwa@webkit.org> 2 3 Image pasting is not working on tineye.com / gmail.com / GitHub.com due to lack of support for DataTransfer.items 4 https://bugs.webkit.org/show_bug.cgi?id=170449 5 <rdar://problem/31432525> 6 7 Reviewed by Wenson Hsieh. 8 9 Added an API test to paste an image from pasteboard. The test is shared between iOS and macOS. 10 11 The tests to paste image files are only enabled on macOS since putting files into pasteboard isn't a thing on iOS. 12 13 * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: 14 * TestWebKitAPI/Tests/WebKitCocoa/PasteImage.mm: Added. 15 (writeImageDataToPasteboard): 16 (writeBundleFileToPasteboard): 17 * TestWebKitAPI/Tests/WebKitCocoa/paste-image.html: Added. 18 * TestWebKitAPI/Tests/WebKitCocoa/sunset-in-cupertino-100px.tiff: Added. 19 * TestWebKitAPI/Tests/WebKitCocoa/sunset-in-cupertino-200px.png: Added. 20 * TestWebKitAPI/Tests/WebKitCocoa/sunset-in-cupertino-400px.gif: Added. 21 * TestWebKitAPI/Tests/WebKitCocoa/sunset-in-cupertino-600px.jpg: Added. 22 * TestWebKitAPI/Tests/ios/DataInteractionTests.mm: Rebaselined the test now that types contain "Files". 23 1 24 2017-09-29 Wenson Hsieh <wenson_hsieh@apple.com> 2 25 -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r222633 r222656 545 545 9BD4239A1E04BD9800200395 /* AttributedSubstringForProposedRangeWithImage.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9BD423991E04BD9800200395 /* AttributedSubstringForProposedRangeWithImage.mm */; }; 546 546 9BD4239C1E04C01C00200395 /* chinese-character-with-image.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9BD4239B1E04BFD000200395 /* chinese-character-with-image.html */; }; 547 9BD6D3A21F7B218300BD4962 /* sunset-in-cupertino-100px.tiff in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9BD6D3A11F7B202100BD4962 /* sunset-in-cupertino-100px.tiff */; }; 548 9BD6D3A31F7B218300BD4962 /* sunset-in-cupertino-200px.png in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9BD6D3A01F7B202000BD4962 /* sunset-in-cupertino-200px.png */; }; 549 9BD6D3A41F7B218300BD4962 /* sunset-in-cupertino-400px.gif in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9BD6D39F1F7B202000BD4962 /* sunset-in-cupertino-400px.gif */; }; 550 9BD6D3A51F7B218300BD4962 /* sunset-in-cupertino-600px.jpg in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9BD6D39E1F7B201E00BD4962 /* sunset-in-cupertino-600px.jpg */; }; 551 9BD6D3A71F7B21DC00BD4962 /* paste-image.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9BD6D3A61F7B21CC00BD4962 /* paste-image.html */; }; 552 9BDCCD871F7D0B0700009A18 /* PasteImage.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9BDCCD851F7D0B0700009A18 /* PasteImage.mm */; }; 547 553 9C64DC321D76198A004B598E /* YouTubePluginReplacement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9C64DC311D76198A004B598E /* YouTubePluginReplacement.cpp */; }; 548 554 A10F047E1E3AD29C00C95E19 /* NSFileManagerExtras.mm in Sources */ = {isa = PBXBuildFile; fileRef = A10F047C1E3AD29C00C95E19 /* NSFileManagerExtras.mm */; }; … … 969 975 A57A34F216AF6B2B00C2501F /* PageVisibilityStateWithWindowChanges.html in Copy Resources */, 970 976 A1409AD91E7254D4004949D9 /* password-protected.pages in Copy Resources */, 977 9BD6D3A71F7B21DC00BD4962 /* paste-image.html in Copy Resources */, 971 978 3FCC4FE81EC4E8CA0076E37C /* PictureInPictureDelegate.html in Copy Resources */, 972 979 F415086D1DA040C50044BE9B /* play-audio-on-click.html in Copy Resources */, … … 992 999 E194E1BD177E53C7009C4D4E /* StopLoadingFromDidReceiveResponse.html in Copy Resources */, 993 1000 515BE16F1D428BB100DD7C68 /* StoreBlobToBeDeleted.html in Copy Resources */, 1001 9BD6D3A21F7B218300BD4962 /* sunset-in-cupertino-100px.tiff in Copy Resources */, 1002 9BD6D3A31F7B218300BD4962 /* sunset-in-cupertino-200px.png in Copy Resources */, 1003 9BD6D3A41F7B218300BD4962 /* sunset-in-cupertino-400px.gif in Copy Resources */, 1004 9BD6D3A51F7B218300BD4962 /* sunset-in-cupertino-600px.jpg in Copy Resources */, 994 1005 CD59F53519E9110D00CF1835 /* test-mse.mp4 in Copy Resources */, 995 1006 C95984F71E36BCEF002C0D45 /* test-without-audio-track.mp4 in Copy Resources */, … … 1493 1504 9BD423991E04BD9800200395 /* AttributedSubstringForProposedRangeWithImage.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AttributedSubstringForProposedRangeWithImage.mm; sourceTree = "<group>"; }; 1494 1505 9BD4239B1E04BFD000200395 /* chinese-character-with-image.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "chinese-character-with-image.html"; sourceTree = "<group>"; }; 1506 9BD6D39E1F7B201E00BD4962 /* sunset-in-cupertino-600px.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "sunset-in-cupertino-600px.jpg"; sourceTree = "<group>"; }; 1507 9BD6D39F1F7B202000BD4962 /* sunset-in-cupertino-400px.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = "sunset-in-cupertino-400px.gif"; sourceTree = "<group>"; }; 1508 9BD6D3A01F7B202000BD4962 /* sunset-in-cupertino-200px.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "sunset-in-cupertino-200px.png"; sourceTree = "<group>"; }; 1509 9BD6D3A11F7B202100BD4962 /* sunset-in-cupertino-100px.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = "sunset-in-cupertino-100px.tiff"; sourceTree = "<group>"; }; 1510 9BD6D3A61F7B21CC00BD4962 /* paste-image.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "paste-image.html"; sourceTree = "<group>"; }; 1511 9BDCCD851F7D0B0700009A18 /* PasteImage.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = PasteImage.mm; sourceTree = "<group>"; }; 1495 1512 9C64DC311D76198A004B598E /* YouTubePluginReplacement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = YouTubePluginReplacement.cpp; sourceTree = "<group>"; }; 1496 1513 A10F047C1E3AD29C00C95E19 /* NSFileManagerExtras.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NSFileManagerExtras.mm; sourceTree = "<group>"; }; … … 1989 2006 CEA6CF2219CCF5BD0064F5A7 /* OpenAndCloseWindow.mm */, 1990 2007 CEBCA12E1E3A660100C73293 /* OverrideContentSecurityPolicy.mm */, 2008 9BDCCD851F7D0B0700009A18 /* PasteImage.mm */, 1991 2009 3FCC4FE41EC4E8520076E37C /* PictureInPictureDelegate.mm */, 1992 2010 83BAEE8C1EF4625500DDE894 /* PluginLoadClientPolicies.mm */, … … 2281 2299 CEBCA1371E3A803400C73293 /* page-without-csp.html */, 2282 2300 A1409AD81E7254AC004949D9 /* password-protected.pages */, 2301 9BD6D3A61F7B21CC00BD4962 /* paste-image.html */, 2283 2302 3FCC4FE61EC4E87E0076E37C /* PictureInPictureDelegate.html */, 2284 2303 F415086C1DA040C10044BE9B /* play-audio-on-click.html */, … … 2291 2310 F4F405BB1D4C0CF8007A9707 /* skinny-autoplaying-video-with-audio.html */, 2292 2311 515BE16E1D4288FF00DD7C68 /* StoreBlobToBeDeleted.html */, 2312 9BD6D3A11F7B202100BD4962 /* sunset-in-cupertino-100px.tiff */, 2313 9BD6D3A01F7B202000BD4962 /* sunset-in-cupertino-200px.png */, 2314 9BD6D39F1F7B202000BD4962 /* sunset-in-cupertino-400px.gif */, 2315 9BD6D39E1F7B201E00BD4962 /* sunset-in-cupertino-600px.jpg */, 2293 2316 2E9896141D8F092B00739892 /* text-and-password-inputs.html */, 2294 2317 F41AB9951EF4692C0083FA08 /* textarea-to-input.html */, … … 3340 3363 7C83E0511D0A641800FEBCF3 /* ParsedContentRange.cpp in Sources */, 3341 3364 7CCE7F0A1A411AE600447C4C /* PasteboardNotifications.mm in Sources */, 3365 9BDCCD871F7D0B0700009A18 /* PasteImage.mm in Sources */, 3342 3366 7C83E0531D0A643A00FEBCF3 /* PendingAPIRequestURL.cpp in Sources */, 3343 3367 3FCC4FE51EC4E8520076E37C /* PictureInPictureDelegate.mm in Sources */, -
trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm
r222595 r222656 1558 1558 // File URLs should never be exposed directly to web content, so DataTransfer.getData should return an empty string here. 1559 1559 checkJSONWithLogging([webView stringByEvaluatingJavaScript:@"output.value"], @{ 1560 @"dragover": @{ @" text/uri-list" : @"" },1561 @"drop": @{ @" text/uri-list" : @"" }1560 @"dragover": @{ @"Files": @"", @"text/uri-list" : @"" }, 1561 @"drop": @{ @"Files": @"", @"text/uri-list" : @"" } 1562 1562 }); 1563 1563 }
Note:
See TracChangeset
for help on using the changeset viewer.