2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-08-26 23:43:23 +00:00
|
|
|
|
2011-03-01 05:36:43 +00:00
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2010-08-26 23:43:23 +00:00
|
|
|
#include "nsClipboard.h"
|
|
|
|
#include "nsISupportsPrimitives.h"
|
|
|
|
#include "AndroidBridge.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsComponentManagerUtils.h"
|
2011-03-01 05:36:43 +00:00
|
|
|
#include "nsXULAppAPI.h"
|
2010-08-26 23:43:23 +00:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2011-03-01 05:36:43 +00:00
|
|
|
using mozilla::dom::ContentChild;
|
2010-08-26 23:43:23 +00:00
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(nsClipboard, nsIClipboard)
|
2010-08-26 23:43:23 +00:00
|
|
|
|
|
|
|
/* The Android clipboard only supports text and doesn't support mime types
|
|
|
|
* so we assume all clipboard data is text/unicode for now. Documentation
|
|
|
|
* indicates that support for other data types is planned for future
|
|
|
|
* releases.
|
|
|
|
*/
|
|
|
|
|
|
|
|
nsClipboard::nsClipboard()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsClipboard::SetData(nsITransferable *aTransferable,
|
2012-08-22 15:56:38 +00:00
|
|
|
nsIClipboardOwner *anOwner, int32_t aWhichClipboard)
|
2010-08-26 23:43:23 +00:00
|
|
|
{
|
|
|
|
if (aWhichClipboard != kGlobalClipboard)
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> tmp;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t len;
|
2010-08-26 23:43:23 +00:00
|
|
|
nsresult rv = aTransferable->GetTransferData(kUnicodeMime, getter_AddRefs(tmp),
|
|
|
|
&len);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
nsCOMPtr<nsISupportsString> supportsString = do_QueryInterface(tmp);
|
|
|
|
// No support for non-text data
|
|
|
|
NS_ENSURE_TRUE(supportsString, NS_ERROR_NOT_IMPLEMENTED);
|
|
|
|
nsAutoString buffer;
|
|
|
|
supportsString->GetData(buffer);
|
2011-03-01 05:36:43 +00:00
|
|
|
|
2016-08-13 03:15:52 +00:00
|
|
|
java::Clipboard::SetText(buffer);
|
2010-08-26 23:43:23 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsClipboard::GetData(nsITransferable *aTransferable, int32_t aWhichClipboard)
|
2010-08-26 23:43:23 +00:00
|
|
|
{
|
|
|
|
if (aWhichClipboard != kGlobalClipboard)
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
nsAutoString buffer;
|
2014-02-10 00:13:10 +00:00
|
|
|
if (!AndroidBridge::Bridge())
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
if (!AndroidBridge::Bridge()->GetClipboardText(buffer))
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2010-08-26 23:43:23 +00:00
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsISupportsString> dataWrapper =
|
|
|
|
do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = dataWrapper->SetData(buffer);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// If our data flavor has already been added, this will fail. But we don't care
|
|
|
|
aTransferable->AddDataFlavor(kUnicodeMime);
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> nsisupportsDataWrapper =
|
|
|
|
do_QueryInterface(dataWrapper);
|
|
|
|
rv = aTransferable->SetTransferData(kUnicodeMime, nsisupportsDataWrapper,
|
2014-01-04 15:02:17 +00:00
|
|
|
buffer.Length() * sizeof(char16_t));
|
2010-08-26 23:43:23 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsClipboard::EmptyClipboard(int32_t aWhichClipboard)
|
2010-08-26 23:43:23 +00:00
|
|
|
{
|
|
|
|
if (aWhichClipboard != kGlobalClipboard)
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2016-07-21 17:49:04 +00:00
|
|
|
java::Clipboard::ClearText();
|
2014-04-01 12:29:25 +00:00
|
|
|
|
2010-08-26 23:43:23 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsClipboard::HasDataMatchingFlavors(const char **aFlavorList,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aLength, int32_t aWhichClipboard,
|
2012-07-06 20:14:07 +00:00
|
|
|
bool *aHasText)
|
2010-08-26 23:43:23 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
*aHasText = false;
|
2010-08-26 23:43:23 +00:00
|
|
|
if (aWhichClipboard != kGlobalClipboard)
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2016-05-11 14:04:19 +00:00
|
|
|
|
|
|
|
for (uint32_t k = 0; k < aLength; k++) {
|
|
|
|
if (strcmp(aFlavorList[k], kUnicodeMime) == 0) {
|
2016-07-21 17:49:04 +00:00
|
|
|
*aHasText = java::Clipboard::HasText();
|
2016-05-11 14:04:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-26 23:43:23 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-07-06 20:14:07 +00:00
|
|
|
nsClipboard::SupportsSelectionClipboard(bool *aIsSupported)
|
2010-08-26 23:43:23 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
*aIsSupported = false;
|
2010-08-26 23:43:23 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-28 15:07:30 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsClipboard::SupportsFindClipboard(bool* _retval)
|
|
|
|
{
|
|
|
|
*_retval = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|