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"
11 #include "mozilla/dom/ContentChild.h"
12 #include "mozilla/net/CookieJarSettings.h"
13 #include "nsITransferable.h"
17 NS_IMPL_ISUPPORTS(ClipboardWriteRequestChild
, nsIAsyncSetClipboardData
)
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
);
27 return NS_ERROR_FAILURE
;
30 #if defined(ACCESSIBILITY) && defined(XP_WIN)
31 a11y::Compatibility::SuppressA11yForClipboardCopy();
35 IPCDataTransfer ipcDataTransfer
;
36 nsContentUtils::TransferableToIPCTransferable(aTransferable
, &ipcDataTransfer
,
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());
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
);
66 ipc::IPCResult
ClipboardWriteRequestChild::Recv__delete__(nsresult aResult
) {
67 MaybeNotifyCallback(aResult
);
71 void ClipboardWriteRequestChild::ActorDestroy(ActorDestroyReason aReason
) {
72 MaybeNotifyCallback(NS_ERROR_ABORT
);
75 void ClipboardWriteRequestChild::MaybeNotifyCallback(nsresult aResult
) {
77 if (nsCOMPtr
<nsIAsyncSetClipboardDataCallback
> callback
=
79 callback
->OnComplete(aResult
);
83 } // namespace mozilla