commit | 2337917314d754f212f108a7c254efcd51304e5b | [log] [tgz] |
---|---|---|
author | rniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc> | Fri Sep 29 18:46:51 2017 +0000 |
committer | rniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc> | Fri Sep 29 18:46:51 2017 +0000 |
tree | 9c52af63f8de1362f2ad0be7c19b449f40ba9720 | |
parent | a0484573d68b145f3d374f21fdbec4dc978c3bc0 [diff] |
Image pasting is not working on tineye.com / gmail.com / GitHub.com due to lack of support for DataTransfer.items https://bugs.webkit.org/show_bug.cgi?id=170449 <rdar://problem/31432525> Reviewed by Wenson Hsieh. Source/WebCore: The bug was caused by image types in NSPasteboard or UIPasteboard not being treated as file items in dataTransfer. Because there is no Web API to get binary data out of dataTransfer unlike text data, we need to treat any image data as files even if they're entirely in the memory. This patch introduces the notion of pasteboard types to be treated as files and expose them on dataTransfer.files as well as dataTransfer.items of type "file". Because in-memory images are stored as TIFF in macOS and websites don't typically support image/tiff, we convert all such in-memory TIFF images into PNG images ourselves for a better web compatibility. This is done inside read(PasteboardFileReader&) in PasteboardCocoa.mm. Note that PasteboardFileReader cannot directly have RefPtr<File> as a member variable as code in WebCore/platform including Pasteboard code is not supposed to depend on WebCore types. WebCorePasteboardFileReader, a subclass of PasteboardFileReader was introduced to resolve this reverse dependency. In addition, this patch removes the restriction on dataTransfer.items that it only includes files of the supported MIME types. This was unwarranted since 1. we don't have any restriction on what an user can drag & drop into a web page via input element so there is no security benefit in this, and 2. the user should be able to copy & paste whatever file he/she desires regardless of the MIME type on websites like Google Drive. Tests: PasteImage * CMakeLists.txt: * WebCore.xcodeproj/project.pbxproj: * WebCore/PlatformMac.cmake: * dom/DataTransfer.cpp: (WebCore::DataTransfer::types const): Now excludes image/gif, image/png, image/jpeg, and image/tiff. (WebCore::DataTransfer::files const): Add fake files we create for in-memory images but only when there are no real files in the pasteboard since it's expensive to copy image data across UI/Web processes to create a blob URL. * dom/DataTransferItemList.cpp: (WebCore::DataTransferItemList::ensureItems const): Just expose every file type. If the user had decided to paste a file, it's okay for the page to access that file regardless of whether it's a zip file, JPEG image, etc... * editing/WebCorePasteboardFileReader.cpp: (WebCorePasteboardFileReader::~WebCorePasteboardFileReader): (WebCorePasteboardFileReader::read): * editing/WebCorePasteboardFileReader.h: (WebCorePasteboardFileReader): * platform/Pasteboard.cpp: (WebCore::PasteboardImage::PasteboardImage): Moved from platform specific translation units. (WebCore::PasteboardImage::~PasteboardImage): Ditto. * platform/Pasteboard.h: (PasteboardFileReader): Added. (* platform/StaticPasteboard.h: (StaticPasteboard::typesForBindings): Added. (StaticPasteboard::typesTreatedAsFiles): Added. Returns an empty list we don't support the web content writing image files into pasteboard at the moment. * platform/cocoa/PasteboardCocoa.mm: Added. (WebCore::PasteboardWebContent::PasteboardWebContent): Moved from PasteboardMac.mm and PasteboardIOS.mm. (WebCore::PasteboardWebContent::~PasteboardWebContent): (WebCore::cocoaTypeToImageType): Added. (WebCore::imageTypeToMIMEType): Added. Pretends to have image/png when the Cocoa type is image/tiff since most of websites don't support image/tiff. (WebCore::imageTypeToFakeFilename): Added. (WebCore::mimeTypeToImageType): Added. (WebCore::Pasteboard::shouldTreatCocoaTypeAsFile): Added. Pasteboard::typesForBindings excludes the type for which this function returns true. (WebCore::Pasteboard::typesTreatedAsFiles): Returns the list of all in-memory image types in the pasteboard. (WebCore::Pasteboard::read): Added. On macOS, we convert TIFF to PNG for web compatibility. We don't do this rather memory intensive coercion on iOS where most of apps like Photos put PNG file into the pasteboard in the first place. * platform/gtk/PasteboardGtk.cpp: (WebCore::PasteboardImage::PasteboardImage): Deleted. (WebCore::PasteboardImage::~PasteboardImage): Deleted. (WebCore::Pasteboard::read): (WebCore::Pasteboard::typesForBindings): Renamed from types. (WebCore::Pasteboard::typesTreatedAsFiles): * platform/ios/PasteboardIOS.mm: (WebCore::addHTMLClipboardTypesForCocoaType): (WebCore::Pasteboard::typesForBindings): (WebCore::PasteboardWebContent::PasteboardWebContent): Deleted. (WebCore::PasteboardWebContent::~PasteboardWebContent): Deleted. (WebCore::PasteboardImage::PasteboardImage): Deleted. (WebCore::PasteboardImage::~PasteboardImage): Deleted. (WebCore::Pasteboard::types): Deleted. * platform/ios/PlatformPasteboardIOS.mm: (WebCore::safeTypeForDOMToReadAndWriteForPlatformType): Add "Files" to dataTransfer.types when there is an in-memory image type in the pasteboard. * platform/mac/PasteboardMac.mm: (WebCore::PasteboardWebContent::PasteboardWebContent): Deleted. (WebCore::PasteboardWebContent::~PasteboardWebContent): Deleted. (WebCore::PasteboardImage::PasteboardImage): Deleted. (WebCore::PasteboardImage::~PasteboardImage): Deleted. (WebCore::addHTMLClipboardTypesForCocoaType): Moved the check for the legacy NeXT plain text check here. Also add "Files" to dataTransfer.types when there is an in-memory image type in the pasteboard. (WebCore::Pasteboard::typesForBindings): Renamed from types. * platform/mac/PlatformPasteboardMac.mm: (WebCore::safeTypeForDOMToReadAndWriteForPlatformType): Ditto to add "Files". * platform/win/PasteboardWin.cpp: (WebCore::Pasteboard::typesForBindings): Renamed from types. (WebCore::Pasteboard::typesTreatedAsFiles): (WebCore::Pasteboard::read): * platform/wpe/PasteboardWPE.cpp: (WebCore::Pasteboard::typesForBindings): Renamed from types. (WebCore::Pasteboard::typesTreatedAsFiles): (WebCore::Pasteboard::read): Source/WebKit: Add sandbox extensions for files in the pasteboard to make copying & pasting image files work. This is what we do for drag & drop but we should consider adding a mechanism to rekoke the extension in the future. * UIProcess/Cocoa/WebPasteboardProxyCocoa.mm: (WebKit::WebPasteboardProxy::getPasteboardPathnamesForType): Add sandbox extensions to the pasted files. * UIProcess/WebPasteboardProxy.h: * UIProcess/WebPasteboardProxy.messages.in: * WebProcess/WebCoreSupport/WebPlatformStrategies.cpp: (WebKit::WebPlatformStrategies::getPathnamesForType): Consume the sandbox tokens sent by the UI process permanently since WebCore will now create File objects for these pasted files. Tools: Added an API test to paste an image from pasteboard. The test is shared between iOS and macOS. The tests to paste image files are only enabled on macOS since putting files into pasteboard isn't a thing on iOS. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebKitCocoa/PasteImage.mm: Added. (writeImageDataToPasteboard): (writeBundleFileToPasteboard): * TestWebKitAPI/Tests/WebKitCocoa/paste-image.html: Added. * TestWebKitAPI/Tests/WebKitCocoa/sunset-in-cupertino-100px.tiff: Added. * TestWebKitAPI/Tests/WebKitCocoa/sunset-in-cupertino-200px.png: Added. * TestWebKitAPI/Tests/WebKitCocoa/sunset-in-cupertino-400px.gif: Added. * TestWebKitAPI/Tests/WebKitCocoa/sunset-in-cupertino-600px.jpg: Added. * TestWebKitAPI/Tests/ios/DataInteractionTests.mm: Rebaselined the test now that types contain "Files". git-svn-id: http://svn.webkit.org/repository/webkit/trunk@222656 268f45cc-cd09-0410-ab3c-d52691b4dbfc
WebKit is a cross-platform web browser engine. On iOS and macOS, it powers Safari, Mail, iBooks, and many other applications.
Visit WebKit Feature Status page to see which Web API has been implemented, in development, or under consideration.
Downloading Safari Technology Preview to test the latest version of WebKit.
Once your bug is filed, you will receive email when it is updated at each stage in the bug life cycle. After the bug is considered fixed, you may be asked to download the latest nightly and confirm that the fix works for you.
On Windows, follow the instructions on our website.
Run the following command to clone WebKit's Git SVN repository:
git clone git://git.webkit.org/WebKit.git WebKit
If you want to be able to commit changes to the repository, or just want to check out branches that aren’t contained in WebKit.git, you will need track WebKit's Subversion repository. You can run the following command to configure this and other options of the new Git clone for WebKit development.
Tools/Scripts/webkit-patch setup-git-clone
For information about this, and other aspects of using Git with WebKit, read the wiki page.
Run the following command to check out WebKit's subversion repository:
svn checkout https://svn.webkit.org/repository/webkit/trunk WebKit
Install Xcode and its command line tools if you haven't done so already:
xcode-select --install
Run the following command to build a debug build with debugging symbols and assertions:
Tools/Scripts/build-webkit --debug
For performance testing, and other purposes, use --release
instead.
You can open WebKit.xcworkspace
to build and debug WebKit within WebKit.
If you don't use a custom build location in Xcode preferences, you have to update the workspace settings to use WebKitBuild
directory. In menu bar, choose File > Workspace Settings, then click the Advanced button, select “Custom”, “Relative to Workspace”, and enter WebKitBuild
for both Products and Intermediates.
The first time after you install a new Xcode, you will need to run the following command to enable Xcode to build command line tools for iOS Simulator:
sudo Tools/Scripts/configure-xcode-for-ios-development
Without this step, you will see the error message: “target specifies product type ‘com.apple.product-type.tool’, but there’s no such product type for the ‘iphonesimulator’ platform.
” when building target JSCLLIntOffsetsExtractor
of project JavaScriptCore
.
Run the following command to build a debug build with debugging symbols and assertions for iOS:
Tools/Scripts/build-webkit --debug --ios-simulator.
Install the dependencies by running the following command:
Tools/gtk/install-dependencies
Then run the following command to build additional dependencies:
Tools/Scripts/update-webkitgtk-libs
Run the following command to build WebKit with debugging symbols for GTK+ port:
Tools/Scripts/build-webkit --debug --gtk
Note that the procedure for building a release tarball is different. For more information, see the wiki page.
For building WebKit on Windows, see the wiki page.
Run the following command to launch Safari with your local build of WebKit:
Tools/Scripts/run-safari --debug
The run-safari
script sets the DYLD_FRAMEWORK_PATH
environment variable to point to your build products, and then launches /Applications/Safari.app
. DYLD_FRAMEWORK_PATH
tells the system loader to prefer your build products over the frameworks installed in /System/Library/Frameworks
.
To run other applications with your local build of WebKit, run the following command:
Tools/Scripts/run-webkit-app <application-path>
Run the following command to launch iOS simulator with your local build of WebKit:
run-safari --debug --ios-simulator
In both cases, if you have built release builds instead, use --release
instead of --debug
.
Congratulations! You’re up and running. Now you can begin coding in WebKit and contribute your fixes and new features to the project. For details on submitting your code to the project, read Contributing Code.