Bumping manifests a=b2g-bump
[gecko.git] / widget / gonk / nsClipboard.cpp
blobaed3782daa212f40252dc900d5c876f494474639
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 "nsClipboard.h"
7 #include "nsISupportsPrimitives.h"
8 #include "nsCOMPtr.h"
9 #include "nsComponentManagerUtils.h"
10 #include "nsXULAppAPI.h"
12 using namespace mozilla;
13 using mozilla::dom::ContentChild;
15 #define LOG_TAG "Clipboard"
16 #define LOGI(args...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, ## args)
17 #define LOGE(args...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, ## args)
19 NS_IMPL_ISUPPORTS(nsClipboard, nsIClipboard)
21 nsClipboard::nsClipboard()
25 NS_IMETHODIMP
26 nsClipboard::SetData(nsITransferable *aTransferable,
27 nsIClipboardOwner *anOwner, int32_t aWhichClipboard)
29 if (aWhichClipboard != kGlobalClipboard) {
30 return NS_ERROR_NOT_IMPLEMENTED;
33 nsCOMPtr<nsISupports> tmp;
34 uint32_t len;
35 nsresult rv = aTransferable->GetTransferData(kUnicodeMime, getter_AddRefs(tmp),
36 &len);
37 if (NS_WARN_IF(NS_FAILED(rv))) {
38 return rv;
40 nsCOMPtr<nsISupportsString> supportsString = do_QueryInterface(tmp);
41 // No support for non-text data
42 if (NS_WARN_IF(!supportsString)) {
43 LOGE("No support for non-text data. See bug 952456.");
44 return NS_ERROR_NOT_IMPLEMENTED;
46 nsAutoString buffer;
47 supportsString->GetData(buffer);
49 if (XRE_GetProcessType() == GeckoProcessType_Default) {
50 mClipboard = buffer;
51 } else {
52 bool isPrivateData = false;
53 aTransferable->GetIsPrivateData(&isPrivateData);
54 ContentChild::GetSingleton()->SendSetClipboardText(buffer, isPrivateData,
55 aWhichClipboard);
58 return NS_OK;
61 NS_IMETHODIMP
62 nsClipboard::GetData(nsITransferable *aTransferable, int32_t aWhichClipboard)
64 if (aWhichClipboard != kGlobalClipboard) {
65 return NS_ERROR_NOT_IMPLEMENTED;
68 nsAutoString buffer;
69 if (XRE_GetProcessType() == GeckoProcessType_Default) {
70 buffer = mClipboard;
71 } else {
72 ContentChild::GetSingleton()->SendGetClipboardText(aWhichClipboard, &buffer);
75 nsresult rv;
76 nsCOMPtr<nsISupportsString> dataWrapper =
77 do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv);
78 if (NS_WARN_IF(NS_FAILED(rv))) {
79 return rv;
82 rv = dataWrapper->SetData(buffer);
83 if (NS_WARN_IF(NS_FAILED(rv))) {
84 return rv;
87 // If our data flavor has already been added, this will fail. But we don't care
88 aTransferable->AddDataFlavor(kUnicodeMime);
90 nsCOMPtr<nsISupports> nsisupportsDataWrapper =
91 do_QueryInterface(dataWrapper);
92 rv = aTransferable->SetTransferData(kUnicodeMime, nsisupportsDataWrapper,
93 buffer.Length() * sizeof(PRUnichar));
94 if (NS_WARN_IF(NS_FAILED(rv))) {
95 return rv;
98 return NS_OK;
101 NS_IMETHODIMP
102 nsClipboard::EmptyClipboard(int32_t aWhichClipboard)
104 if (aWhichClipboard != kGlobalClipboard) {
105 return NS_ERROR_NOT_IMPLEMENTED;
107 if (XRE_GetProcessType() == GeckoProcessType_Default) {
108 mClipboard.Truncate(0);
109 } else {
110 ContentChild::GetSingleton()->SendEmptyClipboard(aWhichClipboard);
113 return NS_OK;
116 NS_IMETHODIMP
117 nsClipboard::HasDataMatchingFlavors(const char **aFlavorList,
118 uint32_t aLength, int32_t aWhichClipboard,
119 bool *aHasText)
121 *aHasText = false;
122 if (aWhichClipboard != kGlobalClipboard) {
123 return NS_ERROR_NOT_IMPLEMENTED;
125 if (XRE_GetProcessType() == GeckoProcessType_Default) {
126 *aHasText = !mClipboard.IsEmpty();
127 } else {
128 ContentChild::GetSingleton()->SendClipboardHasText(aWhichClipboard, aHasText);
130 return NS_OK;
133 NS_IMETHODIMP
134 nsClipboard::SupportsSelectionClipboard(bool *aIsSupported)
136 *aIsSupported = false;
137 return NS_OK;
140 NS_IMETHODIMP
141 nsClipboard::SupportsFindClipboard(bool* _retval)
143 NS_ENSURE_ARG_POINTER(_retval);
145 *_retval = false;
146 return NS_OK;