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; }
// 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; }
/// 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; }
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; }
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; }
char* CPlugin::GetGuiText() { if( m_pScriptableObject->_class == GET_NPOBJECT_CLASS(ScriptablePluginObject)) { char* p = ( (ScriptablePluginObject*) m_pScriptableObject )->m_szTextGui; if( *p ) return p; } return m_String; }
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 * 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; }
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; }
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"); } }
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); }
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); }