components.interfaces.nsiprocess2在Firefox 3.6中 - 它去了哪里?
-
19-09-2019 - |
题
我正在测试一个包括Firefox扩展名作为一个组件的应用程序。它最初是在FF3.5.5是最新版本的3.5.6和3.5.7时部署的。但是,在ff3.6上,我在错误控制台中获得以下内容:
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助手文件(由注册表密钥定位),并设置一个观察者,以异步等待响应并处理出口代码。
有问题的线意味着 components.interfaces.nsiprocess2 不再在FF3.6中定义。它去了哪里?我在Mozilla文档中找不到任何东西,表明它已在最新版本中进行了更改。
解决方案
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存储在变量中并使用变量:
let iid = ("nsIProcess2" in Components.interfaces) ?
Components.interfaces.nsIProcess2 :
Components.interfaces.nsIProcess;
otwProcess = Components.classes["@mozilla.org/process/util;1"]
.createInstance(iid);
不隶属于 StackOverflow