Bug 1576614 - Port Bug 1452361 "Don't reset to default permissions for cookies in page info" to SeaMonkey. r=frg a=frg
authorIan Neal <iann_cvs@blueyonder.co.uk>
Tue, 01 Oct 2019 16:59:22 +0200
changeset 32320 8643534c597195f0b45b4d94d4ceb695e804eece
parent 32319 2de29b2f2c3ed933481691812f51df071a78d512
child 32321 242953296b0fdb50612627dc56846ab6e060da9b
push id220
push userfrgrahl@gmx.net
push dateTue, 01 Oct 2019 15:01:16 +0000
treeherdercomm-esr60@e71c6693877f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfrg, frg
bugs1576614, 1452361
Bug 1576614 - Port Bug 1452361 "Don't reset to default permissions for cookies in page info" to SeaMonkey. r=frg a=frg
suite/browser/pageinfo/permissions.js
suite/modules/SitePermissions.jsm
--- a/suite/browser/pageinfo/permissions.js
+++ b/suite/browser/pageinfo/permissions.js
@@ -72,16 +72,37 @@ function initRow(aPartId)
     command.setAttribute("disabled", "true");
     document.getElementById(aPartId + "RadioGroup").selectedItem = null;
     return;
   }
   checkbox.removeAttribute("disabled");
   var {state} = SitePermissions.get(gPermURI, aPartId);
   let defaultState = SitePermissions.getDefault(aPartId);
 
+  // Since cookies preferences have many different possible configuration states
+  // we don't consider any permission except "no permission" to be default.
+  if (aPartId == "cookie") {
+    state = Services.perms.testPermissionFromPrincipal(gPermPrincipal, "cookie");
+
+    if (state == SitePermissions.UNKNOWN) {
+      checkbox.checked = true;
+      command.setAttribute("disabled", "true");
+      // Don't select any item in the radio group, as we can't
+      // confidently say that all cookies on the site will be allowed.
+      let radioGroup = document.getElementById("cookieRadioGroup");
+      radioGroup.selectedItem = null;
+    } else {
+      checkbox.checked = false;
+      command.removeAttribute("disabled");
+    }
+
+    setRadioState(aPartId, state);
+    return;
+  }
+
   // When flash permission state is "Hide", we show it as "Always Ask"
   // in page info.
   if (aPartId.startsWith("plugin") && state == SitePermissions.PROMPT_HIDE) {
     defaultState == SitePermissions.UNKNOWN ? state = defaultState :
                                               state = SitePermissions.PROMPT;
   }
 
   if (state != defaultState) {
@@ -154,29 +175,27 @@ function createRow(aPartId) {
 
 function onCheckboxClick(aPartId)
 {
   var command  = document.getElementById("cmd_" + aPartId + "Toggle");
   var checkbox = document.getElementById(aPartId + "Def");
   if (checkbox.checked) {
     SitePermissions.remove(gPermURI, aPartId);
     command.setAttribute("disabled", "true");
-    var perm = SitePermissions.getDefault(aPartId);
-    setRadioState(aPartId, perm);
   }
   else {
     onRadioClick(aPartId);
     command.removeAttribute("disabled");
   }
 }
 
 function onRadioClick(aPartId)
 {
   var radioGroup = document.getElementById(aPartId + "RadioGroup");
-  var id = radioGroup.selectedItem.id;
+  var id = radioGroup.selectedItem ? radioGroup.selectedItem.id : "#1";
   var permission = parseInt(id.split("#")[1]);
   SitePermissions.set(gPermURI, aPartId, permission);
 }
 
 function setRadioState(aPartId, aValue)
 {
   var radio = document.getElementById(aPartId + "#" + aValue);
   if (radio) {
--- a/suite/modules/SitePermissions.jsm
+++ b/suite/modules/SitePermissions.jsm
@@ -397,18 +397,24 @@ var SitePermissions = {
    * @param {SitePermissions scope} scope (optional)
    *        The scope of the permission. Defaults to SCOPE_PERSISTENT.
    * @param {Browser} browser (optional)
    *        The browser object to set temporary permissions on.
    *        This needs to be provided if the scope is SCOPE_TEMPORARY!
    */
   set(uri, permissionID, state, scope = this.SCOPE_PERSISTENT, browser = null) {
     if (state == this.UNKNOWN || state == this.getDefault(permissionID)) {
-      this.remove(uri, permissionID, browser);
-      return;
+      // Because they are controlled by two prefs with many states that do not
+      // correspond to the classical ALLOW/DENY/PROMPT model, we want to always
+      // allow the user to add exceptions to their cookie rules without
+      // removing them.
+      if (permissionID != "cookie") {
+        this.remove(uri, permissionID, browser);
+        return;
+      }
     }
 
     if (state == this.ALLOW_COOKIES_FOR_SESSION && permissionID != "cookie") {
       throw "ALLOW_COOKIES_FOR_SESSION can only be set on the cookie permission";
     }
 
     // Save temporary permissions.
     if (scope == this.SCOPE_TEMPORARY) {
@@ -627,20 +633,20 @@ var gPermissionObject = {
       }
       throw new Error(`Unknown state: ${state}`);
     },
   },
 
   "cookie": {
     states: [ SitePermissions.ALLOW, SitePermissions.ALLOW_COOKIES_FOR_SESSION, SitePermissions.BLOCK ],
     getDefault() {
-      if (Services.prefs.getIntPref("network.cookie.cookieBehavior") == 2)
+      if (Services.prefs.getIntPref("network.cookie.cookieBehavior") == Ci.nsICookieService.BEHAVIOR_REJECT)
         return SitePermissions.BLOCK;
 
-      if (Services.prefs.getIntPref("network.cookie.lifetimePolicy") == 2)
+      if (Services.prefs.getIntPref("network.cookie.lifetimePolicy") == Ci.nsICookieService.ACCEPT_SESSION)
         return SitePermissions.ALLOW_COOKIES_FOR_SESSION;
 
       return SitePermissions.ALLOW;
     }
   },
 
   "desktop-notification": {
     exactHostMatch: true,