Bug 1572470 - Add wikipedia to engines.json r=Standard8
authorDale Harvey <dale@arandomurl.com>
Fri, 30 Aug 2019 15:02:47 +0000
changeset 491036 19b8d6a399f60de32ca253fa497c23cbfa93d265
parent 491035 97ec7ec089c4e91acd34d7324711cc9c556b1117
child 491037 9798d276348f91a467897783525134fe2b10723a
push id94193
push userdharvey@mozilla.com
push dateSat, 31 Aug 2019 14:07:15 +0000
treeherderautoland@19b8d6a399f6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersStandard8
bugs1572470
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1572470 - Add wikipedia to engines.json r=Standard8 Differential Revision: https://phabricator.services.mozilla.com/D43768
browser/components/search/extensions/engines.json
toolkit/components/search/SearchEngineSelector.jsm
toolkit/components/search/docs/SearchEngineConfiguration.rst
toolkit/components/search/tests/xpcshell/test_engine_selector.js
--- a/browser/components/search/extensions/engines.json
+++ b/browser/components/search/extensions/engines.json
@@ -803,11 +803,83 @@
       "webExtensionVersion": "1.2",
       "appliesTo": [{ "included": { "locales": { "matches": ["ja-JP-mac", "ja"]}}}]
     },
     {
       "engineName": "zoznam-sk",
       "webExtensionId": "zoznam-sk@search.mozilla.org",
       "webExtensionVersion": "1.2",
       "appliesTo": [{ "included": { "locales": { "matches": ["sk"]}}}]
+    },
+    {
+      "engineName": "wikipedia",
+      "webExtensionId": "wikipedia@search.mozilla.org",
+      "webExtensionVersion": "1.0",
+      "appliesTo": [ {
+        "included": { "locales": { "matches": [
+          "af", "an", "ar", "as", "ast", "az", "be", "bg",
+          "br", "bs", "ca", "crh", "cy", "da", "de", "dsb",
+          "el", "eo", "et", "eu", "fa", "fi", "fy-NL", "ga-IE",
+          "gd", "gl", "gn", "he", "hr", "hsb", "hu", "ia",
+          "id", "is", "it", "ka", "kab", "kk", "km", "kn",
+          "lij", "lo", "lt", "ltg", "lv", "mk", "ml", "mr",
+          "ms", "my", "nl", "oc", "or", "pl", "rm", "ro", "ru",
+          "si", "sk", "sl", "sq", "sr", "sv-SE", "ta", "te",
+          "th", "tl", "tr", "uk", "ur", "uz", "vi", "wo",
+          "zh-CN", "zh-TW"
+        ]}},
+        "webExtensionLocale": "$USER_LOCALE"
+      }, {
+        "included": { "locales": { "matches": [
+          "en-CA", "en-GB", "en-US", "en-ZA", "ach", "xh"
+          ]}},
+          "webExtensionLocale": "en"
+      }, {
+        "included": { "locales": { "matches": [ "bn", "bn-BD", "bn-IN" ] } },
+        "webExtensionLocale": "bn"
+      }, {
+        "included": { "locales": { "matches": [
+          "cak", "es-AR", "es-CL", "es-ES", "es-MX", "trs"
+        ]}},
+        "webExtensionLocale": "es"
+      }, {
+        "included": { "locales": { "matches": [ "cs" ] } },
+        "webExtensionLocale": "cz"
+      }, {
+        "included": { "locales": { "matches": [ "ff", "fr", "son" ] } },
+        "webExtensionLocale": "fr"
+      }, {
+        "included": { "locales": { "matches": [ "gu-IN" ] } },
+        "webExtensionLocale": "gu"
+      }, {
+        "included": { "locales": { "matches": [ "hi-IN" ] } },
+        "webExtensionLocale": "hi"
+      }, {
+        "included": { "locales": { "matches": [ "hy-AM" ] } },
+        "webExtensionLocale": "hy"
+      }, {
+        "included": { "locales": { "matches": [ "ja-JP-macos", "ja" ] } },
+        "webExtensionLocale": "ja"
+      }, {
+        "included": { "locales": { "matches": [ "ko" ] } },
+        "webExtensionLocale": "kr"
+      }, {
+        "included": { "locales": { "matches": [ "mai" ] } },
+        "webExtensionLocale": "hi"
+      }, {
+        "included": { "locales": { "matches": [ "nb-NO" ] } },
+        "webExtensionLocale": "NO"
+      }, {
+        "included": { "locales": { "matches": [ "ne-NP" ] } },
+        "webExtensionLocale": "ne"
+      }, {
+        "included": { "locales": { "matches": [ "nn-NO" ] } },
+        "webExtensionLocale": "NN"
+      }, {
+        "included": { "locales": { "matches": [ "pa-IN" ] } },
+        "webExtensionLocale": "pa"
+      }, {
+        "included": { "locales": { "matches": [ "pt-BR", "pt-PT" ] } },
+        "webExtensionLocale": "pt"
+      }]
     }
   ]
 }
