2010-02-08 68 views
2

我正在測試包含Firefox擴展作爲一個組件的應用程序。它最初是在FF3.5.5是最新版本時部署的,並在3.5.6和3.5.7中倖存下來。然而在FF3.6我得到我的錯誤控制檯如下:Firefox 3.6中的Components.interfaces.nsIProcess2 - 它去了哪裏?

Warning: reference to undefined property Components.interfaces.nsIProcess2 
Source file: chrome://overthewall/content/otwhelper.js 
Line: 55 

Error: Component returned failure code: 0x80570018 (NS_ERROR_XPC_BAD_IID) 
     [nsIJSCID.createInstance] 
Source file: chrome://overthewall/content/otwhelper.js 
Line: 55 

引發錯誤的功能是:

48 function otwRunHelper(cmd, aCallback) { 
49 var file = 
50  Components.classes["@mozilla.org/file/local;1"]. 
51  createInstance(Components.interfaces.nsILocalFile); 
52 file.initWithPath(otwRegInstallDir+'otwhelper.exe'); 
53 
54 otwProcess = Components.classes["@mozilla.org/process/util;1"] 
55     .createInstance(Components.interfaces.nsIProcess2); 
56 
57 otwProcess.init(file); 
58 var params = new Array(); 
59 params = cmd.split(' '); 
60 
61 otwNextCallback = aCallback; 
62 otwObserver = new otwHelperProcess(); 
63 otwProcess.runAsync(params, params.length, otwObserver, false); 
64 } 

正如你所看到的,這一切的功能並運行一個外部EXE幫助程序文件(通過註冊表項定位)以及一些命令行參數,並設置Observer以異步等待響應並處理退出代碼。

違規行意味着Components.interfaces.nsIProcess2不再在FF3.6中定義。它去了哪裏?我在Mozilla文檔中找不到任何內容,指出它在最新版本中已被更改。

回答

5

將nsIProcess2上的方法移至nsIProcess。爲了您的代碼在這兩種版本,改變這一行:

otwProcess = Components.classes["@mozilla.org/process/util;1"] 
       .createInstance(Components.interfaces.nsIProcess2); 

這樣:

otwProcess = Components.classes["@mozilla.org/process/util;1"] 
       .createInstance(Components.interfaces.nsIProcess2 || Components.interfaces.nsIProcess); 

你仍然會得到警告,但錯誤會消失,你的代碼將只是工作在兩個版本都很好。您還可以將接口iid存儲在變量中並使用變量:

+0

太棒了。謝謝!!!我錯過了Mozilla文檔中的一行指出這一點。 – rwired 2010-02-09 07:11:18

+2

公平地說,你沒有錯過它。我剛剛告訴那個因爲你的問題而做出改變以更新文檔的人。 :) – sdwilsh 2010-02-09 15:39:27