Bug 1243549 - Make sure that startup sanitization doesn't throw because it can't find a tabbrowser. r=mak

This commit is contained in:
David Rajchenbach-Teller 2016-02-04 09:40:40 -05:00
parent 259ea7a423
commit 89b5971b7c

View File

@ -15,6 +15,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "Downloads",
"resource://gre/modules/Downloads.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Promise",
"resource://gre/modules/Promise.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PromiseUtils",
"resource://gre/modules/PromiseUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Task",
"resource://gre/modules/Task.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "DownloadsCommon",
@ -339,6 +341,13 @@ Sanitizer.prototype = {
if (searchBar)
searchBar.textbox.reset();
let tabBrowser = currentWindow.gBrowser;
if (!tabBrowser) {
// No tab browser? This means that it's too early during startup (typically,
// Session Restore hasn't completed yet). Since we don't have find
// bars at that stage and since Session Restore will not restore
// find bars further down during startup, we have nothing to clear.
continue;
}
for (let tab of tabBrowser.tabs) {
if (tabBrowser.isFindBarInitialized(tab))
tabBrowser.getFindBar(tab).clear();
@ -683,14 +692,24 @@ Sanitizer.sanitize = function(aParentWindow)
};
Sanitizer.onStartup = Task.async(function*() {
// Make sure that we are triggered during shutdown, at the right time.
let shutdownClient = Cc["@mozilla.org/browser/nav-history-service;1"]
.getService(Ci.nsPIPlacesDatabase)
// 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)
.shutdownClient
.jsclient;
shutdownClient.addBlocker("sanitize.js: Sanitize on shutdown",
() => Sanitizer.onShutdown());
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()
);
}
placesClient.addBlocker("sanitize.js: Sanitize on shutdown", doSanitize);
// Handle incomplete sanitizations
if (Preferences.has(Sanitizer.PREF_SANITIZE_IN_PROGRESS)) {