B2G/gecko/toolkit/mozapps/extensions/XPIProvider.jsm
/**
   * Called after the add-on is a local file and the signature and install
   * manifest can be read.
   *
   * @param  aCallback
   *         A function to call when the manifest has been loaded
   * @throws if the add-on does not contain a valid install manifest or the
   *         XPI is incorrectly signed
   */
Called after the add-on is a local file and the signature and install
manifest can be read.

@param  aCallback
A function to call when the manifest has been loaded
@throws if the add-on does not contain a valid install manifest or the
XPI is incorrectly signed
Called after the add - on is a local file and the signature and install manifest can be read . @param aCallback A function to call when the manifest has been loaded @throws if the add - on does not contain a valid install manifest or the XPI is incorrectly signed
function AI_loadManifest(aCallback) {
    function addRepositoryData(aAddon) {
      AddonRepository.getCachedAddonByID(aAddon.id, function loadManifest_getCachedAddonByID(aRepoAddon) {
        if (aRepoAddon) {
          aAddon._repositoryAddon = aRepoAddon;
          aAddon.compatibilityOverrides = aRepoAddon.compatibilityOverrides;
          aAddon.appDisabled = !isUsableAddon(aAddon);
          aCallback();
          return;
        }
        AddonRepository.cacheAddons([aAddon.id], function loadManifest_cacheAddons() {
          AddonRepository.getCachedAddonByID(aAddon.id, function loadManifest_getCachedAddonByID(aRepoAddon) {
            aAddon._repositoryAddon = aRepoAddon;
            aAddon.compatibilityOverrides = aRepoAddon ?
                                              aRepoAddon.compatibilityOverrides :
                                              null;
            aAddon.appDisabled = !isUsableAddon(aAddon);
            aCallback();
          });
        });
      });
    }
    let zipreader = Cc["@mozilla.org/libjar/zip-reader;1"].
                    createInstance(Ci.nsIZipReader);
    try {
      zipreader.open(this.file);
    }
    catch (e) {
      zipreader.close();
      throw e;
    }
    let principal = zipreader.getCertificatePrincipal(null);
    if (principal && principal.hasCertificate) {
      LOG("Verifying XPI signature");
      if (verifyZipSigning(zipreader, principal)) {
        let x509 = principal.certificate;
        if (x509 instanceof Ci.nsIX509Cert)
          this.certificate = x509;
        if (this.certificate && this.certificate.commonName.length > 0)
          this.certName = this.certificate.commonName;
        else
          this.certName = principal.prettyName;
      }
      else {
        zipreader.close();
        throw new Error("XPI is incorrectly signed");
      }
    }
    try {
      this.addon = loadManifestFromZipReader(zipreader);
    }
    catch (e) {
      zipreader.close();
      throw e;
    }
    if (this.addon.type == "multipackage") {
      let self = this;
      this.loadMultipackageManifests(zipreader, function loadManifest_loadMultipackageManifests() {
        addRepositoryData(self.addon);
      });
      return;
    }
    zipreader.close();
    this.updateAddonURIs();
    this.addon._install = this;
    this.name = this.addon.selectedLocale.name;
    this.type = this.addon.type;
    this.version = this.addon.version;
    addRepositoryData(this.addon);
  }
function AI_loadManifest ( aCallback ) { function addRepositoryData ( aAddon ) { AddonRepository . getCachedAddonByID ( aAddon . id , function loadManifest_getCachedAddonByID ( aRepoAddon ) { if ( aRepoAddon ) { aAddon . _repositoryAddon = aRepoAddon ; aAddon . compatibilityOverrides = aRepoAddon . compatibilityOverrides ; aAddon . appDisabled = ! isUsableAddon ( aAddon ) ; aCallback ( ) ; return ; } AddonRepository . cacheAddons ( [ aAddon . id ] , function loadManifest_cacheAddons ( ) { AddonRepository . getCachedAddonByID ( aAddon . id , function loadManifest_getCachedAddonByID ( aRepoAddon ) { aAddon . _repositoryAddon = aRepoAddon ; aAddon . compatibilityOverrides = aRepoAddon ? aRepoAddon . compatibilityOverrides : null ; aAddon . appDisabled = ! isUsableAddon ( aAddon ) ; aCallback ( ) ; } ) ; } ) ; } ) ; } let zipreader = Cc [ "@mozilla.org/libjar/zip-reader;1" ] . createInstance ( Ci . nsIZipReader ) ; try { zipreader . open ( this . file ) ; } catch ( e ) { zipreader . close ( ) ; throw e ; } let principal = zipreader . getCertificatePrincipal ( null ) ; if ( principal && principal . hasCertificate ) { LOG ( "Verifying XPI signature" ) ; if ( verifyZipSigning ( zipreader , principal ) ) { let x509 = principal . certificate ; if ( x509 instanceof Ci . nsIX509Cert ) this . certificate = x509 ; if ( this . certificate && this . certificate . commonName . length > 0 ) this . certName = this . certificate . commonName ; else this . certName = principal . prettyName ; } else { zipreader . close ( ) ; throw new Error ( "XPI is incorrectly signed" ) ; } } try { this . addon = loadManifestFromZipReader ( zipreader ) ; } catch ( e ) { zipreader . close ( ) ; throw e ; } if ( this . addon . type == "multipackage" ) { let self = this ; this . loadMultipackageManifests ( zipreader , function loadManifest_loadMultipackageManifests ( ) { addRepositoryData ( self . addon ) ; } ) ; return ; } zipreader . close ( ) ; this . updateAddonURIs ( ) ; this . addon . _install = this ; this . name = this . addon . selectedLocale . name ; this . type = this . addon . type ; this . version = this . addon . version ; addRepositoryData ( this . addon ) ; }
Called after the add-on is a local file and the signature and install
 manifest can be read.
Called after the add - on is a local file and the signature and install manifest can be read .
// Try to load from the existing cache first // It wasn't there so try to re-download it // Setting the iconURL to something inside the XPI locks the XPI and // makes it impossible to delete on Windows. //let newIcon = createWrapper(this.addon).iconURL; //if (newIcon) //  this.iconURL = newIcon;