static bool
plugin_object_set_property (NPObject        *npobj,
			    NPIdentifier     name,
			    const NPVariant *value)
{
  PluginObject *obj;

  g_return_val_if_fail (plugin_object_has_property (npobj, name), FALSE);

  obj = (PluginObject*) npobj;
  if (obj->listener)
    funcs.releaseobject (obj->listener);

  obj->listener = NULL;
  if (NPVARIANT_IS_OBJECT (*value))
    {
      obj->listener = NPVARIANT_TO_OBJECT (*value);
      funcs.retainobject (obj->listener);
      return TRUE;
    }
  else if (NPVARIANT_IS_NULL (*value))
    return TRUE;

  return FALSE;
}
Esempio n. 2
0
void NPN_ReleaseObject(NPObject *obj)
{
    char msg[1024];
    sprintf(msg, "NPN_ReleaseObject");
    logger->logMessage(msg);

    NPNFuncs.releaseobject(obj);

    sprintf(msg, "--Return.");
    logger->logMessage(msg);
}
static void
plugin_object_deallocate (NPObject *npobj)
{
  PluginObject *obj = (PluginObject*)npobj;

  g_signal_handler_disconnect (obj->proxy, obj->signal_id);
  g_object_unref (obj->proxy);

  if (obj->listener)
    funcs.releaseobject (obj->listener);

  g_debug ("plugin object destroyed");

  g_slice_free (PluginObject, obj);
}
static bool
plugin_object_set_callback (NPObject        **listener,
                            const NPVariant  *value)
{
  if (!NPVARIANT_IS_OBJECT (*value) && !NPVARIANT_IS_NULL (*value))
    return FALSE;

  if (*listener)
    funcs.releaseobject (*listener);
  *listener = NULL;

  if (NPVARIANT_IS_OBJECT (*value))
    {
      *listener = NPVARIANT_TO_OBJECT (*value);
      funcs.retainobject (*listener);
    }

  return TRUE;
}
void NPN_ReleaseObject(NPObject *obj)
{
  return NPNFuncs.releaseobject(obj);
}
Esempio n. 6
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;
}
Esempio n. 7
0
void NPN_ReleaseObject(NPObject *npobj)
{
	NPNFuncs.releaseobject(npobj);
}
NPError
NPP_New(NPMIMEType    mimetype,
	NPP           instance,
	uint16_t      mode,
	int16_t       argc,
	char        **argn,
	char        **argv,
	NPSavedData  *saved)
{
  /* instance initialization function */
  NPError ret = NPERR_NO_ERROR;
  PluginData *data;
  GError *error = NULL;

  /* first, check if the location is what we expect */
  NPObject *window;
  NPVariant document;
  NPVariant location;
  NPVariant href;

  g_debug ("plugin created");

  funcs.getvalue (instance, NPNVWindowNPObject, &window);

  funcs.getproperty (instance, window,
		     funcs.getstringidentifier ("document"),
		     &document);
  g_assert (NPVARIANT_IS_OBJECT (document));

  funcs.getproperty (instance, NPVARIANT_TO_OBJECT (document),
		     funcs.getstringidentifier ("location"),
		     &location);
  g_assert (NPVARIANT_IS_OBJECT (location));

  funcs.getproperty (instance, NPVARIANT_TO_OBJECT (location),
		     funcs.getstringidentifier ("href"),
		     &href);
  g_assert (NPVARIANT_IS_STRING (href));

  if (strncmp (NPVARIANT_TO_STRING (href).UTF8Characters, ORIGIN, sizeof (ORIGIN)-1))
    {
      g_debug ("origin does not match, is %s", NPVARIANT_TO_STRING (href).UTF8Characters);

      if (!ALLOW_FOREIGN_ORIGIN)
	{
	  ret = NPERR_GENERIC_ERROR;
	  goto out;
	}
    }

  data = g_slice_new (PluginData);
  instance->pdata = data;

  data->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
					       G_DBUS_PROXY_FLAGS_NONE,
					       NULL, /* interface info */
					       "org.gnome.Shell",
					       "/org/gnome/Shell",
					       "org.gnome.Shell",
					       NULL, /* GCancellable */
					       &error);
  if (!data->proxy) {
    /* ignore error if the shell is not running, otherwise warn */
    if (error->domain != G_DBUS_ERROR ||
	error->code != G_DBUS_ERROR_NAME_HAS_NO_OWNER)
      {
	g_warning ("Failed to set up Shell proxy: %s", error->message);
	g_error_clear (&error);
      }
    ret = NPERR_GENERIC_ERROR;
  }

  g_debug ("plugin created successfully");

 out:
  funcs.releaseobject (window);
  funcs.releasevariantvalue (&document);
  funcs.releasevariantvalue (&location);
  funcs.releasevariantvalue (&href);

  return ret;
}
static gboolean
check_origin_and_protocol (NPP instance)
{
  gboolean ret = FALSE;
  NPError error;
  NPObject *window = NULL;
  NPVariant document = { NPVariantType_Void };
  NPVariant location = { NPVariantType_Void };
  gchar *hostname = NULL;
  gchar *protocol = NULL;

  error = funcs.getvalue (instance, NPNVWindowNPObject, &window);
  if (error != NPERR_NO_ERROR)
    goto out;

  if (!funcs.getproperty (instance, window,
                          funcs.getstringidentifier ("document"),
                          &document))
    goto out;

  if (!NPVARIANT_IS_OBJECT (document))
    goto out;

  if (!funcs.getproperty (instance, NPVARIANT_TO_OBJECT (document),
                          funcs.getstringidentifier ("location"),
                          &location))
    goto out;

  if (!NPVARIANT_IS_OBJECT (location))
    goto out;

  hostname = get_string_property (instance,
                                  NPVARIANT_TO_OBJECT (location),
                                  "hostname");

  if (g_strcmp0 (hostname, ORIGIN))
    {
      g_debug ("origin does not match, is %s",
               hostname);

      goto out;
    }

  protocol = get_string_property (instance,
                                  NPVARIANT_TO_OBJECT (location),
                                  "protocol");

  if (g_strcmp0 (protocol, "https:") != 0)
    {
      g_debug ("protocol does not match, is %s",
               protocol);

      goto out;
    }

  ret = TRUE;

 out:
  g_free (protocol);
  g_free (hostname);

  funcs.releasevariantvalue (&location);
  funcs.releasevariantvalue (&document);

  if (window != NULL)
    funcs.releaseobject (window);
  return ret;
}
Esempio n. 10
-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);
}