2

我写了一个二进制 XPCOM 组件。它使用 XULRunner SDK 12.0 (Gecko 12.0) 成功编译,但在 Firefox 中注册失败!消息是:

WARN addons.updates: testxp@meilijie.com 的更新清单不包含更新属性

我的install.rdf样子是这样的:

<?xml version="1.0"?>

<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:em="http://www.mozilla.org/2004/em-rdf#">

  <Description about="urn:mozilla:install-manifest">
   <em:id>testxp@meilijie.com</em:id>
   <em:unpack>true</em:unpack>
   <em:name>CTestXP</em:name>
   <em:description>Welcome to meilijie!</em:description>
   <em:version>0.1</em:version>
   <em:creator>wanyunxiao</em:creator>
   <em:homepageURL>https://meilijie.com/testxp</em:homepageURL>
   <em:type>2</em:type>
   <!-- Mozilla Firefox -->
   <em:targetApplication>
     <Description>
       <em:id>{9f748727-57a0-4f2d-8d24-b71212c18d32}</em:id> 
       <em:minVersion>4.0</em:minVersion>
       <em:maxVersion>12.*</em:maxVersion>
     </Description>
   </em:targetApplication>
 </Description>

我的chrome.manifest

binary-component components/TestXP.so

interfaces components/CTestXP.xpt

contract  @meilijie.com/newedu/CTestXP;1 {9f748727-57a0-4f2d-8d24-b71212c18d32}

我用 firefox 工具检查组件:错误控制台。
当我输入这些代码时:

Components.classes["@meilijie.com/newedu/CTestXP;1"].createInstance();

错误信息是:

错误:Components.com/newedu/CTestXP;1'] is undefined javascript:%20Components.classes["@meilijie.classes["@meilijie.classes['@meilijie.com/newedu/CTestXP;1'] com/newedu/CTestXP;1"].createInstance(); 行:1

我用html和js代码检查它,html代码是:

<html>
  <SCRIPT SRC="MyComponentTest.js"></SCRIPT>
  <BODY>
    <BUTTON ONCLICK="MyComponentTestGo();">Go</BUTTON>
  </BODY>
</html>

和下面的 js 文件 MyComponentTest.js:

function MyComponentTestGo() {
try {
    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
    const cid = "@meilijie.com/newedu/CTestXP;1";
    obj = Components.classes[cid].createInstance();
    obj = obj.QueryInterface(Components.interfaces.IMyComponent);
} catch (err) {
    alert(err);
    return;
}
var res = obj.Add(3, 4);
alert('Performing 3+4. Returned ' + res + '.');
4

0 回答 0