summaryrefslogtreecommitdiffstats
path: root/dom/base/nsCopySupport.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:14:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:14:29 +0000
commitfbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8 (patch)
tree4c1ccaf5486d4f2009f9a338a98a83e886e29c97 /dom/base/nsCopySupport.cpp
parentReleasing progress-linux version 124.0.1-1~progress7.99u1. (diff)
downloadfirefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.tar.xz
firefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.zip
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/base/nsCopySupport.cpp')
-rw-r--r--dom/base/nsCopySupport.cpp42
1 files changed, 38 insertions, 4 deletions
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<nsGlobalWindowInner> 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<nsPresContext> presContext = presShell->GetPresContext();
- EventDispatcher::Dispatch(targetElement, presContext, &evt, nullptr,
- &status);
+ {
+ AutoHandlingPasteEvent autoHandlingPasteEvent(
+ nsGlobalWindowInner::Cast(doc->GetInnerWindow()), clipboardData,
+ aEventMessage, aClipboardType);
+
+ RefPtr<nsPresContext> 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);
}