static Eina_Bool ewk_js_variant_to_npvariant(const Ewk_JS_Variant* data, NPVariant* result) { EINA_SAFETY_ON_NULL_RETURN_VAL(data, false); EINA_SAFETY_ON_NULL_RETURN_VAL(result, false); const char* string_value; switch (data->type) { case EWK_JS_VARIANT_VOID: VOID_TO_NPVARIANT(*result); break; case EWK_JS_VARIANT_NULL: NULL_TO_NPVARIANT(*result); break; case EWK_JS_VARIANT_INT32: INT32_TO_NPVARIANT(data->value.i, *result); break; case EWK_JS_VARIANT_DOUBLE: DOUBLE_TO_NPVARIANT(data->value.d, *result); break; case EWK_JS_VARIANT_STRING: string_value = eina_stringshare_add(data->value.s); if (string_value) STRINGZ_TO_NPVARIANT(string_value, *result); else return false; break; case EWK_JS_VARIANT_BOOL: BOOLEAN_TO_NPVARIANT(data->value.b, *result); break; case EWK_JS_VARIANT_OBJECT: OBJECT_TO_NPVARIANT(reinterpret_cast<NPObject*>(data->value.o), *result); break; default: return false; } return true; }
// Variant value must be released with NPReleaseVariantValue() void convertValueToNPVariant(ExecState* exec, JSValue* value, NPVariant* result) { JSLock lock(false); VOID_TO_NPVARIANT(*result); if (value->isString()) { UString ustring = value->toString(exec); CString cstring = ustring.UTF8String(); NPString string = { (const NPUTF8*)cstring.c_str(), static_cast<uint32_t>(cstring.size()) }; NPN_InitializeVariantWithStringCopy(result, &string); } else if (value->isNumber()) { DOUBLE_TO_NPVARIANT(value->toNumber(exec), *result); } else if (value->isBoolean()) { BOOLEAN_TO_NPVARIANT(value->toBoolean(exec), *result); } else if (value->isNull()) { NULL_TO_NPVARIANT(*result); } else if (value->isObject()) { JSObject* object = static_cast<JSObject*>(value); if (object->classInfo() == &RuntimeObjectImp::s_info) { RuntimeObjectImp* imp = static_cast<RuntimeObjectImp*>(value); CInstance* instance = static_cast<CInstance*>(imp->getInternalInstance()); if (instance) { NPObject* obj = instance->getObject(); _NPN_RetainObject(obj); OBJECT_TO_NPVARIANT(obj, *result); } } else { JSGlobalObject* globalObject = exec->dynamicGlobalObject(); RootObject* rootObject = findRootObject(globalObject); if (rootObject) { NPObject* npObject = _NPN_CreateScriptObject(0, object, rootObject); OBJECT_TO_NPVARIANT(npObject, *result); } } } }
// Variant value must be released with NPReleaseVariantValue() void convertValueToNPVariant(ExecState* exec, JSValue value, NPVariant* result) { JSLock lock(SilenceAssertionsOnly); VOID_TO_NPVARIANT(*result); if (value.isString()) { UString ustring = value.toString(exec)->value(exec); CString cstring = ustring.utf8(); NPString string = { (const NPUTF8*)cstring.data(), static_cast<uint32_t>(cstring.length()) }; NPN_InitializeVariantWithStringCopy(result, &string); } else if (value.isNumber()) { DOUBLE_TO_NPVARIANT(value.toNumber(exec), *result); } else if (value.isBoolean()) { BOOLEAN_TO_NPVARIANT(value.toBoolean(exec), *result); } else if (value.isNull()) { NULL_TO_NPVARIANT(*result); } else if (value.isObject()) { JSObject* object = asObject(value); if (object->classInfo() == &CRuntimeObject::s_info) { CRuntimeObject* runtimeObject = static_cast<CRuntimeObject*>(object); CInstance* instance = runtimeObject->getInternalCInstance(); if (instance) { NPObject* obj = instance->getObject(); _NPN_RetainObject(obj); OBJECT_TO_NPVARIANT(obj, *result); } } else { JSGlobalObject* globalObject = exec->dynamicGlobalObject(); RootObject* rootObject = findRootObject(globalObject); if (rootObject) { NPObject* npObject = _NPN_CreateScriptObject(0, object, rootObject); OBJECT_TO_NPVARIANT(npObject, *result); } } } }
void testNPRuntime(NPP npp) { NPObject* windowScriptObject; browser->getvalue(npp, NPNVWindowNPObject, &windowScriptObject); // Invoke NPIdentifier testNPInvoke = browser->getstringidentifier("testNPInvoke"); NPVariant args[7]; VOID_TO_NPVARIANT(args[0]); NULL_TO_NPVARIANT(args[1]); BOOLEAN_TO_NPVARIANT(true, args[2]); INT32_TO_NPVARIANT(242, args[3]); DOUBLE_TO_NPVARIANT(242.242, args[4]); STRINGZ_TO_NPVARIANT("Hello, World", args[5]); OBJECT_TO_NPVARIANT(windowScriptObject, args[6]); NPVariant result; if (browser->invoke(npp, windowScriptObject, testNPInvoke, args, 7, &result)) browser->releasevariantvalue(&result); browser->releaseobject(windowScriptObject); }
bool JavaNPObjectGetProperty(NPObject* obj, NPIdentifier identifier, NPVariant* result) { VOID_TO_NPVARIANT(*result); JavaInstance* instance = ExtractJavaInstance(obj); if (!instance) return false; NPUTF8* name = _NPN_UTF8FromIdentifier(identifier); if (!name) return false; instance->begin(); JavaField* field = instance->getClass()->fieldNamed(name); free(name); // TODO: use NPN_MemFree if (!field) return false; JavaValue value = instance->getField(field); instance->end(); convertJavaValueToNPVariant(value, result); return true; }
// 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; } }
JSValue* CInstance::invokeDefaultMethod(ExecState* exec, const List& args) { if (!_object->_class->invokeDefault) return jsUndefined(); unsigned count = args.size(); Vector<NPVariant, 128> cArgs(count); unsigned i; for (i = 0; i < count; i++) convertValueToNPVariant(exec, args.at(i), &cArgs[i]); // Invoke the 'C' method. NPVariant resultVariant; VOID_TO_NPVARIANT(resultVariant); _object->_class->invokeDefault(_object, cArgs, count, &resultVariant); for (i = 0; i < count; i++) _NPN_ReleaseVariantValue(&cArgs[i]); JSValue* resultValue = convertNPVariantToValue(exec, &resultVariant); _NPN_ReleaseVariantValue(&resultVariant); return resultValue; }
static v8::Handle<v8::Value> npObjectSetProperty(v8::Local<v8::Object> self, NPIdentifier identifier, v8::Local<v8::Value> value, v8::Isolate* isolate) { NPObject* npObject = v8ObjectToNPObject(self); // Verify that our wrapper wasn't using a NPObject which has already been deleted. if (!npObject || !_NPN_IsAlive(npObject)) { throwError(v8ReferenceError, "NPObject deleted", isolate); return value; // Intercepted, but an exception was thrown. } if (npObject->_class->hasProperty && npObject->_class->setProperty && npObject->_class->hasProperty(npObject, identifier)) { if (!_NPN_IsAlive(npObject)) return throwError(v8ReferenceError, "NPObject deleted", isolate); NPVariant npValue; VOID_TO_NPVARIANT(npValue); convertV8ObjectToNPVariant(value, npObject, &npValue); bool success = npObject->_class->setProperty(npObject, identifier, &npValue); _NPN_ReleaseVariantValue(&npValue); if (success) return value; // Intercept the call. } return v8Undefined(); }
bool xplayerNPObject::VoidVariant (NPVariant* _result) { VOID_TO_NPVARIANT (*_result); return true; }
bool ScriptablePluginObject::Invoke(NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result) /* name : method name args : arguments argCount : number of arguments result : return value */ { NPIdentifier test_id = NPN_GetStringIdentifier("test"); if (name == test_id) { printf("temp = %s\n",getTemporaryPath()); printf("home = %s\n",getHomePath()); printf("firefox = %s\n",getFirefoxPath()); printf("conf = %s\n",getConfPath()); printf("classpath = %s\n",getClassPath()); printf("spawn = %s\n",getSpawnPath()); VOID_TO_NPVARIANT(*result); return true; } NPError err; if (!this->HasMethod(name)) return false; VOID_TO_NPVARIANT(*result); //login.jsp test NPIdentifier doSignature_id = NPN_GetStringIdentifier("doSignature"); NPIdentifier getPublicKeyContent_id = NPN_GetStringIdentifier("getPublicKeyContent"); NPObject* sWindowNPObj; if ((err = NPN_GetValue(mNpp, NPNVWindowNPObject, &sWindowNPObj)) != NPERR_NO_ERROR) { printf("Error in getting NPNVWindowNPObject: %d\n",err); return false; } const char *tmpdir = getTemporaryPath(); const char *classpath = getClassPath(); const char *spawnpath = getSpawnPath(); if (name == doSignature_id) { if ((argCount == 2) && (NPVARIANT_IS_STRING(args[0])) && (NPVARIANT_IS_STRING(args[1]))) { char *randomStr = NULL; char *tpmPass = NULL; NPString n_randomStr = NPVARIANT_TO_STRING(args[0]); NPString n_tpmPass = NPVARIANT_TO_STRING(args[1]); m_strFromNP(&randomStr,n_randomStr); m_strFromNP(&tpmPass,n_tpmPass); printf("input = %s, %s",randomStr, tpmPass); char* ret = NULL; char *fname = tempnam(tmpdir,"jni"); if (fname == NULL) fname = "tmp"; char* margs[12]; margs[0] = (char*) spawn_file; margs[1] = "--file"; margs[2] = fname; margs[3] = "--method"; margs[4] = "doSignature"; margs[5] = "--classpath"; margs[6] = (char*) classpath; margs[7] = "--args"; margs[8] = "2"; margs[9] = randomStr; margs[10] = tpmPass; margs[11] = NULL; // in windows use registry to find Firefox directory // in other OS, use path _spawnvp int rval = _spawnv(_P_WAIT,spawnpath,margs); if (rval) { fprintf(stderr,"error = %d\n",rval); } else { ret = getFileContent(fname); if (ret) { STRINGZ_TO_NPVARIANT(ret,*result); } else { fprintf(stderr,"cannot read output file"); } unlink(fname); } free(fname); } else { NPString str; str.UTF8Characters = "alert('usage: doSignature(String, String)');"; str.UTF8Length = strlen(str.UTF8Characters); NPN_Evaluate(this->mNpp, sWindowNPObj, &str, NULL); } } else if (name == getPublicKeyContent_id) { if (argCount == 0) { char *ret = NULL; char *fname = tempnam(tmpdir,"jni"); if (fname == NULL) fname = "tmp"; char* margs[8]; margs[0] = (char*) spawn_file; margs[1] = "--file"; margs[2] = fname; margs[3] = "--method"; margs[4] = "getPublicKeyContent"; margs[5] = "--classpath"; margs[6] = (char*) classpath; margs[7] = NULL; int rval = _spawnv(_P_WAIT,spawnpath,margs); if (rval) { fprintf(stderr,"error = %d\n",rval); } else { ret = getFileContent(fname); if (ret) { STRINGZ_TO_NPVARIANT(ret,*result); } else { fprintf(stderr,"cannot read output file"); } unlink(fname); } free(fname); } else { NPString str; str.UTF8Characters = "alert('usage: getPublicKeyContent()');"; str.UTF8Length = strlen(str.UTF8Characters); NPN_Evaluate(this->mNpp, sWindowNPObj, &str, NULL); } } NPN_ReleaseObject(sWindowNPObj); return true; }
RuntimeNPObject::InvokeResult LibvlcAudioNPObject::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 ) { case ID_audio_togglemute: if( argCount == 0 ) { libvlc_audio_toggle_mute(p_plugin->getVLC(), &ex); RETURN_ON_EXCEPTION(this,ex); VOID_TO_NPVARIANT(result); return INVOKERESULT_NO_ERROR; } return INVOKERESULT_NO_SUCH_METHOD; case ID_audio_description: { if( argCount == 1) { char *psz_name; int i_trackID, i_limit, i; libvlc_track_description_t *p_trackDesc; libvlc_media_player_t *p_md = p_plugin->getMD(&ex); RETURN_ON_EXCEPTION(this,ex); /* get tracks description */ p_trackDesc = libvlc_audio_get_track_description(p_md, &ex); RETURN_ON_EXCEPTION(this,ex); if( !p_trackDesc ) return INVOKERESULT_GENERIC_ERROR; /* get the number of track available */ i_limit = libvlc_audio_get_track_count(p_md, &ex); RETURN_ON_EXCEPTION(this,ex); /* check if a number is given by the user * and get the track number */ if( isNumberValue(args[0]) ) i_trackID = numberValue(args[0]); else return INVOKERESULT_INVALID_VALUE; /* if bad number is given return invalid value */ if ( ( i_trackID > ( i_limit - 1 ) ) || ( i_trackID < 0 ) ) return INVOKERESULT_INVALID_VALUE; /* get the good trackDesc */ for( i = 0 ; i < i_trackID ; i++ ) { p_trackDesc = p_trackDesc->p_next; } psz_name = p_trackDesc->psz_name; /* display the name of the track chosen */ return invokeResultString( psz_name, result ); } return INVOKERESULT_NO_SUCH_METHOD; } default: ; } } return INVOKERESULT_GENERIC_ERROR; }
bool ScriptablePluginObject::GetProperty(NPIdentifier name, NPVariant *result) { if (m_pMainWindow == NULL) return false; // readonly property {string} URL if (name == m_URLID) { CString URL = m_pMainWindow->GetURL(); STRINGZ_TO_NPVARIANT(CStringToNPStringCharacters(URL), *result); return true; } // readonly property {title} LocationURL else if (name == m_TitleID) { CString title = m_pMainWindow->GetTitle(); STRINGZ_TO_NPVARIANT(CStringToNPStringCharacters(title), *result); return true; } // readonly property {boolean} CanRefresh else if (name == m_CanRefreshID) { BOOL canRefresh = m_pMainWindow->GetCanRefresh(); BOOLEAN_TO_NPVARIANT(canRefresh, *result); return true; } // readonly property {boolean} CanStop else if (name == m_CanStopID) { BOOL canStop = m_pMainWindow->GetCanStop(); BOOLEAN_TO_NPVARIANT(canStop, *result); return true; } // readonly property {boolean} CanBack else if (name == m_CanBackID) { BOOL canBack = m_pMainWindow->GetCanBack(); BOOLEAN_TO_NPVARIANT(canBack, *result); return true; } // readonly property {boolean} CanForward else if (name == m_CanForwardID) { BOOL canForward = m_pMainWindow->GetCanForward(); BOOLEAN_TO_NPVARIANT(canForward, *result); return true; } // readonly property {boolean} CanCopy else if (name == m_CanCopyID) { BOOL canCopy = m_pMainWindow->GetCanCopy(); BOOLEAN_TO_NPVARIANT(canCopy, *result); return true; } // readonly property {boolean} CanCut else if (name == m_CanCutID) { BOOL canCut = m_pMainWindow->GetCanCut(); BOOLEAN_TO_NPVARIANT(canCut, *result); return true; } // readonly property {boolean} CanPaste else if (name == m_CanPasteID) { BOOL canPaste = m_pMainWindow->GetCanPaste(); BOOLEAN_TO_NPVARIANT(canPaste, *result); return true; } // readonly property {boolean} CanSelectAll else if (name == m_CanSelectAllID) { BOOL canSelectAll = m_pMainWindow->GetCanSelectAll(); BOOLEAN_TO_NPVARIANT(canSelectAll, *result); return true; } // readonly property {boolean} Progress else if (name == m_ProgressID) { INT32_TO_NPVARIANT(m_pMainWindow->GetProgress(),*result); return true; } VOID_TO_NPVARIANT(*result); return true; }
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; }
static bool removeDefaultMethod(PluginObject*, const NPVariant* args, uint32_t argCount, NPVariant* result) { pluginClass.invokeDefault = 0; VOID_TO_NPVARIANT(*result); return true; }
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; }
void convertJavaValueToNPVariant(JavaValue value, NPVariant* result) { switch (value.m_type) { case JavaTypeVoid: { VOID_TO_NPVARIANT(*result); } break; case JavaTypeObject: { // If the JavaValue is a String object, it should have type JavaTypeString. if (value.m_objectValue) OBJECT_TO_NPVARIANT(JavaInstanceToNPObject(value.m_objectValue.get()), *result); else VOID_TO_NPVARIANT(*result); } break; case JavaTypeString: { const char* utf8String = strdup(value.m_stringValue.utf8().data()); // The copied string is freed in NPN_ReleaseVariantValue (see npruntime.cpp) STRINGZ_TO_NPVARIANT(utf8String, *result); } break; case JavaTypeBoolean: { BOOLEAN_TO_NPVARIANT(value.m_booleanValue, *result); } break; case JavaTypeByte: { INT32_TO_NPVARIANT(value.m_byteValue, *result); } break; case JavaTypeChar: { INT32_TO_NPVARIANT(value.m_charValue, *result); } break; case JavaTypeShort: { INT32_TO_NPVARIANT(value.m_shortValue, *result); } break; case JavaTypeInt: { INT32_TO_NPVARIANT(value.m_intValue, *result); } break; // TODO: Check if cast to double is needed. case JavaTypeLong: { DOUBLE_TO_NPVARIANT(value.m_longValue, *result); } break; case JavaTypeFloat: { DOUBLE_TO_NPVARIANT(value.m_floatValue, *result); } break; case JavaTypeDouble: { DOUBLE_TO_NPVARIANT(value.m_doubleValue, *result); } break; case JavaTypeInvalid: default: { VOID_TO_NPVARIANT(*result); } break; } }
// FIXME: need comments. // Params: holder could be HTMLEmbedElement or NPObject static void npObjectInvokeImpl(const v8::FunctionCallbackInfo<v8::Value>& args, InvokeFunctionType functionId) { NPObject* npObject; WrapperWorldType currentWorldType = worldType(args.GetIsolate()); // These three types are subtypes of HTMLPlugInElement. if (V8HTMLAppletElement::HasInstance(args.Holder(), args.GetIsolate(), currentWorldType) || V8HTMLEmbedElement::HasInstance(args.Holder(), args.GetIsolate(), currentWorldType) || V8HTMLObjectElement::HasInstance(args.Holder(), args.GetIsolate(), currentWorldType)) { // The holder object is a subtype of HTMLPlugInElement. HTMLPlugInElement* element; if (V8HTMLAppletElement::HasInstance(args.Holder(), args.GetIsolate(), currentWorldType)) element = V8HTMLAppletElement::toNative(args.Holder()); else if (V8HTMLEmbedElement::HasInstance(args.Holder(), args.GetIsolate(), currentWorldType)) element = V8HTMLEmbedElement::toNative(args.Holder()); else element = V8HTMLObjectElement::toNative(args.Holder()); ScriptInstance scriptInstance = element->getInstance(); if (scriptInstance) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::HandleScope handleScope(isolate); npObject = v8ObjectToNPObject(scriptInstance->newLocal(isolate)); } else npObject = 0; } else { // The holder object is not a subtype of HTMLPlugInElement, it must be an NPObject which has three // internal fields. if (args.Holder()->InternalFieldCount() != npObjectInternalFieldCount) { throwError(v8ReferenceError, "NPMethod called on non-NPObject", args.GetIsolate()); return; } npObject = v8ObjectToNPObject(args.Holder()); } // Verify that our wrapper wasn't using a NPObject which has already been deleted. if (!npObject || !_NPN_IsAlive(npObject)) { throwError(v8ReferenceError, "NPObject deleted", args.GetIsolate()); return; } // Wrap up parameters. int numArgs = args.Length(); OwnArrayPtr<NPVariant> npArgs = adoptArrayPtr(new NPVariant[numArgs]); for (int i = 0; i < numArgs; i++) convertV8ObjectToNPVariant(args[i], npObject, &npArgs[i]); NPVariant result; VOID_TO_NPVARIANT(result); bool retval = true; switch (functionId) { case InvokeMethod: if (npObject->_class->invoke) { v8::Handle<v8::String> functionName = v8::Handle<v8::String>::Cast(args.Data()); NPIdentifier identifier = getStringIdentifier(functionName); retval = npObject->_class->invoke(npObject, identifier, npArgs.get(), numArgs, &result); } break; case InvokeConstruct: if (npObject->_class->construct) retval = npObject->_class->construct(npObject, npArgs.get(), numArgs, &result); break; case InvokeDefault: if (npObject->_class->invokeDefault) retval = npObject->_class->invokeDefault(npObject, npArgs.get(), numArgs, &result); break; default: break; } if (!retval) throwError(v8GeneralError, "Error calling method on NPObject.", args.GetIsolate()); for (int i = 0; i < numArgs; i++) _NPN_ReleaseVariantValue(&npArgs[i]); // Unwrap return values. v8::Handle<v8::Value> returnValue; if (_NPN_IsAlive(npObject)) returnValue = convertNPVariantToV8Object(&result, npObject, args.GetIsolate()); _NPN_ReleaseVariantValue(&result); v8SetReturnValue(args, returnValue); }
static bool pluginInvoke(NPObject* header, NPIdentifier name, const NPVariant* args, uint32_t argCount, NPVariant* result) { PluginObject* plugin = reinterpret_cast<PluginObject*>(header); if (name == pluginMethodIdentifiers[ID_TEST_CALLBACK_METHOD]) return testCallback(plugin, args, argCount, result); if (name == pluginMethodIdentifiers[ID_TEST_CALLBACK_METHOD_RETURN]) return testCallbackReturn(plugin, args, argCount, result); if (name == pluginMethodIdentifiers[ID_TEST_GETURL]) return getURL(plugin, args, argCount, result); if (name == pluginMethodIdentifiers[ID_TEST_DOM_ACCESS]) return testDOMAccess(plugin, args, argCount, result); if (name == pluginMethodIdentifiers[ID_TEST_GET_URL_NOTIFY]) return getURLNotify(plugin, args, argCount, result); if (name == pluginMethodIdentifiers[ID_TEST_INVOKE_DEFAULT]) return testInvokeDefault(plugin, args, argCount, result); if (name == pluginMethodIdentifiers[ID_TEST_ENUMERATE]) return testEnumerate(plugin, args, argCount, result); if (name == pluginMethodIdentifiers[ID_DESTROY_STREAM]) return destroyStream(plugin, args, argCount, result); if (name == pluginMethodIdentifiers[ID_TEST_GETINTIDENTIFIER]) return testGetIntIdentifier(plugin, args, argCount, result); if (name == pluginMethodIdentifiers[ID_TEST_EVALUATE]) return testEvaluate(plugin, args, argCount, result); if (name == pluginMethodIdentifiers[ID_TEST_GET_PROPERTY]) return testGetProperty(plugin, args, argCount, result); if (name == pluginMethodIdentifiers[ID_TEST_GET_PROPERTY_RETURN_VALUE]) return testGetPropertyReturnValue(plugin, args, argCount, result); if (name == pluginMethodIdentifiers[ID_TEST_HAS_PROPERTY]) return testHasProperty(plugin, args, argCount, result); if (name == pluginMethodIdentifiers[ID_TEST_HAS_METHOD]) return testHasMethod(plugin, args, argCount, result); if (name == pluginMethodIdentifiers[ID_TEST_IDENTIFIER_TO_STRING]) return testIdentifierToString(plugin, args, argCount, result); if (name == pluginMethodIdentifiers[ID_TEST_IDENTIFIER_TO_INT]) return testIdentifierToInt(plugin, args, argCount, result); if (name == pluginMethodIdentifiers[ID_TEST_PASS_TEST_OBJECT]) return testPassTestObject(plugin, args, argCount, result); if (name == pluginMethodIdentifiers[ID_TEST_POSTURL_FILE]) return testPostURLFile(plugin, args, argCount, result); if (name == pluginMethodIdentifiers[ID_TEST_CONSTRUCT]) return testConstruct(plugin, args, argCount, result); if (name == pluginMethodIdentifiers[ID_TEST_SCRIPT_OBJECT_INVOKE]) return testScriptObjectInvoke(plugin, args, argCount, result); if (name == pluginMethodIdentifiers[ID_TEST_THROW_EXCEPTION_METHOD]) { browser->setexception(header, "plugin object testThrowException SUCCESS"); return true; } if (name == pluginMethodIdentifiers[ID_TEST_FAIL_METHOD]) { NPObject* windowScriptObject; browser->getvalue(plugin->npp, NPNVWindowNPObject, &windowScriptObject); browser->invoke(plugin->npp, windowScriptObject, name, args, argCount, result); return false; } if (name == pluginMethodIdentifiers[ID_TEST_CLONE_OBJECT]) { NPObject* new_object = browser->createobject(plugin->npp, &pluginClass); assert(new_object->referenceCount == 1); OBJECT_TO_NPVARIANT(new_object, *result); return true; } if (name == pluginMethodIdentifiers[ID_TEST_CREATE_TEST_OBJECT]) { NPObject* testObject = browser->createobject(plugin->npp, getTestClass()); assert(testObject->referenceCount == 1); OBJECT_TO_NPVARIANT(testObject, *result); return true; } if (name == pluginMethodIdentifiers[ID_DESTROY_NULL_STREAM]) return destroyNullStream(plugin, args, argCount, result); if (name == pluginMethodIdentifiers[ID_TEST_RELOAD_PLUGINS_NO_PAGES]) { browser->reloadplugins(false); return true; } if (name == pluginMethodIdentifiers[ID_TEST_RELOAD_PLUGINS_AND_PAGES]) { browser->reloadplugins(true); return true; } if (name == pluginMethodIdentifiers[ID_TEST_GET_BROWSER_PROPERTY]) { browser->getproperty(plugin->npp, NPVARIANT_TO_OBJECT(args[0]), stringVariantToIdentifier(args[1]), result); return true; } if (name == pluginMethodIdentifiers[ID_TEST_SET_BROWSER_PROPERTY]) { browser->setproperty(plugin->npp, NPVARIANT_TO_OBJECT(args[0]), stringVariantToIdentifier(args[1]), &args[2]); return true; } if (name == pluginMethodIdentifiers[ID_REMEMBER]) { if (plugin->rememberedObject) browser->releaseobject(plugin->rememberedObject); plugin->rememberedObject = NPVARIANT_TO_OBJECT(args[0]); browser->retainobject(plugin->rememberedObject); VOID_TO_NPVARIANT(*result); return true; } if (name == pluginMethodIdentifiers[ID_GET_REMEMBERED_OBJECT]) { assert(plugin->rememberedObject); browser->retainobject(plugin->rememberedObject); OBJECT_TO_NPVARIANT(plugin->rememberedObject, *result); return true; } if (name == pluginMethodIdentifiers[ID_GET_AND_FORGET_REMEMBERED_OBJECT]) { assert(plugin->rememberedObject); OBJECT_TO_NPVARIANT(plugin->rememberedObject, *result); plugin->rememberedObject = 0; return true; } if (name == pluginMethodIdentifiers[ID_REF_COUNT]) { uint32_t refCount = NPVARIANT_TO_OBJECT(args[0])->referenceCount; INT32_TO_NPVARIANT(refCount, *result); return true; } if (name == pluginMethodIdentifiers[ID_SET_STATUS]) return testSetStatus(plugin, args, argCount, result); if (name == pluginMethodIdentifiers[ID_RESIZE_TO]) return testResizeTo(plugin, args, argCount, result); if (name == pluginMethodIdentifiers[ID_NORMALIZE]) return normalizeOverride(plugin, args, argCount, result); if (name == pluginMethodIdentifiers[ID_INVALIDATE_RECT]) return invalidateRect(plugin, args, argCount, result); if (name == pluginMethodIdentifiers[ID_OBJECTS_ARE_SAME]) return objectsAreSame(plugin, args, argCount, result); return false; }
RuntimeNPObject::InvokeResult RuntimeNPObject::invokeDefault(const NPVariant *, uint32_t, NPVariant &result) { /* return void */ VOID_TO_NPVARIANT(result); return INVOKERESULT_NO_ERROR; }
// 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; }
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; }
bool ScriptablePluginObject::Invoke(NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result) { if (m_pMainWindow == NULL) return false; // void Navigate({string} URL, {string} post, {string} headers) if (name == m_NavigateID) { TRACE ("Navigate called!\n"); if (argCount < 3) return false; NPVariant vURL = args[0]; if (vURL.type != NPVariantType_String) return false; CString URL = NPStringToCString(vURL.value.stringValue); NPVariant vHeaders = args[1]; if (vHeaders.type != NPVariantType_String) return false; CString headers = NPStringToCString(vHeaders.value.stringValue); NPVariant vPost = args[2]; if (vPost.type != NPVariantType_String) return false; CString post = NPStringToCString(vPost.value.stringValue); m_pMainWindow->Navigate(URL, post, headers); VOID_TO_NPVARIANT(*result); return true; } // void Refresh() else if (name == m_RefreshID) { TRACE ("Refresh called!\n"); m_pMainWindow->Refresh(); return true; } // void Stop() else if (name == m_StopID) { TRACE ("Stop called!\n"); m_pMainWindow->Stop(); return true; } // void Back() else if (name == m_BackID) { TRACE ("Back called!\n"); m_pMainWindow->Back(); return true; } // void Forward() else if (name == m_ForwardID) { TRACE ("Forward called!\n"); m_pMainWindow->Forward(); return true; } // void Focus() else if (name == m_FocusID) { TRACE ("Focus called!\n"); m_pMainWindow->Focus(); return true; } // void Copy() else if (name == m_CopyID) { TRACE ("Copy called!\n"); m_pMainWindow->Copy(); return true; } // void Cut() else if (name == m_CutID) { TRACE ("Cut called!\n"); m_pMainWindow->Cut(); return true; } // void Paste() else if (name == m_PasteID) { TRACE ("Paste called!\n"); m_pMainWindow->Paste(); return true; } // void SelectAll() else if (name == m_SelectAllID) { TRACE ("SelectAll called!\n"); m_pMainWindow->SelectAll(); return true; } // void Find() else if (name == m_FindID) { TRACE ("Find called!\n"); m_pMainWindow->Find(); return true; } // void HandOverFocus() else if (name == m_HandOverFocusID) { TRACE ("HandOverFocus called!\n"); m_pMainWindow->HandOverFocus(); return true; } // void Zoom({number} level) else if (name == m_ZoomID) { TRACE ("Zoom called!\n"); if (argCount < 1) return false; double level = 1; if (NPVARIANT_IS_DOUBLE(args[0])) level = NPVARIANT_TO_DOUBLE(args[0]); else if ( NPVARIANT_IS_INT32(args[0]) ) level = NPVARIANT_TO_INT32(args[0]); m_pMainWindow->Zoom(level); return true; } // void DisplaySecurityInfo() else if (name == m_DisplaySecurityInfoID) { TRACE ("DisplaySecurityInfo called!\n"); m_pMainWindow->DisplaySecurityInfo(); return true; } // void SaveAs() else if (name == m_SaveAsID) { TRACE ("SaveAs called!\n"); m_pMainWindow->SaveAs(); return true; } // void Print() else if (name == m_PrintID) { TRACE ("Print called!\n"); m_pMainWindow->Print(); return true; } // void PrintPreview() else if (name == m_PrintPreviewID) { TRACE ("PrintPreview called!\n"); m_pMainWindow->PrintPreview(); return true; } // void PrintSetup() else if (name == m_PrintSetupID) { TRACE ("PrintSetup called!\n"); m_pMainWindow->PrintSetup(); return true; } return false; }
void convertJValueToNPVariant(jvalue value, JNIType jniType, const char* javaTypeName, NPVariant* result) { switch (jniType) { case void_type: { VOID_TO_NPVARIANT(*result); } break; case object_type: { if (value.l) { if (!strcmp(javaTypeName, "java.lang.String")) { const char* v = getCharactersFromJString(static_cast<jstring>(value.l)); // s is freed in NPN_ReleaseVariantValue (see npruntime.cpp) const char* s = strdup(v); releaseCharactersForJString(static_cast<jstring>(value.l), v); STRINGZ_TO_NPVARIANT(s, *result); } else OBJECT_TO_NPVARIANT(JavaInstanceToNPObject(new JavaInstance(value.l)), *result); } else VOID_TO_NPVARIANT(*result); } break; case boolean_type: { BOOLEAN_TO_NPVARIANT(value.z, *result); } break; case byte_type: { INT32_TO_NPVARIANT(value.b, *result); } break; case char_type: { INT32_TO_NPVARIANT(value.c, *result); } break; case short_type: { INT32_TO_NPVARIANT(value.s, *result); } break; case int_type: { INT32_TO_NPVARIANT(value.i, *result); } break; // TODO: Check if cast to double is needed. case long_type: { DOUBLE_TO_NPVARIANT(value.j, *result); } break; case float_type: { DOUBLE_TO_NPVARIANT(value.f, *result); } break; case double_type: { DOUBLE_TO_NPVARIANT(value.d, *result); } break; case invalid_type: default: { VOID_TO_NPVARIANT(*result); } break; } }
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; }
RuntimeNPObject::InvokeResult LibvlcVideoNPObject::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); libvlc_media_player_t *p_md = p_plugin->getMD(&ex); RETURN_ON_EXCEPTION(this,ex); switch( index ) { case ID_video_togglefullscreen: { if( argCount == 0 ) { p_plugin->toggle_fullscreen(&ex); RETURN_ON_EXCEPTION(this,ex); VOID_TO_NPVARIANT(result); return INVOKERESULT_NO_ERROR; } return INVOKERESULT_NO_SUCH_METHOD; } case ID_video_toggleteletext: { if( argCount == 0 ) { libvlc_toggle_teletext(p_md, &ex); RETURN_ON_EXCEPTION(this,ex); VOID_TO_NPVARIANT(result); return INVOKERESULT_NO_ERROR; } return INVOKERESULT_NO_SUCH_METHOD; } case ID_video_deinterlacedisable: { libvlc_video_set_deinterlace(p_md, 0, "", &ex); RETURN_ON_EXCEPTION(this,ex); return INVOKERESULT_NO_ERROR; } case ID_video_deinterlaceenable: { if(argCount == 1) { if( NPVARIANT_IS_STRING( args[0] ) ) { /* get deinterlace mode from the user */ char *psz_mode = stringValue( NPVARIANT_TO_STRING( args[0] ) ); /* enable deinterlace filter if possible */ libvlc_video_set_deinterlace(p_md, 1, psz_mode, &ex); free(psz_mode); RETURN_ON_EXCEPTION(this,ex); return INVOKERESULT_NO_ERROR; } else { return INVOKERESULT_INVALID_VALUE; } } } default: return INVOKERESULT_NO_SUCH_METHOD; } } return INVOKERESULT_GENERIC_ERROR; }