Bug 1151598 - Remove more uses of preprocessor in toolkit (r=gavin)
authorBill McCloskey <billm@mozilla.com>
Mon, 13 Apr 2015 15:37:20 -0700
changeset 238929 5fdc7a8a42698c38e70ed8d9ed445b83d170b835
parent 238928 74b5bb9f1263bcd4b46e6b175165e70f67cf5d5c
child 238930 0511335a89fdad7bab8806a06512e5b05b38932a
push id58363
push userwmccloskey@mozilla.com
push dateTue, 14 Apr 2015 01:11:59 +0000
treeherdermozilla-inbound@5fdc7a8a4269 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgavin
bugs1151598
milestone40.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1151598 - Remove more uses of preprocessor in toolkit (r=gavin)
browser/base/content/browser.js
toolkit/modules/Services.jsm
toolkit/modules/UpdateChannel.jsm
toolkit/modules/WindowsPrefSync.jsm
toolkit/modules/moz.build
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -5,17 +5,16 @@
 
 let Ci = Components.interfaces;
 let Cu = Components.utils;
 let Cc = Components.classes;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/NotificationDB.jsm");
 Cu.import("resource:///modules/RecentWindow.jsm");
-Cu.import("resource://gre/modules/WindowsPrefSync.jsm");
 
 
 XPCOMUtils.defineLazyModuleGetter(this, "Preferences",
                                   "resource://gre/modules/Preferences.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Deprecated",
                                   "resource://gre/modules/Deprecated.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "BrowserUITelemetry",
                                   "resource:///modules/BrowserUITelemetry.jsm");
--- a/toolkit/modules/Services.jsm
+++ b/toolkit/modules/Services.jsm
@@ -3,16 +3,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 this.EXPORTED_SYMBOLS = ["Services"];
 
 const Ci = Components.interfaces;
 const Cc = Components.classes;
 const Cr = Components.results;
 
