Title: [286825] trunk/Source
Revision
286825
Author
[email protected]
Date
2021-12-09 19:08:53 -0800 (Thu, 09 Dec 2021)

Log Message

Add a `DOMPasteAccessCategory` to control which pasteboard the WebProcess is granted access to when pasting
https://bugs.webkit.org/show_bug.cgi?id=233939

Reviewed by Wenson Hsieh.

Implementing `-pasteFont:` <https://webkit.org/b/191379> requires that we read from the font
pasteboard instead of the general pasteboard. In order to allow web content to trigger this
(e.g. `document.execCommand("PasteFont"))`) we must have a way for the WebProcess to signal
that it wishes to read from the font pasteboard instead of the general pasteboard. As such,
create and pass along a `DOMPasteAccessCategory` to `requestDOMPasteAccess`.

No change in behavior.

Source/WebCore:

* dom/DOMPasteAccess.h:
Create `DOMPasteAccessCategory`.

* page/EditorClient.h:
* page/Frame.h:
* page/Frame.cpp:
(WebCore::Frame::requestDOMPasteAccess):
* loader/EmptyClients.cpp:
(WebCore::EmptyEditorClient::requestDOMPasteAccess):
Pass along the `DOMPasteAccessCategory`.

Source/WebKit:

* Scripts/webkit/messages.py:
(headers_for_type):
Indicate which header is associated with `DOMPasteAccessCategory`.

* UIProcess/Cocoa/WebViewImpl.h:
* UIProcess/Cocoa/WebViewImpl.mm:
(-[WKDOMPasteMenuDelegate initWithWebViewImpl:pasteAccessCategory:]): Added.
(-[WKDOMPasteMenuDelegate menuDidClose:]):
(-[WKDOMPasteMenuDelegate _web_grantDOMPasteAccess]): Added.
(WebKit::WebViewImpl::handleProcessSwapOrExit):
(WebKit::pasteboardNameForAccessCategory): Added.
(WebKit::pasteboardForAccessCategory): Added.
(WebKit::WebViewImpl::requestDOMPasteAccess):
(WebKit::WebViewImpl::handleDOMPasteRequestForCategoryWithResult):
(WebKit::WebViewImpl::hideDOMPasteMenuWithResult): Added.
(-[WKDOMPasteMenuDelegate initWithWebViewImpl:]): Deleted.
(WebKit::WebViewImpl::handleDOMPasteRequestWithResult): Deleted.
* UIProcess/API/mac/WKView.mm:
(-[WKView _web_grantDOMPasteAccess]): Deleted.
* UIProcess/API/mac/WKWebViewMac.mm:
(-[WKWebView _web_grantDOMPasteAccess]): Deleted.
Pass the `DOMPasteAccessCategory` to the `WKDOMPasteMenuDelegate` and use it as the `target`
of the `NSMenuItem` so that we can pass along the `DOMPasteAccessCategory` in the `action`.

* UIProcess/ios/WKContentViewInteraction.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(pasteboardNameForAccessCategory): Added.
(pasteboardForAccessCategory): Added.
(-[WKContentView _handleDOMPasteRequestWithResult:]):
(-[WKContentView _requestDOMPasteAccessForCategory:elementRect:originIdentifier:completionHandler:]): Added.
(-[WKContentView _requestDOMPasteAccessWithElementRect:originIdentifier:completionHandler:]): Deleted.
* UIProcess/PageClient.h:
* UIProcess/API/gtk/PageClientImpl.h:
* UIProcess/API/gtk/PageClientImpl.cpp:
(WebKit::PageClientImpl::requestDOMPasteAccess):
* UIProcess/API/wpe/PageClientImpl.h:
* UIProcess/API/wpe/PageClientImpl.cpp:
(WebKit::PageClientImpl::requestDOMPasteAccess):
* UIProcess/ios/PageClientImplIOS.h:
* UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::requestDOMPasteAccess):
* UIProcess/mac/PageClientImplMac.h:
* UIProcess/mac/PageClientImplMac.mm:
(WebKit::PageClientImpl::requestDOMPasteAccess):
* UIProcess/playstation/PageClientImpl.h:
* UIProcess/playstation/PageClientImpl.cpp:
(WebKit::PageClientImpl::requestDOMPasteAccess):
* UIProcess/win/PageClientImpl.h:
* UIProcess/win/PageClientImpl.cpp:
(WebKit::PageClientImpl::requestDOMPasteAccess):
* WebProcess/WebCoreSupport/WebEditorClient.h:
* WebProcess/WebCoreSupport/WebEditorClient.cpp:
(WebKit::WebEditorClient::requestDOMPasteAccess):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::requestDOMPasteAccess):
Pass along the `DOMPasteAccessCategory`.

* UIProcess/WebPageProxy.messages.in:
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::pasteAccessCategoryForCommand): Added.
(WebKit::WebPageProxy::executeEditCommand):
(WebKit::WebPageProxy::requestDOMPasteAccess):
(WebKit::WebPageProxy::willPerformPasteCommand):
(WebKit::isPasteCommandName): Deleted.
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::willPerformPasteCommand):
* UIProcess/mac/WebPageProxyMac.mm:
(WebKit::WebPageProxy::willPerformPasteCommand)
Create a mapping between paste command name and `DOMPasteAccessCategory`.

Source/WebKitLegacy/mac:

* WebCoreSupport/WebEditorClient.h:
(WebEditorClient::requestDOMPasteAccess):

Source/WebKitLegacy/win:

* WebCoreSupport/WebEditorClient.h:
(WebEditorClient::requestDOMPasteAccess):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (286824 => 286825)


--- trunk/Source/WebCore/ChangeLog	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebCore/ChangeLog	2021-12-10 03:08:53 UTC (rev 286825)
@@ -1,3 +1,29 @@
+2021-12-09  Devin Rousso  <[email protected]>
+
+        Add a `DOMPasteAccessCategory` to control which pasteboard the WebProcess is granted access to when pasting
+        https://bugs.webkit.org/show_bug.cgi?id=233939
+
+        Reviewed by Wenson Hsieh.
+
+        Implementing `-pasteFont:` <https://webkit.org/b/191379> requires that we read from the font
+        pasteboard instead of the general pasteboard. In order to allow web content to trigger this
+        (e.g. `document.execCommand("PasteFont"))`) we must have a way for the WebProcess to signal
+        that it wishes to read from the font pasteboard instead of the general pasteboard. As such,
+        create and pass along a `DOMPasteAccessCategory` to `requestDOMPasteAccess`.
+
+        No change in behavior.
+
+        * dom/DOMPasteAccess.h:
+        Create `DOMPasteAccessCategory`.
+
+        * page/EditorClient.h:
+        * page/Frame.h:
+        * page/Frame.cpp:
+        (WebCore::Frame::requestDOMPasteAccess):
+        * loader/EmptyClients.cpp:
+        (WebCore::EmptyEditorClient::requestDOMPasteAccess):
+        Pass along the `DOMPasteAccessCategory`.
+
 2021-12-09  Said Abou-Hallawa  <[email protected]>
 
         [GPU Process] [Filters] Add the encoding and decoding for FEImage

Modified: trunk/Source/WebCore/dom/DOMPasteAccess.h (286824 => 286825)


