B2G/gecko/toolkit/mozapps/extensions/XPIProviderUtils.js
/**
   * Synchronously adds an AddonInternal's metadata to the database.
   *
   * @param  aAddon
   *         AddonInternal to add
   * @param  aDescriptor
   *         The file descriptor of the add-on
   */
Synchronously adds an AddonInternal's metadata to the database.
@param  aAddon
AddonInternal to add
@param  aDescriptor
The file descriptor of the add-on
Synchronously adds an AddonInternal ' s metadata to the database . @param aAddon AddonInternal to add @param aDescriptor The file descriptor of the add - on
function XPIDB_addAddonMetadata(aAddon, aDescriptor) {
    if (!this.connection)
      this.openConnection(false, true);
    this.beginTransaction();
    var self = this;
    function insertLocale(aLocale) {
      let localestmt = self.getStatement("addAddonMetadata_locale");
      let stringstmt = self.getStatement("addAddonMetadata_strings");
      copyProperties(aLocale, PROP_LOCALE_SINGLE, localestmt.params);
      executeStatement(localestmt);
      let row = XPIDatabase.connection.lastInsertRowID;
      PROP_LOCALE_MULTI.forEach(function(aProp) {
        aLocale[aProp].forEach(function(aStr) {
          stringstmt.params.locale = row;
          stringstmt.params.type = aProp;
          stringstmt.params.value = aStr;
          executeStatement(stringstmt);
        });
      });
      return row;
    }
    try {
      if (aAddon.visible) {
        let stmt = this.getStatement("clearVisibleAddons");
        stmt.params.id = aAddon.id;
        executeStatement(stmt);
      }
      let stmt = this.getStatement("addAddonMetadata_addon");
      stmt.params.locale = insertLocale(aAddon.defaultLocale);
      stmt.params.location = aAddon._installLocation.name;
      stmt.params.descriptor = aDescriptor;
      copyProperties(aAddon, PROP_METADATA, stmt.params);
      copyProperties(aAddon, DB_METADATA, stmt.params);
      DB_BOOL_METADATA.forEach(function(aProp) {
        stmt.params[aProp] = aAddon[aProp] ? 1 : 0;
      });
      executeStatement(stmt);
      let internal_id = this.connection.lastInsertRowID;
      stmt = this.getStatement("addAddonMetadata_addon_locale");
      aAddon.locales.forEach(function(aLocale) {
        let id = insertLocale(aLocale);
        aLocale.locales.forEach(function(aName) {
          stmt.params.internal_id = internal_id;
          stmt.params.name = aName;
          stmt.params.locale = id;
          executeStatement(stmt);
        });
      });
      stmt = this.getStatement("addAddonMetadata_targetApplication");
      aAddon.targetApplications.forEach(function(aApp) {
        stmt.params.internal_id = internal_id;
        stmt.params.id = aApp.id;
        stmt.params.minVersion = aApp.minVersion;
        stmt.params.maxVersion = aApp.maxVersion;
        executeStatement(stmt);
      });
      stmt = this.getStatement("addAddonMetadata_targetPlatform");
      aAddon.targetPlatforms.forEach(function(aPlatform) {
        stmt.params.internal_id = internal_id;
        stmt.params.os = aPlatform.os;
        stmt.params.abi = aPlatform.abi;
        executeStatement(stmt);
      });
      this.commitTransaction();
    }
    catch (e) {
      this.rollbackTransaction();
      throw e;
    }
  }
function XPIDB_addAddonMetadata ( aAddon , aDescriptor ) { if ( ! this . connection ) this . openConnection ( false , true ) ; this . beginTransaction ( ) ; var self = this ; function insertLocale ( aLocale ) { let localestmt = self . getStatement ( "addAddonMetadata_locale" ) ; let stringstmt = self . getStatement ( "addAddonMetadata_strings" ) ; copyProperties ( aLocale , PROP_LOCALE_SINGLE , localestmt . params ) ; executeStatement ( localestmt ) ; let row = XPIDatabase . connection . lastInsertRowID ; PROP_LOCALE_MULTI . forEach ( function ( aProp ) { aLocale [ aProp ] . forEach ( function ( aStr ) { stringstmt . params . locale = row ; stringstmt . params . type = aProp ; stringstmt . params . value = aStr ; executeStatement ( stringstmt ) ; } ) ; } ) ; return row ; } try { if ( aAddon . visible ) { let stmt = this . getStatement ( "clearVisibleAddons" ) ; stmt . params . id = aAddon . id ; executeStatement ( stmt ) ; } let stmt = this . getStatement ( "addAddonMetadata_addon" ) ; stmt . params . locale = insertLocale ( aAddon . defaultLocale ) ; stmt . params . location = aAddon . _installLocation . name ; stmt . params . descriptor = aDescriptor ; copyProperties ( aAddon , PROP_METADATA , stmt . params ) ; copyProperties ( aAddon , DB_METADATA , stmt . params ) ; DB_BOOL_METADATA . forEach ( function ( aProp ) { stmt . params [ aProp ] = aAddon [ aProp ] ? 1 : 0 ; } ) ; executeStatement ( stmt ) ; let internal_id = this . connection . lastInsertRowID ; stmt = this . getStatement ( "addAddonMetadata_addon_locale" ) ; aAddon . locales . forEach ( function ( aLocale ) { let id = insertLocale ( aLocale ) ; aLocale . locales . forEach ( function ( aName ) { stmt . params . internal_id = internal_id ; stmt . params . name = aName ; stmt . params . locale = id ; executeStatement ( stmt ) ; } ) ; } ) ; stmt = this . getStatement ( "addAddonMetadata_targetApplication" ) ; aAddon . targetApplications . forEach ( function ( aApp ) { stmt . params . internal_id = internal_id ; stmt . params . id = aApp . id ; stmt . params . minVersion = aApp . minVersion ; stmt . params . maxVersion = aApp . maxVersion ; executeStatement ( stmt ) ; } ) ; stmt = this . getStatement ( "addAddonMetadata_targetPlatform" ) ; aAddon . targetPlatforms . forEach ( function ( aPlatform ) { stmt . params . internal_id = internal_id ; stmt . params . os = aPlatform . os ; stmt . params . abi = aPlatform . abi ; executeStatement ( stmt ) ; } ) ; this . commitTransaction ( ) ; } catch ( e ) { this . rollbackTransaction ( ) ; throw e ; } }
Synchronously adds an AddonInternal's metadata to the database.
Synchronously adds an AddonInternal ' s metadata to the database .
// If there is no DB yet then forcibly create one // Any errors in here should rollback the transaction