--- a/toolkit/components/search/SearchEngineSelector.jsm
+++ b/toolkit/components/search/SearchEngineSelector.jsm
@@ -13,16 +13,17 @@ const { XPCOMUtils } = ChromeUtils.impor
 XPCOMUtils.defineLazyGlobalGetters(this, ["fetch"]);
 
 XPCOMUtils.defineLazyModuleGetters(this, {
   SearchUtils: "resource://gre/modules/SearchUtils.jsm",
 });
 
 const EXT_SEARCH_PREFIX = "resource://search-extensions/";
 const ENGINE_CONFIG_URL = `${EXT_SEARCH_PREFIX}engines.json`;
+const USER_LOCALE = "$USER_LOCALE";
 
 function log(str) {
   SearchUtils.log("SearchEngineSelector " + str + "\n");
 }
 
 /**
  * SearchEngineSelector parses the JSON configuration for
  * search engines and returns the applicable engines depending
@@ -72,16 +73,21 @@ class SearchEngineSelector {
       let baseConfig = this._copyObject({}, config);
 
       // Loop through all the appliedTo sections that apply to
       // this configuration
       if (applies.length) {
         for (let section of applies) {
           this._copyObject(baseConfig, section);
         }
+
+        if (baseConfig.webExtensionLocale == USER_LOCALE) {
+          baseConfig.webExtensionLocale = locale;
+        }
+
         engines.push(baseConfig);
       }
     }
 
     engines.sort(this._sort.bind(this));
 
     let privateEngine = engines.find(engine => {
       return (
--- a/toolkit/components/search/docs/SearchEngineConfiguration.rst
+++ b/toolkit/components/search/docs/SearchEngineConfiguration.rst
@@ -104,16 +104,39 @@ located specific regions or with certain
         "webExtensionVersion": "1.2"
       }]
     }
 
 In this case users identified as being in the US region would use the WebExtension
 with identifier ``webext-engine1``, version 1.1. GB region users would get
 ``webext-gb`` version 1.2, and all other users would get ``webext`` version 1.0.
 
+Special Attributes
+------------------
+
+If a ``webExtensionLocale`` attribute is specified with the value
+``"$USER_LOCALE"`` then the special value will be replaced in the
+configuration object with the users locale. For example:
+
+.. code-block:: js
+
+    "engine1": {
+      "webExtensionId": "webext",
+      "webExtensionVersion": "1.0",
+      "appliesTo": [{
+        "included": {
+          "locales": {
+            "matches": ["us", "gb"]
+          },
+          "webExtensionLocale": "$USER_LOCALE",
+        },
+
+Will report either ``us`` or ``gb`` as the ``webExtensionLocale``
+depending on the user.
+
 Engine Defaults
 ---------------
 
 An engine may be specified as the default for one of two purposes:
 
 #. normal browsing mode,
 #. private browsing mode.
 
--- a/toolkit/components/search/tests/xpcshell/test_engine_selector.js
+++ b/toolkit/components/search/tests/xpcshell/test_engine_selector.js
@@ -16,17 +16,17 @@ const CONFIG_URL =
         orderHint: 500,
         webExtensionLocale: "default",
         appliesTo: [
           {
             included: { everywhere: true },
           },
           {
             included: { regions: ["us"] },
-            webExtensionLocale: "us",
+            webExtensionLocale: "$USER_LOCALE",
           },
         ],
       },
       {
         engineName: "lycos",
         orderHint: 1000,
         default: "yes",
         appliesTo: [
@@ -75,17 +75,17 @@ add_task(async function() {
     privateDefault,
     "altavista",
     "Should set altavista as privateDefault"
   );
   let names = engines.map(obj => obj.engineName);
   Assert.deepEqual(names, ["lycos", "altavista", "aol"], "Correct order");
   Assert.equal(
     engines[2].webExtensionLocale,
-    "us",
+    "en-US",
     "Subsequent matches in applies to can override default"
   );
 
   ({ engines, privateDefault } = engineSelector.fetchEngineConfiguration(
     "kz",
     "zh-CN"
   ));
   Assert.equal(engines.length, 2, "Correct engines are returns");