Changeset 259151 in webkit


Ignore:
Timestamp:
Mar 27, 2020 8:05:01 PM (4 years ago)
Author:
Wenson Hsieh
Message:

Web content processes should not be able to arbitrarily request pasteboard data from the UI process
https://bugs.webkit.org/show_bug.cgi?id=209657
<rdar://problem/59611585>

Reviewed by Geoff Garen.

Source/WebCore:

Match macOS behavior in the iOS implementation of Pasteboard::createForCopyAndPaste by using the name of the
general pasteboard by default, when initializing a Pasteboard for copying and pasting. In WebKit2, this allows
us to grant permission to the web process when reading from the general pasteboard.

  • platform/ios/PasteboardIOS.mm:

(WebCore::Pasteboard::createForCopyAndPaste):

Source/WebCore/PAL:

Soft-link the string constant UIPasteboardNameGeneral. See WebKit/ChangeLog for more details.

  • pal/ios/UIKitSoftLink.h:
  • pal/ios/UIKitSoftLink.mm:

Source/WebKit:

This patch adds a mechanism to prevent the UI process from sending pasteboard data to the web process in
response to WebPasteboardProxy IPC messages, unless the user (or the WebKit client, on behalf of the user) has
explicitly made the contents of the pasteboard available to a page in that web process. We determine the latter
by maintaining information about the changeCounts of each pasteboard we allow each web process to read. This
mapping is updated when either the user interacts with trusted UI (context menus, DOM paste menu) for pasting,
or an API client calls into -[WKWebView paste:], as is the case when pasting via the callout bar on iOS or
pasting via keyboard shortcuts (i.e. cmd + V) on macOS and iOS.

See per-change comments below for more details. Under normal circumstances, there should be no change in
behavior; refer to the radar for more context.

  • UIProcess/Cocoa/WebPageProxyCocoa.mm:

(WebKit::WebPageProxy::grantAccessToCurrentPasteboardData):

Add a helper method to grant access to the data currently on the pasteboard with the given name; for now, this
grants access to all related pages that reside in the same web process, but this may be refactored in a future
change to make the mapping granular to each WebPageProxy rather than WebProcessProxy.

(Note: it is _critical_ that this method is never invoked as a result of IPC from the web process.)

  • UIProcess/Cocoa/WebPasteboardProxyCocoa.mm:

(WebKit::WebPasteboardProxy::grantAccessToCurrentData):

Helper method to grant access to the current contents on the named pasteboard. Calling this method updates
m_pasteboardNameToChangeCountAndProcessesMap, such that the given web process is able to read from the
pasteboard with the given name, as long as the changeCount is still the same. To implement this behavior,
we either (1) add the process to an existing WeakHashSet of process proxies in the case where the
changeCount is the same as it was when we added the existing WeakHashSet, or in all other cases, (2) add a
replace the current (changeCount, processes) pair with the new change count and a weak set containing only the
given WebProcessProxy.

(WebKit::WebPasteboardProxy::revokeAccessToAllData):

Helper method to revoke all pasteboard access for the given WebProcessProxy. Called when resetting state, e.g.
after web process termination.

(WebKit::WebPasteboardProxy::canAccessPasteboardData const):

Private helper method to check whether an IPC message can access pasteboard data, based on the IPC::Connection
used to receive the message. This helper method returns true if either the WebKit client has used SPI
(both DOMPasteAllowed and JavaScriptCanAccessClipboard) to grant unmitigated access to the clipboard from the
web process, or access has been previously granted due to user interaction in the UI process or API calls made
directly by the WebKit client.

(WebKit::WebPasteboardProxy::didModifyContentsOfPasteboard):

Private helper method to update the pasteboard changeCount that has been granted to a given web process, in the
case where that web process was also responsible for writing data to the pasteboard and the pasteboard
changeCount prior to modifying the pasteboard was still valid. In other words, we should always allow a web
process to read contents it has just written. This allows us to maintain the use case where a WKWebView client
copies and pastes using back-to-back API calls:

`
[webView copy:nil];
[webView paste:nil];
`

(WebKit::WebPasteboardProxy::getPasteboardPathnamesForType):

