B2G/gecko/toolkit/mozapps/extensions/XPIProviderUtils.js
/**
   * Asynchronously fetches additional metadata for a DBAddonInternal.
   *
   * @param  aAddon
   *         The DBAddonInternal
   * @param  aCallback
   *         The callback to call when the metadata is completely retrieved
   */
Asynchronously fetches additional metadata for a DBAddonInternal.
@param  aAddon
The DBAddonInternal
@param  aCallback
The callback to call when the metadata is completely retrieved
Asynchronously fetches additional metadata for a DBAddonInternal . @param aAddon The DBAddonInternal @param aCallback The callback to call when the metadata is completely retrieved
function XPIDB_fetchAddonMetadata(aAddon) {
    function readLocaleStrings(aLocale, aCallback) {
      let stmt = XPIDatabase.getStatement("_readLocaleStrings");
      stmt.params.id = aLocale.id;
      stmt.executeAsync({
        handleResult: function(aResults) {
          let row = null;
          while ((row = aResults.getNextRow())) {
            let type = row.getResultByName("type");
            if (!(type in aLocale))
              aLocale[type] = [];
            aLocale[type].push(row.getResultByName("value"));
          }
        },
        handleError: asyncErrorLogger,
        handleCompletion: function(aReason) {
          aCallback();
        }
      });
    }
    function readDefaultLocale() {
      delete aAddon.defaultLocale;
      let stmt = XPIDatabase.getStatement("_getDefaultLocale");
      stmt.params.id = aAddon._defaultLocale;
      stmt.executeAsync({
        handleResult: function(aResults) {
          aAddon.defaultLocale = copyRowProperties(aResults.getNextRow(),
                                                   PROP_LOCALE_SINGLE);
          aAddon.defaultLocale.id = aAddon._defaultLocale;
        },
        handleError: asyncErrorLogger,
        handleCompletion: function(aReason) {
          if (aAddon.defaultLocale) {
            readLocaleStrings(aAddon.defaultLocale, readLocales);
          }
          else {
            ERROR("Missing default locale for " + aAddon.id);
            readLocales();
          }
        }
      });
    }
    function readLocales() {
      delete aAddon.locales;
      aAddon.locales = [];
      let stmt = XPIDatabase.getStatement("_getLocales");
      stmt.params.internal_id = aAddon._internal_id;
      stmt.executeAsync({
        handleResult: function(aResults) {
          let row = null;
          while ((row = aResults.getNextRow())) {
            let locale = {
              id: row.getResultByName("id"),
              locales: [row.getResultByName("locale")]
            };
            copyRowProperties(row, PROP_LOCALE_SINGLE, locale);
            aAddon.locales.push(locale);
          }
        },
        handleError: asyncErrorLogger,
        handleCompletion: function(aReason) {
          let pos = 0;
          function readNextLocale() {
            if (pos < aAddon.locales.length)
              readLocaleStrings(aAddon.locales[pos++], readNextLocale);
            else
              readTargetApplications();
          }
          readNextLocale();
        }
      });
    }
    function readTargetApplications() {
      delete aAddon.targetApplications;
      aAddon.targetApplications = [];
      let stmt = XPIDatabase.getStatement("_getTargetApplications");
      stmt.params.internal_id = aAddon._internal_id;
      stmt.executeAsync({
        handleResult: function(aResults) {
          let row = null;
          while ((row = aResults.getNextRow()))
            aAddon.targetApplications.push(copyRowProperties(row, PROP_TARGETAPP));
        },
        handleError: asyncErrorLogger,
        handleCompletion: function(aReason) {
          readTargetPlatforms();
        }
      });
    }
    function readTargetPlatforms() {
      delete aAddon.targetPlatforms;
      aAddon.targetPlatforms = [];
      let stmt = XPIDatabase.getStatement("_getTargetPlatforms");
      stmt.params.internal_id = aAddon._internal_id;
      stmt.executeAsync({
        handleResult: function(aResults) {
          let row = null;
          while ((row = aResults.getNextRow()))
            aAddon.targetPlatforms.push(copyRowProperties(row, ["os", "abi"]));
        },
        handleError: asyncErrorLogger,
        handleCompletion: function(aReason) {
          let callbacks = aAddon._pendingCallbacks;
          delete aAddon._pendingCallbacks;
          callbacks.forEach(function(aCallback) {
            aCallback(aAddon);
          });
        }
      });
    }
    readDefaultLocale();
  }
