2016-04-30 19 views
0

我想prroviding命令行選項, 我在瀏覽器控制檯收到此錯誤:自舉清單不得用<a href="https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XUL/Providing_Command-Line_Options" rel="nofollow">this</a>例如使用「組件」指令

  • 自舉清單不允許使用「組件」指令。
  • 自引證明不允許使用'合同'指令。
  • 引導式清單不允許使用'category'指令。

PARAMS:-no-remote -p Developer -jsconsole -ssprint:1137403

這裏是我的文件內容:

[install.rdf中]

<?xml version="1.0" encoding="utf-8"?> 
<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>@spidersprint</em:id> 
      <em:type>2</em:type> 
      <em:bootstrap>true</em:bootstrap> 
      <em:unpack>false</em:unpack> 
      <em:version>1.0.0</em:version> 
      <em:name>SpiderSprint</em:name> 
      <em:description>SpiderSprint extension (for self-using).</em:description> 
      <em:creator>Alexander Macedonian</em:creator> 
      <em:iconURL>resource://spidersprint/data/icon/s32.png</em:iconURL> 
      <em:icon64URL>resource://spidersprint/data/icon/s64.png</em:icon64URL> 

      <em:targetApplication> 
      <Description> 
       <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id> 
       <em:minVersion>38.0a1</em:minVersion> 
       <em:maxVersion>*</em:maxVersion> 
      </Description> 
      </em:targetApplication> 
    </Description> 
</RDF> 

[chrome.manifest用於]:

component {75ceb908-0807-4395-affb-e0792ac4c548} components/commandlinehandler.js 
contract @spidersprint/commandlinehandler;1 {75ceb908-0807-4395-affb-e0792ac4c548} 
category command-line-handler CommandLineHandler @spidersprint/commandlinehandler;1 

[ commandlinehandler.js]

let {CC,Cc,Ci,Cu,Cr,components} = require('chrome'); 

Cu.import("resource://gre/modules/XPCOMUtils.jsm"); 
Cu.import("resource://gre/modules/Services.jsm"); 
const CHROME_URI = "resource://spidersprint/data/"; 

function openWindow(aChromeURISpec, aArgument) { 
    Services.ww.openWindow(null, aChromeURISpec, "_blank", 
     "chrome,menubar,toolbar,status,resizable,dialog=no", aArgument); 
} 

function CommandLineHandler() {}; 

CommandLineHandler.prototype = { 
    classDescription: "myAppHandler", 
    classID: components.ID("{75ceb908-0807-4395-affb-e0792ac4c548}"), 
    contractID: "@spidersprint/commandlinehandler;1", 
    _xpcom_categories: [{ 
     category: "command-line-handler", 
     entry: "s-ssprint" 
    }], 

    QueryInterface: XPCOMUtils.generateQI([ 
     Ci.nsICommandLineHandler 
    ]), 

    handle : function clh_handle(cmdLine) 
    { 
     try { 
      var uristr = cmdLine.handleFlagWithParam("viewapp", false); 
      if (uristr) { 
       var uri = cmdLine.resolveURI(uristr); 
       openWindow(CHROME_URI, uri); 
       cmdLine.preventDefault = true; 
      } 
     } 
     catch (e) { 
      Cu.reportError("incorrect parameter passed to -viewapp on the command line."); 
     } 

     if (cmdLine.handleFlag("ssprint", false)) { 
      openWindow(CHROME_URI, null); 
      cmdLine.preventDefault = true; 
     } 
    }, 

    helpInfo : " -ssprint    Open My Application\n" + 
     " -viewapp <uri>  View and edit the URI in My Application,\n" + 
     "      wrapping this description\n" 
}; 

var NSGetFactory = XPCOMUtils.generateNSGetFactory([CommandLineHandler]); 

回答

0

該示例使用僅適用於(不推薦)xul覆蓋擴展類型的chrome清單。在自舉擴展中,您需要提供bootstrap.js,然後使用Cu.import加載其他模塊。

有關代碼遷移指南,請參閱How to convert an overlay extension to restartless

此外,您可能需要跳過另一個步驟來使用SDK extension APIs,這本質上是一種特殊形式的自舉擴展,它提供了更穩定的API。

+0

哦,我明白了。那我怎麼編輯我的引導文件?因爲「jpm xpi」會自動創建引導文件並將其壓縮到xpi文件 – Macedonian

+0

XUL覆蓋文件尚未*棄用。已經宣佈的是,將來有一個計劃將予以否決(從現在開始約爲1年的時間段,IIRC)。 – Makyen

+0

@Macedonian,只需要自己創建一個bootstrap.js,如果它已經存在,那麼jpm會使用它(重啓動addon)或者創建一個(如果不存在的話)(sdk addons)。 – the8472

相關問題