Bug 1461345 - Move browser.search.order to list.json. r=adw

MozReview-Commit-ID: 1ulgkNgkAP9

--HG--
extra : rebase_source : 16c469f449a4684c6f43dd2cc82d2288b9fd2a34
This commit is contained in:
Michael Kaply 2018-05-21 14:27:06 -05:00
parent 60d982d254
commit a97758663a
11 changed files with 81 additions and 32 deletions

View File

@ -381,19 +381,10 @@ pref("browser.helperApps.deleteTempFileOnExit", true);
// search engines URL
pref("browser.search.searchEnginesURL", "https://addons.mozilla.org/%LOCALE%/firefox/search-engines/");
// Ordering of Search Engines in the Engine list.
pref("browser.search.order.1", "chrome://browser-region/locale/region.properties");
pref("browser.search.order.2", "chrome://browser-region/locale/region.properties");
pref("browser.search.order.3", "chrome://browser-region/locale/region.properties");
// Market-specific search defaults
pref("browser.search.geoSpecificDefaults", true);
pref("browser.search.geoSpecificDefaults.url", "https://search.services.mozilla.com/1/%APP%/%VERSION%/%CHANNEL%/%LOCALE%/%REGION%/%DISTRIBUTION%/%DISTRIBUTION_VERSION%");
// US specific default
pref("browser.search.order.US.1", "data:text/plain,browser.search.order.US.1=Google");
pref("browser.search.order.US.2", "data:text/plain,browser.search.order.US.2=Bing");
// search bar results always open in a new tab
pref("browser.search.openintab", false);

View File

@ -2,10 +2,6 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# Search engine order (order displayed in the search bar dropdown)s
browser.search.order.1=Google
browser.search.order.2=Bing
# This is the default set of web based feed handlers shown in the reader
# selection UI
browser.contentHandlers.types.0.title=My Yahoo!

View File

