From 3fe5e954e6093f3aea1654278ff8e5ed00f99cff Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Wed, 6 Mar 2013 09:51:00 -0500 Subject: [PATCH] Bug 842290 - Make privacy preference tab always check for permanent private browsing status changing, regardless of whether pref changes apply instantly. r=ehsan --- .../preferences/in-content/privacy.js | 72 +++++++++---------- .../preferences/in-content/privacy.xul | 7 +- browser/components/preferences/privacy.js | 72 +++++++++---------- browser/components/preferences/privacy.xul | 7 +- 4 files changed, 72 insertions(+), 86 deletions(-) diff --git a/browser/components/preferences/in-content/privacy.js b/browser/components/preferences/in-content/privacy.js index 12fbabcf2c3..bef928f1e0b 100644 --- a/browser/components/preferences/in-content/privacy.js +++ b/browser/components/preferences/in-content/privacy.js @@ -24,9 +24,7 @@ var gPrivacyPane = { this.initializeHistoryMode(); this.updateHistoryModePane(); this.updatePrivacyMicroControls(); - this.initAutoStartPrivateBrowsingObserver(); - - window.addEventListener("unload", this.removeASPBObserver.bind(this), false); + this.initAutoStartPrivateBrowsingReverter(); }, // HISTORY MODE @@ -232,44 +230,37 @@ var gPrivacyPane = { // PRIVATE BROWSING /** - * Install the observer for the auto-start private browsing mode pref. + * Initialize the starting state for the auto-start private browsing mode pref reverter. */ - initAutoStartPrivateBrowsingObserver: function PPP_initAutoStartPrivateBrowsingObserver() + initAutoStartPrivateBrowsingReverter: function PPP_initAutoStartPrivateBrowsingReverter() { - let prefService = document.getElementById("privacyPreferences") - .service - .QueryInterface(Components.interfaces.nsIPrefBranch); - prefService.addObserver("browser.privatebrowsing.autostart", - this.autoStartPrivateBrowsingObserver, - false); + let mode = document.getElementById("historyMode"); + let autoStart = document.getElementById("privateBrowsingAutoStart"); + this._lastMode = mode.selectedIndex; + this._lastCheckState = autoStart.hasAttribute('checked'); }, - /** - * Install the observer for the auto-start private browsing mode pref. - */ - removeASPBObserver: function PPP_removeASPBObserver() - { - let prefService = document.getElementById("privacyPreferences") - .service - .QueryInterface(Components.interfaces.nsIPrefBranch); - prefService.removeObserver("browser.privatebrowsing.autostart", - this.autoStartPrivateBrowsingObserver); - }, + _lastMode: null, + _lasCheckState: null, + updateAutostart: function PPP_updateAutostart() { + let mode = document.getElementById("historyMode"); + let autoStart = document.getElementById("privateBrowsingAutoStart"); + let pref = document.getElementById("browser.privatebrowsing.autostart"); + if ((mode.value == "custom" && this._lastCheckState == autoStart.checked) || + (mode.value == "remember" && !this._lastCheckState) || + (mode.value == "dontremember" && this._lastCheckState)) { + // These are all no-op changes, so we don't need to prompt. + this._lastMode = mode.selectedIndex; + this._lastCheckState = autoStart.hasAttribute('checked'); + return; + } - autoStartPrivateBrowsingObserver: - { - QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIObserver]), - - observe: function PPP_observe(aSubject, aTopic, aData) - { - if (!gPrivacyPane._shouldPromptForRestart) { + if (!this._shouldPromptForRestart) { // We're performing a revert. Just let it happen. - gPrivacyPane._shouldPromptForRestart = true; return; } const Cc = Components.classes, Ci = Components.interfaces; - let pref = document.getElementById("browser.privatebrowsing.autostart"); let brandName = document.getElementById("bundleBrand").getString("brandShortName"); let bundle = document.getElementById("bundlePreferences"); let msg = bundle.getFormattedString(pref.value ? @@ -286,24 +277,25 @@ var gPrivacyPane = { shouldProceed = !cancelQuit.data; if (shouldProceed) { + document.documentElement.acceptDialog(); let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"] .getService(Ci.nsIAppStartup); appStartup.quit(Ci.nsIAppStartup.eAttemptQuit | Ci.nsIAppStartup.eRestart); return; } } - gPrivacyPane._shouldPromptForRestart = false; - pref.value = !pref.value; - let mode = document.getElementById("historyMode"); - if (mode.value != "custom") { - mode.selectedIndex = pref.value ? 1 : 0; - mode.doCommand(); + this._shouldPromptForRestart = false; + + if (this._lastCheckState) { + autoStart.checked = "checked"; } else { - let rememberHistoryCheckbox = document.getElementById("rememberHistory"); - rememberHistory.checked = pref.value; + autoStart.removeAttribute('checked'); } - } + mode.selectedIndex = this._lastMode; + mode.doCommand(); + + this._shouldPromptForRestart = true; }, // HISTORY diff --git a/browser/components/preferences/in-content/privacy.xul b/browser/components/preferences/in-content/privacy.xul index 9580ce54ecf..9129c1e434a 100644 --- a/browser/components/preferences/in-content/privacy.xul +++ b/browser/components/preferences/in-content/privacy.xul @@ -61,7 +61,6 @@ @@ -101,7 +100,8 @@ + gPrivacyPane.updatePrivacyMicroControls(); + gPrivacyPane.updateAutostart();"> @@ -148,7 +148,8 @@ + preference="browser.privatebrowsing.autostart" + oncommand="gPrivacyPane.updateAutostart()"/> @@ -113,7 +112,8 @@ + gPrivacyPane.updatePrivacyMicroControls(); + gPrivacyPane.updateAutostart();"> @@ -160,7 +160,8 @@ + preference="browser.privatebrowsing.autostart" + oncommand="gPrivacyPane.updateAutostart()"/>