summaryrefslogtreecommitdiffstats
path: root/widget/ClipboardWriteRequestParent.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:44:51 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:44:51 +0000
commit9e3c08db40b8916968b9f30096c7be3f00ce9647 (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /widget/ClipboardWriteRequestParent.cpp
parentInitial commit. (diff)
downloadthunderbird-9e3c08db40b8916968b9f30096c7be3f00ce9647.tar.xz
thunderbird-9e3c08db40b8916968b9f30096c7be3f00ce9647.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 'widget/ClipboardWriteRequestParent.cpp')
-rw-r--r--widget/ClipboardWriteRequestParent.cpp109
1 files changed, 109 insertions, 0 deletions
diff --git a/widget/ClipboardWriteRequestParent.cpp b/widget/ClipboardWriteRequestParent.cpp
new file mode 100644
index 0000000000..c7d99c61ce
--- /dev/null
+++ b/widget/ClipboardWriteRequestParent.cpp
@@ -0,0 +1,109 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 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 "mozilla/ClipboardWriteRequestParent.h"
+
+#include "mozilla/dom/ContentParent.h"
+#include "mozilla/net/CookieJarSettings.h"
+#include "nsComponentManagerUtils.h"
+#include "nsIClipboard.h"
+#include "nsITransferable.h"
+#include "nsWidgetsCID.h"
+
+static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID);
+
+using mozilla::dom::ContentParent;
+using mozilla::ipc::IPCResult;
+
+namespace mozilla {
+
+NS_IMPL_ISUPPORTS(ClipboardWriteRequestParent, nsIAsyncSetClipboardDataCallback)
+
+ClipboardWriteRequestParent::ClipboardWriteRequestParent(
+ ContentParent* aManager)
+ : mManager(aManager) {}
+
+ClipboardWriteRequestParent::~ClipboardWriteRequestParent() = default;
+
+nsresult ClipboardWriteRequestParent::Init(const int32_t& aClipboardType) {
+ nsCOMPtr<nsIClipboard> clipboard(do_GetService(kCClipboardCID));
+ if (!clipboard) {
+ Unused << PClipboardWriteRequestParent::Send__delete__(this,
+ NS_ERROR_FAILURE);
+ return NS_ERROR_FAILURE;
+ }
+
+ nsresult rv = clipboard->AsyncSetData(aClipboardType, this,
+ getter_AddRefs(mAsyncSetClipboardData));
+ if (NS_FAILED(rv)) {
+ Unused << PClipboardWriteRequestParent::Send__delete__(this, rv);
+ return rv;
+ }
+
+ return NS_OK;
+}
+
+NS_IMETHODIMP ClipboardWriteRequestParent::OnComplete(nsresult aResult) {
+ nsCOMPtr<nsIAsyncSetClipboardData> clipboardData =
+ std::move(mAsyncSetClipboardData);
+ if (clipboardData) {
+ Unused << PClipboardWriteRequestParent::Send__delete__(this, aResult);
+ }
+ return NS_OK;
+}
+
+IPCResult ClipboardWriteRequestParent::RecvSetData(
+ const IPCTransferable& aTransferable) {
+ if (!mManager->ValidatePrincipal(
+ aTransferable.requestingPrincipal(),
+ {ContentParent::ValidatePrincipalOptions::AllowNullPtr})) {
+ ContentParent::LogAndAssertFailedPrincipalValidationInfo(
+ aTransferable.requestingPrincipal(), __func__);
+ }
+
+ if (!mAsyncSetClipboardData) {
+ return IPC_OK();
+ }
+
+ nsresult rv = NS_ERROR_FAILURE;
+ nsCOMPtr<nsITransferable> trans =
+ do_CreateInstance("@mozilla.org/widget/transferable;1", &rv);
+ if (NS_FAILED(rv)) {
+ mAsyncSetClipboardData->Abort(rv);
+ return IPC_OK();
+ }
+
+ trans->Init(nullptr);
+ rv = nsContentUtils::IPCTransferableToTransferable(
+ aTransferable, true /* aAddDataFlavor */, trans,
+ true /* aFilterUnknownFlavors */);
+ if (NS_FAILED(rv)) {
+ mAsyncSetClipboardData->Abort(rv);
+ return IPC_OK();
+ }
+
+ mAsyncSetClipboardData->SetData(trans, nullptr);
+ return IPC_OK();
+}
+
+IPCResult ClipboardWriteRequestParent::Recv__delete__(nsresult aReason) {
+ MOZ_DIAGNOSTIC_ASSERT(NS_FAILED(aReason));
+ nsCOMPtr<nsIAsyncSetClipboardData> clipboardData =
+ std::move(mAsyncSetClipboardData);
+ if (clipboardData) {
+ clipboardData->Abort(aReason);
+ }
+ return IPC_OK();
+}
+
+void ClipboardWriteRequestParent::ActorDestroy(ActorDestroyReason aReason) {
+ nsCOMPtr<nsIAsyncSetClipboardData> clipboardData =
+ std::move(mAsyncSetClipboardData);
+ if (clipboardData) {
+ clipboardData->Abort(NS_ERROR_ABORT);
+ }
+}
+
+} // namespace mozilla