Bug 1831086 - Patch winsock2.h usage in nICEr to include missing types r=RyanVM
[gecko.git] / widget / ClipboardWriteRequestChild.cpp
blob6c60ca26d48e9a1b98e3389d245584ae5923d595
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "mozilla/ClipboardWriteRequestChild.h"
8 #if defined(ACCESSIBILITY) && defined(XP_WIN)
9 # include "mozilla/a11y/Compatibility.h"
10 #endif
11 #include "mozilla/dom/ContentChild.h"
12 #include "mozilla/net/CookieJarSettings.h"
13 #include "nsITransferable.h"
15 namespace mozilla {
17 NS_IMPL_ISUPPORTS(ClipboardWriteRequestChild, nsIAsyncSetClipboardData)
19 NS_IMETHODIMP
20 ClipboardWriteRequestChild::SetData(nsITransferable* aTransferable,
21 nsIClipboardOwner* aOwner) {
22 MOZ_ASSERT(aTransferable);
23 // Callback should be notified if actor is destroyed.
24 MOZ_ASSERT_IF(!CanSend(), !mIsValid && !mCallback);
26 if (!mIsValid) {
27 return NS_ERROR_FAILURE;
30 #if defined(ACCESSIBILITY) && defined(XP_WIN)
31 a11y::Compatibility::SuppressA11yForClipboardCopy();
32 #endif
34 mIsValid = false;
35 IPCDataTransfer ipcDataTransfer;
36 nsContentUtils::TransferableToIPCTransferable(aTransferable, &ipcDataTransfer,
37 false, nullptr);
38 Maybe<net::CookieJarSettingsArgs> cookieJarSettingsArgs;
39 if (nsCOMPtr<nsICookieJarSettings> cookieJarSettings =
40 aTransferable->GetCookieJarSettings()) {
41 net::CookieJarSettingsArgs args;
42 net::CookieJarSettings::Cast(cookieJarSettings)->Serialize(args);
43 cookieJarSettingsArgs = Some(std::move(args));
45 SendSetData(std::move(ipcDataTransfer), aTransferable->GetIsPrivateData(),
46 aTransferable->GetRequestingPrincipal(), cookieJarSettingsArgs,
47 aTransferable->GetContentPolicyType(),
48 aTransferable->GetReferrerInfo());
49 return NS_OK;
52 NS_IMETHODIMP ClipboardWriteRequestChild::Abort(nsresult aReason) {
53 // Callback should be notified if actor is destroyed.
54 MOZ_ASSERT_IF(!CanSend(), !mIsValid && !mCallback);
56 if (!mIsValid || !NS_FAILED(aReason)) {
57 return NS_ERROR_FAILURE;
60 // Need to notify callback first to propagate reason properly.
61 MaybeNotifyCallback(aReason);
62 Unused << PClipboardWriteRequestChild::Send__delete__(this, aReason);
63 return NS_OK;
66 ipc::IPCResult ClipboardWriteRequestChild::Recv__delete__(nsresult aResult) {
67 MaybeNotifyCallback(aResult);
68 return IPC_OK();
71 void ClipboardWriteRequestChild::ActorDestroy(ActorDestroyReason aReason) {
72 MaybeNotifyCallback(NS_ERROR_ABORT);
75 void ClipboardWriteRequestChild::MaybeNotifyCallback(nsresult aResult) {
76 mIsValid = false;
77 if (nsCOMPtr<nsIAsyncSetClipboardDataCallback> callback =
78 mCallback.forget()) {
79 callback->OnComplete(aResult);
83 } // namespace mozilla