Bug 1291700 - Allow negotiate/ntml to work when in the 'Never remember history' mode. r=jduell a=lizzard
authorHonza Bambas <honzab.moz@firemni.cz>
Tue, 16 Aug 2016 06:24:00 -0400
changeset 347781 28353c3a97ed6409a37f15d62b0be87ae37b91db
parent 347780 41fb33de0efc503eb5c4d8c27c708bc99011b12c
child 347782 4998add2cdadd31a8a3c106a231731edd8216b52
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjduell, lizzard
bugs1291700
milestone50.0a2
Bug 1291700 - Allow negotiate/ntml to work when in the 'Never remember history' mode. r=jduell a=lizzard
extensions/auth/nsHttpNegotiateAuth.cpp
netwerk/protocol/http/nsHttpNTLMAuth.cpp
--- a/extensions/auth/nsHttpNegotiateAuth.cpp
+++ b/extensions/auth/nsHttpNegotiateAuth.cpp
@@ -60,17 +60,37 @@ static const char kNegotiateAuthSSPI[] =
 //-----------------------------------------------------------------------------
 
 // Return false when the channel comes from a Private browsing window.
 static bool
 TestNotInPBMode(nsIHttpAuthenticableChannel *authChannel)
 {
     nsCOMPtr<nsIChannel> bareChannel = do_QueryInterface(authChannel);
     MOZ_ASSERT(bareChannel);
-    return !NS_UsePrivateBrowsing(bareChannel);
+
+    if (!NS_UsePrivateBrowsing(bareChannel)) {
+        return true;
+    }
+
+    nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
+    if (!prefs) {
+        return true;
+    }
+
+    // When the "Never remember history" option is set, all channels are
+    // set PB mode flag, but here we want to make an exception, users
+    // want their credentials go out.
+    bool dontRememberHistory;
+    if (NS_SUCCEEDED(prefs->GetBoolPref("browser.privatebrowsing.autostart",
+                                        &dontRememberHistory)) &&
+        dontRememberHistory) {
+        return true;
+    }
+
+    return false;
 }
 
 NS_IMETHODIMP
 nsHttpNegotiateAuth::GetAuthFlags(uint32_t *flags)
 {
     //
     // Negotiate Auth creds should not be reused across multiple requests.
     // Only perform the negotiation when it is explicitly requested by the
--- a/netwerk/protocol/http/nsHttpNTLMAuth.cpp
+++ b/netwerk/protocol/http/nsHttpNTLMAuth.cpp
@@ -182,27 +182,37 @@ ForceGenericNTLM()
     return flag;
 }
 
 // Check to see if we should use default credentials for this host or proxy.
 static bool
 CanUseDefaultCredentials(nsIHttpAuthenticableChannel *channel,
                          bool isProxyAuth)
 {
+    nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
+
     // Prevent using default credentials for authentication when we are in the
     // private browsing mode.  It would cause a privacy data leak.
     nsCOMPtr<nsIChannel> bareChannel = do_QueryInterface(channel);
     MOZ_ASSERT(bareChannel);
+
     if (NS_UsePrivateBrowsing(bareChannel)) {
-        return false;
+        // But allow when in the "Never remember history" mode.
+        bool dontRememberHistory;
+        if (prefs &&
+            NS_SUCCEEDED(prefs->GetBoolPref("browser.privatebrowsing.autostart",
+                                            &dontRememberHistory)) &&
+            !dontRememberHistory) {
+            return false;
+        }
     }
 
-    nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
-    if (!prefs)
+    if (!prefs) {
         return false;
+    }
 
     if (isProxyAuth) {
         bool val;
         if (NS_FAILED(prefs->GetBoolPref(kAllowProxies, &val)))
             val = false;
         LOG(("Default credentials allowed for proxy: %d\n", val));
         return val;
     }