function XPIDB_fetchAddonMetadata ( aAddon ) { function readLocaleStrings ( aLocale , aCallback ) { let stmt = XPIDatabase . getStatement ( "_readLocaleStrings" ) ; stmt . params . id = aLocale . id ; stmt . executeAsync ( { handleResult : function ( aResults ) { let row = null ; while ( ( row = aResults . getNextRow ( ) ) ) { let type = row . getResultByName ( "type" ) ; if ( ! ( type in aLocale ) ) aLocale [ type ] = [ ] ; aLocale [ type ] . push ( row . getResultByName ( "value" ) ) ; } } , handleError : asyncErrorLogger , handleCompletion : function ( aReason ) { aCallback ( ) ; } } ) ; } function readDefaultLocale ( ) { delete aAddon . defaultLocale ; let stmt = XPIDatabase . getStatement ( "_getDefaultLocale" ) ; stmt . params . id = aAddon . _defaultLocale ; stmt . executeAsync ( { handleResult : function ( aResults ) { aAddon . defaultLocale = copyRowProperties ( aResults . getNextRow ( ) , PROP_LOCALE_SINGLE ) ; aAddon . defaultLocale . id = aAddon . _defaultLocale ; } , handleError : asyncErrorLogger , handleCompletion : function ( aReason ) { if ( aAddon . defaultLocale ) { readLocaleStrings ( aAddon . defaultLocale , readLocales ) ; } else { ERROR ( "Missing default locale for " + aAddon . id ) ; readLocales ( ) ; } } } ) ; } function readLocales ( ) { delete aAddon . locales ; aAddon . locales = [ ] ; let stmt = XPIDatabase . getStatement ( "_getLocales" ) ; stmt . params . internal_id = aAddon . _internal_id ; stmt . executeAsync ( { handleResult : function ( aResults ) { let row = null ; while ( ( row = aResults . getNextRow ( ) ) ) { let locale = { id : row . getResultByName ( "id" ) , locales : [ row . getResultByName ( "locale" ) ] } ; copyRowProperties ( row , PROP_LOCALE_SINGLE , locale ) ; aAddon . locales . push ( locale ) ; } } , handleError : asyncErrorLogger , handleCompletion : function ( aReason ) { let pos = 0 ; function readNextLocale ( ) { if ( pos < aAddon . locales . length ) readLocaleStrings ( aAddon . locales [ pos ++ ] , readNextLocale ) ; else readTargetApplications ( ) ; } readNextLocale ( ) ; } } ) ; } function readTargetApplications ( ) { delete aAddon . targetApplications ; aAddon . targetApplications = [ ] ; let stmt = XPIDatabase . getStatement ( "_getTargetApplications" ) ; stmt . params . internal_id = aAddon . _internal_id ; stmt . executeAsync ( { handleResult : function ( aResults ) { let row = null ; while ( ( row = aResults . getNextRow ( ) ) ) aAddon . targetApplications . push ( copyRowProperties ( row , PROP_TARGETAPP ) ) ; } , handleError : asyncErrorLogger , handleCompletion : function ( aReason ) { readTargetPlatforms ( ) ; } } ) ; } function readTargetPlatforms ( ) { delete aAddon . targetPlatforms ; aAddon . targetPlatforms = [ ] ; let stmt = XPIDatabase . getStatement ( "_getTargetPlatforms" ) ; stmt . params . internal_id = aAddon . _internal_id ; stmt . executeAsync ( { handleResult : function ( aResults ) { let row = null ; while ( ( row = aResults . getNextRow ( ) ) ) aAddon . targetPlatforms . push ( copyRowProperties ( row , [ "os" , "abi" ] ) ) ; } , handleError : asyncErrorLogger , handleCompletion : function ( aReason ) { let callbacks = aAddon . _pendingCallbacks ; delete aAddon . _pendingCallbacks ; callbacks . forEach ( function ( aCallback ) { aCallback ( aAddon ) ; } ) ; } } ) ; } readDefaultLocale ( ) ; }
Asynchronously fetches additional metadata for a DBAddonInternal.
Asynchronously fetches additional metadata for a DBAddonInternal .