diff --git a/modules/plugin/test/mochitest/Makefile.in b/modules/plugin/test/mochitest/Makefile.in index b3caba2fa27..7095c066237 100644 --- a/modules/plugin/test/mochitest/Makefile.in +++ b/modules/plugin/test/mochitest/Makefile.in @@ -104,6 +104,12 @@ _MOCHICHROME_FILES += \ $(NULL) endif +ifeq (gtk2,$(MOZ_WIDGET_TOOLKIT)) +_MOCHITEST_FILES += \ + test_copyText.html \ + $(NULL) +endif + ifdef MOZ_IPC _MOCHICHROME_FILES += \ test_crash_notify.xul \ diff --git a/modules/plugin/test/mochitest/test_copyText.html b/modules/plugin/test/mochitest/test_copyText.html new file mode 100644 index 00000000000..7f5a269f47e --- /dev/null +++ b/modules/plugin/test/mochitest/test_copyText.html @@ -0,0 +1,37 @@ + + + + Test copying text from browser to plugin + + + + + + + + + + + + diff --git a/modules/plugin/test/testplugin/nptest.cpp b/modules/plugin/test/testplugin/nptest.cpp index 747f8f86bc9..6c9cf11fc60 100644 --- a/modules/plugin/test/testplugin/nptest.cpp +++ b/modules/plugin/test/testplugin/nptest.cpp @@ -154,6 +154,7 @@ static bool getAuthInfo(NPObject* npobj, const NPVariant* args, uint32_t argCoun static bool asyncCallbackTest(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result); static bool checkGCRace(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result); static bool hangPlugin(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result); +static bool getClipboardText(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result); static const NPUTF8* sPluginMethodIdentifierNames[] = { "npnEvaluateTest", @@ -193,6 +194,7 @@ static const NPUTF8* sPluginMethodIdentifierNames[] = { "asyncCallbackTest", "checkGCRace", "hang", + "getClipboardText", }; static NPIdentifier sPluginMethodIdentifiers[ARRAY_LENGTH(sPluginMethodIdentifierNames)]; static const ScriptableFunction sPluginMethodFunctions[ARRAY_LENGTH(sPluginMethodIdentifierNames)] = { @@ -233,6 +235,7 @@ static const ScriptableFunction sPluginMethodFunctions[ARRAY_LENGTH(sPluginMetho asyncCallbackTest, checkGCRace, hangPlugin, + getClipboardText, }; struct URLNotifyData @@ -2580,3 +2583,36 @@ hangPlugin(NPObject* npobj, const NPVariant* args, uint32_t argCount, // test will fail. return true; } + +#if defined(MOZ_WIDGET_GTK2) +bool +getClipboardText(NPObject* npobj, const NPVariant* args, uint32_t argCount, + NPVariant* result) +{ + NPP npp = static_cast(npobj)->npp; + InstanceData* id = static_cast(npp->pdata); + string sel = pluginGetClipboardText(id); + + uint32 len = sel.size(); + char* selCopy = static_cast(NPN_MemAlloc(1 + len)); + if (!selCopy) + return false; + + memcpy(selCopy, sel.c_str(), len); + selCopy[len] = '\0'; + + STRINGN_TO_NPVARIANT(selCopy, len, *result); + // *result owns str now + + return true; +} + +#else +# warning "Implement pluginGetClipboardText for this platform" +bool +getClipboardText(NPObject* npobj, const NPVariant* args, uint32_t argCount, + NPVariant* result) +{ + return false; +} +#endif diff --git a/modules/plugin/test/testplugin/nptest_gtk2.cpp b/modules/plugin/test/testplugin/nptest_gtk2.cpp index d6162eb6110..ef5a9d073a5 100644 --- a/modules/plugin/test/testplugin/nptest_gtk2.cpp +++ b/modules/plugin/test/testplugin/nptest_gtk2.cpp @@ -621,3 +621,17 @@ int32_t pluginGetClipRegionRectEdge(InstanceData* instanceData, void pluginDoInternalConsistencyCheck(InstanceData* instanceData, string& error) { } + +string +pluginGetClipboardText(InstanceData* instanceData) +{ + GtkClipboard* cb = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); + // XXX this is a BAD WAY to interact with GtkClipboard. We use this + // deprecated interface only to test nested event loop handling. + gchar* text = gtk_clipboard_wait_for_text(cb); + string retText = text ? text : ""; + + g_free(text); + + return retText; +} diff --git a/modules/plugin/test/testplugin/nptest_platform.h b/modules/plugin/test/testplugin/nptest_platform.h index 945fc672bb5..2e85306ecba 100644 --- a/modules/plugin/test/testplugin/nptest_platform.h +++ b/modules/plugin/test/testplugin/nptest_platform.h @@ -120,4 +120,10 @@ int32_t pluginGetClipRegionRectEdge(InstanceData* instanceData, */ void pluginDoInternalConsistencyCheck(InstanceData* instanceData, std::string& error); +/** + * Get the current clipboard item as text. If the clipboard item + * isn't text, the returned value is undefined. + */ +std::string pluginGetClipboardText(InstanceData* instanceData); + #endif // nptest_platform_h_