Bug 1656219 - Allow search configuration to specify an engine should report to an attribution URL. r=daleharvey
authorMark Banner <standard8@mozilla.com>
Thu, 20 Aug 2020 11:24:13 +0000
changeset 610140 3b983f83c30730c14be4f9c55949c6a823c6f857
parent 610139 24d6087acc6409a352d18f24945a73468579e9c6
child 610141 5c795477d83a25be5a6ade887d52d5261c319885
push id13553
push userffxbld-merge
push dateMon, 24 Aug 2020 12:51:36 +0000
treeherdermozilla-beta@a54f8b5d0977 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdaleharvey
bugs1656219
milestone81.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 1656219 - Allow search configuration to specify an engine should report to an attribution URL. r=daleharvey Differential Revision: https://phabricator.services.mozilla.com/D87473
toolkit/components/search/SearchEngine.jsm
toolkit/components/search/nsISearchService.idl
toolkit/components/search/schema/search-engine-config-schema.json
toolkit/components/search/schema/search-engine-config-ui-schema.json
toolkit/components/search/tests/xpcshell/test-extensions/engines.json
toolkit/components/search/tests/xpcshell/test_config_attribution.js
toolkit/components/search/tests/xpcshell/xpcshell.ini
--- a/toolkit/components/search/SearchEngine.jsm
+++ b/toolkit/components/search/SearchEngine.jsm
@@ -590,16 +590,18 @@ class SearchEngine {
   // overridden by a non-preferred icon).
   _hasPreferredIcon = null;
   // The engine's name.
   _name = null;
   // The name of the charset used to submit the search terms.
   _queryCharset = null;
   // The engine's raw SearchForm value (URL string pointing to a search form).
   __searchForm = null;
+  // Whether or not to send an attribution request to the server.
+  _sendAttributionRequest = false;
   // The number of days between update checks for new versions
   _updateInterval = null;
   // The url to check at for a new update
   _updateURL = null;
   // The url to check for a new icon
   _iconUpdateURL = null;
   // The extension ID if added by an extension.
   _extensionID = null;
@@ -968,16 +970,18 @@ class SearchEngine {
     }
 
     this._extensionID = extensionID;
     this._locale = locale;
     this._orderHint = configuration.orderHint;
     this._telemetryId = configuration.telemetryId;
     this._name = searchProvider.name.trim();
     this._regionParams = configuration.regionParams;
+    this._sendAttributionRequest =
+      configuration.sendAttributionRequest ?? false;
 
     if (shortName) {
       this._shortName = shortName;
     }
 
     this._definedAliases = [];
     if (Array.isArray(searchProvider.keyword)) {
       this._definedAliases = searchProvider.keyword.map(k => k.trim());
@@ -1390,16 +1394,20 @@ class SearchEngine {
   get name() {
     return this._name;
   }
 
   get searchForm() {
     return this._getSearchFormWithPurpose();
   }
 
+  get sendAttributionRequest() {
+    return this._sendAttributionRequest;
+  }
+
   _getSearchFormWithPurpose(purpose) {
     // First look for a <Url rel="searchform">
     var searchFormURL = this._getURLOfType(
       SearchUtils.URL_TYPE.SEARCH,
       "searchform"
     );
     if (searchFormURL) {
       let submission = searchFormURL.getSubmission("", this, purpose);
--- a/toolkit/components/search/nsISearchService.idl
+++ b/toolkit/components/search/nsISearchService.idl
@@ -126,16 +126,22 @@ interface nsISearchEngine : nsISupports
   readonly attribute AString name;
 
   /**
    * A URL string pointing to the engine's search form.
    */
   readonly attribute AString searchForm;
 
   /**
+   * A boolean to indicate if we should send an attribution request to Mozilla's
+   * server.
+   */
+  readonly attribute boolean sendAttributionRequest;
+
+  /**
    * The identifier to use for this engine when submitting to telemetry.
    */
   readonly attribute AString telemetryId;
 
   /**
    * An optional unique identifier for this search engine within the context of
    * the distribution, as provided by the distributing entity.
    */
--- a/toolkit/components/search/schema/search-engine-config-schema.json
+++ b/toolkit/components/search/schema/search-engine-config-schema.json
@@ -16,16 +16,19 @@
     "appliesTo": {
       "type": "array",
       "title": "Applies To",
       "description": "This section defines the region/locales/application information for where a search engine is available, and any specifics for that region/locale/application. If there are no entries in the list, it is considered to be included everywhere",
       "items": {
         "$ref": "#/definitions/appliesToSection"
       }
     },
+    "sendAttributionRequest": {
+      "$ref": "#/definitions/sendAttributionRequest"
+    },
     "telemetryId": {
       "type": "string",
       "title": "Telemetry Id",
       "description": "The telemetry Id as used for some of SEARCH_COUNTS telemetry."
     },
     "webExtension": {
       "$ref": "#/definitions/webExtension"
     },
@@ -280,16 +283,21 @@
                 "title": "Value",
                 "description": "The value to override with"
               }
             }
           }
         }
       }
     },
+    "sendAttributionRequest": {
+      "type": "boolean",
+      "title": "Send Attribution Request",
+      "description": "Indicates if we should send an attribution request to Mozilla's server."
+    },
     "telemetryId": {
       "type": "string",
       "title": "Telemetry Id",
       "description": "The telemetry Id as used for some of SEARCH_COUNTS telemetry."
     },
     "webExtension": {
       "type": "object",
       "title": "WebExtension",
@@ -394,16 +402,19 @@
           "$ref": "#/definitions/excluded"
         },
         "application": {
           "$ref": "#/definitions/application"
         },
         "webextension": {
           "$ref": "#/definitions/webExtension"
         },
+        "sendAttributionRequest": {
+          "$ref": "#/definitions/sendAttributionRequest"
+        },
         "telemetryId": {
           "$ref": "#/definitions/telemetryId"
         },
         "params": {
           "$ref": "#/definitions/params"
         },
         "regionParams": {
           "$ref": "#/definitions/regionParams"
--- a/toolkit/components/search/schema/search-engine-config-ui-schema.json
+++ b/toolkit/components/search/schema/search-engine-config-ui-schema.json
@@ -1,13 +1,14 @@
 {
   "ui:order": [
     "webExtension",
     "default",
     "defaultPrivate",
     "orderHint",
+    "sendAttributionRequest",
     "telemetryId",
     "params",
     "extraParams",
     "regionParams",
     "appliesTo"
   ]
 }
--- a/toolkit/components/search/tests/xpcshell/test-extensions/engines.json
+++ b/toolkit/components/search/tests/xpcshell/test-extensions/engines.json
@@ -1,30 +1,32 @@
 {
   "data": [
     {
       "webExtension": {
         "id": "plainengine@search.mozilla.org"
       },
       "orderHint": 10000,
+      "sendAttributionRequest": true,
       "appliesTo": [{
         "included": { "everywhere": true },
         "default": "yes-if-no-other"
       }]
     },
     {
       "webExtension": {
         "id": "special-engine@search.mozilla.org"
       },
       "orderHint": 7000,
       "appliesTo": [{
-          "included": { "regions": ["tr"] },
-          "default": "yes"
-        }, {
-        "included": { "everywhere": true }
+        "included": { "regions": ["tr"] },
+        "default": "yes"
+      }, {
+        "included": { "everywhere": true },
+        "sendAttributionRequest": true
       }]
     },
     {
       "webExtension": {
         "id": "multilocale@search.mozilla.org",
         "locales": ["an"]
       },
       "orderHint": 6000,
new file mode 100644
--- /dev/null
+++ b/toolkit/components/search/tests/xpcshell/test_config_attribution.js
@@ -0,0 +1,29 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+add_task(async function setup() {
+  Region._setHomeRegion("an", false);
+  await useTestEngines("test-extensions");
+  await AddonTestUtils.promiseStartupManager();
+  await Services.search.init();
+});
+
+add_task(async function test_send_attribution_request() {
+  let engine = await Services.search.getEngineByName("Plain");
+  Assert.ok(
+    engine.sendAttributionRequest,
+    "Should have noted to send the attribution request for Plain"
+  );
+
+  engine = await Services.search.getEngineByName("Special");
+  Assert.ok(
+    engine.sendAttributionRequest,
+    "Should have noted to send the attribution request for Special"
+  );
+
+  engine = await Services.search.getEngineByName("Multilocale AN");
+  Assert.ok(
+    !engine.sendAttributionRequest,
+    "Should not have noted to send the attribution request for Multilocale AN"
+  );
+});
--- a/toolkit/components/search/tests/xpcshell/xpcshell.ini
+++ b/toolkit/components/search/tests/xpcshell/xpcshell.ini
@@ -62,16 +62,17 @@ support-files =
 [test_addEngine_callback.js]
 [test_addEngineWithDetails.js]
 [test_addEngineWithDetailsObject.js]
 [test_addEngineWithExtensionID.js]
 [test_async.js]
 [test_bug930456_child.js]
 skip-if = true # Is confusing
 [test_bug930456.js]
+[test_config_attribution.js]
 [test_config_engine_params.js]
 support-files =
   method-extensions/get/manifest.json
   method-extensions/post/manifest.json
   method-extensions/engines.json
 [test_defaultEngine_fallback.js]
 [test_defaultEngine.js]
 [test_defaultPrivateEngine.js]