void CPlugin::showGetPluginDialog() { assert(m_pNPMIMEType != NULL); if(m_pNPMIMEType == NULL) return; // Get environment BOOL bOffline = FALSE; NPN_GetValue(m_pNPInstance, NPNVisOfflineBool, (void *)&bOffline); NPN_GetValue(m_pNPInstance, NPNVjavascriptEnabledBool, (void *)&m_bJavaScript); //NPN_GetValue(m_pNPInstance, NPNVasdEnabledBool, (void *)&m_bSmartUpdate); m_bOnline = !bOffline; dbgOut1("Environment:"); dbgOut2("%s", m_bOnline ? "On-line" : "Off-line"); dbgOut2("JavaScript %s", m_bJavaScript ? "Enabled" : "Disabled"); dbgOut2("SmartUpdate %s", m_bSmartUpdate ? "Enabled" : "Disabled"); if((!m_bSmartUpdate && (m_szPageURL != NULL) || (m_szFileURL != NULL)) || !m_bJavaScript) { // we don't want it more than once if(m_hWndDialog == NULL) CreateDialogParam(m_hInst, MAKEINTRESOURCE(IDD_PLUGIN_DOWNLOAD), m_hWnd, (DLGPROC)GetPluginDialogProc, (LPARAM)this); } else getPlugin(); }
static mrb_value mrb_js_obj_get(mrb_state *mrb, mrb_value klass) { mrb_value str; mrb_get_args(mrb, "S", &str); NPObject *window; NPN_GetValue(MRB_UD_NPP(mrb), NPNVWindowNPObject, &window); NPUTF8 *s = (NPUTF8 *)NPN_MemAlloc(RSTRING_LEN(str)); std::copy(RSTRING_PTR(str), RSTRING_END(str), s); NPString evaluated_str = { s, RSTRING_LEN(str) }; NPVariant result; std::string js_str(RSTRING_PTR(str), RSTRING_LEN(str)); NPN_Evaluate(MRB_UD_NPP(mrb), window, &evaluated_str, &result); NPN_ReleaseObject(window); NPN_MemFree(s); mrb_value ret; if (!convert_js_to_mrb(MRB_UD_NPP(mrb), result, mrb, &ret)){ return mrb_nil_value(); } return ret; }
bool convert_mrb_to_js_hash(mrb_state *mrb, mrb_value value, NPP npp, NPVariant *result) { NPObject *window; NPN_GetValue(npp, NPNVWindowNPObject, &window); NPVariant hash; NPN_Invoke(npp, window, NPN_GetStringIdentifier("Object"), NULL, 0, &hash); NPN_ReleaseObject(window); khash_t(ht) *h = RHASH_TBL(value); if (!h){ *result = hash; return true; } NPObject *hash_obj = NPVARIANT_TO_OBJECT(hash); for (khiter_t k=kh_begin(h); k!=kh_end(h); k++){ if (kh_exist(h, k)) { mrb_value key = mrb_funcall(mrb, kh_key(h, k), "to_s", 0); mrb_value val = kh_value(h, k); NPVariant var; if (!convert_mrb_to_js(mrb, val, npp, &var)){ NPN_ReleaseVariantValue(&hash); return false; } std::string name(RSTRING_PTR(key), RSTRING_LEN(key)); NPN_SetProperty(npp, hash_obj, NPN_GetStringIdentifier(name.c_str()), &var); } } *result = hash; return true; }
bool convert_mrb_to_js_array(mrb_state *mrb, mrb_value value, NPP npp, NPVariant *result) { NPObject *window; NPN_GetValue(npp, NPNVWindowNPObject, &window); NPVariant array; NPN_Invoke(npp, window, NPN_GetStringIdentifier("Array"), NULL, 0, &array); NPN_ReleaseObject(window); NPIdentifier push = NPN_GetStringIdentifier("push"); mrb_value *ptr = RARRAY_PTR(value); for (int i=0, len=RARRAY_LEN(value); i<len; i++){ NPVariant var; if (!convert_mrb_to_js(mrb, ptr[i], npp, &var)){ NPN_ReleaseVariantValue(&array); return false; } NPVariant ret; NPN_Invoke(npp, NPVARIANT_TO_OBJECT(array), push, &var, 1, &ret); NPN_ReleaseVariantValue(&ret); } *result = array; return true; }
// 清空IECtrl::Navigate的参数 void CPlugin::RemoveNavigateParams() { NPObject* pWindow = NULL; NPVariant vCOBAContainer; VOID_TO_NPVARIANT(vCOBAContainer); NPVariant vResult; VOID_TO_NPVARIANT(vResult); try { if ((NPN_GetValue( m_pNPInstance, NPNVWindowNPObject, &pWindow) != NPERR_NO_ERROR ) || !pWindow ) { throw(CString(_T("Cannot get window"))); } if ((!NPN_GetProperty( m_pNPInstance, pWindow, NPN_GetStringIdentifier ("COBAContainer"), &vCOBAContainer)) || !NPVARIANT_IS_OBJECT (vCOBAContainer)) { throw(CString(_T("Cannot get window.COBAContainer"))); } if (!NPN_Invoke(m_pNPInstance, NPVARIANT_TO_OBJECT(vCOBAContainer), NPN_GetStringIdentifier("removeNavigateParams"), NULL, 0, &vResult)) { throw(CString(_T("Cannot execute window.COBAContainer.removeNavigateParams()"))); } } catch (CString strMessage) { TRACE(_T("[CPlugin::RemoveNavigateParams Exception] %s"), strMessage); } if (!NPVARIANT_IS_VOID(vResult)) NPN_ReleaseVariantValue(&vResult); if (!NPVARIANT_IS_VOID(vCOBAContainer)) NPN_ReleaseVariantValue(&vCOBAContainer); if (pWindow != NULL) NPN_ReleaseObject(pWindow); }
NPError DoDirtyInit() { #ifdef XP_UNIX JVMP_ShmRequest* req = NULL; int* pmsg_id; char* npname; Dl_info nfo; g_data.m_msgid = (int)g_ctx->reserved0; g_data.m_dpy = NULL; NPN_GetValue(NULL, NPNVxDisplay, &(g_data.m_dpy)); if (!AllocateEventWidget(g_data.m_dpy, &(g_data.m_xid))) { fprintf(stderr, "Cannot allocate event widget\n"); return NPERR_GENERIC_ERROR; } req = JVMP_NewShmReq(g_data.m_msgid, JVMP_NEW_EXT_FUNCNO(WFNetscape4VendorID, 1)); JVMP_EncodeRequest(req, "Ii", g_data.m_xid, &(g_data.m_msgid1)); if (!JVMP_SendShmRequest(req, 1)) return NPERR_GENERIC_ERROR; JVMP_WaitConfirmShmRequest(req); if (!req->retval) return NPERR_GENERIC_ERROR; pmsg_id = &(g_data.m_msgid1); JVMP_DecodeRequest(req, 0, "Ii", &g_data.m_xid, &pmsg_id); /* just to increment refcount and forbid to unload plugin DLL */ if (dladdr(&DoDirtyInit, &nfo) != 0) LoadDlLibrary(nfo.dli_fname); g_inited = 1; #endif return NPERR_NO_ERROR; }
NPObject * mmp_script_get_window (NPP npp) { NPObject *window; g_return_val_if_fail (NPN_GetValue (npp, NPNVWindowNPObject, &window) == NPERR_NO_ERROR, NULL); return window; }
NPObject* CPlugin::GetEnvironmentObject(NPNVariable variable, const TCHAR* szDescription) const { NPObject* pObject; if ((NPN_GetValue(m_pNPInstance, variable, &pObject) != NPERR_NO_ERROR) || !pObject) throw CString(_T("Cannot get ")) + szDescription; return pObject; }
CNPPluginMisc::CNPPluginMisc(NPP pNPInstance) : m_pNPInstance(pNPInstance), m_pWindowObj(NULL), m_bInitialized(FALSE), m_pScriptableObject(NULL) { m_hWnd = NULL; NPN_GetValue(m_pNPInstance, NPNVWindowNPObject, &m_pWindowObj); }
static NPError staticPluginQuirkRequiresGtkToolKit_NPN_GetValue(NPP instance, NPNVariable variable, void* value) { if (variable == NPNVToolkit) { *static_cast<uint32_t*>(value) = 2; return NPERR_NO_ERROR; } return NPN_GetValue(instance, variable, value); }
NS_METHOD CPluginInstancePeer::GetValue(nsPluginInstancePeerVariable variable, void *value) { #ifdef XP_UNIX return fromNPError[NPN_GetValue(NULL, (NPNVariable)varMap[(int)variable], value)]; #else return fromNPError[NPERR_GENERIC_ERROR]; #endif // XP_UNIX }
// 获取Plugin所在页面的URL CString CPlugin::GetHostURL() const { CString url; BOOL bOK = FALSE; NPObject* pWindow = NULL; NPVariant vLocation; VOID_TO_NPVARIANT(vLocation); NPVariant vHref; VOID_TO_NPVARIANT(vHref); try { if (( NPN_GetValue( m_pNPInstance, NPNVWindowNPObject, &pWindow) != NPERR_NO_ERROR ) || !pWindow ) { throw(CString(_T("Cannot get window"))); } if ((!NPN_GetProperty( m_pNPInstance, pWindow, NPN_GetStringIdentifier ("location"), &vLocation)) || !NPVARIANT_IS_OBJECT (vLocation)) { throw(CString(_T("Cannot get window.location"))); } if ((!NPN_GetProperty( m_pNPInstance, NPVARIANT_TO_OBJECT(vLocation), NPN_GetStringIdentifier ("href"), &vHref)) || !NPVARIANT_IS_STRING(vHref)) { throw(CString(_T("Cannot get window.location.href"))); } // 转换window.location.href的编码 int buffer_size = vHref.value.stringValue.UTF8Length + 1; char* szUnescaped = new char[buffer_size]; DWORD dwSize = buffer_size; if (SUCCEEDED(UrlUnescapeA(const_cast<LPSTR>(vHref.value.stringValue.UTF8Characters), szUnescaped, &dwSize, 0))) { WCHAR* szURL = new WCHAR[dwSize + 1]; if (MultiByteToWideChar(CP_UTF8, 0, szUnescaped, -1, szURL, dwSize + 1) > 0) { url = CW2T(szURL); } delete[] szURL; } delete[] szUnescaped; } catch (CString strMessage) { TRACE(_T("[CPlugin::GetHostURL Exception] %s"), strMessage); } if (!NPVARIANT_IS_VOID(vHref)) NPN_ReleaseVariantValue(&vHref); if (!NPVARIANT_IS_VOID(vLocation)) NPN_ReleaseVariantValue(&vLocation); if (pWindow != NULL) NPN_ReleaseObject(pWindow); return url; }
JsAgent::JsAgent(NPP npp) : NPObjectWrapper<JsAgent>(npp) , m_channel(new Channel()) , m_helper(NULL) , m_lastRefId(1) { if (NPN_GetValue(npp, NPNVWindowNPObject, &m_window) != NPERR_NO_ERROR) { Debug::println("Error getting window object"); } }
CPlugin::CPlugin(NPP pNPInstance) : m_pNPInstance(pNPInstance), m_pNPStream(NULL), m_bInitialized(false), m_pScriptableObject(NULL) { OutputDebugStringA("cplugin_cplugin"); #ifdef XP_WIN m_hWnd = NULL; #endif NPN_GetValue(m_pNPInstance, NPNVWindowNPObject, &sWindowObj); cinput=NULL; }
ScriptablePluginObject::ScriptablePluginObject(NPP npp) : ScriptablePluginObjectBase(npp) { // Get the instance of the browser window object NPN_GetValue(npp, NPNVWindowNPObject, &sWindowObj); // define some npids for HTML elements that we commonly use. sDocument_id = NPN_GetStringIdentifier("document"); sBody_id = NPN_GetStringIdentifier("body"); // these are the element npid used to create new elements to be appended to the dom sCreateElement_id = NPN_GetStringIdentifier("createElement"); sCreateTextNode_id = NPN_GetStringIdentifier("createTextNode"); // used to append to the loaded dom sAppendChild_id = NPN_GetStringIdentifier("appendChild"); }
bool convert_js_to_mrb_object(NPP npp, const NPVariant &variant, mrb_state *mrb, mrb_value *result) { if (NPVARIANT_IS_MRB_JS_OBJECT(variant)){ MrbJsObject *obj = static_cast< MrbJsObject* >(NPVARIANT_TO_OBJECT(variant)); *result = obj->Value(); return true; } NPObject *window; NPN_GetValue(npp, NPNVWindowNPObject, &window); NPVariant object; NPN_GetProperty(npp, window, NPN_GetStringIdentifier("Object"), &object); NPN_ReleaseObject(window); NPVariant prototype; NPN_GetProperty(npp, NPVARIANT_TO_OBJECT(object), NPN_GetStringIdentifier("prototype"), &prototype); NPN_ReleaseVariantValue(&object); NPVariant to_string; NPN_GetProperty(npp, NPVARIANT_TO_OBJECT(prototype), NPN_GetStringIdentifier("toString"), &to_string); NPN_ReleaseVariantValue(&prototype); NPVariant type_string; NPN_Invoke(npp, NPVARIANT_TO_OBJECT(to_string), NPN_GetStringIdentifier("call"), &variant, 1, &type_string); NPN_ReleaseVariantValue(&to_string); if (!NPVARIANT_IS_STRING(type_string)){ NPN_ReleaseVariantValue(&type_string); return false; } std::string type(NPVARIANT_TO_STRING(type_string).UTF8Characters, NPVARIANT_TO_STRING(type_string).UTF8Length); NPN_ReleaseVariantValue(&type_string); if (type == "[object Array]"){ return convert_js_to_mrb_array(npp, variant, mrb, result); }else if (type == "[object Object]"){ return convert_js_to_mrb_hash(npp, variant, mrb, result); }else if (type == "[object Function]"){ return convert_js_to_mrb_function(npp, variant, mrb, result); }else{ *result = mrb_js_obj_class_new(mrb, NPVARIANT_TO_OBJECT(variant)); return true; } return true; }
////////////////////////////////////// // // general initialization and shutdown // NPError NS_PluginInitialize() { // this is probably a good place to get the service manager // note that Mozilla will add reference, so do not forget to release nsISupports * sm = NULL; NPN_GetValue(NULL, NPNVserviceManager, &sm); // Mozilla returns nsIServiceManager so we can use it directly; doing QI on // nsISupports here can still be more appropriate in case something is changed // in the future so we don't need to do casting of any sort. if(sm) { sm->QueryInterface(NS_GET_IID(nsIServiceManager), (void**)&gServiceManager); NS_RELEASE(sm); } return NPERR_NO_ERROR; }
double CPlugin::GetZoomLevel() { double level = 1; NPObject* pWindow = NULL; NPVariant vCOBA; VOID_TO_NPVARIANT(vCOBA); NPVariant vLevel; VOID_TO_NPVARIANT(vLevel); try { if ((NPN_GetValue( m_pNPInstance, NPNVWindowNPObject, &pWindow) != NPERR_NO_ERROR ) || !pWindow ) { throw(CString(_T("Cannot get window"))); } if ((!NPN_GetProperty( m_pNPInstance, pWindow, NPN_GetStringIdentifier ("COBA"), &vCOBA)) || !NPVARIANT_IS_OBJECT (vCOBA)) { throw(CString(_T("Cannot get window.COBA"))); } if (!NPN_Invoke(m_pNPInstance, NPVARIANT_TO_OBJECT(vCOBA), NPN_GetStringIdentifier("getZoomLevel"), NULL, 0, &vLevel)) { throw(CString(_T("Cannot execute window.COBA.getZoomLevel()"))); } if (NPVARIANT_IS_DOUBLE(vLevel)) level = NPVARIANT_TO_DOUBLE(vLevel); else if ( NPVARIANT_IS_INT32(vLevel) ) level = NPVARIANT_TO_INT32(vLevel); } catch (CString strMessage) { level = 1; TRACE(_T("[CPlugin::FireEvent Exception] %s"), strMessage); } if (!NPVARIANT_IS_VOID(vLevel)) NPN_ReleaseVariantValue(&vLevel); if (!NPVARIANT_IS_VOID(vCOBA)) NPN_ReleaseVariantValue(&vCOBA); if (pWindow != NULL) NPN_ReleaseObject(pWindow); return level; }
CString CPlugin::GetNavigateParam(const NPUTF8* name) const { CString strParam; NPObject* pWindow = NULL; NPVariant vCOBAContainer; VOID_TO_NPVARIANT(vCOBAContainer); NPVariant vParam; VOID_TO_NPVARIANT(vParam); try { if ((NPN_GetValue( m_pNPInstance, NPNVWindowNPObject, &pWindow) != NPERR_NO_ERROR ) || !pWindow ) { throw(CString(_T("Cannot get window"))); } if ((!NPN_GetProperty( m_pNPInstance, pWindow, NPN_GetStringIdentifier ("COBAContainer"), &vCOBAContainer)) || !NPVARIANT_IS_OBJECT (vCOBAContainer)) { throw(CString(_T("Cannot get window.COBAContainer"))); } if (!NPN_Invoke(m_pNPInstance, NPVARIANT_TO_OBJECT(vCOBAContainer), NPN_GetStringIdentifier(name), NULL, 0, &vParam)) { throw(CString(_T("Cannot execute window.COBAContainer.getXXX()"))); } if (!NPVARIANT_IS_STRING(vParam)) { throw(CString(_T("Invalid return value."))); } strParam = NPStringToCString(vParam.value.stringValue); } catch (CString strMessage) { TRACE(_T("[CPlugin::GetNavigateHeaders Exception] %s"), strMessage); } if (!NPVARIANT_IS_VOID(vParam)) NPN_ReleaseVariantValue(&vParam); if (!NPVARIANT_IS_VOID(vCOBAContainer)) NPN_ReleaseVariantValue(&vCOBAContainer); if (pWindow != NULL) NPN_ReleaseObject(pWindow); return strParam; }
extern "C" NPError WINAPI NP_Initialize(NPNetscapeFuncs* nFuncs, NPPluginFuncs* pFuncs) { if(!nFuncs) return NPERR_INVALID_FUNCTABLE_ERROR; qNetscapeFuncs = nFuncs; int navMajorVers = qNetscapeFuncs->version >> 8; // if the plugin's major version is lower than the Navigator's, // then they are incompatible, and should return an error if(navMajorVers > NP_VERSION_MAJOR) return NPERR_INCOMPATIBLE_VERSION_ERROR; // check if the Browser supports the XEmbed protocol int supportsXEmbed = 0; NPError err = NPN_GetValue(0, NPNVSupportsXEmbedBool, (void *)&supportsXEmbed); if (err != NPERR_NO_ERROR ||!supportsXEmbed) return NPERR_INCOMPATIBLE_VERSION_ERROR; return NP_GetEntryPoints(pFuncs); }
static mrb_value mrb_js_func_call(mrb_state *mrb, mrb_value self) { NPP npp = MRB_UD_NPP(mrb); NPObject *func = (NPObject *)DATA_PTR(self); if (!func){ return mrb_nil_value(); } mrb_value *values; int len; mrb_get_args(mrb, "*", &values, &len); NPVariant empty = { NPVariantType_Void, NULL }; std::vector< NPVariant > args(len + 1, empty); bool success = true; for (int i=0; i<len; i++){ if (!convert_mrb_to_js(mrb, values[i], npp, &args[i + 1])){ success = false; break; } } mrb_value ret = mrb_nil_value(); if (success){ NPObject *window; NPN_GetValue(npp, NPNVWindowNPObject, &window); NPVariant result; OBJECT_TO_NPVARIANT(window, args[0]); NPN_Invoke(npp, func, NPN_GetStringIdentifier("call"), &args[0], args.size(), &result); convert_js_to_mrb(npp, result, mrb, &ret); } for (int i=0; i<len+1; i++){ NPN_ReleaseVariantValue(&args[i]); } return ret; }
gboolean mmp_script_evaluate (NPP npp, const gchar *code) { NPObject *host; NPString string; NPVariant output; gboolean result; g_return_val_if_fail (npp != NULL, FALSE); g_return_val_if_fail (NPN_GetValue (npp, NPNVWindowNPObject, &host) == NPERR_NO_ERROR, FALSE); string.UTF8Characters = code; string.UTF8Length = strlen (code); if ((result = NPN_Evaluate (npp, host, &string, &output))) { NPN_ReleaseVariantValue (&output); } NPN_ReleaseObject (host); return result; }
int QtSignalForwarder::qt_metacall(QMetaObject::Call call, int index, void **args) { // no support for QObject method/properties etc! if (!This || !This->npp || call != QMetaObject::InvokeMetaMethod || !This->qt.object) return index; switch (index) { case -1: { QString msg = *(QString*)args[1]; NPN_Status(This->npp, msg.toLocal8Bit().constData()); } break; default: { QObject *qobject = This->qt.object; if (!domNode) NPN_GetValue(This->npp, NPNVPluginElementNPObject, &domNode); if (!domNode) break; const QMetaObject *metaObject = qobject->metaObject(); if (index < metaOffset(metaObject, MetaMethod)) break; const QMetaMethod method = metaObject->method(index); Q_ASSERT(method.methodType() == QMetaMethod::Signal); QByteArray signalSignature = method.signature(); QByteArray scriptFunction = signalSignature.left(signalSignature.indexOf('(')); NPIdentifier id = NPN_GetStringIdentifier(scriptFunction.constData()); if (NPN_HasMethod(This->npp, domNode, id)) { QList<QByteArray> parameterTypes = method.parameterTypes(); QVector<NPVariant> parameters; NPVariant result; bool error = false; for (int p = 0; p < parameterTypes.count(); ++p) { QVariant::Type type = QVariant::nameToType(parameterTypes.at(p)); if (type == QVariant::Invalid) { NPN_SetException(domNode, QByteArray("Unsupported parameter type in ") + scriptFunction); error = true; break; } QVariant qvar(type, args[p + 1]); NPVariant npvar = NPVariant::fromQVariant(This, qvar); if (npvar.type == NPVariant::Null || npvar.type == NPVariant::Void) { NPN_SetException(domNode, QByteArray("Unsupported parameter value in ") + scriptFunction); error =true; break; } parameters += npvar; } if (error) break; NPError nperror = NPN_Invoke(This->npp, domNode, id, parameters.constData(), parameters.count(), &result); if (nperror != NPERR_NO_ERROR && false) { // disabled, as NPN_Invoke seems to always return GENERICERROR NPN_SetException(domNode, QByteArray("Error invoking event handler ") + scriptFunction); } // ### TODO: update return value (args[0]) (out-parameters not supported anyway) NPN_ReleaseVariantValue(&result); } } break; } return index; }
HRESULT nsEventSink::InternalInvoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr) { FUNCDESC *pFuncDesc = NULL; HRESULT hr = S_OK; CComBSTR bstrName; // Must search and compare each member to the dispid... if (m_spEventSinkTypeInfo) { HRESULT hr = S_OK; TYPEATTR* pAttr; hr = m_spEventSinkTypeInfo->GetTypeAttr(&pAttr); if (pAttr) { int i; for (i = 0; i < pAttr->cFuncs;i++) { hr = m_spEventSinkTypeInfo->GetFuncDesc(i, &pFuncDesc); if (FAILED(hr)) return hr; if (pFuncDesc->memid == dispIdMember) { UINT cNames = 0; m_spEventSinkTypeInfo->GetNames(dispIdMember, &bstrName, 1, &cNames); break; } m_spEventSinkTypeInfo->ReleaseFuncDesc(pFuncDesc); pFuncDesc = NULL; } m_spEventSinkTypeInfo->ReleaseTypeAttr(pAttr); } } if (!pFuncDesc) { // Return return S_OK; } #ifdef DEBUG { // Dump out some info to look at ATLTRACE(_T("Invoke(%d)\n"), (int) dispIdMember); ATLTRACE(_T(" ")); /* Return code */ switch (pFuncDesc->elemdescFunc.tdesc.vt) { case VT_HRESULT: ATLTRACE(_T("HRESULT")); break; case VT_VOID: ATLTRACE(_T("void")); break; default: ATLTRACE(_T("void /* vt = %d */"), pFuncDesc->elemdescFunc.tdesc.vt); break; } /* Function name */ ATLTRACE(_T(" %S("), SUCCEEDED(hr) ? bstrName.m_str : L"?unknown?"); /* Parameters */ for (int i = 0; i < pFuncDesc->cParams; i++) { USHORT paramFlags = pFuncDesc->lprgelemdescParam[i].paramdesc.wParamFlags; ATLTRACE("["); BOOL addComma = FALSE; if (paramFlags & PARAMFLAG_FIN) { ATLTRACE(_T("in")); addComma = TRUE; } if (paramFlags & PARAMFLAG_FOUT) { ATLTRACE(addComma ? _T(",out") : _T("out")); addComma = TRUE; } if (paramFlags & PARAMFLAG_FRETVAL) { ATLTRACE(addComma ? _T(",retval") : _T("retval")); addComma = TRUE; } ATLTRACE("] "); VARTYPE vt = pFuncDesc->lprgelemdescParam[i].tdesc.vt; switch (vt) { case VT_HRESULT: ATLTRACE(_T("HRESULT")); break; case VT_VARIANT: ATLTRACE(_T("VARIANT")); break; case VT_I2: ATLTRACE(_T("short")); break; case VT_I4: ATLTRACE(_T("long")); break; case VT_R8: ATLTRACE(_T("double")); break; case VT_BOOL: ATLTRACE(_T("VARIANT_BOOL")); break; case VT_BSTR: ATLTRACE(_T("BSTR")); break; case VT_DISPATCH: ATLTRACE(_T("IDispatch *")); break; case VT_UNKNOWN: ATLTRACE(_T("IUnknown *")); break; case VT_USERDEFINED: ATLTRACE(_T("/* Userdefined */")); break; case VT_PTR: ATLTRACE(_T("void *")); break; case VT_VOID: ATLTRACE(_T("void")); break; // More could be added... default: ATLTRACE(_T("/* vt = %d */"), vt); break; } if (i + 1 < pFuncDesc->cParams) { ATLTRACE(_T(", ")); } } ATLTRACE(_T(");\n")); } #endif m_spEventSinkTypeInfo->ReleaseFuncDesc(pFuncDesc); pFuncDesc = NULL; nsCOMPtr<nsIDOMElement> element; NPN_GetValue(mPlugin->pPluginInstance, NPNVDOMElement, static_cast<nsIDOMElement **>(getter_AddRefs(element))); if (!element) { NS_ERROR("can't get the object element"); return S_OK; } nsAutoString id; if (NS_FAILED(element->GetAttribute(NS_LITERAL_STRING("id"), id)) || id.IsEmpty()) { // Object has no name so it can't fire events return S_OK; } nsDependentString eventName(bstrName.m_str); // Fire the script event handler... nsCOMPtr<nsIDOMWindow> window; NPN_GetValue(mPlugin->pPluginInstance, NPNVDOMWindow, static_cast<nsIDOMWindow **>(getter_AddRefs(window))); nsCOMPtr<nsIScriptEventManager> eventManager(do_GetInterface(window)); if (!eventManager) return S_OK; nsCOMPtr<nsISupports> handler; eventManager->FindEventHandler(id, eventName, pDispParams->cArgs, getter_AddRefs(handler)); if (!handler) { return S_OK; } // Create a list of arguments to pass along // // This array is created on the stack if the number of arguments // less than kMaxArgsOnStack. Otherwise, the array is heap // allocated. // const int kMaxArgsOnStack = 10; PRUint32 argc = pDispParams->cArgs; jsval *args = nsnull; jsval stackArgs[kMaxArgsOnStack]; // Heap allocate the jsval array if it is too big to fit on // the stack (ie. more than kMaxArgsOnStack arguments) if (argc > kMaxArgsOnStack) { args = new jsval[argc]; if (!args) return S_OK; } else if (argc) { // Use the jsval array on the stack... args = stackArgs; } if (argc) { nsCOMPtr<nsIDispatchSupport> disp(do_GetService("@mozilla.org/nsdispatchsupport;1")); for (UINT i = 0; i < argc; i++) { // Arguments are listed backwards, intentionally, in rgvarg disp->COMVariant2JSVal(&pDispParams->rgvarg[argc - 1 - i], &args[i]); } } // Fire the Event. eventManager->InvokeEventHandler(handler, element, args, argc); // Free the jsvals if they were heap allocated... if (args != stackArgs) { delete [] args; } // TODO Turn js objects for out params back into VARIANTS // TODO Turn js return code into VARIANT // TODO handle js exception and fill in exception info (do we care?) if (pExcepInfo) { pExcepInfo->wCode = 0; } return S_OK; }
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 MessageBox(NULL, "begin", "test", MB_OK); NPN_GetValue(m_pNPInstance, NPNVWindowNPObject, &sWindowObj); // 添加自定义方法 sGetVersion = NPN_GetStringIdentifier("GetVersion"); /* 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); MessageBox(NULL, "end", "test", MB_OK); }
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; }
// 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; }
BOOL CPlugin::init(HWND hWndParent) { dbgOut1("CPlugin::init()"); nsISupports * sm = NULL; nsIPrefBranch * prefBranch = NULL; PRBool bSendUrls = PR_FALSE; // default to false if problem getting pref // note that Mozilla will add reference, so do not forget to release NPN_GetValue(NULL, NPNVserviceManager, &sm); // do a QI on the service manager we get back to ensure it's the one we are expecting if(sm) { sm->QueryInterface(NS_GET_IID(nsIServiceManager), (void**)&gServiceManager); NS_RELEASE(sm); } if (gServiceManager) { // get service using its contract id and use it to allocate the memory gServiceManager->GetServiceByContractID(NS_PREFSERVICE_CONTRACTID, NS_GET_IID(nsIPrefBranch), (void **)&prefBranch); if(prefBranch) { prefBranch->GetBoolPref("application.use_ns_plugin_finder", &bSendUrls); NS_RELEASE(prefBranch); } } m_bSmartUpdate = bSendUrls; if(!m_bHidden) { assert(IsWindow(hWndParent)); if(IsWindow(hWndParent)) m_hWndParent = hWndParent; RECT rcParent; GetClientRect(m_hWndParent, &rcParent); CreateWindow(szNullPluginWindowClassName, "NULL Plugin", WS_CHILD, 0,0, rcParent.right, rcParent.bottom, m_hWndParent, (HMENU)NULL, m_hInst, (LPVOID)this); assert(m_hWnd != NULL); if((m_hWnd == NULL) || (!IsWindow(m_hWnd))) return FALSE; UpdateWindow(m_hWnd); ShowWindow(m_hWnd, SW_SHOW); } if(IsNewMimeType((LPSTR)m_pNPMIMEType) || m_bHidden) showGetPluginDialog(); return TRUE; }
NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[]) { /* prepare VLC command line */ const char *ppsz_argv[32]; int ppsz_argc = 0; #ifndef NDEBUG ppsz_argv[ppsz_argc++] = "--no-plugins-cache"; #endif /* locate VLC module path */ #ifdef XP_MACOSX ppsz_argv[ppsz_argc++] = "--plugin-path=/Library/Internet\\ Plug-Ins/VLC\\ Plugin.plugin/Contents/MacOS/modules"; ppsz_argv[ppsz_argc++] = "--vout=minimal_macosx"; #elif defined(XP_WIN) HKEY h_key; DWORD i_type, i_data = MAX_PATH + 1; char p_data[MAX_PATH + 1]; if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\VideoLAN\\VLC", 0, KEY_READ, &h_key ) == ERROR_SUCCESS ) { if( RegQueryValueEx( h_key, "InstallDir", 0, &i_type, (LPBYTE)p_data, &i_data ) == ERROR_SUCCESS ) { if( i_type == REG_SZ ) { strcat( p_data, "\\plugins" ); ppsz_argv[ppsz_argc++] = "--plugin-path"; ppsz_argv[ppsz_argc++] = p_data; } } RegCloseKey( h_key ); } ppsz_argv[ppsz_argc++] = "--no-one-instance"; #endif /* XP_MACOSX */ /* common settings */ ppsz_argv[ppsz_argc++] = "-vv"; ppsz_argv[ppsz_argc++] = "--no-stats"; ppsz_argv[ppsz_argc++] = "--no-media-library"; ppsz_argv[ppsz_argc++] = "--intf=dummy"; ppsz_argv[ppsz_argc++] = "--no-video-title-show"; const char *progid = NULL; /* parse plugin arguments */ for( int i = 0; (i < argc) && (ppsz_argc < 32); i++ ) { /* fprintf(stderr, "argn=%s, argv=%s\n", argn[i], argv[i]); */ if( !strcmp( argn[i], "target" ) || !strcmp( argn[i], "mrl") || !strcmp( argn[i], "filename") || !strcmp( argn[i], "src") ) { psz_target = argv[i]; } else if( !strcmp( argn[i], "text" ) ) { free( psz_text ); psz_text = strdup( argv[i] ); } else if( !strcmp( argn[i], "autoplay") || !strcmp( argn[i], "autostart") ) { b_autoplay = boolValue(argv[i]); } else if( !strcmp( argn[i], "fullscreen" ) ) { if( boolValue(argv[i]) ) { ppsz_argv[ppsz_argc++] = "--fullscreen"; } else { ppsz_argv[ppsz_argc++] = "--no-fullscreen"; } } else if( !strcmp( argn[i], "mute" ) ) { if( boolValue(argv[i]) ) { ppsz_argv[ppsz_argc++] = "--volume=0"; } } else if( !strcmp( argn[i], "loop") || !strcmp( argn[i], "autoloop") ) { if( boolValue(argv[i]) ) { ppsz_argv[ppsz_argc++] = "--loop"; } else { ppsz_argv[ppsz_argc++] = "--no-loop"; } } else if( !strcmp( argn[i], "version") || !strcmp( argn[i], "progid") ) { progid = argv[i]; } else if( !strcmp( argn[i], "toolbar" ) ) { /* FIXME: Remove this when toolbar functionality has been implemented on * MacOS X and Win32 for Firefox/Mozilla/Safari. */ #ifdef XP_UNIX b_toolbar = boolValue(argv[i]); #endif } } libvlc_exception_t ex; libvlc_exception_init(&ex); libvlc_instance = libvlc_new(ppsz_argc, ppsz_argv, &ex); if( libvlc_exception_raised(&ex) ) { libvlc_exception_clear(&ex); return NPERR_GENERIC_ERROR; } libvlc_media_list = libvlc_media_list_new(libvlc_instance,&ex); if( libvlc_exception_raised(&ex) ) { libvlc_exception_clear(&ex); return NPERR_GENERIC_ERROR; } /* ** fetch plugin base URL, which is the URL of the page containing the plugin ** this URL is used for making absolute URL from relative URL that may be ** passed as an MRL argument */ NPObject *plugin = NULL; if( NPERR_NO_ERROR == NPN_GetValue(p_browser, NPNVWindowNPObject, &plugin) ) { /* ** is there a better way to get that info ? */ static const char docLocHref[] = "document.location.href"; NPString script; NPVariant result; script.utf8characters = docLocHref; script.utf8length = sizeof(docLocHref)-1; if( NPN_Evaluate(p_browser, plugin, &script, &result) ) { if( NPVARIANT_IS_STRING(result) ) { NPString &location = NPVARIANT_TO_STRING(result); psz_baseURL = (char *) malloc(location.utf8length+1); if( psz_baseURL ) { strncpy(psz_baseURL, location.utf8characters, location.utf8length); psz_baseURL[location.utf8length] = '\0'; } } NPN_ReleaseVariantValue(&result); } NPN_ReleaseObject(plugin); } if( psz_target ) { // get absolute URL from src char *psz_absurl = getAbsoluteURL(psz_target); psz_target = psz_absurl ? psz_absurl : strdup(psz_target); } /* assign plugin script root class */ /* new APIs */ p_scriptClass = RuntimeNPClass<LibvlcRootNPObject>::getClass(); return NPERR_NO_ERROR; }