Bug 644856: Make sure any child processes clear the jar cache when uninstalling extensions. r=dtownsend

This commit is contained in:
Giorgio Maone 2011-05-20 10:40:11 -07:00
parent 860b64af7f
commit 98dde442ac
2 changed files with 35 additions and 5 deletions

View File

@ -155,6 +155,8 @@ const TYPES = {
multipackage: 32
};
const MSG_JAR_FLUSH = "AddonJarFlush";
/**
* Valid IDs fit this pattern.
*/
@ -903,6 +905,18 @@ function buildJarURI(aJarfile, aPath) {
return NetUtil.newURI(uri);
}
/**
* Sends local and remote notifications to flush a JAR file cache entry
*
* @param aJarFile
* The ZIP/XPI/JAR file as a nsIFile
*/
function flushJarCache(aJarFile) {
Services.obs.notifyObservers(aJarFile, "flush-cache-entry", null);
Cc["@mozilla.org/globalmessagemanager;1"].getService(Ci.nsIChromeFrameMessageManager)
.sendAsyncMessage(MSG_JAR_FLUSH, aJarFile.path);
}
/**
* Creates and returns a new unique temporary file. The caller should delete
* the file when it is no longer needed.
@ -5438,7 +5452,7 @@ AddonInstall.prototype = {
LOG("Cancelling install of " + this.addon.id);
let xpi = this.installLocation.getStagingDir();
xpi.append(this.addon.id + ".xpi");
Services.obs.notifyObservers(xpi, "flush-cache-entry", null);
flushJarCache(xpi);
cleanStagingDir(this.installLocation.getStagingDir(),
[this.addon.id, this.addon.id + ".xpi",
this.addon.id + ".json"]);
@ -7363,7 +7377,7 @@ DirectoryInstallLocation.prototype = {
file = self._directory.clone().QueryInterface(Ci.nsILocalFile);
file.append(aId + ".xpi");
if (file.exists()) {
Services.obs.notifyObservers(file, "flush-cache-entry", null);
flushJarCache(file);
transaction.move(file, trashDir);
}
}
@ -7380,7 +7394,7 @@ DirectoryInstallLocation.prototype = {
}
else {
if (aSource.isFile())
Services.obs.notifyObservers(aSource, "flush-cache-entry", null);
flushJarCache(aSource);
transaction.move(aSource, this._directory);
}
@ -7443,7 +7457,7 @@ DirectoryInstallLocation.prototype = {
let trashDir = this.getTrashDir();
if (file.leafName != aId)
Services.obs.notifyObservers(file, "flush-cache-entry", null);
flushJarCache(file);
let transaction = new SafeInstallOperation();

View File

@ -44,6 +44,7 @@ const Cu = Components.utils;
const MSG_INSTALL_ENABLED = "WebInstallerIsInstallEnabled";
const MSG_INSTALL_ADDONS = "WebInstallerInstallAddonsFromWebpage";
const MSG_INSTALL_CALLBACK = "WebInstallerInstallCallback";
const MSG_JAR_FLUSH = "AddonJarFlush";
var gIoService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
@ -221,7 +222,22 @@ function InstallTriggerManager() {
this.callbacks = {};
addMessageListener(MSG_INSTALL_CALLBACK, this);
try {
// only if we live in a child process...
if (Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime).processType !== Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT) {
// ... propagate JAR cache flush notifications across process boundaries
addMessageListener(MSG_JAR_FLUSH, function(msg) {
let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
file.initWithPath(msg.json);
Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService)
.notifyObservers(file, "flush-cache-entry", null);
});
}
} catch(e) {
Cu.reportError(e);
}
addEventListener("DOMWindowCreated", this, false);
var self = this;