--- trunk/Source/WebCore/dom/DOMPasteAccess.h	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebCore/dom/DOMPasteAccess.h	2021-12-10 03:08:53 UTC (rev 286825)
@@ -29,6 +29,10 @@
 
 namespace WebCore {
 
+enum class DOMPasteAccessCategory : uint8_t {
+    General,
+};
+
 enum class DOMPasteAccessPolicy : uint8_t {
     NotRequestedYet,
     Denied,
@@ -45,6 +49,13 @@
 
 namespace WTF {
 
+template<> struct EnumTraits<WebCore::DOMPasteAccessCategory> {
+    using values = EnumValues<
+        WebCore::DOMPasteAccessCategory,
+        WebCore::DOMPasteAccessCategory::General
+    >;
+};
+
 template<> struct EnumTraits<WebCore::DOMPasteAccessResponse> {
     using values = EnumValues<
         WebCore::DOMPasteAccessResponse,

Modified: trunk/Source/WebCore/loader/EmptyClients.cpp (286824 => 286825)


--- trunk/Source/WebCore/loader/EmptyClients.cpp	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebCore/loader/EmptyClients.cpp	2021-12-10 03:08:53 UTC (rev 286825)
@@ -286,7 +286,7 @@
     void registerRedoStep(UndoStep&) final;
     void clearUndoRedoOperations() final { }
 
-    DOMPasteAccessResponse requestDOMPasteAccess(const String&) final { return DOMPasteAccessResponse::DeniedForGesture; }
+    DOMPasteAccessResponse requestDOMPasteAccess(DOMPasteAccessCategory, const String&) final { return DOMPasteAccessResponse::DeniedForGesture; }
 
     bool canCopyCut(Frame*, bool defaultValue) const final { return defaultValue; }
     bool canPaste(Frame*, bool defaultValue) const final { return defaultValue; }

Modified: trunk/Source/WebCore/page/EditorClient.h (286824 => 286825)


--- trunk/Source/WebCore/page/EditorClient.h	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebCore/page/EditorClient.h	2021-12-10 03:08:53 UTC (rev 286825)
@@ -36,6 +36,7 @@
 
 namespace WebCore {
 
+enum class DOMPasteAccessCategory : uint8_t;
 enum class DOMPasteAccessResponse : uint8_t;
 
 class DocumentFragment;
@@ -101,7 +102,7 @@
     virtual void requestCandidatesForSelection(const VisibleSelection&) { }
     virtual void handleAcceptedCandidateWithSoftSpaces(TextCheckingResult) { }
 
-    virtual DOMPasteAccessResponse requestDOMPasteAccess(const String& originIdentifier) = 0;
+    virtual DOMPasteAccessResponse requestDOMPasteAccess(DOMPasteAccessCategory, const String& originIdentifier) = 0;
 
     // Notify an input method that a composition was voluntarily discarded by WebCore, so that it could clean up too.
     // This function is not called when a composition is closed per a request from an input method.

Modified: trunk/Source/WebCore/page/Frame.cpp (286824 => 286825)


--- trunk/Source/WebCore/page/Frame.cpp	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebCore/page/Frame.cpp	2021-12-10 03:08:53 UTC (rev 286825)
@@ -561,7 +561,7 @@
 }
 #endif // PLATFORM(IOS_FAMILY)
 
-bool Frame::requestDOMPasteAccess()
+bool Frame::requestDOMPasteAccess(DOMPasteAccessCategory pasteAccessCategory)
 {
     if (m_settings->_javascript_CanAccessClipboard() && m_settings->domPasteAllowed())
         return true;
@@ -589,7 +589,7 @@
         if (!client)
             return false;
 
-        auto response = client->requestDOMPasteAccess(m_doc->originIdentifierForPasteboard());
+        auto response = client->requestDOMPasteAccess(pasteAccessCategory, m_doc->originIdentifierForPasteboard());
         gestureToken->didRequestDOMPasteAccess(response);
         switch (response) {
         case DOMPasteAccessResponse::GrantedForCommand:

Modified: trunk/Source/WebCore/page/Frame.h (286824 => 286825)


--- trunk/Source/WebCore/page/Frame.h	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebCore/page/Frame.h	2021-12-10 03:08:53 UTC (rev 286825)
@@ -176,7 +176,7 @@
     bool hasHadUserInteraction() const { return m_hasHadUserInteraction; }
     void setHasHadUserInteraction() { m_hasHadUserInteraction = true; }
 
-    bool requestDOMPasteAccess();
+    bool requestDOMPasteAccess(DOMPasteAccessCategory = DOMPasteAccessCategory::General);
 
     String debugDescription() const;
 

Modified: trunk/Source/WebKit/ChangeLog (286824 => 286825)


--- trunk/Source/WebKit/ChangeLog	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebKit/ChangeLog	2021-12-10 03:08:53 UTC (rev 286825)
@@ -1,3 +1,90 @@
+2021-12-09  Devin Rousso  <[email protected]>
+
+        Add a `DOMPasteAccessCategory` to control which pasteboard the WebProcess is granted access to when pasting
+        https://bugs.webkit.org/show_bug.cgi?id=233939
+
+        Reviewed by Wenson Hsieh.
+
+        Implementing `-pasteFont:` <https://webkit.org/b/191379> requires that we read from the font
+        pasteboard instead of the general pasteboard. In order to allow web content to trigger this
+        (e.g. `document.execCommand("PasteFont"))`) we must have a way for the WebProcess to signal
+        that it wishes to read from the font pasteboard instead of the general pasteboard. As such,
+        create and pass along a `DOMPasteAccessCategory` to `requestDOMPasteAccess`.
+
+        No change in behavior.
+
+        * Scripts/webkit/messages.py:
+        (headers_for_type):
+        Indicate which header is associated with `DOMPasteAccessCategory`.
+
+        * UIProcess/Cocoa/WebViewImpl.h:
+        * UIProcess/Cocoa/WebViewImpl.mm:
+        (-[WKDOMPasteMenuDelegate initWithWebViewImpl:pasteAccessCategory:]): Added.
+        (-[WKDOMPasteMenuDelegate menuDidClose:]):
+        (-[WKDOMPasteMenuDelegate _web_grantDOMPasteAccess]): Added.
+        (WebKit::WebViewImpl::handleProcessSwapOrExit):
+        (WebKit::pasteboardNameForAccessCategory): Added.
+        (WebKit::pasteboardForAccessCategory): Added.
+        (WebKit::WebViewImpl::requestDOMPasteAccess):
+        (WebKit::WebViewImpl::handleDOMPasteRequestForCategoryWithResult):
+        (WebKit::WebViewImpl::hideDOMPasteMenuWithResult): Added.
+        (-[WKDOMPasteMenuDelegate initWithWebViewImpl:]): Deleted.
+        (WebKit::WebViewImpl::handleDOMPasteRequestWithResult): Deleted.
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView _web_grantDOMPasteAccess]): Deleted.
+        * UIProcess/API/mac/WKWebViewMac.mm:
+        (-[WKWebView _web_grantDOMPasteAccess]): Deleted.
+        Pass the `DOMPasteAccessCategory` to the `WKDOMPasteMenuDelegate` and use it as the `target`
+        of the `NSMenuItem` so that we can pass along the `DOMPasteAccessCategory` in the `action`.
+
+        * UIProcess/ios/WKContentViewInteraction.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (pasteboardNameForAccessCategory): Added.
+        (pasteboardForAccessCategory): Added.
+        (-[WKContentView _handleDOMPasteRequestWithResult:]):
+        (-[WKContentView _requestDOMPasteAccessForCategory:elementRect:originIdentifier:completionHandler:]): Added.
+        (-[WKContentView _requestDOMPasteAccessWithElementRect:originIdentifier:completionHandler:]): Deleted.
+        * UIProcess/PageClient.h:
+        * UIProcess/API/gtk/PageClientImpl.h:
+        * UIProcess/API/gtk/PageClientImpl.cpp:
+        (WebKit::PageClientImpl::requestDOMPasteAccess):
+        * UIProcess/API/wpe/PageClientImpl.h:
+        * UIProcess/API/wpe/PageClientImpl.cpp:
+        (WebKit::PageClientImpl::requestDOMPasteAccess):
+        * UIProcess/ios/PageClientImplIOS.h:
+        * UIProcess/ios/PageClientImplIOS.mm:
+        (WebKit::PageClientImpl::requestDOMPasteAccess):
+        * UIProcess/mac/PageClientImplMac.h:
+        * UIProcess/mac/PageClientImplMac.mm:
+        (WebKit::PageClientImpl::requestDOMPasteAccess):
+        * UIProcess/playstation/PageClientImpl.h:
+        * UIProcess/playstation/PageClientImpl.cpp:
+        (WebKit::PageClientImpl::requestDOMPasteAccess):
+        * UIProcess/win/PageClientImpl.h:
+        * UIProcess/win/PageClientImpl.cpp:
+        (WebKit::PageClientImpl::requestDOMPasteAccess):
+        * WebProcess/WebCoreSupport/WebEditorClient.h:
+        * WebProcess/WebCoreSupport/WebEditorClient.cpp:
+        (WebKit::WebEditorClient::requestDOMPasteAccess):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::requestDOMPasteAccess):
+        Pass along the `DOMPasteAccessCategory`.
+
+        * UIProcess/WebPageProxy.messages.in:
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::pasteAccessCategoryForCommand): Added.
+        (WebKit::WebPageProxy::executeEditCommand):
+        (WebKit::WebPageProxy::requestDOMPasteAccess):
+        (WebKit::WebPageProxy::willPerformPasteCommand):
+        (WebKit::isPasteCommandName): Deleted.
+        * UIProcess/ios/WebPageProxyIOS.mm:
+        (WebKit::WebPageProxy::willPerformPasteCommand):
+        * UIProcess/mac/WebPageProxyMac.mm:
+        (WebKit::WebPageProxy::willPerformPasteCommand)
+        Create a mapping between paste command name and `DOMPasteAccessCategory`.
+
 2021-12-09  Said Abou-Hallawa  <[email protected]>
 
         [GPU Process] [Filters] Add the encoding and decoding for FEImage

Modified: trunk/Source/WebKit/Scripts/webkit/messages.py (286824 => 286825)


--- trunk/Source/WebKit/Scripts/webkit/messages.py	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebKit/Scripts/webkit/messages.py	2021-12-10 03:08:53 UTC (rev 286825)
@@ -758,6 +758,7 @@
         'WebCore::COOPDisposition': ['<WebCore/CrossOriginOpenerPolicy.h>'],
         'WebCore::CompositeOperator': ['<WebCore/GraphicsTypes.h>'],
         'WebCore::CreateNewGroupForHighlight': ['<WebCore/AppHighlight.h>'],
+        'WebCore::DOMPasteAccessCategory': ['<WebCore/DOMPasteAccess.h>'],
         'WebCore::DOMPasteAccessResponse': ['<WebCore/DOMPasteAccess.h>'],
         'WebCore::DestinationColorSpace': ['<WebCore/ColorSpace.h>'],
         'WebCore::DisplayList::ItemBufferIdentifier': ['<WebCore/DisplayList.h>'],

Modified: trunk/Source/WebKit/UIProcess/API/gtk/PageClientImpl.cpp (286824 => 286825)


--- trunk/Source/WebKit/UIProcess/API/gtk/PageClientImpl.cpp	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebKit/UIProcess/API/gtk/PageClientImpl.cpp	2021-12-10 03:08:53 UTC (rev 286825)
@@ -548,7 +548,7 @@
 }
 #endif
 
-void PageClientImpl::requestDOMPasteAccess(const IntRect&, const String&, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&& completionHandler)
+void PageClientImpl::requestDOMPasteAccess(WebCore::DOMPasteAccessCategory, const IntRect&, const String&, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&& completionHandler)
 {
     completionHandler(WebCore::DOMPasteAccessResponse::DeniedForGesture);
 }

Modified: trunk/Source/WebKit/UIProcess/API/gtk/PageClientImpl.h (286824 => 286825)


--- trunk/Source/WebKit/UIProcess/API/gtk/PageClientImpl.h	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebKit/UIProcess/API/gtk/PageClientImpl.h	2021-12-10 03:08:53 UTC (rev 286825)
@@ -160,7 +160,7 @@
     void isPlayingAudioWillChange() final { }
     void isPlayingAudioDidChange() final { }
 
-    void requestDOMPasteAccess(const WebCore::IntRect&, const String&, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&&) final;
+    void requestDOMPasteAccess(WebCore::DOMPasteAccessCategory, const WebCore::IntRect&, const String&, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&&) final;
 
 #if ENABLE(VIDEO) && USE(GSTREAMER)
     bool decidePolicyForInstallMissingMediaPluginsPermissionRequest(InstallMissingMediaPluginsPermissionRequest&) override;

Modified: trunk/Source/WebKit/UIProcess/API/mac/WKView.mm (286824 => 286825)


--- trunk/Source/WebKit/UIProcess/API/mac/WKView.mm	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebKit/UIProcess/API/mac/WKView.mm	2021-12-10 03:08:53 UTC (rev 286825)
@@ -912,11 +912,6 @@
     return _data->_impl->namesOfPromisedFilesDroppedAtDestination(dropDestination);
 }
 
