⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nsextensionmanager.js

📁 从国外的站点上淘的个人财务管理系统.开源.
💻 JS
📖 第 1 页 / 共 5 页
字号:
/** * Given an Install Manifest Datasource, retrieves the type of item the manifest * describes. * @param   installManifest  *          The Install Manifest Datasource. * @return  The nsIUpdateItem type of the item described by the manifest *          returns TYPE_EXTENSION if attempts to determine the type fail. */function getAddonTypeFromInstallManifest(installManifest) {  var target = installManifest.GetTarget(gInstallManifestRoot,                                          gRDF.GetResource(EM_NS("type")), true);  if (target) {    var type = stringData(target);    return type === undefined ? intData(target) : parseInt(type);  }  // Firefox 1.0 and earlier did not support addon-type annotation on the   // Install Manifest, so we fall back to a theme-only property to   // differentiate.  if (getManifestProperty(installManifest, "internalName") !== undefined)    return nsIUpdateItem.TYPE_THEME;  // If no type is provided, default to "Extension"  return nsIUpdateItem.TYPE_EXTENSION;    }/** * Shows a message about an incompatible Extension/Theme.  * @param   installData *          An Install Data object from |getInstallData| */function showIncompatibleError(installData) {  var extensionStrings = BundleManager.getBundle(URI_EXTENSIONS_PROPERTIES);  var params = [extensionStrings.GetStringFromName("type-" + installData.type)];  var title = extensionStrings.formatStringFromName("incompatibleTitle",                                                     params, params.length);  var message;  var targetAppData = installData.currentApp;  if (!targetAppData) {    params = [installData.name, installData.version, BundleManager.appName];    message = extensionStrings.formatStringFromName("incompatibleMessageNoApp",                                                     params, params.length);  }  else if (targetAppData.minVersion == targetAppData.maxVersion) {    // If the min target app version and the max target app version are the same, don't show    // a message like, "Foo is only compatible with Firefox versions 0.7 to 0.7", rather just    // show, "Foo is only compatible with Firefox 0.7"    params = [installData.name, installData.version, BundleManager.appName, gApp.version,               installData.name, installData.version, BundleManager.appName,               targetAppData.minVersion];    message = extensionStrings.formatStringFromName("incompatibleMsgSingleAppVersion",                                                     params, params.length);  }  else {    params = [installData.name, installData.version, BundleManager.appName, gApp.version,               installData.name, installData.version, BundleManager.appName,               targetAppData.minVersion, targetAppData.maxVersion];    message = extensionStrings.formatStringFromName("incompatibleMsg", params, params.length);  }  var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]                     .getService(Components.interfaces.nsIPromptService);  ps.alert(null, title, message);}/** * Shows a message. * @param   titleKey *          String key of the title string in the Extensions localization file. * @param   messageKey *          String key of the message string in the Extensions localization file. * @param   messageParams *          Array of strings to be substituted into |messageKey|. Can be null. */function showMessage(titleKey, titleParams, messageKey, messageParams) {  var extensionStrings = BundleManager.getBundle(URI_EXTENSIONS_PROPERTIES);  if (titleParams && titleParams.length > 0) {    var title = extensionStrings.formatStringFromName(titleKey, titleParams,                                                      titleParams.length);  }  else    title = extensionStrings.GetStringFromName(titleKey);  if (messageParams && messageParams.length > 0) {    var message = extensionStrings.formatStringFromName(messageKey, messageParams,                                                        messageParams.length);  }  else    message = extensionStrings.GetStringFromName(messageKey);  var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]                     .getService(Components.interfaces.nsIPromptService);  ps.alert(null, title, message);}/** * Shows a dialog for blocklisted items. * @param   items *          An array of nsIUpdateItems. * @param   fromInstall *          Whether this is called from an install or from the blocklist *          background check. */function showBlocklistMessage(items, fromInstall) {  var win = null;  var params = Components.classes["@mozilla.org/embedcomp/dialogparam;1"]                         .createInstance(Components.interfaces.nsIDialogParamBlock);  params.SetInt(0, (fromInstall ? 1 : 0));  params.SetInt(1, items.length);  params.SetNumberStrings(items.length * 2);  for (var i = 0; i < items.length; ++i)     params.SetString(i, items[i].name + " " + items[i].version);  // if this was initiated from an install try to find the appropriate manager  if (fromInstall) {    var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]                       .getService(Components.interfaces.nsIWindowMediator);    win = wm.getMostRecentWindow(nsIUpdateItem.TYPE_THEME ? "Extension:Manager-themes" :                                                            "Extension:Manager-extensions");  }  var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]                     .getService(Components.interfaces.nsIWindowWatcher);  ww.openWindow(win, URI_EXTENSION_LIST_DIALOG, "",                "chrome,centerscreen,modal,dialog,titlebar", params);}/**  * Gets a zip reader for the file specified. * @param   zipFile *          A ZIP archive to open with a nsIZipReader. * @return  A nsIZipReader for the file specified. */function getZipReaderForFile(zipFile) {  try {    var zipReader = Components.classes["@mozilla.org/libjar/zip-reader;1"]                              .createInstance(Components.interfaces.nsIZipReader);    zipReader.init(zipFile);    zipReader.open();  }  catch (e) {    zipReader.close();    throw e;  }  return zipReader;}/**  * Extract a RDF file from a ZIP archive to a random location in the system * temp directory. * @param   zipFile *          A ZIP archive to read from * @param   fileName  *          The name of the file to read from the zip.  * @param   suppressErrors *          Whether or not to report errors.  * @return  The file created in the temp directory. */function extractRDFFileToTempDir(zipFile, fileName, suppressErrors) {  var file = getFile(KEY_TEMPDIR, [getRandomFileName(fileName)]);  try {    var zipReader = getZipReaderForFile(zipFile);    zipReader.getEntry(fileName);    zipReader.extract(fileName, file);    zipReader.close();  }  catch (e) {    if (!suppressErrors) {      showMessage("missingFileTitle", [], "missingFileMessage",                   [BundleManager.appName, fileName]);      throw e;    }  }  return file;}/** * Show a message to the user informing them they are installing an old non-EM * style Theme, and that these are not supported. * @param   installManifest  *          The Old-Style Contents Manifest datasource representing the theme.  */function showOldThemeError(contentsManifest) {  var extensionStrings = BundleManager.getBundle(URI_EXTENSIONS_PROPERTIES);  var params = [extensionStrings.GetStringFromName("theme")];  var title = extensionStrings.formatStringFromName("incompatibleTitle",                                                     params, params.length);  var appVersion = extensionStrings.GetStringFromName("incompatibleOlder");    try {      var ctr = getContainer(contentsManifest,                            gRDF.GetResource("urn:mozilla:skin:root"));    var elts = ctr.GetElements();    var nameArc = gRDF.GetResource(CHROME_NS("displayName"));    while (elts.hasMoreElements()) {      var elt = elts.getNext().QueryInterface(Components.interfaces.nsIRDFResource);      themeName = stringData(contentsManifest.GetTarget(elt, nameArc, true));      if (themeName)         break;    }  }  catch (e) {    themeName = extensionStrings.GetStringFromName("incompatibleThemeName");  }    params = [themeName, "", BundleManager.appName, gApp.version, themeName, "",             BundleManager.appName, appVersion];  var message = extensionStrings.formatStringFromName("incompatibleMsgSingleAppVersion",                                                      params, params.length);  var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]                     .getService(Components.interfaces.nsIPromptService);  ps.alert(null, title, message);}/** * Gets an Install Manifest datasource from a file. * @param   file *          The nsIFile that contains the Install Manifest RDF * @returns The Install Manifest datasource */function getInstallManifest(file) {  var fileURL = getURLSpecFromFile(file);  var ds = gRDF.GetDataSourceBlocking(fileURL);  var arcs = ds.ArcLabelsOut(gInstallManifestRoot);  if (!arcs.hasMoreElements()) {    ds = null;    var uri = Components.classes["@mozilla.org/network/io-service;1"]                        .getService(Components.interfaces.nsIIOService)                        .newFileURI(file);    var url = uri.QueryInterface(nsIURL);    showMessage("malformedTitle", [], "malformedMessage",                 [BundleManager.appName, url.fileName]);  }  return ds;}/** * An enumeration of items in a JS array. * @constructor */function ArrayEnumerator(aItems) {  this._index = 0;  if (aItems) {    for (var i = 0; i < aItems.length; ++i) {      if (!aItems[i])        aItems.splice(i, 1);          }  }  this._contents = aItems;}ArrayEnumerator.prototype = {  _index: 0,  _contents: [],    hasMoreElements: function() {    return this._index < this._contents.length;  },    getNext: function() {    return this._contents[this._index++];        }};/** * An enumeration of files in a JS array. * @param   files *          The files to enumerate * @constructor */function FileEnumerator(files) {  this._index = 0;  if (files) {    for (var i = 0; i < files.length; ++i) {      if (!files[i])        files.splice(i, 1);          }  }  this._contents = files;}FileEnumerator.prototype = {  _index: 0,  _contents: [],  /**   * Gets the next file in the sequence.   */    get nextFile() {    if (this._index < this._contents.length)      return this._contents[this._index++];    return null;  },    /**   * Stop enumerating. Nothing to do here.   */  close: function() {  },};/** * An object which identifies an Install Location for items, where the location * relationship is each item living in a directory named with its GUID under  * the directory used when constructing this object. * * e.g. <location>\{GUID1} *      <location>\{GUID2} *      <location>\{GUID3} *      ... * * @param   name *          The string identifier of this Install Location. * @param   location *          The directory that contains the items.  * @constructor */function DirectoryInstallLocation(name, location, restricted, priority) {  this._name = name;  if (location.exists()) {    if (!location.isDirectory())      throw new Error("location must be a directoy!");  }  else {    try {      location.create(nsILocalFile.DIRECTORY_TYPE, 0775);    }    catch (e) {      LOG("DirectoryInstallLocation: failed to create location " +           " directory = " + location.path + ", exception = " + e + "\n");    }  }  this._location = location;  this._locationToIDMap = {};  this._restricted = restricted;  this._priority = priority;}DirectoryInstallLocation.prototype = {  _name           : "",  _location       : null,  _locationToIDMap: null,  _restricted     : false,  _priority       : 0,  _canAccess      : null,    /**   * See nsIExtensionManager.idl   */  get name() {    return this._name;  },    /**   * Reads a directory linked to in a file.   * @param   file   *          The file containing the directory path   * @returns A nsILocalFile object representing the linked directory.   */  _readDirectoryFromFile: function(file) {    var fis = Components.classes["@mozilla.org/network/file-input-stream;1"]                        .createInstance(Components.interfaces.nsIFileInputStream);    fis.init(file, -1, -1, false);    var line = { value: "" };    if (fis instanceof nsILineInputStream)      fis.readLine(line);    fis.close();    if (line.value) {      var linkedDirectory = Components.classes["@mozilla.org/file/local;1"]                                      .createInstance(nsILocalFile);      try {        linkedDirectory.initWithPath(line.value);      }      catch (e) {        linkedDirectory.setRelativeDescriptor(file.parent, line.value);      }            return linkedDirectory;    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -