Bug 1117186 - fix geo-specific search defaults interaction with the defaultEngine getter/setter and use a helper for getting geo-specific prefs f=gavin,r=markh

This commit is contained in:
Mark Finkle 2015-01-21 23:05:48 -05:00
parent fd4f268ff5
commit 547f72f091

View File

@ -407,9 +407,8 @@ loadListener.prototype = {
onStatus: function (aRequest, aContext, aStatus, aStatusArg) {}
}
// Hacky method that tries to determine if this user is in a US geography, and
// using an en-US build.
function getIsUS() {
// Method to determine if we should be using geo-specific defaults
function geoSpecificDefaultsEnabled() {
let geoSpecificDefaults = false;
try {
geoSpecificDefaults = Services.prefs.getBoolPref("browser.search.geoSpecificDefaults");
@ -420,10 +419,12 @@ function getIsUS() {
distroID = Services.prefs.getCharPref("distribution.id");
} catch (e) {}
if (!geoSpecificDefaults || distroID) {
return false;
}
return (geoSpecificDefaults && !distroID);
}
// Hacky method that tries to determine if this user is in a US geography, and
// using an en-US build.
function getIsUS() {
// If we've set the pref before, just return that result.
let cachePref = "browser.search.isUS";
try {
@ -439,6 +440,15 @@ function getIsUS() {
return isNA;
}
// Helper method to modify preference keys with geo-specific modifiers, if needed
function getGeoSpecificPrefName(basepref) {
if (!geoSpecificDefaultsEnabled())
return basepref;
if (getIsUS())
return basepref + ".US";
return basepref;
}
function isUSTimezone() {
// Timezone assumptions! We assume that if the system clock's timezone is
// between Newfoundland and Hawaii, that the user is in North America.
@ -1963,10 +1973,7 @@ Engine.prototype = {
let defaultPrefB = Services.prefs.getDefaultBranch(BROWSER_SEARCH_PREF);
let nsIPLS = Ci.nsIPrefLocalizedString;
let defaultEngine;
let pref = "defaultenginename";
if (getIsUS()) {
pref += ".US";
}
let pref = getGeoSpecificPrefName("defaultenginename");
try {
defaultEngine = defaultPrefB.getComplexValue(pref, nsIPLS).data;
} catch (ex) {}
@ -3186,13 +3193,7 @@ SearchService.prototype = {
let nsIPLS = Ci.nsIPrefLocalizedString;
let defaultEngine;
let defPref;
if (getIsUS()) {
defPref = "defaultenginename.US";
} else {
defPref = "defaultenginename";
}
let defPref = getGeoSpecificPrefName("defaultenginename");
try {
defaultEngine = defaultPrefB.getComplexValue(defPref, nsIPLS).data;
} catch (ex) {
@ -3973,12 +3974,10 @@ SearchService.prototype = {
}
catch (e) { }
let prefNameBase = getGeoSpecificPrefName(BROWSER_SEARCH_PREF + "order");
while (true) {
prefName = BROWSER_SEARCH_PREF + "order.";
if (getIsUS()) {
prefName += "US.";
}
engineName = getLocalizedPref(prefName + (++i));
prefName = prefNameBase + "." + (++i);
engineName = getLocalizedPref(prefName);
if (!engineName)
break;
@ -4139,12 +4138,9 @@ SearchService.prototype = {
}
// Now look through the "browser.search.order" branch.
let prefNameBase = getGeoSpecificPrefName(BROWSER_SEARCH_PREF + "order");
for (var j = 1; ; j++) {
var prefName = BROWSER_SEARCH_PREF + "order.";
if (getIsUS()) {
prefName += "US.";
}
prefName += j;
let prefName = prefNameBase + "." + j;
engineName = getLocalizedPref(prefName);
if (!engineName)
break;
@ -4357,7 +4353,7 @@ SearchService.prototype = {
get defaultEngine() {
this._ensureInitialized();
if (!this._defaultEngine) {
let defPref = BROWSER_SEARCH_PREF + "defaultenginename";
let defPref = getGeoSpecificPrefName(BROWSER_SEARCH_PREF + "defaultenginename");
let defaultEngine = this.getEngineByName(getLocalizedPref(defPref, ""))
if (!defaultEngine)
defaultEngine = this._getSortedEngines(false)[0] || null;
@ -4385,7 +4381,8 @@ SearchService.prototype = {
this._defaultEngine = newDefaultEngine;
let defPref = BROWSER_SEARCH_PREF + "defaultenginename";
let defPref = getGeoSpecificPrefName(BROWSER_SEARCH_PREF + "defaultenginename");
// If we change the default engine in the future, that change should impact
// users who have switched away from and then back to the build's "default"
// engine. So clear the user pref when the defaultEngine is set to the