Ejemplo n.º 1
0
static bool pluginSetProperty(NPObject* obj, NPIdentifier name, const NPVariant* variant)
{
    PluginObject* plugin = reinterpret_cast<PluginObject*>(obj);
    if (name == pluginPropertyIdentifiers[ID_PROPERTY_EVENT_LOGGING]) {
        plugin->eventLogging = NPVARIANT_TO_BOOLEAN(*variant);
        return true;
    }
    if (name == pluginPropertyIdentifiers[ID_PROPERTY_LOG_DESTROY]) {
        plugin->logDestroy = NPVARIANT_TO_BOOLEAN(*variant);
        return true;
    }
    if (name == pluginPropertyIdentifiers[ID_PROPERTY_RETURN_ERROR_FROM_NEWSTREAM]) {
        plugin->returnErrorFromNewStream = NPVARIANT_TO_BOOLEAN(*variant);
        return true;
    }
    if (name == pluginPropertyIdentifiers[ID_PROPERTY_RETURN_NEGATIVE_ONE_FROM_WRITE]) {
        plugin->returnNegativeOneFromWrite = NPVARIANT_TO_BOOLEAN(*variant);
        return true;
    }
    if (name == pluginPropertyIdentifiers[ID_PROPERTY_THROW_EXCEPTION_PROPERTY]) {
        browser->setexception(obj, "plugin object testThrowExceptionProperty SUCCESS");
        return true;
    }
    if (name == pluginPropertyIdentifiers[ID_PROPERTY_WINDOWED_PLUGIN]) {
        browser->setvalue(plugin->npp, NPPVpluginWindowBool, (void *)NPVARIANT_TO_BOOLEAN(*variant));
        return true;
    }

    return false;
}
Ejemplo n.º 2
0
static bool pluginSetProperty(NPObject *obj, NPIdentifier name, const NPVariant *variant)
{
    if (name == pluginPropertyIdentifiers[ID_PROPERTY_EVENT_LOGGING]) {
        ((PluginObject *)obj)->eventLogging = NPVARIANT_TO_BOOLEAN(*variant);
        return true;
    } else if (name == pluginPropertyIdentifiers[ID_PROPERTY_LOG_DESTROY]) {
        ((PluginObject *)obj)->logDestroy = NPVARIANT_TO_BOOLEAN(*variant);
        return true;
    }
    
    return false;
}
Ejemplo n.º 3
0
bool ScriptablePluginObject::SetProperty(NPIdentifier name, const NPVariant *value)
{
    if (!m_plugin)
        return false;

    std::string str;
    std::stringstream ss;
    bool boolean = false;
    unsigned short val = -1;

    if (NPVARIANT_IS_STRING(*value))
    {
        str.assign(NPVARIANT_TO_STRING(*value).UTF8Characters,
                   NPVARIANT_TO_STRING(*value).UTF8Length);
    }
    else if (NPVARIANT_IS_BOOLEAN(*value))
    {
        boolean = NPVARIANT_TO_BOOLEAN(*value);
    }
    else if (NPVARIANT_IS_INT32(*value))
    {
        val = NPVARIANT_TO_INT32(*value);
        ss << val;
        ss >> str;
    }
Ejemplo n.º 4
0
void
ShockerScriptableControlObject::GetTestDefinition (const NPVariant *args, uint32_t arg_count, NPVariant *result)
{
	char *test_definition;
	bool free_test_definition = false;
	char *retval;
	bool isJson = false;
	
	g_assert (arg_count <= 1);

	LOG_PLUGIN ("[%i shocker] ShockerScriptableControlObject::GetTestDefinition ()\n", getpid ());

	test_definition = getenv ("MOONLIGHT_HARNESS_TESTDEFINITION");

	if (test_definition == NULL) {

		if (arg_count > 0) {
			g_assert (NPVARIANT_IS_BOOLEAN (args [0]));
			isJson = NPVARIANT_TO_BOOLEAN (args [0]);
		}

		test_definition = LogProvider::GetInstance ()->GetTestDefinition (isJson);
		free_test_definition = true;
	}

	retval = NPN_strdup (test_definition == NULL ? "" : test_definition);
	
	STRINGZ_TO_NPVARIANT (retval, *result);
	if (free_test_definition)
		g_free (test_definition);
}
Ejemplo n.º 5
0
bool convert_js_to_mrb(NPP npp, const NPVariant &variant, mrb_state *mrb, mrb_value *result)
{
    switch(variant.type){
      case NPVariantType_Void:
      case NPVariantType_Null:
        *result = mrb_nil_value();
        return true;
      case NPVariantType_Bool:
        if (NPVARIANT_TO_BOOLEAN(variant)){
            *result = mrb_true_value();
        }else{
            *result = mrb_false_value();
        }
        return true;
      case NPVariantType_Int32:
        *result = mrb_fixnum_value(NPVARIANT_TO_INT32(variant));
        return true;
      case NPVariantType_Double:
        *result = mrb_float_value(NPVARIANT_TO_DOUBLE(variant));
        return true;
      case NPVariantType_String:
        *result = mrb_str_new(mrb, NPVARIANT_TO_STRING(variant).UTF8Characters,
                              NPVARIANT_TO_STRING(variant).UTF8Length);
        return true;
      case NPVariantType_Object:
        return convert_js_to_mrb_object(npp, variant, mrb, result);
      default:
        break;
    }
    return false;
}
Ejemplo n.º 6
0
v8::Handle<v8::Value> ConvertNPVariantToV8Object(const NPVariant* variant,
                                                 NPObject* npobject) {
  NPVariantType type = variant->type;

  if (type == NPVariantType_Int32) {
    return v8::Integer::New(NPVARIANT_TO_INT32(*variant));
  }
  if (type == NPVariantType_Double) {
    return v8::Number::New(NPVARIANT_TO_DOUBLE(*variant));
  }
  if (type == NPVariantType_Bool) {
    return NPVARIANT_TO_BOOLEAN(*variant) ? v8::True() : v8::False();
  }
  if (type == NPVariantType_Null) {
    return v8::Null();
  }
  if (type == NPVariantType_Void) {
    return v8::Undefined();
  }
  if (type == NPVariantType_String) {
    NPString src = NPVARIANT_TO_STRING(*variant);
    return v8::String::New(src.UTF8Characters, src.UTF8Length);
  }
  if (type == NPVariantType_Object) {
    NPObject* obj = NPVARIANT_TO_OBJECT(*variant);
    if (obj->_class == NPScriptObjectClass) {
      return reinterpret_cast<V8NPObject*>(obj)->v8_object;
    }
    return CreateV8ObjectForNPObject(obj, npobject);
  }
  return v8::Undefined();
}
Ejemplo n.º 7
0
v8::Handle<v8::Value> convertNPVariantToV8Object(const NPVariant* variant, NPObject* npobject)
{
    NPVariantType type = variant->type;

    switch (type) {
    case NPVariantType_Int32:
        return v8Integer(NPVARIANT_TO_INT32(*variant));
    case NPVariantType_Double:
        return v8::Number::New(NPVARIANT_TO_DOUBLE(*variant));
    case NPVariantType_Bool:
        return v8Boolean(NPVARIANT_TO_BOOLEAN(*variant));
    case NPVariantType_Null:
        return v8::Null();
    case NPVariantType_Void:
        return v8::Undefined();
    case NPVariantType_String: {
        NPString src = NPVARIANT_TO_STRING(*variant);
        return v8::String::New(src.UTF8Characters, src.UTF8Length);
    }
    case NPVariantType_Object: {
        NPObject* obj = NPVARIANT_TO_OBJECT(*variant);
        if (obj->_class == npScriptObjectClass)
            return reinterpret_cast<V8NPObject*>(obj)->v8Object;
        return createV8ObjectForNPObject(obj, npobject);
    }
    default:
        return v8::Undefined();
    }
}
Ejemplo n.º 8
0
v8::Handle<v8::Value> convertNPVariantToV8Object(const NPVariant* variant, NPObject* owner, v8::Isolate* isolate)
{
    NPVariantType type = variant->type;

    switch (type) {
    case NPVariantType_Int32:
        return v8::Integer::New(NPVARIANT_TO_INT32(*variant), isolate);
    case NPVariantType_Double:
        return v8::Number::New(isolate, NPVARIANT_TO_DOUBLE(*variant));
    case NPVariantType_Bool:
        return v8Boolean(NPVARIANT_TO_BOOLEAN(*variant), isolate);
    case NPVariantType_Null:
        return v8::Null(isolate);
    case NPVariantType_Void:
        return v8::Undefined(isolate);
    case NPVariantType_String: {
        NPString src = NPVARIANT_TO_STRING(*variant);
        return v8::String::NewFromUtf8(isolate, src.UTF8Characters, v8::String::kNormalString, src.UTF8Length);
    }
    case NPVariantType_Object: {
        NPObject* object = NPVARIANT_TO_OBJECT(*variant);
        if (V8NPObject* v8Object = npObjectToV8NPObject(object))
            return v8::Local<v8::Object>::New(isolate, v8Object->v8Object);
        return createV8ObjectForNPObject(object, owner, isolate);
    }
    default:
        return v8::Undefined(isolate);
    }
}
Ejemplo n.º 9
0
JSValue convertNPVariantToValue(ExecState* exec, const NPVariant* variant, RootObject* rootObject)
{
    JSLockHolder lock(exec);
    
    NPVariantType type = variant->type;

    if (type == NPVariantType_Bool)
        return jsBoolean(NPVARIANT_TO_BOOLEAN(*variant));
    if (type == NPVariantType_Null)
        return jsNull();
    if (type == NPVariantType_Void)
        return jsUndefined();
    if (type == NPVariantType_Int32)
        return jsNumber(NPVARIANT_TO_INT32(*variant));
    if (type == NPVariantType_Double)
        return jsNumber(NPVARIANT_TO_DOUBLE(*variant));
    if (type == NPVariantType_String)
        return WebCore::jsString(exec, convertNPStringToUTF16(&variant->value.stringValue));
    if (type == NPVariantType_Object) {
        NPObject* obj = variant->value.objectValue;
        
        if (obj->_class == NPScriptObjectClass)
            // Get JSObject from NP_JavaScriptObject.
            return ((JavaScriptObject*)obj)->imp;

        // Wrap NPObject in a CInstance.
        return CInstance::create(obj, rootObject)->createRuntimeObject(exec);
    }
    
    return jsUndefined();
}
Ejemplo n.º 10
0
void
ShockerScriptableControlObject::SendKeyInput (const NPVariant *args, uint32_t arg_count, NPVariant *result)
{
	g_assert (arg_count >= 4);
	g_assert (NPVARIANT_IS_NUMBER (args [0]));
	g_assert (NPVARIANT_IS_BOOLEAN (args [1]));
	g_assert (NPVARIANT_IS_BOOLEAN (args [2]));
	g_assert (NPVARIANT_IS_BOOLEAN (args [3]));

	LOG_PLUGIN ("[%i shocker] ShockerScriptableControlObject::SendKeyInput (key_code: %i, key_down: %i extended: %i, unicode: %i)\n", getpid (),
		NUMBER_TO_INT32 (args [0]), NPVARIANT_TO_BOOLEAN (args [1]), NPVARIANT_TO_BOOLEAN (args [2]), NPVARIANT_TO_BOOLEAN (args [3]));

	GetInputProvider ()->SendKeyInput (NUMBER_TO_INT32 (args [0]), NPVARIANT_TO_BOOLEAN (args [1]),
		NPVARIANT_TO_BOOLEAN (args [2]), NPVARIANT_TO_BOOLEAN (args [3]));

	BOOLEAN_TO_NPVARIANT (true, *result);
}
bool PluginMethodListenOnFile::ExecuteListenOnFile(
  const NPVariant *args,
  uint32_t argCount,
  NPVariant *result) {
  std::string filename;
  bool skip_to_end = false;

  try {
    if (argCount < 3 ||
      !NPVARIANT_IS_STRING(args[0]) ||
      !NPVARIANT_IS_BOOLEAN(args[1]) ||
      !NPVARIANT_IS_OBJECT(args[2])) {
      NPN_SetException(
        object_, 
        "invalid or missing params passed to function - expecting 3 params: "
        "filename, skipToEnd, callback(status, data)");
      return false;
    }

    callback_ = NPVARIANT_TO_OBJECT(args[2]);
    skip_to_end = NPVARIANT_TO_BOOLEAN(args[1]);

    // add ref count to callback object so it won't delete
    NPN_RetainObject(callback_);

    filename.append(
      NPVARIANT_TO_STRING(args[0]).UTF8Characters,
      NPVARIANT_TO_STRING(args[0]).UTF8Length);  
  } catch(...) {

  }

  if (nullptr == thread_.get()) {
    thread_.reset(new utils::Thread);
    if (!thread_->Start()) {
      NPN_SetException(
        __super::object_,
        "an unexpected error occurred - couldn't start file listening thread");
      return false;
    }
  }

  std::wstring wide_filename = utils::Encoders::utf8_decode(filename);

  if (!file_stream_.Initialize(wide_filename.c_str(), this, skip_to_end)) {
    NPN_SetException(
      __super::object_,
      "an unexpected error occurred - couldn't open the file for read access");
    return false;
  }

  return thread_->PostTask(
    std::bind(
    &PluginMethodListenOnFile::StartListening,
    this));
}
Ejemplo n.º 12
0
static bool pluginSetProperty(NPObject* obj, NPIdentifier name, const NPVariant* variant)
{
    PluginObject* plugin = reinterpret_cast<PluginObject*>(obj);
    if (name == pluginPropertyIdentifiers[ID_PROPERTY_EVENT_LOGGING]) {
        plugin->eventLogging = NPVARIANT_TO_BOOLEAN(*variant);
        return true;
    } else if (name == pluginPropertyIdentifiers[ID_PROPERTY_LOG_DESTROY]) {
        plugin->logDestroy = NPVARIANT_TO_BOOLEAN(*variant);
        return true;
    } else if (name == pluginPropertyIdentifiers[ID_PROPERTY_RETURN_ERROR_FROM_NEWSTREAM]) {
        plugin->returnErrorFromNewStream = NPVARIANT_TO_BOOLEAN(*variant);
        return true;
    } else if (name == pluginPropertyIdentifiers[ID_PROPERTY_THROW_EXCEPTION_PROPERTY]) {
        browser->setexception(obj, "plugin object testThrowExceptionProperty SUCCESS");
        return true;
    }

    return false;
}
Ejemplo n.º 13
0
RuntimeNPObject::InvokeResult
LibvlcAudioNPObject::setProperty(int index, const NPVariant &value)
{
    /* is plugin still running */
    if( isPluginRunning() )
    {
        VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

        switch( index )
        {
            case ID_audio_mute:
                if( NPVARIANT_IS_BOOLEAN(value) )
                {
                    libvlc_audio_set_mute(p_plugin->getVLC(),
                                          NPVARIANT_TO_BOOLEAN(value), &ex);
                    RETURN_ON_EXCEPTION(this,ex);
                    return INVOKERESULT_NO_ERROR;
                }
                return INVOKERESULT_INVALID_VALUE;
            case ID_audio_volume:
                if( isNumberValue(value) )
                {
                    libvlc_audio_set_volume(p_plugin->getVLC(),
                                            numberValue(value), &ex);
                    RETURN_ON_EXCEPTION(this,ex);
                    return INVOKERESULT_NO_ERROR;
                }
                return INVOKERESULT_INVALID_VALUE;
            case ID_audio_track:
                if( isNumberValue(value) )
                {
                    libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
                    RETURN_ON_EXCEPTION(this,ex);
                    libvlc_audio_set_track(p_md, numberValue(value), &ex);
                    RETURN_ON_EXCEPTION(this,ex);
                    return INVOKERESULT_NO_ERROR;
                }
                return INVOKERESULT_INVALID_VALUE;
            case ID_audio_channel:
                if( isNumberValue(value) )
                {
                    libvlc_audio_set_channel(p_plugin->getVLC(),
                                             numberValue(value), &ex);
                    RETURN_ON_EXCEPTION(this,ex);
                    return INVOKERESULT_NO_ERROR;
                }
                return INVOKERESULT_INVALID_VALUE;
            default:
                ;
        }
    }
    return INVOKERESULT_GENERIC_ERROR;
}
Ejemplo n.º 14
0
void
ShockerScriptableControlObject::CompareImages (const NPVariant *args, uint32_t arg_count, NPVariant *result)
{
	guint8 res = false;

	g_assert (arg_count >= 5);
	g_assert (NPVARIANT_IS_STRING (args [0]));
	g_assert (NPVARIANT_IS_STRING (args [1]));
	g_assert (NPVARIANT_IS_NUMBER (args [2]));
	g_assert (NPVARIANT_IS_STRING (args [3]));
	g_assert (NPVARIANT_IS_BOOLEAN (args [4]));

	LOG_PLUGIN ("[%i shocker] ShockerScriptableControlObject::CompareImages (imageFile1: '%s', imageFile2: '%s', tolerance: %i, diffFileName: '%s', copySourceFiles: %i)\n", getpid (),
		STR_FROM_VARIANT (args [0]), STR_FROM_VARIANT (args [1]), NUMBER_TO_INT32 (args [2]),
		STR_FROM_VARIANT (args [3]), NPVARIANT_TO_BOOLEAN (args [4]));


	::CompareImages (STR_FROM_VARIANT (args [0]), STR_FROM_VARIANT (args [1]), NUMBER_TO_INT32 (args [2]),
		STR_FROM_VARIANT (args [3]), NPVARIANT_TO_BOOLEAN (args [4]), &res);
	
	BOOLEAN_TO_NPVARIANT ((bool) res, *result);
}
Ejemplo n.º 15
0
static
void
topmost_rect_ptac(void *param)
{
    struct topmost_rect_param_s *p = param;
    struct pp_instance_s *pp_i = tables_get_pp_instance(p->instance);
    if (!pp_i) {
        trace_error("%s, no instance\n", __func__);
        goto err_1;
    }

    p->result = PP_FALSE;

    NPString topmost_func_src = NPString_literal(
        "(function(elem, x, y) {"
            "var r = elem.getBoundingClientRect();"
            "return document.elementFromPoint(x + r.left, y + r.top) == elem;"
        "})");
    NPVariant topmost_func;

    if (!npn.evaluate(pp_i->npp, pp_i->np_window_obj, &topmost_func_src, &topmost_func))
        goto err_1;

    if (!NPVARIANT_IS_OBJECT(topmost_func))
        goto err_1;

    NPObject *topmost_func_obj = NPVARIANT_TO_OBJECT(topmost_func);

    NPVariant is_topmost;
    NPVariant args[3];

    OBJECT_TO_NPVARIANT(pp_i->np_plugin_element_obj, args[0]);
    INT32_TO_NPVARIANT(p->rect.point.x + p->rect.size.width / 2, args[1]);
    INT32_TO_NPVARIANT(p->rect.point.y + p->rect.size.height / 2, args[2]);

    if (!npn.invokeDefault(pp_i->npp, topmost_func_obj, args, 3, &is_topmost))
        goto err_2;

    if (!NPVARIANT_IS_BOOLEAN(is_topmost))
        goto err_3;

    p->result = NPVARIANT_TO_BOOLEAN(is_topmost);

err_3:
    npn.releasevariantvalue(&is_topmost);
err_2:
    npn.releasevariantvalue(&topmost_func);
err_1:
    ppb_message_loop_post_quit_depth(p->m_loop, PP_FALSE, p->depth);
}
Ejemplo n.º 16
0
Any convertToAny(NPP npp, const NPVariant* variant)
{
    switch (variant->type)
    {
    case NPVariantType_Void:
    case NPVariantType_Null:
        return Any();
        break;
    case NPVariantType_Bool:
        return NPVARIANT_TO_BOOLEAN(*variant);
        break;
    case NPVariantType_Int32:
        return NPVARIANT_TO_INT32(*variant);
        break;
    case NPVariantType_Double:
        return NPVARIANT_TO_DOUBLE(*variant);
        break;
    case NPVariantType_String:
        return std::string(NPVARIANT_TO_STRING(*variant).utf8characters, NPVARIANT_TO_STRING(*variant).utf8length);
        break;
    case NPVariantType_Object:
    {
        NPObject* object = NPVARIANT_TO_OBJECT(*variant);
        if (!object)
        {
            break;
        }
        if (StubObject::isStub(object))
        {
            StubObject* stub = static_cast<StubObject*>(object);
            return stub->getObject();
        }
        PluginInstance* instance = static_cast<PluginInstance*>(npp->pdata);
        if (instance)
        {
            ProxyControl* proxyControl = instance->getProxyControl();
            if (proxyControl)
            {
                return proxyControl->createProxy(object);
            }
        }
        break;
    }
    default:
        break;
    }
    return Any();
}
Ejemplo n.º 17
0
static bool
plugin_object_invoke (NPObject        *npobj,
		      NPIdentifier     name,
		      const NPVariant *args,
		      uint32_t         argc,
		      NPVariant       *result)
{
  PluginObject *obj;

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

  g_debug ("invoking plugin object method");

  obj = (PluginObject*) npobj;

  VOID_TO_NPVARIANT (*result);

  if (name == list_extensions_id)
    return plugin_list_extensions (obj, result);
  else if (name == get_metadata_id)
    {
      g_return_val_if_fail (argc >= 1, FALSE);
      g_return_val_if_fail (NPVARIANT_IS_STRING(args[0]), FALSE);

      return plugin_get_metadata (obj, NPVARIANT_TO_STRING(args[0]), result);
    }
  else if (name == enable_extension_id)
    {
      g_return_val_if_fail (argc >= 2, FALSE);
      g_return_val_if_fail (NPVARIANT_IS_STRING(args[0]), FALSE);
      g_return_val_if_fail (NPVARIANT_IS_BOOLEAN(args[1]), FALSE);

      return plugin_enable_extension (obj,
				      NPVARIANT_TO_STRING(args[0]),
				      NPVARIANT_TO_BOOLEAN(args[1]));
    }
  else if (name == install_extension_id)
    {
      g_return_val_if_fail (argc >= 1, FALSE);
      g_return_val_if_fail (NPVARIANT_IS_STRING(args[0]), FALSE);

      return plugin_install_extension (obj,
				       NPVARIANT_TO_STRING(args[0]));
    }

  return TRUE;
}
Ejemplo n.º 18
0
// IsPlaying()
//
// Sends this:
// <invoke name="IsPlaying" returntype="xml">
//      <arguments></arguments>
// </invoke>
//
// Receives something like this:
//      </true/>
bool
IsPlaying (NPObject *npobj, NPIdentifier /* name */, const NPVariant */*args */,
           uint32_t argCount, NPVariant *result)
{
    log_debug(__PRETTY_FUNCTION__);

    GnashPluginScriptObject *gpso = (GnashPluginScriptObject *)npobj;

    if (argCount == 0) {
        std::vector<std::string> iargs;
        std::string str = plugin::ExternalInterface::makeInvoke("IsPlaying", iargs);

        // Write the message to the Control FD.
        size_t ret = gpso->writePlayer(str);
        // Unless we wrote the same amount of data as the message contained,
        // something went wrong.
        if (ret != str.size()) {
            log_error("Couldn't check if the movie is playing, network problems.");
            BOOLEAN_TO_NPVARIANT(false, *result);
            return false;
        }
        std::string data = gpso->readPlayer();
        if (data.empty()) {
            BOOLEAN_TO_NPVARIANT(false, *result);
            return false;
        }

        GnashNPVariant value = plugin::ExternalInterface::parseXML(data);
        if (NPVARIANT_TO_BOOLEAN(value.get()) == true) {
            BOOLEAN_TO_NPVARIANT(true, *result);
        } else {
            BOOLEAN_TO_NPVARIANT(false, *result);
        }

        return true;
    }

    BOOLEAN_TO_NPVARIANT(false, *result);
    return false;
}
Ejemplo n.º 19
0
static Eina_Bool ewk_js_npvariant_to_variant(Ewk_JS_Variant* data, const NPVariant* result)
{
    EINA_SAFETY_ON_NULL_RETURN_VAL(data, false);
    EINA_SAFETY_ON_NULL_RETURN_VAL(result, false);
    switch (result->type) {
    case NPVariantType_Void:
        data->type = EWK_JS_VARIANT_VOID;
        data->value.o = 0;
        break;
    case NPVariantType_Null:
        data->type = EWK_JS_VARIANT_NULL;
        data->value.o = 0;
        break;
    case NPVariantType_Int32:
        data->type = EWK_JS_VARIANT_INT32;
        data->value.i = NPVARIANT_TO_INT32(*result);
        break;
    case NPVariantType_Double:
        data->type = EWK_JS_VARIANT_DOUBLE;
        data->value.d = NPVARIANT_TO_DOUBLE(*result);
        break;
    case NPVariantType_String:
        data->value.s = eina_stringshare_add_length(NPVARIANT_TO_STRING(*result).UTF8Characters, NPVARIANT_TO_STRING(*result).UTF8Length);
        data->type = EWK_JS_VARIANT_STRING;
        break;
    case NPVariantType_Bool:
        data->type = EWK_JS_VARIANT_BOOL;
        data->value.b = NPVARIANT_TO_BOOLEAN(*result);
        break;
    case NPVariantType_Object:
        data->type = EWK_JS_VARIANT_OBJECT;
        data->value.o = ewk_js_npobject_to_object(NPVARIANT_TO_OBJECT(*result));
        break;
    default:
        return false;
    }

    return true;
}
Ejemplo n.º 20
0
void
printNPVariant(const NPVariant *value)
{
    if (NPVARIANT_IS_DOUBLE(*value)) {
        double num = NPVARIANT_TO_DOUBLE(*value);
        log_debug("is double, value %g", num);
    } else if (NPVARIANT_IS_STRING(*value)) {
        std::string str = NPStringToString(NPVARIANT_TO_STRING(*value));
        log_debug("is string, value %s", str);
    } else if (NPVARIANT_IS_BOOLEAN(*value)) {
        bool flag = NPVARIANT_TO_BOOLEAN(*value);
        log_debug("is boolean, value %d", flag);
    } else if (NPVARIANT_IS_INT32(*value)) {
        int num = NPVARIANT_TO_INT32(*value);
        log_debug("is int, value %d", num);
    } else if (NPVARIANT_IS_NULL(*value)) {
        log_debug("value is null");
    } else if (NPVARIANT_IS_VOID(*value)) {
        log_debug("value is void");
    } else if (NPVARIANT_IS_OBJECT(*value)) {
        log_debug("value is object");
    }    
}
Ejemplo n.º 21
0
bool
xplayerNPObject::GetBoolFromArguments (const NPVariant* argv,
                                     uint32_t argc,
                                     uint32_t argNum,
                                     bool& _result)
{
  if (!CheckArg (argv, argc, argNum, NPVariantType_Bool))
    return false;

  NPVariant arg = argv[argNum];
  if (NPVARIANT_IS_BOOLEAN (arg)) {
    _result = NPVARIANT_TO_BOOLEAN (arg);
  } else if (NPVARIANT_IS_INT32 (arg)) {
    _result = NPVARIANT_TO_INT32 (arg) != 0;
  } else if (NPVARIANT_IS_DOUBLE (arg)) {
    _result = NPVARIANT_TO_DOUBLE (arg) != 0.0;
  } else {
    /* void/null */
    _result = false;
  }

  return true;
}
Ejemplo n.º 22
0
JSValue *convertNPVariantToValue(ExecState*, const NPVariant* variant, RootObject* rootObject)
{
    JSLock lock;
    
    NPVariantType type = variant->type;

    if (type == NPVariantType_Bool)
        return jsBoolean(NPVARIANT_TO_BOOLEAN(*variant));
    if (type == NPVariantType_Null)
        return jsNull();
    if (type == NPVariantType_Void)
        return jsUndefined();
    if (type == NPVariantType_Int32)
        return jsNumber(NPVARIANT_TO_INT32(*variant));
    if (type == NPVariantType_Double)
        return jsNumber(NPVARIANT_TO_DOUBLE(*variant));
    if (type == NPVariantType_String) {
        NPUTF16 *stringValue;
        unsigned int UTF16Length;
        convertNPStringToUTF16(&variant->value.stringValue, &stringValue, &UTF16Length); // requires free() of returned memory
        UString resultString((const UChar *)stringValue,UTF16Length);
        free(stringValue);
        return jsString(resultString);
    }
    if (type == NPVariantType_Object) {
        NPObject *obj = variant->value.objectValue;
        
        if (obj->_class == NPScriptObjectClass)
            // Get JSObject from NP_JavaScriptObject.
            return ((JavaScriptObject *)obj)->imp;

        // Wrap NPObject in a CInstance.
        return Instance::createRuntimeObject(Instance::CLanguage, obj, rootObject);
    }
    
    return jsUndefined();
}
Ejemplo n.º 23
0
	// This function is equivalent to the following JavaScript function:
	// function FireEvent(strEventType, strDetail) {
	//   FireIEContainer.dispatchEvent(strEventType, strDetail)
	// }
	// 
	// Uses following JavaScript code to listen to the event fired:
	// pluginObject.addEventListener(strEventType, function(event) {
	//    alert(event.detail);
	// }
	BOOL CPlugin::FireEvent(const CString &strEventType, const CString &strDetail)
	{
		// Fast event dispatching, requires helper function in container object
		try
		{
			// FireIEContainer.dispatchEvent(strEventType, strDetail);
			NPObject* pContainer = GetContainer();
			NPVariant args[2];
			STRINGZ_TO_NPVARIANT(CStringToNPStringCharacters(strEventType), args[0]);
			STRINGZ_TO_NPVARIANT(CStringToNPStringCharacters(strDetail), args[1]);
			NPVariant vSucceeded;
			VOID_TO_NPVARIANT(vSucceeded);

			BOOL bOK = NPN_Invoke(m_pNPInstance, pContainer, GetIdentifier("dispatchEvent"), args, 2, &vSucceeded);
				
			for (int i = 0; i < 2; i++)
				NPN_ReleaseVariantValue(&args[i]);

			if (!bOK || !NPVARIANT_IS_BOOLEAN(vSucceeded))
			{
				NPN_ReleaseVariantValue(&vSucceeded);
				throw CString(_T("Cannot invoke dispatchEvent"));
			}
			bool bSucceeded = NPVARIANT_TO_BOOLEAN(vSucceeded);
			NPN_ReleaseVariantValue(&vSucceeded);
			if (!bSucceeded)
				throw CString(_T("Event dispatch failed"));

			return TRUE;
		}
		catch (const CString& strMessage)
		{
			UNUSED(strMessage);
			TRACE(_T("[CPlugin::FireEvent Exception] Fast event dispatching failed: %s\n"), strMessage);
			return FALSE;
		}
	}
Ejemplo n.º 24
0
NPError 
StatementObject::AddParam(const NPVariant *value)
{
  nsODBCParam* pRec = NULL;

  if (NPVARIANT_IS_VOID(*value) || NPVARIANT_IS_NULL(*value)) {
    pRec = new nsODBCParam();

  } else if (NPVARIANT_IS_BOOLEAN(*value)) {
    pRec = new nsODBCParam(NPVARIANT_TO_BOOLEAN(*value));

  } else if (NPVARIANT_IS_INT32(*value)) {
    pRec = new nsODBCParam(NPVARIANT_TO_INT32(*value));

  } else if (NPVARIANT_IS_DOUBLE(*value)) {
    double data = NPVARIANT_TO_DOUBLE(*value);
    double delta = ceil(data);

    if (data-0.000000001 <delta  && data+0.000000001 > delta)
        pRec = new nsODBCParam((int)data);
    else
        pRec = new nsODBCParam(data);
    //--pRec = new nsODBCParam(NPVARIANT_TO_DOUBLE(*value));

  } else if (NPVARIANT_IS_STRING(*value)) {
    pRec = new nsODBCParam((NPString*)&NPVARIANT_TO_STRING(*value));

  } else {
    NPN_SetException(this, "Unsupported parameter type");
    return NPERR_GENERIC_ERROR;
  }

  if (pRec)
    m_params.push_back(pRec);
  return NPERR_NO_ERROR;
}
Ejemplo n.º 25
0
jvalue convertNPVariantToJValue(NPVariant value, JNIType jniType, const char* javaClassName)
{
    jvalue result;
    NPVariantType type = value.type;

    switch (jniType) {
    case array_type:
    case object_type:
        {
            result.l = static_cast<jobject>(0);

            // First see if we have a Java instance.
            if (type == NPVariantType_Object) {
                NPObject* objectImp = NPVARIANT_TO_OBJECT(value);
                if (JavaInstance* instance = ExtractJavaInstance(objectImp))
                    result.l = instance->javaInstance();
            }

            // Now convert value to a string if the target type is a java.lang.string, and we're not
            // converting from a Null.
            if (!result.l && !strcmp(javaClassName, "java.lang.String")) {
#ifdef CONVERT_NULL_TO_EMPTY_STRING
                if (type == NPVariantType_Null) {
                    JNIEnv* env = getJNIEnv();
                    jchar buf[2];
                    jobject javaString = env->functions->NewString(env, buf, 0);
                    result.l = javaString;
                } else
#else
                if (type == NPVariantType_String)
#endif
                {
                    NPString src = NPVARIANT_TO_STRING(value);
                    JNIEnv* env = getJNIEnv();
                    jobject javaString = env->NewStringUTF(src.UTF8Characters);
                    result.l = javaString;
                }
            } else if (!result.l)
                memset(&result, 0, sizeof(jvalue)); // Handle it the same as a void case
        }
        break;

    case boolean_type:
        {
            if (type == NPVariantType_Bool)
                result.z = NPVARIANT_TO_BOOLEAN(value);
            else
                memset(&result, 0, sizeof(jvalue)); // as void case
        }
        break;

    case byte_type:
        {
            if (type == NPVariantType_Int32)
                result.b = static_cast<char>(NPVARIANT_TO_INT32(value));
            else
                memset(&result, 0, sizeof(jvalue));
        }
        break;

    case char_type:
        {
            if (type == NPVariantType_Int32)
                result.c = static_cast<char>(NPVARIANT_TO_INT32(value));
            else
                memset(&result, 0, sizeof(jvalue));
        }
        break;

    case short_type:
        {
            if (type == NPVariantType_Int32)
                result.s = static_cast<jshort>(NPVARIANT_TO_INT32(value));
            else
                memset(&result, 0, sizeof(jvalue));
        }
        break;

    case int_type:
        {
            if (type == NPVariantType_Int32)
                result.i = static_cast<jint>(NPVARIANT_TO_INT32(value));
            else
                memset(&result, 0, sizeof(jvalue));
        }
        break;

    case long_type:
        {
            if (type == NPVariantType_Int32)
                result.j = static_cast<jlong>(NPVARIANT_TO_INT32(value));
            else if (type == NPVariantType_Double)
                result.j = static_cast<jlong>(NPVARIANT_TO_DOUBLE(value));
            else
                memset(&result, 0, sizeof(jvalue));
        }
        break;

    case float_type:
        {
            if (type == NPVariantType_Int32)
                result.f = static_cast<jfloat>(NPVARIANT_TO_INT32(value));
            else if (type == NPVariantType_Double)
                result.f = static_cast<jfloat>(NPVARIANT_TO_DOUBLE(value));
            else
                memset(&result, 0, sizeof(jvalue));
        }
        break;

    case double_type:
        {
            if (type == NPVariantType_Int32)
                result.d = static_cast<jdouble>(NPVARIANT_TO_INT32(value));
            else if (type == NPVariantType_Double)
                result.d = static_cast<jdouble>(NPVARIANT_TO_DOUBLE(value));
            else
                memset(&result, 0, sizeof(jvalue));
        }
        break;

        break;

    case invalid_type:
    default:
    case void_type:
        {
            memset(&result, 0, sizeof(jvalue));
        }
        break;
    }
    return result;
}
Ejemplo n.º 26
0
RuntimeNPObject::InvokeResult
LibvlcVideoNPObject::setProperty(int index, const NPVariant &value)
{
    /* is plugin still running */
    if( isPluginRunning() )
    {
        VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

        libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
        RETURN_ON_EXCEPTION(this,ex);

        switch( index )
        {
            case ID_video_fullscreen:
            {
                if( ! NPVARIANT_IS_BOOLEAN(value) )
                {
                    return INVOKERESULT_INVALID_VALUE;
                }

                int val = NPVARIANT_TO_BOOLEAN(value);
                p_plugin->set_fullscreen(val, &ex);
                RETURN_ON_EXCEPTION(this,ex);
                return INVOKERESULT_NO_ERROR;
            }
            case ID_video_aspectratio:
            {
                char *psz_aspect = NULL;

                if( ! NPVARIANT_IS_STRING(value) )
                {
                    return INVOKERESULT_INVALID_VALUE;
                }

                psz_aspect = stringValue(NPVARIANT_TO_STRING(value));
                if( !psz_aspect )
                {
                    return INVOKERESULT_GENERIC_ERROR;
                }

                libvlc_video_set_aspect_ratio(p_md, psz_aspect, &ex);
                free(psz_aspect);
                RETURN_ON_EXCEPTION(this,ex);

                return INVOKERESULT_NO_ERROR;
            }
            case ID_video_subtitle:
            {
                if( isNumberValue(value) )
                {
                    libvlc_video_set_spu(p_md, numberValue(value), &ex);
                    RETURN_ON_EXCEPTION(this,ex);

                    return INVOKERESULT_NO_ERROR;
                }
                return INVOKERESULT_INVALID_VALUE;
            }
            case ID_video_crop:
            {
                char *psz_geometry = NULL;

                if( ! NPVARIANT_IS_STRING(value) )
                {
                    return INVOKERESULT_INVALID_VALUE;
                }

                psz_geometry = stringValue(NPVARIANT_TO_STRING(value));
                if( !psz_geometry )
                {
                    return INVOKERESULT_GENERIC_ERROR;
                }

                libvlc_video_set_crop_geometry(p_md, psz_geometry, &ex);
                free(psz_geometry);
                RETURN_ON_EXCEPTION(this,ex);

                return INVOKERESULT_NO_ERROR;
            }
            case ID_video_teletext:
            {
                if( isNumberValue(value) )
                {
                    libvlc_video_set_teletext(p_md, numberValue(value), &ex);
                    RETURN_ON_EXCEPTION(this,ex);

                    return INVOKERESULT_NO_ERROR;
                }
                return INVOKERESULT_INVALID_VALUE;
            }
        }
    }
    return INVOKERESULT_GENERIC_ERROR;
}
Ejemplo n.º 27
0
// This function is equivalent to the following JavaScript function:
// function FireEvent(strEventType, strDetail) {
//   var event = document.createEvent("CustomEvent");
//   event.initCustomEvent(strEventType, true, true, strDetail);
//   pluginObject.dispatchEvent(event);
// }
// 
// Uses following JavaScript code to listen to the event fired:
// pluginObject.addEventListener(strEventType, function(event) {
//    alert(event.detail);
// }
BOOL CPlugin::FireEvent(const CString &strEventType, const CString &strDetail)
{
  BOOL bOK = FALSE;
  NPObject* pWindow = NULL;
  NPVariant vDocument;
  VOID_TO_NPVARIANT(vDocument);
  NPVariant vEvent;
  NPObject* pDocument = NULL;
  VOID_TO_NPVARIANT(vEvent);
  NPObject *pEvent = NULL;
  NPObject* pPlugin = NULL;

  try
  {
    // get window object
    if (NPN_GetValue(m_pNPInstance, NPNVWindowNPObject, &pWindow) != NPERR_NO_ERROR || pWindow == NULL)
    {
      throw CString(_T("Cannot get window"));
    }

    // get window.document
    bOK = NPN_GetProperty(m_pNPInstance, pWindow, NPN_GetStringIdentifier("document"), &vDocument);
    if (!NPVARIANT_IS_OBJECT(vDocument) || !bOK)
    {
      throw CString(_T("Cannot get window.document"));
    }
    pDocument = NPVARIANT_TO_OBJECT(vDocument);

    // var event = document.createEvent("CustomEvent");
    if (pDocument) 
    {
      NPVariant arg;
      STRINGZ_TO_NPVARIANT(CStringToNPStringCharacters(_T("CustomEvent")), arg);
      bOK = NPN_Invoke(m_pNPInstance, pDocument, NPN_GetStringIdentifier("createEvent"), &arg, 1, &vEvent);
      NPN_ReleaseVariantValue(&arg);
      if (!NPVARIANT_IS_OBJECT(vEvent) || !bOK)
      {
        throw CString(_T("Cannot document.createEvent"));
      }
    }
    else 
    {
      throw CString(_T("window.document is null"));
    }
    pEvent = NPVARIANT_TO_OBJECT(vEvent);;

    // event.initCustomEvent(strEventType, true, true, strDetail);
    if (pEvent)
    {
      NPVariant args[4];
      STRINGZ_TO_NPVARIANT(CStringToNPStringCharacters(strEventType), args[0]);
      BOOLEAN_TO_NPVARIANT(true, args[1]);
      BOOLEAN_TO_NPVARIANT(true, args[2]);
      STRINGZ_TO_NPVARIANT(CStringToNPStringCharacters(strDetail), args[3]);
      NPVariant vResult;
      bOK = NPN_Invoke(m_pNPInstance, pEvent, NPN_GetStringIdentifier("initCustomEvent"), args, 4, &vResult);
      for (int i=0; i<4; i++)
      {
        NPN_ReleaseVariantValue(&args[i]);
      }
      NPN_ReleaseVariantValue(&vResult);
      if (!bOK)
      {
        throw CString(_T("Cannot event.initCustomEvent"));
      }
    }
    else
    {
      throw CString(_T("event is null"));
    }

    // get plugin object
    if (NPN_GetValue(m_pNPInstance, NPNVPluginElementNPObject, &pPlugin) != NPERR_NO_ERROR || pPlugin == NULL)
    {
      throw CString(_T("Cannot get window"));
    }


    // pluginObject.dispatchEvent(event);
    NPVariant vNotCanceled; 
    bOK = NPN_Invoke(m_pNPInstance, pPlugin, NPN_GetStringIdentifier("dispatchEvent"), &vEvent, 1, &vNotCanceled);
    NPN_ReleaseVariantValue(&vEvent);
    if (!bOK || !NPVARIANT_IS_BOOLEAN(vNotCanceled)) 
    {
      throw CString(_T("Cannot dispatchEvent"));
    }
    if (NPVARIANT_TO_BOOLEAN(vNotCanceled) != true)
    {
      throw CString(_T("Event is canceled"));
    }
  }
  catch (CString strMessage)
  {
    TRACE(_T("[CPlugin::FireEvent Exception] %s"), strMessage);
    bOK = FALSE;
  }
  if (pPlugin != NULL) NPN_ReleaseObject(pPlugin);
  if (!NPVARIANT_IS_VOID(vEvent))	NPN_ReleaseVariantValue(&vEvent);
  if (!NPVARIANT_IS_VOID(vDocument))	NPN_ReleaseVariantValue(&vDocument);
  if (pWindow != NULL) NPN_ReleaseObject(pWindow);
  return bOK;
}
// listenOnFile(id, filename, skipToEnd, callback(status, data) )
bool PluginMethodListenOnFile::ExecuteListenOnFile(
  const NPVariant *args,
  uint32_t argCount,
  NPVariant *result) {
  std::string id;
  std::string filename;
  bool skip_to_end = false;
  NPObject* callback = nullptr;

  try {
    if (argCount < 4 ||
      !NPVARIANT_IS_STRING(args[0]) ||
      !NPVARIANT_IS_STRING(args[1]) ||
      !NPVARIANT_IS_BOOLEAN(args[2]) ||
      !NPVARIANT_IS_OBJECT(args[3])) {
      NPN_SetException(
        object_, 
        "invalid or missing params passed to function - expecting 4 params: "
        "id, filename, skipToEnd, callback(id, status, data)");
      return false;
    }

    callback = NPVARIANT_TO_OBJECT(args[3]);
    skip_to_end = NPVARIANT_TO_BOOLEAN(args[2]);

    // add ref count to callback object so it won't delete
    NPN_RetainObject(callback);

    id.append(
      NPVARIANT_TO_STRING(args[0]).UTF8Characters,
      NPVARIANT_TO_STRING(args[0]).UTF8Length);

    filename.append(
      NPVARIANT_TO_STRING(args[1]).UTF8Characters,
      NPVARIANT_TO_STRING(args[1]).UTF8Length);  
  } catch(...) {

  }


  TextFileThreadMap::iterator iter = threads_.find(id);
  if (iter != threads_.end()) {
    if (!iter->second.first->StopListening()) {
      NPN_SetException(
        __super::object_,
        "an unexpected error occurred - couldn't stop existing listener");
      return false;
    }
    
    if (!iter->second.second->Stop()) {
      NPN_SetException(
        __super::object_,
        "an unexpected error occurred - couldn't stop existing listener thread");
      return false;
    }
  }

  std::wstring wide_filename = utils::Encoders::utf8_decode(filename);
  threads_.insert(
    std::pair<std::string, TextFileThread>(
      id, 
      TextFileThread(new utils::TxtFileStream, new utils::Thread)));
  if (!threads_[id].first->Initialize(
    id.c_str(),
    wide_filename.c_str(), 
    this, 
    skip_to_end)) {
    NPN_SetException(
      __super::object_,
      "an unexpected error occurred - couldn't open the file for read access");
    return false;
  }
  
  if (!threads_[id].second->Start()) {
    NPN_SetException(
      __super::object_,
      "an unexpected error occurred - couldn't start file listening thread");
    return false;
  }

  // set a callback
  TextFileIdToCallbackMap::iterator iter_callback = ids_to_callbacks_.find(id);
  if (iter_callback != ids_to_callbacks_.end()) {
    if (nullptr != ids_to_callbacks_[id]) {
      NPN_ReleaseObject(ids_to_callbacks_[id]);
    }
  }

  ids_to_callbacks_[id] = callback;

  char* id_to_pass = new char[id.size()+1];
  strcpy(id_to_pass, id.c_str());

  return threads_[id].second->PostTask(
    std::bind(
    &PluginMethodListenOnFile::StartListening,
    this,
    id_to_pass));
}
Ejemplo n.º 29
0
JavaValue convertNPVariantToJavaValue(NPVariant value, const String& javaClass)
{
    CString javaClassName = javaClass.utf8();
    JavaType javaType = javaTypeFromClassName(javaClassName.data());
    JavaValue result;
    result.m_type = javaType;
    NPVariantType type = value.type;

    switch (javaType) {
    case JavaTypeArray:
    case JavaTypeObject:
        {
            // See if we have a Java instance.
            if (type == NPVariantType_Object) {
                NPObject* objectImp = NPVARIANT_TO_OBJECT(value);
                result.m_objectValue = ExtractJavaInstance(objectImp);
            }
        }
        break;

    case JavaTypeString:
        {
#ifdef CONVERT_NULL_TO_EMPTY_STRING
            if (type == NPVariantType_Null) {
                result.m_type = JavaTypeString;
                result.m_stringValue = String::fromUTF8("");
            } else
#else
            if (type == NPVariantType_String)
#endif
            {
                NPString src = NPVARIANT_TO_STRING(value);
                result.m_type = JavaTypeString;
                result.m_stringValue = String::fromUTF8(src.UTF8Characters);
            }
        }
        break;

    case JavaTypeBoolean:
        {
            if (type == NPVariantType_Bool)
                result.m_booleanValue = NPVARIANT_TO_BOOLEAN(value);
        }
        break;

    case JavaTypeByte:
        {
            if (type == NPVariantType_Int32)
                result.m_byteValue = static_cast<signed char>(NPVARIANT_TO_INT32(value));
            else if (type == NPVariantType_Double)
                result.m_byteValue = static_cast<signed char>(NPVARIANT_TO_DOUBLE(value));
        }
        break;

    case JavaTypeChar:
        {
            if (type == NPVariantType_Int32)
                result.m_charValue = static_cast<unsigned short>(NPVARIANT_TO_INT32(value));
        }
        break;

    case JavaTypeShort:
        {
            if (type == NPVariantType_Int32)
                result.m_shortValue = static_cast<short>(NPVARIANT_TO_INT32(value));
            else if (type == NPVariantType_Double)
                result.m_shortValue = static_cast<short>(NPVARIANT_TO_DOUBLE(value));
        }
        break;

    case JavaTypeInt:
        {
            if (type == NPVariantType_Int32)
                result.m_intValue = static_cast<int>(NPVARIANT_TO_INT32(value));
            else if (type == NPVariantType_Double)
                result.m_intValue = static_cast<int>(NPVARIANT_TO_DOUBLE(value));
        }
        break;

    case JavaTypeLong:
        {
            if (type == NPVariantType_Int32)
                result.m_longValue = static_cast<long long>(NPVARIANT_TO_INT32(value));
            else if (type == NPVariantType_Double)
                result.m_longValue = static_cast<long long>(NPVARIANT_TO_DOUBLE(value));
        }
        break;

    case JavaTypeFloat:
        {
            if (type == NPVariantType_Int32)
                result.m_floatValue = static_cast<float>(NPVARIANT_TO_INT32(value));
            else if (type == NPVariantType_Double)
                result.m_floatValue = static_cast<float>(NPVARIANT_TO_DOUBLE(value));
        }
        break;

    case JavaTypeDouble:
        {
            if (type == NPVariantType_Int32)
                result.m_doubleValue = static_cast<double>(NPVARIANT_TO_INT32(value));
            else if (type == NPVariantType_Double)
                result.m_doubleValue = static_cast<double>(NPVARIANT_TO_DOUBLE(value));
        }
        break;
    default:
        break;
    }
    return result;
}
static bool
plugin_object_invoke (NPObject        *npobj,
                      NPIdentifier     name,
                      const NPVariant *args,
                      uint32_t         argc,
                      NPVariant       *result)
{
  PluginObject *obj;

  g_debug ("invoking plugin object method");

  obj = (PluginObject*) npobj;

  VOID_TO_NPVARIANT (*result);

  if (!plugin_object_has_method (npobj, name))
    return FALSE;

  if (name == list_extensions_id)
    return plugin_list_extensions (obj, result);
  else if (name == get_info_id)
    {
      if (!NPVARIANT_IS_STRING(args[0])) return FALSE;

      return plugin_get_info (obj, NPVARIANT_TO_STRING(args[0]), result);
    }
  else if (name == enable_extension_id)
    {
      if (!NPVARIANT_IS_STRING(args[0])) return FALSE;
      if (!NPVARIANT_IS_BOOLEAN(args[1])) return FALSE;

      return plugin_enable_extension (obj,
                                      NPVARIANT_TO_STRING(args[0]),
                                      NPVARIANT_TO_BOOLEAN(args[1]));
    }
  else if (name == install_extension_id)
    {
      if (!NPVARIANT_IS_STRING(args[0])) return FALSE;
      if (!NPVARIANT_IS_STRING(args[1])) return FALSE;

      return plugin_install_extension (obj,
                                       NPVARIANT_TO_STRING(args[0]),
                                       NPVARIANT_TO_STRING(args[1]));
    }
  else if (name == uninstall_extension_id)
    {
      if (!NPVARIANT_IS_STRING(args[0])) return FALSE;

      return plugin_uninstall_extension (obj,
                                         NPVARIANT_TO_STRING(args[0]),
                                         result);
    }
  else if (name == get_errors_id)
    {
      if (!NPVARIANT_IS_STRING(args[0])) return FALSE;

      return plugin_get_errors (obj,
                                NPVARIANT_TO_STRING(args[0]),
                                result);
    }
  else if (name == launch_extension_prefs_id)
    {
      if (!NPVARIANT_IS_STRING(args[0])) return FALSE;

      return plugin_launch_extension_prefs (obj,
                                            NPVARIANT_TO_STRING(args[0]),
                                            result);
    }

  return TRUE;
}