B2G/gecko/toolkit/mozapps/extensions/AddonManager.jsm
/**
   * Asynchronously gets an AddonInstall for a URL.
   *
   * @param  aUrl
   *         The string represenation of the URL the add-on is located at
   * @param  aCallback
   *         A callback to pass the AddonInstall to
   * @param  aMimetype
   *         The mimetype of the add-on
   * @param  aHash
   *         An optional hash of the add-on
   * @param  aName
   *         An optional placeholder name while the add-on is being downloaded
   * @param  aIcons
   *         Optional placeholder icons while the add-on is being downloaded
   * @param  aVersion
   *         An optional placeholder version while the add-on is being downloaded
   * @param  aLoadGroup
   *         An optional nsILoadGroup to associate any network requests with
   * @throws if the aUrl, aCallback or aMimetype arguments are not specified
   */
Asynchronously gets an AddonInstall for a URL.
Asynchronously gets an AddonInstall for a URL .
function AMI_getInstallForURL(aUrl, aCallback, aMimetype,
                                                  aHash, aName, aIcons,
                                                  aVersion, aLoadGroup) {
    if (!gStarted)
      throw Components.Exception("AddonManager is not initialized",
                                 Cr.NS_ERROR_NOT_INITIALIZED);
    if (!aUrl || typeof aUrl != "string")
      throw Components.Exception("aURL must be a non-empty string",
                                 Cr.NS_ERROR_INVALID_ARG);
    if (typeof aCallback != "function")
      throw Components.Exception("aCallback must be a function",
                                 Cr.NS_ERROR_INVALID_ARG);
    if (!aMimetype || typeof aMimetype != "string")
      throw Components.Exception("aMimetype must be a non-empty string",
                                 Cr.NS_ERROR_INVALID_ARG);
    if (aHash && typeof aHash != "string")
      throw Components.Exception("aHash must be a string or null",
                                 Cr.NS_ERROR_INVALID_ARG);
    if (aName && typeof aName != "string")
      throw Components.Exception("aName must be a string or null",
                                 Cr.NS_ERROR_INVALID_ARG);
    if (aIcons) {
      if (typeof aIcons == "string")
        aIcons = { "32": aIcons };
      else if (typeof aIcons != "object")
        throw Components.Exception("aIcons must be a string, an object or null",
                                   Cr.NS_ERROR_INVALID_ARG);
    } else {
      aIcons = {};
    }
    if (aVersion && typeof aVersion != "string")
      throw Components.Exception("aVersion must be a string or null",
                                 Cr.NS_ERROR_INVALID_ARG);
    if (aLoadGroup && (!(aLoadGroup instanceof Ci.nsILoadGroup)))
      throw Components.Exception("aLoadGroup must be a nsILoadGroup or null",
                                 Cr.NS_ERROR_INVALID_ARG);
    let providers = this.providers.slice(0);
    for (let provider of providers) {
      if (callProvider(provider, "supportsMimetype", false, aMimetype)) {
        callProvider(provider, "getInstallForURL", null,
                     aUrl, aHash, aName, aIcons, aVersion, aLoadGroup,
                     function(aInstall) {
          safeCall(aCallback, aInstall);
        });
        return;
      }
    }
    safeCall(aCallback, null);
  }
function AMI_getInstallForURL ( aUrl , aCallback , aMimetype , aHash , aName , aIcons , aVersion , aLoadGroup ) { if ( ! gStarted ) throw Components . Exception ( "AddonManager is not initialized" , Cr . NS_ERROR_NOT_INITIALIZED ) ; if ( ! aUrl || typeof aUrl != "string" ) throw Components . Exception ( "aURL must be a non-empty string" , Cr . NS_ERROR_INVALID_ARG ) ; if ( typeof aCallback != "function" ) throw Components . Exception ( "aCallback must be a function" , Cr . NS_ERROR_INVALID_ARG ) ; if ( ! aMimetype || typeof aMimetype != "string" ) throw Components . Exception ( "aMimetype must be a non-empty string" , Cr . NS_ERROR_INVALID_ARG ) ; if ( aHash && typeof aHash != "string" ) throw Components . Exception ( "aHash must be a string or null" , Cr . NS_ERROR_INVALID_ARG ) ; if ( aName && typeof aName != "string" ) throw Components . Exception ( "aName must be a string or null" , Cr . NS_ERROR_INVALID_ARG ) ; if ( aIcons ) { if ( typeof aIcons == "string" ) aIcons = { "32" : aIcons } ; else if ( typeof aIcons != "object" ) throw Components . Exception ( "aIcons must be a string, an object or null" , Cr . NS_ERROR_INVALID_ARG ) ; } else { aIcons = { } ; } if ( aVersion && typeof aVersion != "string" ) throw Components . Exception ( "aVersion must be a string or null" , Cr . NS_ERROR_INVALID_ARG ) ; if ( aLoadGroup && ( ! ( aLoadGroup instanceof Ci . nsILoadGroup ) ) ) throw Components . Exception ( "aLoadGroup must be a nsILoadGroup or null" , Cr . NS_ERROR_INVALID_ARG ) ; let providers = this . providers . slice ( 0 ) ; for ( let provider of providers ) { if ( callProvider ( provider , "supportsMimetype" , false , aMimetype ) ) { callProvider ( provider , "getInstallForURL" , null , aUrl , aHash , aName , aIcons , aVersion , aLoadGroup , function ( aInstall ) { safeCall ( aCallback , aInstall ) ; } ) ; return ; } } safeCall ( aCallback , null ) ; }
Asynchronously gets an AddonInstall for a URL.
Asynchronously gets an AddonInstall for a URL .