summaryrefslogtreecommitdiffstats
path: root/toolkit/components/antitracking/URLDecorationAnnotationsService.jsm
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /toolkit/components/antitracking/URLDecorationAnnotationsService.jsm
parentInitial commit. (diff)
downloadfirefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz
firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/antitracking/URLDecorationAnnotationsService.jsm')
-rw-r--r--toolkit/components/antitracking/URLDecorationAnnotationsService.jsm74
1 files changed, 74 insertions, 0 deletions
diff --git a/toolkit/components/antitracking/URLDecorationAnnotationsService.jsm b/toolkit/components/antitracking/URLDecorationAnnotationsService.jsm
new file mode 100644
index 0000000000..d34c22a58b
--- /dev/null
+++ b/toolkit/components/antitracking/URLDecorationAnnotationsService.jsm
@@ -0,0 +1,74 @@
+/* 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() {};
+
+ChromeUtils.defineModuleGetter(
+ this,
+ "RemoteSettings",
+ "resource://services-settings/remote-settings.js"
+);
+
+const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
+
+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([
+ "nsIObserver",
+ "nsIURLDecorationAnnotationsService",
+ ]),
+
+ _initialized: false,
+ _prefBranch: null,
+
+ 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.
+ if (this._prefBranch === null) {
+ this._prefBranch = Services.prefs.getDefaultBranch("");
+ }
+
+ const branch = this._prefBranch;
+ branch.unlockPref(PREF_NAME);
+ branch.setStringPref(
+ PREF_NAME,
+ entries.map(x => x.token.replace(/ /, "%20")).join(" ")
+ );
+ branch.lockPref(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"];