From 9f72dfd5dc444d216818c26e69a54ba7e94d313a Mon Sep 17 00:00:00 2001 From: Bill McCloskey Date: Mon, 13 Apr 2015 15:37:20 -0700 Subject: [PATCH] Bug 1151598 - Remove more uses of preprocessor in toolkit (r=gavin) --- browser/base/content/browser.js | 1 - toolkit/modules/Services.jsm | 43 ++++--- toolkit/modules/UpdateChannel.jsm | 5 +- toolkit/modules/WindowsPrefSync.jsm | 173 ---------------------------- toolkit/modules/moz.build | 5 +- 5 files changed, 24 insertions(+), 203 deletions(-) delete mode 100644 toolkit/modules/WindowsPrefSync.jsm diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index e49269fbb97..5f97894ad79 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -10,7 +10,6 @@ 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", diff --git a/toolkit/modules/Services.jsm b/toolkit/modules/Services.jsm index 6f982d40812..b1adb53d3c3 100644 --- a/toolkit/modules/Services.jsm +++ b/toolkit/modules/Services.jsm @@ -8,6 +8,7 @@ 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 = {}; @@ -36,14 +37,14 @@ XPCOMUtils.defineLazyGetter(Services, "dirsvc", function () { .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"] @@ -58,9 +59,8 @@ XPCOMUtils.defineLazyGetter(Services, "ppmm", () => { }); 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"], @@ -78,14 +78,12 @@ let initTable = [ ["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"], @@ -102,14 +100,13 @@ let initTable = [ ["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; diff --git a/toolkit/modules/UpdateChannel.jsm b/toolkit/modules/UpdateChannel.jsm index c2bdce8ad5d..4dc74684441 100644 --- a/toolkit/modules/UpdateChannel.jsm +++ b/toolkit/modules/UpdateChannel.jsm @@ -1,5 +1,3 @@ -#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/. */ @@ -8,6 +6,7 @@ this.EXPORTED_SYMBOLS = ["UpdateChannel"]; const Cu = Components.utils; +Cu.import("resource://gre/modules/AppConstants.jsm"); Cu.import("resource://gre/modules/Services.jsm"); this.UpdateChannel = { @@ -20,7 +19,7 @@ this.UpdateChannel = { * 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"); diff --git a/toolkit/modules/WindowsPrefSync.jsm b/toolkit/modules/WindowsPrefSync.jsm deleted file mode 100644 index 6b200b3dc70..00000000000 --- 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 diff --git a/toolkit/modules/moz.build b/toolkit/modules/moz.build index 923bee92f4b..8112d5ce789 100644 --- a/toolkit/modules/moz.build +++ b/toolkit/modules/moz.build @@ -57,6 +57,7 @@ EXTRA_JS_MODULES += [ 'secondscreen/SimpleServiceDiscovery.jsm', 'SelectContentHelper.jsm', 'SelectParentHelper.jsm', + 'Services.jsm', 'sessionstore/FormData.jsm', 'sessionstore/ScrollPosition.jsm', 'sessionstore/XPathGenerator.jsm', @@ -68,6 +69,7 @@ EXTRA_JS_MODULES += [ 'TelemetryTimestamps.jsm', 'Timer.jsm', 'Troubleshoot.jsm', + 'UpdateChannel.jsm', 'WebChannel.jsm', 'WindowDraggingUtils.jsm', 'ZipUtils.jsm', @@ -75,10 +77,7 @@ EXTRA_JS_MODULES += [ EXTRA_PP_JS_MODULES += [ 'AppConstants.jsm', - 'Services.jsm', 'SessionRecorder.jsm', - 'UpdateChannel.jsm', - 'WindowsPrefSync.jsm', ] if 'Android' != CONFIG['OS_TARGET']: