Bug 1243549 - Making sure that startup sanitization doesn't throw because it can't find a tabbrowser;r=mak
--- a/browser/base/content/sanitize.js
+++ b/browser/base/content/sanitize.js
@@ -10,16 +10,18 @@ XPCOMUtils.defineLazyModuleGetter(this,
XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
"resource://gre/modules/PlacesUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "FormHistory",
"resource://gre/modules/FormHistory.jsm");
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",
"resource:///modules/DownloadsCommon.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "TelemetryStopwatch",
"resource://gre/modules/TelemetryStopwatch.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "console",
"resource://gre/modules/Console.jsm");
@@ -334,16 +336,23 @@ Sanitizer.prototype = {
var windows = windowManager.getEnumerator("navigator:browser");
while (windows.hasMoreElements()) {
let currentWindow = windows.getNext();
let currentDocument = currentWindow.document;
let searchBar = currentDocument.getElementById("searchbar");
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();
}
// Clear any saved find value
tabBrowser._lastFindValue = "";
}
@@ -678,36 +687,47 @@ Sanitizer.showUI = function(aParentWindo
* sanitize UI, according to user preferences
*/
Sanitizer.sanitize = function(aParentWindow)
{
Sanitizer.showUI(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"]
+ // 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);
- // One time migration to remove support for the clear saved passwords on exit feature.
- if (!Services.prefs.getBoolPref("privacy.sanitize.migrateClearSavedPwdsOnExit")) {
- let deprecatedPref = "privacy.clearOnShutdown.passwords";
- let doUpdate = Services.prefs.prefHasUserValue(deprecatedPref) &&
- Services.prefs.getBoolPref(deprecatedPref);
- if (doUpdate) {
- Services.logins.removeAllLogins();
- Services.prefs.setBoolPref("signon.rememberSignons", false);
- }
- Services.prefs.clearUserPref(deprecatedPref);
- Services.prefs.setBoolPref("privacy.sanitize.migrateClearSavedPwdsOnExit", true);
+ // One time migration to remove support for the clear saved passwords on exit feature.
+ if (!Services.prefs.getBoolPref("privacy.sanitize.migrateClearSavedPwdsOnExit")) {
+ let deprecatedPref = "privacy.clearOnShutdown.passwords";
+ let doUpdate = Services.prefs.prefHasUserValue(deprecatedPref) &&
+ Services.prefs.getBoolPref(deprecatedPref);
+ if (doUpdate) {
+ Services.logins.removeAllLogins();
+ Services.prefs.setBoolPref("signon.rememberSignons", false);
+ }
+ Services.prefs.clearUserPref(deprecatedPref);
+ Services.prefs.setBoolPref("privacy.sanitize.migrateClearSavedPwdsOnExit", true);
}
// 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);