B2G/gecko/toolkit/mozapps/extensions/XPIProvider.jsm
/**
   * Installs any add-ons located in the extensions directory of the
   * application's distribution specific directory into the profile unless a
   * newer version already exists or the user has previously uninstalled the
   * distributed add-on.
   *
   * @param  aManifests
   *         A dictionary to add new install manifests to to save having to
   *         reload them later
   * @return true if any new add-ons were installed
   */
Installs any add-ons located in the extensions directory of the
application's distribution specific directory into the profile unless a
newer version already exists or the user has previously uninstalled the
distributed add-on.

@param  aManifests
A dictionary to add new install manifests to to save having to
reload them later
@return true if any new add-ons were installed
Installs any add - ons located in the extensions directory of the application ' s distribution specific directory into the profile unless a newer version already exists or the user has previously uninstalled the distributed add - on . @param aManifests A dictionary to add new install manifests to to save having to reload them later @return true if any new add - ons were installed
function XPI_installDistributionAddons(aManifests) {
    let distroDir;
    try {
      distroDir = FileUtils.getDir(KEY_APP_DISTRIBUTION, [DIR_EXTENSIONS]);
    }
    catch (e) {
      return false;
    }
    if (!distroDir.exists())
      return false;
    if (!distroDir.isDirectory())
      return false;
    let changed = false;
    let profileLocation = this.installLocationsByName[KEY_APP_PROFILE];
    let entries = distroDir.directoryEntries
                           .QueryInterface(Ci.nsIDirectoryEnumerator);
    let entry;
    while (entry = entries.nextFile) {
      let id = entry.leafName;
      if (entry.isFile()) {
        if (id.substring(id.length - 4).toLowerCase() == ".xpi") {
          id = id.substring(0, id.length - 4);
        }
        else {
          LOG("Ignoring distribution add-on that isn't an XPI: " + entry.path);
          continue;
        }
      }
      else if (!entry.isDirectory()) {
        LOG("Ignoring distribution add-on that isn't a file or directory: " +
            entry.path);
        continue;
      }
      if (!gIDTest.test(id)) {
        LOG("Ignoring distribution add-on whose name is not a valid add-on ID: " +
            entry.path);
        continue;
      }
      let addon;
      try {
        addon = loadManifestFromFile(entry);
      }
      catch (e) {
        WARN("File entry " + entry.path + " contains an invalid add-on", e);
        continue;
      }
      if (addon.id != id) {
        WARN("File entry " + entry.path + " contains an add-on with an " +
             "incorrect ID")
        continue;
      }
      let existingEntry = null;
      try {
        existingEntry = profileLocation.getLocationForID(id);
      }
      catch (e) {
      }
      if (existingEntry) {
        let existingAddon;
        try {
          existingAddon = loadManifestFromFile(existingEntry);
          if (Services.vc.compare(addon.version, existingAddon.version) <= 0)
            continue;
        }
        catch (e) {
          WARN("Profile contains an add-on with a bad or missing install " +
               "manifest at " + existingEntry.path + ", overwriting", e);
        }
      }
      else if (Prefs.getBoolPref(PREF_BRANCH_INSTALLED_ADDON + id, false)) {
        continue;
      }
      try {
        profileLocation.installAddon(id, entry, null, true);
        LOG("Installed distribution add-on " + id);
        Services.prefs.setBoolPref(PREF_BRANCH_INSTALLED_ADDON + id, true)
        if (!(KEY_APP_PROFILE in aManifests))
          aManifests[KEY_APP_PROFILE] = {};
        aManifests[KEY_APP_PROFILE][id] = addon;
        changed = true;
      }
      catch (e) {
        ERROR("Failed to install distribution add-on " + entry.path, e);
      }
    }
    entries.close();
    return changed;
  }
function XPI_installDistributionAddons ( aManifests ) { let distroDir ; try { distroDir = FileUtils . getDir ( KEY_APP_DISTRIBUTION , [ DIR_EXTENSIONS ] ) ; } catch ( e ) { return false ; } if ( ! distroDir . exists ( ) ) return false ; if ( ! distroDir . isDirectory ( ) ) return false ; let changed = false ; let profileLocation = this . installLocationsByName [ KEY_APP_PROFILE ] ; let entries = distroDir . directoryEntries . QueryInterface ( Ci . nsIDirectoryEnumerator ) ; let entry ; while ( entry = entries . nextFile ) { let id = entry . leafName ; if ( entry . isFile ( ) ) { if ( id . substring ( id . length - 4 ) . toLowerCase ( ) == ".xpi" ) { id = id . substring ( 0 , id . length - 4 ) ; } else { LOG ( "Ignoring distribution add-on that isn't an XPI: " + entry . path ) ; continue ; } } else if ( ! entry . isDirectory ( ) ) { LOG ( "Ignoring distribution add-on that isn't a file or directory: " + entry . path ) ; continue ; } if ( ! gIDTest . test ( id ) ) { LOG ( "Ignoring distribution add-on whose name is not a valid add-on ID: " + entry . path ) ; continue ; } let addon ; try { addon = loadManifestFromFile ( entry ) ; } catch ( e ) { WARN ( "File entry " + entry . path + " contains an invalid add-on" , e ) ; continue ; } if ( addon . id != id ) { WARN ( "File entry " + entry . path + " contains an add-on with an " + "incorrect ID" ) continue ; } let existingEntry = null ; try { existingEntry = profileLocation . getLocationForID ( id ) ; } catch ( e ) { } if ( existingEntry ) { let existingAddon ; try { existingAddon = loadManifestFromFile ( existingEntry ) ; if ( Services . vc . compare ( addon . version , existingAddon . version ) <= 0 ) continue ; } catch ( e ) { WARN ( "Profile contains an add-on with a bad or missing install " + "manifest at " + existingEntry . path + ", overwriting" , e ) ; } } else if ( Prefs . getBoolPref ( PREF_BRANCH_INSTALLED_ADDON + id , false ) ) { continue ; } try { profileLocation . installAddon ( id , entry , null , true ) ; LOG ( "Installed distribution add-on " + id ) ; Services . prefs . setBoolPref ( PREF_BRANCH_INSTALLED_ADDON + id , true ) if ( ! ( KEY_APP_PROFILE in aManifests ) ) aManifests [ KEY_APP_PROFILE ] = { } ; aManifests [ KEY_APP_PROFILE ] [ id ] = addon ; changed = true ; } catch ( e ) { ERROR ( "Failed to install distribution add-on " + entry . path , e ) ; } } entries . close ( ) ; return changed ; }
Installs any add-ons located in the extensions directory of the
 application's distribution specific directory into the profile unless a
 newer version already exists or the user has previously uninstalled the
 distributed add-on.
Installs any add - ons located in the extensions directory of the application ' s distribution specific directory into the profile unless a newer version already exists or the user has previously uninstalled the distributed add - on .
// Bad add-on in the profile so just proceed and install over the top // Install the add-on // aManifests may contain a copy of a newly installed add-on's manifest // and we'll have overwritten that so instead cache our install manifest // which will later be put into the database in processFileChanges