Bug 861322 - Make Metro read Desktop app.update.mode setting. r=jimm

This commit is contained in:
Brian R. Bondy 2013-05-22 10:17:05 -04:00
parent 88be8a4661
commit ac27a79840
2 changed files with 105 additions and 0 deletions

View File

@ -1278,6 +1278,15 @@ var gBrowserInit = {
Services.obs.notifyObservers(window, "browser-delayed-startup-finished", "");
setTimeout(function () { BrowserChromeTest.markAsReady(); }, 0);
TelemetryTimestamps.add("delayedStartupFinished");
#ifdef XP_WIN
#ifdef MOZ_METRO
gMetroPrefs.prefDomain.forEach(function(prefName) {
gMetroPrefs.pushDesktopControlledPrefToMetro(prefName);
Services.prefs.addObserver(prefName, gMetroPrefs, false);
}, this);
#endif
#endif
},
onUnload: function() {
@ -1356,6 +1365,14 @@ var gBrowserInit = {
Cu.reportError(ex);
}
#ifdef XP_WIN
#ifdef MOZ_METRO
gMetroPrefs.prefDomain.forEach(function(prefName) {
Services.prefs.removeObserver(prefName, gMetroPrefs);
});
#endif
#endif
BrowserOffline.uninit();
OfflineApps.uninit();
IndexedDBPromptHelper.uninit();
@ -1513,6 +1530,7 @@ var gBrowserInit = {
},
}
/* Legacy global init functions */
var BrowserStartup = gBrowserInit.onLoad.bind(gBrowserInit);
var BrowserShutdown = gBrowserInit.onUnload.bind(gBrowserInit);
@ -4831,6 +4849,60 @@ function fireSidebarFocusedEvent() {
sidebar.contentWindow.dispatchEvent(event);
}
#ifdef XP_WIN
#ifdef MOZ_METRO
/**
* Some prefs that have consequences in both Metro and Desktop such as
* app-update prefs, are automatically pushed from Desktop here for use
* in Metro.
*/
var gMetroPrefs = {
prefDomain: ["app.update.auto", "app.update.enabled",
"app.update.service.enabled"],
observe: function (aSubject, aTopic, aPrefName)
{
if (aTopic != "nsPref:changed")
return;
this.pushDesktopControlledPrefToMetro(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.
*/
pushDesktopControlledPrefToMetro: 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 == Components.interfaces.nsIPrefBranch.PREF_INT)
prefFunc = "getIntPref";
else if (prefType == Components.interfaces.nsIPrefBranch.PREF_BOOL)
prefFunc = "getBoolPref";
else if (prefType == Components.interfaces.nsIPrefBranch.PREF_STRING)
prefFunc = "getCharPref";
else
throw "Unsupported pref type";
let prefValue = Services.prefs[prefFunc](aPrefName);
registry.create(Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
"Software\\Mozilla\\Firefox\\Metro\\Prefs\\" + 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) {
Components.utils.reportError("Couldn't push pref " + aPrefName + ": " + ex);
} finally {
registry.close();
}
}
};
#endif
#endif
var gHomeButton = {
prefDomain: "browser.startup.homepage",
observe: function (aSubject, aTopic, aPrefName)

View File

@ -154,6 +154,8 @@ var BrowserUI = {
Util.dumpLn("Exception in delay load module:", ex.message);
}
BrowserUI._pullDesktopControlledPrefs();
// check for left over crash reports and submit them if found.
if (BrowserUI.startupCrashCheck()) {
Browser.selectedTab = BrowserUI.newOrSelectTab("about:crash");
@ -244,6 +246,37 @@ var BrowserUI = {
return uri.spec;
},
/**
* Some prefs that have consequences in both Metro and Desktop such as
* app-update prefs, are automatically pulled from Desktop here.
*/
_pullDesktopControlledPrefs: function() {
function pullDesktopControlledPrefType(prefType, prefFunc) {
try {
registry.create(Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
"Software\\Mozilla\\Firefox\\Metro\\Prefs\\" + 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";
}
Services.prefs[prefFunc](prefName, prefValue);
}
} catch (ex) {
Util.dumpLn("Could not pull for prefType " + prefType + ": " + ex);
} finally {
registry.close();
}
}
let registry = Cc["@mozilla.org/windows-registry-key;1"].
createInstance(Ci.nsIWindowsRegKey);
pullDesktopControlledPrefType(Ci.nsIPrefBranch.PREF_INT, "setIntPref");
pullDesktopControlledPrefType(Ci.nsIPrefBranch.PREF_BOOL, "setBoolPref");
pullDesktopControlledPrefType(Ci.nsIPrefBranch.PREF_STRING, "setCharPref");
},
/* Set the location to the current content */
updateURI: function(aOptions) {
aOptions = aOptions || {};