两天多来,我一直在用头撞这堵特殊的砖墙。我正在尝试创建用于 Firefox 扩展的 XPCOM 服务,但无法初始化组件,并在 Firefox 的错误控制台中显示以下错误。
Timestamp: 07/06/2012 09:23:28 Error: uncaught exception: [Exception...
"Component returned failure code: 0x80570016 (NS_ERROR_XPC_GS_RETURNED_FAILURE)
[nsIJSCID.getService]" nsresult: "0x80570016 (NS_ERROR_XPC_GS_RETURNED_FAILURE)"
location: "JS frame :: chrome://logger/content/logger.js :: <TOP_LEVEL> :: line 21"
data: no]
我使用ted.mielczarek.org上出色的样板生成器将组件减少到最低限度。组件代码如下...
const nsISupports = Components.interfaces.nsISupports;
const CLASS_ID = Components.ID("808e1607-caea-418c-b563-d9fe1df6ee08");
const CLASS_NAME = "Test component";
const CONTRACT_ID = "@test/loggerservice;1";
function LoggerService() {
this.wrappedJSObject = this;
}
LoggerService.prototype = {
QueryInterface: function(aIID)
{
if (!aIID.equals(nsISupports))
throw Components.results.NS_ERROR_NO_INTERFACE;
return this;
}
}
创建模块和工厂接口的样板的其余部分保持不变。
chrome.manifest 文件看起来像这样......
content logger chrome/content/
skin logger classic/1.0 chrome/skin/
locale logger en-US chrome/locale/en-US/
component {808e1607-caea-418c-b563-d9fe1df6ee08} components/loggerservice.js
contract @test/loggerservice;1 {808e1607-caea-418c-b563-d9fe1df6ee08}
overlay chrome://browser/content/browser.xul chrome://logger/content/logger-overlay.xul
style chrome://global/content/customizeToolbar.xul chrome://logger/skin/overlay.css
最后,该logger-overlay.xul
文件包含一个脚本文件logger.js
——它尝试LoggerService
使用以下代码获取对组件的引用...
this.loggerService = Components.classes["@test/logger;1"].getService().wrappedJSObject;
正是这一行在 Firefox 错误控制台中报告。
我看不出我可以使它变得多么简单-非常感谢任何见解。