Exemplo n.º 1
0
bool NPN_Invoke(NPP id, NPObject* obj, NPIdentifier identifier, const NPVariant *args, uint32_t count, NPVariant*result)
{
    char msg[1024];
    sprintf(msg, "NPN_Invoke");
    logger->logMessage(msg);

    bool rv = NPNFuncs.invoke(id, obj, identifier, args, count, result);

    sprintf(msg, "--Return: %x", rv);
    logger->logMessage(msg);

    return rv;
}
Exemplo n.º 2
0
bool NPN_Invoke(NPP npp, NPObject* obj, NPIdentifier methodName,
                const NPVariant *args, uint32_t argCount, NPVariant *result)
{
  return NPNFuncs.invoke(npp, obj, methodName, args, argCount, result);
}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
-1
static void
cloud_spy_log (const gchar * log_domain, GLogLevelFlags log_level, const gchar * message, gpointer user_data)
{
  NPNetscapeFuncs * browser = cloud_spy_nsfuncs;
  NPP instance = static_cast<NPP> (user_data);
  NPObject * window = NULL, * console = NULL;
  NPVariant variant, result;
  NPError error;

  (void) log_domain;
  (void) log_level;

  error = browser->getvalue (instance, NPNVWindowNPObject, &window);
  if (error != NPERR_NO_ERROR)
    goto beach;

  VOID_TO_NPVARIANT (variant);
  if (!browser->getproperty (instance, window, browser->getstringidentifier ("console"), &variant))
    goto beach;
  console = NPVARIANT_TO_OBJECT (variant);

  STRINGZ_TO_NPVARIANT (message, variant);
  VOID_TO_NPVARIANT (result);
  if (!browser->invoke (instance, console, browser->getstringidentifier ("log"), &variant, 1, &result))
    goto beach;
  browser->releasevariantvalue (&result);

beach:
  if (console != NULL)
    browser->releaseobject (console);
  if (window != NULL)
    browser->releaseobject (window);
}