-- (void)_web_grantDOMPasteAccess
-{
-    _data->_impl->handleDOMPasteRequestWithResult(WebCore::DOMPasteAccessResponse::GrantedForGesture);
-}
-
 - (void)maybeInstallIconLoadingClient
 {
     ALLOW_DEPRECATED_DECLARATIONS_BEGIN

Modified: trunk/Source/WebKit/UIProcess/API/mac/WKWebViewMac.mm (286824 => 286825)


--- trunk/Source/WebKit/UIProcess/API/mac/WKWebViewMac.mm	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebKit/UIProcess/API/mac/WKWebViewMac.mm	2021-12-10 03:08:53 UTC (rev 286825)
@@ -1232,11 +1232,6 @@
     [self _gestureEventWasNotHandledByWebCore:event];
 }
 
-- (void)_web_grantDOMPasteAccess
-{
-    _impl->handleDOMPasteRequestWithResult(WebCore::DOMPasteAccessResponse::GrantedForGesture);
-}
-
 - (void)_takeFindStringFromSelectionInternal:(id)sender
 {
     [self takeFindStringFromSelection:sender];

Modified: trunk/Source/WebKit/UIProcess/API/wpe/PageClientImpl.cpp (286824 => 286825)


--- trunk/Source/WebKit/UIProcess/API/wpe/PageClientImpl.cpp	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebKit/UIProcess/API/wpe/PageClientImpl.cpp	2021-12-10 03:08:53 UTC (rev 286825)
@@ -415,7 +415,7 @@
 
 #endif // ENABLE(FULLSCREEN_API)
 
-void PageClientImpl::requestDOMPasteAccess(const WebCore::IntRect&, const String&, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&& completionHandler)
+void PageClientImpl::requestDOMPasteAccess(WebCore::DOMPasteAccessCategory, const WebCore::IntRect&, const String&, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&& completionHandler)
 {
     completionHandler(WebCore::DOMPasteAccessResponse::DeniedForGesture);
 }

Modified: trunk/Source/WebKit/UIProcess/API/wpe/PageClientImpl.h (286824 => 286825)


--- trunk/Source/WebKit/UIProcess/API/wpe/PageClientImpl.h	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebKit/UIProcess/API/wpe/PageClientImpl.h	2021-12-10 03:08:53 UTC (rev 286825)
@@ -36,6 +36,7 @@
 }
 
 namespace WebCore {
+enum class DOMPasteAccessCategory : uint8_t;
 enum class DOMPasteAccessResponse : uint8_t;
 }
 
