Bug 1568341 - Part 1: Add a component for consuming the anti-tracking-url-decoration remote settings bucket and making it available to content processes; r=baku a=RyanVM
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 31 Jul 2019 19:32:01 +0000
changeset 545036 4c5561a2a35f9d18652478fdc64957cf2cf09b95
parent 545035 5a547795e5704468959f379e87d6a35d67ef4e75
child 545037 cb67222721b8cb65abc4acea8c68ff7aedd04720
push id2131
push userffxbld-merge
push dateMon, 26 Aug 2019 18:30:20 +0000
treeherdermozilla-release@b19ffb3ca153 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku, RyanVM
bugs1568341
milestone69.0
Bug 1568341 - Part 1: Add a component for consuming the anti-tracking-url-decoration remote settings bucket and making it available to content processes; r=baku a=RyanVM Differential Revision: https://phabricator.services.mozilla.com/D39919
modules/libpref/init/all.js
toolkit/components/antitracking/URLDecorationAnnotationsService.jsm
toolkit/components/antitracking/antitracking.manifest
toolkit/components/antitracking/components.conf
toolkit/components/antitracking/moz.build
toolkit/components/antitracking/nsIURLDecorationAnnotationsService.idl
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -1219,16 +1219,20 @@ pref("privacy.popups.disable_from_plugin
 // Enable Paritioned LocalStorage for a list of hosts when detected as trackers
 // (See nsICookieService::BEHAVIOR_REJECT_TRACKER cookie behavior)
 pref("privacy.restrict3rdpartystorage.partitionedHosts", "accounts.google.com/o/oauth2/");
 
 // If a host is contained in this pref list, user-interaction is required
 // before granting the storage access permission.
 pref("privacy.restrict3rdpartystorage.userInteractionRequiredForHosts", "");
 
+// The url decoration tokens used to for stripping document referrers based on.
+// A list separated by spaces.  This pref isn't meant to be changed by users.
+pref("privacy.restrict3rdpartystorage.url_decorations", "");
+
 // Excessive reporting of blocked popups can be a DOS vector,
 // by overloading the main process as popups get blocked and when
 // users try to restore all popups, which is the most visible
 // option in our UI at the time of writing.
 // We will invisibly drop any popups from a page that has already
 // opened more than this number of popups.
 pref("privacy.popups.maxReported", 100);
 
new file mode 100644
--- /dev/null
+++ b/toolkit/components/antitracking/URLDecorationAnnotationsService.jsm
@@ -0,0 +1,70 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * 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/. */
+
+this.URLDecorationAnnotationsService = function() {};
+
+const { Preferences } = ChromeUtils.import(
+  "resource://gre/modules/Preferences.jsm"
+);
+
+ChromeUtils.defineModuleGetter(
+  this,
+  "RemoteSettings",
+  "resource://services-settings/remote-settings.js"
+);
+
+const COLLECTION_NAME = "anti-tracking-url-decoration";
+const PREF_NAME = "privacy.restrict3rdpartystorage.url_decorations";
+
+URLDecorationAnnotationsService.prototype = {
+  classID: Components.ID("{5874af6d-5719-4e1b-b155-ef4eae7fcb32}"),
+  QueryInterface: ChromeUtils.generateQI([
+    Ci.nsIObserver,
+    Ci.nsIURLDecorationAnnotationsService,
+  ]),
+
+  _initialized: false,
+
+  onDataAvailable(entries) {
+    // Use this technique in order to ensure the pref cannot be changed by the
+    // user e.g. through about:config.  This preferences is only intended as a
+    // mechanism for reflecting this data to content processes.
+    Preferences.unlock(PREF_NAME);
+    new Preferences({ defaultBranch: true }).set(
+      PREF_NAME,
+      entries.map(x => x.token.replace(/ /, "%20")).join(" ")
+    );
+    Preferences.lock(PREF_NAME);
+  },
+
+  observe(aSubject, aTopic, aData) {
+    if (aTopic == "profile-after-change") {
+      this.ensureUpdated();
+    }
+  },
+
+  ensureUpdated() {
+    if (this._initialized) {
+      return Promise.resolve();
+    }
+    this._initialized = true;
+
+    const client = RemoteSettings(COLLECTION_NAME);
+    client.on("sync", event => {
+      let {
+        data: { current },
+      } = event;
+      this.onDataAvailable(current);
+    });
+
+    // Now trigger an update from the server if necessary to get a fresh copy
+    // of the data
+    return client.get({}).then(entries => {
+      this.onDataAvailable(entries);
+      return undefined;
+    });
+  },
+};
+
+var EXPORTED_SYMBOLS = ["URLDecorationAnnotationsService"];
new file mode 100644
--- /dev/null
+++ b/toolkit/components/antitracking/antitracking.manifest
@@ -0,0 +1,1 @@
+category profile-after-change URLDecorationAnnotationsService @mozilla.org/tracking-url-decoration-service;1 process=main
--- a/toolkit/components/antitracking/components.conf
+++ b/toolkit/components/antitracking/components.conf
@@ -6,9 +6,16 @@
 
 Classes = [
     {
         'cid': '{3c9c43b6-09eb-4ed2-9b87-e29f4221eef0}',
         'contract_ids': ['@mozilla.org/tracking-db-service;1'],
         'jsm': 'resource://gre/modules/TrackingDBService.jsm',
         'constructor': 'TrackingDBService',
     },
+    {
+        'cid': '{5874af6d-5719-4e1b-b155-ef4eae7fcb32}',
+        'contract_ids': ['@mozilla.org/tracking-url-decoration-service;1'],
+        'jsm': 'resource://gre/modules/URLDecorationAnnotationsService.jsm',
+        'constructor': 'URLDecorationAnnotationsService',
+        'processes': ProcessSelector.MAIN_PROCESS_ONLY,
+    },
 ]
--- a/toolkit/components/antitracking/moz.build
+++ b/toolkit/components/antitracking/moz.build
@@ -4,22 +4,28 @@
 # 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/.
 
 with Files('**'):
     BUG_COMPONENT = ('Core', 'DOM: Security')
 
 XPIDL_SOURCES += [
     'nsITrackingDBService.idl',
+    'nsIURLDecorationAnnotationsService.idl',
 ]
 
 XPIDL_MODULE = 'toolkit_antitracking'
 
+EXTRA_COMPONENTS += [
+    'antitracking.manifest',
+]
+
 EXTRA_JS_MODULES += [
     'TrackingDBService.jsm',
+    'URLDecorationAnnotationsService.jsm',
 ]
 
 XPCOM_MANIFESTS += [
     'components.conf',
 ]
 
 EXPORTS.mozilla = [
     'AntiTrackingCommon.h',
new file mode 100644
--- /dev/null
+++ b/toolkit/components/antitracking/nsIURLDecorationAnnotationsService.idl
@@ -0,0 +1,27 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * 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/. */
+
+#include "nsISupports.idl"
+
+/**
+ * A service that monitors updates to the anti-tracking URL decoration
+ * annotations from remote settings.
+ */
+[scriptable, uuid(937d0c66-6821-4e3f-9e04-50dbc2b2b476)]
+interface nsIURLDecorationAnnotationsService : nsISupports
+{
+  /**
+   * Ensures that the list is updated and resolves the returned promise when
+   * the update is finished.
+   *
+   * The new list will be written to a space-separated list of tokens inside
+   * the following string preference:
+   *   privacy.restrict3rdpartystorage.url_decorations
+   *
+   * This preference will be kept up to date with future list updates from
+   * the remote settings server.  This preference cannot be modified by any
+   * external component and is managed by this service.
+   */
+  Promise ensureUpdated();
+};