2012-05-21 15:12:37 +04: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-27 03:43:23 +04:00
|
|
|
|
2011-03-01 08:36:43 +03:00
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2010-08-27 03:43:23 +04:00
|
|
|
#include "nsClipboard.h"
|
|
|
|
#include "nsISupportsPrimitives.h"
|
|
|
|
#include "AndroidBridge.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsComponentManagerUtils.h"
|
2011-03-01 08:36:43 +03:00
|
|
|
#include "nsXULAppAPI.h"
|
2010-08-27 03:43:23 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2011-03-01 08:36:43 +03:00
|
|
|
using mozilla::dom::ContentChild;
|
2010-08-27 03:43:23 +04:00
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(nsClipboard, nsIClipboard)
|
|
|
|
|
|
|
|
/* 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 19:56:38 +04:00
|
|
|
nsIClipboardOwner *anOwner, int32_t aWhichClipboard)
|
2010-08-27 03:43:23 +04:00
|
|
|
{
|
|
|
|
if (aWhichClipboard != kGlobalClipboard)
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> tmp;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t len;
|
2010-08-27 03:43:23 +04: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 08:36:43 +03:00
|
|
|
|
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
2013-11-12 22:41:01 +04:00
|
|
|
Clipboard::SetClipboardText(buffer);
|
2011-03-01 08:36:43 +03:00
|
|
|
} else {
|
2012-08-15 07:37:44 +04:00
|
|
|
bool isPrivateData = false;
|
|
|
|
aTransferable->GetIsPrivateData(&isPrivateData);
|
|
|
|
ContentChild::GetSingleton()->SendSetClipboardText(buffer, isPrivateData,
|
|
|
|
aWhichClipboard);
|
2011-03-01 08:36:43 +03:00
|
|
|
}
|
|
|
|
|
2010-08-27 03:43:23 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsClipboard::GetData(nsITransferable *aTransferable, int32_t aWhichClipboard)
|
2010-08-27 03:43:23 +04:00
|
|
|
{
|
|
|
|
if (aWhichClipboard != kGlobalClipboard)
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
nsAutoString buffer;
|
2011-03-01 08:36:43 +03:00
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
|
|
|
if (!AndroidBridge::Bridge())
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
if (!AndroidBridge::Bridge()->GetClipboardText(buffer))
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
} else {
|
|
|
|
ContentChild::GetSingleton()->SendGetClipboardText(aWhichClipboard, &buffer);
|
|
|
|
}
|
2010-08-27 03:43:23 +04: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,
|
|
|
|
buffer.Length() * sizeof(PRUnichar));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsClipboard::EmptyClipboard(int32_t aWhichClipboard)
|
2010-08-27 03:43:23 +04:00
|
|
|
{
|
|
|
|
if (aWhichClipboard != kGlobalClipboard)
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2011-03-01 08:36:43 +03:00
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
2013-11-12 22:41:01 +04:00
|
|
|
Clipboard::ClearText();
|
2011-03-01 08:36:43 +03:00
|
|
|
} else {
|
|
|
|
ContentChild::GetSingleton()->SendEmptyClipboard();
|
|
|
|
}
|
|
|
|
|
2010-08-27 03:43:23 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsClipboard::HasDataMatchingFlavors(const char **aFlavorList,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aLength, int32_t aWhichClipboard,
|
2012-07-07 00:14:07 +04:00
|
|
|
bool *aHasText)
|
2010-08-27 03:43:23 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
*aHasText = false;
|
2010-08-27 03:43:23 +04:00
|
|
|
if (aWhichClipboard != kGlobalClipboard)
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2011-03-01 08:36:43 +03:00
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
2013-11-12 22:41:01 +04:00
|
|
|
*aHasText = Clipboard::HasText();
|
2011-03-01 08:36:43 +03:00
|
|
|
} else {
|
|
|
|
ContentChild::GetSingleton()->SendClipboardHasText(aHasText);
|
|
|
|
}
|
2010-08-27 03:43:23 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-07-07 00:14:07 +04:00
|
|
|
nsClipboard::SupportsSelectionClipboard(bool *aIsSupported)
|
2010-08-27 03:43:23 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
*aIsSupported = false;
|
2010-08-27 03:43:23 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|