From 65057a43545fc0d0b014bcd90bd5fc9d734b40ee Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Sun, 18 Jan 2009 13:58:08 +0330 Subject: [PATCH] Bug 461627 - Hide the UI for saving certificate exceptions permanently in Private Browsing mode; r=kaie,gavin --- browser/base/content/browser.js | 2 +- .../pki/resources/content/exceptionDialog.js | 47 +++++++++++++------ .../pki/resources/content/exceptionDialog.xul | 2 +- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index cc3350f9d832..317f08bf4641 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -2286,7 +2286,7 @@ function BrowserOnCommand(event) { // Exception…" or "Get me out of here!" button if (/^about:certerror/.test(errorDoc.documentURI)) { if (ot == errorDoc.getElementById('exceptionDialogButton')) { - var params = { exceptionAdded : false }; + var params = { exceptionAdded : false, handlePrivateBrowsing : true }; try { switch (gPrefService.getIntPref("browser.ssl_override_behavior")) { diff --git a/security/manager/pki/resources/content/exceptionDialog.js b/security/manager/pki/resources/content/exceptionDialog.js index 14a233b1c381..ae36f0ad4efc 100644 --- a/security/manager/pki/resources/content/exceptionDialog.js +++ b/security/manager/pki/resources/content/exceptionDialog.js @@ -83,19 +83,6 @@ function initExceptionDialog() { [brandName], 1)); gDialog.getButton("extra1").disabled = true; - // If the Private Browsing service is available and the mode is active, - // don't store permanent exceptions, since they would persist after - // private browsing mode was disabled. - try { - var pb = Components.classes["@mozilla.org/privatebrowsing;1"]. - getService(Components.interfaces.nsIPrivateBrowsingService); - if (pb.privateBrowsingEnabled) { - var permanentCheckbox = document.getElementById("permanent"); - permanentCheckbox.setAttribute("disabled", "true"); - permanentCheckbox.removeAttribute("checked"); - } - } catch (ex) {} - var args = window.arguments; if (args && args[0]) { if (args[0].location) { @@ -300,7 +287,15 @@ function updateCertStatus() { // In these cases, we do want to enable the "Add Exception" button gDialog.getButton("extra1").disabled = false; - document.getElementById("permanent").disabled = false; + + // If the Private Browsing service is available and the mode is active, + // don't store permanent exceptions, since they would persist after + // private browsing mode was disabled. + var inPrivateBrowsing = inPrivateBrowsingMode(); + var pe = document.getElementById("permanent"); + pe.disabled = inPrivateBrowsing; + pe.checked = !inPrivateBrowsing; + setText("headerDescription", gPKIBundle.GetStringFromName("addExceptionInvalidHeader")); } else { @@ -370,13 +365,14 @@ function addException() { flags |= overrideService.ERROR_TIME; var permanentCheckbox = document.getElementById("permanent"); + var shouldStorePermanently = permanentCheckbox.checked && !inPrivateBrowsingMode(); var uri = getURI(); overrideService.rememberValidityOverride( uri.asciiHost, uri.port, gCert, flags, - !permanentCheckbox.checked); + !shouldStorePermanently); var args = window.arguments; if (args && args[0]) @@ -384,3 +380,24 @@ function addException() { gDialog.acceptDialog(); } + +/** + * Returns true if the private browsing mode is currently active and + * we have been instructed to handle it. + */ +function inPrivateBrowsingMode() { + // first, check to see if we should handle the private browsing mode + var args = window.arguments; + if (args && args[0] && args[0].handlePrivateBrowsing) { + // detect if the private browsing mode is active + try { + var pb = Components.classes["@mozilla.org/privatebrowsing;1"]. + getService(Components.interfaces.nsIPrivateBrowsingService); + return pb.privateBrowsingEnabled; + } catch (ex) { + Components.utils.reportError("Could not get the Private Browsing service"); + } + } + + return false; +} diff --git a/security/manager/pki/resources/content/exceptionDialog.xul b/security/manager/pki/resources/content/exceptionDialog.xul index c0d4eb648de8..37e8623338d0 100644 --- a/security/manager/pki/resources/content/exceptionDialog.xul +++ b/security/manager/pki/resources/content/exceptionDialog.xul @@ -115,7 +115,7 @@ -