【问题标题】:custom protocol handlers in bootstrapped firefox addon自举Firefox插件中的自定义协议处理程序
【发布时间】:2013-11-13 03:19:58
【问题描述】:

我正在编写一个引导 Firefox 插件,需要注册一个新的协议/模式处理程序(例如foo:somthing)。我已经看遍了,我只看到了使用 chrome.manifest 的方法,而引导加载项无法使用。

那么,有没有人知道一种方法或者是否可以在引导加载项中注册自定义协议处理程序?

【问题讨论】:

    标签: firefox-addon protocols firefox-addon-restartless


    【解决方案1】:

    是的,但您必须完成插件/组件管理器将为您完成的工作,尤其是您自己致电 .registerFactory

    已经有a test 演示了如何在运行时自己注册一般的组件,特别是协议处理程序。

    【讨论】:

      【解决方案2】:

      虽然@nmair 的回答是一个很好的一般性问题,但我会牢记在心,但我能够找到更好的解决方案来解决我自己的问题。我注意到有一个 HTML5 方法会尝试要求用户为协议/模式注册一个处理程序,在omni.ja(firefox 源代码)中挑选之后,我找到了它的定义。在摆弄之后,我写了这个:

      var handler = Cc["@mozilla.org/uriloader/web-handler-app;1"]
          .createInstance(Ci.nsIWebHandlerApp);
      handler.name='My Protocol';
      handler.uriTemplate='chrome://myprotocol/content/launcher.xul#%s';
      
      var eps=Cc["@mozilla.org/uriloader/external-protocol-service;1"].
          getService(Ci.nsIExternalProtocolService);
      var handlerInfo=eps.getProtocolHandlerInfo('myprotocol');
      handlerInfo.possibleApplicationHandlers.appendElement(handler, false);
      handlerInfo.alwaysAskBeforeHandling=false;        // don't ask the user
      handlerInfo.preferredApplicationHandler=handler;  // set my handler as default
      hi=handlerInfo;
      
      var hs=Cc["@mozilla.org/uriloader/handler-service;1"].
      getService(Ci.nsIHandlerService);
      hs.store(handlerInfo);
      

      注册协议,无需重启或组件。

      【讨论】:

        猜你喜欢
        • 2011-10-28
        • 2013-04-28
        • 1970-01-01
        • 1970-01-01
        • 2011-01-30
        • 1970-01-01
        • 1970-01-01
        • 2011-09-10
        相关资源
        最近更新 更多