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 IPCTransferable ipcTransferable
;
36 nsContentUtils::TransferableToIPCTransferable(aTransferable
, &ipcTransferable
,
38 SendSetData(std::move(ipcTransferable
));
42 NS_IMETHODIMP
ClipboardWriteRequestChild::Abort(nsresult aReason
) {
43 // Callback should be notified if actor is destroyed.
44 MOZ_ASSERT_IF(!CanSend(), !mIsValid
&& !mCallback
);
46 if (!mIsValid
|| !NS_FAILED(aReason
)) {
47 return NS_ERROR_FAILURE
;
50 // Need to notify callback first to propagate reason properly.
51 MaybeNotifyCallback(aReason
);
52 Unused
<< PClipboardWriteRequestChild::Send__delete__(this, aReason
);
56 ipc::IPCResult
ClipboardWriteRequestChild::Recv__delete__(nsresult aResult
) {
57 MaybeNotifyCallback(aResult
);
61 void ClipboardWriteRequestChild::ActorDestroy(ActorDestroyReason aReason
) {
62 MaybeNotifyCallback(NS_ERROR_ABORT
);
65 void ClipboardWriteRequestChild::MaybeNotifyCallback(nsresult aResult
) {
67 if (nsCOMPtr
<nsIAsyncClipboardRequestCallback
> callback
=
69 callback
->OnComplete(aResult
);
73 } // namespace mozilla