Bug 1505331 - Port bug 1458308 to TB: (update-prefs) Move update prefs out of profile. r=jorgk,mkmelin

This commit is contained in:
aceman 2018-11-10 09:53:00 +13:00
Родитель f3f4983f21
Коммит 943ba91d2b
5 изменённых файлов: 156 добавлений и 73 удалений

Просмотреть файл

@ -75,9 +75,15 @@ pref("app.update.certs.2.issuerName", "CN=thawte SSL CA - G2,O=\"thawte, Inc.\",
pref("app.update.certs.2.commonName", "aus5.mozilla.org");
// If set to true, the Update Service will automatically download updates when
// app updates are enabled per the app.update.enabled preference and if the user
// can apply updates.
pref("app.update.auto", true);
// user can apply updates. This pref is no longer used on Windows, except as the
// default value to migrate to the new location that this data is now stored
// (which is in a file in the update directory). Because of this, this pref
// should no longer be used directly. Instead,
// nsIUpdateService::getAutoUpdateIsEnabled and
// nsIUpdateService::setAutoUpdateIsEnabled should be used.
#ifndef XP_WIN
pref("app.update.auto", true);
#endif
// If set to true, the Update Service will present no UI for any event.
pref("app.update.silent", false);

Просмотреть файл

@ -25,6 +25,7 @@ function onUnload(aEvent) {
function appUpdater()
{
this.updateDeck = document.getElementById("updateDeck");
this.promiseAutoUpdateSetting = null;
// Hide the update deck when there is already an update window open to avoid
// syncing issues between them.
@ -73,6 +74,9 @@ function appUpdater()
return;
}
// We might need this value later, so start loading it from the disk now.
this.promiseAutoUpdateSetting = this.aus.getAutoUpdateIsEnabled();
// That leaves the options
// "Check for updates, but let me choose whether to install them", and
// "Automatically install updates".
@ -130,15 +134,6 @@ appUpdater.prototype =
gAppUpdater.aus.canStageUpdates;
},
// true when updating is automatic.
get updateAuto() {
try {
return Services.prefs.getBoolPref("app.update.auto");
}
catch (e) { }
return true; // Thunderbird default is true
},
/**
* Sets the panel of the updateDeck.
*
@ -256,10 +251,16 @@ appUpdater.prototype =
return;
}
if (gAppUpdater.updateAuto) // automatically download and install
gAppUpdater.startDownload();
else // ask
gAppUpdater.selectPanel("downloadAndInstall");
if (this.promiseAutoUpdateSetting == null) {
this.promiseAutoUpdateSetting = this.aus.getAutoUpdateIsEnabled();
}
this.promiseAutoUpdateSetting.then(updateAuto => {
if (updateAuto) { // automatically download and install
gAppUpdater.startDownload();
} else { // ask
gAppUpdater.selectPanel("downloadAndInstall");
}
});
},
/**

Просмотреть файл

@ -79,9 +79,6 @@
type="bool"/>
#ifdef MOZ_UPDATER
<!-- Update tab -->
<preference id="app.update.auto"
name="app.update.auto"
type="bool"/>
<preference id="app.update.disable_button.showUpdateHistory"
name="app.update.disable_button.showUpdateHistory"
type="bool"/>
@ -473,12 +470,13 @@
</vbox>
<separator/>
<radiogroup id="updateRadioGroup"
align="start"
oncommand="gAdvancedPane.updateWritePrefs();">
<radio value="auto"
align="start">
<radio id="autoDesktop"
value="true"
label="&updateAuto.label;"
accesskey="&updateAuto.accesskey;"/>
<radio value="checkOnly"
<radio id="manualDesktop"
value="false"
label="&updateCheck.label;"
accesskey="&updateCheck.accesskey;"/>
</radiogroup>

Просмотреть файл

@ -14,6 +14,12 @@ ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.import("resource://gre/modules/L10nRegistry.jsm");
ChromeUtils.import("resource://gre/modules/Localization.jsm");
XPCOMUtils.defineLazyServiceGetters(this, {
gAUS: ["@mozilla.org/updates/update-service;1", "nsIApplicationUpdateService"],
});
const AUTO_UPDATE_CHANGED_TOPIC = "auto-update-config-change";
var gAdvancedPane = {
mPane: null,
mInitialized: false,
@ -22,6 +28,11 @@ var gAdvancedPane = {
requestingLocales: null,
init() {
function setEventListener(aId, aEventType, aCallback) {
document.getElementById(aId)
.addEventListener(aEventType, aCallback.bind(gAdvancedPane));
}
this.mPane = document.getElementById("paneAdvanced");
this.updateCompactOptions();
this.mBundle = document.getElementById("bundlePreferences");
@ -90,6 +101,23 @@ var gAdvancedPane = {
}
if (AppConstants.MOZ_UPDATER) {
gAppUpdater = new appUpdater(); // eslint-disable-line no-global-assign
if (Services.policies && !Services.policies.isAllowed("appUpdate")) {
document.getElementById("updateAllowDescription").hidden = true;
document.getElementById("updateRadioGroup").hidden = true;
if (AppConstants.MOZ_MAINTENANCE_SERVICE) {
document.getElementById("useService").hidden = true;
}
} else {
// Start with no option selected since we are still reading the value
document.getElementById("autoDesktop").removeAttribute("selected");
document.getElementById("manualDesktop").removeAttribute("selected");
// Start reading the correct value from the disk
this.updateReadPrefs();
setEventListener("updateRadioGroup", "command",
gAdvancedPane.updateWritePrefs);
}
let distroId = Services.prefs.getCharPref("distribution.id", "");
if (distroId) {
let distroVersion = Services.prefs.getCharPref("distribution.version");
@ -106,6 +134,25 @@ var gAdvancedPane = {
}
}
if (AppConstants.MOZ_MAINTENANCE_SERVICE) {
// Check to see if the maintenance service is installed.
// If it isn't installed, don't show the preference at all.
let installed;
try {
let wrk = Cc["@mozilla.org/windows-registry-key;1"]
.createInstance(Ci.nsIWindowsRegKey);
wrk.open(wrk.ROOT_KEY_LOCAL_MACHINE,
"SOFTWARE\\Mozilla\\MaintenanceService",
wrk.ACCESS_READ | wrk.WOW64_64);
installed = wrk.readIntValue("Installed");
wrk.close();
} catch (e) {
}
if (installed != 1) {
document.getElementById("useService").hidden = true;
}
}
let version = AppConstants.MOZ_APP_VERSION_DISPLAY;
// Include the build ID and display warning if this is an "a#" (nightly) build
@ -139,8 +186,13 @@ var gAdvancedPane = {
}
}
}
// Initialize Application section.
// Listen for window unload so we can remove our preference observers.
window.addEventListener("unload", this);
Services.obs.addObserver(this, AUTO_UPDATE_CHANGED_TOPIC);
gAppUpdater = new appUpdater(); // eslint-disable-line no-global-assign
}
this.mInitialized = true;
@ -262,66 +314,56 @@ var gAdvancedPane = {
},
/**
* Selects the item of the radiogroup based on the pref values and locked
* states.
*
* UI state matrix for update preference conditions
*
* UI Components: Preferences
* Radiogroup i = app.update.auto
* Selects the correct item in the update radio group
*/
updateReadPrefs() {
let autoPref = document.getElementById("app.update.auto");
let radiogroup = document.getElementById("updateRadioGroup");
if (autoPref.value)
radiogroup.value = "auto"; // Automatically install updates
else
radiogroup.value = "checkOnly"; // Check, but let me choose
let canCheck = Cc["@mozilla.org/updates/update-service;1"].
getService(Ci.nsIApplicationUpdateService).
canCheckForUpdates;
// canCheck is false if the binary platform or OS version is not known.
// A locked pref is sufficient to disable the radiogroup.
radiogroup.disabled = !canCheck || autoPref.locked;
if (AppConstants.MOZ_MAINTENANCE_SERVICE) {
// Check to see if the maintenance service is installed.
// If it is don't show the preference at all.
let installed;
async updateReadPrefs() {
if (AppConstants.MOZ_UPDATER &&
(!Services.policies || Services.policies.isAllowed("appUpdate"))) {
let radiogroup = document.getElementById("updateRadioGroup");
radiogroup.disabled = true;
try {
let wrk = Cc["@mozilla.org/windows-registry-key;1"]
.createInstance(Ci.nsIWindowsRegKey);
wrk.open(wrk.ROOT_KEY_LOCAL_MACHINE,
"SOFTWARE\\Mozilla\\MaintenanceService",
wrk.ACCESS_READ | wrk.WOW64_64);
installed = wrk.readIntValue("Installed");
wrk.close();
} catch (e) { }
if (installed != 1) {
document.getElementById("useService").hidden = true;
let enabled = await gAUS.getAutoUpdateIsEnabled();
radiogroup.value = enabled;
radiogroup.disabled = false;
} catch (error) {
Cu.reportError(error);
}
}
},
/**
* Sets the pref values based on the selected item of the radiogroup.
* Writes the value of the update radio group to the disk
*/
updateWritePrefs() {
let autoPref = document.getElementById("app.update.auto");
let radiogroup = document.getElementById("updateRadioGroup");
switch (radiogroup.value) {
case "auto": // Automatically install updates
autoPref.value = true;
break;
case "checkOnly": // Check, but but let me choose
autoPref.value = false;
break;
async updateWritePrefs() {
if (AppConstants.MOZ_UPDATER &&
(!Services.policies || Services.policies.isAllowed("appUpdate"))) {
let radiogroup = document.getElementById("updateRadioGroup");
let updateAutoValue = (radiogroup.value == "true");
radiogroup.disabled = true;
try {
await gAUS.setAutoUpdateIsEnabled(updateAutoValue);
radiogroup.disabled = false;
} catch (error) {
Cu.reportError(error);
await this.updateReadPrefs();
await this.reportUpdatePrefWriteError(error);
}
}
},
async reportUpdatePrefWriteError(error) {
let [title, message] = await document.l10n.formatValues([
{id: "update-pref-write-failure-title"},
{id: "update-pref-write-failure-message", args: {path: error.path}},
]);
// Set up the Ok Button
let buttonFlags = (Services.prompt.BUTTON_POS_0 *
Services.prompt.BUTTON_TITLE_OK);
Services.prompt.confirmEx(window, title, message, buttonFlags,
null, null, null, null, {});
},
showUpdates() {
gSubDialog.open("chrome://mozapps/content/update/history.xul");
},
@ -602,4 +644,34 @@ var gAdvancedPane = {
]).values());
this.showConfirmLanguageChangeMessageBar(locales);
},
destroy() {
window.removeEventListener("unload", this);
Services.obs.removeObserver(this, AUTO_UPDATE_CHANGED_TOPIC);
},
// nsISupports
QueryInterface: ChromeUtils.generateQI([Ci.nsIObserver]),
// nsIObserver
async observe(aSubject, aTopic, aData) {
if (aTopic == AUTO_UPDATE_CHANGED_TOPIC) {
if (aData != "true" && aData != "false") {
throw new Error("Invalid preference value for app.update.auto");
}
document.getElementById("updateRadioGroup").value = aData;
}
},
// EventListener
handleEvent(aEvent) {
if (aEvent.type == "unload") {
this.destroy();
}
},
};

Просмотреть файл

@ -8,3 +8,9 @@ manage-messenger-languages-button =
.accesskey = l
confirm-messenger-language-change-description = Restart { -brand-short-name } to apply these changes
confirm-messenger-language-change-button = Apply and Restart
update-pref-write-failure-title = Write Failure
# Variables:
# $path (String) - Path to the configuration file
update-pref-write-failure-message = Unable to save preference. Could not write to file: { $path }