michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "mozilla/dom/ContentChild.h" michael@0: #include "nsClipboard.h" michael@0: #include "nsISupportsPrimitives.h" michael@0: #include "AndroidBridge.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsComponentManagerUtils.h" michael@0: #include "nsXULAppAPI.h" michael@0: michael@0: using namespace mozilla; michael@0: using mozilla::dom::ContentChild; michael@0: michael@0: NS_IMPL_ISUPPORTS(nsClipboard, nsIClipboard) michael@0: michael@0: /* The Android clipboard only supports text and doesn't support mime types michael@0: * so we assume all clipboard data is text/unicode for now. Documentation michael@0: * indicates that support for other data types is planned for future michael@0: * releases. michael@0: */ michael@0: michael@0: nsClipboard::nsClipboard() michael@0: { michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsClipboard::SetData(nsITransferable *aTransferable, michael@0: nsIClipboardOwner *anOwner, int32_t aWhichClipboard) michael@0: { michael@0: if (aWhichClipboard != kGlobalClipboard) michael@0: return NS_ERROR_NOT_IMPLEMENTED; michael@0: michael@0: nsCOMPtr tmp; michael@0: uint32_t len; michael@0: nsresult rv = aTransferable->GetTransferData(kUnicodeMime, getter_AddRefs(tmp), michael@0: &len); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: nsCOMPtr supportsString = do_QueryInterface(tmp); michael@0: // No support for non-text data michael@0: NS_ENSURE_TRUE(supportsString, NS_ERROR_NOT_IMPLEMENTED); michael@0: nsAutoString buffer; michael@0: supportsString->GetData(buffer); michael@0: michael@0: mozilla::widget::android::Clipboard::SetClipboardText(buffer); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsClipboard::GetData(nsITransferable *aTransferable, int32_t aWhichClipboard) michael@0: { michael@0: if (aWhichClipboard != kGlobalClipboard) michael@0: return NS_ERROR_NOT_IMPLEMENTED; michael@0: michael@0: nsAutoString buffer; michael@0: if (!AndroidBridge::Bridge()) michael@0: return NS_ERROR_NOT_IMPLEMENTED; michael@0: if (!AndroidBridge::Bridge()->GetClipboardText(buffer)) michael@0: return NS_ERROR_UNEXPECTED; michael@0: michael@0: nsresult rv; michael@0: nsCOMPtr dataWrapper = michael@0: do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: rv = dataWrapper->SetData(buffer); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: // If our data flavor has already been added, this will fail. But we don't care michael@0: aTransferable->AddDataFlavor(kUnicodeMime); michael@0: michael@0: nsCOMPtr nsisupportsDataWrapper = michael@0: do_QueryInterface(dataWrapper); michael@0: rv = aTransferable->SetTransferData(kUnicodeMime, nsisupportsDataWrapper, michael@0: buffer.Length() * sizeof(char16_t)); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsClipboard::EmptyClipboard(int32_t aWhichClipboard) michael@0: { michael@0: if (aWhichClipboard != kGlobalClipboard) michael@0: return NS_ERROR_NOT_IMPLEMENTED; michael@0: mozilla::widget::android::Clipboard::ClearText(); michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsClipboard::HasDataMatchingFlavors(const char **aFlavorList, michael@0: uint32_t aLength, int32_t aWhichClipboard, michael@0: bool *aHasText) michael@0: { michael@0: *aHasText = false; michael@0: if (aWhichClipboard != kGlobalClipboard) michael@0: return NS_ERROR_NOT_IMPLEMENTED; michael@0: *aHasText = mozilla::widget::android::Clipboard::HasText(); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsClipboard::SupportsSelectionClipboard(bool *aIsSupported) michael@0: { michael@0: *aIsSupported = false; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsClipboard::SupportsFindClipboard(bool* _retval) michael@0: { michael@0: *_retval = false; michael@0: return NS_OK; michael@0: }