commit | fdc942c5052133d9f3534312553b7ba8c309c092 | [log] [tgz] |
---|---|---|
author | wenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc> | Thu Oct 10 16:17:18 2019 +0000 |
committer | wenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc> | Thu Oct 10 16:17:18 2019 +0000 |
tree | ad27e8580790e6aed6e568d9bad9f927ece513f4 | |
parent | 90acb9d3aae85597081c3e88b7c7c705f08fe88d [diff] |
Support programmatic paste requests on macOS https://bugs.webkit.org/show_bug.cgi?id=202773 <rdar://problem/48957166> Reviewed by Tim Horton. Source/WebCore: Adds support for programmatic paste requests on macOS. See below for more details. Tests: editing/pasteboard/dom-paste/dom-paste-confirmation.html editing/pasteboard/dom-paste/dom-paste-consecutive-confirmations.html editing/pasteboard/dom-paste/dom-paste-rejection.html editing/pasteboard/dom-paste/dom-paste-requires-user-gesture.html editing/pasteboard/dom-paste/dom-paste-same-origin.html * editing/EditorCommand.cpp: (WebCore::defaultValueForSupportedPaste): (WebCore::supportedPaste): (WebCore::allowPasteFromDOM): (WebCore::enabledPaste): Fixes an existing bug uncovered by the layout test editing/execCommand/clipboard-access.html, which tests the results of `document.queryCommandEnabled("copy")` and `document.queryCommandEnabled("paste")`. The problem here is that document.queryCommandEnabled("paste") returns true if DOM paste access requests are enabled, regardless of whether or not there is an active user gesture. This is inconsistent with the behavior of "copy" and "cut", which return false in the case where there is no user gesture (and the clipboard access policy is also equal to ClipboardAccessPolicy::RequiresUserGesture -- refer to `allowCopyCutFromDOM`). When pasting, we only DOM paste access requests to be triggered only in the case where there is a user gesture. This means that enabledPaste should additionally be gated on a user gesture check. For consistency with the implementation of `enabledCopy`, we introduce a `allowPasteFromDOM` helper that is similar to `allowCopyCutFromDOM`, and additionally check this constraint when the paste command's source is the DOM (as opposed to a menu or key binding). This adjustment also adds a missing canDHTMLPaste() check prior to consulting canPaste(). This ensures that when evaluating document.queryCommandEnabled("Paste"), we'll dispatch a "beforepaste" event, similar to how evaluating document.queryCommandEnabled("Copy") dispatches a "beforecopy" event. * platform/LocalizedStrings.h: Mark a function as WEBCORE_EXPORT. Source/WebKit: Adds support for programmatic paste requests on macOS, as well as some testing SPI in WKWebView to allow WebKitTestRunner to grab the NSMenu used for the DOM paste request. This patch adopts the same strategy taken to allow programmatic paste on iOS, by allowing programmatic pastes coming from the page to show platform UI which the user must then interact with in order to proceed with the paste. See below for more details. * Shared/WebPreferencesDefaultValues.h: Make this available on both iOS and macOS (iOS family is omitted for now, since callout bar UI is not generally present on non-iOS iOS-family platforms such as Apple Watch). * UIProcess/API/Cocoa/WKWebView.mm: (-[WKWebView _web_grantDOMPasteAccess]): This selector is called when the user taps the Paste option in the presented NSMenu. (-[WKWebView _activeMenu]): Returns the currently active NSMenu. Only for testing purposes. * UIProcess/API/Cocoa/WKWebViewInternal.h: * UIProcess/API/Cocoa/WKWebViewPrivate.h: * UIProcess/API/mac/WKView.mm: (-[WKView _web_grantDOMPasteAccess]): Same exercise as above, only for WKView instead of WKWebView. * UIProcess/Cocoa/WebViewImpl.h: (WebKit::WebViewImpl::domPasteMenu const): * UIProcess/Cocoa/WebViewImpl.mm: (-[WKDOMPasteMenuDelegate initWithWebViewImpl:]): (-[WKDOMPasteMenuDelegate menuDidClose:]): (-[WKDOMPasteMenuDelegate numberOfItemsInMenu:]): (-[WKDOMPasteMenuDelegate confinementRectForMenu:onScreen:]): Adds a new object, whose purpose is to be a delegate for the NSMenu that is presented when requesting DOM paste access. This object is used instead of WKWebView, since API clients may end up making the WKWebView the delegate for a different menu, in which case some implementations (either theirs or ours) of NSMenuDelegate methods would not be called. Avoiding this would require the client to be aware that WKWebView conforms to NSMenuDelegate, which is only declared privately. (WebKit::WebViewImpl::handleProcessSwapOrExit): On process swap or exit, automatically bail out of any pending DOM paste request by denying it. (WebKit::WebViewImpl::requestDOMPasteAccess): (WebKit::WebViewImpl::handleDOMPasteRequestWithResult): Handle the DOM paste request by showing an NSMenu near the mouse cursor with a single option to paste. * UIProcess/mac/PageClientImplMac.h: * UIProcess/mac/PageClientImplMac.mm: (WebKit::PageClientImpl::requestDOMPasteAccess): Tools: Adds new testing support to enable us to test programmatic paste requests on macOS. * TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl: Add a few new UIScriptController methods: - activateAtPoint(x, y, callback): used to activate content underneath at (x, y), in root view coordinates (WKWebView on macOS, and WKContentView on iOS). On macOS, this moves the mouse to the given location and clicks. - chooseMenuAction(action, callback): used to select a menu item with the given title. - dismissMenu(): dismisses the platform menu. Note that dismissMenu and chooseMenuAction currently only work for the DOM paste menu, but could be extended in the future to handle the system context menu. * TestRunnerShared/UIScriptContext/UIScriptController.cpp: (WTR::UIScriptController::dismissMenu): (WTR::UIScriptController::chooseMenuAction): * TestRunnerShared/UIScriptContext/UIScriptController.h: (WTR::UIScriptController::activateAtPoint): * WebKitTestRunner/cocoa/TestControllerCocoa.mm: (WTR::TestController::cocoaResetStateToConsistentValues): * WebKitTestRunner/cocoa/TestRunnerWKWebView.h: * WebKitTestRunner/cocoa/TestRunnerWKWebView.mm: (-[TestRunnerWKWebView initWithFrame:configuration:]): (-[TestRunnerWKWebView _didShowMenu]): (-[TestRunnerWKWebView _didHideMenu]): Make these present across both macOS and iOS. On macOS, we listen for NSMenuDidBeginTrackingNotification and NSMenuDidEndTrackingNotification to know when a menu has been shown or dismissed. (-[TestRunnerWKWebView dismissActiveMenu]): (-[TestRunnerWKWebView resetInteractionCallbacks]): Make these available on both iOS and macOS. The only interaction callbacks on macOS are currently didShowMenuCallback and didHideMenuCallback. (-[TestRunnerWKWebView _willHideMenu]): * WebKitTestRunner/cocoa/UIScriptControllerCocoa.h: * WebKitTestRunner/cocoa/UIScriptControllerCocoa.mm: (WTR::UIScriptControllerCocoa::setDidShowMenuCallback): (WTR::UIScriptControllerCocoa::setDidHideMenuCallback): (WTR::UIScriptControllerCocoa::dismissMenu): (WTR::UIScriptControllerCocoa::isShowingMenu const): Move these implementations into UIScriptControllerCocoa, from UIScriptControllerIOS. * WebKitTestRunner/ios/TestControllerIOS.mm: (WTR::TestController::platformResetStateToConsistentValues): Instead of clearing all interaction callbacks in TestControllerIOS, do it in TestControllerCocoa where it affects both macOS and iOS. * WebKitTestRunner/ios/UIScriptControllerIOS.h: * WebKitTestRunner/ios/UIScriptControllerIOS.mm: (WTR::UIScriptControllerIOS::activateAtPoint): (WTR::UIScriptControllerIOS::singleTapAtPointWithModifiers): (WTR::UIScriptControllerIOS::chooseMenuAction): (WTR::UIScriptControllerIOS::rectForMenuAction const): (WTR::UIScriptControllerIOS::setDidShowMenuCallback): Deleted. (WTR::UIScriptControllerIOS::setDidHideMenuCallback): Deleted. (WTR::UIScriptControllerIOS::isShowingMenu const): Deleted. Abstract rectForMenuAction and singleTapAtPointWithModifiers out into private helper methods, such that they can be used from within other script controller methods. * WebKitTestRunner/mac/UIScriptControllerMac.h: * WebKitTestRunner/mac/UIScriptControllerMac.mm: Implement the new script controller hooks on macOS. (WTR::UIScriptControllerMac::clearAllCallbacks): (WTR::UIScriptControllerMac::chooseMenuAction): (WTR::UIScriptControllerMac::activateAtPoint): LayoutTests: Refactors existing layout tests for programmatic paste requests on iOS, such that they now run in both iOS and macOS. See below for more details. * TestExpectations: * editing/pasteboard/dom-paste/dom-paste-confirmation-expected.txt: Renamed from LayoutTests/editing/pasteboard/ios/dom-paste-confirmation-expected.txt. * editing/pasteboard/dom-paste/dom-paste-confirmation.html: Renamed from LayoutTests/editing/pasteboard/ios/dom-paste-confirmation.html. * editing/pasteboard/dom-paste/dom-paste-consecutive-confirmations-expected.txt: Added. * editing/pasteboard/dom-paste/dom-paste-consecutive-confirmations.html: Renamed from LayoutTests/editing/pasteboard/ios/dom-paste-consecutive-confirmations.html. * editing/pasteboard/dom-paste/dom-paste-rejection-expected.txt: Added. * editing/pasteboard/dom-paste/dom-paste-rejection.html: Renamed from LayoutTests/editing/pasteboard/ios/dom-paste-rejection.html. * editing/pasteboard/dom-paste/dom-paste-requires-user-gesture-expected.txt: Renamed from LayoutTests/editing/pasteboard/ios/dom-paste-requires-user-gesture-expected.txt. * editing/pasteboard/dom-paste/dom-paste-requires-user-gesture.html: Renamed from LayoutTests/editing/pasteboard/ios/dom-paste-requires-user-gesture.html. * editing/pasteboard/dom-paste/dom-paste-same-origin-expected.txt: Renamed from LayoutTests/editing/pasteboard/ios/dom-paste-same-origin-expected.txt. * editing/pasteboard/dom-paste/dom-paste-same-origin.html: Renamed from LayoutTests/editing/pasteboard/ios/dom-paste-same-origin.html. * editing/pasteboard/dom-paste/resources/dom-paste-helper.js: Added. Re-word some of these layout tests' descriptions to reference "clicks or taps", instead of just "taps", and also replace mentions of "callout bars" with platform-agnostic "menus". (return.new.Promise.): (async._waitForOrTriggerPasteMenu): (async.triggerPasteMenuAfterActivatingLocation): (async.waitForPasteMenu): Refactor these testing helpers to support both iOS and macOS: (1) Replace code that finds callout bar menu items and synthesizes taps on iOS, with code that instead chooses a menu item with the given title (in this case, "Paste"). This is supported on both macOS and iOS, where we invoke the NSMenuItem's action and dismiss the menu item, and find and tap the callout bar menu item, respectively. (2) Implement UIScriptController::activateAtPoint, which is used as a cross-platform way of activating an element at the given point. On iOS, this taps the given location, and on macOS, this moves the mouse to that location and then simulates a click (mouse down and mouse up). In a subsequent patch, we should additionally use this in the implementation of UIHelper.activateAt(). * editing/pasteboard/ios/dom-paste-consecutive-confirmations-expected.txt: Removed. * editing/pasteboard/ios/dom-paste-rejection-expected.txt: Removed. * editing/pasteboard/ios/resources/dom-paste-helper.js: Removed. * platform/ios-wk2/TestExpectations: * platform/ios/TestExpectations: * platform/mac-wk2/TestExpectations: * platform/win/TestExpectations: * platform/wincairo/TestExpectations: Skip editing/pasteboard/dom-paste everywhere for now, except for macOS and iOS WebKit2. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@250973 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.
On macOS, download Safari Technology Preview to test the latest version of WebKit. On Linux, download Epiphany Technology Preview. On Windows, you'll have to build it yourself.
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
or
git clone https://git.webkit.org/git/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.
If you don‘t want to use Git, 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 Xcode.
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
For production builds:
cmake -DPORT=GTK -DCMAKE_BUILD_TYPE=RelWithDebInfo -GNinja ninja sudo ninja install
For development builds:
Tools/gtk/install-dependencies Tools/Scripts/update-webkitgtk-libs Tools/Scripts/build-webkit --gtk --debug
For more information on building WebKitGTK+, see the wiki page.
For production builds:
cmake -DPORT=WPE -DCMAKE_BUILD_TYPE=RelWithDebInfo -GNinja ninja sudo ninja install
For development builds:
Tools/wpe/install-dependencies Tools/Scripts/update-webkitwpe-libs Tools/Scripts/build-webkit --wpe --debug
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
.
If you have a development build, you can use the run-minibrowser script, e.g.:
run-minibrowser --debug --wpe
Pass one of --gtk
, --jsc-only
, or --wpe
to indicate the port to use.
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.