bug 636666 - paste option doesn't appear in context menu for text boxes in content on android r=dougt a=blocking-fennec

This commit is contained in:
Brad Lassey 2011-03-01 00:36:43 -05:00
Родитель 34c1f6823d
Коммит abe793bee6
4 изменённых файлов: 132 добавлений и 11 удалений

Просмотреть файл

@ -92,6 +92,12 @@
#include "gfxAndroidPlatform.h"
#endif
#include "nsIClipboard.h"
#include "nsWidgetsCID.h"
#include "nsISupportsPrimitives.h"
static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID);
static const char* sClipboardTextFlavors[] = { kUnicodeMime };
using namespace mozilla::ipc;
using namespace mozilla::net;
using namespace mozilla::places;
@ -390,6 +396,84 @@ ContentParent::RecvReadPermissions(InfallibleTArray<IPC::Permission>* aPermissio
return true;
}
bool
ContentParent::RecvSetClipboardText(const nsString& text, const PRInt32& whichClipboard)
{
nsresult rv;
nsCOMPtr<nsIClipboard> clipboard(do_GetService(kCClipboardCID, &rv));
NS_ENSURE_SUCCESS(rv, true);
nsCOMPtr<nsISupportsString> dataWrapper =
do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, true);
rv = dataWrapper->SetData(text);
NS_ENSURE_SUCCESS(rv, true);
nsCOMPtr<nsITransferable> trans = do_CreateInstance("@mozilla.org/widget/transferable;1", &rv);
NS_ENSURE_SUCCESS(rv, true);
// If our data flavor has already been added, this will fail. But we don't care
trans->AddDataFlavor(kUnicodeMime);
nsCOMPtr<nsISupports> nsisupportsDataWrapper =
do_QueryInterface(dataWrapper);
rv = trans->SetTransferData(kUnicodeMime, nsisupportsDataWrapper,
text.Length() * sizeof(PRUnichar));
NS_ENSURE_SUCCESS(rv, true);
clipboard->SetData(trans, NULL, whichClipboard);
return true;
}
bool
ContentParent::RecvGetClipboardText(const PRInt32& whichClipboard, nsString* text)
{
nsresult rv;
nsCOMPtr<nsIClipboard> clipboard(do_GetService(kCClipboardCID, &rv));
NS_ENSURE_SUCCESS(rv, true);
nsCOMPtr<nsITransferable> trans = do_CreateInstance("@mozilla.org/widget/transferable;1", &rv);
NS_ENSURE_SUCCESS(rv, true);
clipboard->GetData(trans, whichClipboard);
nsCOMPtr<nsISupports> tmp;
PRUint32 len;
rv = trans->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);
supportsString->GetData(*text);
return true;
}
bool
ContentParent::RecvEmptyClipboard()
{
nsresult rv;
nsCOMPtr<nsIClipboard> clipboard(do_GetService(kCClipboardCID, &rv));
NS_ENSURE_SUCCESS(rv, true);
clipboard->EmptyClipboard(nsIClipboard::kGlobalClipboard);
return true;
}
bool
ContentParent::RecvClipboardHasText(PRBool* hasText)
{
nsresult rv;
nsCOMPtr<nsIClipboard> clipboard(do_GetService(kCClipboardCID, &rv));
NS_ENSURE_SUCCESS(rv, true);
clipboard->HasDataMatchingFlavors(sClipboardTextFlavors, 1,
nsIClipboard::kGlobalClipboard, hasText);
return true;
}
NS_IMPL_THREADSAFE_ISUPPORTS3(ContentParent,
nsIObserver,
nsIThreadObserver,

Просмотреть файл

@ -148,6 +148,10 @@ private:
void EnsurePrefService();
virtual bool RecvReadPermissions(InfallibleTArray<IPC::Permission>* aPermissions);
virtual bool RecvSetClipboardText(const nsString& text, const PRInt32& whichClipboard);
virtual bool RecvGetClipboardText(const PRInt32& whichClipboard, nsString* text);
virtual bool RecvEmptyClipboard();
virtual bool RecvClipboardHasText(PRBool* hasText);
virtual bool RecvStartVisitedQuery(const IPC::URI& uri);

Просмотреть файл

@ -179,6 +179,15 @@ parent:
// nsIPermissionManager messages
sync ReadPermissions() returns (Permission[] permissions);
// These clipboard methods are only really used on Android since
// the clipboard is not available in the content process.
SetClipboardText(nsString text, PRInt32 whichClipboard);
sync GetClipboardText(PRInt32 whichClipboard)
returns (nsString text);
EmptyClipboard();
sync ClipboardHasText()
returns (PRBool hasText);
both:
AsyncMessage(nsString aMessage, nsString aJSON);

Просмотреть файл

@ -34,13 +34,16 @@
*
* ***** END LICENSE BLOCK ***** */
#include "mozilla/dom/ContentChild.h"
#include "nsClipboard.h"
#include "nsISupportsPrimitives.h"
#include "AndroidBridge.h"
#include "nsCOMPtr.h"
#include "nsComponentManagerUtils.h"
#include "nsXULAppAPI.h"
using namespace mozilla;
using mozilla::dom::ContentChild;
NS_IMPL_ISUPPORTS1(nsClipboard, nsIClipboard)
@ -60,8 +63,6 @@ nsClipboard::SetData(nsITransferable *aTransferable,
{
if (aWhichClipboard != kGlobalClipboard)
return NS_ERROR_NOT_IMPLEMENTED;
if (!AndroidBridge::Bridge())
return NS_ERROR_NOT_IMPLEMENTED;
nsCOMPtr<nsISupports> tmp;
PRUint32 len;
@ -73,7 +74,17 @@ nsClipboard::SetData(nsITransferable *aTransferable,
NS_ENSURE_TRUE(supportsString, NS_ERROR_NOT_IMPLEMENTED);
nsAutoString buffer;
supportsString->GetData(buffer);
AndroidBridge::Bridge()->SetClipboardText(buffer);
if (XRE_GetProcessType() == GeckoProcessType_Default) {
if (AndroidBridge::Bridge())
AndroidBridge::Bridge()->SetClipboardText(buffer);
else
return NS_ERROR_NOT_IMPLEMENTED;
} else {
ContentChild::GetSingleton()->SendSetClipboardText(buffer, aWhichClipboard);
}
return NS_OK;
}
@ -82,12 +93,16 @@ nsClipboard::GetData(nsITransferable *aTransferable, PRInt32 aWhichClipboard)
{
if (aWhichClipboard != kGlobalClipboard)
return NS_ERROR_NOT_IMPLEMENTED;
if (!AndroidBridge::Bridge())
return NS_ERROR_NOT_IMPLEMENTED;
nsAutoString buffer;
if (!AndroidBridge::Bridge()->GetClipboardText(buffer))
return NS_ERROR_UNEXPECTED;
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);
}
nsresult rv;
nsCOMPtr<nsISupportsString> dataWrapper =
@ -114,8 +129,13 @@ nsClipboard::EmptyClipboard(PRInt32 aWhichClipboard)
{
if (aWhichClipboard != kGlobalClipboard)
return NS_ERROR_NOT_IMPLEMENTED;
if (AndroidBridge::Bridge())
AndroidBridge::Bridge()->EmptyClipboard();
if (XRE_GetProcessType() == GeckoProcessType_Default) {
if (AndroidBridge::Bridge())
AndroidBridge::Bridge()->EmptyClipboard();
} else {
ContentChild::GetSingleton()->SendEmptyClipboard();
}
return NS_OK;
}
@ -127,8 +147,12 @@ nsClipboard::HasDataMatchingFlavors(const char **aFlavorList,
*aHasText = PR_FALSE;
if (aWhichClipboard != kGlobalClipboard)
return NS_ERROR_NOT_IMPLEMENTED;
if (AndroidBridge::Bridge())
*aHasText = AndroidBridge::Bridge()->ClipboardHasText();
if (XRE_GetProcessType() == GeckoProcessType_Default) {
if (AndroidBridge::Bridge())
*aHasText = AndroidBridge::Bridge()->ClipboardHasText();
} else {
ContentChild::GetSingleton()->SendClipboardHasText(aHasText);
}
return NS_OK;
}