我書面方式一個NPAPI插件,它包含兩個插件類型:NPAPI調用參數包裝
- 的x捕獲用於從相機
- X-展示用於顯示圖像捕獲捕獲一些視頻通過x捕獲對象
和我有一個使用插件以下HTML/JavaScript代碼:
<html>
<embed id="display" type="application/x-display" width=640 height=480 /></td>
<embed id="capture" type="application/x-capture" width=0 height=0 /><br> <!-- windowless plugin -->
<script>
var capture = document.getElementById('capture');
var display = document.getElementById('display');
capture.addDisplay(display);
</script>
</html>
我的問題是,我的庫中addDisplay的調用接收到不同的NPObject指針作爲調用參數,然後與提供的x-display的實例關聯。 另外,收到的NPObject結構的_class成員與我在創建x-display腳本對象時提供的成員不同。
在嘗試枚舉接收對象的方法(來自handleAddDisplay函數)以瞭解更多關於接收參數類型的信息之後,我得到了一個包含nsJSObjWrapper的調用堆棧(我正在Firefox/Windows上測試它) 。我的庫是npCaptureDemoPlugin.dll。最後,包裝器正在調用顯示對象的枚舉。
npCaptureDemoPlugin.dll!RendererPlugin::hasMethod(void * name=0x06311d00) Line 84 C++
npCaptureDemoPlugin.dll!ScriptableObject<RendererPlugin>::Class::hasMethod(NPObject* object=0x191fd0b4, void * name=0x06311d00) Line 382 + 0x43 bytes C++
xul.dll!NPObjWrapper_NewResolve(JSContext * cx=0x13bf8f60, JSObject * obj=0x0650c4c0, int id=0x06311d00, unsigned int flags=0x00000001, JSObject * * objp=0x003cb838) Line 1659 C++
mozjs.dll!CallResolveOp(JSContext * cx=0x13bf8f60, JSObject * start=0x0650c4a0, JS::Handle<JSObject *> obj={...}, JS::Handle<int> id={...}, unsigned int flags=0x00000000, JSObject * * objp=0x003cb8dc, JSProperty * * propp=0x003cb8d4, bool * recursedp=0x003cb883) Line 4637 + 0x1b bytes C++
mozjs.dll!js_LookupProperty(JSContext * cx=0x13bf8f60, JSObject * obj=0x0650c4a0, int id=0x06311d00, JSObject * * objp=0x003cb8dc, JSProperty * * propp=0x003cb8d4) Line 4745 + 0x7a bytes C++
mozjs.dll!JS_LookupPropertyById(JSContext * cx=0x00000000, JSObject * obj=0x0650c4a0, int id=0x06311d00, JS::Value * vp=0x003cb8e4) Line 3502 + 0x49 bytes C++
xul.dll!xpc_ForcePropertyResolve(JSContext * cx=0x13bf8f60, JSObject * obj=0x0650c4a0, int id=0x06311d00) Line 652 + 0x13 bytes C++
xul.dll!XPC_WN_Shared_Enumerate(JSContext * cx=0x13bf8f60, JSObject * obj=0x0650c4a0) Line 605 + 0xe bytes C++
xul.dll!XPC_WN_JSOp_Enumerate(JSContext * cx=0x13bf8f60, JSObject * obj=0x0650c4a0, JSIterateOp enum_op=JSENUMERATE_INIT, JS::Value * statep=0x003cbaf4, int * idp=0x00000000) Line 1275 + 0x1b bytes C++
mozjs.dll!Snapshot(JSContext * cx=0x00000000, JSObject * obj=0x00000000, unsigned int flags=0x00000008, JS::AutoIdVector * props=0x003cbb78) Line 364 + 0x25 bytes C++
mozjs.dll!js::GetPropertyNames(JSContext * cx=0x13bf8f60, JSObject * obj=0x0650c4a0, unsigned int flags=0x00000008, JS::AutoIdVector * props=0x003cbb78) Line 440 + 0x1a bytes C++
mozjs.dll!JS_Enumerate(JSContext * cx=0x13bf8f60, JSObject * obj=0x0650c4a0) Line 4241 + 0x34 bytes C++
xul.dll!nsJSObjWrapper::NP_Enumerate(NPObject * npobj=0x089cbd90, void * * * idarray=0x003cbf74, unsigned int * count=0x003cbf68) Line 968 + 0xe bytes C++
xul.dll!mozilla::plugins::parent::_enumerate(_NPP * npp=0x10eff7c8, NPObject * npobj=0x089cbd90, void * * * identifier=0x003cbf74, unsigned int * count=0x003cbf68) Line 1900 + 0xc bytes C++
npCaptureDemoPlugin.dll!NPN_Enumerate(_NPP * npp=0x10eff7c8, NPObject * obj=0x089cbd90, void * * * identifier=0x003cbf74, unsigned int * count=0x003cbf68) Line 254 + 0x18 bytes C++
npCaptureDemoPlugin.dll!CapturePlugin::handleAddDisplay(NPObject * object=0x089cbd90) Line 382 + 0x18 bytes C++
npCaptureDemoPlugin.dll!CapturePlugin::invoke(void * name=0x13855280, const _NPVariant * args=0x003cc270, unsigned int argCount=0x00000001, _NPVariant * result=0x003cc248) Line 142 + 0xf bytes C++
npCaptureDemoPlugin.dll!ScriptableObject<CapturePlugin>::Class::invoke(NPObject * object=0x191feb04, void * name=0x13855280, const _NPVariant * args=0x003cc270, unsigned int argCount=0x00000001, _NPVariant * result=0x003cc248) Line 414 + 0x4f bytes C++
xul.dll!CallNPMethodInternal(JSContext * cx=0x13bf8f60, JSObject * obj=0x0650c3a0, unsigned int argc=0x00000001, JS::Value * argv=0x05cd0070, JS::Value * rval=0x05cd0060, bool ctorCall=false) Line 1482 + 0x11 bytes C++
所以它看起來像Firefox的總結我NPObject到另一個NPObject其類型我不能處理這NPObject作爲代理來調用我的對象。
我的問題:是否有一種方法將相同的NPObject傳遞給一個函數調用,就像我已經與一個插件實例關聯的一樣?還是有另一種方法來檢查收到的對象作爲參數的調用調用,它是我以前創建的預期類型?或者唯一的方法是使用傳遞給JS的某種本地id並返回到本機代碼,這樣我可以使我的對象之間的關聯?
經過一些調查後,它看起來像收到的NPObject是一個包裝,其中還包括DOM功能(如與/高度屬性等)。解決方案可能是添加一個函數,該函數返回我的可腳本化對象,並在類型不是預期的(包裝器)時,在addDisplay函數中調用該函數。 –
請注意,無窗口插件和不繪製的插件之間存在很大差異。在將其標記爲無窗口之前,請確保您瞭解該差異=] – taxilian
我的錯誤。我正在考慮隱藏VS可見插件。 –