1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 ChromeUtils.defineESModuleGetters(lazy, {
8 RemoteSettings: "resource://services-settings/remote-settings.sys.mjs",
10 "resource://services-settings/RemoteSettingsClient.sys.mjs",
13 const SETTINGS_IGNORELIST_KEY = "hijack-blocklists";
15 class IgnoreListsManager {
17 if (!this._ignoreListSettings) {
18 this._ignoreListSettings = lazy.RemoteSettings(SETTINGS_IGNORELIST_KEY);
22 async getAndSubscribe(listener) {
25 // Trigger a get of the initial value.
26 const settings = await this._getIgnoreList();
28 // Listen for future updates after we first get the values.
29 this._ignoreListSettings.on("sync", listener);
34 unsubscribe(listener) {
35 if (!this._ignoreListSettings) {
39 this._ignoreListSettings.off("sync", listener);
42 async _getIgnoreList() {
43 if (this._getSettingsPromise) {
44 return this._getSettingsPromise;
47 const settings = await (this._getSettingsPromise =
48 this._getIgnoreListSettings());
49 delete this._getSettingsPromise;
54 * Obtains the current ignore list from remote settings. This includes
55 * verifying the signature of the ignore list within the database.
57 * If the signature in the database is invalid, the database will be wiped
58 * and the stored dump will be used, until the settings next update.
60 * Note that this may cause a network check of the certificate, but that
61 * should generally be quick.
63 * @param {boolean} [firstTime]
64 * Internal boolean to indicate if this is the first time check or not.
66 * An array of objects in the database, or an empty array if none
69 async _getIgnoreListSettings(firstTime = true) {
72 result = await this._ignoreListSettings.get({
73 verifySignature: true,
77 ex instanceof lazy.RemoteSettingsClient.InvalidSignatureError &&
80 // The local database is invalid, try and reset it.
81 await this._ignoreListSettings.db.clear();
82 // Now call this again.
83 return this._getIgnoreListSettings(false);
85 // Don't throw an error just log it, just continue with no data, and hopefully
86 // a sync will fix things later on.
93 export const IgnoreLists = new IgnoreListsManager();