2012-05-21 04:12:37 -07: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 16:43:23 -07:00
|
|
|
|
2011-02-28 21:36:43 -08:00
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2010-08-26 16:43:23 -07:00
|
|
|
#include "nsClipboard.h"
|
|
|
|
#include "nsISupportsPrimitives.h"
|
|
|
|
#include "AndroidBridge.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsComponentManagerUtils.h"
|
2011-02-28 21:36:43 -08:00
|
|
|
#include "nsXULAppAPI.h"
|
2010-08-26 16:43:23 -07:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2011-02-28 21:36:43 -08:00
|
|
|
using mozilla::dom::ContentChild;
|
2010-08-26 16:43:23 -07:00
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(nsClipboard, nsIClipboard)
|
2010-08-26 16:43:23 -07: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 08:56:38 -07:00
|
|
|
nsIClipboardOwner *anOwner, int32_t aWhichClipboard)
|
2010-08-26 16:43:23 -07:00
|
|
|
{
|
|
|
|
if (aWhichClipboard != kGlobalClipboard)
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> tmp;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t len;
|
2010-08-26 16:43:23 -07: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-02-28 21:36:43 -08:00
|
|
|
|
2014-04-01 05:29:25 -07:00
|
|
|
mozilla::widget::android::Clipboard::SetClipboardText(buffer);
|
2010-08-26 16:43:23 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsClipboard::GetData(nsITransferable *aTransferable, int32_t aWhichClipboard)
|
2010-08-26 16:43:23 -07:00
|
|
|
{
|
|
|
|
if (aWhichClipboard != kGlobalClipboard)
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
nsAutoString buffer;
|
2014-02-09 16:13:10 -08:00
|
|
|
if (!AndroidBridge::Bridge())
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
if (!AndroidBridge::Bridge()->GetClipboardText(buffer))
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2010-08-26 16:43:23 -07: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 07:02:17 -08:00
|
|
|
buffer.Length() * sizeof(char16_t));
|
2010-08-26 16:43:23 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsClipboard::EmptyClipboard(int32_t aWhichClipboard)
|
2010-08-26 16:43:23 -07:00
|
|
|
{
|
|
|
|
if (aWhichClipboard != kGlobalClipboard)
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2014-04-01 05:29:25 -07:00
|
|
|
mozilla::widget::android::Clipboard::ClearText();
|
|
|
|
|
2010-08-26 16:43:23 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsClipboard::HasDataMatchingFlavors(const char **aFlavorList,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aLength, int32_t aWhichClipboard,
|
2012-07-06 13:14:07 -07:00
|
|
|
bool *aHasText)
|
2010-08-26 16:43:23 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
*aHasText = false;
|
2010-08-26 16:43:23 -07:00
|
|
|
if (aWhichClipboard != kGlobalClipboard)
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2014-04-01 05:29:25 -07:00
|
|
|
*aHasText = mozilla::widget::android::Clipboard::HasText();
|
2010-08-26 16:43:23 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-07-06 13:14:07 -07:00
|
|
|
nsClipboard::SupportsSelectionClipboard(bool *aIsSupported)
|
2010-08-26 16:43:23 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
*aIsSupported = false;
|
2010-08-26 16:43:23 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-28 07:07:30 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsClipboard::SupportsFindClipboard(bool* _retval)
|
|
|
|
{
|
|
|
|
*_retval = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|