@@ -158,7 +159,7 @@
 #endif
 
     IPC::Attachment hostFileDescriptor() final;
-    void requestDOMPasteAccess(const WebCore::IntRect&, const String&, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&&) final;
+    void requestDOMPasteAccess(WebCore::DOMPasteAccessCategory, const WebCore::IntRect&, const String&, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&&) final;
 
     WebCore::UserInterfaceLayoutDirection userInterfaceLayoutDirection() override;
 

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h (286824 => 286825)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h	2021-12-10 03:08:53 UTC (rev 286825)
@@ -135,8 +135,6 @@
 - (void)_web_didPerformDragOperation:(BOOL)handled;
 #endif
 
-- (void)_web_grantDOMPasteAccess;
-
 @optional
 - (void)_web_didAddMediaControlsManager:(id)controlsManager;
 - (void)_web_didRemoveMediaControlsManager;
@@ -652,9 +650,10 @@
     void takeFocus(WebCore::FocusDirection);
     void clearPromisedDragImage();
 
-    void requestDOMPasteAccess(const WebCore::IntRect&, const String& originIdentifier, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&&);
-    void handleDOMPasteRequestWithResult(WebCore::DOMPasteAccessResponse);
+    void requestDOMPasteAccess(WebCore::DOMPasteAccessCategory, const WebCore::IntRect&, const String& originIdentifier, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&&);
+    void handleDOMPasteRequestForCategoryWithResult(WebCore::DOMPasteAccessCategory, WebCore::DOMPasteAccessResponse);
     NSMenu *domPasteMenu() const { return m_domPasteMenu.get(); }
+    void hideDOMPasteMenuWithResult(WebCore::DOMPasteAccessResponse);
 
 #if HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS)
     bool canHandleContextMenuTranslation() const;

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm (286824 => 286825)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm	2021-12-10 03:08:53 UTC (rev 286825)
@@ -1007,19 +1007,21 @@
 @end
 
 @interface WKDOMPasteMenuDelegate : NSObject<NSMenuDelegate>
-- (instancetype)initWithWebViewImpl:(WebKit::WebViewImpl&)impl;
+- (instancetype)initWithWebViewImpl:(WebKit::WebViewImpl&)impl pasteAccessCategory:(WebCore::DOMPasteAccessCategory)category;
 @end
 
 @implementation WKDOMPasteMenuDelegate {
     WeakPtr<WebKit::WebViewImpl> _impl;
+    WebCore::DOMPasteAccessCategory _category;
 }
 
-- (instancetype)initWithWebViewImpl:(WebKit::WebViewImpl&)impl
+- (instancetype)initWithWebViewImpl:(WebKit::WebViewImpl&)impl pasteAccessCategory:(WebCore::DOMPasteAccessCategory)category
 {
     if (!(self = [super init]))
         return nil;
 
     _impl = impl;
+    _category = category;
     return self;
 }
 
@@ -1027,7 +1029,7 @@
 {
     RunLoop::main().dispatch([impl = _impl] {
         if (impl)
-            impl->handleDOMPasteRequestWithResult(WebCore::DOMPasteAccessResponse::DeniedForGesture);
+            impl->hideDOMPasteMenuWithResult(WebCore::DOMPasteAccessResponse::DeniedForGesture);
     });
 }
 
@@ -1043,6 +1045,11 @@
     return confinementRect;
 }
 
+- (void)_web_grantDOMPasteAccess
+{
+    _impl->handleDOMPasteRequestForCategoryWithResult(_category, WebCore::DOMPasteAccessResponse::GrantedForGesture);
+}
+
 @end
 
 namespace WebKit {
@@ -1603,7 +1610,7 @@
 
     updateRemoteAccessibilityRegistration(false);
 
-    handleDOMPasteRequestWithResult(WebCore::DOMPasteAccessResponse::DeniedForGesture);
+    hideDOMPasteMenuWithResult(WebCore::DOMPasteAccessResponse::DeniedForGesture);
 }
 
 void WebViewImpl::processWillSwap()
@@ -4578,34 +4585,58 @@
     return @[[path lastPathComponent]];
 }
 
-void WebViewImpl::requestDOMPasteAccess(const WebCore::IntRect&, const String& originIdentifier, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&& completion)
+static NSPasteboardName pasteboardNameForAccessCategory(WebCore::DOMPasteAccessCategory pasteAccessCategory)
 {
+    switch (pasteAccessCategory) {
+    case WebCore::DOMPasteAccessCategory::General:
+        return NSPasteboardNameGeneral;
+    }
+}
+
+static NSPasteboard *pasteboardForAccessCategory(WebCore::DOMPasteAccessCategory pasteAccessCategory)
+{
+    switch (pasteAccessCategory) {
+    case WebCore::DOMPasteAccessCategory::General:
+        return NSPasteboard.generalPasteboard;
+    }
+}
+
+void WebViewImpl::requestDOMPasteAccess(WebCore::DOMPasteAccessCategory pasteAccessCategory, const WebCore::IntRect&, const String& originIdentifier, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&& completion)
+{
     ASSERT(!m_domPasteRequestHandler);
-    handleDOMPasteRequestWithResult(WebCore::DOMPasteAccessResponse::DeniedForGesture);
+    hideDOMPasteMenuWithResult(WebCore::DOMPasteAccessResponse::DeniedForGesture);
 
-    NSData *data = "" dataForType:@(WebCore::PasteboardCustomData::cocoaType())];
+    NSData *data = "" dataForType:@(WebCore::PasteboardCustomData::cocoaType())];
     auto buffer = WebCore::SharedBuffer::create(data);
     if (WebCore::PasteboardCustomData::fromSharedBuffer(buffer.get()).origin() == originIdentifier) {
-        m_page->grantAccessToCurrentPasteboardData(NSPasteboardNameGeneral);
+        m_page->grantAccessToCurrentPasteboardData(pasteboardNameForAccessCategory(pasteAccessCategory));
         completion(WebCore::DOMPasteAccessResponse::GrantedForGesture);
         return;
     }
 
-    m_domPasteMenuDelegate = adoptNS([[WKDOMPasteMenuDelegate alloc] initWithWebViewImpl:*this]);
+    m_domPasteMenuDelegate = adoptNS([[WKDOMPasteMenuDelegate alloc] initWithWebViewImpl:*this pasteAccessCategory:pasteAccessCategory]);
     m_domPasteRequestHandler = WTFMove(completion);
     m_domPasteMenu = adoptNS([[NSMenu alloc] initWithTitle:WebCore::contextMenuItemTagPaste()]);
 
     [m_domPasteMenu setDelegate:m_domPasteMenuDelegate.get()];
     [m_domPasteMenu setAllowsContextMenuPlugIns:NO];
-    [m_domPasteMenu insertItemWithTitle:WebCore::contextMenuItemTagPaste() action:@selector(_web_grantDOMPasteAccess) keyEquivalent:emptyString() atIndex:0];
+
+    auto pasteMenuItem = RetainPtr([m_domPasteMenu insertItemWithTitle:WebCore::contextMenuItemTagPaste() action:@selector(_web_grantDOMPasteAccess) keyEquivalent:emptyString() atIndex:0]);
+    [pasteMenuItem setTarget:m_domPasteMenuDelegate.get()];
+
     [NSMenu popUpContextMenu:m_domPasteMenu.get() withEvent:m_lastMouseDownEvent.get() forView:m_view.getAutoreleased()];
 }
 
