From 40a355a42d4a9444dc753c04c6608dade2f06a23 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:13:27 +0200 Subject: Adding upstream version 125.0.1. Signed-off-by: Daniel Baumann --- dom/base/nsCopySupport.cpp | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) (limited to 'dom/base/nsCopySupport.cpp') diff --git a/dom/base/nsCopySupport.cpp b/dom/base/nsCopySupport.cpp index 4dc183d664..15c0cf4cf0 100644 --- a/dom/base/nsCopySupport.cpp +++ b/dom/base/nsCopySupport.cpp @@ -5,6 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "nsCopySupport.h" +#include "nsGlobalWindowInner.h" #include "nsIDocumentEncoder.h" #include "nsISupports.h" #include "nsIContent.h" @@ -38,7 +39,6 @@ #include "nsIImageLoadingContent.h" #include "nsIInterfaceRequestorUtils.h" #include "nsContentUtils.h" -#include "nsContentCID.h" #ifdef XP_WIN # include "mozilla/StaticPrefs_clipboard.h" @@ -714,6 +714,33 @@ static Element* GetElementOrNearestFlattenedTreeParentElement(nsINode* aNode) { return nullptr; } +/** + * This class is used while processing clipboard paste event. + */ +class MOZ_RAII AutoHandlingPasteEvent final { + public: + explicit AutoHandlingPasteEvent(nsGlobalWindowInner* aWindow, + DataTransfer* aDataTransfer, + const EventMessage& aEventMessage, + const int32_t& aClipboardType) { + MOZ_ASSERT(aDataTransfer); + if (aWindow && aEventMessage == ePaste && + aClipboardType == nsIClipboard::kGlobalClipboard) { + aWindow->SetCurrentPasteDataTransfer(aDataTransfer); + mInnerWindow = aWindow; + } + } + + ~AutoHandlingPasteEvent() { + if (mInnerWindow) { + mInnerWindow->SetCurrentPasteDataTransfer(nullptr); + } + } + + private: + RefPtr mInnerWindow; +}; + bool nsCopySupport::FireClipboardEvent(EventMessage aEventMessage, int32_t aClipboardType, PresShell* aPresShell, @@ -791,9 +818,16 @@ bool nsCopySupport::FireClipboardEvent(EventMessage aEventMessage, InternalClipboardEvent evt(true, originalEventMessage); evt.mClipboardData = clipboardData; - RefPtr presContext = presShell->GetPresContext(); - EventDispatcher::Dispatch(targetElement, presContext, &evt, nullptr, - &status); + { + AutoHandlingPasteEvent autoHandlingPasteEvent( + nsGlobalWindowInner::Cast(doc->GetInnerWindow()), clipboardData, + aEventMessage, aClipboardType); + + RefPtr presContext = presShell->GetPresContext(); + EventDispatcher::Dispatch(targetElement, presContext, &evt, nullptr, + &status); + } + // If the event was cancelled, don't do the clipboard operation doDefault = (status != nsEventStatus_eConsumeNoDefault); } -- cgit v1.2.3