zoukankan      html  css  js  c++  java
  • (FFOS Gecko)

    1. JavaScript Component

      (1) add a CustomComponent.manifest

    # The {classID} here must match the classID in CustomComponent.js
    component {e6b866e3-41b2-4f05-a4d2-3d4bde0f7ef8} components/CustomComponent.js
    contract @foobar/customcomponent;1 {e6b866e3-41b2-4f05-a4d2-3d4bde0f7ef8}
    category profile-after-change CustomComponent @foobar/customcomponent;1

      (2)  export a NSGetFactory() function

    Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
    
    function CustomComponent() {
    }
    CustomComponent.prototype = {
      // this must match whatever is in chrome.manifest!
      classID: Components.ID("{e6b866e3-41b2-4f05-a4d2-3d4bde0f7ef8}"),
      QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsICustomComponent]),
      /* nsICustomComponent implementation goes here */
      ...
    };
    
    // The following line is what XPCOM uses to create components. Each component prototype
    // must have a .classID which is used to create it.
    if (XPCOMUtils.generateNSGetFactory) {
        const NSGetFactory = XPCOMUtils.generateNSGetFactory([CustomComponent]);
        this.NSGetFactory = XPCOMUtils.generateNSGetFactory([CustomComponent]);
    } else {
        // for Mozilla 1.9.2 (Firefox 3.6)
        var NSGetModule = XPCOMUtils.generateNSGetModule([CustomComponent]);
    }

      (3) add to moz.build

    # EXTRA_COMPONENTS installs components written JavaScript to
    # dist/bin/components
    EXTRA_COMPONENTS += [
        'CustomComponent.js',
        'CustomComponent.manifest',
    ]

     reference: https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/XPCOMUtils.jsm

    2. C++ Component

    copy from gecko/xpcom/sample/nsSampleModule.cpp

    ////////////////////////////////////////////////////////////////////////
    // Define the contructor function for the object nsSampleImpl
    //
    // What this does is defines a function nsSampleImplConstructor which we
    // will specific in the nsModuleComponentInfo table. This function will
    // be used by the generic factory to create an instance of nsSampleImpl.
    //
    // NOTE: This creates an instance of nsSampleImpl by using the default
    //         constructor nsSampleImpl::nsSampleImpl()
    //
    NS_GENERIC_FACTORY_CONSTRUCTOR(nsSampleImpl)
    
    // The following line defines a kNS_SAMPLE_CID CID variable.
    NS_DEFINE_NAMED_CID(NS_SAMPLE_CID);
    
    // Build a table of ClassIDs (CIDs) which are implemented by this module. CIDs
    // should be completely unique UUIDs.
    // each entry has the form { CID, service, factoryproc, constructorproc }
    // where factoryproc is usually nullptr.
    static const mozilla::Module::CIDEntry kSampleCIDs[] = {
      { &kNS_SAMPLE_CID, false, nullptr, nsSampleImplConstructor },
      { nullptr }
    };
    
    // Build a table which maps contract IDs to CIDs.
    // A contract is a string which identifies a particular set of functionality. In some
    // cases an extension component may override the contract ID of a builtin gecko component
    // to modify or extend functionality.
    static const mozilla::Module::ContractIDEntry kSampleContracts[] = {
      { NS_SAMPLE_CONTRACTID, &kNS_SAMPLE_CID },
      { nullptr }
    };
    
    // Category entries are category/key/value triples which can be used
    // to register contract ID as content handlers or to observe certain
    // notifications. Most modules do not need to register any category
    // entries: this is just a sample of how you'd do it.
    // @see nsICategoryManager for information on retrieving category data.
    static const mozilla::Module::CategoryEntry kSampleCategories[] = {
      { "my-category", "my-key", NS_SAMPLE_CONTRACTID },
      { nullptr }
    };
    
    static const mozilla::Module kSampleModule = {
      mozilla::Module::kVersion,
      kSampleCIDs,
      kSampleContracts,
      kSampleCategories
    };
    
    // The following line implements the one-and-only "NSModule" symbol exported from this
    // shared library.
    NSMODULE_DEFN(nsSampleModule) = &kSampleModule;
    
    // The following line implements the one-and-only "NSGetModule" symbol
    // for compatibility with mozilla 1.9.2. You should only use this
    // if you need a binary which is backwards-compatible and if you use
    // interfaces carefully across multiple versions.
    NS_IMPL_MOZILLA192_NSGETMODULE(&kSampleModule)
  • 相关阅读:
    [Python][小知识][NO.3] Python 使用系统默认浏览器打开指定URL的网址
    [Python][小知识][NO.2] Python 字符串跨行连接,或拆分为多行显示
    [Python] wxPython 状态栏组件、消息对话框组件 学习总结(原创)
    [Python][小知识][NO.1] Python字符串前 加 u、r、b 的含义
    [Python] wxPython 编辑框组件学习总结 (原创)
    [Python] wxPython 菜单栏控件学习总结(原创)
    [Python] wxPython 基本控件 (转)
    HDU 2086 A1 = ? (找规律推导公式 + 水题)(Java版)
    HDU 1840 Equations (简单数学 + 水题)(Java版)
    UVA 1152 4 Values whose Sum is 0 (枚举+中途相遇法)(+Java版)(Java手撕快排+二分)
  • 原文地址:https://www.cnblogs.com/code-4-fun/p/4663779.html
Copyright © 2011-2022 走看看