static bool plugin_get_metadata (PluginObject *obj, NPString uuid, NPVariant *result) { GError *error = NULL; GVariant *res; const gchar *json; gchar *buffer; res = g_dbus_proxy_call_sync (obj->proxy, "GetExtensionInfo", g_variant_new ("(s)", uuid.UTF8Characters), G_DBUS_CALL_FLAGS_NONE, -1, /* timeout */ NULL, /* cancellable */ &error); if (!res) { g_warning ("Failed to retrieve extension list: %s", error->message); g_error_free (error); return FALSE; } g_variant_get(res, "(&s)", &json); buffer = funcs.memalloc (strlen (json)); strcpy(buffer, json); STRINGZ_TO_NPVARIANT (buffer, *result); g_variant_unref (res); return TRUE; }
void * NPN_MemAlloc(uint32_t size) { void * rv = NULL; rv = NPNFuncs.memalloc(size); return rv; }
static void* MyNPN_MemAlloc(uint32 size) { void *ret; DEB(ef, "-> NPN_MemAlloc( %d )\n", size); ret = gNetscapeFuncs.memalloc( size ); DEB(ef, "<- NPN_MemAlloc = 0x%x\n", ret); return ret; }
void* NPN_MemAlloc(uint32 size) { void * rv = NULL; if(logger) logger->logCall(action_npn_mem_alloc, (DWORD)size); rv = NPNFuncs.memalloc(size); if(logger) logger->logReturn(); return rv; }
SEXP R_ConvertRToNP(SEXP Robj, SEXP plug) { NPP inst = (NPP) R_ExternalPtrAddr(GET_SLOT( plug , Rf_install( "ref" ) ) ); NPNetscapeFuncs *funcs = (NPNetscapeFuncs *) R_ExternalPtrAddr(GET_SLOT( GET_SLOT(plug, Rf_install("funcs")), Rf_install("ref") ) ) ; NPVariant *var = (NPVariant *) funcs->memalloc(sizeof(NPVariant)); SEXP ans; PROTECT(ans = R_NilValue); ConvertRToNP(Robj, inst, funcs, var, CONV_COPY); ConvertNPToR(var, inst, funcs, CONV_REF, &ans); UNPROTECT(1); return ans; }
static gboolean jsonify_variant (GVariant *variant, NPVariant *result) { gboolean ret; GVariant *real_value; JsonNode *root; JsonGenerator *generator; gsize json_length; gchar *json; gchar *buffer; ret = TRUE; /* DBus methods can return multiple values, * but we're only interested in the first. */ g_variant_get (variant, "(@*)", &real_value); root = json_gvariant_serialize (real_value); generator = json_generator_new (); json_generator_set_root (generator, root); json = json_generator_to_data (generator, &json_length); buffer = funcs.memalloc (json_length + 1); if (!buffer) { ret = FALSE; goto out; } strcpy (buffer, json); STRINGN_TO_NPVARIANT (buffer, json_length, *result); out: g_variant_unref (variant); g_variant_unref (real_value); json_node_free (root); g_free (json); return ret; }
SEXP R_NPAPI_GetProperty(SEXP plug, SEXP Robj, SEXP Rname, SEXP RconvRet) { NPP inst = (NPP) R_ExternalPtrAddr(GET_SLOT( plug , Rf_install( "ref" ) ) ); NPNetscapeFuncs *funcs = (NPNetscapeFuncs *) R_ExternalPtrAddr(GET_SLOT( GET_SLOT(plug, Rf_install("funcs")), Rf_install("ref"))); NPVariant *obj = (NPVariant *) R_ExternalPtrAddr(GET_SLOT( Robj , Rf_install( "ref" ) ) ); if(!NPVARIANT_IS_OBJECT(*obj)) { //What should we return in this case? Rf_error("Robj is not an NPVariant containing an NPObject."); return R_NilValue; } convert_t convRet = (convert_t) INTEGER(RconvRet)[0]; NPVariant *ret = (NPVariant *) funcs->memalloc(sizeof(NPVariant)); const char *ccname = CHAR(STRING_ELT(Rname, 0)); bool success = funcs->getproperty(inst, obj->value.objectValue, funcs->getstringidentifier(ccname), ret); if(!success) { Rf_error("Invoke failed."); return R_NilValue; } SEXP ans; PROTECT(ans = R_NilValue); //ConvertNPToR returns a bool which indicates whether it is safe to release the converted object. bool canfree = ConvertNPToR(ret, inst, funcs, convRet, &ans); if(canfree) funcs->releasevariantvalue(ret); UNPROTECT(1); return ans ; }
static gboolean plugin_get_shell_version (PluginObject *obj, NPVariant *result) { GVariant *res; const gchar *version; gsize length; gchar *buffer; gboolean ret; ret = TRUE; res = g_dbus_proxy_get_cached_property (obj->proxy, "ShellVersion"); if (res == NULL) { g_warning ("Failed to grab shell version."); version = "-1"; } else { g_variant_get (res, "&s", &version); } length = strlen (version); buffer = funcs.memalloc (length + 1); if (!buffer) { ret = FALSE; goto out; } strcpy (buffer, version); STRINGN_TO_NPVARIANT (buffer, length, *result); out: if (res) g_variant_unref (res); return ret; }
SEXP R_NP_GetGlobal(SEXP Rplug) { NPP inst = (NPP) R_ExternalPtrAddr(GET_SLOT( Rplug , Rf_install( "ref" ) ) ); NPNetscapeFuncs *funcs = (NPNetscapeFuncs *) R_ExternalPtrAddr(GET_SLOT( GET_SLOT(Rplug, Rf_install("funcs")), Rf_install("ref"))); NPObject *domwin = NULL; NPVariant *toret = (NPVariant *) funcs->memalloc(sizeof(NPVariant)); //NPVariant vartmp2; NPError res; bool success; res = funcs->getvalue(inst, NPNVWindowNPObject , &domwin); funcs->retainobject(domwin); OBJECT_TO_NPVARIANT(domwin, *toret); SEXP ans; PROTECT(ans = R_NilValue); ConvertNPToR(toret, inst, funcs, CONV_REF, &ans); UNPROTECT(1); return ans; }
void* NPN_MemAlloc(uint32 size) { return NPNFuncs.memalloc(size); }
SEXP R_NPAPI_Invoke(SEXP plug, SEXP Robj, SEXP Rname, SEXP Rargs, SEXP RconvArgsEnum, SEXP RconvArgsFuns, SEXP RconvRet, SEXP RkeepRes ) { NPP inst = (NPP) R_ExternalPtrAddr(GET_SLOT( plug , Rf_install( "ref" ) ) ); NPNetscapeFuncs *funcs = (NPNetscapeFuncs *) R_ExternalPtrAddr(GET_SLOT( GET_SLOT(plug, Rf_install("funcs")), Rf_install("ref"))); NPVariant *obj = (NPVariant *) R_ExternalPtrAddr(GET_SLOT( Robj , Rf_install( "ref" ) ) ); if(!NPVARIANT_IS_OBJECT(*obj)) { //What should we return in this case? Rf_error("Robj is not an NPVariant containing an NPObject."); return R_NilValue; } //custom conversion functions are applied on R side for return value. convert_t convRet = (convert_t) INTEGER(RconvRet)[0]; convert_t curConvArg; int nargs = LENGTH(Rargs); NPVariant *args = (NPVariant *) funcs->memalloc(nargs*sizeof(NPVariant)); for(int i = 0; i < nargs; i++) { curConvArg = (convert_t) INTEGER(RconvArgsEnum)[i]; ConvertRToNP(VECTOR_ELT(Rargs, i), inst, funcs, &(args[i]), curConvArg); //If we have a custom converter we invoke it with here if(curConvArg == CONV_CUSTOM) { fprintf(stderr, "Custom argument converter detected. Attempting to call JS Conversion function.");fflush(stderr); funcs->invokeDefault(inst, ((NPVariant *) R_ExternalPtrAddr(GET_SLOT( VECTOR_ELT(RconvArgsFuns, i), Rf_install( "ref" ) ) ) ) -> value.objectValue, &args[i], 1, &args[i]) ; } } NPVariant *ret = (NPVariant *) funcs->memalloc(sizeof(NPVariant)); const char *ccname = CHAR(STRING_ELT(Rname, 0)); bool hasMethod = funcs->hasmethod(inst, obj->value.objectValue, funcs->getstringidentifier(ccname)); if(!hasMethod) { char msg[200]; sprintf(msg, "Object has no %s method.", ccname); Rf_error(msg); return R_NilValue; } bool success = funcs->invoke(inst, obj->value.objectValue, funcs->getstringidentifier(ccname), args, nargs, ret); if(!success) { fprintf(stderr, "\nInvocation of JS method %s failed.", ccname);fflush(stderr); } for(int j=0; j<nargs; j++) { if (NPVARIANT_IS_OBJECT(args[j])) funcs->releaseobject(args[j].value.objectValue); //funcs->releasevariantvalue(&args[j]); } funcs->memfree(args); if(!success) { char msg2[200]; sprintf(msg2, "Invoke failed for %s method.", ccname); Rf_error(msg2); return R_NilValue; } SEXP ans; //PROTECT(ans = R_NilValue); PROTECT(ans = NEW_INTEGER(1)); bool canfree = ConvertNPToR(ret, inst, funcs, convRet, &ans); bool keepRes = LOGICAL(RkeepRes)[0]; if(canfree || !keepRes) funcs->releasevariantvalue(ret); UNPROTECT(1); if(keepRes) return ans ; else return R_NilValue; }