User:Jminta/Mail XPCOMUtils

From MozillaWiki
Jump to: navigation, search

Writing XPCOMUtils patches for Thunderbird is a great way to get beginning exposure to a specific area of the codebase. This page provides a brief tutorial on how to go about writing one of these patches.

What is XPCOMUtils?

XPCOMUtils is a javascript module that can be included in any javascript file via Components.utils.import. The module is only compiled once, meaning that putting repetitive code in a module can result in startup improvements.

Specifically, XPCOMUtils provides functions that simplify the registration process for XPCOM components.

How do I write the patch?

  1. Find a javascript component file (see list below).
  2. Import the XPCOMUtils module
  3. Replace any QueryInterface functions with XPCOMUtils.generateQI
  4. Remove any nsIFactory and nsIModule implementations
  5. Add in the appropriate fields to the component's prototype. (see this example)
  6. Replace the NSGetModule implementation

Then test your patch (rebuild Thunderbird and watch your console during startup to see that your component is registered), file a bug, attach it, and request a review.

Here is an example patch.

Which files need to be fixed?

Any javascript component file. Tentative list: