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"
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) {}
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
);
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
,
52 return nsContentUtils::IPCTransferableToTransferable(
53 dataTransfer
, false /* aAddDataFlavor */, aTransferable
,
54 ContentChild::GetSingleton());
58 nsClipboardProxy::EmptyClipboard(int32_t aWhichClipboard
) {
59 ContentChild::GetSingleton()->SendEmptyClipboard(aWhichClipboard
);
64 nsClipboardProxy::HasDataMatchingFlavors(const nsTArray
<nsCString
>& aFlavorList
,
65 int32_t aWhichClipboard
,
69 ContentChild::GetSingleton()->SendClipboardHasType(aFlavorList
,
70 aWhichClipboard
, aHasType
);
76 nsClipboardProxy::SupportsSelectionClipboard(bool* aIsSupported
) {
77 *aIsSupported
= mClipboardCaps
.supportsSelectionClipboard();
82 nsClipboardProxy::SupportsFindClipboard(bool* aIsSupported
) {
83 *aIsSupported
= mClipboardCaps
.supportsFindClipboard();
87 void nsClipboardProxy::SetCapabilities(
88 const ClipboardCapabilities
& aClipboardCaps
) {
89 mClipboardCaps
= aClipboardCaps
;