Bug 1448198 - Make the DisplayBookmarksBar and DisplayMenuBar policies support both true and false params. r=bytesized draft
authorFelipe Gomes <felipc@gmail.com>
Tue, 27 Mar 2018 15:17:14 -0300
changeset 773251 4bb176d6a5fc1258ef78c1a104d2517302d5cafe
parent 771413 28d966d1881897e84a816a7c760e94905741bc85
push id104187
push userfelipc@gmail.com
push dateTue, 27 Mar 2018 18:20:42 +0000
reviewersbytesized
bugs1448198
milestone61.0a1
Bug 1448198 - Make the DisplayBookmarksBar and DisplayMenuBar policies support both true and false params. r=bytesized MozReview-Commit-ID: 7hMINn856WO
browser/components/enterprisepolicies/Policies.jsm
--- a/browser/components/enterprisepolicies/Policies.jsm
+++ b/browser/components/enterprisepolicies/Policies.jsm
@@ -229,37 +229,35 @@ var Policies = {
       if (param) {
         manager.disallowFeature("SysAddonUpdate");
       }
     }
   },
 
   "DisplayBookmarksToolbar": {
     onBeforeUIStartup(manager, param) {
-      if (param) {
-        // This policy is meant to change the default behavior, not to force it.
-        // If this policy was alreay applied and the user chose to re-hide the
-        // bookmarks toolbar, do not show it again.
-        runOnce("displayBookmarksToolbar", () => {
-          gXulStore.setValue(BROWSER_DOCUMENT_URL, "PersonalToolbar", "collapsed", "false");
-        });
-      }
+      let value = (!param).toString();
+      // This policy is meant to change the default behavior, not to force it.
+      // If this policy was alreay applied and the user chose to re-hide the
+      // bookmarks toolbar, do not show it again.
+      runOncePerModification("displayBookmarksToolbar", value, () => {
+        gXulStore.setValue(BROWSER_DOCUMENT_URL, "PersonalToolbar", "collapsed", value);
+      });
     }
   },
 
   "DisplayMenuBar": {
     onBeforeUIStartup(manager, param) {
-      if (param) {
+      let value = (!param).toString();
         // This policy is meant to change the default behavior, not to force it.
         // If this policy was alreay applied and the user chose to re-hide the
         // menu bar, do not show it again.
-        runOnce("displayMenuBar", () => {
-          gXulStore.setValue(BROWSER_DOCUMENT_URL, "toolbar-menubar", "autohide", "false");
-        });
-      }
+      runOncePerModification("displayMenuBar", value, () => {
+        gXulStore.setValue(BROWSER_DOCUMENT_URL, "toolbar-menubar", "autohide", value);
+      });
     }
   },
 
   "DontCheckDefaultBrowser": {
     onBeforeUIStartup(manager, param) {
       setAndLockPref("browser.shell.checkDefaultBrowser", false);
     }
   },
@@ -452,16 +450,17 @@ function addAllowDenyPermissions(permiss
  *
  * Helper function to run a callback only once per policy.
  *
  * @param {string} actionName
  *        A given name which will be used to track if this callback has run.
  * @param {Functon} callback
  *        The callback to run only once.
  */
+ // eslint-disable-next-line no-unused-vars
 function runOnce(actionName, callback) {
   let prefName = `browser.policies.runonce.${actionName}`;
   if (Services.prefs.getBoolPref(prefName, false)) {
     log.debug(`Not running action ${actionName} again because it has already run.`);
     return;
   }
   Services.prefs.setBoolPref(prefName, true);
   callback();