-void WebViewImpl::handleDOMPasteRequestWithResult(WebCore::DOMPasteAccessResponse response)
+void WebViewImpl::handleDOMPasteRequestForCategoryWithResult(WebCore::DOMPasteAccessCategory pasteAccessCategory, WebCore::DOMPasteAccessResponse response)
 {
     if (response == WebCore::DOMPasteAccessResponse::GrantedForCommand || response == WebCore::DOMPasteAccessResponse::GrantedForGesture)
-        m_page->grantAccessToCurrentPasteboardData(NSPasteboardNameGeneral);
+        m_page->grantAccessToCurrentPasteboardData(pasteboardNameForAccessCategory(pasteAccessCategory));
 
+    hideDOMPasteMenuWithResult(response);
+}
+
+void WebViewImpl::hideDOMPasteMenuWithResult(WebCore::DOMPasteAccessResponse response)
+{
     if (auto handler = std::exchange(m_domPasteRequestHandler, { }))
         handler(response);
     [m_domPasteMenu removeAllItems];

Modified: trunk/Source/WebKit/UIProcess/PageClient.h (286824 => 286825)


--- trunk/Source/WebKit/UIProcess/PageClient.h	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebKit/UIProcess/PageClient.h	2021-12-10 03:08:53 UTC (rev 286825)
@@ -110,6 +110,7 @@
 enum class ScrollbarStyle : uint8_t;
 enum class TextIndicatorLifetime : uint8_t;
 enum class TextIndicatorDismissalAnimation : uint8_t;
+enum class DOMPasteAccessCategory : uint8_t;
 enum class DOMPasteAccessResponse : uint8_t;
 enum class ScrollIsAnimated : uint8_t;
 
@@ -599,7 +600,7 @@
     virtual void didChangeDragCaretRect(const WebCore::IntRect& previousCaretRect, const WebCore::IntRect& caretRect) = 0;
 #endif
 
-    virtual void requestDOMPasteAccess(const WebCore::IntRect& elementRect, const String& originIdentifier, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&&) = 0;
+    virtual void requestDOMPasteAccess(WebCore::DOMPasteAccessCategory, const WebCore::IntRect& elementRect, const String& originIdentifier, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&&) = 0;
 
 #if ENABLE(ATTACHMENT_ELEMENT)
     virtual void didInsertAttachment(API::Attachment&, const String& source) { }

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (286824 => 286825)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-12-10 03:08:53 UTC (rev 286825)
@@ -2510,15 +2510,20 @@
     send(Messages::WebPage::SelectAll());
 }
 
-static bool isPasteCommandName(const String& commandName)
+static std::optional<DOMPasteAccessCategory> pasteAccessCategoryForCommand(const String& commandName)
 {
-    static NeverDestroyed<HashSet<String, ASCIICaseInsensitiveHash>> pasteCommandNames = HashSet<String, ASCIICaseInsensitiveHash> {
-        "Paste",
-        "PasteAndMatchStyle",
-        "PasteAsQuotation",
-        "PasteAsPlainText"
+    static NeverDestroyed<HashMap<String, DOMPasteAccessCategory, ASCIICaseInsensitiveHash>> pasteCommandNames = HashMap<String, DOMPasteAccessCategory, ASCIICaseInsensitiveHash> {
+        { "Paste", DOMPasteAccessCategory::General },
+        { "PasteAndMatchStyle", DOMPasteAccessCategory::General },
+        { "PasteAsQuotation", DOMPasteAccessCategory::General },
+        { "PasteAsPlainText", DOMPasteAccessCategory::General },
     };
-    return pasteCommandNames->contains(commandName);
+
+    auto it = pasteCommandNames->find(commandName);
+    if (it != pasteCommandNames->end())
+        return it->value;
+
+    return std::nullopt;
 }
 
 void WebPageProxy::executeEditCommand(const String& commandName, const String& argument, CompletionHandler<void()>&& callbackFunction)
@@ -2528,8 +2533,8 @@
         return;
     }
 
