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 "nsClipboardProxy.h"
7 #include "nsISupportsPrimitives.h"
9 #include "nsComponentManagerUtils.h"
10 #include "nsXULAppAPI.h"
12 using namespace mozilla
;
13 using namespace mozilla::dom
;
15 NS_IMPL_ISUPPORTS(nsClipboardProxy
, nsIClipboard
, nsIClipboardProxy
)
17 nsClipboardProxy::nsClipboardProxy()
18 : mClipboardCaps(false, false)
23 nsClipboardProxy::SetData(nsITransferable
*aTransferable
,
24 nsIClipboardOwner
*anOwner
, int32_t aWhichClipboard
)
26 nsCOMPtr
<nsISupports
> tmp
;
28 nsresult rv
= aTransferable
->GetTransferData(kUnicodeMime
, getter_AddRefs(tmp
),
30 NS_ENSURE_SUCCESS(rv
, rv
);
31 nsCOMPtr
<nsISupportsString
> supportsString
= do_QueryInterface(tmp
);
32 // No support for non-text data
33 NS_ENSURE_TRUE(supportsString
, NS_ERROR_NOT_IMPLEMENTED
);
35 supportsString
->GetData(buffer
);
37 bool isPrivateData
= false;
38 aTransferable
->GetIsPrivateData(&isPrivateData
);
39 ContentChild::GetSingleton()->SendSetClipboardText(buffer
, isPrivateData
,
46 nsClipboardProxy::GetData(nsITransferable
*aTransferable
, int32_t aWhichClipboard
)
49 ContentChild::GetSingleton()->SendGetClipboardText(aWhichClipboard
, &buffer
);
52 nsCOMPtr
<nsISupportsString
> dataWrapper
=
53 do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID
, &rv
);
54 NS_ENSURE_SUCCESS(rv
, rv
);
56 rv
= dataWrapper
->SetData(buffer
);
57 NS_ENSURE_SUCCESS(rv
, rv
);
59 // If our data flavor has already been added, this will fail. But we don't care
60 aTransferable
->AddDataFlavor(kUnicodeMime
);
62 nsCOMPtr
<nsISupports
> nsisupportsDataWrapper
=
63 do_QueryInterface(dataWrapper
);
64 rv
= aTransferable
->SetTransferData(kUnicodeMime
, nsisupportsDataWrapper
,
65 buffer
.Length() * sizeof(char16_t
));
66 NS_ENSURE_SUCCESS(rv
, rv
);
72 nsClipboardProxy::EmptyClipboard(int32_t aWhichClipboard
)
74 ContentChild::GetSingleton()->SendEmptyClipboard(aWhichClipboard
);
79 nsClipboardProxy::HasDataMatchingFlavors(const char **aFlavorList
,
80 uint32_t aLength
, int32_t aWhichClipboard
,
84 ContentChild::GetSingleton()->SendClipboardHasText(aWhichClipboard
, aHasText
);
89 nsClipboardProxy::SupportsSelectionClipboard(bool *aIsSupported
)
91 *aIsSupported
= mClipboardCaps
.supportsSelectionClipboard();
97 nsClipboardProxy::SupportsFindClipboard(bool *aIsSupported
)
99 *aIsSupported
= mClipboardCaps
.supportsFindClipboard();
104 nsClipboardProxy::SetCapabilities(const ClipboardCapabilities
& aClipboardCaps
)
106 mClipboardCaps
= aClipboardCaps
;