+Components.utils.import("resource://gre/modules/AppConstants.jsm");
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 this.Services = {};
 
 XPCOMUtils.defineLazyGetter(Services, "prefs", function () {
   return Cc["@mozilla.org/preferences-service;1"]
            .getService(Ci.nsIPrefService)
            .QueryInterface(Ci.nsIPrefBranch);
@@ -31,41 +32,40 @@ XPCOMUtils.defineLazyGetter(Services, "a
 });
 
 XPCOMUtils.defineLazyGetter(Services, "dirsvc", function () {
   return Cc["@mozilla.org/file/directory_service;1"]
            .getService(Ci.nsIDirectoryService)
            .QueryInterface(Ci.nsIProperties);
 });
 
-#ifdef MOZ_CRASHREPORTER
-XPCOMUtils.defineLazyGetter(Services, "crashmanager", () => {
-  let ns = {};
-  Components.utils.import("resource://gre/modules/CrashManager.jsm", ns);
+if (AppConstants.MOZ_CRASHREPORTER) {
+  XPCOMUtils.defineLazyGetter(Services, "crashmanager", () => {
+    let ns = {};
+    Components.utils.import("resource://gre/modules/CrashManager.jsm", ns);
 
-  return ns.CrashManager.Singleton;
-});
-#endif
+    return ns.CrashManager.Singleton;
+  });
+}
 
 XPCOMUtils.defineLazyGetter(Services, "mm", () => {
   return Cc["@mozilla.org/globalmessagemanager;1"]
            .getService(Ci.nsIMessageBroadcaster)
            .QueryInterface(Ci.nsIFrameScriptLoader);
 });
 
 XPCOMUtils.defineLazyGetter(Services, "ppmm", () => {
   return Cc["@mozilla.org/parentprocessmessagemanager;1"]
            .getService(Ci.nsIMessageBroadcaster)
            .QueryInterface(Ci.nsIProcessScriptLoader);
 });
 
 let initTable = [
-#ifdef MOZ_WIDGET_ANDROID
-  ["androidBridge", "@mozilla.org/android/bridge;1", "nsIAndroidBridge"],
-#endif
+  ["androidBridge", "@mozilla.org/android/bridge;1", "nsIAndroidBridge",
+   AppConstants.platform == "android"],
   ["appShell", "@mozilla.org/appshell/appShellService;1", "nsIAppShellService"],
   ["cache", "@mozilla.org/network/cache-service;1", "nsICacheService"],
   ["cache2", "@mozilla.org/netwerk/cache-storage-service;1", "nsICacheStorageService"],
   ["cpmm", "@mozilla.org/childprocessmessagemanager;1", "nsIMessageSender"],
   ["console", "@mozilla.org/consoleservice;1", "nsIConsoleService"],
   ["contentPrefs", "@mozilla.org/content-pref/service;1", "nsIContentPrefService"],
   ["cookies", "@mozilla.org/cookiemanager;1", "nsICookieManager2"],
   ["downloads", "@mozilla.org/download-manager;1", "nsIDownloadManager"],
@@ -73,43 +73,40 @@ let initTable = [
   ["els", "@mozilla.org/eventlistenerservice;1", "nsIEventListenerService"],
   ["eTLD", "@mozilla.org/network/effective-tld-service;1", "nsIEffectiveTLDService"],
   ["io", "@mozilla.org/network/io-service;1", "nsIIOService2"],
   ["locale", "@mozilla.org/intl/nslocaleservice;1", "nsILocaleService"],
   ["logins", "@mozilla.org/login-manager;1", "nsILoginManager"],
   ["obs", "@mozilla.org/observer-service;1", "nsIObserverService"],
   ["perms", "@mozilla.org/permissionmanager;1", "nsIPermissionManager"],
   ["prompt", "@mozilla.org/embedcomp/prompt-service;1", "nsIPromptService"],
-#ifdef MOZ_ENABLE_PROFILER_SPS
-  ["profiler", "@mozilla.org/tools/profiler;1", "nsIProfiler"],
-#endif
+  ["profiler", "@mozilla.org/tools/profiler;1", "nsIProfiler",
+   AppConstants.MOZ_ENABLE_PROFILER_SPS],
   ["scriptloader", "@mozilla.org/moz/jssubscript-loader;1", "mozIJSSubScriptLoader"],
   ["scriptSecurityManager", "@mozilla.org/scriptsecuritymanager;1", "nsIScriptSecurityManager"],
-#ifdef MOZ_TOOLKIT_SEARCH
-  ["search", "@mozilla.org/browser/search-service;1", "nsIBrowserSearchService"],
-#endif
+  ["search", "@mozilla.org/browser/search-service;1", "nsIBrowserSearchService",
+   AppConstants.MOZ_TOOLKIT_SEARCH],
   ["storage", "@mozilla.org/storage/service;1", "mozIStorageService"],
   ["domStorageManager", "@mozilla.org/dom/localStorage-manager;1", "nsIDOMStorageManager"],
   ["strings", "@mozilla.org/intl/stringbundle;1", "nsIStringBundleService"],
   ["telemetry", "@mozilla.org/base/telemetry;1", "nsITelemetry"],
   ["tm", "@mozilla.org/thread-manager;1", "nsIThreadManager"],
   ["urlFormatter", "@mozilla.org/toolkit/URLFormatterService;1", "nsIURLFormatter"],
   ["vc", "@mozilla.org/xpcom/version-comparator;1", "nsIVersionComparator"],
   ["wm", "@mozilla.org/appshell/window-mediator;1", "nsIWindowMediator"],
   ["ww", "@mozilla.org/embedcomp/window-watcher;1", "nsIWindowWatcher"],
   ["startup", "@mozilla.org/toolkit/app-startup;1", "nsIAppStartup"],
   ["sysinfo", "@mozilla.org/system-info;1", "nsIPropertyBag2"],
   ["clipboard", "@mozilla.org/widget/clipboard;1", "nsIClipboard"],
   ["DOMRequest", "@mozilla.org/dom/dom-request-service;1", "nsIDOMRequestService"],
   ["focus", "@mozilla.org/focus-manager;1", "nsIFocusManager"],
   ["uriFixup", "@mozilla.org/docshell/urifixup;1", "nsIURIFixup"],
   ["blocklist", "@mozilla.org/extensions/blocklist;1", "nsIBlocklistService"],
-#ifdef XP_WIN
-#ifdef MOZ_METRO
-  ["metro", "@mozilla.org/windows-metroutils;1", "nsIWinMetroUtils"],
-#endif
-#endif
 ];
 
-initTable.forEach(function ([name, contract, intf])
-  XPCOMUtils.defineLazyServiceGetter(Services, name, contract, intf));
+initTable.forEach(([name, contract, intf, enabled = true]) => {
+  if (enabled) {
+    XPCOMUtils.defineLazyServiceGetter(Services, name, contract, intf);
+  }
+});
+
 
 initTable = undefined;
--- a/toolkit/modules/UpdateChannel.jsm
+++ b/toolkit/modules/UpdateChannel.jsm
@@ -1,31 +1,30 @@
-#filter substitution
-
 /* 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/. */
 
 this.EXPORTED_SYMBOLS = ["UpdateChannel"];
 
 const Cu = Components.utils;
 
+Cu.import("resource://gre/modules/AppConstants.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 
 this.UpdateChannel = {
   /**
    * Read the update channel from defaults only.  We do this to ensure that
    * the channel is tightly coupled with the application and does not apply
    * to other instances of the application that may use the same profile.
    *
    * @param [optional] aIncludePartners
    *        Whether or not to include the partner bits. Default: true.
    */
   get: function UpdateChannel_get(aIncludePartners = true) {
-    let channel = "@MOZ_UPDATE_CHANNEL@";
+    let channel = AppConstants.MOZ_UPDATE_CHANNEL;
     let defaults = Services.prefs.getDefaultBranch(null);
     try {
       channel = defaults.getCharPref("app.update.channel");
     } catch (e) {
       // use default value when pref not found
     }
 
     if (aIncludePartners) {
deleted file mode 100644
--- a/toolkit/modules/WindowsPrefSync.jsm
+++ /dev/null
@@ -1,173 +0,0 @@
-/* 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/. */
-
-'use strict';
-
-this.EXPORTED_SYMBOLS = [];
-
-#ifdef XP_WIN
-#ifdef MOZ_METRO
-
-const {classes: Cc, interfaces: Ci, results: Cr, utils: Cu, manager: Cm} =
-  Components;
-const PREF_BASE_KEY = "Software\\Mozilla\\Firefox\\Metro\\Prefs\\";
-
-Cu.import("resource://gre/modules/XPCOMUtils.jsm");
-Cu.import("resource://gre/modules/Services.jsm");
-
-this.EXPORTED_SYMBOLS = [ "WindowsPrefSync" ];
-
-/**
- * Manages preferences that need to be pulled and pushed between Metro
- * and desktop.
- */
-this.WindowsPrefSync = {
-  init: function() {
-    this.pullSharedPrefs();
-    this.prefListToPush.forEach(function(prefName) {
-      this.pushSharedPref(prefName);
-      Services.prefs.addObserver(prefName, this, false);
-    }, this);
-  },
-
-  uninit: function() {
-    this.prefListToPush.forEach(function(prefName) {
-        Services.prefs.removeObserver(prefName, this);
-    }, this);
-  },
-
-  /**
-   * Returns the list of prefs that should be pushed for the current
-   * environment.
-   */
-  get prefListToPush() {
-    return !Services.metro.immersive ? this.desktopControlledPrefs :
-      this.metroControlledPrefs;
-  },
-
-  /**
-   * Returns the list of prefs that should be pulled for the current
-   * environment.
-   */
-  get prefListToPull() {
-    return Services.metro.immersive ? this.desktopControlledPrefs :
-      this.metroControlledPrefs;
-  },
-
-  /**
-   * The following preferences will be pushed to registry from Desktop
-   * Firefox and pulled in from Metro Firefox.
-   *
-   * app.update.* prefs are because Metro shares an installation directory with
-   * Firefox, and the options for these are only present in the Desktop options.
-   *
-   * browser.sessionstore.resume_session_once is mainly for the switch to Metro
-   * and switch to Desktop feature.
-   *
-   * browser.startup.page - if a desktop Firefox user wants her/his sessions
-   * to always restore, we need to honor that in metro Firefox as well.
-   */
-  desktopControlledPrefs: ["app.update.auto",
-    "app.update.enabled",
-    "app.update.service.enabled",
-    "app.update.metro.enabled",
-    "browser.sessionstore.resume_session_once",
-    "browser.startup.page"],
-
-  /**
-   * Returns the base path where registry sync prefs are stored.
-   */
-  get prefRegistryPath() {
-    let profileService = Cc["@mozilla.org/toolkit/profile-service;1"].
-      createInstance(Ci.nsIToolkitProfileService);
-    return PREF_BASE_KEY + profileService.selectedProfile.name + "\\";
-  },
-
-  /**
-   * The following preferences will be pushed to registry from Metro
-   * Firefox and pulled in from Desktop Firefox.
-   *
-   * browser.sessionstore.resume_session_once is mainly for the switch to Metro
-   * and switch to Desktop feature.
-   */
-  metroControlledPrefs: ["browser.sessionstore.resume_session_once"],
-
-  /**
-   * Observes preference changes and writes them to the registry, only
-   * the list of preferences initialized will be observed
-   */
-  observe: function (aSubject, aTopic, aPrefName) {
-    if (aTopic != "nsPref:changed")
-      return;
-
-    this.pushSharedPref(aPrefName);
-  },
-
-  /**
-   * Writes the pref to HKCU in the registry and adds a pref-observer to keep
-   * the registry in sync with changes to the value.
-   */
-  pushSharedPref : function(aPrefName) {
-    let registry = Cc["@mozilla.org/windows-registry-key;1"].
-      createInstance(Ci.nsIWindowsRegKey);
-    try {
-      var prefType = Services.prefs.getPrefType(aPrefName);
-      let prefFunc;
-      if (prefType == Ci.nsIPrefBranch.PREF_INT)
-        prefFunc = "getIntPref";
-      else if (prefType == Ci.nsIPrefBranch.PREF_BOOL)
-        prefFunc = "getBoolPref";
-      else if (prefType == Ci.nsIPrefBranch.PREF_STRING)
-        prefFunc = "getCharPref";
-      else
-        throw "Unsupported pref type";
-
-      let prefValue = Services.prefs[prefFunc](aPrefName);
-      registry.create(Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
-        this.prefRegistryPath + prefType, Ci.nsIWindowsRegKey.ACCESS_WRITE);
-      // Always write as string, but the registry subfolder will determine
-      // how Metro interprets that string value.
-      registry.writeStringValue(aPrefName, prefValue);
-    } catch (ex) {
-      Cu.reportError("Couldn't push pref " + aPrefName + ": " + ex);
-    } finally {
-      registry.close();
-    }
-  },
-
-  /**
-   * Pulls in all shared prefs from the registry
-   */
-  pullSharedPrefs: function() {
-    function pullSharedPrefType(prefType, prefFunc) {
-      try {
-        registry.create(Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
-          self.prefRegistryPath + prefType,
-          Ci.nsIWindowsRegKey.ACCESS_ALL);
-        for (let i = 0; i < registry.valueCount; i++) {
-          let prefName = registry.getValueName(i);
-          let prefValue = registry.readStringValue(prefName);
-          if (prefType == Ci.nsIPrefBranch.PREF_BOOL) {
-            prefValue = prefValue == "true";
-          }
-          if (self.prefListToPull.indexOf(prefName) != -1) {
-            Services.prefs[prefFunc](prefName, prefValue);
-          }
-        }
-      } catch (ex) {
-        dump("Could not pull for prefType " + prefType + ": " + ex + "\n");
-      } finally {
-        registry.close();
-      }
-    }
-    let self = this;
-    let registry = Cc["@mozilla.org/windows-registry-key;1"].
-      createInstance(Ci.nsIWindowsRegKey);
-    pullSharedPrefType(Ci.nsIPrefBranch.PREF_INT, "setIntPref");
-    pullSharedPrefType(Ci.nsIPrefBranch.PREF_BOOL, "setBoolPref");
-    pullSharedPrefType(Ci.nsIPrefBranch.PREF_STRING, "setCharPref");
-  }
-};
-#endif
-#endif
--- a/toolkit/modules/moz.build
+++ b/toolkit/modules/moz.build
@@ -52,38 +52,37 @@ EXTRA_JS_MODULES += [
     'RemoteSecurityUI.jsm',
     'RemoteWebNavigation.jsm',
     'RemoteWebProgress.jsm',
     'ResetProfile.jsm',
     'secondscreen/RokuApp.jsm',
     'secondscreen/SimpleServiceDiscovery.jsm',
     'SelectContentHelper.jsm',
     'SelectParentHelper.jsm',
+    'Services.jsm',
     'sessionstore/FormData.jsm',
     'sessionstore/ScrollPosition.jsm',
     'sessionstore/XPathGenerator.jsm',
     'ShortcutUtils.jsm',
     'Sntp.jsm',
     'SpatialNavigation.jsm',
     'Sqlite.jsm',
     'Task.jsm',
     'TelemetryTimestamps.jsm',
     'Timer.jsm',
     'Troubleshoot.jsm',
+    'UpdateChannel.jsm',
     'WebChannel.jsm',
     'WindowDraggingUtils.jsm',
     'ZipUtils.jsm',
 ]
 
 EXTRA_PP_JS_MODULES += [
     'AppConstants.jsm',
-    'Services.jsm',
     'SessionRecorder.jsm',
-    'UpdateChannel.jsm',
-    'WindowsPrefSync.jsm',
 ]
 
 if 'Android' != CONFIG['OS_TARGET']:
     EXTRA_JS_MODULES += [
         'LightweightThemeConsumer.jsm',
     ]
 else:
     DEFINES['ANDROID'] = True