B2G/gecko/toolkit/mozapps/extensions/XPIProvider.jsm
/**
 * Loads an AddonInternal object from an add-on extracted in a directory.
 *
 * @param  aDir
 *         The nsIFile directory holding the add-on
 * @return an AddonInternal object
 * @throws if the directory does not contain a valid install manifest
 */
Loads an AddonInternal object from an add-on extracted in a directory.
@param  aDir
The nsIFile directory holding the add-on
@return an AddonInternal object
@throws if the directory does not contain a valid install manifest
Loads an AddonInternal object from an add - on extracted in a directory . @param aDir The nsIFile directory holding the add - on @return an AddonInternal object @throws if the directory does not contain a valid install manifest
function loadManifestFromDir(aDir) {
  function getFileSize(aFile) {
    if (aFile.isSymlink())
      return 0;
    if (!aFile.isDirectory())
      return aFile.fileSize;
    let size = 0;
    let entries = aFile.directoryEntries.QueryInterface(Ci.nsIDirectoryEnumerator);
    let entry;
    while (entry = entries.nextFile)
      size += getFileSize(entry);
    entries.close();
    return size;
  }
  let file = aDir.clone();
  file.append(FILE_INSTALL_MANIFEST);
  if (!file.exists() || !file.isFile())
    throw new Error("Directory " + aDir.path + " does not contain a valid " +
                    "install manifest");
  let fis = Cc["@mozilla.org/network/file-input-stream;1"].
            createInstance(Ci.nsIFileInputStream);
  fis.init(file, -1, -1, false);
  let bis = Cc["@mozilla.org/network/buffered-input-stream;1"].
            createInstance(Ci.nsIBufferedInputStream);
  bis.init(fis, 4096);
  try {
    let addon = loadManifestFromRDF(Services.io.newFileURI(file), bis);
    addon._sourceBundle = aDir.clone();
    addon.size = getFileSize(aDir);
    file = aDir.clone();
    file.append("chrome.manifest");
    let chromeManifest = ChromeManifestParser.parseSync(Services.io.newFileURI(file));
    addon.hasBinaryComponents = ChromeManifestParser.hasType(chromeManifest,
                                                             "binary-component");
    addon.appDisabled = !isUsableAddon(addon);
    return addon;
  }
  finally {
    bis.close();
    fis.close();
  }
}
function loadManifestFromDir ( aDir ) { function getFileSize ( aFile ) { if ( aFile . isSymlink ( ) ) return 0 ; if ( ! aFile . isDirectory ( ) ) return aFile . fileSize ; let size = 0 ; let entries = aFile . directoryEntries . QueryInterface ( Ci . nsIDirectoryEnumerator ) ; let entry ; while ( entry = entries . nextFile ) size += getFileSize ( entry ) ; entries . close ( ) ; return size ; } let file = aDir . clone ( ) ; file . append ( FILE_INSTALL_MANIFEST ) ; if ( ! file . exists ( ) || ! file . isFile ( ) ) throw new Error ( "Directory " + aDir . path + " does not contain a valid " + "install manifest" ) ; let fis = Cc [ "@mozilla.org/network/file-input-stream;1" ] . createInstance ( Ci . nsIFileInputStream ) ; fis . init ( file , - 1 , - 1 , false ) ; let bis = Cc [ "@mozilla.org/network/buffered-input-stream;1" ] . createInstance ( Ci . nsIBufferedInputStream ) ; bis . init ( fis , 4096 ) ; try { let addon = loadManifestFromRDF ( Services . io . newFileURI ( file ) , bis ) ; addon . _sourceBundle = aDir . clone ( ) ; addon . size = getFileSize ( aDir ) ; file = aDir . clone ( ) ; file . append ( "chrome.manifest" ) ; let chromeManifest = ChromeManifestParser . parseSync ( Services . io . newFileURI ( file ) ) ; addon . hasBinaryComponents = ChromeManifestParser . hasType ( chromeManifest , "binary-component" ) ; addon . appDisabled = ! isUsableAddon ( addon ) ; return addon ; } finally { bis . close ( ) ; fis . close ( ) ; } }
Loads an AddonInternal object from an add-on extracted in a directory.
Loads an AddonInternal object from an add - on extracted in a directory .