Prevent mistaken overwriting of browser.newtab.url when using the browser preferences dialog

This commit is contained in:
JustOff 2019-03-26 01:27:46 +02:00 • committed by Roy Tam
commit 3b9e91ba75
2 changed files with 39 additions and 26 deletions

View file

@ -22,7 +22,11 @@ var gNewtabUrl = {
return;
}
} else {
newtabUrlChoice = Services.prefs.getIntPref("browser.newtab.choice");
if (this.newtabUrlChoiceIsSet) {
newtabUrlChoice = Services.prefs.getIntPref("browser.newtab.choice");
} else {
newtabUrlChoice = this.getNewtabChoice();
}
}
if (browserHomepageUrl || browserHomepageUrl == "") {
if (Services.prefs.getBoolPref("browser.preferences.instantApply")) {
@ -64,5 +68,35 @@ var gNewtabUrl = {
}
Services.prefs.setCharPref("browser.newtab.url",newtabUrlPref);
} catch(e) { console.error(e); }
},
/**
* Determines the value of browser.newtab.choice based
* on the value of browser.newtab.url
*
* @returns the value of browser.newtab.choice
*/
getNewtabChoice: function() {
let newtabUrlPref = Services.prefs.getCharPref("browser.newtab.url");
let browserHomepageUrl = Services.prefs.getComplexValue("browser.startup.homepage",
Components.interfaces.nsIPrefLocalizedString).data;
let newtabUrlSanitizedPref = browserHomepageUrl.split("|")[0];
let defaultStartupHomepage = Services.prefs.getDefaultBranch("browser.")
.getComplexValue("startup.homepage",
Components.interfaces.nsIPrefLocalizedString).data;
switch (newtabUrlPref) {
case "about:logopage":
return 1;
case defaultStartupHomepage:
return 2;
case newtabUrlSanitizedPref:
return 3;
case "about:newtab":
return 4;
default: // Custom URL entered.
// We need this to consider instantApply.
this.newtabPageCustom = newtabUrlPref;
return 0;
}
}
};