Add a FIXME to add the canAccessPasteboardData check here as well. We can't do this yet because the web
process currently relies on being able to read the full list of pasteboard path names when dragging over the
page, but this will be fixed in a followup patch in the near future (see https://webkit.org/b/209671).

(WebKit::WebPasteboardProxy::getPasteboardStringForType):
(WebKit::WebPasteboardProxy::getPasteboardStringsForType):
(WebKit::WebPasteboardProxy::getPasteboardBufferForType):
(WebKit::WebPasteboardProxy::getPasteboardColor):
(WebKit::WebPasteboardProxy::getPasteboardURL):

In all the call sites where we ask for pasteboard data (with the exception of getPasteboardPathnamesForType, for
the time being), check whether we're allowed to read pasteboard data by consulting canAccessPasteboardData. If
not, return early with no data.

(WebKit::WebPasteboardProxy::addPasteboardTypes):
(WebKit::WebPasteboardProxy::setPasteboardTypes):
(WebKit::WebPasteboardProxy::setPasteboardURL):
(WebKit::WebPasteboardProxy::setPasteboardColor):
(WebKit::WebPasteboardProxy::setPasteboardStringForType):

In all the call sites where we knowingly mutate the pasteboard (and bump the changeCount as a result),
additionally update the changeCount to which we've granted access on behalf of the web process that is modifying
the pasteboard.

(WebKit::WebPasteboardProxy::urlStringSuitableForLoading):
(WebKit::WebPasteboardProxy::setPasteboardBufferForType):
(WebKit::WebPasteboardProxy::writeCustomData):
(WebKit::WebPasteboardProxy::readStringFromPasteboard):
(WebKit::WebPasteboardProxy::readURLFromPasteboard):
(WebKit::WebPasteboardProxy::readBufferFromPasteboard):
(WebKit::WebPasteboardProxy::writeURLToPasteboard):
(WebKit::WebPasteboardProxy::writeWebContentToPasteboard):
(WebKit::WebPasteboardProxy::writeImageToPasteboard):
(WebKit::WebPasteboardProxy::writeStringToPasteboard):

(See comments above).

  • UIProcess/Cocoa/WebViewImpl.mm:

(WebKit::WebViewImpl::performDragOperation):

When performing a drop on macOS, grant temporary access to the drag pasteboard.

(WebKit::WebViewImpl::requestDOMPasteAccess):
(WebKit::WebViewImpl::handleDOMPasteRequestWithResult):

If the user has granted DOM paste access, additionally grant access to the general pasteboard.

  • UIProcess/WebPageProxy.cpp:

(WebKit::isPasteCommandName):
(WebKit::WebPageProxy::executeEditCommand):

When executing an edit command on behalf of a WebKit client, check to see if it is a paste command (one of
the four that are defined in EditorCommand.cpp). If so, we grant access to the current contents of the general
pasteboard.

  • UIProcess/WebPageProxy.h:
  • UIProcess/WebPasteboardProxy.cpp:

(WebKit::WebPasteboardProxy::webProcessProxyForConnection const):

Add a helper method to map a given IPC::Connection to a WebProcessProxy. While we have a list of WebProcessProxy
objects, we know a priori that at most one of them will have the given connection, so returning a single
WebProcessProxy* here is sufficient (rather than a list of WebProcessProxy*s).

(WebKit::WebPasteboardProxy::allPasteboardItemInfo):
(WebKit::WebPasteboardProxy::informationForItemAtIndex):
(WebKit::WebPasteboardProxy::getPasteboardItemsCount):
(WebKit::WebPasteboardProxy::readURLFromPasteboard):
(WebKit::WebPasteboardProxy::readBufferFromPasteboard):
(WebKit::WebPasteboardProxy::readStringFromPasteboard):
(WebKit::WebPasteboardProxy::urlStringSuitableForLoading):

Update interface stubs for non-Cocoa platforms.

  • UIProcess/WebPasteboardProxy.h:
  • UIProcess/WebPasteboardProxy.messages.in:

Decorate more IPC endpoints with WantsConnection, so that we can reason about the IPC::Connections used to
receive pasteboard messages.

  • UIProcess/ios/WKContentViewInteraction.mm:

(-[WKContentView _handleDOMPasteRequestWithResult:]):

If the user has granted DOM paste access, additionally grant access to the general pasteboard.

(-[WKContentView dropInteraction:performDrop:]):

When performing a drop on iOS, grant temporary access to the drag pasteboard.

  • UIProcess/ios/WebPageProxyIOS.mm:

(WebKit::WebPageProxy::willPerformPasteCommand):

  • UIProcess/libwpe/WebPasteboardProxyLibWPE.cpp:

(WebKit::WebPasteboardProxy::readStringFromPasteboard):

  • UIProcess/mac/WebPageProxyMac.mm:

(WebKit::WebPageProxy::platformDidSelectItemFromActiveContextMenu):

Grant pasteboard access when using the context menu to paste on macOS.

(WebKit::WebPageProxy::willPerformPasteCommand):

Grant pasteboard access when triggering the "Paste" edit command using WebKit SPI.

Location:
trunk/Source
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r259148 r259151  
     12020-03-27  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Web content processes should not be able to arbitrarily request pasteboard data from the UI process
     4        https://bugs.webkit.org/show_bug.cgi?id=209657
     5        <rdar://problem/59611585>
     6
     7        Reviewed by Geoff Garen.
     8
     9        Match macOS behavior in the iOS implementation of Pasteboard::createForCopyAndPaste by using the name of the
     10        general pasteboard by default, when initializing a Pasteboard for copying and pasting. In WebKit2, this allows
     11        us to grant permission to the web process when reading from the general pasteboard.
     12
     13        * platform/ios/PasteboardIOS.mm:
     14        (WebCore::Pasteboard::createForCopyAndPaste):
     15
    1162020-03-27  Zalan Bujtas  <zalan@apple.com>
    217
  • trunk/Source/WebCore/PAL/ChangeLog

    r258772 r259151  
     12020-03-27  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Web content processes should not be able to arbitrarily request pasteboard data from the UI process
     4        https://bugs.webkit.org/show_bug.cgi?id=209657
     5        <rdar://problem/59611585>
     6
     7        Reviewed by Geoff Garen.
     8
     9        Soft-link the string constant `UIPasteboardNameGeneral`. See WebKit/ChangeLog for more details.
     10
     11        * pal/ios/UIKitSoftLink.h:
     12        * pal/ios/UIKitSoftLink.mm:
     13
    1142020-03-20  Tim Horton  <timothy_horton@apple.com>
    215
  • trunk/Source/WebCore/PAL/pal/ios/UIKitSoftLink.h

    r241828 r259151  
    4242SOFT_LINK_CONSTANT_FOR_HEADER(PAL, UIKit, UIContentSizeCategoryDidChangeNotification, NSNotificationName)
    4343SOFT_LINK_CONSTANT_FOR_HEADER(PAL, UIKit, UIFontTextStyleCallout, UIFontTextStyle)
     44SOFT_LINK_CONSTANT_FOR_HEADER(PAL, UIKit, UIPasteboardNameGeneral, UIPasteboardName)
    4445SOFT_LINK_CONSTANT_FOR_HEADER(PAL, UIKit, UITextEffectsBeneathStatusBarWindowLevel, UIWindowLevel)
    4546SOFT_LINK_CLASS_FOR_HEADER(PAL, NSParagraphStyle)
  • trunk/Source/WebCore/PAL/pal/ios/UIKitSoftLink.mm

    r241828 r259151  
    4242SOFT_LINK_CONSTANT_FOR_SOURCE(PAL, UIKit, UIContentSizeCategoryDidChangeNotification, NSNotificationName)
    4343SOFT_LINK_CONSTANT_FOR_SOURCE(PAL, UIKit, UIFontTextStyleCallout, UIFontTextStyle)
     44SOFT_LINK_CONSTANT_FOR_SOURCE(PAL, UIKit, UIPasteboardNameGeneral, UIPasteboardName)
    4445SOFT_LINK_CONSTANT_FOR_SOURCE(PAL, UIKit, UITextEffectsBeneathStatusBarWindowLevel, UIWindowLevel)
    4546SOFT_LINK_CLASS_FOR_SOURCE(PAL, UIKit, NSParagraphStyle)
  • trunk/Source/WebCore/platform/ios/PasteboardIOS.mm

    r259020 r259151  
    3939#import "WebNSAttributedStringExtras.h"
    4040#import <MobileCoreServices/MobileCoreServices.h>
     41#import <pal/ios/UIKitSoftLink.h>
    4142#import <wtf/URL.h>
    4243#import <wtf/text/StringHash.h>
     
    107108std::unique_ptr<Pasteboard> Pasteboard::createForCopyAndPaste()
    108109{
    109     return makeUnique<Pasteboard>(changeCountForPasteboard());
     110    return makeUnique<Pasteboard>(PAL::get_UIKit_UIPasteboardNameGeneral());
    110111}
    111112
  • trunk/Source/WebKit/ChangeLog

    r259146 r259151  
     12020-03-27  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Web content processes should not be able to arbitrarily request pasteboard data from the UI process
     4        https://bugs.webkit.org/show_bug.cgi?id=209657
     5        <rdar://problem/59611585>
     6
     7        Reviewed by Geoff Garen.
     8
     9        This patch adds a mechanism to prevent the UI process from sending pasteboard data to the web process in
     10        response to WebPasteboardProxy IPC messages, unless the user (or the WebKit client, on behalf of the user) has
     11        explicitly made the contents of the pasteboard available to a page in that web process. We determine the latter
     12        by maintaining information about the `changeCount`s of each pasteboard we allow each web process to read. This
     13        mapping is updated when either the user interacts with trusted UI (context menus, DOM paste menu) for pasting,
     14        or an API client calls into -[WKWebView paste:], as is the case when pasting via the callout bar on iOS or
     15        pasting via keyboard shortcuts (i.e. cmd + V) on macOS and iOS.
     16
     17        See per-change comments below for more details. Under normal circumstances, there should be no change in
     18        behavior; refer to the radar for more context.
     19
     20        * UIProcess/Cocoa/WebPageProxyCocoa.mm:
     21        (WebKit::WebPageProxy::grantAccessToCurrentPasteboardData):
     22
     23        Add a helper method to grant access to the data currently on the pasteboard with the given name; for now, this
     24        grants access to all related pages that reside in the same web process, but this may be refactored in a future
     25        change to make the mapping granular to each WebPageProxy rather than WebProcessProxy.
     26
     27        (Note: it is _critical_ that this method is never invoked as a result of IPC from the web process.)
     28
     29        * UIProcess/Cocoa/WebPasteboardProxyCocoa.mm:
     30        (WebKit::WebPasteboardProxy::grantAccessToCurrentData):
     31
     32        Helper method to grant access to the current contents on the named pasteboard. Calling this method updates
     33        `m_pasteboardNameToChangeCountAndProcessesMap`, such that the given web process is able to read from the
     34        pasteboard with the given name, as long as the `changeCount` is still the same. To implement this behavior,
     35        we either (1) add the process to an existing `WeakHashSet` of process proxies in the case where the
     36        `changeCount` is the same as it was when we added the existing `WeakHashSet`, or in all other cases, (2) add a
     37        replace the current (changeCount, processes) pair with the new change count and a weak set containing only the
     38        given WebProcessProxy.
     39
     40        (WebKit::WebPasteboardProxy::revokeAccessToAllData):
     41
     42        Helper method to revoke all pasteboard access for the given WebProcessProxy. Called when resetting state, e.g.
     43        after web process termination.
     44
     45        (WebKit::WebPasteboardProxy::canAccessPasteboardData const):
     46
     47        Private helper method to check whether an IPC message can access pasteboard data, based on the IPC::Connection
     48        used to receive the message. This helper method returns true if either the WebKit client has used SPI
     49        (both DOMPasteAllowed and JavaScriptCanAccessClipboard) to grant unmitigated access to the clipboard from the
     50        web process, or access has been previously granted due to user interaction in the UI process or API calls made
     51        directly by the WebKit client.
     52
     53        (WebKit::WebPasteboardProxy::didModifyContentsOfPasteboard):
     54
     55        Private helper method to update the pasteboard changeCount that has been granted to a given web process, in the
     56        case where that web process was also responsible for writing data to the pasteboard and the pasteboard
     57        changeCount prior to modifying the pasteboard was still valid. In other words, we should always allow a web
     58        process to read contents it has just written. This allows us to maintain the use case where a WKWebView client
     59        copies and pastes using back-to-back API calls:
     60
     61        ```
     62        [webView copy:nil];
     63        [webView paste:nil];
     64        ```
     65
     66        (WebKit::WebPasteboardProxy::getPasteboardPathnamesForType):
     67
     68        Add a FIXME to add the `canAccessPasteboardData` check here as well. We can't do this yet because the web
     69        process currently relies on being able to read the full list of pasteboard path names when dragging over the
     70        page, but this will be fixed in a followup patch in the near future (see https://webkit.org/b/209671).
     71
     72        (WebKit::WebPasteboardProxy::getPasteboardStringForType):
     73        (WebKit::WebPasteboardProxy::getPasteboardStringsForType):
     74        (WebKit::WebPasteboardProxy::getPasteboardBufferForType):
     75        (WebKit::WebPasteboardProxy::getPasteboardColor):
     76        (WebKit::WebPasteboardProxy::getPasteboardURL):
     77
     78        In all the call sites where we ask for pasteboard data (with the exception of getPasteboardPathnamesForType, for
     79        the time being), check whether we're allowed to read pasteboard data by consulting canAccessPasteboardData. If
     80        not, return early with no data.
     81
     82        (WebKit::WebPasteboardProxy::addPasteboardTypes):
     83        (WebKit::WebPasteboardProxy::setPasteboardTypes):
     84        (WebKit::WebPasteboardProxy::setPasteboardURL):
     85        (WebKit::WebPasteboardProxy::setPasteboardColor):
     86        (WebKit::WebPasteboardProxy::setPasteboardStringForType):
     87
     88        In all the call sites where we knowingly mutate the pasteboard (and bump the changeCount as a result),
     89        additionally update the changeCount to which we've granted access on behalf of the web process that is modifying
     90        the pasteboard.
     91
     92        (WebKit::WebPasteboardProxy::urlStringSuitableForLoading):
     93        (WebKit::WebPasteboardProxy::setPasteboardBufferForType):
     94        (WebKit::WebPasteboardProxy::writeCustomData):
     95        (WebKit::WebPasteboardProxy::readStringFromPasteboard):
     96        (WebKit::WebPasteboardProxy::readURLFromPasteboard):
     97        (WebKit::WebPasteboardProxy::readBufferFromPasteboard):
     98        (WebKit::WebPasteboardProxy::writeURLToPasteboard):
     99        (WebKit::WebPasteboardProxy::writeWebContentToPasteboard):
     100        (WebKit::WebPasteboardProxy::writeImageToPasteboard):
     101        (WebKit::WebPasteboardProxy::writeStringToPasteboard):
     102
     103        (See comments above).
     104
     105        * UIProcess/Cocoa/WebViewImpl.mm:
     106        (WebKit::WebViewImpl::performDragOperation):
     107
     108        When performing a drop on macOS, grant temporary access to the drag pasteboard.
     109
     110        (WebKit::WebViewImpl::requestDOMPasteAccess):
     111        (WebKit::WebViewImpl::handleDOMPasteRequestWithResult):
     112
     113        If the user has granted DOM paste access, additionally grant access to the general pasteboard.
     114
     115        * UIProcess/WebPageProxy.cpp:
     116        (WebKit::isPasteCommandName):
     117        (WebKit::WebPageProxy::executeEditCommand):
     118
     119        When executing an edit command on behalf of a WebKit client, check to see if it is a paste command (one of
     120        the four that are defined in EditorCommand.cpp). If so, we grant access to the current contents of the general
     121        pasteboard.
     122
     123        * UIProcess/WebPageProxy.h:
     124        * UIProcess/WebPasteboardProxy.cpp:
     125        (WebKit::WebPasteboardProxy::webProcessProxyForConnection const):
     126
     127        Add a helper method to map a given IPC::Connection to a WebProcessProxy. While we have a list of WebProcessProxy
     128        objects, we know a priori that at most one of them will have the given connection, so returning a single
     129        `WebProcessProxy*` here is sufficient (rather than a list of `WebProcessProxy*`s).
     130
     131        (WebKit::WebPasteboardProxy::allPasteboardItemInfo):
     132        (WebKit::WebPasteboardProxy::informationForItemAtIndex):
     133        (WebKit::WebPasteboardProxy::getPasteboardItemsCount):
     134        (WebKit::WebPasteboardProxy::readURLFromPasteboard):
     135        (WebKit::WebPasteboardProxy::readBufferFromPasteboard):
     136        (WebKit::WebPasteboardProxy::readStringFromPasteboard):
     137        (WebKit::WebPasteboardProxy::urlStringSuitableForLoading):
     138
     139        Update interface stubs for non-Cocoa platforms.
     140
     141        * UIProcess/WebPasteboardProxy.h:
     142        * UIProcess/WebPasteboardProxy.messages.in:
     143
     144        Decorate more IPC endpoints with `WantsConnection`, so that we can reason about the `IPC::Connection`s used to
     145        receive pasteboard messages.
     146
     147        * UIProcess/ios/WKContentViewInteraction.mm:
     148        (-[WKContentView _handleDOMPasteRequestWithResult:]):
     149
     150        If the user has granted DOM paste access, additionally grant access to the general pasteboard.
     151
     152        (-[WKContentView dropInteraction:performDrop:]):
     153
     154        When performing a drop on iOS, grant temporary access to the drag pasteboard.
     155
     156        * UIProcess/ios/WebPageProxyIOS.mm:
     157        (WebKit::WebPageProxy::willPerformPasteCommand):
     158        * UIProcess/libwpe/WebPasteboardProxyLibWPE.cpp:
     159        (WebKit::WebPasteboardProxy::readStringFromPasteboard):
     160        * UIProcess/mac/WebPageProxyMac.mm:
     161        (WebKit::WebPageProxy::platformDidSelectItemFromActiveContextMenu):
     162
     163        Grant pasteboard access when using the context menu to paste on macOS.
     164
     165        (WebKit::WebPageProxy::willPerformPasteCommand):
     166
     167        Grant pasteboard access when triggering the "Paste" edit command using WebKit SPI.
     168
    11692020-03-27  Chris Dumez  <cdumez@apple.com>
    2170
  • trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm

    r258796 r259151  
    3737#import "SharedBufferDataReference.h"
    3838#import "WebPageMessages.h"
     39#import "WebPasteboardProxy.h"
    3940#import "WebProcessProxy.h"
    4041#import "WebsiteDataStore.h"
     
    7879
    7980    completionHandler(WebCore::loadRecentSearches(name));
     81}
     82
     83void WebPageProxy::grantAccessToCurrentPasteboardData(const String& pasteboardName)
     84{
     85    if (!hasRunningProcess())
     86        return;
     87
     88    WebPasteboardProxy::singleton().grantAccessToCurrentData(m_process.get(), pasteboardName);
    8089}
    8190
  • trunk/Source/WebKit/UIProcess/Cocoa/WebPasteboardProxyCocoa.mm

    r259124 r259151  
    2929#import "Connection.h"
    3030#import "SandboxExtension.h"
     31#import "WebPageProxy.h"
     32#import "WebPreferences.h"
    3133#import "WebProcessProxy.h"
    3234#import <WebCore/Color.h>
     
    4244using namespace WebCore;
    4345
     46void WebPasteboardProxy::grantAccessToCurrentData(WebProcessProxy& process, const String& pasteboardName)
     47{
     48    if (!m_webProcessProxyList.contains(&process))
     49        return;
     50
     51    if (pasteboardName.isEmpty()) {
     52        ASSERT_NOT_REACHED();
     53        return;
     54    }
     55
     56    auto changeCount = PlatformPasteboard(pasteboardName).changeCount();
     57    auto changeCountsAndProcesses = m_pasteboardNameToChangeCountAndProcessesMap.find(pasteboardName);
     58    if (changeCountsAndProcesses != m_pasteboardNameToChangeCountAndProcessesMap.end() && changeCountsAndProcesses->value.first == changeCount) {
     59        changeCountsAndProcesses->value.second.add(process);
     60        return;
     61    }
     62
     63    WeakHashSet<WebProcessProxy> processes;
     64    processes.add(process);
     65    m_pasteboardNameToChangeCountAndProcessesMap.set(pasteboardName, std::make_pair(changeCount, WTFMove(processes)));
     66}
     67
     68void WebPasteboardProxy::revokeAccessToAllData(WebProcessProxy& process)
     69{
     70    for (auto& changeCountAndProcesses : m_pasteboardNameToChangeCountAndProcessesMap.values())
     71        changeCountAndProcesses.second.remove(process);
     72}
     73
     74bool WebPasteboardProxy::canAccessPasteboardData(IPC::Connection& connection, const String& pasteboardName) const
     75{
     76    if (pasteboardName.isEmpty()) {
     77        ASSERT_NOT_REACHED();
     78        return false;
     79    }
     80
     81    auto* process = webProcessProxyForConnection(connection);
     82    if (!process)
     83        return false;
     84
     85    for (auto* page : process->pages()) {
     86        auto& preferences = page->preferences();
     87        if (!preferences.domPasteAllowed() || !preferences.javaScriptCanAccessClipboard())
     88            continue;
     89
     90        // If a web page already allows JavaScript to programmatically read pasteboard data,
     91        // then it is possible for any other web page residing in the same web process to send
     92        // IPC messages that can read pasteboard data by pretending to be the page that has
     93        // allowed unmitigated pasteboard access from script. As such, there is no security
     94        // benefit in limiting the scope of pasteboard data access to only the web page that
     95        // enables programmatic pasteboard access.
     96        return true;
     97    }
     98
     99    auto changeCountAndProcesses = m_pasteboardNameToChangeCountAndProcessesMap.find(pasteboardName);
     100    if (changeCountAndProcesses == m_pasteboardNameToChangeCountAndProcessesMap.end())
     101        return false;
     102
     103    auto& [changeCount, processes] = changeCountAndProcesses->value;
     104    return changeCount == PlatformPasteboard(pasteboardName).changeCount() && processes.contains(*process);
     105}
     106
     107void WebPasteboardProxy::didModifyContentsOfPasteboard(IPC::Connection& connection, const String& pasteboardName, int64_t previousChangeCount, int64_t newChangeCount)
     108{
     109    auto* process = webProcessProxyForConnection(connection);
     110    if (!process)
     111        return;
     112
     113    auto changeCountAndProcesses = m_pasteboardNameToChangeCountAndProcessesMap.find(pasteboardName);
     114    if (changeCountAndProcesses != m_pasteboardNameToChangeCountAndProcessesMap.end() && previousChangeCount == changeCountAndProcesses->value.first) {
     115        WeakHashSet<WebProcessProxy> processes;
     116        processes.add(process);
     117        changeCountAndProcesses->value = std::make_pair(newChangeCount, WTFMove(processes));
     118    }
     119}
     120
    44121void WebPasteboardProxy::getPasteboardTypes(const String& pasteboardName, CompletionHandler<void(Vector<String>&&)>&& completionHandler)
    45122{
     
    56133        return completionHandler({ }, { });
    57134
     135    // FIXME: This should consult canAccessPasteboardData() as well, and avoid responding with file paths if it returns false.
    58136    Vector<String> pathnames;
    59137    SandboxExtension::HandleArray sandboxExtensions;
    60     for (auto* webProcessProxy : m_webProcessProxyList) {
    61         if (!webProcessProxy->hasConnection(connection))
    62             continue;
    63 
     138    if (webProcessProxyForConnection(connection)) {
    64139        PlatformPasteboard(pasteboardName).getPathnamesForType(pathnames, pasteboardType);
    65140
     
    78153}
    79154
    80 void WebPasteboardProxy::getPasteboardStringForType(const String& pasteboardName, const String& pasteboardType, CompletionHandler<void(String&&)>&& completionHandler)
    81 {
     155void WebPasteboardProxy::getPasteboardStringForType(IPC::Connection& connection, const String& pasteboardName, const String& pasteboardType, CompletionHandler<void(String&&)>&& completionHandler)
     156{
     157    if (!canAccessPasteboardData(connection, pasteboardName))
     158        return completionHandler({ });
     159
    82160    ASSERT(!pasteboardType.isNull());
    83161    if (pasteboardType.isNull())
     
    87165}
    88166
    89 void WebPasteboardProxy::getPasteboardStringsForType(const String& pasteboardName, const String& pasteboardType, CompletionHandler<void(Vector<String>&&)>&& completionHandler)
    90 {
    91     ASSERT(!pasteboardType.isNull());
    92     if (pasteboardType.isNull())
     167void WebPasteboardProxy::getPasteboardStringsForType(IPC::Connection& connection, const String& pasteboardName, const String& pasteboardType, CompletionHandler<void(Vector<String>&&)>&& completionHandler)
     168{
     169    ASSERT(!pasteboardType.isNull());
     170    if (pasteboardType.isNull())
     171        return completionHandler({ });
     172
     173    if (!canAccessPasteboardData(connection, pasteboardName))
    93174        return completionHandler({ });
    94175
     
    96177}
    97178
    98 void WebPasteboardProxy::getPasteboardBufferForType(const String& pasteboardName, const String& pasteboardType, CompletionHandler<void(SharedMemory::Handle&&, uint64_t)>&& completionHandler)
    99 {
    100     ASSERT(!pasteboardType.isNull());
    101     if (pasteboardType.isNull())
     179void WebPasteboardProxy::getPasteboardBufferForType(IPC::Connection& connection, const String& pasteboardName, const String& pasteboardType, CompletionHandler<void(SharedMemory::Handle&&, uint64_t)>&& completionHandler)
     180{
     181    ASSERT(!pasteboardType.isNull());
     182    if (pasteboardType.isNull())
     183        return completionHandler({ }, 0);
     184
     185    if (!canAccessPasteboardData(connection, pasteboardName))
    102186        return completionHandler({ }, 0);
    103187
     
    122206}
    123207
    124 void WebPasteboardProxy::getPasteboardColor(const String& pasteboardName, CompletionHandler<void(WebCore::Color&&)>&& completionHandler)
    125 {
     208void WebPasteboardProxy::getPasteboardColor(IPC::Connection& connection, const String& pasteboardName, CompletionHandler<void(WebCore::Color&&)>&& completionHandler)
     209{
     210    if (!canAccessPasteboardData(connection, pasteboardName))
     211        return completionHandler({ });
     212
    126213    completionHandler(PlatformPasteboard(pasteboardName).color());
    127214}
    128215
    129 void WebPasteboardProxy::getPasteboardURL(const String& pasteboardName, CompletionHandler<void(const String&)>&& completionHandler)
    130 {
     216void WebPasteboardProxy::getPasteboardURL(IPC::Connection& connection, const String& pasteboardName, CompletionHandler<void(const String&)>&& completionHandler)
     217{
     218    if (!canAccessPasteboardData(connection, pasteboardName))
     219        return completionHandler({ });
     220
    131221    completionHandler(PlatformPasteboard(pasteboardName).url().string());
    132222}
    133223
    134 void WebPasteboardProxy::addPasteboardTypes(const String& pasteboardName, const Vector<String>& pasteboardTypes, CompletionHandler<void(int64_t)>&& completionHandler)
    135 {
    136     completionHandler(PlatformPasteboard(pasteboardName).addTypes(pasteboardTypes));
    137 }
    138 
    139 void WebPasteboardProxy::setPasteboardTypes(const String& pasteboardName, const Vector<String>& pasteboardTypes, CompletionHandler<void(int64_t)>&& completionHandler)
    140 {
    141     completionHandler(PlatformPasteboard(pasteboardName).setTypes(pasteboardTypes));
     224void WebPasteboardProxy::addPasteboardTypes(IPC::Connection& connection, const String& pasteboardName, const Vector<String>& pasteboardTypes, CompletionHandler<void(int64_t)>&& completionHandler)
     225{
     226    auto previousChangeCount = PlatformPasteboard(pasteboardName).changeCount();
     227    auto newChangeCount = PlatformPasteboard(pasteboardName).addTypes(pasteboardTypes);
     228    didModifyContentsOfPasteboard(connection, pasteboardName, previousChangeCount, previousChangeCount);
     229    completionHandler(newChangeCount);
     230}
     231
     232void WebPasteboardProxy::setPasteboardTypes(IPC::Connection& connection, const String& pasteboardName, const Vector<String>& pasteboardTypes, CompletionHandler<void(int64_t)>&& completionHandler)
     233{
     234    auto previousChangeCount = PlatformPasteboard(pasteboardName).changeCount();
     235    auto newChangeCount = PlatformPasteboard(pasteboardName).setTypes(pasteboardTypes);
     236    didModifyContentsOfPasteboard(connection, pasteboardName, previousChangeCount, newChangeCount);
     237    completionHandler(newChangeCount);
    142238}
    143239
    144240void WebPasteboardProxy::setPasteboardURL(IPC::Connection& connection, const PasteboardURL& pasteboardURL, const String& pasteboardName, CompletionHandler<void(int64_t)>&& completionHandler)
    145241{
    146     for (auto* webProcessProxy : m_webProcessProxyList) {
    147         if (!webProcessProxy->hasConnection(connection))
    148             continue;
    149 
     242    if (auto* webProcessProxy = webProcessProxyForConnection(connection)) {
    150243        if (!webProcessProxy->checkURLReceivedFromWebProcess(pasteboardURL.url.string()))
    151244            return completionHandler(0);
    152245
    153         return completionHandler(PlatformPasteboard(pasteboardName).setURL(pasteboardURL));
     246        auto previousChangeCount = PlatformPasteboard(pasteboardName).changeCount();
     247        auto newChangeCount = PlatformPasteboard(pasteboardName).setURL(pasteboardURL);
     248        didModifyContentsOfPasteboard(connection, pasteboardName, previousChangeCount, newChangeCount);
     249        return completionHandler(newChangeCount);
    154250    }
    155251    completionHandler(0);
    156252}
    157253
    158 void WebPasteboardProxy::setPasteboardColor(const String& pasteboardName, const WebCore::Color& color, CompletionHandler<void(int64_t)>&& completionHandler)
    159 {
    160     completionHandler(PlatformPasteboard(pasteboardName).setColor(color));
    161 }
    162 
    163 void WebPasteboardProxy::setPasteboardStringForType(const String& pasteboardName, const String& pasteboardType, const String& string, CompletionHandler<void(int64_t)>&& completionHandler)
     254void WebPasteboardProxy::setPasteboardColor(IPC::Connection& connection, const String& pasteboardName, const WebCore::Color& color, CompletionHandler<void(int64_t)>&& completionHandler)
     255{
     256    auto previousChangeCount = PlatformPasteboard(pasteboardName).changeCount();
     257    auto newChangeCount = PlatformPasteboard(pasteboardName).setColor(color);
     258    didModifyContentsOfPasteboard(connection, pasteboardName, previousChangeCount, newChangeCount);
     259    completionHandler(newChangeCount);
     260}
     261
     262void WebPasteboardProxy::setPasteboardStringForType(IPC::Connection& connection, const String& pasteboardName, const String& pasteboardType, const String& string, CompletionHandler<void(int64_t)>&& completionHandler)
    164263{
    165264    ASSERT(!pasteboardType.isNull());
     
    167266        return completionHandler(0);
    168267
    169     completionHandler(PlatformPasteboard(pasteboardName).setStringForType(string, pasteboardType));
     268    auto previousChangeCount = PlatformPasteboard(pasteboardName).changeCount();
     269    auto newChangeCount = PlatformPasteboard(pasteboardName).setStringForType(string, pasteboardType);
     270    didModifyContentsOfPasteboard(connection, pasteboardName, previousChangeCount, newChangeCount);
     271    completionHandler(newChangeCount);
    170272}
    171273
     
    175277}
    176278
    177 void WebPasteboardProxy::urlStringSuitableForLoading(const String& pasteboardName, CompletionHandler<void(String&& url, String&& title)>&& completionHandler)
    178 {
     279void WebPasteboardProxy::urlStringSuitableForLoading(IPC::Connection& connection, const String& pasteboardName, CompletionHandler<void(String&& url, String&& title)>&& completionHandler)
     280{
     281    if (!canAccessPasteboardData(connection, pasteboardName))
     282        return completionHandler({ }, { });
     283
    179284    String title;
    180285    auto urlString = PlatformPasteboard(pasteboardName).urlStringSuitableForLoading(title);
     
    188293        return completionHandler(0);
    189294
    190     if (handle.isNull())
    191         return completionHandler(PlatformPasteboard(pasteboardName).setBufferForType(nullptr, pasteboardType));
     295    auto previousChangeCount = PlatformPasteboard(pasteboardName).changeCount();
     296    if (handle.isNull()) {
     297        auto newChangeCount = PlatformPasteboard(pasteboardName).setBufferForType(nullptr, pasteboardType);
     298        didModifyContentsOfPasteboard(connection, pasteboardName, previousChangeCount, newChangeCount);
     299        return completionHandler(newChangeCount);
     300    }
    192301
    193302    // SharedMemory::Handle::size() is rounded up to the nearest page.
     
    198307        return completionHandler(0);
    199308    auto buffer = SharedBuffer::create(static_cast<unsigned char *>(sharedMemoryBuffer->data()), static_cast<size_t>(size));
    200     completionHandler(PlatformPasteboard(pasteboardName).setBufferForType(buffer.ptr(), pasteboardType));
     309    auto newChangeCount = PlatformPasteboard(pasteboardName).setBufferForType(buffer.ptr(), pasteboardType);
     310    didModifyContentsOfPasteboard(connection, pasteboardName, previousChangeCount, newChangeCount);
     311    completionHandler(newChangeCount);
    201312}
    202313
     
    215326}
    216327
    217 void WebPasteboardProxy::writeCustomData(const Vector<PasteboardCustomData>& data, const String& pasteboardName, CompletionHandler<void(int64_t)>&& completionHandler)
    218 {
    219     completionHandler(PlatformPasteboard(pasteboardName).write(data));
     328void WebPasteboardProxy::writeCustomData(IPC::Connection& connection, const Vector<PasteboardCustomData>& data, const String& pasteboardName, CompletionHandler<void(int64_t)>&& completionHandler)
     329{
     330    auto previousChangeCount = PlatformPasteboard(pasteboardName).changeCount();
     331    auto newChangeCount = PlatformPasteboard(pasteboardName).write(data);
     332    didModifyContentsOfPasteboard(connection, pasteboardName, previousChangeCount, newChangeCount);
     333    completionHandler(newChangeCount);
    220334}
    221335
     
    235349}
    236350
    237 void WebPasteboardProxy::readStringFromPasteboard(size_t index, const String& pasteboardType, const String& pasteboardName, CompletionHandler<void(String&&)>&& completionHandler)
    238 {
    239     ASSERT(!pasteboardType.isNull());
    240     if (pasteboardType.isNull())
     351void WebPasteboardProxy::readStringFromPasteboard(IPC::Connection& connection, size_t index, const String& pasteboardType, const String& pasteboardName, CompletionHandler<void(String&&)>&& completionHandler)
     352{
     353    ASSERT(!pasteboardType.isNull());
     354    if (pasteboardType.isNull())
     355        return completionHandler({ });
     356
     357    if (!canAccessPasteboardData(connection, pasteboardName))
    241358        return completionHandler({ });
    242359
     
    244361}
    245362
    246 void WebPasteboardProxy::readURLFromPasteboard(size_t index, const String& pasteboardName, CompletionHandler<void(String&& url, String&& title)>&& completionHandler)
    247 {
     363void WebPasteboardProxy::readURLFromPasteboard(IPC::Connection& connection, size_t index, const String& pasteboardName, CompletionHandler<void(String&& url, String&& title)>&& completionHandler)
     364{
     365    if (!canAccessPasteboardData(connection, pasteboardName))
     366        return completionHandler({ }, { });
     367
    248368    String title;
    249369    String url = PlatformPasteboard(pasteboardName).readURL(index, title);
     
    251371}
    252372
    253 void WebPasteboardProxy::readBufferFromPasteboard(size_t index, const String& pasteboardType, const String& pasteboardName, CompletionHandler<void(SharedMemory::Handle&&, uint64_t size)>&& completionHandler)
    254 {
    255     ASSERT(!pasteboardType.isNull());
    256     if (pasteboardType.isNull())
     373void WebPasteboardProxy::readBufferFromPasteboard(IPC::Connection& connection, size_t index, const String& pasteboardType, const String& pasteboardName, CompletionHandler<void(SharedMemory::Handle&&, uint64_t size)>&& completionHandler)
     374{
     375    ASSERT(!pasteboardType.isNull());
     376    if (pasteboardType.isNull())
     377        return completionHandler({ }, 0);
     378
     379    if (!canAccessPasteboardData(connection, pasteboardName))
    257380        return completionHandler({ }, 0);
    258381
     
    279402#if PLATFORM(IOS_FAMILY)
    280403
    281 void WebPasteboardProxy::writeURLToPasteboard(const PasteboardURL& url, const String& pasteboardName)
    282 {
     404void WebPasteboardProxy::writeURLToPasteboard(IPC::Connection& connection, const PasteboardURL& url, const String& pasteboardName)
     405{
     406    auto previousChangeCount = PlatformPasteboard(pasteboardName).changeCount();
    283407    PlatformPasteboard(pasteboardName).write(url);
    284 }
    285 
    286 void WebPasteboardProxy::writeWebContentToPasteboard(const WebCore::PasteboardWebContent& content, const String& pasteboardName)
    287 {
     408    didModifyContentsOfPasteboard(connection, pasteboardName, previousChangeCount, PlatformPasteboard(pasteboardName).changeCount());
     409}
     410
     411void WebPasteboardProxy::writeWebContentToPasteboard(IPC::Connection& connection, const WebCore::PasteboardWebContent& content, const String& pasteboardName)
     412{
     413    auto previousChangeCount = PlatformPasteboard(pasteboardName).changeCount();
    288414    PlatformPasteboard(pasteboardName).write(content);
    289 }
    290 
    291 void WebPasteboardProxy::writeImageToPasteboard(const WebCore::PasteboardImage& pasteboardImage, const String& pasteboardName)
    292 {
     415    didModifyContentsOfPasteboard(connection, pasteboardName, previousChangeCount, PlatformPasteboard(pasteboardName).changeCount());
     416}
     417
     418void WebPasteboardProxy::writeImageToPasteboard(IPC::Connection& connection, const WebCore::PasteboardImage& pasteboardImage, const String& pasteboardName)
     419{
     420    auto previousChangeCount = PlatformPasteboard(pasteboardName).changeCount();
    293421    PlatformPasteboard(pasteboardName).write(pasteboardImage);
    294 }
    295 
    296 void WebPasteboardProxy::writeStringToPasteboard(const String& pasteboardType, const String& text, const String& pasteboardName)
    297 {
     422    didModifyContentsOfPasteboard(connection, pasteboardName, previousChangeCount, PlatformPasteboard(pasteboardName).changeCount());
     423}
     424
     425void WebPasteboardProxy::writeStringToPasteboard(IPC::Connection& connection, const String& pasteboardType, const String& text, const String& pasteboardName)
     426{
     427    auto previousChangeCount = PlatformPasteboard(pasteboardName).changeCount();
    298428    PlatformPasteboard(pasteboardName).write(pasteboardType, text);
     429    didModifyContentsOfPasteboard(connection, pasteboardName, previousChangeCount, PlatformPasteboard(pasteboardName).changeCount());
    299430}
    300431
  • trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm

    r258796 r259151  
    40384038    }
    40394039
    4040     m_page->performDragOperation(*dragData, draggingInfo.draggingPasteboard.name, WTFMove(sandboxExtensionHandle), WTFMove(sandboxExtensionForUpload));
     4040    String draggingPasteboardName = draggingInfo.draggingPasteboard.name;
     4041    m_page->grantAccessToCurrentPasteboardData(draggingPasteboardName);
     4042    m_page->performDragOperation(*dragData, draggingPasteboardName, WTFMove(sandboxExtensionHandle), WTFMove(sandboxExtensionForUpload));
    40414043    delete dragData;
    40424044
     
    43324334    auto buffer = WebCore::SharedBuffer::create(data);
    43334335    if (WebCore::PasteboardCustomData::fromSharedBuffer(buffer.get()).origin() == originIdentifier) {
     4336        m_page->grantAccessToCurrentPasteboardData(NSPasteboardNameGeneral);
    43344337        completion(WebCore::DOMPasteAccessResponse::GrantedForGesture);
    43354338        return;
     
    43484351void WebViewImpl::handleDOMPasteRequestWithResult(WebCore::DOMPasteAccessResponse response)
    43494352{
     4353    if (response == WebCore::DOMPasteAccessResponse::GrantedForCommand || response == WebCore::DOMPasteAccessResponse::GrantedForGesture)
     4354        m_page->grantAccessToCurrentPasteboardData(NSPasteboardNameGeneral);
     4355
    43504356    if (auto handler = std::exchange(m_domPasteRequestHandler, { }))
    43514357        handler(response);
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r259146 r259151  
    125125#include "WebPageMessages.h"
    126126#include "WebPageProxyMessages.h"
     127#include "WebPasteboardProxy.h"
    127128#include "WebPaymentCoordinatorProxy.h"
    128129#include "WebPopupItem.h"
     
    22802281}
    22812282
     2283static bool isPasteCommandName(const String& commandName)
     2284{
     2285    static NeverDestroyed<HashSet<String, ASCIICaseInsensitiveHash>> pasteCommandNames = HashSet<String, ASCIICaseInsensitiveHash> {
     2286        "Paste",
     2287        "PasteAndMatchStyle",
     2288        "PasteAsQuotation",
     2289        "PasteAsPlainText"
     2290    };
     2291    return pasteCommandNames->contains(commandName);
     2292}
     2293
    22822294void WebPageProxy::executeEditCommand(const String& commandName, const String& argument, WTF::Function<void(CallbackBase::Error)>&& callbackFunction)
    22832295{
     
    22872299    }
    22882300
     2301    if (isPasteCommandName(commandName))
     2302        willPerformPasteCommand();
     2303
    22892304    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::executeEditCommand"_s));
    22902305    send(Messages::WebPage::ExecuteEditCommandWithCallback(commandName, argument, callbackID));
     
    22972312    if (!hasRunningProcess())
    22982313        return;
     2314
     2315    if (isPasteCommandName(commandName))
     2316        willPerformPasteCommand();
    22992317
    23002318    if (commandName == ignoreSpellingCommandName)
     
    65406558        ++m_pendingLearnOrIgnoreWordMessageCount;
    65416559
     6560    platformDidSelectItemFromActiveContextMenu(item);
     6561
    65426562    send(Messages::WebPage::DidSelectItemFromActiveContextMenu(item));
    65436563}
     
    75927612
    75937613    pageClient().clearAllEditCommands();
     7614
     7615#if PLATFORM(COCOA)
     7616    WebPasteboardProxy::singleton().revokeAccessToAllData(m_process.get());
     7617#endif
    75947618
    75957619    auto resetStateReason = terminationReason == ProcessTerminationReason::NavigationSwap ? ResetStateReason::NavigationSwap : ResetStateReason::WebProcessExited;
     
    1000010024#endif
    1000110025
     10026#if ENABLE(CONTEXT_MENUS) && !PLATFORM(MAC)
     10027
     10028void WebPageProxy::platformDidSelectItemFromActiveContextMenu(const WebContextMenuItemData&)
     10029{
     10030}
     10031
     10032#endif
     10033
     10034#if !PLATFORM(COCOA)
     10035
     10036void WebPageProxy::willPerformPasteCommand()
     10037{
     10038}
     10039
     10040#endif
     10041
    1000210042} // namespace WebKit
    1000310043
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r259146 r259151  
    17151715    NavigatingToAppBoundDomain isNavigatingToAppBoundDomain() const { return m_isNavigatingToAppBoundDomain; }
    17161716
     1717#if PLATFORM(COCOA)
     1718    void grantAccessToCurrentPasteboardData(const String& pasteboardName);
     1719#endif
     1720
     1721#if ENABLE(CONTEXT_MENUS)
     1722    void platformDidSelectItemFromActiveContextMenu(const WebContextMenuItemData&);
     1723#endif
     1724
    17171725private:
    17181726    WebPageProxy(PageClient&, WebProcessProxy&, Ref<API::PageConfiguration>&&);
     
    19341942
    19351943    void requestDOMPasteAccess(const WebCore::IntRect&, const String&, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&&);
     1944    void willPerformPasteCommand();
    19361945
    19371946    // Back/Forward list management
  • trunk/Source/WebKit/UIProcess/WebPasteboardProxy.cpp

    r259124 r259151  
    6969}
    7070
     71WebProcessProxy* WebPasteboardProxy::webProcessProxyForConnection(IPC::Connection& connection) const
     72{
     73    for (auto* webProcessProxy : m_webProcessProxyList) {
     74        if (webProcessProxy->hasConnection(connection))
     75            return webProcessProxy;
     76    }
     77    return nullptr;
     78}
     79
    7180#if !PLATFORM(COCOA)
    7281
     
    7685}
    7786
    78 void WebPasteboardProxy::writeCustomData(const Vector<WebCore::PasteboardCustomData>&, const String&, CompletionHandler<void(int64_t)>&& completionHandler)
     87void WebPasteboardProxy::writeCustomData(IPC::Connection&, const Vector<WebCore::PasteboardCustomData>&, const String&, CompletionHandler<void(int64_t)>&& completionHandler)
    7988{
    8089    completionHandler(0);
     
    96105}
    97106
    98 void WebPasteboardProxy::readURLFromPasteboard(size_t, const String&, CompletionHandler<void(String&& url, String&& title)>&& completionHandler)
     107void WebPasteboardProxy::readURLFromPasteboard(IPC::Connection&, size_t, const String&, CompletionHandler<void(String&& url, String&& title)>&& completionHandler)
    99108{
    100109    completionHandler({ }, { });
    101110}
    102111
    103 void WebPasteboardProxy::readBufferFromPasteboard(size_t, const String&, const String&, CompletionHandler<void(SharedMemory::Handle&&, uint64_t size)>&& completionHandler)
     112void WebPasteboardProxy::readBufferFromPasteboard(IPC::Connection&, size_t, const String&, const String&, CompletionHandler<void(SharedMemory::Handle&&, uint64_t size)>&& completionHandler)
    104113{
    105114    completionHandler({ }, 0);
     
    108117#if !USE(LIBWPE)
    109118
    110 void WebPasteboardProxy::readStringFromPasteboard(size_t, const String&, const String&, CompletionHandler<void(String&&)>&& completionHandler)
     119void WebPasteboardProxy::readStringFromPasteboard(IPC::Connection&, size_t, const String&, const String&, CompletionHandler<void(String&&)>&& completionHandler)
    111120{
    112121    completionHandler({ });
     
    125134}
    126135
    127 void WebPasteboardProxy::urlStringSuitableForLoading(const String&, CompletionHandler<void(String&& url, String&& title)>&& completionHandler)
     136void WebPasteboardProxy::urlStringSuitableForLoading(IPC::Connection&, const String&, CompletionHandler<void(String&& url, String&& title)>&& completionHandler)
    128137{
    129138    completionHandler({ }, { });
  • trunk/Source/WebKit/UIProcess/WebPasteboardProxy.h

    r259124 r259151  
    3131#include <WebCore/SharedBuffer.h>
    3232#include <wtf/Forward.h>
     33#include <wtf/HashMap.h>
    3334#include <wtf/HashSet.h>
     35#include <wtf/WeakHashSet.h>
    3436
    3537namespace WebCore {
     
    5759    void removeWebProcessProxy(WebProcessProxy&);
    5860
     61#if PLATFORM(COCOA)
     62    void revokeAccessToAllData(WebProcessProxy&);
     63    void grantAccessToCurrentData(WebProcessProxy&, const String& pasteboardName);
     64#endif
     65
    5966#if PLATFORM(GTK)
    6067    void setPrimarySelectionOwner(WebFrameProxy*);
     
    6572    WebPasteboardProxy();
    6673   
    67     typedef HashSet<WebProcessProxy*> WebProcessProxyList;
     74    using WebProcessProxyList = HashSet<WebProcessProxy*>;
    6875
    6976    void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
    7077    void didReceiveSyncMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&) override;
    7178
     79    WebProcessProxy* webProcessProxyForConnection(IPC::Connection&) const;
     80
    7281#if PLATFORM(IOS_FAMILY)
    73     void writeURLToPasteboard(const WebCore::PasteboardURL&, const String& pasteboardName);
    74     void writeWebContentToPasteboard(const WebCore::PasteboardWebContent&, const String& pasteboardName);
    75     void writeImageToPasteboard(const WebCore::PasteboardImage&, const String& pasteboardName);
    76     void writeStringToPasteboard(const String& pasteboardType, const String&, const String& pasteboardName);
     82    void writeURLToPasteboard(IPC::Connection&, const WebCore::PasteboardURL&, const String& pasteboardName);
     83    void writeWebContentToPasteboard(IPC::Connection&, const WebCore::PasteboardWebContent&, const String& pasteboardName);
     84    void writeImageToPasteboard(IPC::Connection&, const WebCore::PasteboardImage&, const String& pasteboardName);
     85    void writeStringToPasteboard(IPC::Connection&, const String& pasteboardType, const String&, const String& pasteboardName);
    7786    void updateSupportedTypeIdentifiers(const Vector<String>& identifiers, const String& pasteboardName);
    7887#endif
     
    8190    void getPasteboardTypes(const String& pasteboardName, CompletionHandler<void(Vector<String>&&)>&&);
    8291    void getPasteboardPathnamesForType(IPC::Connection&, const String& pasteboardName, const String& pasteboardType, CompletionHandler<void(Vector<String>&& pathnames, SandboxExtension::HandleArray&&)>&&);
    83     void getPasteboardStringForType(const String& pasteboardName, const String& pasteboardType, CompletionHandler<void(String&&)>&&);
    84     void getPasteboardStringsForType(const String& pasteboardName, const String& pasteboardType, CompletionHandler<void(Vector<String>&&)>&&);
    85     void getPasteboardBufferForType(const String& pasteboardName, const String& pasteboardType, CompletionHandler<void(SharedMemory::Handle&&, uint64_t)>&&);
     92    void getPasteboardStringForType(IPC::Connection&, const String& pasteboardName, const String& pasteboardType, CompletionHandler<void(String&&)>&&);
     93    void getPasteboardStringsForType(IPC::Connection&, const String& pasteboardName, const String& pasteboardType, CompletionHandler<void(Vector<String>&&)>&&);
     94    void getPasteboardBufferForType(IPC::Connection&, const String& pasteboardName, const String& pasteboardType, CompletionHandler<void(SharedMemory::Handle&&, uint64_t)>&&);
    8695    void getPasteboardChangeCount(const String& pasteboardName, CompletionHandler<void(int64_t)>&&);
    87     void getPasteboardColor(const String& pasteboardName, CompletionHandler<void(WebCore::Color&&)>&&);
    88     void getPasteboardURL(const String& pasteboardName, CompletionHandler<void(const String&)>&&);
    89     void addPasteboardTypes(const String& pasteboardName, const Vector<String>& pasteboardTypes, CompletionHandler<void(int64_t)>&&);
    90     void setPasteboardTypes(const String& pasteboardName, const Vector<String>& pasteboardTypes, CompletionHandler<void(int64_t)>&&);
     96    void getPasteboardColor(IPC::Connection&, const String& pasteboardName, CompletionHandler<void(WebCore::Color&&)>&&);
     97    void getPasteboardURL(IPC::Connection&, const String& pasteboardName, CompletionHandler<void(const String&)>&&);
     98    void addPasteboardTypes(IPC::Connection&, const String& pasteboardName, const Vector<String>& pasteboardTypes, CompletionHandler<void(int64_t)>&&);
     99    void setPasteboardTypes(IPC::Connection&, const String& pasteboardName, const Vector<String>& pasteboardTypes, CompletionHandler<void(int64_t)>&&);
    91100    void setPasteboardURL(IPC::Connection&, const WebCore::PasteboardURL&, const String& pasteboardName, CompletionHandler<void(int64_t)>&&);
    92     void setPasteboardColor(const String&, const WebCore::Color&, CompletionHandler<void(int64_t)>&&);
    93     void setPasteboardStringForType(const String& pasteboardName, const String& pasteboardType, const String&, CompletionHandler<void(int64_t)>&&);
     101    void setPasteboardColor(IPC::Connection&, const String&, const WebCore::Color&, CompletionHandler<void(int64_t)>&&);
     102    void setPasteboardStringForType(IPC::Connection&, const String& pasteboardName, const String& pasteboardType, const String&, CompletionHandler<void(int64_t)>&&);
    94103    void setPasteboardBufferForType(IPC::Connection&, const String& pasteboardName, const String& pasteboardType, const SharedMemory::Handle&, uint64_t size, CompletionHandler<void(int64_t)>&&);
    95104#endif
    96105
    97     void readStringFromPasteboard(size_t index, const String& pasteboardType, const String& pasteboardName, CompletionHandler<void(String&&)>&&);
    98     void readURLFromPasteboard(size_t index, const String& pasteboardName, CompletionHandler<void(String&& url, String&& title)>&&);
    99     void readBufferFromPasteboard(size_t index, const String& pasteboardType, const String& pasteboardName, CompletionHandler<void(SharedMemory::Handle&&, uint64_t size)>&&);
     106    void readStringFromPasteboard(IPC::Connection&, size_t index, const String& pasteboardType, const String& pasteboardName, CompletionHandler<void(String&&)>&&);
     107    void readURLFromPasteboard(IPC::Connection&, size_t index, const String& pasteboardName, CompletionHandler<void(String&& url, String&& title)>&&);
     108    void readBufferFromPasteboard(IPC::Connection&, size_t index, const String& pasteboardType, const String& pasteboardName, CompletionHandler<void(SharedMemory::Handle&&, uint64_t size)>&&);
    100109    void getPasteboardItemsCount(const String& pasteboardName, CompletionHandler<void(uint64_t)>&&);
    101110    void informationForItemAtIndex(size_t index, const String& pasteboardName, int64_t changeCount, CompletionHandler<void(Optional<WebCore::PasteboardItemInfo>&&)>&&);
    102111    void allPasteboardItemInfo(const String& pasteboardName, int64_t changeCount, CompletionHandler<void(Optional<Vector<WebCore::PasteboardItemInfo>>&&)>&&);
    103112
    104     void writeCustomData(const Vector<WebCore::PasteboardCustomData>&, const String& pasteboardName, CompletionHandler<void(int64_t)>&&);
     113    void writeCustomData(IPC::Connection&, const Vector<WebCore::PasteboardCustomData>&, const String& pasteboardName, CompletionHandler<void(int64_t)>&&);
    105114    void typesSafeForDOMToReadAndWrite(const String& pasteboardName, const String& origin, CompletionHandler<void(Vector<String>&&)>&&);
    106115    void containsStringSafeForDOMToReadForType(const String&, const String& pasteboardName, CompletionHandler<void(bool)>&&);
    107116    void containsURLStringSuitableForLoading(const String& pasteboardName, CompletionHandler<void(bool)>&&);
    108     void urlStringSuitableForLoading(const String& pasteboardName, CompletionHandler<void(String&& url, String&& title)>&&);
     117    void urlStringSuitableForLoading(IPC::Connection&, const String& pasteboardName, CompletionHandler<void(String&& url, String&& title)>&&);
    109118
    110119#if PLATFORM(GTK)
     
    122131#endif
    123132
     133#if PLATFORM(COCOA)
     134    bool canAccessPasteboardData(IPC::Connection&, const String& pasteboardName) const;
     135    void didModifyContentsOfPasteboard(IPC::Connection&, const String& pasteboardName, int64_t previousChangeCount, int64_t newChangeCount);
     136#endif
     137
    124138    WebProcessProxyList m_webProcessProxyList;
     139
     140#if PLATFORM(COCOA)
     141    HashMap<String, std::pair<int64_t, WeakHashSet<WebProcessProxy>>> m_pasteboardNameToChangeCountAndProcessesMap;
     142#endif
    125143};
    126144
  • trunk/Source/WebKit/UIProcess/WebPasteboardProxy.messages.in

    r259124 r259151  
    2323messages -> WebPasteboardProxy NotRefCounted {
    2424#if PLATFORM(IOS_FAMILY)
    25     WriteURLToPasteboard(struct WebCore::PasteboardURL url, String pasteboardName)
    26     WriteWebContentToPasteboard(struct WebCore::PasteboardWebContent content, String pasteboardName)
    27     WriteImageToPasteboard(struct WebCore::PasteboardImage pasteboardImage, String pasteboardName)
    28     WriteStringToPasteboard(String pasteboardType, String text, String pasteboardName)
     25    WriteURLToPasteboard(struct WebCore::PasteboardURL url, String pasteboardName) WantsConnection
     26    WriteWebContentToPasteboard(struct WebCore::PasteboardWebContent content, String pasteboardName) WantsConnection
     27    WriteImageToPasteboard(struct WebCore::PasteboardImage pasteboardImage, String pasteboardName) WantsConnection
     28    WriteStringToPasteboard(String pasteboardType, String text, String pasteboardName) WantsConnection
    2929    UpdateSupportedTypeIdentifiers(Vector<String> identifiers, String pasteboardName)
    3030#endif
    3131
    32     WriteCustomData(Vector<WebCore::PasteboardCustomData> data, String pasteboardName) -> (int64_t changeCount) Synchronous
     32    WriteCustomData(Vector<WebCore::PasteboardCustomData> data, String pasteboardName) -> (int64_t changeCount) Synchronous WantsConnection
    3333    TypesSafeForDOMToReadAndWrite(String pasteboardName, String origin) -> (Vector<String> types) Synchronous
    3434    AllPasteboardItemInfo(String pasteboardName, int64_t changeCount) -> (Optional<Vector<WebCore::PasteboardItemInfo>> allInfo) Synchronous
    3535    InformationForItemAtIndex(uint64_t index, String pasteboardName, int64_t changeCount) -> (Optional<WebCore::PasteboardItemInfo> info) Synchronous
    3636    GetPasteboardItemsCount(String pasteboardName) -> (uint64_t itemsCount) Synchronous
    37     ReadStringFromPasteboard(uint64_t index, String pasteboardType, String pasteboardName) -> (String string) Synchronous
    38     ReadURLFromPasteboard(uint64_t index, String pasteboardName) -> (String url, String title) Synchronous
    39     ReadBufferFromPasteboard(uint64_t index, String pasteboardType, String pasteboardName) -> (WebKit::SharedMemory::Handle handle, uint64_t size) Synchronous
     37    ReadStringFromPasteboard(uint64_t index, String pasteboardType, String pasteboardName) -> (String string) Synchronous WantsConnection
     38    ReadURLFromPasteboard(uint64_t index, String pasteboardName) -> (String url, String title) Synchronous WantsConnection
     39    ReadBufferFromPasteboard(uint64_t index, String pasteboardType, String pasteboardName) -> (WebKit::SharedMemory::Handle handle, uint64_t size) Synchronous WantsConnection
    4040    ContainsStringSafeForDOMToReadForType(String type, String pasteboardName) -> (bool result) Synchronous
    4141
     
    4545    GetPasteboardTypes(String pasteboardName) -> (Vector<String> types) Synchronous
    4646    GetPasteboardPathnamesForType(String pasteboardName, String pasteboardType) -> (Vector<String> pathnames, WebKit::SandboxExtension::HandleArray sandboxExtensions) Synchronous WantsConnection
    47     GetPasteboardStringForType(String pasteboardName, String pasteboardType) -> (String string) Synchronous
    48     GetPasteboardStringsForType(String pasteboardName, String pasteboardType) -> (Vector<String> strings) Synchronous
    49     GetPasteboardBufferForType(String pasteboardName, String pasteboardType) -> (WebKit::SharedMemory::Handle handle, uint64_t size) Synchronous
     47    GetPasteboardStringForType(String pasteboardName, String pasteboardType) -> (String string) Synchronous WantsConnection
     48    GetPasteboardStringsForType(String pasteboardName, String pasteboardType) -> (Vector<String> strings) Synchronous WantsConnection
     49    GetPasteboardBufferForType(String pasteboardName, String pasteboardType) -> (WebKit::SharedMemory::Handle handle, uint64_t size) Synchronous WantsConnection
    5050    GetPasteboardChangeCount(String pasteboardName) -> (int64_t changeCount) Synchronous
    51     GetPasteboardColor(String pasteboardName) -> (WebCore::Color color) Synchronous
    52     GetPasteboardURL(String pasteboardName) -> (String urlString) Synchronous
    53     AddPasteboardTypes(String pasteboardName, Vector<String> pasteboardTypes) -> (int64_t changeCount) Synchronous
    54     SetPasteboardTypes(String pasteboardName, Vector<String> pasteboardTypes) -> (int64_t changeCount) Synchronous
     51    GetPasteboardColor(String pasteboardName) -> (WebCore::Color color) Synchronous WantsConnection
     52    GetPasteboardURL(String pasteboardName) -> (String urlString) Synchronous WantsConnection
     53    AddPasteboardTypes(String pasteboardName, Vector<String> pasteboardTypes) -> (int64_t changeCount) Synchronous WantsConnection
     54    SetPasteboardTypes(String pasteboardName, Vector<String> pasteboardTypes) -> (int64_t changeCount) Synchronous WantsConnection
    5555    SetPasteboardURL(struct WebCore::PasteboardURL pasteboardURL, String pasteboardName) -> (int64_t changeCount) Synchronous WantsConnection
    56     SetPasteboardColor(String pasteboardName, WebCore::Color color) -> (int64_t changeCount) Synchronous
    57     SetPasteboardStringForType(String pasteboardName, String pasteboardType, String string) -> (int64_t changeCount) Synchronous
     56    SetPasteboardColor(String pasteboardName, WebCore::Color color) -> (int64_t changeCount) Synchronous WantsConnection
     57    SetPasteboardStringForType(String pasteboardName, String pasteboardType, String string) -> (int64_t changeCount) Synchronous WantsConnection
    5858    SetPasteboardBufferForType(String pasteboardName, String pasteboardType, WebKit::SharedMemory::Handle handle, uint64_t size) -> (int64_t changeCount) Synchronous WantsConnection
    5959    ContainsURLStringSuitableForLoading(String pasteboardName) -> (bool result) Synchronous
    60     URLStringSuitableForLoading(String pasteboardName) -> (String url, String title) Synchronous
     60    URLStringSuitableForLoading(String pasteboardName) -> (String url, String title) Synchronous WantsConnection
    6161#endif
    6262
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm

    r259126 r259151  
    36323632- (BOOL)_handleDOMPasteRequestWithResult:(WebCore::DOMPasteAccessResponse)response
    36333633{
     3634    if (response == WebCore::DOMPasteAccessResponse::GrantedForCommand || response == WebCore::DOMPasteAccessResponse::GrantedForGesture)
     3635        _page->grantAccessToCurrentPasteboardData(UIPasteboardNameGeneral);
     3636
    36343637    if (auto pasteHandler = WTFMove(_domPasteRequestHandler)) {
    36353638        [self hideGlobalMenuController];
     
    78797882        WebKit::SandboxExtension::Handle sandboxExtensionHandle;
    78807883        WebKit::SandboxExtension::HandleArray sandboxExtensionForUpload;
     7884        auto dragPasteboardName = WebCore::Pasteboard::nameOfDragPasteboard();
     7885        retainedSelf->_page->grantAccessToCurrentPasteboardData(dragPasteboardName);
    78817886        retainedSelf->_page->createSandboxExtensionsIfNeeded(filenames, sandboxExtensionHandle, sandboxExtensionForUpload);
    7882         retainedSelf->_page->performDragOperation(capturedDragData, WebCore::Pasteboard::nameOfDragPasteboard(), WTFMove(sandboxExtensionHandle), WTFMove(sandboxExtensionForUpload));
     7887        retainedSelf->_page->performDragOperation(capturedDragData, dragPasteboardName, WTFMove(sandboxExtensionHandle), WTFMove(sandboxExtensionForUpload));
    78837888        if (shouldSnapshotView) {
    78847889            retainedSelf->_visibleContentViewSnapshot = [retainedSelf snapshotViewAfterScreenUpdates:NO];
  • trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm

    r259146 r259151  
    15711571#endif
    15721572
     1573void WebPageProxy::willPerformPasteCommand()
     1574{
     1575    grantAccessToCurrentPasteboardData(UIPasteboardNameGeneral);
     1576}
     1577
    15731578} // namespace WebKit
    15741579
  • trunk/Source/WebKit/UIProcess/libwpe/WebPasteboardProxyLibWPE.cpp

    r254524 r259151  
    4141}
    4242
    43 void WebPasteboardProxy::readStringFromPasteboard(size_t index, const String& pasteboardType, const String&, CompletionHandler<void(String&&)>&& completionHandler)
     43void WebPasteboardProxy::readStringFromPasteboard(IPC::Connection&, size_t index, const String& pasteboardType, const String&, CompletionHandler<void(String&&)>&& completionHandler)
    4444{
    4545    completionHandler(PlatformPasteboard().readString(index, pasteboardType));
  • trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm

    r258507 r259151  
    655655#endif
    656656
     657#if ENABLE(CONTEXT_MENUS)
     658
     659void WebPageProxy::platformDidSelectItemFromActiveContextMenu(const WebContextMenuItemData& item)
     660{
     661    if (item.action() == ContextMenuItemTagPaste)
     662        grantAccessToCurrentPasteboardData(NSPasteboardNameGeneral);
     663}
     664
     665#endif
     666
     667void WebPageProxy::willPerformPasteCommand()
     668{
     669    grantAccessToCurrentPasteboardData(NSPasteboardNameGeneral);
     670}
     671
    657672} // namespace WebKit
    658673
Note: See TracChangeset for help on using the changeset viewer.