-    if (isPasteCommandName(commandName))
-        willPerformPasteCommand();
+    if (auto pasteAccessCategory = pasteAccessCategoryForCommand(commandName))
+        willPerformPasteCommand(*pasteAccessCategory);
 
     sendWithAsyncReply(Messages::WebPage::ExecuteEditCommandWithCallback(commandName, argument), [callbackFunction = WTFMove(callbackFunction), backgroundActivity = m_process->throttler().backgroundActivity("WebPageProxy::executeEditCommand"_s)] () mutable {
         callbackFunction();
@@ -2543,8 +2548,8 @@
     if (!hasRunningProcess())
         return;
 
-    if (isPasteCommandName(commandName))
-        willPerformPasteCommand();
+    if (auto pasteAccessCategory = pasteAccessCategoryForCommand(commandName))
+        willPerformPasteCommand(*pasteAccessCategory);
 
     if (commandName == ignoreSpellingCommandName)
         ++m_pendingLearnOrIgnoreWordMessageCount;
@@ -6616,9 +6621,9 @@
 
 #endif
 
-void WebPageProxy::requestDOMPasteAccess(const WebCore::IntRect& elementRect, const String& originIdentifier, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&& completionHandler)
+void WebPageProxy::requestDOMPasteAccess(WebCore::DOMPasteAccessCategory pasteAccessCategory, const WebCore::IntRect& elementRect, const String& originIdentifier, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&& completionHandler)
 {
-    m_pageClient->requestDOMPasteAccess(elementRect, originIdentifier, WTFMove(completionHandler));
+    m_pageClient->requestDOMPasteAccess(pasteAccessCategory, elementRect, originIdentifier, WTFMove(completionHandler));
 }
 
 // BackForwardList
@@ -10822,7 +10827,7 @@
 
 #if !PLATFORM(COCOA)
 
-void WebPageProxy::willPerformPasteCommand()
+void WebPageProxy::willPerformPasteCommand(DOMPasteAccessCategory)
 {
 }
 

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (286824 => 286825)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2021-12-10 03:08:53 UTC (rev 286825)
@@ -267,6 +267,7 @@
 enum class AutoplayEvent : uint8_t;
 enum class CookieConsentDecisionResult : uint8_t;
 enum class CreateNewGroupForHighlight : bool;
+enum class DOMPasteAccessCategory : uint8_t;
 enum class DOMPasteAccessResponse : uint8_t;
 enum class EventMakesGamepadsVisible : bool;
 enum class LockBackForwardList : bool;
@@ -2261,8 +2262,8 @@
     void setIsNeverRichlyEditableForTouchBar(bool);
 #endif
 
-    void requestDOMPasteAccess(const WebCore::IntRect&, const String&, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&&);
-    void willPerformPasteCommand();
+    void requestDOMPasteAccess(WebCore::DOMPasteAccessCategory, const WebCore::IntRect&, const String&, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&&);
+    void willPerformPasteCommand(WebCore::DOMPasteAccessCategory);
 
     // Back/Forward list management
     void backForwardAddItem(BackForwardListItemState&&);

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in (286824 => 286825)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2021-12-10 03:08:53 UTC (rev 286825)
@@ -232,7 +232,7 @@
     SetIsNeverRichlyEditableForTouchBar(bool isNeverRichlyEditable)
 #endif
 
-    RequestDOMPasteAccess(WebCore::IntRect elementRect, String originIdentifier) -> (enum:uint8_t WebCore::DOMPasteAccessResponse response) Synchronous
+    RequestDOMPasteAccess(enum:uint8_t WebCore::DOMPasteAccessCategory pasteAccessCategory, WebCore::IntRect elementRect, String originIdentifier) -> (enum:uint8_t WebCore::DOMPasteAccessResponse response) Synchronous
 
     # Find messages
     DidCountStringMatches(String string, uint32_t matchCount)

Modified: trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.h (286824 => 286825)


--- trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.h	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.h	2021-12-10 03:08:53 UTC (rev 286825)
@@ -38,6 +38,7 @@
 OBJC_CLASS WKEditorUndoTarget;
 
 namespace WebCore {
+enum class DOMPasteAccessCategory : uint8_t;
 enum class DOMPasteAccessResponse : uint8_t;
 struct PromisedAttachmentInfo;
 }
@@ -266,7 +267,7 @@
     void requestPasswordForQuickLookDocument(const String& fileName, WTF::Function<void(const String&)>&&) override;
 #endif
 
-    void requestDOMPasteAccess(const WebCore::IntRect& elementRect, const String&, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&&) final;
+    void requestDOMPasteAccess(WebCore::DOMPasteAccessCategory, const WebCore::IntRect& elementRect, const String&, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&&) final;
 
 #if ENABLE(DRAG_SUPPORT)
     void didPerformDragOperation(bool handled) override;

Modified: trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm (286824 => 286825)


--- trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm	2021-12-10 03:08:53 UTC (rev 286825)
@@ -951,9 +951,9 @@
 }
 #endif
 
-void PageClientImpl::requestDOMPasteAccess(const WebCore::IntRect& elementRect, const String& originIdentifier, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&& completionHandler)
+void PageClientImpl::requestDOMPasteAccess(WebCore::DOMPasteAccessCategory pasteAccessCategory, const WebCore::IntRect& elementRect, const String& originIdentifier, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&& completionHandler)
 {
-    [m_contentView _requestDOMPasteAccessWithElementRect:elementRect originIdentifier:originIdentifier completionHandler:WTFMove(completionHandler)];
+    [m_contentView _requestDOMPasteAccessForCategory:pasteAccessCategory elementRect:elementRect originIdentifier:originIdentifier completionHandler:WTFMove(completionHandler)];
 }
 
 void PageClientImpl::cancelPointersForGestureRecognizer(UIGestureRecognizer* gestureRecognizer)

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h (286824 => 286825)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h	2021-12-10 03:08:53 UTC (rev 286825)
@@ -90,6 +90,7 @@
 struct PromisedAttachmentInfo;
 struct ShareDataWithParsedURL;
 struct TextRecognitionResult;
+enum class DOMPasteAccessCategory : uint8_t;
 enum class DOMPasteAccessResponse : uint8_t;
 enum class MouseEventPolicy : uint8_t;
 enum class RouteSharingPolicy : uint8_t;
@@ -459,6 +460,7 @@
     NSUInteger _activeTextInteractionCount;
     NSInteger _suppressNonEditableSingleTapTextInteractionCount;
     CompletionHandler<void(WebCore::DOMPasteAccessResponse)> _domPasteRequestHandler;
+    std::optional<WebCore::DOMPasteAccessCategory> _domPasteRequestCategory;
     BlockPtr<void(UIWKAutocorrectionContext *)> _pendingAutocorrectionContextHandler;
     CompletionHandler<void()> _pendingRunModalJavaScriptDialogCallback;
 
@@ -678,7 +680,7 @@
 - (void)updateFocusedElementSelectedIndex:(uint32_t)index allowsMultipleSelection:(bool)allowsMultipleSelection;
 - (void)updateFocusedElementFocusedWithDataListDropdown:(BOOL)value;
 
-- (void)_requestDOMPasteAccessWithElementRect:(const WebCore::IntRect&)elementRect originIdentifier:(const String&)originIdentifier completionHandler:(CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&&)completionHandler;
+- (void)_requestDOMPasteAccessForCategory:(WebCore::DOMPasteAccessCategory)pasteAccessCategory elementRect:(const WebCore::IntRect&)elementRect originIdentifier:(const String&)originIdentifier completionHandler:(CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&&)completionHandler;
 
 - (void)doAfterPositionInformationUpdate:(void (^)(WebKit::InteractionInformationAtPosition))action forRequest:(WebKit::InteractionInformationRequest)request;
 - (BOOL)ensurePositionInformationIsUpToDate:(WebKit::InteractionInformationRequest)request;

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (286824 => 286825)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2021-12-10 03:08:53 UTC (rev 286825)
@@ -4164,10 +4164,28 @@
     _page->storeSelectionForAccessibility(false);
 }
 
+static UIPasteboardName pasteboardNameForAccessCategory(WebCore::DOMPasteAccessCategory pasteAccessCategory)
+{
+    switch (pasteAccessCategory) {
+    case WebCore::DOMPasteAccessCategory::General:
+        return UIPasteboardNameGeneral;
+    }
+}
+
+static UIPasteboard *pasteboardForAccessCategory(WebCore::DOMPasteAccessCategory pasteAccessCategory)
+{
+    switch (pasteAccessCategory) {
+    case WebCore::DOMPasteAccessCategory::General:
+        return UIPasteboard.generalPasteboard;
+    }
+}
+
 - (BOOL)_handleDOMPasteRequestWithResult:(WebCore::DOMPasteAccessResponse)response
 {
-    if (response == WebCore::DOMPasteAccessResponse::GrantedForCommand || response == WebCore::DOMPasteAccessResponse::GrantedForGesture)
-        _page->grantAccessToCurrentPasteboardData(UIPasteboardNameGeneral);
+    if (auto pasteAccessCategory = std::exchange(_domPasteRequestCategory, std::nullopt)) {
+        if (response == WebCore::DOMPasteAccessResponse::GrantedForCommand || response == WebCore::DOMPasteAccessResponse::GrantedForGesture)
+            _page->grantAccessToCurrentPasteboardData(pasteboardNameForAccessCategory(*pasteAccessCategory));
+    }
 
     if (auto pasteHandler = WTFMove(_domPasteRequestHandler)) {
         [UIMenuController.sharedMenuController hideMenuFromView:self];
@@ -6635,7 +6653,7 @@
     return foundAtLeastOneMatchingIdentifier;
 }
 
-- (void)_requestDOMPasteAccessWithElementRect:(const WebCore::IntRect&)elementRect originIdentifier:(const String&)originIdentifier completionHandler:(CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&&)completionHandler
+- (void)_requestDOMPasteAccessForCategory:(WebCore::DOMPasteAccessCategory)pasteAccessCategory elementRect:(const WebCore::IntRect&)elementRect originIdentifier:(const String&)originIdentifier completionHandler:(CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&&)completionHandler
 {
     if (auto existingCompletionHandler = std::exchange(_domPasteRequestHandler, WTFMove(completionHandler))) {
         ASSERT_NOT_REACHED();
@@ -6642,7 +6660,9 @@
         existingCompletionHandler(WebCore::DOMPasteAccessResponse::DeniedForGesture);
     }
 
-    if (allPasteboardItemOriginsMatchOrigin(UIPasteboard.generalPasteboard, originIdentifier)) {
+    _domPasteRequestCategory = pasteAccessCategory;
+
+    if (allPasteboardItemOriginsMatchOrigin(pasteboardForAccessCategory(pasteAccessCategory), originIdentifier)) {
         [self _handleDOMPasteRequestWithResult:WebCore::DOMPasteAccessResponse::GrantedForCommand];
         return;
     }

Modified: trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm (286824 => 286825)


--- trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm	2021-12-10 03:08:53 UTC (rev 286825)
@@ -1544,9 +1544,13 @@
 }
 #endif
 
-void WebPageProxy::willPerformPasteCommand()
+void WebPageProxy::willPerformPasteCommand(DOMPasteAccessCategory pasteAccessCategory)
 {
-    grantAccessToCurrentPasteboardData(UIPasteboardNameGeneral);
+    switch (pasteAccessCategory) {
+    case DOMPasteAccessCategory::General:
+        grantAccessToCurrentPasteboardData(UIPasteboardNameGeneral);
+        return;
+    }
 }
 
 void WebPageProxy::setDeviceHasAGXCompilerServiceForTesting() const

Modified: trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.h (286824 => 286825)


--- trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.h	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.h	2021-12-10 03:08:53 UTC (rev 286825)
@@ -225,7 +225,7 @@
     void willRecordNavigationSnapshot(WebBackForwardListItem&) override;
     void didRemoveNavigationGestureSnapshot() override;
 
-    void requestDOMPasteAccess(const WebCore::IntRect&, const String&, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&&) final;
+    void requestDOMPasteAccess(WebCore::DOMPasteAccessCategory, const WebCore::IntRect&, const String&, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&&) final;
 
     void makeViewBlank(bool) final;
 

Modified: trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.mm (286824 => 286825)


--- trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.mm	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.mm	2021-12-10 03:08:53 UTC (rev 286825)
@@ -1000,9 +1000,9 @@
     m_impl->takeFocus(direction);
 }
 
-void PageClientImpl::requestDOMPasteAccess(const WebCore::IntRect& elementRect, const String& originIdentifier, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&& completion)
+void PageClientImpl::requestDOMPasteAccess(WebCore::DOMPasteAccessCategory pasteAccessCategory, const WebCore::IntRect& elementRect, const String& originIdentifier, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&& completion)
 {
-    m_impl->requestDOMPasteAccess(elementRect, originIdentifier, WTFMove(completion));
+    m_impl->requestDOMPasteAccess(pasteAccessCategory, elementRect, originIdentifier, WTFMove(completion));
 }
 
 

Modified: trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm (286824 => 286825)


--- trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm	2021-12-10 03:08:53 UTC (rev 286825)
@@ -651,9 +651,13 @@
 
 #endif
 
-void WebPageProxy::willPerformPasteCommand()
+void WebPageProxy::willPerformPasteCommand(DOMPasteAccessCategory pasteAccessCategory)
 {
-    grantAccessToCurrentPasteboardData(NSPasteboardNameGeneral);
+    switch (pasteAccessCategory) {
+    case DOMPasteAccessCategory::General:
+        grantAccessToCurrentPasteboardData(NSPasteboardNameGeneral);
+        return;
+    }
 }
 
 PlatformView* WebPageProxy::platformView() const

Modified: trunk/Source/WebKit/UIProcess/playstation/PageClientImpl.cpp (286824 => 286825)


--- trunk/Source/WebKit/UIProcess/playstation/PageClientImpl.cpp	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebKit/UIProcess/playstation/PageClientImpl.cpp	2021-12-10 03:08:53 UTC (rev 286825)
@@ -317,7 +317,7 @@
     return WebCore::UserInterfaceLayoutDirection::LTR;
 }
 
