RuntimeNPObject::InvokeResult LibvlcRootNPObject::getProperty(int index, NPVariant &result) { /* is plugin still running */ if( isPluginRunning() ) { switch( index ) { case ID_root_audio: // create child object in lazyman fashion to avoid // ownership problem with firefox if( ! audioObj ) audioObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcAudioNPObject>::getClass()); OBJECT_TO_NPVARIANT(NPN_RetainObject(audioObj), result); return INVOKERESULT_NO_ERROR; case ID_root_input: // create child object in lazyman fashion to avoid // ownership problem with firefox if( ! inputObj ) inputObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcInputNPObject>::getClass()); OBJECT_TO_NPVARIANT(NPN_RetainObject(inputObj), result); return INVOKERESULT_NO_ERROR; case ID_root_playlist: // create child object in lazyman fashion to avoid // ownership problem with firefox if( ! playlistObj ) playlistObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcPlaylistNPObject>::getClass()); OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistObj), result); return INVOKERESULT_NO_ERROR; case ID_root_subtitle: // create child object in lazyman fashion to avoid // ownership problem with firefox if( ! subtitleObj ) subtitleObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcSubtitleNPObject>::getClass()); OBJECT_TO_NPVARIANT(NPN_RetainObject(subtitleObj), result); return INVOKERESULT_NO_ERROR; case ID_root_video: // create child object in lazyman fashion to avoid // ownership problem with firefox if( ! videoObj ) videoObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcVideoNPObject>::getClass()); OBJECT_TO_NPVARIANT(NPN_RetainObject(videoObj), result); return INVOKERESULT_NO_ERROR; case ID_root_VersionInfo: return invokeResultString(libvlc_get_version(),result); default: ; } } return INVOKERESULT_GENERIC_ERROR; }
// here we supply our scriptable object NPError nsPluginInstanceInputTracker::GetValue( NPPVariable variable, void* ret_value) { NPError rv = NPERR_INVALID_PARAM; switch (variable) { case NPPVpluginScriptableNPObject: { if (nullptr == scriptable_object_) { { CriticalSectionLocker lock(scriptable_object_CS_); scriptable_object_ = NPN_CreateObject( instance_, GET_NPOBJECT_CLASS(nsScriptableObjectInputTracker)); NPN_RetainObject(scriptable_object_); ((nsScriptableObjectInputTracker*)scriptable_object_)->Init(); *(NPObject **)ret_value = scriptable_object_; } } rv = NPERR_NO_ERROR; return rv; } default: break; } return rv; }
bool ScriptablePluginObject::GetProperty(NPIdentifier name, NPVariant *result) { VOID_TO_NPVARIANT(*result); if (name == sBar_id) { static int a = 17; INT32_TO_NPVARIANT(a, *result); a += 5; return true; } if (name == sPluginType_id) { NPObject *myobj = NPN_CreateObject(mNpp, GET_NPOBJECT_CLASS(ConstructablePluginObject)); if (!myobj) { return false; } OBJECT_TO_NPVARIANT(myobj, *result); return true; } return true; }
/// Returns true if the scriptable property is managed and fills the NPVariant pointer with the value bool BasePlugin::GetProperty(NPIdentifier name, NPVariant *result) { VOID_TO_NPVARIANT(*result); //VIENE FATTA LA VERIFICA SULLA DERIVAZIONE DELLA CLASSE DA NPOBJECT PER IL SUPPORTO SCRIPT if (name == sPluginType_id) { NPObject *myobj = NPN_CreateObject(mNpp, GET_NPOBJECT_CLASS(BasePlugin)); if (!myobj) { return false; } OBJECT_TO_NPVARIANT(myobj, *result); return true; } // /*if (name == sBar_id) { static int a = 17; INT32_TO_NPVARIANT(a, *result); a += 5; return true; }*/ return true; }
NPError NPP_GetValue(NPP instance, NPPVariable variable, void *ret_value) { functionLog("NPP_GetValue"); NPError rv = NPERR_NO_ERROR; switch(variable) { case NPPVpluginNameString: functionLog("NPPVpluginNameString"); *((char **)ret_value) = description; break; case NPPVpluginDescriptionString: // Plugin description functionLog("NPPVpluginDescriptionString"); *((char **)ret_value) = description; break; case NPPVpluginScriptableNPObject:// Scriptable plugin interface (for accessing from javascript) { functionLog("NPPVpluginScriptableNPObject"); //*(NPObject **)ret_value = this->getScriptableObject(); //ret_value = (NPObject *)ExtendedNPObject::NewObject(instance); *(NPObject **)ret_value = NPN_CreateObject(instance, &ExtendedNPObject::_npclass); //NPN_RetainObject((NPObject*)ret_value); break; } case NPPVpluginWindowBool: functionLog("NPPVpluginWindowBool"); //*((PRBool *)ret_value) = this->isWindowed; break; default: functionLog("NPERR_GENERIC_ERROR"); rv = NPERR_GENERIC_ERROR; } return rv; }
void nsPluginInstance::CreateScriptableObject() { NPObject *so = NPN_CreateObject(mInstance, &CPCManScriptable::MyClass); m_pPCManScriptable = (CPCManScriptable *) so; // We retain it until we are released ourselves. NPN_RetainObject(so); }
NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value ) { static char psz_name[] = PLUGIN_NAME; static char psz_desc[1000]; /* plugin class variables */ switch( variable ) { case NPPVpluginNameString: *((char **)value) = psz_name; return NPERR_NO_ERROR; case NPPVpluginDescriptionString: snprintf( psz_desc, sizeof(psz_desc), PLUGIN_DESCRIPTION, libvlc_get_version() ); *((char **)value) = psz_desc; return NPERR_NO_ERROR; default: /* move on to instance variables ... */ ; } if( instance == NULL ) { return NPERR_INVALID_INSTANCE_ERROR; } /* plugin instance variables */ VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata); if( NULL == p_plugin ) { // plugin has not been initialized yet ! return NPERR_INVALID_INSTANCE_ERROR; } switch( variable ) { case NPPVpluginScriptableNPObject: { /* retrieve plugin root class */ NPClass *scriptClass = p_plugin->getScriptClass(); if( scriptClass ) { /* create an instance and return it */ *(NPObject**)value = NPN_CreateObject(instance, scriptClass); return NPERR_NO_ERROR; } break; } default: ; } return NPERR_GENERIC_ERROR; }
/** * Create a new jsNetToolsClass instance * * @param plugin - Parent plugin * @return JS Object */ jsInterfaceObject* jsInterface_New(NPP plugin) { jsInterfaceObject* object = NULL; object = (jsInterfaceObject*) NPN_CreateObject(plugin, &jsNetToolsClass); object->plugin = plugin; return object; }
NPObject * CNPPluginMisc::GetScriptableObject() { if (!m_pScriptableObject) m_pScriptableObject = NPN_CreateObject(m_pNPInstance, GET_NPOBJECT_CLASS(ScriptablePluginObject)); if (m_pScriptableObject) NPN_RetainObject(m_pScriptableObject); return m_pScriptableObject; }
bool JsAgent::onLoad(const NPVariant* args, unsigned argCount) { Debug::println("JsAgent::onLoad"); if(argCount != 4) { Debug::println("JsAgent::onLoad> argCount != 4"); return false; } if( !NPVARIANT_IS_OBJECT(args[0]) || !NPVARIANT_IS_STRING(args[1]) || !NPVARIANT_IS_INT32(args[2]) || !NPVARIANT_IS_STRING(args[3]) ) { Debug::println("JsAgent::onLoad> arg types wrong"); return false; } NPObject* pObject = NPVARIANT_TO_OBJECT(args[0]); m_helper = NPN_RetainObject(pObject); NPObject* pDebug = NPN_CreateObject(getNPP(), GetNPClass<JsDebug>()); NPN_RetainObject(pDebug); Variant var; var.set(pDebug); if(!NPN_SetProperty(getNPP(), m_window, methods.debug, var.ptr())) { Debug::println("JsAgent::onLoad> set property failed"); return false; } NPString npstr = NPVARIANT_TO_STRING(args[1]); std::string host(npstr.UTF8Characters, npstr.UTF8Length); int port = NPVARIANT_TO_INT32(args[2]); npstr = NPVARIANT_TO_STRING(args[3]); std::string typeName(npstr.UTF8Characters, npstr.UTF8Length); if(!m_channel->connect(host.c_str(), port)) { Debug::println("JsAgent::onLoad> could not connect"); return false; } LoadMessage msg; msg.typeName = typeName; ArchiveWriter<Channel> ar(*m_channel); if(!Message::send(msg, ar)) { Debug::println("JsAgent::onLoad> send failed"); return false; } JsValue ret; return dispatchAndReturn(ret); }
static NPError NPP_GetValue(NPP instance, NPPVariable variable, void* value) { InstanceData* id = NPPToInstance(instance); if (variable == NPPVpluginScriptableNPObject) { NPObject* obj = NPN_CreateObject(instance, const_cast<NPClass*>(&sProtoNPClass)); id->proto = NPN_RetainObject(obj); *static_cast<NPObject**>(value) = obj; return NPERR_NO_ERROR; } return NPERR_GENERIC_ERROR; }
NPObject *CPlugin::GetScriptableObject() { if (!m_pScriptableObject) { m_pScriptableObject = NPN_CreateObject(m_pNPInstance, GET_NPOBJECT_CLASS(ScriptablePluginObject)); } if (m_pScriptableObject) { NPN_RetainObject(m_pScriptableObject); } return m_pScriptableObject; }
NPObject* JsAgent::getRemoteObject(uint32_t id) { RefToObj_t::const_iterator it = m_remoteObjects.find(id); if(it == m_remoteObjects.end()) { JsObjectWrapper* wrapper = (JsObjectWrapper*)NPN_CreateObject(getNPP(), GetNPClass<JsObjectWrapper>()); wrapper->init(this, id); m_remoteObjects[id] = wrapper; return NPN_RetainObject(wrapper); } else { return NPN_RetainObject(it->second); } }
bool ConstructablePluginObject::Construct(const NPVariant *args, uint32_t argCount, NPVariant *result) { NPObject *myobj = NPN_CreateObject(mNpp, GET_NPOBJECT_CLASS(ConstructablePluginObject)); if (!myobj) return false; OBJECT_TO_NPVARIANT(myobj, *result); return true; }
NPObject * dn_create_plugin_object (NPP instance) { NPObject *object = NPN_CreateObject (instance, &js_object_class); g_return_val_if_fail (object != NULL, NULL); g_debug ("%s()", G_STRFUNC); DnObjectWrapper *wrapper = (DnObjectWrapper *) object; g_hash_table_insert (wrapper->methods, "showNotification", dn_show_notification); return object; }
NPObject * CPlugin::GetScriptableObject() { OutputDebugStringA("cplugin_getscriptableobject"); if (!m_pScriptableObject) { m_pScriptableObject = NPN_CreateObject(m_pNPInstance, GET_NPOBJECT_CLASS(ScriptablePluginObject)); } if (m_pScriptableObject) { NPN_RetainObject(m_pScriptableObject); } return m_pScriptableObject; }
NPObject * CPlugin::GetScriptableObject() { if (!m_pScriptableObject) { m_pScriptableObject = NPN_CreateObject(m_pNPInstance, GET_NPOBJECT_CLASS(ScriptablePluginObject)); } if (m_pScriptableObject) { NPN_RetainObject(m_pScriptableObject); } //kk for invalidating the output ( (ScriptablePluginObject*) m_pScriptableObject )->m_hWnd = m_hWnd; return m_pScriptableObject; }
bool ScriptablePluginObject::GetProperty(NPIdentifier name, NPVariant *result) { VOID_TO_NPVARIANT(*result); //kk /*if (name == sBar_id) { static int a = 17; INT32_TO_NPVARIANT(a, *result); a += 5; return true; }*/ char *pProp = NPN_UTF8FromIdentifier(name); if( !strcmp( "Version", pProp ) ) { char *p = (char*) NPN_MemAlloc( "Version 1.0" );//allocating Memory for the string with invocation of Browser-API STRINGZ_TO_NPVARIANT( p, *result); return true; } if( !strcmp( "Name", pProp ) ) { char *p = (char*) NPN_MemAlloc( m_pszName );//allocating Memory for the string with invocation of Browser-API STRINGZ_TO_NPVARIANT( p, *result); return true; } if (name == sPluginType_id) { NPObject *myobj = NPN_CreateObject(mNpp, GET_NPOBJECT_CLASS(ConstructablePluginObject)); if (!myobj) { return false; } OBJECT_TO_NPVARIANT(myobj, *result); return true; } return true; }
NPObject *CPlugin::GetScriptableObject() { if (!m_pScriptableObject) { m_pScriptableObject = NPN_CreateObject(m_pNPInstance, GET_NPOBJECT_CLASS(ScriptablePluginObject)); if (m_pIEHostWindow) m_pIEHostWindow->RunAsync([this] { FireInitEvent(); }); } if (m_pScriptableObject) { NPN_RetainObject(m_pScriptableObject); } return m_pScriptableObject; }
NPVariant NPVariant::fromQVariant(QtNPInstance *This, const QVariant &qvariant) { Q_ASSERT(This); NPVariant npvar; npvar.type = Null; QVariant qvar(qvariant); switch(qvariant.type()) { case QVariant::Bool: npvar.value.boolValue = qvar.toBool(); npvar.type = Boolean; break; case QVariant::Int: npvar.value.intValue = qvar.toInt(); npvar.type = Int32; break; case QVariant::Double: npvar.value.doubleValue = qvar.toDouble(); npvar.type = Double; break; case QVariant::UserType: { QByteArray userType = qvariant.typeName(); if (userType.endsWith('*')) { QtNPInstance *that = new QtNPInstance; that->npp = This->npp; that->qt.object = *(QObject**)qvariant.constData(); NPClass *npclass = new NPClass(that); npclass->delete_qtnp = true; npvar.value.objectValue = NPN_CreateObject(This->npp, npclass); npvar.type = Object; } } break; default: // including QVariant::String if (!qvar.convert(QVariant::String)) break; npvar.type = String; npvar.value.stringValue = NPString::fromQString(qvar.toString()); break; } return npvar; }
RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::getProperty(int index, 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_playlist_itemcount: /* deprecated */ { int val = p_plugin->playlist_count(&ex); RETURN_ON_EXCEPTION(this,ex); INT32_TO_NPVARIANT(val, result); return INVOKERESULT_NO_ERROR; } case ID_playlist_isplaying: { int val = p_plugin->playlist_isplaying(&ex); RETURN_ON_EXCEPTION(this,ex); BOOLEAN_TO_NPVARIANT(val, result); return INVOKERESULT_NO_ERROR; } case ID_playlist_items: { // create child object in lazyman fashion to avoid // ownership problem with firefox if( ! playlistItemsObj ) playlistItemsObj = NPN_CreateObject(_instance, RuntimeNPClass< LibvlcPlaylistItemsNPObject>::getClass()); OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistItemsObj), result); return INVOKERESULT_NO_ERROR; } default: ; } } return INVOKERESULT_GENERIC_ERROR; }
void OnConnection(uv_stream_t* server, int status) { uv_tcp_t* stream = new uv_tcp_t; TCPWrap* tcpWrap = (TCPWrap*)server->data; TCPWrap* newTcpWrap = (TCPWrap*)NPN_CreateObject(tcpWrap->m_Instance,&TCPWrap::_npclass); newTcpWrap->init(stream); NPN_RetainObject((NPObject*)newTcpWrap); int r = uv_accept(server, (uv_stream_t*)stream); NPVariant* args = new NPVariant[1]; args[0].type = NPVariantType_Object; args[0].value.objectValue = (NPObject*)newTcpWrap; tcpWrap->fireCallback("onconnection",args,1); }
NPError nsPluginInstanceOverwolfGW2::GetValue(NPPVariable variable, void* ret_value) { NPError rv = NPERR_INVALID_PARAM; switch (variable) { case NPPVpluginScriptableNPObject: if (scriptable_object == NULL) { scriptable_object = NPN_CreateObject(instance, GET_NPOBJECT_CLASS(nsScriptableObjectOverwolfGW2)); NPN_RetainObject(scriptable_object); ((nsScriptableObjectOverwolfGW2*)scriptable_object)->Init(); } *(NPObject **)ret_value = scriptable_object; rv = NPERR_NO_ERROR; default: break; } return rv; }
NPError NPP_GetValue(NPP instance, NPPVariable variable, void * value ) { #if 1 log_function(); #endif static char psz_desc[1000]; /* plugin class variables */ switch (variable) { case NPPVpluginNameString: *((char **)value) = PLUGIN_NAME; return NPERR_NO_ERROR; case NPPVpluginDescriptionString: snprintf(psz_desc, sizeof(psz_desc), PLUGIN_DESCRIPTION, get_version()); //log_debug("NPP_GetValue: psz_desc = " << static_cast<char *> (psz_desc)); *((char **)value) = psz_desc; return NPERR_NO_ERROR; default: snprintf(psz_desc, sizeof(psz_desc), PLUGIN_DESCRIPTION, get_version()); /*log_debug( "NPP_GetValue: default = " << reinterpret_cast<char *> (variable) << ":" << reinterpret_cast<char *> (psz_desc) );*/ ; } if (instance == 0) { return NPERR_INVALID_INSTANCE_ERROR; } little_shoot_plugin * plugin = reinterpret_cast<little_shoot_plugin *>( instance->pdata ); if (0 == plugin) { return NPERR_INVALID_INSTANCE_ERROR; } switch (variable) { case NPPVpluginScriptableNPObject: { NPClass * scriptClass = plugin->getScriptClass(); if (scriptClass) { *(NPObject **)value = NPN_CreateObject(instance, scriptClass); return NPERR_NO_ERROR; } break; } default: ; } return NPERR_GENERIC_ERROR; }
CPlugin::CPlugin(NPP pNPInstance) : m_pNPInstance(pNPInstance), m_pNPStream(NULL), m_bInitialized(FALSE), m_pScriptableObject(NULL) { #ifdef XP_WIN m_hWnd = NULL; #endif NPN_GetValue(m_pNPInstance, NPNVWindowNPObject, &sWindowObj); NPIdentifier n = NPN_GetStringIdentifier("foof"); sendCmd_id = NPN_GetStringIdentifier("sendCmd"); NPVariant v; INT32_TO_NPVARIANT(46, v); NPN_SetProperty(m_pNPInstance, sWindowObj, n, &v); n = NPN_GetStringIdentifier("document"); NPVariant arg; OBJECT_TO_NPVARIANT(sWindowObj, arg); NPObject *myobj = NPN_CreateObject(m_pNPInstance, GET_NPOBJECT_CLASS(ScriptablePluginObject)); n = NPN_GetStringIdentifier("objJSExt"); OBJECT_TO_NPVARIANT(myobj, v); NPN_SetProperty(m_pNPInstance, sWindowObj, n, &v); NPN_ReleaseObject(myobj); const char *ua = NPN_UserAgent(m_pNPInstance); strcpy(m_String, ua); // Create a "location" identifier. NPIdentifier identifier = NPN_GetStringIdentifier( "location" ); // Declare a local variant value. NPVariant variantValue; // Get the location property from the window object (which is another object). bool b1 = NPN_GetProperty( m_pNPInstance, sWindowObj, identifier, &variantValue ); // Get a pointer to the "location" object. NPObject *locationObj = variantValue.value.objectValue; // Create a "href" identifier. identifier = NPN_GetStringIdentifier( "href" ); // Get the location property from the location object. bool b2 = NPN_GetProperty( m_pNPInstance, locationObj, identifier, &variantValue ); g_strPageURL = ""; NPString npStr = NPVARIANT_TO_STRING( variantValue ); for (unsigned int i=0; i<npStr.utf8length; i++) { g_strPageURL += npStr.utf8characters[ i ]; } NPN_ReleaseObject(locationObj); }
CPlugin::CPlugin(NPP pNPInstance) : m_pNPInstance(pNPInstance), m_pNPStream(NULL), m_bInitialized(FALSE), m_pScriptableObject(NULL) { NPVariant v; NPVariant rval; NPObject *browserWndObj = NULL; #ifdef XP_WIN m_hWnd = NULL; #endif // setup the display string const char *ua = NPN_UserAgent(m_pNPInstance); strcpy(m_String, ua); if ( NPERR_NO_ERROR == NPN_GetValue(m_pNPInstance, NPNVWindowNPObject, &browserWndObj)) { // this is interesting. // Here we are setting up an instance in JavaScript of the ScriptablePluginObject // by inserting a new instance into the DOM. this will be referenced by document.pluginobj; // NPObject *myobj = NPN_CreateObject(m_pNPInstance, GET_NPOBJECT_CLASS(ScriptablePluginObject)); if ( myobj ) { // create an identifier for the plugin object NPIdentifier n = NPN_GetStringIdentifier("pluginobj"); // now insert into the DOM OBJECT_TO_NPVARIANT(myobj, v); if (NPN_SetProperty(m_pNPInstance, browserWndObj, n, &v)) { // validate the object if ( NPN_GetProperty(m_pNPInstance, browserWndObj, n, &rval) ) { printf ("Object set/get test "); if (NPVARIANT_IS_OBJECT(rval) && NPVARIANT_TO_OBJECT(rval) == myobj) { printf ("succeeded!\n"); } else { printf ("FAILED!\n"); } } else { printf("failed to get pluginobj"); } NPN_ReleaseVariantValue(&rval); } else { printf("failed to set pluginobj"); } NPN_ReleaseObject(myobj); } else { printf("failed to create pluginobj"); } } else { printf("failed to get browser window"); } }
// Plugin functions extern "C" NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value) { if (!instance || !instance->pdata) return NPERR_INVALID_INSTANCE_ERROR; QtNPInstance* This = (QtNPInstance*) instance->pdata; switch (variable) { case NPPVpluginNameString: { static QByteArray name = qtNPFactory()->pluginName().toLocal8Bit(); *(const char**)value = name.constData(); } break; case NPPVpluginDescriptionString: { static QByteArray description = qtNPFactory()->pluginDescription().toLocal8Bit(); *(const char**)value = description.constData(); } break; #ifdef Q_WS_X11 case NPPVpluginNeedsXEmbed: *(int*)value = true; // PRBool = int break; #endif case NPPVpluginScriptableNPObject: { NPObject *object = NPN_CreateObject(instance, new NPClass(This)); *(NPObject**)value = object; } break; case NPPVformValue: { QObject *object = This->qt.object; const QMetaObject *metaObject = object->metaObject(); int defaultIndex = metaObject->indexOfClassInfo("DefaultProperty"); if (defaultIndex == -1) return NPERR_GENERIC_ERROR; QByteArray defaultProperty = metaObject->classInfo(defaultIndex).value(); if (defaultProperty.isEmpty()) return NPERR_GENERIC_ERROR; QVariant defaultValue = object->property(defaultProperty); if (!defaultValue.isValid()) return NPERR_GENERIC_ERROR; defaultProperty = defaultValue.toString().toUtf8(); int size = defaultProperty.size(); char *utf8 = (char*)NPN_MemAlloc(size + 1); memcpy(utf8, defaultProperty.constData(), size); utf8[size] = 0; // null-terminator *(void**)value = utf8; } break; default: return NPERR_GENERIC_ERROR; } return NPERR_NO_ERROR; }
CPlugin::CPlugin(NPP pNPInstance) : m_pNPInstance(pNPInstance), m_pNPStream(NULL), m_bInitialized(false), m_pScriptableObject(NULL) { #ifdef XP_WIN m_hWnd = NULL; #endif NPN_GetValue(m_pNPInstance, NPNVWindowNPObject, &sWindowObj); NPIdentifier n = NPN_GetStringIdentifier("foof"); sFoo_id = NPN_GetStringIdentifier("foo"); sBar_id = NPN_GetStringIdentifier("bar"); sDocument_id = NPN_GetStringIdentifier("document"); sBody_id = NPN_GetStringIdentifier("body"); sCreateElement_id = NPN_GetStringIdentifier("createElement"); sCreateTextNode_id = NPN_GetStringIdentifier("createTextNode"); sAppendChild_id = NPN_GetStringIdentifier("appendChild"); sPluginType_id = NPN_GetStringIdentifier("PluginType"); NPVariant v; INT32_TO_NPVARIANT(46, v); NPN_SetProperty(m_pNPInstance, sWindowObj, n, &v); NPVariant rval; NPN_GetProperty(m_pNPInstance, sWindowObj, n, &rval); if (NPVARIANT_IS_INT32(rval)) { printf("rval = %d\n", NPVARIANT_TO_INT32(rval)); } n = NPN_GetStringIdentifier("document"); if (!NPN_IdentifierIsString(n)) { NPString str; str.UTF8Characters = "alert('NPN_IdentifierIsString() test failed!');"; str.UTF8Length = strlen(str.UTF8Characters); NPN_Evaluate(m_pNPInstance, sWindowObj, &str, NULL); } NPObject *doc; NPN_GetProperty(m_pNPInstance, sWindowObj, n, &rval); if (NPVARIANT_IS_OBJECT(rval) && (doc = NPVARIANT_TO_OBJECT(rval))) { n = NPN_GetStringIdentifier("title"); NPN_GetProperty(m_pNPInstance, doc, n, &rval); if (NPVARIANT_IS_STRING(rval)) { printf ("title = %s\n", NPVARIANT_TO_STRING(rval).UTF8Characters); NPN_ReleaseVariantValue(&rval); } n = NPN_GetStringIdentifier("plugindoc"); OBJECT_TO_NPVARIANT(doc, v); NPN_SetProperty(m_pNPInstance, sWindowObj, n, &v); NPString str; str.UTF8Characters = "document.getElementById('result').innerHTML += '<p>' + 'NPN_Evaluate() test, document = ' + this + '</p>';"; str.UTF8Length = strlen(str.UTF8Characters); //NPN_Evaluate(m_pNPInstance, doc, &str, NULL); NPN_ReleaseObject(doc); } NPVariant barval; NPN_GetProperty(m_pNPInstance, sWindowObj, sBar_id, &barval); NPVariant arg; OBJECT_TO_NPVARIANT(sWindowObj, arg); NPN_InvokeDefault(m_pNPInstance, NPVARIANT_TO_OBJECT(barval), &arg, 1, &rval); if (NPVARIANT_IS_INT32(rval) && NPVARIANT_TO_INT32(rval) == 4) { printf ("Default function call SUCCEEDED!\n"); } else { printf ("Default function call FAILED!\n"); } NPN_ReleaseVariantValue(&barval); NPN_ReleaseVariantValue(&rval); #if 0 n = NPN_GetStringIdentifier("prompt"); NPVariant vars[3]; STRINGZ_TO_NPVARIANT("foo", vars[0]); STRINGZ_TO_NPVARIANT("bar", vars[1]); STRINGZ_TO_NPVARIANT("foof", vars[2]); NPN_Invoke(sWindowObj, n, vars, 3, &rval); if (NPVARIANT_IS_STRING(rval)) { printf ("prompt returned '%s'\n", NPVARIANT_TO_STRING(rval).UTF8Characters); } NPN_ReleaseVariantValue(&rval); #endif NPObject *myobj = NPN_CreateObject(m_pNPInstance, GET_NPOBJECT_CLASS(ScriptablePluginObject)); n = NPN_GetStringIdentifier("pluginobj"); OBJECT_TO_NPVARIANT(myobj, v); NPN_SetProperty(m_pNPInstance, sWindowObj, n, &v); NPN_GetProperty(m_pNPInstance, sWindowObj, n, &rval); printf ("Object set/get test "); if (NPVARIANT_IS_OBJECT(rval) && NPVARIANT_TO_OBJECT(rval) == myobj) { printf ("succeeded!\n"); } else { printf ("FAILED!\n"); } NPN_ReleaseVariantValue(&rval); NPN_ReleaseObject(myobj); const char *ua = NPN_UserAgent(m_pNPInstance); strcpy(m_String, ua); }
bool TCPWrap::Invoke(NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result) { if(name == onconnection_cb) { apply(onconnection_callback,args,argCount,result); return true; } if(name == onread_cb) { apply(onread_callback,args,argCount,result); return true; } if(name == onshutdown_cb) { apply(onshutdown_callback,args,argCount,result); return true; } InvokeParams* params = new InvokeParams; params->name = name; params->object = this; params->args = new NPVariant[argCount]; params->argCount = argCount; for(uint32_t q = 0; q < argCount; q++) { params->args[q] = *CopyNPVariant(&args[q]); } // if there is a write request a reference must be returned to javascript so it has // to be done before the rest of the work is handed off to the worker thread if(name == write_func) { argCount++; WriteReq* w = (WriteReq*)NPN_CreateObject(m_Instance,&WriteReq::_npclass); // when we get a buffer we have to find the SlowBuffer._handle to access its data if(params->args[0].type == NPVariantType_Object) { // we dont want to delete the buffer because it's a SlowBuffer and might be accessed later // via a Buffer w->retainBuffer = true; NPVariant offset, length, parent, handle; // buffer.offset NPN_GetProperty(m_Instance,params->args[0].value.objectValue,NPN_GetStringIdentifier("offset"),&offset); // buffer.length NPN_GetProperty(m_Instance,params->args[0].value.objectValue,NPN_GetStringIdentifier("length"),&length); // buffer.parent NPN_GetProperty(m_Instance,params->args[0].value.objectValue,NPN_GetStringIdentifier("parent"),&parent); // buffer.parent._handle NPN_GetProperty(m_Instance,parent.value.objectValue,NPN_GetStringIdentifier("_handle"),&handle); params->args[0].type = NPVariantType_String; params->args[0].value.stringValue.UTF8Length = static_cast<uint32_t>(length.value.doubleValue); params->args[0].value.stringValue.UTF8Characters = ((BufferWrap*)handle.value.objectValue)->data + (uint16_t)offset.value.doubleValue; } w->init(this,args[1],args[2]); NPN_RetainObject((NPObject*)w); params->returnObject = (NPObject*)w; //return the write request result->type = NPVariantType_Object; result->value.objectValue = params->returnObject; } if(name == shutdown_func) { ShutdownReq* w = (ShutdownReq*)NPN_CreateObject(m_Instance,&ShutdownReq::_npclass); w->init(this, args[0]); NPN_RetainObject((NPObject*)w); params->returnObject = (NPObject *)w; //return the shutdown request result->type = NPVariantType_Object; result->value.objectValue = params->returnObject; } invoke_queue.push(params); //wake the worker thread uv_async_send(&TCPWrap::async_handle); return true; }