widget/android/nsClipboard.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #include "mozilla/dom/ContentChild.h"
michael@0 6 #include "nsClipboard.h"
michael@0 7 #include "nsISupportsPrimitives.h"
michael@0 8 #include "AndroidBridge.h"
michael@0 9 #include "nsCOMPtr.h"
michael@0 10 #include "nsComponentManagerUtils.h"
michael@0 11 #include "nsXULAppAPI.h"
michael@0 12
michael@0 13 using namespace mozilla;
michael@0 14 using mozilla::dom::ContentChild;
michael@0 15
michael@0 16 NS_IMPL_ISUPPORTS(nsClipboard, nsIClipboard)
michael@0 17
michael@0 18 /* The Android clipboard only supports text and doesn't support mime types
michael@0 19 * so we assume all clipboard data is text/unicode for now. Documentation
michael@0 20 * indicates that support for other data types is planned for future
michael@0 21 * releases.
michael@0 22 */
michael@0 23
michael@0 24 nsClipboard::nsClipboard()
michael@0 25 {
michael@0 26 }
michael@0 27
michael@0 28 NS_IMETHODIMP
michael@0 29 nsClipboard::SetData(nsITransferable *aTransferable,
michael@0 30 nsIClipboardOwner *anOwner, int32_t aWhichClipboard)
michael@0 31 {
michael@0 32 if (aWhichClipboard != kGlobalClipboard)
michael@0 33 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 34
michael@0 35 nsCOMPtr<nsISupports> tmp;
michael@0 36 uint32_t len;
michael@0 37 nsresult rv = aTransferable->GetTransferData(kUnicodeMime, getter_AddRefs(tmp),
michael@0 38 &len);
michael@0 39 NS_ENSURE_SUCCESS(rv, rv);
michael@0 40 nsCOMPtr<nsISupportsString> supportsString = do_QueryInterface(tmp);
michael@0 41 // No support for non-text data
michael@0 42 NS_ENSURE_TRUE(supportsString, NS_ERROR_NOT_IMPLEMENTED);
michael@0 43 nsAutoString buffer;
michael@0 44 supportsString->GetData(buffer);
michael@0 45
michael@0 46 mozilla::widget::android::Clipboard::SetClipboardText(buffer);
michael@0 47 return NS_OK;
michael@0 48 }
michael@0 49
michael@0 50 NS_IMETHODIMP
michael@0 51 nsClipboard::GetData(nsITransferable *aTransferable, int32_t aWhichClipboard)
michael@0 52 {
michael@0 53 if (aWhichClipboard != kGlobalClipboard)
michael@0 54 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 55
michael@0 56 nsAutoString buffer;
michael@0 57 if (!AndroidBridge::Bridge())
michael@0 58 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 59 if (!AndroidBridge::Bridge()->GetClipboardText(buffer))
michael@0 60 return NS_ERROR_UNEXPECTED;
michael@0 61
michael@0 62 nsresult rv;
michael@0 63 nsCOMPtr<nsISupportsString> dataWrapper =
michael@0 64 do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv);
michael@0 65 NS_ENSURE_SUCCESS(rv, rv);
michael@0 66
michael@0 67 rv = dataWrapper->SetData(buffer);
michael@0 68 NS_ENSURE_SUCCESS(rv, rv);
michael@0 69
michael@0 70 // If our data flavor has already been added, this will fail. But we don't care
michael@0 71 aTransferable->AddDataFlavor(kUnicodeMime);
michael@0 72
michael@0 73 nsCOMPtr<nsISupports> nsisupportsDataWrapper =
michael@0 74 do_QueryInterface(dataWrapper);
michael@0 75 rv = aTransferable->SetTransferData(kUnicodeMime, nsisupportsDataWrapper,
michael@0 76 buffer.Length() * sizeof(char16_t));
michael@0 77 NS_ENSURE_SUCCESS(rv, rv);
michael@0 78
michael@0 79 return NS_OK;
michael@0 80 }
michael@0 81
michael@0 82 NS_IMETHODIMP
michael@0 83 nsClipboard::EmptyClipboard(int32_t aWhichClipboard)
michael@0 84 {
michael@0 85 if (aWhichClipboard != kGlobalClipboard)
michael@0 86 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 87 mozilla::widget::android::Clipboard::ClearText();
michael@0 88
michael@0 89 return NS_OK;
michael@0 90 }
michael@0 91
michael@0 92 NS_IMETHODIMP
michael@0 93 nsClipboard::HasDataMatchingFlavors(const char **aFlavorList,
michael@0 94 uint32_t aLength, int32_t aWhichClipboard,
michael@0 95 bool *aHasText)
michael@0 96 {
michael@0 97 *aHasText = false;
michael@0 98 if (aWhichClipboard != kGlobalClipboard)
michael@0 99 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 100 *aHasText = mozilla::widget::android::Clipboard::HasText();
michael@0 101 return NS_OK;
michael@0 102 }
michael@0 103
michael@0 104 NS_IMETHODIMP
michael@0 105 nsClipboard::SupportsSelectionClipboard(bool *aIsSupported)
michael@0 106 {
michael@0 107 *aIsSupported = false;
michael@0 108 return NS_OK;
michael@0 109 }
michael@0 110
michael@0 111 NS_IMETHODIMP
michael@0 112 nsClipboard::SupportsFindClipboard(bool* _retval)
michael@0 113 {
michael@0 114 *_retval = false;
michael@0 115 return NS_OK;
michael@0 116 }

mercurial