-void PageClientImpl::requestDOMPasteAccess(const WebCore::IntRect&, const String&, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&& completionHandler)
+void PageClientImpl::requestDOMPasteAccess(WebCore::DOMPasteAccessCategory, const WebCore::IntRect&, const String&, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&& completionHandler)
 {
     completionHandler(WebCore::DOMPasteAccessResponse::DeniedForGesture);
 }

Modified: trunk/Source/WebKit/UIProcess/playstation/PageClientImpl.h (286824 => 286825)


--- trunk/Source/WebKit/UIProcess/playstation/PageClientImpl.h	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebKit/UIProcess/playstation/PageClientImpl.h	2021-12-10 03:08:53 UTC (rev 286825)
@@ -149,7 +149,7 @@
 
     WebCore::UserInterfaceLayoutDirection userInterfaceLayoutDirection() override;
 
-    void requestDOMPasteAccess(const WebCore::IntRect&, const String&, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&&) override;
+    void requestDOMPasteAccess(WebCore::DOMPasteAccessCategory, const WebCore::IntRect&, const String&, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&&) override;
 
     PlayStationWebView& m_view;
 };

Modified: trunk/Source/WebKit/UIProcess/win/PageClientImpl.cpp (286824 => 286825)


--- trunk/Source/WebKit/UIProcess/win/PageClientImpl.cpp	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebKit/UIProcess/win/PageClientImpl.cpp	2021-12-10 03:08:53 UTC (rev 286825)
@@ -373,7 +373,7 @@
     return m_view.window();
 }
 
-void PageClientImpl::requestDOMPasteAccess(const IntRect&, const String&, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&& completionHandler)
+void PageClientImpl::requestDOMPasteAccess(WebCore::DOMPasteAccessCategory, const IntRect&, const String&, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&& completionHandler)
 {
     completionHandler(WebCore::DOMPasteAccessResponse::DeniedForGesture);
 }

Modified: trunk/Source/WebKit/UIProcess/win/PageClientImpl.h (286824 => 286825)


--- trunk/Source/WebKit/UIProcess/win/PageClientImpl.h	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebKit/UIProcess/win/PageClientImpl.h	2021-12-10 03:08:53 UTC (rev 286825)
@@ -35,6 +35,7 @@
 #include <WebCore/IntSize.h>
 
 namespace WebCore {
+enum class DOMPasteAccessCategory : uint8_t;
 enum class DOMPasteAccessResponse : uint8_t;
 }
 
@@ -148,7 +149,7 @@
 
     WebCore::UserInterfaceLayoutDirection userInterfaceLayoutDirection() override { return WebCore::UserInterfaceLayoutDirection::LTR; }
 
-    void requestDOMPasteAccess(const WebCore::IntRect&, const String&, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&&) final;
+    void requestDOMPasteAccess(WebCore::DOMPasteAccessCategory, const WebCore::IntRect&, const String&, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&&) final;
 
     // Members of PageClientImpl class
     DefaultUndoController m_undoController;

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebEditorClient.cpp (286824 => 286825)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebEditorClient.cpp	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebEditorClient.cpp	2021-12-10 03:08:53 UTC (rev 286825)
@@ -332,9 +332,9 @@
     m_page->sendSync(Messages::WebPageProxy::ExecuteUndoRedo(UndoOrRedo::Redo), Messages::WebPageProxy::ExecuteUndoRedo::Reply());
 }
 
-WebCore::DOMPasteAccessResponse WebEditorClient::requestDOMPasteAccess(const String& originIdentifier)
+WebCore::DOMPasteAccessResponse WebEditorClient::requestDOMPasteAccess(WebCore::DOMPasteAccessCategory pasteAccessCategory, const String& originIdentifier)
 {
-    return m_page->requestDOMPasteAccess(originIdentifier);
+    return m_page->requestDOMPasteAccess(pasteAccessCategory, originIdentifier);
 }
 
 #if !PLATFORM(COCOA) && !USE(GLIB)

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebEditorClient.h (286824 => 286825)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebEditorClient.h	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebEditorClient.h	2021-12-10 03:08:53 UTC (rev 286825)
@@ -29,6 +29,7 @@
 #include <WebCore/TextCheckerClient.h>
 
 namespace WebCore {
+enum class DOMPasteAccessCategory : uint8_t;
 enum class DOMPasteAccessResponse : uint8_t;
 }
 
@@ -93,7 +94,7 @@
     void registerRedoStep(WebCore::UndoStep&) final;
     void clearUndoRedoOperations() final;
 
