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

Differential Revision: https://phabricator.services.mozilla.com/D39919

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Ehsan Akhgari 2019-07-31 19:32:01 +00:00
parent 45053eac94
commit bea0b67d17
6 changed files with 115 additions and 0 deletions

View File

@ -1137,6 +1137,10 @@ pref("privacy.restrict3rdpartystorage.partitionedHosts", "accounts.google.com/o/
// 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

View File

@ -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"];

View File

@ -0,0 +1 @@
category profile-after-change URLDecorationAnnotationsService @mozilla.org/tracking-url-decoration-service;1 process=main

View File

@ -11,4 +11,11 @@ Classes = [
'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,
},
]

View File

@ -9,12 +9,18 @@ with Files('**'):
XPIDL_SOURCES += [
'nsITrackingDBService.idl',
'nsIURLDecorationAnnotationsService.idl',
]
XPIDL_MODULE = 'toolkit_antitracking'
EXTRA_COMPONENTS += [
'antitracking.manifest',
]
EXTRA_JS_MODULES += [
'TrackingDBService.jsm',
'URLDecorationAnnotationsService.jsm',
]
XPCOM_MANIFESTS += [

View File

@ -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();
};