Bug 1354262 - turn devedition into a pref for js code; r?Gijs draft
authorTom Tromey <tom@tromey.com>
Wed, 12 Apr 2017 10:57:02 -0600
changeset 565351 308044aeba80a0eecc2610fc36b73de463755c08
parent 565350 ac87d7f863e7af4d9c48af8f4797d3f0427374ba
child 565352 bf9489a26c1ada7f072ff492396b20531e568baa
push id54829
push userbmo:ttromey@mozilla.com
push dateWed, 19 Apr 2017 18:27:48 +0000
reviewersGijs
bugs1354262
milestone55.0a1
Bug 1354262 - turn devedition into a pref for js code; r?Gijs Change devedition to be enabled by a pref in JS code. This removes all uses of MOZ_DEV_EDITION from .js and .jsm files. It changes AppConstants to export MOZ_DEV_EDITION as a getter, because some add-ons use it. MozReview-Commit-ID: 82BSbfLDmTG
browser/app/profile/firefox.js
browser/components/customizableui/CustomizableUI.jsm
browser/components/customizableui/test/head.js
browser/components/nsBrowserGlue.js
browser/components/preferences/in-content-old/main.js
browser/components/preferences/in-content-old/main.xul
browser/components/preferences/in-content/main.js
browser/components/preferences/in-content/main.xul
browser/modules/ProcessHangMonitor.jsm
browser/modules/test/browser/browser_BrowserUITelemetry_defaults.js
devtools/client/framework/devtools-browser.js
devtools/client/inspector/webpack/prefs-loader.js
toolkit/content/aboutSupport.js
toolkit/modules/AppConstants.jsm
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -1169,16 +1169,22 @@ pref("services.sync.prefs.sync.xpinstall
 // A preference that controls whether we should show the icon for a remote tab.
 // This pref has no UI but exists because some people may be concerned that
 // fetching these icons to show remote tabs may leak information about that
 // user's tabs and bookmarks. Note this pref is also synced.
 pref("services.sync.syncedTabs.showRemoteIcons", true);
 
 pref("services.sync.sendTabToDevice.enabled", true);
 
+#ifdef MOZ_DEV_EDITION
+pref("devtools.devedition", true);
+#else
+pref("devtools.devedition", false);
+#endif
+
 // Developer edition preferences
 #ifdef MOZ_DEV_EDITION
 sticky_pref("lightweightThemes.selectedThemeID", "firefox-compact-dark@mozilla.org");
 #else
 sticky_pref("lightweightThemes.selectedThemeID", "");
 #endif
 
 // Whether the character encoding menu is under the main Firefox button. This
--- a/browser/components/customizableui/CustomizableUI.jsm
+++ b/browser/components/customizableui/CustomizableUI.jsm
@@ -195,17 +195,17 @@ var CustomizableUIInternal = {
       "history-panelmenu",
       "fullscreen-button",
       "find-button",
       "preferences-button",
       "add-ons-button",
       "sync-button",
     ];
 
-    if (!AppConstants.MOZ_DEV_EDITION) {
+    if (!Services.prefs.getBoolPref("devtools.devedition")) {
       panelPlacements.splice(-1, 0, "developer-button");
     }
 
     if (AppConstants.E10S_TESTING_ONLY) {
       if (gPalette.has("e10s-button")) {
         let newWindowIndex = panelPlacements.indexOf("new-window-button");
         if (newWindowIndex > -1) {
           panelPlacements.splice(newWindowIndex + 1, 0, "e10s-button");
@@ -237,17 +237,17 @@ var CustomizableUIInternal = {
     let navbarPlacements = [
       "urlbar-container",
       "search-container",
       "bookmarks-menu-button",
       "downloads-button",
       "home-button",
     ];
 
-    if (AppConstants.MOZ_DEV_EDITION) {
+    if (Services.prefs.getBoolPref("devtools.devedition")) {
       navbarPlacements.splice(2, 0, "developer-button");
     }
 
     if (Services.prefs.getBoolPref(kPrefWebIDEInNavbar)) {
       navbarPlacements.push("webide-button");
     }
 
     // Place this last, when createWidget is called for pocket, it will
--- a/browser/components/customizableui/test/head.js
+++ b/browser/components/customizableui/test/head.js
@@ -110,17 +110,17 @@ function getToolboxCustomToolbarId(toolb
   return "__customToolbar_" + toolbarName.replace(" ", "_");
 }
 
 function resetCustomization() {
   return CustomizableUI.reset();
 }
 
 function isInDevEdition() {
-  return AppConstants.MOZ_DEV_EDITION;
+  return Services.prefs.getBoolPref("devtools.devedition");
 }
 
 function isInNightly() {
   return AppConstants.NIGHTLY_BUILD;
 }
 
 function removeNonReleaseButtons(areaPanelPlacements) {
   if (isInDevEdition() && areaPanelPlacements.includes("developer-button")) {
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -919,17 +919,17 @@ BrowserGlue.prototype = {
     SimpleServiceDiscovery.registerDevice(rokuDevice);
 
     // Search for devices continuously every 120 seconds
     SimpleServiceDiscovery.search(120 * 1000);
   },
 
   // All initial windows have opened.
   _onWindowsRestored: function BG__onWindowsRestored() {
-    if (AppConstants.MOZ_DEV_EDITION) {
+    if (Services.prefs.getBoolPref("devtools.devedition")) {
       this._createExtraDefaultProfile();
     }
 
     this._initServiceDiscovery();
 
     // Show update notification, if needed.
     if (Services.prefs.prefHasUserValue("app.update.postupdate"))
       this._showUpdateNotification();
@@ -1038,17 +1038,17 @@ BrowserGlue.prototype = {
         });
       }
     }
 
     E10SAccessibilityCheck.onWindowsRestored();
   },
 
   _createExtraDefaultProfile() {
-    if (!AppConstants.MOZ_DEV_EDITION) {
+    if (!Services.prefs.getBoolPref("devtools.devedition")) {
       return;
     }
     // If Developer Edition is the only installed Firefox version and no other
     // profiles are present, create a second one for use by other versions.
     // This helps Firefox versions earlier than 35 avoid accidentally using the
     // unsuitable Developer Edition profile.
     let profileService = Cc["@mozilla.org/toolkit/profile-service;1"]
                          .getService(Ci.nsIToolkitProfileService);
--- a/browser/components/preferences/in-content-old/main.js
+++ b/browser/components/preferences/in-content-old/main.js
@@ -13,17 +13,17 @@ Components.utils.import("resource:///mod
 XPCOMUtils.defineLazyModuleGetter(this, "OS",
                                   "resource://gre/modules/osfile.jsm");
 
 if (AppConstants.E10S_TESTING_ONLY) {
   XPCOMUtils.defineLazyModuleGetter(this, "UpdateUtils",
                                     "resource://gre/modules/UpdateUtils.jsm");
 }
 
-if (AppConstants.MOZ_DEV_EDITION) {
+if (Services.prefs.getBoolPref("devtools.devedition")) {
   XPCOMUtils.defineLazyModuleGetter(this, "fxAccounts",
                                     "resource://gre/modules/FxAccounts.jsm");
 }
 
 var gMainPane = {
   /**
    * Initialization of this.
    */
@@ -103,17 +103,20 @@ var gMainPane = {
         // The checkbox is checked if e10s is preffed on and enabled.
         e10sCheckbox.checked = Services.appinfo.browserTabsRemoteAutostart;
 
         // but if it's force disabled, then the checkbox is disabled.
         e10sCheckbox.disabled = !Services.appinfo.browserTabsRemoteAutostart;
       }
     }
 
-    if (AppConstants.MOZ_DEV_EDITION) {
+    if (Services.prefs.getBoolPref("devtools.devedition")) {
+      let vbox = document.getElementById("separateProfileBox");
+      vbox.hidden = false;
+
       let uAppData = OS.Constants.Path.userApplicationDataDir;
       let ignoreSeparateProfile = OS.Path.join(uAppData, "ignore-dev-edition-profile");
 
       setEventListener("separateProfileMode", "command", gMainPane.separateProfileModeChange);
       let separateProfileModeCheckbox = document.getElementById("separateProfileMode");
       setEventListener("getStarted", "click", gMainPane.onGetStarted);
 
       OS.File.stat(ignoreSeparateProfile).then(() => separateProfileModeCheckbox.checked = false,
@@ -159,17 +162,17 @@ var gMainPane = {
       }
 
       // Revert the checkbox in case we didn't quit
       e10sCheckbox.checked = e10sPref.value || e10sTempPref.value;
     }
   },
 
   separateProfileModeChange() {
-    if (AppConstants.MOZ_DEV_EDITION) {
+    if (Services.prefs.getBoolPref("devtools.devedition")) {
       function quitApp() {
         Services.startup.quit(Ci.nsIAppStartup.eAttemptQuit | Ci.nsIAppStartup.eRestartNotSameProfile);
       }
       function revertCheckbox(error) {
         separateProfileModeCheckbox.checked = !separateProfileModeCheckbox.checked;
         if (error) {
           Cu.reportError("Failed to toggle separate profile mode: " + error);
         }
@@ -208,17 +211,17 @@ var gMainPane = {
           return;
         case CONFIRM_RESTART_PROMPT_RESTART_LATER:
           createOrRemoveSpecialDevEditionFile();
       }
     }
   },
 
   onGetStarted(aEvent) {
-    if (AppConstants.MOZ_DEV_EDITION) {
+    if (Services.prefs.getBoolPref("devtools.devedition")) {
       const Cc = Components.classes, Ci = Components.interfaces;
       let wm = Cc["@mozilla.org/appshell/window-mediator;1"]
                   .getService(Ci.nsIWindowMediator);
       let win = wm.getMostRecentWindow("navigator:browser");
 
       fxAccounts.getSignedInUser().then(data => {
         if (win) {
           if (data) {
--- a/browser/components/preferences/in-content-old/main.xul
+++ b/browser/components/preferences/in-content-old/main.xul
@@ -119,29 +119,27 @@
 </hbox>
 
 <!-- Startup -->
 <groupbox id="startupGroup"
           data-category="paneGeneral"
           hidden="true">
   <caption><label>&startup.label;</label></caption>
 
-#ifdef MOZ_DEV_EDITION
-  <vbox id="separateProfileBox">
+  <vbox id="separateProfileBox" hidden="true">
     <checkbox id="separateProfileMode"
               label="&separateProfileMode.label;"/>
     <hbox align="center" class="indent">
       <label id="useFirefoxSync">&useFirefoxSync.label;</label>
       <deck id="getStarted">
         <label class="text-link">&getStarted.notloggedin.label;</label>
         <label class="text-link">&getStarted.configured.label;</label>
       </deck>
     </hbox>
   </vbox>
-#endif
 
 #ifdef E10S_TESTING_ONLY
   <checkbox id="e10sAutoStart"
             label="&e10sEnabled.label;"/>
 #endif
 
 #ifdef HAVE_SHELL_SERVICE
   <vbox id="defaultBrowserBox">
--- a/browser/components/preferences/in-content/main.js
+++ b/browser/components/preferences/in-content/main.js
@@ -17,17 +17,17 @@ XPCOMUtils.defineLazyModuleGetter(this, 
 if (AppConstants.E10S_TESTING_ONLY) {
   XPCOMUtils.defineLazyModuleGetter(this, "UpdateUtils",
                                     "resource://gre/modules/UpdateUtils.jsm");
 }
 
 XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
                                   "resource://gre/modules/PlacesUtils.jsm");
 
-if (AppConstants.MOZ_DEV_EDITION) {
+if (Services.prefs.getBoolPref("devtools.devedition")) {
   XPCOMUtils.defineLazyModuleGetter(this, "fxAccounts",
                                     "resource://gre/modules/FxAccounts.jsm");
 }
 
 const ENGINE_FLAVOR = "text/x-moz-search-engine";
 
 var gEngineView = null;
 
@@ -176,17 +176,20 @@ var gMainPane = {
         // The checkbox is checked if e10s is preffed on and enabled.
         e10sCheckbox.checked = Services.appinfo.browserTabsRemoteAutostart;
 
         // but if it's force disabled, then the checkbox is disabled.
         e10sCheckbox.disabled = !Services.appinfo.browserTabsRemoteAutostart;
       }
     }
 
-    if (AppConstants.MOZ_DEV_EDITION) {
+    if (Services.prefs.getBoolPref("devtools.devedition")) {
+      let vbox = document.getElementById("separateProfileBox");
+      vbox.hidden = false;
+
       let uAppData = OS.Constants.Path.userApplicationDataDir;
       let ignoreSeparateProfile = OS.Path.join(uAppData, "ignore-dev-edition-profile");
 
       setEventListener("separateProfileMode", "command", gMainPane.separateProfileModeChange);
       let separateProfileModeCheckbox = document.getElementById("separateProfileMode");
       setEventListener("getStarted", "click", gMainPane.onGetStarted);
 
       OS.File.stat(ignoreSeparateProfile).then(() => separateProfileModeCheckbox.checked = false,
@@ -233,17 +236,17 @@ var gMainPane = {
       }
 
       // Revert the checkbox in case we didn't quit
       e10sCheckbox.checked = e10sPref.value || e10sTempPref.value;
     }
   },
 
   separateProfileModeChange() {
-    if (AppConstants.MOZ_DEV_EDITION) {
+    if (Services.prefs.getBoolPref("devtools.devedition")) {
       function quitApp() {
         Services.startup.quit(Ci.nsIAppStartup.eAttemptQuit | Ci.nsIAppStartup.eRestartNotSameProfile);
       }
       function revertCheckbox(error) {
         separateProfileModeCheckbox.checked = !separateProfileModeCheckbox.checked;
         if (error) {
           Cu.reportError("Failed to toggle separate profile mode: " + error);
         }
@@ -282,17 +285,17 @@ var gMainPane = {
           return;
         case CONFIRM_RESTART_PROMPT_RESTART_LATER:
           createOrRemoveSpecialDevEditionFile();
       }
     }
   },
 
   onGetStarted(aEvent) {
-    if (AppConstants.MOZ_DEV_EDITION) {
+    if (Services.prefs.getBoolPref("devtools.devedition")) {
       const Cc = Components.classes, Ci = Components.interfaces;
       let wm = Cc["@mozilla.org/appshell/window-mediator;1"]
                   .getService(Ci.nsIWindowMediator);
       let win = wm.getMostRecentWindow("navigator:browser");
 
       fxAccounts.getSignedInUser().then(data => {
         if (win) {
           if (data) {
--- a/browser/components/preferences/in-content/main.xul
+++ b/browser/components/preferences/in-content/main.xul
@@ -207,29 +207,27 @@
 </hbox>
 
 <!-- Startup -->
 <groupbox id="startupGroup"
           data-category="paneGeneral"
           hidden="true">
   <caption><label>&startup.label;</label></caption>
 
-#ifdef MOZ_DEV_EDITION
-  <vbox id="separateProfileBox">
+  <vbox id="separateProfileBox" hidden="true">
     <checkbox id="separateProfileMode"
               label="&separateProfileMode.label;"/>
     <hbox align="center" class="indent">
       <label id="useFirefoxSync">&useFirefoxSync.label;</label>
       <deck id="getStarted">
         <label class="text-link">&getStarted.notloggedin.label;</label>
         <label class="text-link">&getStarted.configured.label;</label>
       </deck>
     </hbox>
   </vbox>
-#endif
 
 #ifdef E10S_TESTING_ONLY
   <checkbox id="e10sAutoStart"
             label="&e10sEnabled.label;"/>
 #endif
 
 #ifdef HAVE_SHELL_SERVICE
   <vbox id="defaultBrowserBox">
--- a/browser/modules/ProcessHangMonitor.jsm
+++ b/browser/modules/ProcessHangMonitor.jsm
@@ -299,17 +299,17 @@ var ProcessHangMonitor = {
       {
         label: bundle.getString("processHang.button_wait.label"),
         accessKey: bundle.getString("processHang.button_wait.accessKey"),
         callback() {
           ProcessHangMonitor.waitLonger(win);
         }
       }];
 
-    if (AppConstants.MOZ_DEV_EDITION && report.hangType == report.SLOW_SCRIPT) {
+    if (Services.prefs.getBoolPref("devtools.devedition") && report.hangType == report.SLOW_SCRIPT) {
       buttons.push({
         label: bundle.getString("processHang.button_debug.label"),
         accessKey: bundle.getString("processHang.button_debug.accessKey"),
         callback() {
           ProcessHangMonitor.debugScript(win);
         }
       });
     }
--- a/browser/modules/test/browser/browser_BrowserUITelemetry_defaults.js
+++ b/browser/modules/test/browser/browser_BrowserUITelemetry_defaults.js
@@ -6,25 +6,25 @@
 function test() {
   let s = {};
   Cu.import("resource:///modules/CustomizableUI.jsm", s);
   Cu.import("resource:///modules/BrowserUITelemetry.jsm", s);
 
   let { CustomizableUI, BrowserUITelemetry } = s;
 
   // Bug 1278176 - DevEdition never has the UI in a default state by default.
-  if (!AppConstants.MOZ_DEV_EDITION) {
+  if (!Services.prefs.getBoolPref("devtools.devedition")) {
     Assert.ok(CustomizableUI.inDefaultState,
               "No other test should have left CUI in a dirty state.");
   }
 
   let result = BrowserUITelemetry._getWindowMeasurements(window, 0);
 
   // Bug 1278176 - DevEdition always reports the developer-button is moved.
-  if (!AppConstants.MOZ_DEV_EDITION) {
+  if (!Services.prefs.getBoolPref("devtools.devedition")) {
     Assert.deepEqual(result.defaultMoved, []);
   }
   Assert.deepEqual(result.nondefaultAdded, []);
   // This one is a bit weird - the "social-share-button" is dynamically added
   // to the toolbar as the feature is first used - but it's listed as being in
   // the toolbar by default so it doesn't end up in nondefaultAdded once it
   // is created. The end result is that it ends up in defaultRemoved before
   // the feature has been activated.
--- a/devtools/client/framework/devtools-browser.js
+++ b/devtools/client/framework/devtools-browser.js
@@ -417,17 +417,17 @@ var gDevToolsBrowser = exports.gDevTools
       return;
     }
     CustomizableUI.createWidget({
       id: id,
       type: "view",
       viewId: "PanelUI-developer",
       shortcutId: "key_devToolboxMenuItem",
       tooltiptext: "developer-button.tooltiptext2",
-      defaultArea: AppConstants.MOZ_DEV_EDITION ?
+      defaultArea: Services.prefs.getBoolPref("devtools.devedition") ?
                      CustomizableUI.AREA_NAVBAR :
                      CustomizableUI.AREA_PANEL,
       onViewShowing: function (aEvent) {
         // Populate the subview with whatever menuitems are in the developer
         // menu. We skip menu elements, because the menu panel has no way
         // of dealing with those right now.
         let doc = aEvent.target.ownerDocument;
         let win = doc.defaultView;
--- a/devtools/client/inspector/webpack/prefs-loader.js
+++ b/devtools/client/inspector/webpack/prefs-loader.js
@@ -30,17 +30,16 @@ module.exports = function (content) {
   let isDevtools = this.request.endsWith("/devtools.js");
 
   // This maps the text of a "#if" to its truth value.  This has to
   // cover all uses of #if in devtools.js.
   const ifMap = {
     "#if MOZ_UPDATE_CHANNEL == beta": false,
     "#if defined(NIGHTLY_BUILD)": false,
     "#ifdef NIGHTLY_BUILD": false,
-    "#ifdef MOZ_DEV_EDITION": false,
     "#ifdef RELEASE_OR_BETA": true,
     "#ifdef RELEASE_BUILD": true,
   };
 
   let lines = content.split("\n");
   let ignoring = false;
   let newLines = [];
   let continuation = false;
--- a/toolkit/content/aboutSupport.js
+++ b/toolkit/content/aboutSupport.js
@@ -297,17 +297,17 @@ var snapshotFormatters = {
           $.new("td", String(val)),
         ]);
       });
       addRows("diagnostics", trs);
 
       delete data.info;
     }
 
-    if (AppConstants.NIGHTLY_BUILD || AppConstants.MOZ_DEV_EDITION) {
+    if (AppConstants.NIGHTLY_BUILD || Services.prefs.getBoolPref("devtools.devedition")) {
       let windowUtils = window.QueryInterface(Ci.nsIInterfaceRequestor)
                               .getInterface(Ci.nsIDOMWindowUtils);
       let gpuProcessPid = windowUtils.gpuProcessPid;
 
       if (gpuProcessPid != -1) {
         let gpuProcessKillButton = $.new("button");
 
         gpuProcessKillButton.addEventListener("click", function() {
--- a/toolkit/modules/AppConstants.jsm
+++ b/toolkit/modules/AppConstants.jsm
@@ -48,22 +48,21 @@ this.AppConstants = Object.freeze({
 
   MOZ_OFFICIAL_BRANDING:
 #ifdef MOZ_OFFICIAL_BRANDING
   true,
 #else
   false,
 #endif
 
-  MOZ_DEV_EDITION:
-#ifdef MOZ_DEV_EDITION
-  true,
-#else
-  false,
-#endif
+  // This is provided for compatibility, and should not be used in new
+  // code.  See bug 1354262.
+  get MOZ_DEV_EDITION() {
+    return Services.prefs.getBoolPref("devtools.devedition");
+  },
 
   MOZ_SERVICES_HEALTHREPORT:
 #ifdef MOZ_SERVICES_HEALTHREPORT
   true,
 #else
   false,
 #endif