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
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 const BASE_LIST_ID = "base";
6 const CONTENT_LIST_ID = "content";
7 const TRACK_SUFFIX = "-track-digest256";
8 const TRACKING_TABLE_PREF = "urlclassifier.trackingTable";
9 const LISTS_PREF_BRANCH = "browser.safebrowsing.provider.mozilla.lists.";
11 var gBlocklistManager = {
19 return this._rowCount;
21 getCellText(row, column) {
22 if (column.id == "listCol") {
23 let list = gBlocklistManager._blockLists[row];
39 getImageSrc(row, column) {},
40 getCellValue(row, column) {
41 if (column.id == "selectionCol") {
42 return gBlocklistManager._blockLists[row].selected;
46 cycleHeader(column) {},
47 getRowProperties(row) {
50 getColumnProperties(column) {
53 getCellProperties(row, column) {
54 if (column.id == "selectionCol") {
64 document.addEventListener("dialogaccept", () => this.onApplyChanges());
69 // reusing an open dialog, clear the old observer
73 this._type = "tracking";
75 this._loadBlockLists();
81 for (let list of this._blockLists) {
82 list.selected = false;
84 this._blockLists[this._tree.currentIndex].selected = true;
90 let activeList = this._getActiveList();
92 for (let list of this._blockLists) {
99 if (activeList !== selected.id) {
100 let trackingTable = Services.prefs.getCharPref(TRACKING_TABLE_PREF);
101 if (selected.id != CONTENT_LIST_ID) {
102 trackingTable = trackingTable.replace(
103 "," + CONTENT_LIST_ID + TRACK_SUFFIX,
107 trackingTable += "," + CONTENT_LIST_ID + TRACK_SUFFIX;
109 Services.prefs.setCharPref(TRACKING_TABLE_PREF, trackingTable);
111 // Force an update after changing the tracking protection table.
112 let listmanager = Cc[
113 "@mozilla.org/url-classifier/listmanager;1"
114 ].getService(Ci.nsIUrlListManager);
116 listmanager.forceUpdates(trackingTable);
121 async _loadBlockLists() {
122 this._blockLists = [];
124 // Load blocklists into a table.
125 let branch = Services.prefs.getBranch(LISTS_PREF_BRANCH);
126 let itemArray = branch.getChildList("");
127 for (let itemName of itemArray) {
129 let list = await this._createBlockList(itemName);
130 this._blockLists.push(list);
132 // Ignore bogus or missing list name.
140 async _createBlockList(id) {
141 let branch = Services.prefs.getBranch(LISTS_PREF_BRANCH);
142 let l10nKey = branch.getCharPref(id);
144 // eslint-disable-next-line mozilla/prefer-formatValues
145 let [listName, description] = await document.l10n.formatValues([
146 { id: `blocklist-item-${l10nKey}-listName` },
147 { id: `blocklist-item-${l10nKey}-description` },
150 // eslint-disable-next-line mozilla/prefer-formatValues
151 let name = await document.l10n.formatValue("blocklist-item-list-template", {
159 selected: this._getActiveList() === id,
164 this._tree = document.getElementById("blocklistsTree");
165 this._view._rowCount = this._blockLists.length;
166 this._tree.view = this._view;
170 let trackingTable = Services.prefs.getCharPref(TRACKING_TABLE_PREF);
171 return trackingTable.includes(CONTENT_LIST_ID)