mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-13 13:25:37 +00:00
Bug 1151598 - Remove more uses of preprocessor in toolkit (r=gavin)
This commit is contained in:
parent
79abd6e01a
commit
b38d8dad98
@ -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",
|
||||
|
@ -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;
|
||||
|
@ -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");
|
||||
|
@ -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
|
@ -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']:
|
||||
|
Loading…
Reference in New Issue
Block a user