Bug 1861709 replace AudioCallbackDriver::ThreadRunning() assertions that mean to...
[gecko.git] / widget / ClipboardWriteRequestChild.cpp
blob0c42f7380d666f9df891146babf5c5f7c8ac4347
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 IPCTransferable ipcTransferable;
36 nsContentUtils::TransferableToIPCTransferable(aTransferable, &ipcTransferable,
37 false, nullptr);
38 SendSetData(std::move(ipcTransferable));
39 return NS_OK;
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);
53 return NS_OK;
56 ipc::IPCResult ClipboardWriteRequestChild::Recv__delete__(nsresult aResult) {
57 MaybeNotifyCallback(aResult);
58 return IPC_OK();
61 void ClipboardWriteRequestChild::ActorDestroy(ActorDestroyReason aReason) {
62 MaybeNotifyCallback(NS_ERROR_ABORT);
65 void ClipboardWriteRequestChild::MaybeNotifyCallback(nsresult aResult) {
66 mIsValid = false;
67 if (nsCOMPtr<nsIAsyncClipboardRequestCallback> callback =
68 mCallback.forget()) {
69 callback->OnComplete(aResult);
73 } // namespace mozilla