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/. */
5 export function ContentPrefStore() {
6 this._groups = new Map();
7 this._globalNames = new Map();
10 ContentPrefStore.prototype = {
11 set: function CPS_set(group, name, val) {
13 if (!this._groups.has(group)) {
14 this._groups.set(group, new Map());
16 this._groups.get(group).set(name, val);
18 this._globalNames.set(name, val);
22 setWithCast: function CPS_setWithCast(group, name, val) {
23 if (typeof val == "boolean") {
25 } else if (val === undefined) {
28 this.set(group, name, val);
31 has: function CPS_has(group, name) {
33 return this._groups.has(group) && this._groups.get(group).has(name);
35 return this._globalNames.has(name);
38 get: function CPS_get(group, name) {
39 if (group && this._groups.has(group)) {
40 return this._groups.get(group).get(name);
42 return this._globalNames.get(name);
45 remove: function CPS_remove(group, name) {
47 if (this._groups.has(group)) {
48 this._groups.get(group).delete(name);
49 if (this._groups.get(group).size == 0) {
50 this._groups.delete(group);
54 this._globalNames.delete(name);
58 removeGroup: function CPS_removeGroup(group) {
60 this._groups.delete(group);
62 this._globalNames.clear();
66 removeAllGroups: function CPS_removeAllGroups() {
70 removeAll: function CPS_removeAll() {
71 this.removeAllGroups();
72 this._globalNames.clear();
75 groupsMatchIncludingSubdomains: function CPS_groupsMatchIncludingSubdomains(
79 let idx = group2.indexOf(group);
81 idx == group2.length - group.length &&
82 (idx == 0 || group2[idx - 1] == ".")
86 *[Symbol.iterator]() {
87 for (let [group, names] of this._groups) {
88 for (let [name, val] of names) {
89 yield [group, name, val];
92 for (let [name, val] of this._globalNames) {
93 yield [null, name, val];
97 *match(group, name, includeSubdomains) {
98 for (let sgroup of this.matchGroups(group, includeSubdomains)) {
99 if (this.has(sgroup, name)) {
100 yield [sgroup, this.get(sgroup, name)];
105 *matchGroups(group, includeSubdomains) {
107 if (includeSubdomains) {
108 for (let [sgroup, ,] of this) {
110 if (this.groupsMatchIncludingSubdomains(group, sgroup)) {
115 } else if (this._groups.has(group)) {
118 } else if (this._globalNames.size) {