-    WebCore::DOMPasteAccessResponse requestDOMPasteAccess(const String& originIdentifier) final;
+    WebCore::DOMPasteAccessResponse requestDOMPasteAccess(WebCore::DOMPasteAccessCategory, const String& originIdentifier) final;
 
     bool canCopyCut(WebCore::Frame*, bool defaultValue) const final;
     bool canPaste(WebCore::Frame*, bool defaultValue) const final;

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (286824 => 286825)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2021-12-10 03:08:53 UTC (rev 286825)
@@ -7207,7 +7207,7 @@
     sendWithAsyncReply(Messages::WebPageProxy::ShowContactPicker(requestData), WTFMove(callback));
 }
 
-WebCore::DOMPasteAccessResponse WebPage::requestDOMPasteAccess(const String& originIdentifier)
+WebCore::DOMPasteAccessResponse WebPage::requestDOMPasteAccess(WebCore::DOMPasteAccessCategory pasteAccessCategory, const String& originIdentifier)
 {
     auto response = WebCore::DOMPasteAccessResponse::DeniedForGesture;
 #if PLATFORM(IOS_FAMILY)
@@ -7217,7 +7217,7 @@
     // should be removed once <rdar://problem/16207002> is resolved.
     send(Messages::WebPageProxy::HandleAutocorrectionContext(autocorrectionContext()));
 #endif
-    sendSyncWithDelayedReply(Messages::WebPageProxy::RequestDOMPasteAccess(rectForElementAtInteractionLocation(), originIdentifier), Messages::WebPageProxy::RequestDOMPasteAccess::Reply(response));
+    sendSyncWithDelayedReply(Messages::WebPageProxy::RequestDOMPasteAccess(pasteAccessCategory, rectForElementAtInteractionLocation(), originIdentifier), Messages::WebPageProxy::RequestDOMPasteAccess::Reply(response));
     return response;
 }
 

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (286824 => 286825)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2021-12-10 03:08:53 UTC (rev 286825)
@@ -224,6 +224,7 @@
 enum SyntheticClickType : int8_t;
 enum class COEPDisposition : bool;
 enum class CreateNewGroupForHighlight : bool;
+enum class DOMPasteAccessCategory : uint8_t;
 enum class DOMPasteAccessResponse : uint8_t;
 enum class DragApplicationFlags : uint8_t;
 enum class DragHandlingMethod : uint8_t;
@@ -1340,7 +1341,7 @@
         return sendSync(WTFMove(message), WTFMove(reply), Seconds::infinity(), sendSyncOptions);
     }
 
-    WebCore::DOMPasteAccessResponse requestDOMPasteAccess(const String& originIdentifier);
+    WebCore::DOMPasteAccessResponse requestDOMPasteAccess(WebCore::DOMPasteAccessCategory, const String& originIdentifier);
     WebCore::IntRect rectForElementAtInteractionLocation() const;
 
     const std::optional<WebCore::Color>& backgroundColor() const { return m_backgroundColor; }

Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (286824 => 286825)


--- trunk/Source/WebKitLegacy/mac/ChangeLog	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog	2021-12-10 03:08:53 UTC (rev 286825)
@@ -1,3 +1,21 @@
+2021-12-09  Devin Rousso  <[email protected]>
+
+        Add a `DOMPasteAccessCategory` to control which pasteboard the WebProcess is granted access to when pasting
+        https://bugs.webkit.org/show_bug.cgi?id=233939
+
+        Reviewed by Wenson Hsieh.
+
+        Implementing `-pasteFont:` <https://webkit.org/b/191379> requires that we read from the font
+        pasteboard instead of the general pasteboard. In order to allow web content to trigger this
+        (e.g. `document.execCommand("PasteFont"))`) we must have a way for the WebProcess to signal
+        that it wishes to read from the font pasteboard instead of the general pasteboard. As such,
+        create and pass along a `DOMPasteAccessCategory` to `requestDOMPasteAccess`.
+
+        No change in behavior.
+
+        * WebCoreSupport/WebEditorClient.h:
+        (WebEditorClient::requestDOMPasteAccess):
+
 2021-12-09  Myles C. Maxfield  <[email protected]> and Don Olmstead  <[email protected]>
 
         Move TextCodec files from WebCore/platform/text to WebCore/PAL/text

Modified: trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.h (286824 => 286825)


--- trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.h	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.h	2021-12-10 03:08:53 UTC (rev 286825)
@@ -83,7 +83,7 @@
     void getClientPasteboardData(const std::optional<WebCore::SimpleRange>&, Vector<String>& pasteboardTypes, Vector<RefPtr<WebCore::SharedBuffer>>& pasteboardData) final;
 
     void setInsertionPasteboard(const String&) final;
-    WebCore::DOMPasteAccessResponse requestDOMPasteAccess(const String&) final { return WebCore::DOMPasteAccessResponse::DeniedForGesture; }
+    WebCore::DOMPasteAccessResponse requestDOMPasteAccess(WebCore::DOMPasteAccessCategory, const String&) final { return WebCore::DOMPasteAccessResponse::DeniedForGesture; }
 
 #if USE(APPKIT)
     void uppercaseWord() final;

Modified: trunk/Source/WebKitLegacy/win/ChangeLog (286824 => 286825)


--- trunk/Source/WebKitLegacy/win/ChangeLog	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebKitLegacy/win/ChangeLog	2021-12-10 03:08:53 UTC (rev 286825)
@@ -1,3 +1,21 @@
+2021-12-09  Devin Rousso  <[email protected]>
+
+        Add a `DOMPasteAccessCategory` to control which pasteboard the WebProcess is granted access to when pasting
+        https://bugs.webkit.org/show_bug.cgi?id=233939
+
+        Reviewed by Wenson Hsieh.
+
+        Implementing `-pasteFont:` <https://webkit.org/b/191379> requires that we read from the font
+        pasteboard instead of the general pasteboard. In order to allow web content to trigger this
+        (e.g. `document.execCommand("PasteFont"))`) we must have a way for the WebProcess to signal
+        that it wishes to read from the font pasteboard instead of the general pasteboard. As such,
+        create and pass along a `DOMPasteAccessCategory` to `requestDOMPasteAccess`.
+
+        No change in behavior.
+
+        * WebCoreSupport/WebEditorClient.h:
+        (WebEditorClient::requestDOMPasteAccess):
+
 2021-12-09  Myles C. Maxfield  <[email protected]> and Don Olmstead  <[email protected]>
 
         Move TextCodec files from WebCore/platform/text to WebCore/PAL/text

Modified: trunk/Source/WebKitLegacy/win/WebCoreSupport/WebEditorClient.h (286824 => 286825)


--- trunk/Source/WebKitLegacy/win/WebCoreSupport/WebEditorClient.h	2021-12-10 02:38:54 UTC (rev 286824)
+++ trunk/Source/WebKitLegacy/win/WebCoreSupport/WebEditorClient.h	2021-12-10 03:08:53 UTC (rev 286825)
@@ -117,7 +117,7 @@
     void requestCheckingOfString(WebCore::TextCheckingRequest&, const WebCore::VisibleSelection&) final { }
     bool performTwoStepDrop(WebCore::DocumentFragment&, const WebCore::SimpleRange&, bool) final { return false; }
 
-    WebCore::DOMPasteAccessResponse requestDOMPasteAccess(const String&) final { return WebCore::DOMPasteAccessResponse::DeniedForGesture; }
+    WebCore::DOMPasteAccessResponse requestDOMPasteAccess(WebCore::DOMPasteAccessCategory, const String&) final { return WebCore::DOMPasteAccessResponse::DeniedForGesture; }
 
     WebCore::TextCheckerClient* textChecker() final { return this; }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to