Bug 722978 - Port the certificate exception UI to the new per-window private browsing API; r=jdm
authorEhsan Akhgari <ehsan@mozilla.com>
Fri, 12 Oct 2012 23:38:19 -0400
changeset 110609 2604cbda92ac9f47b893439f32b20f612c3b8af3
parent 110608 3dc836fcff4316cdb9bc697feb1a384c12e060f1
child 110610 ff8cdd87d8c1b14b83946ea4264571a608969f1d
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersjdm
bugs722978
milestone19.0a1
Bug 722978 - Port the certificate exception UI to the new per-window private browsing API; r=jdm
browser/base/content/browser.js
browser/components/privatebrowsing/test/browser/global/browser_privatebrowsing_certexceptionsui.js
security/manager/pki/resources/content/exceptionDialog.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -2544,17 +2544,17 @@ let BrowserOnClick = {
     let elmId = aTargetElm.getAttribute("id");
     let secHistogram = Cc["@mozilla.org/base/telemetry;1"].
                         getService(Ci.nsITelemetry).
                         getHistogramById("SECURITY_UI");
 
     switch (elmId) {
       case "exceptionDialogButton":
         secHistogram.add(Ci.nsISecurityUITelemetry.WARNING_BAD_CERT_CLICK_ADD_EXCEPTION);
-        let params = { exceptionAdded : false, handlePrivateBrowsing : true };
+        let params = { exceptionAdded : false };
 
         try {
           switch (Services.prefs.getIntPref("browser.ssl_override_behavior")) {
             case 2 : // Pre-fetch & pre-populate
               params.prefetchCert = true;
             case 1 : // Pre-populate
               params.location = aOwnerDoc.location.href;
           }
--- a/browser/components/privatebrowsing/test/browser/global/browser_privatebrowsing_certexceptionsui.js
+++ b/browser/components/privatebrowsing/test/browser/global/browser_privatebrowsing_certexceptionsui.js
@@ -14,64 +14,37 @@ function test() {
   const EXCEPTIONS_DLG_URL = 'chrome://pippki/content/exceptionDialog.xul';
   const EXCEPTIONS_DLG_FEATURES = 'chrome,centerscreen';
   const INVALID_CERT_LOCATION = 'https://nocert.example.com/';
   waitForExplicitFinish();
 
   // enter private browsing mode
   pb.privateBrowsingEnabled = true;
 
-  step1();
+  doTest();
 
-  // Test the certificate exceptions dialog as it is invoked from about:certerror
-  function step1() {
+  // Test the certificate exceptions dialog
+  function doTest() {
     let params = {
       exceptionAdded : false,
       location: INVALID_CERT_LOCATION,
-      handlePrivateBrowsing : true,
       prefetchCert: true,
     };
     function testCheckbox() {
       win.removeEventListener("load", testCheckbox, false);
       Services.obs.addObserver(function (aSubject, aTopic, aData) {
         Services.obs.removeObserver(arguments.callee, "cert-exception-ui-ready", false);
         ok(win.gCert, "The certificate information should be available now");
 
         let checkbox = win.document.getElementById("permanent");
         ok(checkbox.hasAttribute("disabled"),
           "the permanent checkbox should be disabled when handling the private browsing mode");
         ok(!checkbox.hasAttribute("checked"),
           "the permanent checkbox should not be checked when handling the private browsing mode");
         win.close();
-        step2();
-      }, "cert-exception-ui-ready", false);
-    }
-    var win = openDialog(EXCEPTIONS_DLG_URL, "", EXCEPTIONS_DLG_FEATURES, params);
-    win.addEventListener("load", testCheckbox, false);
-  }
-
-  // Test the certificate excetions dialog as it is invoked from the Preferences dialog
-  function step2() {
-    let params = {
-      exceptionAdded : false,
-      location: INVALID_CERT_LOCATION,
-      prefetchCert: true,
-    };
-    function testCheckbox() {
-      win.removeEventListener("load", testCheckbox, false);
-      Services.obs.addObserver(function (aSubject, aTopic, aData) {
-        Services.obs.removeObserver(arguments.callee, "cert-exception-ui-ready", false);
-        ok(win.gCert, "The certificate information should be available now");
-
-        let checkbox = win.document.getElementById("permanent");
-        ok(!checkbox.hasAttribute("disabled"),
-          "the permanent checkbox should not be disabled when not handling the private browsing mode");
-        ok(checkbox.hasAttribute("checked"),
-          "the permanent checkbox should be checked when not handling the private browsing mode");
-        win.close();
         cleanup();
       }, "cert-exception-ui-ready", false);
     }
     var win = openDialog(EXCEPTIONS_DLG_URL, "", EXCEPTIONS_DLG_FEATURES, params);
     win.addEventListener("load", testCheckbox, false);
   }
 
   function cleanup() {
--- a/security/manager/pki/resources/content/exceptionDialog.js
+++ b/security/manager/pki/resources/content/exceptionDialog.js
@@ -9,16 +9,18 @@ var gPKIBundle;
 var gSSLStatus;
 var gCert;
 var gChecking;
 var gBroken;
 var gNeedReset;
 var gSecHistogram;
 var gNsISecTel;
 
+Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
+
 function badCertListener() {}
 badCertListener.prototype = {
   getInterface: function (aIID) {
     return this.QueryInterface(aIID);
   },
   QueryInterface: function(aIID) {
     if (aIID.equals(Components.interfaces.nsIBadCertListener2) ||
         aIID.equals(Components.interfaces.nsIInterfaceRequestor) ||
@@ -374,27 +376,13 @@ function addException() {
   var args = window.arguments;
   if (args && args[0])
     args[0].exceptionAdded = true;
   
   gDialog.acceptDialog();
 }
 
 /**
- * Returns true if the private browsing mode is currently active and
- * we have been instructed to handle it.
+ * Returns true if this dialog is in private browsing mode.
  */
 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;
+  return PrivateBrowsingUtils.isWindowPrivate(window);
 }