@ -1,6 +1,7 @@
{
"default": {
"searchDefault": "Google",
"searchOrder": ["Google", "Bing"],
"visibleDefaultEngines": [
"google", "amazondotcom", "bing", "ddg", "ebay", "twitter", "wikipedia"
]
@ -180,6 +181,7 @@
},
"cs": {
"default": {
"searchOrder": ["Google", "Seznam"],
"visibleDefaultEngines": [
"google", "seznam-cz", "ddg", "heureka-cz", "mapy-cz", "wikipedia-cz"
]
@ -447,6 +449,7 @@
},
"ja-JP-mac": {
"default": {
"searchOrder": ["Google", "Yahoo! JAPAN", "Bing", "Amazon.co.jp", "楽天市場", "ヤフオク!", "教えてgoo", "Twitter", "Wikipedia (ja)"],
"visibleDefaultEngines": [
"google", "yahoo-jp", "bing", "amazon-jp", "rakuten", "yahoo-jp-auctions", "oshiete-goo", "twitter-ja", "wikipedia-ja", "ddg"
]
@ -454,6 +457,7 @@
},
"ja": {
"default": {
"searchOrder": ["Google", "Yahoo! JAPAN", "Bing", "Amazon.co.jp", "楽天市場", "ヤフオク!", "教えてgoo", "Twitter", "Wikipedia (ja)"],
"visibleDefaultEngines": [
"google", "yahoo-jp", "bing", "amazon-jp", "rakuten", "yahoo-jp-auctions", "oshiete-goo", "twitter-ja", "wikipedia-ja", "ddg"
]

View File

@ -257,20 +257,10 @@ pref("browser.menu.showCharacterEncoding", "chrome://browser/locale/browser.prop
pref("browser.ssl_override_behavior", 2);
pref("browser.xul.error_pages.expert_bad_cert", false);
// ordering of search engines in the engine list.
pref("browser.search.order.1", "chrome://browser/locale/region.properties");
pref("browser.search.order.2", "chrome://browser/locale/region.properties");
pref("browser.search.order.3", "chrome://browser/locale/region.properties");
// Market-specific search defaults
pref("browser.search.geoSpecificDefaults", true);
pref("browser.search.geoSpecificDefaults.url", "https://search.services.mozilla.com/1/%APP%/%VERSION%/%CHANNEL%/%LOCALE%/%REGION%/%DISTRIBUTION%/%DISTRIBUTION_VERSION%");
// Allow for unique order in the US.
pref("browser.search.order.US.1", "chrome://browser/locale/region.properties");
pref("browser.search.order.US.2", "chrome://browser/locale/region.properties");
pref("browser.search.order.US.3", "chrome://browser/locale/region.properties");
// disable updating
pref("browser.search.update", false);

View File

@ -5,15 +5,6 @@
# This preference is only used to generate browsersearch.json.
browser.search.defaultenginename=Google
# Search engine order (order displayed in the search bar dropdown).
browser.search.order.1=Google
browser.search.order.2=Bing
# These override the equivalents above when the client detects that it is in
# US market only.
browser.search.order.US.1=Google
browser.search.order.US.2=Bing
# increment this number when anything gets changed in the list below. This will
# cause Firefox to re-read these prefs and inject any new handlers into the
# profile database. Note that "new" is defined as "has a different URL"; this

View File

@ -1,6 +1,7 @@
{
"default": {
"searchDefault": "Google",
"searchOrder": ["Google", "Bing"],
"visibleDefaultEngines": [
"google", "bing", "amazondotcom", "ddg", "twitter", "wikipedia"
]

View File

@ -36,6 +36,12 @@ validateDefault("visibleDefaultEngines");
if not "searchDefault" in localeSearchInfo["default"]:
localeSearchInfo["default"]["searchDefault"] = searchinfo["default"]["searchDefault"]
# If the selected locale doesn't have a searchOrder,
# use the global one if present.
# searchOrder is NOT required.
if not "searchOrder" in localeSearchInfo["default"] and "searchOrder" in searchinfo["default"]:
localeSearchInfo["default"]["searchOrder"] = searchinfo["default"]["searchOrder"]
# If we have region overrides, enumerate through them
# and add the additional regions to the locale information.
if "regionOverrides" in searchinfo:

View File

@ -2740,6 +2740,7 @@ SearchService.prototype = {
__sortedEngines: null,
_visibleDefaultEngines: [],
_searchDefault: null,
_searchOrder: [],
get _sortedEngines() {
if (!this.__sortedEngines)
return this._buildSortedEngineList();
@ -2983,6 +2984,7 @@ SearchService.prototype = {
this._currentEngine = null;
this._visibleDefaultEngines = [];
this._searchDefault = null;
this._searchOrder = [];
this._metaData = {};
this._cacheFileJSON = null;
@ -3499,6 +3501,13 @@ SearchService.prototype = {
} else {
this._searchDefault = searchSettings.default.searchDefault;
}
if (searchRegion && searchRegion in searchSettings &&
"searchOrder" in searchSettings[searchRegion]) {
this._searchOrder = searchSettings[searchRegion].searchOrder;
} else if ("searchOrder" in searchSettings.default) {
this._searchOrder = searchSettings.default.searchOrder;
}
},
_parseListTxt: function SRCH_SVC_parseListTxt(list, uris) {
@ -3616,6 +3625,12 @@ SearchService.prototype = {
var engineName;
var prefName;
// The original default engine should always be first in the list
if (this.originalDefaultEngine) {
this.__sortedEngines.push(this.originalDefaultEngine);
addedEngines[this.originalDefaultEngine.name] = this.originalDefaultEngine;
}
try {
var extras =
Services.prefs.getChildList(BROWSER_SEARCH_PREF + "order.extra.");
@ -3646,6 +3661,15 @@ SearchService.prototype = {
this.__sortedEngines.push(engine);
addedEngines[engine.name] = engine;
}
for (let engineName of this._searchOrder) {
engine = this._engines[engineName];
if (!engine || engine.name in addedEngines)
continue;
this.__sortedEngines.push(engine);
addedEngines[engine.name] = engine;
}
}
// Array for the remaining engines, alphabetically sorted.
@ -3781,6 +3805,11 @@ SearchService.prototype = {
engineOrder[engineName] = i++;
}
// Now look at list.json
for (let engineName of this._searchOrder) {
engineOrder[engineName] = i++;
}
LOG("getDefaultEngines: engineOrder: " + engineOrder.toSource());
function compareEngines(a, b) {
@ -4181,6 +4210,13 @@ SearchService.prototype = {
break;
}
}
for (let engineName of this._searchOrder) {
if (result.name == engineName) {
sendSubmissionURL = true;
break;
}
}
}
if (sendSubmissionURL) {

View File

@ -1,6 +1,7 @@
{
"default": {
"searchDefault": "Test search engine",
"searchOrder": ["engine-resourceicon", "engine-chromeicon"],
"visibleDefaultEngines": [
"engine", "engine-pref", "engine-rel-searchform-purpose", "engine-system-purpose", "engine-chromeicon", "engine-resourceicon"
]

View File

@ -0,0 +1,32 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
/* Check default search engine is picked from list.json searchDefault */
"use strict";
function run_test() {
Assert.ok(!Services.search.isInitialized, "search isn't initialized yet");
run_next_test();
}
// Override list.json with test data from data/list.json
// and check that searchOrder is working
add_task(async function test_searchOrderJSON() {
let url = "resource://test/data/";
let resProt = Services.io.getProtocolHandler("resource")
.QueryInterface(Ci.nsIResProtocolHandler);
resProt.setSubstitution("search-plugins", Services.io.newURI(url));
await asyncReInit();
Assert.ok(Services.search.isInitialized, "search initialized");
Assert.equal(Services.search.currentEngine.name,
kTestEngineName, "expected test list JSON default search engine");
let sortedEngines = Services.search.getEngines();
Assert.equal(sortedEngines[0].name, "Test search engine", "First engine should be default");
Assert.equal(sortedEngines[1].name, "engine-resourceicon", "Second engine should be resource");
Assert.equal(sortedEngines[2].name, "engine-chromeicon", "Third engine should be chrome");
});

View File

@ -41,6 +41,7 @@ support-files =
[test_init_async_multiple_then_sync.js]
[test_json_cache.js]
[test_list_json_searchdefault.js]
[test_list_json_searchorder.js]
[test_location.js]
[test_location_error.js]
[test_location_malformed_json.js]