Bumping manifests a=b2g-bump
[gecko.git] / widget / nsClipboardProxy.cpp
blob30c08d94c98449c09041456a0b93ada469d7b318
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"
8 #include "nsCOMPtr.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)
22 NS_IMETHODIMP
23 nsClipboardProxy::SetData(nsITransferable *aTransferable,
24 nsIClipboardOwner *anOwner, int32_t aWhichClipboard)
26 nsCOMPtr<nsISupports> tmp;
27 uint32_t len;
28 nsresult rv = aTransferable->GetTransferData(kUnicodeMime, getter_AddRefs(tmp),
29 &len);
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);
34 nsAutoString buffer;
35 supportsString->GetData(buffer);
37 bool isPrivateData = false;
38 aTransferable->GetIsPrivateData(&isPrivateData);
39 ContentChild::GetSingleton()->SendSetClipboardText(buffer, isPrivateData,
40 aWhichClipboard);
42 return NS_OK;
45 NS_IMETHODIMP
46 nsClipboardProxy::GetData(nsITransferable *aTransferable, int32_t aWhichClipboard)
48 nsAutoString buffer;
49 ContentChild::GetSingleton()->SendGetClipboardText(aWhichClipboard, &buffer);
51 nsresult rv;
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);
68 return NS_OK;
71 NS_IMETHODIMP
72 nsClipboardProxy::EmptyClipboard(int32_t aWhichClipboard)
74 ContentChild::GetSingleton()->SendEmptyClipboard(aWhichClipboard);
75 return NS_OK;
78 NS_IMETHODIMP
79 nsClipboardProxy::HasDataMatchingFlavors(const char **aFlavorList,
80 uint32_t aLength, int32_t aWhichClipboard,
81 bool *aHasText)
83 *aHasText = false;
84 ContentChild::GetSingleton()->SendClipboardHasText(aWhichClipboard, aHasText);
85 return NS_OK;
88 NS_IMETHODIMP
89 nsClipboardProxy::SupportsSelectionClipboard(bool *aIsSupported)
91 *aIsSupported = mClipboardCaps.supportsSelectionClipboard();
92 return NS_OK;
96 NS_IMETHODIMP
97 nsClipboardProxy::SupportsFindClipboard(bool *aIsSupported)
99 *aIsSupported = mClipboardCaps.supportsFindClipboard();
100 return NS_OK;
103 void
104 nsClipboardProxy::SetCapabilities(const ClipboardCapabilities& aClipboardCaps)
106 mClipboardCaps = aClipboardCaps;