2014-05-23 62 views
2

我們正在使用Firefox的自定義Javascript附加組件,該組件在我們的一些Intranet站點中使用。這個插件應該從用戶的PC加載一個特定的文本文件,然後將特定的變量暴露給我們的一些Intranet頁面。Firefox 29,XPCOM和wrappedJSObject

目前的實施工作從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

var obj = PrivateClass.wrappedJSObject; 

我已閱讀關於在此博客文章中對FF30中wrappedJSObject即將發生的更改: https://blog.mozilla.org/addons/2014/04/10/changes-to-unsafewindow-for-the-add-on-sdk/

...但推薦的解決方案不會爲我

注意,wrappedJSObject解決方法是在官方Mozilla開發文檔herehere工作。它也可以在互聯網上找到(例如here),但顯然它已經在某種程度上在FF29中被破​​壞/改變,所以這些都不適用。

我檢查了優秀的FF插件jsPrintSetup,它沒有使用wrappedJSObject(雖然它也有一個C++二進制組件,這也許可以解釋這一點)。我已經閱讀了很多論壇帖子,關於這個與wrappedJSObject有關的問題,但我無法找到任何有關此行爲的特定更改。任何人都可以說明爲了使這個功能在FF29 +下工作需要做些什麼?

回答

1

是的,我添加了一個檢查不可信內容的檢查,檢查XPCOM組件的內核,它真的沒有業務。它應該仍然適用於特權代碼。

Also note that nsISecurityCheckedComponent was removed,所以你不應該再需要那個部分了。

通常,將API暴露給內容的最有前途的方法是將其直接注入到帶有exportFunction的內容範圍中。

Extra info