Bug 1245065 - Making sanitize.js handle properly nsCookieService shutdown;r?mak
These days, the sanitizer often attempts to cleanup cookies during
shutdown *after* the cookie service has been disconnected, hence when
it is too late. This causes privacy issues and is suspected of causing
shutdown hangs/crashes.
Bug 1245578 introduces a shutdownClient for the nsCookieService. In
this patch, we make use of this shutdownClient to properly handle
sanitization of the cookies during shutdown.
--- a/browser/base/content/sanitize.js
+++ b/browser/base/content/sanitize.js
@@ -689,32 +689,39 @@ Sanitizer.showUI = function(aParentWindo
Sanitizer.sanitize = function(aParentWindow)
{
Sanitizer.showUI(aParentWindow);
};
Sanitizer.onStartup = Task.async(function*() {
// Make sure that we are triggered during shutdown, at the right time,
// and only once.
- let placesClient = Cc["@mozilla.org/browser/nav-history-service;1"] .getService(Ci.nsPIPlacesDatabase)
+ let placesClient = Cc["@mozilla.org/browser/nav-history-service;1"]
+ .getService(Ci.nsPIPlacesDatabase)
.shutdownClient
.jsclient;
+ let cookieClient = Components.classes["@mozilla.org/cookiemanager;1"]
+ .getService(Ci.nsICookieManager)
+ .shutdownClient
+ .jsclient;
let deferredSanitization = PromiseUtils.defer();
let sanitizationInProgress = false;
let doSanitize = function() {
if (sanitizationInProgress) {
return deferredSanitization.promise;
}
sanitizationInProgress = true;
Sanitizer.onShutdown().catch(er => {Promise.reject(er) /* Do not return rejected promise */;}).then(() =>
deferredSanitization.resolve()
);
+ return deferredSanitization.promise;
}
placesClient.addBlocker("sanitize.js: Sanitize on shutdown", doSanitize);
+ cookieClient.addBlocker("sanitize.js: Sanitize on shutdown", doSanitize);
// Handle incomplete sanitizations
if (Preferences.has(Sanitizer.PREF_SANITIZE_IN_PROGRESS)) {
// Firefox crashed during sanitization.
let s = new Sanitizer();
let json = Preferences.get(Sanitizer.PREF_SANITIZE_IN_PROGRESS);
let itemsToClear = JSON.parse(json);
yield s.sanitize(itemsToClear);