📄 nsextensionmanager.js
字号:
return null; }, /** * See nsIExtensionManager.idl */ get itemLocations() { var locations = []; if (!this._location.exists()) return new FileEnumerator(locations); try { var entries = this._location.directoryEntries.QueryInterface(nsIDirectoryEnumerator); while (true) { var entry = entries.nextFile; if (!entry) break; entry instanceof nsILocalFile; if (!entry.isDirectory() && gIDTest.test(entry.leafName)) { var linkedDirectory = this._readDirectoryFromFile(entry); if (linkedDirectory && linkedDirectory.exists() && linkedDirectory.isDirectory()) { locations.push(linkedDirectory); this._locationToIDMap[linkedDirectory.persistentDescriptor] = entry.leafName; } } else locations.push(entry); } entries.close(); } catch (e) { } return new FileEnumerator(locations); }, /** * Retrieves the GUID for an item at the specified location. * @param file * The location where an item might live. * @returns The ID for an item that might live at the location specified. * * N.B. This function makes no promises about whether or not this path is * actually maintained by this Install Location. */ getIDForLocation: function(file) { var section = file.leafName; var filePD = file.persistentDescriptor; if (filePD in this._locationToIDMap) section = this._locationToIDMap[filePD]; if (gIDTest.test(section)) return RegExp.$1; return undefined; }, /** * See nsIExtensionManager.idl */ get location() { return this._location.clone(); }, /** * See nsIExtensionManager.idl */ get restricted() { return this._restricted; }, /** * See nsIExtensionManager.idl */ get canAccess() { if (this._canAccess != null) return this._canAccess; var testFile = this.location; testFile.append("Access Privileges Test"); try { testFile.createUnique(nsILocalFile.DIRECTORY_TYPE, PERMS_DIRECTORY); testFile.remove(false); this._canAccess = true; } catch (e) { this._canAccess = false; } return this._canAccess; }, /** * See nsIExtensionManager.idl */ get priority() { return this._priority; }, /** * See nsIExtensionManager.idl */ getItemLocation: function(id) { var itemLocation = this.location; itemLocation.append(id); if (itemLocation.exists() && !itemLocation.isDirectory()) return this._readDirectoryFromFile(itemLocation); if (!itemLocation.exists() && this.canAccess) itemLocation.create(nsILocalFile.DIRECTORY_TYPE, PERMS_DIRECTORY); return itemLocation; }, /** * See nsIExtensionManager.idl */ itemIsManagedIndependently: function(id) { var itemLocation = this.location; itemLocation.append(id); return itemLocation.exists() && !itemLocation.isDirectory(); }, /** * See nsIExtensionManager.idl */ getItemFile: function(id, filePath) { var itemLocation = this.getItemLocation(id).clone(); var parts = filePath.split("/"); for (var i = 0; i < parts.length; ++i) itemLocation.append(parts[i]); return itemLocation; }, /** * Stages the specified file for later. * @param file * The file to stage * @param id * The GUID of the item the file represents */ stageFile: function(file, id) { var stagedFile = this.location; stagedFile.append(DIR_STAGE); stagedFile.append(id); stagedFile.append(file.leafName); // When an incompatible update is successful the file is already staged if (stagedFile.equals(file)) return stagedFile; if (stagedFile.exists()) stagedFile.remove(false); file.copyTo(stagedFile.parent, stagedFile.leafName); // If the file has incorrect permissions set, correct them now. if (!stagedFile.isWritable()) stagedFile.permissions = PERMS_FILE; return stagedFile; }, /** * Returns the most recently staged package (e.g. the last XPI or JAR in a * directory) for an item and removes items that do not qualify. * @param id * The ID of the staged package * @returns an nsIFile if the package exists otherwise null. */ getStageFile: function(id) { var stageFile = null; var stageDir = this.location; stageDir.append(DIR_STAGE); stageDir.append(id); if (!stageDir.exists() || !stageDir.isDirectory()) return null; try { var entries = stageDir.directoryEntries.QueryInterface(nsIDirectoryEnumerator); while (entries.hasMoreElements()) { var file = entries.nextFile; if (!(file instanceof nsILocalFile)) continue; if (file.isDirectory()) removeDirRecursive(file); else if (fileIsItemPackage(file)) { if (stageFile) stageFile.remove(false); stageFile = file; } else file.remove(false); } } catch (e) { } if (entries instanceof nsIDirectoryEnumerator) entries.close(); return stageFile; }, /** * Removes a file from the stage. This cleans up the stage if there is nothing * else left after the remove operation. * @param file * The file to remove. */ removeFile: function(file) { if (file.exists()) file.remove(false); var parent = file.parent; var entries = parent.directoryEntries; try { // XXXrstrong calling hasMoreElements on a nsIDirectoryEnumerator after // it has been removed will cause a crash on Mac OS X - bug 292823 while (parent && !parent.equals(this.location) && !entries.hasMoreElements()) { parent.remove(false); parent = parent.parent; entries = parent.directoryEntries; } if (entries instanceof nsIDirectoryEnumerator) entries.close(); } catch (e) { LOG("DirectoryInstallLocation::removeFile: failed to remove staged " + " directory = " + parent.path + ", exception = " + e + "\n"); } }, /** * See nsISupports.idl */ QueryInterface: function (iid) { if (!iid.equals(Components.interfaces.nsIInstallLocation) && !iid.equals(Components.interfaces.nsISupports)) throw Components.results.NS_ERROR_NO_INTERFACE; return this; }};//@line 1291 "/c/builds/1813/mozilla/toolkit/mozapps/extensions/src/nsExtensionManager.js.in"const nsIWindowsRegKey = Components.interfaces.nsIWindowsRegKey;/** * An object that identifies the location of installed items based on entries * in the Windows registry. For each application a subkey is defined that * contains a set of values, where the name of each value is a GUID and the * contents of the value is a filesystem path identifying a directory * containing an installed item. * * @param name * The string identifier of this Install Location. * @param rootKey * The root key (one of the ROOT_KEY_ values from nsIWindowsRegKey). * @param restricted * Indicates that the location may be restricted (e.g., this is * usually true of a system level install location). * @param priority * The priority of this install location. * @constructor */function WinRegInstallLocation(name, rootKey, restricted, priority) { this._name = name; this._rootKey = rootKey; this._restricted = restricted; this._priority = priority; this._IDToDirMap = {}; this._DirToIDMap = {}; // Reading the registry may throw an exception, and that's ok. In error // cases, we just leave ourselves in the empty state. try { var path = this._appKeyPath + "\\Extensions"; var key = Components.classes["@mozilla.org/windows-registry-key;1"] .createInstance(nsIWindowsRegKey); key.open(this._rootKey, path, nsIWindowsRegKey.ACCESS_READ); this._readAddons(key); } catch (e) { if (key) key.close(); }}WinRegInstallLocation.prototype = { _name : "", _rootKey : null, _restricted : false, _priority : 0, _IDToDirMap : null, // mapping from ID to directory object _DirToIDMap : null, // mapping from directory path to ID /** * Retrieves the path of this Application's data key in the registry. */ get _appKeyPath() { var appVendor = gApp.vendor; var appName = gApp.name;//@line 1353 "/c/builds/1813/mozilla/toolkit/mozapps/extensions/src/nsExtensionManager.js.in" // XULRunner-based apps may intentionally not specify a vendor: if (appVendor != "") appVendor += "\\"; return "SOFTWARE\\" + appVendor + appName; }, /** * Read the registry and build a mapping between GUID and directory for each * installed item. * @param key * The key that contains the GUID->path pairs */ _readAddons: function(key) { var count = key.valueCount; for (var i = 0; i < count; ++i) { var id = key.getValueName(i); var dir = Components.classes["@mozilla.org/file/local;1"] .createInstance(nsILocalFile); dir.initWithPath(key.readStringValue(id)); if (dir.exists() && dir.isDirectory()) { this._IDToDirMap[id] = dir; this._DirToIDMap[dir.path] = id; } } }, get name() { return this._name; }, get itemLocations() { var locations = []; for (var id in this._IDToDirMap) { locations.push(this._IDToDirMap[id]); } return new FileEnumerator(locations); }, get location() { return null; }, get restricted() { return this._restricted; }, // you should never be able to write to this location get canAccess() { return false; }, get priority() { return this._priority; }, getItemLocation: function(id) { return this._IDToDirMap[id]; }, getIDForLocation: function(dir) { return this._DirToIDMap[dir.path]; }, getItemFile: function(id, filePath) { var itemLocation = this.getItemLocation(id).clone(); var parts = filePath.split("/"); for (var i = 0; i < parts.length; ++i) itemLocation.append(parts[i]); return itemLocation; }, itemIsManagedIndependently: function(id) { return true; }, QueryInterface: function(iid) { if (!iid.equals(Components.interfaces.nsIInstallLocation) &&
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -