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; }
bool xplayerNPObject::GetObjectFromArguments (const NPVariant* argv, uint32_t argc, uint32_t argNum, NPObject*& _result) { if (!CheckArg (argv, argc, argNum, NPVariantType_Object)) return false; NPVariant arg = argv[argNum]; if (NPVARIANT_IS_STRING (arg)) { _result = NPVARIANT_TO_OBJECT (arg); } else if (NPVARIANT_IS_NULL (arg) || NPVARIANT_IS_VOID (arg)) { _result = NULL; } return true; }
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; }
bool xplayerNPObject::GetNPStringFromArguments (const NPVariant* argv, uint32_t argc, uint32_t argNum, NPString& _result) { if (!CheckArg (argv, argc, argNum, NPVariantType_String)) return false; NPVariant arg = argv[argNum]; if (NPVARIANT_IS_STRING (arg)) { _result = NPVARIANT_TO_STRING (arg); } else if (NPVARIANT_IS_NULL (arg) || NPVARIANT_IS_VOID (arg)) { _result.UTF8Characters = NULL; _result.UTF8Length = 0; } return true; }
static bool getURLNotify(PluginObject* obj, const NPVariant* args, uint32_t argCount, NPVariant* result) { if (argCount != 3 || !NPVARIANT_IS_STRING(args[0]) || (!NPVARIANT_IS_STRING(args[1]) && !NPVARIANT_IS_NULL(args[1])) || !NPVARIANT_IS_STRING(args[2])) return false; NPUTF8* urlString = createCStringFromNPVariant(&args[0]); NPUTF8* targetString = (NPVARIANT_IS_STRING(args[1]) ? createCStringFromNPVariant(&args[1]) : 0); NPUTF8* callbackString = createCStringFromNPVariant(&args[2]); NPIdentifier callbackIdentifier = browser->getstringidentifier(callbackString); browser->geturlnotify(obj->npp, urlString, targetString, callbackIdentifier); free(urlString); free(targetString); free(callbackString); VOID_TO_NPVARIANT(*result); return true; }
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"); } }
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; }
bool StatementObject::Invoke(NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result) { //sprintf(tmp, "stmt Invoke [%s]\n", NPN_UTF8FromIdentifier(name)); log(tmp); NPError rc; VOID_TO_NPVARIANT(*result); int index = 0; if (name == mc_Init_id) { if (argCount < 2) { NPN_SetException(this, "Too few parameters count"); return true; } #if 0 if (!(NPVARIANT_IS_INT32(args[0]) && NPVARIANT_IS_OBJECT(args[1]))) { NPN_SetException(this, "Wrong argument type"); return true; } SQLHANDLE hdbc = (SQLHANDLE)(long)NPVARIANT_TO_INT32(args[0]); #else if (!(NPVARIANT_IS_OBJECT(args[0]) && NPVARIANT_IS_OBJECT(args[1]))) { NPN_SetException(this, "Wrong argument type"); return true; } SQLHANDLE hdbc = (SQLHANDLE)NPVARIANT_TO_OBJECT(args[0]); #endif Init(hdbc, NPVARIANT_TO_OBJECT(args[1])); return true; } else if (name == mc_AddParameter_id) { if (argCount < 1) { NPN_SetException(this, "Too few parameters count"); return true; } AddParam(args); return true; } else if (name == mc_Execute_id) { if (argCount < 1) { NPN_SetException(this, "Too few parameters count"); return true; } if (!NPVARIANT_IS_STRING(args[0])) { NPN_SetException(this, "Wrong argument type"); return true; } Execute((NPString*)&NPVARIANT_TO_STRING(args[0])); return true; } else if (name == mc_Close_id) { Close(); return true; } else if (name == mc_Fetch_id) { bool ret; rc = Fetch(&ret); if (rc != NPERR_NO_ERROR) return true; BOOLEAN_TO_NPVARIANT(ret, *result); return true; } else if (name == mc_MoreResults_id) { bool ret; rc = MoreResults(&ret); if (rc != NPERR_NO_ERROR) return true; BOOLEAN_TO_NPVARIANT(ret, *result); return true; } else if (name == mc_GetColumnName_id) { const char *ret; if (argCount < 1) { NPN_SetException(this, "Too few parameters count"); return true; } if (NPVARIANT_IS_INT32(args[0])) index = NPVARIANT_TO_INT32(args[0]); else if (NPVARIANT_IS_DOUBLE(args[0])) index = (int)NPVARIANT_TO_DOUBLE(args[0]); else { NPN_SetException(this, "Wrong argument type"); return true; } rc = GetColumnName(index, &ret); if (rc != NPERR_NO_ERROR) return true; STRING_TO_NPVARIANT(ret, *result); return true; } else if (name == mc_GetVariant_id) { if (argCount < 1) { NPN_SetException(this, "Too few parameters count"); return true; } if (NPVARIANT_IS_INT32(args[0])) index = NPVARIANT_TO_INT32(args[0]); else if (NPVARIANT_IS_DOUBLE(args[0])) index = (int)NPVARIANT_TO_DOUBLE(args[0]); else { NPN_SetException(this, "Wrong argument type"); return true; } GetVariant(index, result); return true; } else if (name == mc_GetColumnType_id) { int ret; if (argCount < 1) { NPN_SetException(this, "Too few parameters count"); return true; } if (NPVARIANT_IS_INT32(args[0])) index = NPVARIANT_TO_INT32(args[0]); else if (NPVARIANT_IS_DOUBLE(args[0])) index = (int)NPVARIANT_TO_DOUBLE(args[0]); else { NPN_SetException(this, "Wrong argument type"); return true; } rc = GetColumnType(index, &ret); if (rc != NPERR_NO_ERROR) return true; INT32_TO_NPVARIANT(ret, *result); return true; } else if (name == mc_IsColumnNullable_id) { bool ret; if (argCount < 1) { NPN_SetException(this, "Too few parameters count"); return true; } if (NPVARIANT_IS_INT32(args[0])) index = NPVARIANT_TO_INT32(args[0]); else if (NPVARIANT_IS_DOUBLE(args[0])) index = (int)NPVARIANT_TO_DOUBLE(args[0]); else { NPN_SetException(this, "Wrong argument type"); return true; } rc = IsColumnNullable(index, &ret); if (rc != NPERR_NO_ERROR) return true; BOOLEAN_TO_NPVARIANT(ret, *result); return true; } else if (name == mc_GetTables_id) { if (argCount < 4) { NPN_SetException(this, "Too few parameters count"); return true; } if (!(NPVARIANT_IS_NULL(args[0]) || NPVARIANT_IS_STRING(args[0]))) { NPN_SetException(this, "Wrong 1 argument type"); return true; } if (!(NPVARIANT_IS_NULL(args[1]) || NPVARIANT_IS_STRING(args[1]))) { NPN_SetException(this, "Wrong 2 argument type"); return true; } if (!(NPVARIANT_IS_NULL(args[2]) || NPVARIANT_IS_STRING(args[2]))) { NPN_SetException(this, "Wrong 3 argument type"); return true; } if (!(NPVARIANT_IS_NULL(args[3]) || NPVARIANT_IS_STRING(args[3]))) { NPN_SetException(this, "Wrong 4 argument type"); return true; } GetTables(&args[0], &args[1], &args[2], &args[3]); return true; } else if (name == mc_GetColumns_id) { if (argCount < 4) { NPN_SetException(this, "Too few parameters count"); return true; } if (!(NPVARIANT_IS_NULL(args[0]) || NPVARIANT_IS_STRING(args[0]))) { NPN_SetException(this, "Wrong 1 argument type"); return true; } if (!(NPVARIANT_IS_NULL(args[1]) || NPVARIANT_IS_STRING(args[1]))) { NPN_SetException(this, "Wrong 2 argument type"); return true; } if (!(NPVARIANT_IS_NULL(args[2]) || NPVARIANT_IS_STRING(args[2]))) { NPN_SetException(this, "Wrong 3 argument type"); return true; } if (!(NPVARIANT_IS_NULL(args[3]) || NPVARIANT_IS_STRING(args[3]))) { NPN_SetException(this, "Wrong 4 argument type"); return true; } GetColumns(&args[0], &args[1], &args[2], &args[3]); return true; } else if (name == mc_GetTypeInfo_id) { if (argCount < 1) { NPN_SetException(this, "Too few parameters count"); return true; } if (NPVARIANT_IS_INT32(args[0])) index = NPVARIANT_TO_INT32(args[0]); else if (NPVARIANT_IS_DOUBLE(args[0])) index = (int)NPVARIANT_TO_DOUBLE(args[0]); else { NPN_SetException(this, "Wrong argument type"); return true; } GetTypeInfo(index); return true; } else if (name == mc_GetPrimaryKeys_id) { if (argCount < 3) { NPN_SetException(this, "Too few parameters count"); return true; } if (!(NPVARIANT_IS_NULL(args[0]) || NPVARIANT_IS_STRING(args[0]))) { NPN_SetException(this, "Wrong 1 argument type"); return true; } if (!(NPVARIANT_IS_NULL(args[1]) || NPVARIANT_IS_STRING(args[1]))) { NPN_SetException(this, "Wrong 2 argument type"); return true; } if (!(NPVARIANT_IS_NULL(args[2]) || NPVARIANT_IS_STRING(args[2]))) { NPN_SetException(this, "Wrong 3 argument type"); return true; } GetPrimaryKeys(&args[0], &args[1], &args[2]); return true; } else if (name == mc_GetForeignKeys_id) { if (argCount < 6) { NPN_SetException(this, "Too few parameters count"); return true; } if (!(NPVARIANT_IS_NULL(args[0]) || NPVARIANT_IS_STRING(args[0]))) { NPN_SetException(this, "Wrong 1 argument type"); return true; } if (!(NPVARIANT_IS_NULL(args[1]) || NPVARIANT_IS_STRING(args[1]))) { NPN_SetException(this, "Wrong 2 argument type"); return true; } if (!(NPVARIANT_IS_NULL(args[2]) || NPVARIANT_IS_STRING(args[2]))) { NPN_SetException(this, "Wrong 3 argument type"); return true; } if (!(NPVARIANT_IS_NULL(args[3]) || NPVARIANT_IS_STRING(args[3]))) { NPN_SetException(this, "Wrong 4 argument type"); return true; } if (!(NPVARIANT_IS_NULL(args[4]) || NPVARIANT_IS_STRING(args[4]))) { NPN_SetException(this, "Wrong 5 argument type"); return true; } if (!(NPVARIANT_IS_NULL(args[5]) || NPVARIANT_IS_STRING(args[5]))) { NPN_SetException(this, "Wrong 6 argument type"); return true; } GetForeignKeys(&args[0], &args[1], &args[2], &args[3], &args[4], &args[5]); return true; } else if (name == mc_GetProcedures_id) { if (argCount < 3) { NPN_SetException(this, "Too few parameters count"); return true; } if (!(NPVARIANT_IS_NULL(args[0]) || NPVARIANT_IS_STRING(args[0]))) { NPN_SetException(this, "Wrong 1 argument type"); return true; } if (!(NPVARIANT_IS_NULL(args[1]) || NPVARIANT_IS_STRING(args[1]))) { NPN_SetException(this, "Wrong 2 argument type"); return true; } if (!(NPVARIANT_IS_NULL(args[2]) || NPVARIANT_IS_STRING(args[2]))) { NPN_SetException(this, "Wrong 3 argument type"); return true; } GetProcedures(&args[0], &args[1], &args[2]); return true; } else if (name == mc_GetProcedureColumns_id) { if (argCount < 4) { NPN_SetException(this, "Too few parameters count"); return true; } if (!(NPVARIANT_IS_NULL(args[0]) || NPVARIANT_IS_STRING(args[0]))) { NPN_SetException(this, "Wrong 1 argument type"); return true; } if (!(NPVARIANT_IS_NULL(args[1]) || NPVARIANT_IS_STRING(args[1]))) { NPN_SetException(this, "Wrong 2 argument type"); return true; } if (!(NPVARIANT_IS_NULL(args[2]) || NPVARIANT_IS_STRING(args[2]))) { NPN_SetException(this, "Wrong 3 argument type"); return true; } if (!(NPVARIANT_IS_NULL(args[3]) || NPVARIANT_IS_STRING(args[3]))) { NPN_SetException(this, "Wrong 4 argument type"); return true; } GetProcedureColumns(&args[0], &args[1], &args[2], &args[3]); return true; } return false; }
static bool pluginInvoke(NPObject *header, NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result) { PluginObject *obj = (PluginObject *)header; if (name == pluginMethodIdentifiers[ID_TEST_CALLBACK_METHOD]) { // call whatever method name we're given if (argCount > 0 && NPVARIANT_IS_STRING(args[0])) { NPObject *windowScriptObject; browser->getvalue(obj->npp, NPNVWindowNPObject, &windowScriptObject); NPUTF8* callbackString = createCStringFromNPVariant(&args[0]); NPIdentifier callbackIdentifier = browser->getstringidentifier(callbackString); free(callbackString); NPVariant browserResult; browser->invoke(obj->npp, windowScriptObject, callbackIdentifier, 0, 0, &browserResult); browser->releasevariantvalue(&browserResult); VOID_TO_NPVARIANT(*result); return true; } } else if (name == pluginMethodIdentifiers[ID_TEST_GETURL]) { if (argCount == 2 && NPVARIANT_IS_STRING(args[0]) && NPVARIANT_IS_STRING(args[1])) { NPUTF8* urlString = createCStringFromNPVariant(&args[0]); NPUTF8* targetString = createCStringFromNPVariant(&args[1]); browser->geturl(obj->npp, urlString, targetString); free(urlString); free(targetString); VOID_TO_NPVARIANT(*result); return true; } else if (argCount == 1 && NPVARIANT_IS_STRING(args[0])) { NPUTF8* urlString = createCStringFromNPVariant(&args[0]); browser->geturl(obj->npp, urlString, 0); free(urlString); VOID_TO_NPVARIANT(*result); return true; } } else if (name == pluginMethodIdentifiers[ID_REMOVE_DEFAULT_METHOD]) { pluginClass.invokeDefault = 0; VOID_TO_NPVARIANT(*result); return true; } else if (name == pluginMethodIdentifiers[ID_TEST_DOM_ACCESS]) { testDOMAccess(obj); VOID_TO_NPVARIANT(*result); return true; } else if (name == pluginMethodIdentifiers[ID_TEST_GET_URL_NOTIFY]) { if (argCount == 3 && NPVARIANT_IS_STRING(args[0]) && (NPVARIANT_IS_STRING(args[1]) || NPVARIANT_IS_NULL(args[1])) && NPVARIANT_IS_STRING(args[2])) { NPUTF8* urlString = createCStringFromNPVariant(&args[0]); NPUTF8* targetString = (NPVARIANT_IS_STRING(args[1]) ? createCStringFromNPVariant(&args[1]) : NULL); NPUTF8* callbackString = createCStringFromNPVariant(&args[2]); NPIdentifier callbackIdentifier = browser->getstringidentifier(callbackString); browser->geturlnotify(obj->npp, urlString, targetString, callbackIdentifier); free(urlString); free(targetString); free(callbackString); VOID_TO_NPVARIANT(*result); return true; } } else if (name == pluginMethodIdentifiers[ID_TEST_INVOKE_DEFAULT] && NPVARIANT_IS_OBJECT(args[0])) { NPObject *callback = NPVARIANT_TO_OBJECT(args[0]); NPVariant args[1]; NPVariant browserResult; STRINGZ_TO_NPVARIANT("test", args[0]); bool retval = browser->invokeDefault(obj->npp, callback, args, 1, &browserResult); if (retval) browser->releasevariantvalue(&browserResult); BOOLEAN_TO_NPVARIANT(retval, *result); return true; } else if (name == pluginMethodIdentifiers[ID_TEST_ENUMERATE]) { if (argCount == 2 && NPVARIANT_IS_OBJECT(args[0]) && NPVARIANT_IS_OBJECT(args[1])) { uint32_t count; NPIdentifier* identifiers; if (browser->enumerate(obj->npp, NPVARIANT_TO_OBJECT(args[0]), &identifiers, &count)) { NPObject* outArray = NPVARIANT_TO_OBJECT(args[1]); NPIdentifier pushIdentifier = browser->getstringidentifier("push"); for (uint32_t i = 0; i < count; i++) { NPUTF8* string = browser->utf8fromidentifier(identifiers[i]); if (!string) continue; NPVariant args[1]; STRINGZ_TO_NPVARIANT(string, args[0]); NPVariant browserResult; browser->invoke(obj->npp, outArray, pushIdentifier, args, 1, &browserResult); browser->releasevariantvalue(&browserResult); browser->memfree(string); } browser->memfree(identifiers); } VOID_TO_NPVARIANT(*result); return true; } return false; } else if (name == pluginMethodIdentifiers[ID_DESTROY_STREAM]) { NPError npError = browser->destroystream(obj->npp, obj->stream, NPRES_USER_BREAK); INT32_TO_NPVARIANT(npError, *result); return true; } else if (name == pluginMethodIdentifiers[ID_TEST_GETINTIDENTIFIER]) { if (argCount == 1) { NPIdentifier identifier; if (NPVARIANT_IS_DOUBLE(args[0])) { identifier = browser->getintidentifier((int)NPVARIANT_TO_DOUBLE(args[0])); INT32_TO_NPVARIANT((int32)identifier, *result); return true; } else if (NPVARIANT_IS_INT32(args[0])) { identifier = browser->getintidentifier((int)NPVARIANT_TO_INT32(args[0])); INT32_TO_NPVARIANT((int32)identifier, *result); return true; } } } else if (name == pluginMethodIdentifiers[ID_TEST_EVALUATE] && argCount == 1 && NPVARIANT_IS_STRING(args[0])) { NPObject *windowScriptObject; browser->getvalue(obj->npp, NPNVWindowNPObject, &windowScriptObject); NPString s = NPVARIANT_TO_STRING(args[0]); bool retval = browser->evaluate(obj->npp, windowScriptObject, &s, result); browser->releaseobject(windowScriptObject); return retval; } else if (name == pluginMethodIdentifiers[ID_TEST_GET_PROPERTY] && argCount > 0) { NPObject *object; browser->getvalue(obj->npp, NPNVWindowNPObject, &object); for (uint32_t i = 0; i < argCount; i++) { //assert(NPVARIANT_IS_STRING(args[i])); NPUTF8* propertyString = createCStringFromNPVariant(&args[i]); NPIdentifier propertyIdentifier = browser->getstringidentifier(propertyString); free(propertyString); NPVariant variant; bool retval = browser->getproperty(obj->npp, object, propertyIdentifier, &variant); browser->releaseobject(object); if (!retval) break; if (i + 1 < argCount) { //assert(NPVARIANT_IS_OBJECT(variant)); object = NPVARIANT_TO_OBJECT(variant); } else { *result = variant; return true; } } VOID_TO_NPVARIANT(*result); return false; } else if (name == pluginMethodIdentifiers[ID_TEST_GET_PROPERTY_RETURN_VALUE] && argCount == 2 && NPVARIANT_IS_OBJECT(args[0]) && NPVARIANT_IS_STRING(args[1])) { NPUTF8* propertyString = createCStringFromNPVariant(&args[1]); NPIdentifier propertyIdentifier = browser->getstringidentifier(propertyString); free(propertyString); NPVariant variant; bool retval = browser->getproperty(obj->npp, NPVARIANT_TO_OBJECT(args[0]), propertyIdentifier, &variant); if (retval) browser->releasevariantvalue(&variant); BOOLEAN_TO_NPVARIANT(retval, *result); return true; } else if (name == pluginMethodIdentifiers[ID_TEST_CALLBACK_METHOD_RET]) { // call whatever method name we're given, and pass it the 'window' obj. // we expect the function to return its argument. if (argCount > 0 && NPVARIANT_IS_STRING(args[0])) { NPObject *windowScriptObject; browser->getvalue(obj->npp, NPNVWindowNPObject, &windowScriptObject); NPUTF8* callbackString = createCStringFromNPVariant(&args[0]); NPIdentifier callbackIdentifier = browser->getstringidentifier(callbackString); free(callbackString); NPVariant callbackArgs[1]; OBJECT_TO_NPVARIANT(windowScriptObject, callbackArgs[0]); NPVariant browserResult; browser->invoke(obj->npp, windowScriptObject, callbackIdentifier, callbackArgs, 1, &browserResult); if (NPVARIANT_IS_OBJECT(browserResult)) { // Now return the callbacks return value back to our caller. // BUG 897451: This should be the same as the // windowScriptObject, but its not (in Chrome) - or at least, it // has a different refcount. This means Chrome will delete the // object before returning it and the calling JS gets a garbage // value. Firefox handles it fine. OBJECT_TO_NPVARIANT(NPVARIANT_TO_OBJECT(browserResult), *result); } else { browser->releasevariantvalue(&browserResult); VOID_TO_NPVARIANT(*result); } return true; } } else if (name == pluginMethodIdentifiers[ID_TEST_CREATE_TEST_OBJECT]) { NPObject *testObject = browser->createobject(obj->npp, getTestClass()); //assert(testObject->referenceCount == 1); OBJECT_TO_NPVARIANT(testObject, *result); return true; } else if (name == pluginMethodIdentifiers[ID_TEST_PASS_TEST_OBJECT]) { // call whatever method name we're given, and pass it our second // argument. if (argCount > 1 && NPVARIANT_IS_STRING(args[0])) { NPObject *windowScriptObject; browser->getvalue(obj->npp, NPNVWindowNPObject, &windowScriptObject); NPUTF8* callbackString = createCStringFromNPVariant(&args[0]); NPIdentifier callbackIdentifier = browser->getstringidentifier(callbackString); free(callbackString); NPVariant browserResult; browser->invoke(obj->npp, windowScriptObject, callbackIdentifier, &args[1], 1, &browserResult); browser->releasevariantvalue(&browserResult); VOID_TO_NPVARIANT(*result); return true; } } else if (name == pluginMethodIdentifiers[ID_TEST_CLONE_OBJECT]) { // Create another instance of the same class NPObject *new_object = browser->createobject(obj->npp, &pluginClass); //assert(new_object->referenceCount == 1); OBJECT_TO_NPVARIANT(new_object, *result); return true; } else if (name == pluginMethodIdentifiers[ID_TEST_SCRIPT_OBJECT_INVOKE]) { if (argCount > 1 && NPVARIANT_IS_STRING(args[0])) { // Invoke a script callback to get a script NPObject. Then call // a method on the script NPObject passing it a freshly created // NPObject. // Arguments: // arg1: Callback that returns a script object. // arg2: Name of the method to call on the script object returned // from the callback NPObject *windowScriptObject; browser->getvalue(obj->npp, NPNVWindowNPObject, &windowScriptObject); // Arg1 is the name of the callback NPUTF8* callbackString = createCStringFromNPVariant(&args[0]); NPIdentifier callbackIdentifier = browser->getstringidentifier(callbackString); free(callbackString); // Invoke a callback that returns a script object NPVariant object_result; browser->invoke(obj->npp, windowScriptObject, callbackIdentifier, &args[1], 1, &object_result); // Script object returned NPObject *script_object = object_result.value.objectValue; // Arg2 is the name of the method to be called on the script object NPUTF8* object_mehod_string = createCStringFromNPVariant(&args[1]); NPIdentifier object_method = browser->getstringidentifier(object_mehod_string); free(object_mehod_string); // Create a fresh NPObject to be passed as an argument NPObject *object_arg = browser->createobject(obj->npp, &pluginClass); NPVariant invoke_args[1]; OBJECT_TO_NPVARIANT(object_arg, invoke_args[0]); // Invoke the script method NPVariant object_method_result; browser->invoke(obj->npp, script_object, object_method, invoke_args, 1, &object_method_result); browser->releasevariantvalue(&object_result); VOID_TO_NPVARIANT(*result); if (NPVARIANT_IS_OBJECT(object_method_result)) { // Now return the callbacks return value back to our caller. // BUG 897451: This should be the same as the // windowScriptObject, but its not (in Chrome) - or at least, it // has a different refcount. This means Chrome will delete the // object before returning it and the calling JS gets a garbage // value. Firefox handles it fine. OBJECT_TO_NPVARIANT(NPVARIANT_TO_OBJECT(object_method_result), *result); } else { browser->releasevariantvalue(&object_method_result); VOID_TO_NPVARIANT(*result); } return true; } } return false; }
// Sends something like this: // <invoke name="TestASMethod" returntype="xml"> // <arguments> // <number>123</number> // </arguments> // </invoke> // // Receives: // An XML response of one of the standard types like Number or String. bool remoteCallback (NPObject *npobj, NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result) { // log_debug(__PRETTY_FUNCTION__); GnashPluginScriptObject *gpso = (GnashPluginScriptObject *)npobj; std::string method; #if 1 if (NPN_IdentifierIsString(name)) { log_debug("Invoking remote Method \"%s\"...", NPN_UTF8FromIdentifier(name)); method = NPN_UTF8FromIdentifier(name); } else { log_debug("Invoking remote Method: \"%d\"...", NPN_IntFromIdentifier(name)); } #endif // Build the argument array std::vector<std::string> fnargs; for (uint32_t i=0; i<argCount; ++i) { std::string xml = plugin::ExternalInterface::convertNPVariant(&args[i]); fnargs.push_back(xml); } std::string str = plugin::ExternalInterface::makeInvoke(method, fnargs); // 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 invoke %s, network problems.", method); return false; } // Have the read function allocate the memory std::string data = gpso->readPlayer(); if (data.empty()) { log_error("Couldn't read a response for invoke, network problems."); NULL_TO_NPVARIANT(*result); return false; } std::string answer; GnashNPVariant parsed = plugin::ExternalInterface::parseXML(data); if (!NPVARIANT_IS_NULL(parsed.get())) { answer = NPStringToString(NPVARIANT_TO_STRING(parsed.get())); } if (answer == "Error") { NULL_TO_NPVARIANT(*result); } else if (answer == "SecurityError") { NULL_TO_NPVARIANT(*result); } else { parsed.copy(*result); } // printNPVariant(&parsed.get()); // Returning false makes Javascript stop executing the script. return true; }
bool Any::IsNull() const { return NPVARIANT_IS_VOID(variant) || NPVARIANT_IS_NULL(variant); }
RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result) { /* is plugin still running */ if( isPluginRunning() ) { VlcPlugin* p_plugin = getPrivate<VlcPlugin>(); libvlc_exception_t ex; libvlc_exception_init(&ex); switch( index ) { // XXX FIXME this needs squashing into something much smaller case ID_playlist_add: { if( (argCount < 1) || (argCount > 3) ) return INVOKERESULT_NO_SUCH_METHOD; if( !NPVARIANT_IS_STRING(args[0]) ) return INVOKERESULT_NO_SUCH_METHOD; // grab URL char *s = stringValue(NPVARIANT_TO_STRING(args[0])); if( !s ) return INVOKERESULT_OUT_OF_MEMORY; char *url = p_plugin->getAbsoluteURL(s); if( url ) free(s); else // problem with combining url, use argument url = s; char *name = NULL; // grab name if available if( argCount > 1 ) { if( NPVARIANT_IS_NULL(args[1]) ) { // do nothing } else if( NPVARIANT_IS_STRING(args[1]) ) { name = stringValue(NPVARIANT_TO_STRING(args[1])); } else { free(url); return INVOKERESULT_INVALID_VALUE; } } int i_options = 0; char** ppsz_options = NULL; // grab options if available if( argCount > 2 ) { if( NPVARIANT_IS_NULL(args[2]) ) { // do nothing } else if( NPVARIANT_IS_STRING(args[2]) ) { parseOptions(NPVARIANT_TO_STRING(args[2]), &i_options, &ppsz_options); } else if( NPVARIANT_IS_OBJECT(args[2]) ) { parseOptions(NPVARIANT_TO_OBJECT(args[2]), &i_options, &ppsz_options); } else { free(url); free(name); return INVOKERESULT_INVALID_VALUE; } } int item = p_plugin->playlist_add_extended_untrusted(url, name, i_options, const_cast<const char **>(ppsz_options), &ex); free(url); free(name); for( int i=0; i< i_options; ++i ) { free(ppsz_options[i]); } free(ppsz_options); RETURN_ON_EXCEPTION(this,ex); INT32_TO_NPVARIANT(item, result); return INVOKERESULT_NO_ERROR; } case ID_playlist_play: if( argCount == 0 ) { p_plugin->playlist_play(&ex); RETURN_ON_EXCEPTION(this,ex); VOID_TO_NPVARIANT(result); return INVOKERESULT_NO_ERROR; } return INVOKERESULT_NO_SUCH_METHOD; case ID_playlist_playItem: if( (argCount == 1) && isNumberValue(args[0]) ) { p_plugin->playlist_play_item(numberValue(args[0]),&ex); RETURN_ON_EXCEPTION(this,ex); VOID_TO_NPVARIANT(result); return INVOKERESULT_NO_ERROR; } return INVOKERESULT_NO_SUCH_METHOD; case ID_playlist_togglepause: if( argCount == 0 ) { p_plugin->playlist_pause(&ex); RETURN_ON_EXCEPTION(this,ex); VOID_TO_NPVARIANT(result); return INVOKERESULT_NO_ERROR; } return INVOKERESULT_NO_SUCH_METHOD; case ID_playlist_stop: if( argCount == 0 ) { p_plugin->playlist_stop(&ex); RETURN_ON_EXCEPTION(this,ex); VOID_TO_NPVARIANT(result); return INVOKERESULT_NO_ERROR; } return INVOKERESULT_NO_SUCH_METHOD; case ID_playlist_next: if( argCount == 0 ) { p_plugin->playlist_next(&ex); RETURN_ON_EXCEPTION(this,ex); VOID_TO_NPVARIANT(result); return INVOKERESULT_NO_ERROR; } return INVOKERESULT_NO_SUCH_METHOD; case ID_playlist_prev: if( argCount == 0 ) { p_plugin->playlist_prev(&ex); RETURN_ON_EXCEPTION(this,ex); VOID_TO_NPVARIANT(result); return INVOKERESULT_NO_ERROR; } return INVOKERESULT_NO_SUCH_METHOD; case ID_playlist_clear: /* deprecated */ if( argCount == 0 ) { p_plugin->playlist_clear(&ex); RETURN_ON_EXCEPTION(this,ex); VOID_TO_NPVARIANT(result); return INVOKERESULT_NO_ERROR; } return INVOKERESULT_NO_SUCH_METHOD; case ID_playlist_removeitem: /* deprecated */ if( (argCount == 1) && isNumberValue(args[0]) ) { p_plugin->playlist_delete_item(numberValue(args[0]), &ex); RETURN_ON_EXCEPTION(this,ex); VOID_TO_NPVARIANT(result); return INVOKERESULT_NO_ERROR; } return INVOKERESULT_NO_SUCH_METHOD; default: ; } } return INVOKERESULT_GENERIC_ERROR; }
bool toString(void *object, const NPVariant *args, uint32_t argCount, NPVariant *result) { GenericNPObject *map = (GenericNPObject *)object; if (!map || map->invalid) return false; // no args expected or cared for... std::string out; std::vector<NPVariant>::iterator it; for (it = map->numeric_mapper.begin(); it < map->numeric_mapper.end(); ++it) { if (NPVARIANT_IS_VOID(*it)) { out += ","; } else if (NPVARIANT_IS_NULL(*it)) { out += ","; } else if (NPVARIANT_IS_BOOLEAN(*it)) { if ((*it).value.boolValue) { out += "true,"; } else { out += "false,"; } } else if (NPVARIANT_IS_INT32(*it)) { char tmp[50]; memset(tmp, 0, sizeof(tmp)); _snprintf(tmp, 49, "%d,", (*it).value.intValue); out += tmp; } else if (NPVARIANT_IS_DOUBLE(*it)) { char tmp[50]; memset(tmp, 0, sizeof(tmp)); _snprintf(tmp, 49, "%f,", (*it).value.doubleValue); out += tmp; } else if (NPVARIANT_IS_STRING(*it)) { out += (*it).value.stringValue.UTF8Characters; out += ","; } else if (NPVARIANT_IS_OBJECT(*it)) { out += "[object],"; } } // calculate how much space we need std::string::size_type size = out.length(); char *s = (char *)NPNFuncs.memalloc(size * sizeof(char)); if (NULL == s) { return false; } memcpy(s, out.c_str(), size); s[size - 1] = 0; // overwrite the last "," STRINGZ_TO_NPVARIANT(s, (*result)); return true; }