Bug 1770047 [wpt PR 34117] - Update wpt metadata, a=testonly
[gecko.git] / widget / nsClipboardProxy.cpp
blobc375ac8e57a0a0551afcdcfa300bc3c2b76b515d
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "mozilla/dom/ContentChild.h"
6 #include "mozilla/Unused.h"
7 #include "nsArrayUtils.h"
8 #include "nsClipboardProxy.h"
9 #include "nsISupportsPrimitives.h"
10 #include "nsCOMPtr.h"
11 #include "nsComponentManagerUtils.h"
12 #include "nsXULAppAPI.h"
13 #include "nsContentUtils.h"
14 #include "PermissionMessageUtils.h"
16 using namespace mozilla;
17 using namespace mozilla::dom;
19 NS_IMPL_ISUPPORTS(nsClipboardProxy, nsIClipboard, nsIClipboardProxy)
21 nsClipboardProxy::nsClipboardProxy() : mClipboardCaps(false, false) {}
23 NS_IMETHODIMP
24 nsClipboardProxy::SetData(nsITransferable* aTransferable,
25 nsIClipboardOwner* anOwner, int32_t aWhichClipboard) {
26 ContentChild* child = ContentChild::GetSingleton();
28 IPCDataTransfer ipcDataTransfer;
29 nsContentUtils::TransferableToIPCTransferable(aTransferable, &ipcDataTransfer,
30 false, child, nullptr);
32 bool isPrivateData = aTransferable->GetIsPrivateData();
33 nsCOMPtr<nsIPrincipal> requestingPrincipal =
34 aTransferable->GetRequestingPrincipal();
35 nsContentPolicyType contentPolicyType = aTransferable->GetContentPolicyType();
36 child->SendSetClipboard(ipcDataTransfer, isPrivateData,
37 IPC::Principal(requestingPrincipal),
38 contentPolicyType, aWhichClipboard);
40 return NS_OK;
43 NS_IMETHODIMP
44 nsClipboardProxy::GetData(nsITransferable* aTransferable,
45 int32_t aWhichClipboard) {
46 nsTArray<nsCString> types;
47 aTransferable->FlavorsTransferableCanImport(types);
49 IPCDataTransfer dataTransfer;
50 ContentChild::GetSingleton()->SendGetClipboard(types, aWhichClipboard,
51 &dataTransfer);
52 return nsContentUtils::IPCTransferableToTransferable(
53 dataTransfer, false /* aAddDataFlavor */, aTransferable,
54 ContentChild::GetSingleton());
57 NS_IMETHODIMP
58 nsClipboardProxy::EmptyClipboard(int32_t aWhichClipboard) {
59 ContentChild::GetSingleton()->SendEmptyClipboard(aWhichClipboard);
60 return NS_OK;
63 NS_IMETHODIMP
64 nsClipboardProxy::HasDataMatchingFlavors(const nsTArray<nsCString>& aFlavorList,
65 int32_t aWhichClipboard,
66 bool* aHasType) {
67 *aHasType = false;
69 ContentChild::GetSingleton()->SendClipboardHasType(aFlavorList,
70 aWhichClipboard, aHasType);
72 return NS_OK;
75 NS_IMETHODIMP
76 nsClipboardProxy::SupportsSelectionClipboard(bool* aIsSupported) {
77 *aIsSupported = mClipboardCaps.supportsSelectionClipboard();
78 return NS_OK;
81 NS_IMETHODIMP
82 nsClipboardProxy::SupportsFindClipboard(bool* aIsSupported) {
83 *aIsSupported = mClipboardCaps.supportsFindClipboard();
84 return NS_OK;
87 void nsClipboardProxy::SetCapabilities(
88 const ClipboardCapabilities& aClipboardCaps) {
89 mClipboardCaps = aClipboardCaps;