Bug 1432263 - Make matchBuckets string parsing the same everywhere it's done. r=mak

MozReview-Commit-ID: GmGCHl4RtWB

--HG--
extra : rebase_source : 97f8b643be9431b994fc4dca03b243a664ed56ba
This commit is contained in:
Drew Willcoxon 2018-01-22 11:21:55 -08:00
Родитель c8137ec252
Коммит 86cfc3f0ce
3 изменённых файлов: 26 добавлений и 14 удалений

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

@ -88,9 +88,8 @@ var gSearchPane = {
}
// The pref has a value. If the first bucket in the pref is search
// suggestions, then check the checkbox.
let bucketPair = pref.value.split(",")[0];
let bucketName = bucketPair.split(":")[0];
checkbox.checked = bucketName == "suggestion";
let buckets = PlacesUtils.convertMatchBucketsStringToArray(pref.value);
checkbox.checked = buckets[0] && buckets[0][0] == "suggestion";
},
_syncToShowSearchSuggestionsFirstPref(checked, pref) {

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

@ -423,6 +423,27 @@ this.PlacesUtils = {
return "moz-action:" + type + "," + JSON.stringify(encodedParams);
},
/**
* Parses matchBuckets strings (for example, "suggestion:4,general:Infinity")
* like those used in the browser.urlbar.matchBuckets preference.
*
* @param str
* A matchBuckets string.
* @returns An array of the form: [
* [bucketName_0, bucketPriority_0],
* [bucketName_1, bucketPriority_1],
* ...
* [bucketName_n, bucketPriority_n]
* ]
*/
convertMatchBucketsStringToArray(str) {
return str.split(",")
.map(v => {
let bucket = v.split(":");
return [ bucket[0].trim().toLowerCase(), Number(bucket[1]) ];
});
},
/**
* Determines whether or not a ResultNode is a Bookmark folder.
* @param aNode

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

@ -339,14 +339,6 @@ function setTimeout(callback, ms) {
return timer;
}
function convertBucketsCharPrefToArray(str) {
return str.split(",")
.map(v => {
let bucket = v.split(":");
return [ bucket[0].trim().toLowerCase(), Number(bucket[1]) ];
});
}
/**
* Storage object for switch-to-tab entries.
* This takes care of caching and registering open pages, that will be reused
@ -488,9 +480,9 @@ XPCOMUtils.defineLazyGetter(this, "Prefs", () => {
// Convert from pref char format to an array and add the default buckets.
let val = readPref(pref);
try {
val = convertBucketsCharPrefToArray(val);
val = PlacesUtils.convertMatchBucketsStringToArray(val);
} catch (ex) {
val = convertBucketsCharPrefToArray(PREF_URLBAR_DEFAULTS.get(pref));
val = PlacesUtils.convertMatchBucketsStringToArray(PREF_URLBAR_DEFAULTS.get(pref));
}
return [ ...DEFAULT_BUCKETS_BEFORE,
...val,
@ -502,7 +494,7 @@ XPCOMUtils.defineLazyGetter(this, "Prefs", () => {
if (val) {
// Convert from pref char format to an array and add the default buckets.
try {
val = convertBucketsCharPrefToArray(val);
val = PlacesUtils.convertMatchBucketsStringToArray(val);
return [ ...DEFAULT_BUCKETS_BEFORE,
...val,
...DEFAULT_BUCKETS_AFTER ];