[英]Firefox 29, XPCOM and wrappedJSObject
我們正在使用Firefox的自定義純Java插件,該插件已在我們的某些Intranet網站中使用。 該加載項應該從用戶的PC加載特定的文本文件,然后將特定的變量公開給我們的某些Intranet頁面。
當前實現從FF3到FF28。 在FF29中,wrappedJSObject的行為已更改。
這是我在附加代碼中得到的:
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
function PrivateClass() {
this.wrappedJSObject = this;
}
PrivateClass.prototype = {
// Component details
classDescription: "...",
classID: Components.ID("{...}"),
contractID: "@foo.bar/PrivateClass;1",
QueryInterface: XPCOMUtils.generateQI([Ci.nsIClassInfo]),
getInterfaces: function(countRef) {
var interfaces = [Ci.nsIClassInfo, Ci.nsISupports];
countRef.value = interfaces.length;
return interfaces;
},
implementationLanguage: Components.interfaces.nsIProgrammingLanguage.JAVASCRIPT,
flags: Ci.nsIClassInfo.DOM_OBJECT,
getHelperForLanguage: function(count) { return null; },
// We use the default _xpcom_factory
// Categories to register
_xpcom_categories: [{
category: "JavaScript global property",
entry: "PrivateClass", // optional, defaults to the object's classDescription. Needed for FF3.
value: "@foo.bar/PrivateClass;1", // optional, defaults to the object's contractID. Needed for FF3.
service: false
}],
// nsISecurityCheckedComponent permissions
// return "AllAccess"; / return "NoAccess";
canCreateWrapper : function canCreateWrapper(aIID) { return "AllAccess"; },
canCallMethod: function canCallMethod(aIID, methodName) { return "AllAccess"; },
canGetProperty: function canGetProperty(aIID, propertyName) { return "AllAccess"; }, // needed to access wrappedJSObject
canSetProperty: function canSetProperty(aIID, propertyName) { return "NoAccess"; },
getFunctionA : function() { return "This is A"; },
getFunctionB : function() { return "This is B"; },
// New functionality, needed for FF 17+
// https://developer.mozilla.org/en-US/docs/XPConnect_wrappers#__exposedProps__
__exposedProps__ : { getFunctionA : "r", getFunctionB : "r" }
}
並在客戶端頁面中:
if (typeof PrivateClass != "undefined") {
var obj = PrivateClass.wrappedJSObject;
var a = obj.getFunctionA()
var b = obj.getFunctionB();
}
但是,現在FF返回Error: Attempt to use .wrappedJSObject in untrusted code
在此行的Error: Attempt to use .wrappedJSObject in untrusted code
中Error: Attempt to use .wrappedJSObject in untrusted code
:
var obj = PrivateClass.wrappedJSObject;
我已經在此博客文章中了解了FF30中包裝的JSObject即將發生的更改: https ://blog.mozilla.org/addons/2014/04/10/changes-to-unsafewindow-for-the-add-on-sdk /
...但是推薦的解決方案對我不起作用
請注意,包裝的JSObject解決方案在此處和此處的官方Mozilla開發人員文檔中。 也可以在Internet各處找到它(例如here ),但是顯然在FF29中它已經以某種方式被破壞/更改,因此這些都不適用。
我已經檢查了出色的FF插件jsPrintSetup ,它沒有使用wrappedJSObject(盡管它也具有C ++二進制組件,這也許可以解釋這一點)。 我已經閱讀了很多有關wrappedJSObject的有關此問題的論壇帖子,但找不到有關此行為的特定更改的任何信息。 任何人都可以闡明在FF29 +下運行該功能需要做什么嗎?
是的,我添加了一項檢查不受信任的內容的檢查,以檢查XPCOM組件的內臟,它實際上與業務無關。 從特權代碼來看,它仍然應該可以正常工作。
另請注意,nsISecurityCheckedComponent已刪除 ,因此您不再需要該部分。
通常,將API暴露給內容的最可行的方法是使用exportFunction將其直接注入內容范圍。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.