Javascript Firefox 29、XPCOM和wrappedJSObject

Javascript Firefox 29、XPCOM和wrappedJSObject,javascript,firefox,firefox-addon,firefox-addon-sdk,xpcom,Javascript,Firefox,Firefox Addon,Firefox Addon Sdk,Xpcom,我们正在为Firefox使用一个只支持Javascript的自定义插件,这在我们的一些intranet站点中使用。这个附加组件应该从用户的PC加载一个特定的文本文件,然后将特定的变量暴露到我们的一些intranet页面中 目前的实施工作从FF3到FF28。在FF29中,wrappedJSObject的行为发生了变化 以下是我在加载项代码中得到的信息: Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); func

我们正在为Firefox使用一个只支持Javascript的自定义插件,这在我们的一些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返回
错误:尝试在不受信任的代码中使用.wrappedJSObject

var obj = PrivateClass.wrappedJSObject;
我在这篇博文中读到了FF30中即将对wrappedJSObject进行的更改:

…但推荐的解决方案对我不起作用

请注意,wrappedJSObject解决方案在官方Mozilla开发人员文档和中。它也可以在互联网上找到(例如),但显然它在FF29中被破坏/更改了,所以这些都不适用


我检查了FF插件,它不使用WrAdjdjsObjor(虽然它也有C++二进制组件,这可能解释了这一点)。我已经阅读了很多关于wrappedJSObject这个问题的论坛帖子,但是我找不到任何关于它行为的特殊变化的内容。有人能解释一下,为了让这个功能在FF29+下工作,需要做些什么吗?

是的,我添加了一个针对不受信任内容的检查,检查XPCOM组件的内部,而XPCOM组件实际上不需要这样做。从特权代码来看,它仍然可以正常工作

,所以你不应该再需要那个零件了

一般来说,向内容公开API的最经得起未来考验的方法是使用exportFunction将其直接注入内容范围