haikuwebkit/Source/WebCore/page/PagePasteboardContext.h

63 lines
2.3 KiB
C
Raw Permalink Normal View History

Plumb an Optional<PageIdentifier> through Pasteboard-related codepaths https://bugs.webkit.org/show_bug.cgi?id=221987 Reviewed by Tim Horton. Source/WebCore: In order to facilitate tagging pasteboard reads and writes with a data owner type on iOS sourced from `WKContentView`, we add infrastructure to (indirectly) tag `Pasteboard` with an optional `PageIdentifier` to indicate which page is triggering the pasteboard operation. However, since the `Pasteboard` class should only be responsible for interfacing with platform-dependent strategies for reading or writing data, we can't directly add a `PageIdentifier` member to `Pasteboard`. Instead, we introduce a separate `PasteboardContext` object, and let `Pasteboard` hold a unique pointer to this context (which is set during construction). `PasteboardContext` is then subclassed by `PagePasteboardContext`, which holds a `PageIdentifier` and is created from call sites of the `Pasteboard` constructor that have access to page identifiers (e.g. `Editor`, `Clipboard`, `EventHandler`). In a future patch, this opaque `PasteboardContext` will be converted back to a `PagePasteboardContext` in order to retrieve the page identifier in the WebKit client layer. * Headers.cmake: * Modules/async-clipboard/Clipboard.cpp: (WebCore::Clipboard::readText): (WebCore::Clipboard::writeText): (WebCore::Clipboard::read): (WebCore::Clipboard::ItemWriter::ItemWriter): Here (and in many places below), create `PagePasteboardContext` objects and use them to create `Pasteboard`s, passing them in as opaque `PasteboardContext`s. * WebCore.xcodeproj/project.pbxproj: * dom/DataTransfer.cpp: (WebCore::DataTransfer::createForDrag): * dom/DataTransfer.h: * editing/Editor.cpp: (WebCore::createDataTransferForClipboardEvent): (WebCore::dispatchClipboardEvent): (WebCore::Editor::pasteAsPlainTextBypassingDHTML): (WebCore::Editor::performCutOrCopy): (WebCore::Editor::paste): (WebCore::Editor::pasteAsPlainText): (WebCore::Editor::pasteAsQuotation): (WebCore::Editor::copyURL): (WebCore::Editor::copyImage): * editing/EditorCommand.cpp: (WebCore::executePasteGlobalSelection): * editing/mac/EditorMac.mm: (WebCore::Editor::readSelectionFromPasteboard): (WebCore::Editor::replaceNodeFromPasteboard): * inspector/CommandLineAPIHost.cpp: (WebCore::CommandLineAPIHost::copyText): * inspector/InspectorFrontendHost.cpp: (WebCore::InspectorFrontendHost::copyText): * page/DragController.cpp: (WebCore::documentFragmentFromDragData): (WebCore::DragController::dragExited): (WebCore::DragController::performDragOperation): (WebCore::DragController::tryDHTMLDrag): (WebCore::DragController::tryToUpdateDroppedImagePlaceholders): * page/EventHandler.cpp: (WebCore::EventHandler::handleDrag): * page/PagePasteboardContext.h: Added. Add `PagePasteboardContext`, a `PasteboardContext` subclass that contains a `PageIdentifier` indicating which `Page` is requesting pasteboard access. (isType): * platform/DragData.cpp: (WebCore::DragData::DragData): (WebCore::DragData::createPasteboardContext const): Also plumb a `PageIdentifier` through `DragData`, and use it to implement a helper method that returns a context object for `Pasteboard`. * platform/DragData.h: Additionally make `operator=` platform-agnostic, instead of limited to GTK. (It isn't clear why this needs to be limited to the GTK port). (WebCore::DragData::DragData): (WebCore::DragData::pageID const): * platform/Pasteboard.h: Augment `Pasteboard`'s (numerous) platform-specific constructors to take in a `PasteboardContext` unique pointer as well, and store it in `m_context`. (WebCore::Pasteboard::Pasteboard): (WebCore::Pasteboard::context const): * platform/PasteboardContext.h: Added. Add `PasteboardContext`, which provides additional context for an arbitrary pasteboard operation in an opaque fashion. See `PagePasteboardContext` above. (WebCore::PasteboardContext::isPagePasteboardContext const): * platform/StaticPasteboard.cpp: (WebCore::StaticPasteboard::StaticPasteboard): * platform/cocoa/DragDataCocoa.mm: (WebCore::DragData::DragData): (WebCore::DragData::canSmartReplace const): (WebCore::DragData::asPlainText const): * platform/gtk/PasteboardGtk.cpp: (WebCore::Pasteboard::createForCopyAndPaste): (WebCore::Pasteboard::createForGlobalSelection): (WebCore::Pasteboard::createForDragAndDrop): (WebCore::Pasteboard::create): (WebCore::Pasteboard::Pasteboard): * platform/ios/PasteboardIOS.mm: (WebCore::Pasteboard::Pasteboard): (WebCore::Pasteboard::createForDragAndDrop): (WebCore::Pasteboard::create): (WebCore::Pasteboard::createForCopyAndPaste): * platform/libwpe/PasteboardLibWPE.cpp: (WebCore::Pasteboard::createForCopyAndPaste): (WebCore::Pasteboard::Pasteboard): * platform/mac/PasteboardMac.mm: (WebCore::Pasteboard::Pasteboard): (WebCore::Pasteboard::createForCopyAndPaste): (WebCore::Pasteboard::createForDragAndDrop): (WebCore::Pasteboard::create): * platform/win/DragDataWin.cpp: (WebCore::DragData::DragData): * platform/win/PasteboardWin.cpp: (WebCore::Pasteboard::createForCopyAndPaste): (WebCore::Pasteboard::createForDragAndDrop): (WebCore::Pasteboard::create): (WebCore::Pasteboard::Pasteboard): Source/WebKit: Update more `DragData` and `Pasteboard` initialization sites by passing in a `PageIdentifier` or `PasteboardContext`, respectively. See WebCore ChangeLog for more details. * Shared/WebCoreArgumentCoders.cpp: (IPC::ArgumentCoder<DragData>::encode): (IPC::ArgumentCoder<DragData>::decode): * UIProcess/Cocoa/WebViewImpl.mm: (WebKit::WebViewImpl::draggingEntered): (WebKit::WebViewImpl::draggingUpdated): (WebKit::WebViewImpl::draggingExited): * UIProcess/ios/WKContentViewInteraction.mm: (-[WKContentView dragDataForDropSession:dragDestinationAction:]): * WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp: (WebKit::WebEditorClient::updateGlobalSelection): * WebProcess/WebCoreSupport/mac/WebDragClientMac.mm: (WebKit::WebDragClient::declareAndWriteDragImage): * WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::performDragControllerAction): * WebProcess/WebPage/ios/WebPageIOS.mm: (WebKit::WebPage::performActionOnElement): Source/WebKitLegacy/mac: Create and pass in a `PasteboardContext` when creating a `Pasteboard`. See WebCore ChangeLog for more details. * WebCoreSupport/WebDragClient.mm: (WebDragClient::declareAndWriteDragImage): Canonical link: https://commits.webkit.org/234275@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273077 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-18 16:56:42 +00:00
/*
* Copyright (C) 2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include "PageIdentifier.h"
#include "PasteboardContext.h"
#include <wtf/TypeCasts.h>
namespace WebCore {
class PagePasteboardContext final : public PasteboardContext {
WTF_MAKE_FAST_ALLOCATED;
public:
Remove WTF::Optional synonym for std::optional, using that class template directly instead https://bugs.webkit.org/show_bug.cgi?id=226433 Reviewed by Chris Dumez. Source/JavaScriptCore: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. * inspector/scripts/codegen/generate_objc_protocol_types_implementation.py: (ObjCProtocolTypesImplementationGenerator._generate_init_method_for_payload): Use auto instead of Optional<>. Also use * instead of value() and nest the definition of the local inside an if statement in the case where it's an optional. * inspector/scripts/tests/expected/*: Regenerated these results. Source/WebCore: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WebCore/PAL: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WebDriver: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WebKit: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. * Scripts/webkit/tests: Regenerated expected results, by running the command "python Scripts/webkit/messages_unittest.py -r". (How am I supposed to know to do that?) Source/WebKitLegacy/ios: * WebCoreSupport/WebChromeClientIOS.h: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WebKitLegacy/mac: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WebKitLegacy/win: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WTF: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. * wtf/Optional.h: Remove WTF::Optional. Tools: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Canonical link: https://commits.webkit.org/238290@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@278253 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-05-30 16:11:40 +00:00
PagePasteboardContext(std::optional<PageIdentifier>&& pageID = std::nullopt)
Plumb an Optional<PageIdentifier> through Pasteboard-related codepaths https://bugs.webkit.org/show_bug.cgi?id=221987 Reviewed by Tim Horton. Source/WebCore: In order to facilitate tagging pasteboard reads and writes with a data owner type on iOS sourced from `WKContentView`, we add infrastructure to (indirectly) tag `Pasteboard` with an optional `PageIdentifier` to indicate which page is triggering the pasteboard operation. However, since the `Pasteboard` class should only be responsible for interfacing with platform-dependent strategies for reading or writing data, we can't directly add a `PageIdentifier` member to `Pasteboard`. Instead, we introduce a separate `PasteboardContext` object, and let `Pasteboard` hold a unique pointer to this context (which is set during construction). `PasteboardContext` is then subclassed by `PagePasteboardContext`, which holds a `PageIdentifier` and is created from call sites of the `Pasteboard` constructor that have access to page identifiers (e.g. `Editor`, `Clipboard`, `EventHandler`). In a future patch, this opaque `PasteboardContext` will be converted back to a `PagePasteboardContext` in order to retrieve the page identifier in the WebKit client layer. * Headers.cmake: * Modules/async-clipboard/Clipboard.cpp: (WebCore::Clipboard::readText): (WebCore::Clipboard::writeText): (WebCore::Clipboard::read): (WebCore::Clipboard::ItemWriter::ItemWriter): Here (and in many places below), create `PagePasteboardContext` objects and use them to create `Pasteboard`s, passing them in as opaque `PasteboardContext`s. * WebCore.xcodeproj/project.pbxproj: * dom/DataTransfer.cpp: (WebCore::DataTransfer::createForDrag): * dom/DataTransfer.h: * editing/Editor.cpp: (WebCore::createDataTransferForClipboardEvent): (WebCore::dispatchClipboardEvent): (WebCore::Editor::pasteAsPlainTextBypassingDHTML): (WebCore::Editor::performCutOrCopy): (WebCore::Editor::paste): (WebCore::Editor::pasteAsPlainText): (WebCore::Editor::pasteAsQuotation): (WebCore::Editor::copyURL): (WebCore::Editor::copyImage): * editing/EditorCommand.cpp: (WebCore::executePasteGlobalSelection): * editing/mac/EditorMac.mm: (WebCore::Editor::readSelectionFromPasteboard): (WebCore::Editor::replaceNodeFromPasteboard): * inspector/CommandLineAPIHost.cpp: (WebCore::CommandLineAPIHost::copyText): * inspector/InspectorFrontendHost.cpp: (WebCore::InspectorFrontendHost::copyText): * page/DragController.cpp: (WebCore::documentFragmentFromDragData): (WebCore::DragController::dragExited): (WebCore::DragController::performDragOperation): (WebCore::DragController::tryDHTMLDrag): (WebCore::DragController::tryToUpdateDroppedImagePlaceholders): * page/EventHandler.cpp: (WebCore::EventHandler::handleDrag): * page/PagePasteboardContext.h: Added. Add `PagePasteboardContext`, a `PasteboardContext` subclass that contains a `PageIdentifier` indicating which `Page` is requesting pasteboard access. (isType): * platform/DragData.cpp: (WebCore::DragData::DragData): (WebCore::DragData::createPasteboardContext const): Also plumb a `PageIdentifier` through `DragData`, and use it to implement a helper method that returns a context object for `Pasteboard`. * platform/DragData.h: Additionally make `operator=` platform-agnostic, instead of limited to GTK. (It isn't clear why this needs to be limited to the GTK port). (WebCore::DragData::DragData): (WebCore::DragData::pageID const): * platform/Pasteboard.h: Augment `Pasteboard`'s (numerous) platform-specific constructors to take in a `PasteboardContext` unique pointer as well, and store it in `m_context`. (WebCore::Pasteboard::Pasteboard): (WebCore::Pasteboard::context const): * platform/PasteboardContext.h: Added. Add `PasteboardContext`, which provides additional context for an arbitrary pasteboard operation in an opaque fashion. See `PagePasteboardContext` above. (WebCore::PasteboardContext::isPagePasteboardContext const): * platform/StaticPasteboard.cpp: (WebCore::StaticPasteboard::StaticPasteboard): * platform/cocoa/DragDataCocoa.mm: (WebCore::DragData::DragData): (WebCore::DragData::canSmartReplace const): (WebCore::DragData::asPlainText const): * platform/gtk/PasteboardGtk.cpp: (WebCore::Pasteboard::createForCopyAndPaste): (WebCore::Pasteboard::createForGlobalSelection): (WebCore::Pasteboard::createForDragAndDrop): (WebCore::Pasteboard::create): (WebCore::Pasteboard::Pasteboard): * platform/ios/PasteboardIOS.mm: (WebCore::Pasteboard::Pasteboard): (WebCore::Pasteboard::createForDragAndDrop): (WebCore::Pasteboard::create): (WebCore::Pasteboard::createForCopyAndPaste): * platform/libwpe/PasteboardLibWPE.cpp: (WebCore::Pasteboard::createForCopyAndPaste): (WebCore::Pasteboard::Pasteboard): * platform/mac/PasteboardMac.mm: (WebCore::Pasteboard::Pasteboard): (WebCore::Pasteboard::createForCopyAndPaste): (WebCore::Pasteboard::createForDragAndDrop): (WebCore::Pasteboard::create): * platform/win/DragDataWin.cpp: (WebCore::DragData::DragData): * platform/win/PasteboardWin.cpp: (WebCore::Pasteboard::createForCopyAndPaste): (WebCore::Pasteboard::createForDragAndDrop): (WebCore::Pasteboard::create): (WebCore::Pasteboard::Pasteboard): Source/WebKit: Update more `DragData` and `Pasteboard` initialization sites by passing in a `PageIdentifier` or `PasteboardContext`, respectively. See WebCore ChangeLog for more details. * Shared/WebCoreArgumentCoders.cpp: (IPC::ArgumentCoder<DragData>::encode): (IPC::ArgumentCoder<DragData>::decode): * UIProcess/Cocoa/WebViewImpl.mm: (WebKit::WebViewImpl::draggingEntered): (WebKit::WebViewImpl::draggingUpdated): (WebKit::WebViewImpl::draggingExited): * UIProcess/ios/WKContentViewInteraction.mm: (-[WKContentView dragDataForDropSession:dragDestinationAction:]): * WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp: (WebKit::WebEditorClient::updateGlobalSelection): * WebProcess/WebCoreSupport/mac/WebDragClientMac.mm: (WebKit::WebDragClient::declareAndWriteDragImage): * WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::performDragControllerAction): * WebProcess/WebPage/ios/WebPageIOS.mm: (WebKit::WebPage::performActionOnElement): Source/WebKitLegacy/mac: Create and pass in a `PasteboardContext` when creating a `Pasteboard`. See WebCore ChangeLog for more details. * WebCoreSupport/WebDragClient.mm: (WebDragClient::declareAndWriteDragImage): Canonical link: https://commits.webkit.org/234275@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273077 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-18 16:56:42 +00:00
: PasteboardContext()
, m_pageID(WTFMove(pageID))
{
}
~PagePasteboardContext() { }
Remove WTF::Optional synonym for std::optional, using that class template directly instead https://bugs.webkit.org/show_bug.cgi?id=226433 Reviewed by Chris Dumez. Source/JavaScriptCore: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. * inspector/scripts/codegen/generate_objc_protocol_types_implementation.py: (ObjCProtocolTypesImplementationGenerator._generate_init_method_for_payload): Use auto instead of Optional<>. Also use * instead of value() and nest the definition of the local inside an if statement in the case where it's an optional. * inspector/scripts/tests/expected/*: Regenerated these results. Source/WebCore: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WebCore/PAL: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WebDriver: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WebKit: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. * Scripts/webkit/tests: Regenerated expected results, by running the command "python Scripts/webkit/messages_unittest.py -r". (How am I supposed to know to do that?) Source/WebKitLegacy/ios: * WebCoreSupport/WebChromeClientIOS.h: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WebKitLegacy/mac: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WebKitLegacy/win: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WTF: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. * wtf/Optional.h: Remove WTF::Optional. Tools: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Canonical link: https://commits.webkit.org/238290@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@278253 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-05-30 16:11:40 +00:00
static std::unique_ptr<PasteboardContext> create(std::optional<PageIdentifier>&& pageID = std::nullopt)
Plumb an Optional<PageIdentifier> through Pasteboard-related codepaths https://bugs.webkit.org/show_bug.cgi?id=221987 Reviewed by Tim Horton. Source/WebCore: In order to facilitate tagging pasteboard reads and writes with a data owner type on iOS sourced from `WKContentView`, we add infrastructure to (indirectly) tag `Pasteboard` with an optional `PageIdentifier` to indicate which page is triggering the pasteboard operation. However, since the `Pasteboard` class should only be responsible for interfacing with platform-dependent strategies for reading or writing data, we can't directly add a `PageIdentifier` member to `Pasteboard`. Instead, we introduce a separate `PasteboardContext` object, and let `Pasteboard` hold a unique pointer to this context (which is set during construction). `PasteboardContext` is then subclassed by `PagePasteboardContext`, which holds a `PageIdentifier` and is created from call sites of the `Pasteboard` constructor that have access to page identifiers (e.g. `Editor`, `Clipboard`, `EventHandler`). In a future patch, this opaque `PasteboardContext` will be converted back to a `PagePasteboardContext` in order to retrieve the page identifier in the WebKit client layer. * Headers.cmake: * Modules/async-clipboard/Clipboard.cpp: (WebCore::Clipboard::readText): (WebCore::Clipboard::writeText): (WebCore::Clipboard::read): (WebCore::Clipboard::ItemWriter::ItemWriter): Here (and in many places below), create `PagePasteboardContext` objects and use them to create `Pasteboard`s, passing them in as opaque `PasteboardContext`s. * WebCore.xcodeproj/project.pbxproj: * dom/DataTransfer.cpp: (WebCore::DataTransfer::createForDrag): * dom/DataTransfer.h: * editing/Editor.cpp: (WebCore::createDataTransferForClipboardEvent): (WebCore::dispatchClipboardEvent): (WebCore::Editor::pasteAsPlainTextBypassingDHTML): (WebCore::Editor::performCutOrCopy): (WebCore::Editor::paste): (WebCore::Editor::pasteAsPlainText): (WebCore::Editor::pasteAsQuotation): (WebCore::Editor::copyURL): (WebCore::Editor::copyImage): * editing/EditorCommand.cpp: (WebCore::executePasteGlobalSelection): * editing/mac/EditorMac.mm: (WebCore::Editor::readSelectionFromPasteboard): (WebCore::Editor::replaceNodeFromPasteboard): * inspector/CommandLineAPIHost.cpp: (WebCore::CommandLineAPIHost::copyText): * inspector/InspectorFrontendHost.cpp: (WebCore::InspectorFrontendHost::copyText): * page/DragController.cpp: (WebCore::documentFragmentFromDragData): (WebCore::DragController::dragExited): (WebCore::DragController::performDragOperation): (WebCore::DragController::tryDHTMLDrag): (WebCore::DragController::tryToUpdateDroppedImagePlaceholders): * page/EventHandler.cpp: (WebCore::EventHandler::handleDrag): * page/PagePasteboardContext.h: Added. Add `PagePasteboardContext`, a `PasteboardContext` subclass that contains a `PageIdentifier` indicating which `Page` is requesting pasteboard access. (isType): * platform/DragData.cpp: (WebCore::DragData::DragData): (WebCore::DragData::createPasteboardContext const): Also plumb a `PageIdentifier` through `DragData`, and use it to implement a helper method that returns a context object for `Pasteboard`. * platform/DragData.h: Additionally make `operator=` platform-agnostic, instead of limited to GTK. (It isn't clear why this needs to be limited to the GTK port). (WebCore::DragData::DragData): (WebCore::DragData::pageID const): * platform/Pasteboard.h: Augment `Pasteboard`'s (numerous) platform-specific constructors to take in a `PasteboardContext` unique pointer as well, and store it in `m_context`. (WebCore::Pasteboard::Pasteboard): (WebCore::Pasteboard::context const): * platform/PasteboardContext.h: Added. Add `PasteboardContext`, which provides additional context for an arbitrary pasteboard operation in an opaque fashion. See `PagePasteboardContext` above. (WebCore::PasteboardContext::isPagePasteboardContext const): * platform/StaticPasteboard.cpp: (WebCore::StaticPasteboard::StaticPasteboard): * platform/cocoa/DragDataCocoa.mm: (WebCore::DragData::DragData): (WebCore::DragData::canSmartReplace const): (WebCore::DragData::asPlainText const): * platform/gtk/PasteboardGtk.cpp: (WebCore::Pasteboard::createForCopyAndPaste): (WebCore::Pasteboard::createForGlobalSelection): (WebCore::Pasteboard::createForDragAndDrop): (WebCore::Pasteboard::create): (WebCore::Pasteboard::Pasteboard): * platform/ios/PasteboardIOS.mm: (WebCore::Pasteboard::Pasteboard): (WebCore::Pasteboard::createForDragAndDrop): (WebCore::Pasteboard::create): (WebCore::Pasteboard::createForCopyAndPaste): * platform/libwpe/PasteboardLibWPE.cpp: (WebCore::Pasteboard::createForCopyAndPaste): (WebCore::Pasteboard::Pasteboard): * platform/mac/PasteboardMac.mm: (WebCore::Pasteboard::Pasteboard): (WebCore::Pasteboard::createForCopyAndPaste): (WebCore::Pasteboard::createForDragAndDrop): (WebCore::Pasteboard::create): * platform/win/DragDataWin.cpp: (WebCore::DragData::DragData): * platform/win/PasteboardWin.cpp: (WebCore::Pasteboard::createForCopyAndPaste): (WebCore::Pasteboard::createForDragAndDrop): (WebCore::Pasteboard::create): (WebCore::Pasteboard::Pasteboard): Source/WebKit: Update more `DragData` and `Pasteboard` initialization sites by passing in a `PageIdentifier` or `PasteboardContext`, respectively. See WebCore ChangeLog for more details. * Shared/WebCoreArgumentCoders.cpp: (IPC::ArgumentCoder<DragData>::encode): (IPC::ArgumentCoder<DragData>::decode): * UIProcess/Cocoa/WebViewImpl.mm: (WebKit::WebViewImpl::draggingEntered): (WebKit::WebViewImpl::draggingUpdated): (WebKit::WebViewImpl::draggingExited): * UIProcess/ios/WKContentViewInteraction.mm: (-[WKContentView dragDataForDropSession:dragDestinationAction:]): * WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp: (WebKit::WebEditorClient::updateGlobalSelection): * WebProcess/WebCoreSupport/mac/WebDragClientMac.mm: (WebKit::WebDragClient::declareAndWriteDragImage): * WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::performDragControllerAction): * WebProcess/WebPage/ios/WebPageIOS.mm: (WebKit::WebPage::performActionOnElement): Source/WebKitLegacy/mac: Create and pass in a `PasteboardContext` when creating a `Pasteboard`. See WebCore ChangeLog for more details. * WebCoreSupport/WebDragClient.mm: (WebDragClient::declareAndWriteDragImage): Canonical link: https://commits.webkit.org/234275@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273077 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-18 16:56:42 +00:00
{
return makeUnique<PagePasteboardContext>(WTFMove(pageID));
}
Remove WTF::Optional synonym for std::optional, using that class template directly instead https://bugs.webkit.org/show_bug.cgi?id=226433 Reviewed by Chris Dumez. Source/JavaScriptCore: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. * inspector/scripts/codegen/generate_objc_protocol_types_implementation.py: (ObjCProtocolTypesImplementationGenerator._generate_init_method_for_payload): Use auto instead of Optional<>. Also use * instead of value() and nest the definition of the local inside an if statement in the case where it's an optional. * inspector/scripts/tests/expected/*: Regenerated these results. Source/WebCore: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WebCore/PAL: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WebDriver: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WebKit: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. * Scripts/webkit/tests: Regenerated expected results, by running the command "python Scripts/webkit/messages_unittest.py -r". (How am I supposed to know to do that?) Source/WebKitLegacy/ios: * WebCoreSupport/WebChromeClientIOS.h: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WebKitLegacy/mac: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WebKitLegacy/win: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WTF: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. * wtf/Optional.h: Remove WTF::Optional. Tools: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Canonical link: https://commits.webkit.org/238290@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@278253 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-05-30 16:11:40 +00:00
std::optional<PageIdentifier> pageID() const { return m_pageID; }
Plumb an Optional<PageIdentifier> through Pasteboard-related codepaths https://bugs.webkit.org/show_bug.cgi?id=221987 Reviewed by Tim Horton. Source/WebCore: In order to facilitate tagging pasteboard reads and writes with a data owner type on iOS sourced from `WKContentView`, we add infrastructure to (indirectly) tag `Pasteboard` with an optional `PageIdentifier` to indicate which page is triggering the pasteboard operation. However, since the `Pasteboard` class should only be responsible for interfacing with platform-dependent strategies for reading or writing data, we can't directly add a `PageIdentifier` member to `Pasteboard`. Instead, we introduce a separate `PasteboardContext` object, and let `Pasteboard` hold a unique pointer to this context (which is set during construction). `PasteboardContext` is then subclassed by `PagePasteboardContext`, which holds a `PageIdentifier` and is created from call sites of the `Pasteboard` constructor that have access to page identifiers (e.g. `Editor`, `Clipboard`, `EventHandler`). In a future patch, this opaque `PasteboardContext` will be converted back to a `PagePasteboardContext` in order to retrieve the page identifier in the WebKit client layer. * Headers.cmake: * Modules/async-clipboard/Clipboard.cpp: (WebCore::Clipboard::readText): (WebCore::Clipboard::writeText): (WebCore::Clipboard::read): (WebCore::Clipboard::ItemWriter::ItemWriter): Here (and in many places below), create `PagePasteboardContext` objects and use them to create `Pasteboard`s, passing them in as opaque `PasteboardContext`s. * WebCore.xcodeproj/project.pbxproj: * dom/DataTransfer.cpp: (WebCore::DataTransfer::createForDrag): * dom/DataTransfer.h: * editing/Editor.cpp: (WebCore::createDataTransferForClipboardEvent): (WebCore::dispatchClipboardEvent): (WebCore::Editor::pasteAsPlainTextBypassingDHTML): (WebCore::Editor::performCutOrCopy): (WebCore::Editor::paste): (WebCore::Editor::pasteAsPlainText): (WebCore::Editor::pasteAsQuotation): (WebCore::Editor::copyURL): (WebCore::Editor::copyImage): * editing/EditorCommand.cpp: (WebCore::executePasteGlobalSelection): * editing/mac/EditorMac.mm: (WebCore::Editor::readSelectionFromPasteboard): (WebCore::Editor::replaceNodeFromPasteboard): * inspector/CommandLineAPIHost.cpp: (WebCore::CommandLineAPIHost::copyText): * inspector/InspectorFrontendHost.cpp: (WebCore::InspectorFrontendHost::copyText): * page/DragController.cpp: (WebCore::documentFragmentFromDragData): (WebCore::DragController::dragExited): (WebCore::DragController::performDragOperation): (WebCore::DragController::tryDHTMLDrag): (WebCore::DragController::tryToUpdateDroppedImagePlaceholders): * page/EventHandler.cpp: (WebCore::EventHandler::handleDrag): * page/PagePasteboardContext.h: Added. Add `PagePasteboardContext`, a `PasteboardContext` subclass that contains a `PageIdentifier` indicating which `Page` is requesting pasteboard access. (isType): * platform/DragData.cpp: (WebCore::DragData::DragData): (WebCore::DragData::createPasteboardContext const): Also plumb a `PageIdentifier` through `DragData`, and use it to implement a helper method that returns a context object for `Pasteboard`. * platform/DragData.h: Additionally make `operator=` platform-agnostic, instead of limited to GTK. (It isn't clear why this needs to be limited to the GTK port). (WebCore::DragData::DragData): (WebCore::DragData::pageID const): * platform/Pasteboard.h: Augment `Pasteboard`'s (numerous) platform-specific constructors to take in a `PasteboardContext` unique pointer as well, and store it in `m_context`. (WebCore::Pasteboard::Pasteboard): (WebCore::Pasteboard::context const): * platform/PasteboardContext.h: Added. Add `PasteboardContext`, which provides additional context for an arbitrary pasteboard operation in an opaque fashion. See `PagePasteboardContext` above. (WebCore::PasteboardContext::isPagePasteboardContext const): * platform/StaticPasteboard.cpp: (WebCore::StaticPasteboard::StaticPasteboard): * platform/cocoa/DragDataCocoa.mm: (WebCore::DragData::DragData): (WebCore::DragData::canSmartReplace const): (WebCore::DragData::asPlainText const): * platform/gtk/PasteboardGtk.cpp: (WebCore::Pasteboard::createForCopyAndPaste): (WebCore::Pasteboard::createForGlobalSelection): (WebCore::Pasteboard::createForDragAndDrop): (WebCore::Pasteboard::create): (WebCore::Pasteboard::Pasteboard): * platform/ios/PasteboardIOS.mm: (WebCore::Pasteboard::Pasteboard): (WebCore::Pasteboard::createForDragAndDrop): (WebCore::Pasteboard::create): (WebCore::Pasteboard::createForCopyAndPaste): * platform/libwpe/PasteboardLibWPE.cpp: (WebCore::Pasteboard::createForCopyAndPaste): (WebCore::Pasteboard::Pasteboard): * platform/mac/PasteboardMac.mm: (WebCore::Pasteboard::Pasteboard): (WebCore::Pasteboard::createForCopyAndPaste): (WebCore::Pasteboard::createForDragAndDrop): (WebCore::Pasteboard::create): * platform/win/DragDataWin.cpp: (WebCore::DragData::DragData): * platform/win/PasteboardWin.cpp: (WebCore::Pasteboard::createForCopyAndPaste): (WebCore::Pasteboard::createForDragAndDrop): (WebCore::Pasteboard::create): (WebCore::Pasteboard::Pasteboard): Source/WebKit: Update more `DragData` and `Pasteboard` initialization sites by passing in a `PageIdentifier` or `PasteboardContext`, respectively. See WebCore ChangeLog for more details. * Shared/WebCoreArgumentCoders.cpp: (IPC::ArgumentCoder<DragData>::encode): (IPC::ArgumentCoder<DragData>::decode): * UIProcess/Cocoa/WebViewImpl.mm: (WebKit::WebViewImpl::draggingEntered): (WebKit::WebViewImpl::draggingUpdated): (WebKit::WebViewImpl::draggingExited): * UIProcess/ios/WKContentViewInteraction.mm: (-[WKContentView dragDataForDropSession:dragDestinationAction:]): * WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp: (WebKit::WebEditorClient::updateGlobalSelection): * WebProcess/WebCoreSupport/mac/WebDragClientMac.mm: (WebKit::WebDragClient::declareAndWriteDragImage): * WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::performDragControllerAction): * WebProcess/WebPage/ios/WebPageIOS.mm: (WebKit::WebPage::performActionOnElement): Source/WebKitLegacy/mac: Create and pass in a `PasteboardContext` when creating a `Pasteboard`. See WebCore ChangeLog for more details. * WebCoreSupport/WebDragClient.mm: (WebDragClient::declareAndWriteDragImage): Canonical link: https://commits.webkit.org/234275@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273077 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-18 16:56:42 +00:00
bool isPagePasteboardContext() const override { return true; }
private:
Remove WTF::Optional synonym for std::optional, using that class template directly instead https://bugs.webkit.org/show_bug.cgi?id=226433 Reviewed by Chris Dumez. Source/JavaScriptCore: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. * inspector/scripts/codegen/generate_objc_protocol_types_implementation.py: (ObjCProtocolTypesImplementationGenerator._generate_init_method_for_payload): Use auto instead of Optional<>. Also use * instead of value() and nest the definition of the local inside an if statement in the case where it's an optional. * inspector/scripts/tests/expected/*: Regenerated these results. Source/WebCore: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WebCore/PAL: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WebDriver: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WebKit: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. * Scripts/webkit/tests: Regenerated expected results, by running the command "python Scripts/webkit/messages_unittest.py -r". (How am I supposed to know to do that?) Source/WebKitLegacy/ios: * WebCoreSupport/WebChromeClientIOS.h: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WebKitLegacy/mac: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WebKitLegacy/win: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WTF: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. * wtf/Optional.h: Remove WTF::Optional. Tools: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Canonical link: https://commits.webkit.org/238290@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@278253 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-05-30 16:11:40 +00:00
std::optional<PageIdentifier> m_pageID;
Plumb an Optional<PageIdentifier> through Pasteboard-related codepaths https://bugs.webkit.org/show_bug.cgi?id=221987 Reviewed by Tim Horton. Source/WebCore: In order to facilitate tagging pasteboard reads and writes with a data owner type on iOS sourced from `WKContentView`, we add infrastructure to (indirectly) tag `Pasteboard` with an optional `PageIdentifier` to indicate which page is triggering the pasteboard operation. However, since the `Pasteboard` class should only be responsible for interfacing with platform-dependent strategies for reading or writing data, we can't directly add a `PageIdentifier` member to `Pasteboard`. Instead, we introduce a separate `PasteboardContext` object, and let `Pasteboard` hold a unique pointer to this context (which is set during construction). `PasteboardContext` is then subclassed by `PagePasteboardContext`, which holds a `PageIdentifier` and is created from call sites of the `Pasteboard` constructor that have access to page identifiers (e.g. `Editor`, `Clipboard`, `EventHandler`). In a future patch, this opaque `PasteboardContext` will be converted back to a `PagePasteboardContext` in order to retrieve the page identifier in the WebKit client layer. * Headers.cmake: * Modules/async-clipboard/Clipboard.cpp: (WebCore::Clipboard::readText): (WebCore::Clipboard::writeText): (WebCore::Clipboard::read): (WebCore::Clipboard::ItemWriter::ItemWriter): Here (and in many places below), create `PagePasteboardContext` objects and use them to create `Pasteboard`s, passing them in as opaque `PasteboardContext`s. * WebCore.xcodeproj/project.pbxproj: * dom/DataTransfer.cpp: (WebCore::DataTransfer::createForDrag): * dom/DataTransfer.h: * editing/Editor.cpp: (WebCore::createDataTransferForClipboardEvent): (WebCore::dispatchClipboardEvent): (WebCore::Editor::pasteAsPlainTextBypassingDHTML): (WebCore::Editor::performCutOrCopy): (WebCore::Editor::paste): (WebCore::Editor::pasteAsPlainText): (WebCore::Editor::pasteAsQuotation): (WebCore::Editor::copyURL): (WebCore::Editor::copyImage): * editing/EditorCommand.cpp: (WebCore::executePasteGlobalSelection): * editing/mac/EditorMac.mm: (WebCore::Editor::readSelectionFromPasteboard): (WebCore::Editor::replaceNodeFromPasteboard): * inspector/CommandLineAPIHost.cpp: (WebCore::CommandLineAPIHost::copyText): * inspector/InspectorFrontendHost.cpp: (WebCore::InspectorFrontendHost::copyText): * page/DragController.cpp: (WebCore::documentFragmentFromDragData): (WebCore::DragController::dragExited): (WebCore::DragController::performDragOperation): (WebCore::DragController::tryDHTMLDrag): (WebCore::DragController::tryToUpdateDroppedImagePlaceholders): * page/EventHandler.cpp: (WebCore::EventHandler::handleDrag): * page/PagePasteboardContext.h: Added. Add `PagePasteboardContext`, a `PasteboardContext` subclass that contains a `PageIdentifier` indicating which `Page` is requesting pasteboard access. (isType): * platform/DragData.cpp: (WebCore::DragData::DragData): (WebCore::DragData::createPasteboardContext const): Also plumb a `PageIdentifier` through `DragData`, and use it to implement a helper method that returns a context object for `Pasteboard`. * platform/DragData.h: Additionally make `operator=` platform-agnostic, instead of limited to GTK. (It isn't clear why this needs to be limited to the GTK port). (WebCore::DragData::DragData): (WebCore::DragData::pageID const): * platform/Pasteboard.h: Augment `Pasteboard`'s (numerous) platform-specific constructors to take in a `PasteboardContext` unique pointer as well, and store it in `m_context`. (WebCore::Pasteboard::Pasteboard): (WebCore::Pasteboard::context const): * platform/PasteboardContext.h: Added. Add `PasteboardContext`, which provides additional context for an arbitrary pasteboard operation in an opaque fashion. See `PagePasteboardContext` above. (WebCore::PasteboardContext::isPagePasteboardContext const): * platform/StaticPasteboard.cpp: (WebCore::StaticPasteboard::StaticPasteboard): * platform/cocoa/DragDataCocoa.mm: (WebCore::DragData::DragData): (WebCore::DragData::canSmartReplace const): (WebCore::DragData::asPlainText const): * platform/gtk/PasteboardGtk.cpp: (WebCore::Pasteboard::createForCopyAndPaste): (WebCore::Pasteboard::createForGlobalSelection): (WebCore::Pasteboard::createForDragAndDrop): (WebCore::Pasteboard::create): (WebCore::Pasteboard::Pasteboard): * platform/ios/PasteboardIOS.mm: (WebCore::Pasteboard::Pasteboard): (WebCore::Pasteboard::createForDragAndDrop): (WebCore::Pasteboard::create): (WebCore::Pasteboard::createForCopyAndPaste): * platform/libwpe/PasteboardLibWPE.cpp: (WebCore::Pasteboard::createForCopyAndPaste): (WebCore::Pasteboard::Pasteboard): * platform/mac/PasteboardMac.mm: (WebCore::Pasteboard::Pasteboard): (WebCore::Pasteboard::createForCopyAndPaste): (WebCore::Pasteboard::createForDragAndDrop): (WebCore::Pasteboard::create): * platform/win/DragDataWin.cpp: (WebCore::DragData::DragData): * platform/win/PasteboardWin.cpp: (WebCore::Pasteboard::createForCopyAndPaste): (WebCore::Pasteboard::createForDragAndDrop): (WebCore::Pasteboard::create): (WebCore::Pasteboard::Pasteboard): Source/WebKit: Update more `DragData` and `Pasteboard` initialization sites by passing in a `PageIdentifier` or `PasteboardContext`, respectively. See WebCore ChangeLog for more details. * Shared/WebCoreArgumentCoders.cpp: (IPC::ArgumentCoder<DragData>::encode): (IPC::ArgumentCoder<DragData>::decode): * UIProcess/Cocoa/WebViewImpl.mm: (WebKit::WebViewImpl::draggingEntered): (WebKit::WebViewImpl::draggingUpdated): (WebKit::WebViewImpl::draggingExited): * UIProcess/ios/WKContentViewInteraction.mm: (-[WKContentView dragDataForDropSession:dragDestinationAction:]): * WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp: (WebKit::WebEditorClient::updateGlobalSelection): * WebProcess/WebCoreSupport/mac/WebDragClientMac.mm: (WebKit::WebDragClient::declareAndWriteDragImage): * WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::performDragControllerAction): * WebProcess/WebPage/ios/WebPageIOS.mm: (WebKit::WebPage::performActionOnElement): Source/WebKitLegacy/mac: Create and pass in a `PasteboardContext` when creating a `Pasteboard`. See WebCore ChangeLog for more details. * WebCoreSupport/WebDragClient.mm: (WebDragClient::declareAndWriteDragImage): Canonical link: https://commits.webkit.org/234275@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273077 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-18 16:56:42 +00:00
};
} // namespace WebCore
SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::PagePasteboardContext)
static bool isType(const WebCore::PasteboardContext& context) { return context.isPagePasteboardContext(); }
SPECIALIZE_TYPE_TRAITS_END()