bool WriteReq::Invoke(NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result) { if(name == cb_func) { NPN_InvokeDefault(m_Instance,cb_callback,args,argCount,result); } if(name == oncomplete_func) { NPN_InvokeDefault(m_Instance,oncomplete_callback,args,argCount,result); } return true; }
bool nsScriptableObjectRawInput::DeleteInstance( NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result) { if (argCount != 2 || !NPVARIANT_IS_DOUBLE(args[0]) || !NPVARIANT_IS_OBJECT(args[1])) { NPN_SetException(this, "(DeleteInstance) invalid params passed to function"); return true; } int32_t id = (int32_t)(int)floor(NPVARIANT_TO_DOUBLE(args[0]) + 0.5); // all numbers come in as double in chrome... bool foundAndDeleted = PluginMethodKeyCapture::DeleteInstance(id); NPVariant out_args[2]; NPVariant ret_val; BOOLEAN_TO_NPVARIANT(foundAndDeleted, out_args[0]); INT32_TO_NPVARIANT(id, out_args[1]); // fire callback NPN_InvokeDefault( __super::npp_, NPVARIANT_TO_OBJECT(args[1]), out_args, 2, &ret_val); NPN_ReleaseVariantValue(&ret_val); return true; }
static void retrieve_highres_icon (WebappMonitor *monitor, const gchar *desktop_file) { GKeyFile *key_file; gchar *s; GError *error = NULL; /* Get URL to get icon for */ key_file = g_key_file_new (); if (!g_key_file_load_from_data (key_file, desktop_file, strlen (desktop_file), 0, &error)) { g_warning ("Could not parse desktop file: %s", error->message); g_error_free (error); goto out; } if (get_icon_size (key_file) >= 64) goto out; s = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_EXEC, NULL); if (s != NULL) { gint n_args, i; gchar **args, *url = NULL; g_debug ("Parsing command line %s", s); if (!g_shell_parse_argv (s, &n_args, &args, &error)) { g_debug ("Failed parsing command line %s", s); goto out; } for (i = 0; i < n_args && args[i] != NULL; i++) { g_debug ("Processing argument %s", args[i]); if (g_str_has_prefix (args[i], "--app=")) { url = g_strdup (args[i] + 6); g_debug ("Found URL %s", url); break; } } if (url != NULL) { NPVariant url_varg, result; STRINGZ_TO_NPVARIANT(url, url_varg); NULL_TO_NPVARIANT(result); if (!NPN_InvokeDefault (monitor->instance, monitor->icon_loader_callback, &url_varg, 1, &result)) g_debug ("Failed calling JS callback"); g_free (url); NPN_ReleaseVariantValue (&result); } g_strfreev (args); g_free (s); } out: g_key_file_free (key_file); }
// this is not called on the main thread - so we need to // use NPN_PluginThreadAsyncCall void nsScriptableObjectOverwolfSample::EchoTask( const std::string& message, NPObject* callback) { if (shutting_down_) { return; } NPVariant arg; NPVariant ret_val; STRINGN_TO_NPVARIANT( message.c_str(), message.size(), arg); // fire callback NPN_InvokeDefault( __super::npp_, callback, &arg, 1, &ret_val); NPN_ReleaseVariantValue(&ret_val); }
//virtual void PluginMethodListenOnFile::OnError( const char* id, const char* message, unsigned int len) { TextFileIdToCallbackMap::iterator iter = ids_to_callbacks_.find(id); if ((iter == ids_to_callbacks_.end()) || (nullptr == iter->second)) { OutputDebugStringA("SimpleIOPlugin OnNewLine - missing callback error!"); return; } static bool write_to_trace = utils::ShouldWriteToTrace(); if (write_to_trace) { std::string str = "SimpleIOPlugin OnError - ["; str += id; str += "] "; str += message; OutputDebugStringA(str.c_str()); } NPVariant args[3]; NPVariant ret_val; STRINGN_TO_NPVARIANT( id, strlen(id), args[0]); BOOLEAN_TO_NPVARIANT( false, args[1]); STRINGN_TO_NPVARIANT( message, len, args[2]); // fire callback NPN_InvokeDefault( npp_, iter->second, args, 3, &ret_val); NPN_ReleaseVariantValue(&ret_val); }
void nsScriptableObjectOverwolfSample::AddTask( double first, double second, NPObject* callback) { if (shutting_down_) { return; } NPVariant arg; NPVariant ret_val; DOUBLE_TO_NPVARIANT(first+second, arg); // fire callback NPN_InvokeDefault( __super::npp_, callback, &arg, 1, &ret_val); NPN_ReleaseVariantValue(&ret_val); }
//virtual void PluginMethodListenOnFile::OnError(const char* message, unsigned int len) { NPVariant args[2]; NPVariant ret_val; BOOLEAN_TO_NPVARIANT( false, args[0]); STRINGN_TO_NPVARIANT( message, len, args[1]); // fire callback NPN_InvokeDefault( npp_, callback_, args, 2, &ret_val); NPN_ReleaseVariantValue(&ret_val); }
CPlugin::CPlugin(NPP pNPInstance) : m_pNPInstance(pNPInstance), m_pNPStream(NULL), m_bInitialized(false), m_pScriptableObject(NULL) { #ifdef XP_WIN m_hWnd = NULL; #endif NPN_GetValue(m_pNPInstance, NPNVWindowNPObject, &sWindowObj); NPIdentifier n = NPN_GetStringIdentifier("foof"); sFoo_id = NPN_GetStringIdentifier("foo"); sBar_id = NPN_GetStringIdentifier("bar"); sDocument_id = NPN_GetStringIdentifier("document"); sBody_id = NPN_GetStringIdentifier("body"); sCreateElement_id = NPN_GetStringIdentifier("createElement"); sCreateTextNode_id = NPN_GetStringIdentifier("createTextNode"); sAppendChild_id = NPN_GetStringIdentifier("appendChild"); sPluginType_id = NPN_GetStringIdentifier("PluginType"); NPVariant v; INT32_TO_NPVARIANT(46, v); NPN_SetProperty(m_pNPInstance, sWindowObj, n, &v); NPVariant rval; NPN_GetProperty(m_pNPInstance, sWindowObj, n, &rval); if (NPVARIANT_IS_INT32(rval)) { printf("rval = %d\n", NPVARIANT_TO_INT32(rval)); } n = NPN_GetStringIdentifier("document"); if (!NPN_IdentifierIsString(n)) { NPString str; str.UTF8Characters = "alert('NPN_IdentifierIsString() test failed!');"; str.UTF8Length = strlen(str.UTF8Characters); NPN_Evaluate(m_pNPInstance, sWindowObj, &str, NULL); } NPObject *doc; NPN_GetProperty(m_pNPInstance, sWindowObj, n, &rval); if (NPVARIANT_IS_OBJECT(rval) && (doc = NPVARIANT_TO_OBJECT(rval))) { n = NPN_GetStringIdentifier("title"); NPN_GetProperty(m_pNPInstance, doc, n, &rval); if (NPVARIANT_IS_STRING(rval)) { printf ("title = %s\n", NPVARIANT_TO_STRING(rval).UTF8Characters); NPN_ReleaseVariantValue(&rval); } n = NPN_GetStringIdentifier("plugindoc"); OBJECT_TO_NPVARIANT(doc, v); NPN_SetProperty(m_pNPInstance, sWindowObj, n, &v); NPString str; str.UTF8Characters = "document.getElementById('result').innerHTML += '<p>' + 'NPN_Evaluate() test, document = ' + this + '</p>';"; str.UTF8Length = strlen(str.UTF8Characters); //NPN_Evaluate(m_pNPInstance, doc, &str, NULL); NPN_ReleaseObject(doc); } NPVariant barval; NPN_GetProperty(m_pNPInstance, sWindowObj, sBar_id, &barval); NPVariant arg; OBJECT_TO_NPVARIANT(sWindowObj, arg); NPN_InvokeDefault(m_pNPInstance, NPVARIANT_TO_OBJECT(barval), &arg, 1, &rval); if (NPVARIANT_IS_INT32(rval) && NPVARIANT_TO_INT32(rval) == 4) { printf ("Default function call SUCCEEDED!\n"); } else { printf ("Default function call FAILED!\n"); } NPN_ReleaseVariantValue(&barval); NPN_ReleaseVariantValue(&rval); #if 0 n = NPN_GetStringIdentifier("prompt"); NPVariant vars[3]; STRINGZ_TO_NPVARIANT("foo", vars[0]); STRINGZ_TO_NPVARIANT("bar", vars[1]); STRINGZ_TO_NPVARIANT("foof", vars[2]); NPN_Invoke(sWindowObj, n, vars, 3, &rval); if (NPVARIANT_IS_STRING(rval)) { printf ("prompt returned '%s'\n", NPVARIANT_TO_STRING(rval).UTF8Characters); } NPN_ReleaseVariantValue(&rval); #endif NPObject *myobj = NPN_CreateObject(m_pNPInstance, GET_NPOBJECT_CLASS(ScriptablePluginObject)); n = NPN_GetStringIdentifier("pluginobj"); OBJECT_TO_NPVARIANT(myobj, v); NPN_SetProperty(m_pNPInstance, sWindowObj, n, &v); NPN_GetProperty(m_pNPInstance, sWindowObj, n, &rval); printf ("Object set/get test "); if (NPVARIANT_IS_OBJECT(rval) && NPVARIANT_TO_OBJECT(rval) == myobj) { printf ("succeeded!\n"); } else { printf ("FAILED!\n"); } NPN_ReleaseVariantValue(&rval); NPN_ReleaseObject(myobj); const char *ua = NPN_UserAgent(m_pNPInstance); strcpy(m_String, ua); }