Bug 801630 - exception.js makes use of the global Private Browsing service to make decisions r=ehsan
authorMark Finkle <mfinkle@mozilla.com>
Mon, 22 Oct 2012 18:10:16 -0400
changeset 111216 a1170e62ccd519d89585fd1e50bb50145a302f84
parent 111215 48502b61a63e9c17df6914429101cf8a6b2253cf
child 111217 f2686a2cd826699d16eef33fa11f810dfc4a08cb
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersehsan
bugs801630
milestone19.0a1
Bug 801630 - exception.js makes use of the global Private Browsing service to make decisions r=ehsan
mobile/android/chrome/content/browser.js
mobile/android/chrome/content/exceptions.js
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -4283,19 +4283,19 @@ var ErrorPageEventHandler = {
           if (target == temp || target == perm) {
             // Handle setting an cert exception and reloading the page
             try {
               // Add a new SSL exception for this URL
               let uri = Services.io.newURI(errorDoc.location.href, null, null);
               let sslExceptions = new SSLExceptions();
 
               if (target == perm)
-                sslExceptions.addPermanentException(uri);
+                sslExceptions.addPermanentException(uri, errorDoc.defaultView);
               else
-                sslExceptions.addTemporaryException(uri);
+                sslExceptions.addTemporaryException(uri, errorDoc.defaultView);
             } catch (e) {
               dump("Failed to set cert exception: " + e + "\n");
             }
             errorDoc.location.reload();
           } else if (target == errorDoc.getElementById("getMeOutOfHereButton")) {
             errorDoc.location = "about:home";
           }
         } else if (/^about:blocked/.test(errorDoc.documentURI)) {
--- a/mobile/android/chrome/content/exceptions.js
+++ b/mobile/android/chrome/content/exceptions.js
@@ -1,14 +1,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 let Cc = Components.classes;
 let Ci = Components.interfaces;
+let Cu = Components.utils;
+
+Cu.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
 
 /**
   A class to add exceptions to override SSL certificate problems. The functionality
   itself is borrowed from exceptionDialog.js.
 */
 function SSLExceptions() {
   this._overrideService = Cc["@mozilla.org/security/certoverride;1"]
                           .getService(Ci.nsICertOverrideService);
@@ -35,27 +38,16 @@ SSLExceptions.prototype = {
     and store the status for later use.
   */
   notifyCertProblem: function SSLE_notifyCertProblem(socketInfo, sslStatus, targetHost) {
     this._sslStatus = sslStatus.QueryInterface(Ci.nsISSLStatus);
     return true; // suppress error UI
   },
 
   /**
-    Returns true if the private browsing mode is currently active
-   */
-  _inPrivateBrowsingMode: function SSLE_inPrivateBrowsingMode() {
-    try {
-      var pb = Cc["@mozilla.org/privatebrowsing;1"].getService(Ci.nsIPrivateBrowsingService);
-      return pb.privateBrowsingEnabled;
-    } catch (ex) {}
-    return false;
-  },
-
-  /**
     Attempt to download the certificate for the location specified to get the SSLState
     for the certificate and the errors.
    */
   _checkCert: function SSLE_checkCert(aURI) {
     this._sslStatus = null;
   
     var req = new XMLHttpRequest();
     try {
@@ -74,24 +66,24 @@ SSLExceptions.prototype = {
     }
 
     return this._sslStatus;
   },
 
   /**
     Internal method to create an override.
   */
-  _addOverride: function SSLE_addOverride(aURI, temporary) {
+  _addOverride: function SSLE_addOverride(aURI, aWindow, temporary) {
     var SSLStatus = this._checkCert(aURI);
     var certificate = SSLStatus.serverCert;
 
     var flags = 0;
 
     // in private browsing do not store exceptions permanently ever
-    if (this._inPrivateBrowsingMode()) {
+    if (PrivateBrowsingUtils.isWindowPrivate(aWindow)) {
       temporary = true;
     }
 
     if(SSLStatus.isUntrusted)
       flags |= this._overrideService.ERROR_UNTRUSTED;
     if(SSLStatus.isDomainMismatch)
       flags |= this._overrideService.ERROR_MISMATCH;
     if(SSLStatus.isNotValidAtThisTime)
@@ -104,20 +96,20 @@ SSLExceptions.prototype = {
       flags,
       temporary);
   },
 
   /**
     Creates a permanent exception to override all overridable errors for
     the given URL.
   */
-  addPermanentException: function SSLE_addPermanentException(aURI) {
-    this._addOverride(aURI, false);
+  addPermanentException: function SSLE_addPermanentException(aURI, aWindow) {
+    this._addOverride(aURI, aWindow, false);
   },
 
   /**
     Creates a temporary exception to override all overridable errors for
     the given URL.
   */
-  addTemporaryException: function SSLE_addTemporaryException(aURI) {
-    this._addOverride(aURI, true);
+  addTemporaryException: function SSLE_addTemporaryException(aURI, aWindow) {
+    this._addOverride(aURI, aWindow, true);
   }
 };