【问题标题】:Components.interfaces.nsIProcess2 in Firefox 3.6 -- where did it go?Firefox 3.6 中的 Components.interfaces.nsIProcess2 —— 它去哪儿了?
【发布时间】:2010-02-09 05:11:06
【问题描述】:

我正在测试一个包含 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 帮助文件(由注册表项定位),并设置一个 Observer 以异步等待响应并处理退出代码。

违规行暗示 Components.interfaces.nsIProcess2 在 FF3.6 中不再定义。它去哪儿了?我在 Mozilla 文档中找不到任何表明它在最新版本中已更改的内容。

【问题讨论】:

    标签: xpcom firefox3.6


    【解决方案1】:

    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);
    

    【讨论】:

    • 太棒了。谢谢!!!我错过了 Mozilla 文档中指出这一点的一行。
    • 公平地说,你没有错过它。由于您的问题,我刚刚告诉昨天进行更改以更新文档的人。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-03
    • 2014-03-15
    • 2015-07-17
    • 2012-10-30
    • 2013-05-23
    相关资源
    最近更新 更多