summaryrefslogtreecommitdiffstats
path: root/dom/events/RemoteDragStartData.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /dom/events/RemoteDragStartData.cpp
parentInitial commit. (diff)
downloadthunderbird-upstream.tar.xz
thunderbird-upstream.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/events/RemoteDragStartData.cpp')
-rw-r--r--dom/events/RemoteDragStartData.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/dom/events/RemoteDragStartData.cpp b/dom/events/RemoteDragStartData.cpp
new file mode 100644
index 0000000000..69d7692bf8
--- /dev/null
+++ b/dom/events/RemoteDragStartData.cpp
@@ -0,0 +1,83 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "nsContentAreaDragDrop.h"
+#include "RemoteDragStartData.h"
+#include "nsContentUtils.h"
+#include "nsICookieJarSettings.h"
+#include "nsVariant.h"
+#include "mozilla/dom/BlobImpl.h"
+#include "mozilla/dom/BrowserParent.h"
+#include "mozilla/dom/IPCBlobUtils.h"
+#include "mozilla/dom/DOMTypes.h"
+#include "mozilla/ipc/ProtocolUtils.h"
+
+using namespace mozilla::ipc;
+
+namespace mozilla::dom {
+
+RemoteDragStartData::~RemoteDragStartData() = default;
+
+RemoteDragStartData::RemoteDragStartData(
+ BrowserParent* aBrowserParent,
+ nsTArray<IPCTransferableData>&& aTransferableData,
+ const LayoutDeviceIntRect& aRect, nsIPrincipal* aPrincipal,
+ nsIContentSecurityPolicy* aCsp, nsICookieJarSettings* aCookieJarSettings,
+ WindowContext* aSourceWindowContext, WindowContext* aSourceTopWindowContext)
+ : mBrowserParent(aBrowserParent),
+ mTransferableData(std::move(aTransferableData)),
+ mRect(aRect),
+ mPrincipal(aPrincipal),
+ mCsp(aCsp),
+ mCookieJarSettings(aCookieJarSettings),
+ mSourceWindowContext(aSourceWindowContext),
+ mSourceTopWindowContext(aSourceTopWindowContext) {}
+
+void RemoteDragStartData::AddInitialDnDDataTo(
+ DataTransfer* aDataTransfer, nsIPrincipal** aPrincipal,
+ nsIContentSecurityPolicy** aCsp,
+ nsICookieJarSettings** aCookieJarSettings) {
+ NS_IF_ADDREF(*aPrincipal = mPrincipal);
+ NS_IF_ADDREF(*aCsp = mCsp);
+ NS_IF_ADDREF(*aCookieJarSettings = mCookieJarSettings);
+
+ for (uint32_t i = 0; i < mTransferableData.Length(); ++i) {
+ nsTArray<IPCTransferableDataItem>& itemArray = mTransferableData[i].items();
+ for (auto& item : itemArray) {
+ if (!nsContentUtils::IPCTransferableDataItemHasKnownFlavor(item)) {
+ NS_WARNING(
+ "Ignoring unknown flavor in "
+ "RemoteDragStartData::AddInitialDnDDataTo");
+ continue;
+ }
+
+ RefPtr<nsVariantCC> variant = new nsVariantCC();
+ // Special case kFilePromiseMime so that we get the right
+ // nsIFlavorDataProvider for it.
+ if (item.flavor().EqualsLiteral(kFilePromiseMime)) {
+ RefPtr<nsISupports> flavorDataProvider =
+ new nsContentAreaDragDropDataProvider();
+ variant->SetAsISupports(flavorDataProvider);
+ } else {
+ nsresult rv =
+ nsContentUtils::IPCTransferableDataItemToVariant(item, variant);
+ if (NS_FAILED(rv)) {
+ continue;
+ }
+ }
+
+ // We set aHidden to false, as we don't need to worry about hiding data
+ // from content in the parent process where there is no content.
+ aDataTransfer->SetDataWithPrincipalFromOtherProcess(
+ NS_ConvertUTF8toUTF16(item.flavor()), variant, i, mPrincipal,
+ /* aHidden = */ false);
+ }
+ }
+
+ // Clear things that are no longer needed.
+ mTransferableData.Clear();
+ mPrincipal = nullptr;
+}
+
+} // namespace mozilla::dom