我已經將我的頭撞到了這個特殊的磚牆上,現在已經超過兩天了。我正在嘗試創建一個用於Firefox擴展的XPCOM服務,但無法初始化組件,並在Firefox中的錯誤控制檯中顯示以下錯誤。無法爲Firefox擴展創建JavaScript XPCOM服務
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錯誤控制檯中報告的這一行。
我看不出有多簡單,我可以做到 - 任何洞察力將非常感激。
弗拉基米爾 - 感謝 - 頂級的意見!現在使用XPCOMUtils的代碼更加清潔。最後,我現在可以繼續並發展我的服務! – drew