This file is indexed.

/usr/share/xul-ext/self-destructing-cookies/lib/domaintree.js is in xul-ext-self-destructing-cookies 0.4.12-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/* Copyright (c) 2013, 2014, 2015 Ove Sörensen <sdc@elektro-eel.org>

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2, or (at your option)
 any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 02110-1301, USA.
*/

"use strict";

const STYLE_TOP = 0;
const STYLE_FRAME = 1;

// this class tracks references to domains, exploiting their hierarchical
// nature to store them in a tree, offering fast lookups of subdomains
exports.DomainTree = function() {
    this.root = this.makeDomain(null, "");
}

// increase worker count
exports.DomainTree.prototype.incRefs = function(domain, style, count) {
    var a = this.get(domain);
    if (a == undefined) {
        // this is the first time we see this host, add it
        var x = domain.split(".").reverse();
        // start inserting here
        var [y, n] = this.closestAncestor(x);
        // add each segment
        for (var i = n; i < x.length; i++) {
            var z = this.makeDomain(y, x[i]);
            y.children[x[i]] = z;
            y.childCount += 1;
            y = z;
        }
        a = y;
        a.childCount = 0;
    }

    a.refCounts[style] += count;
    //console.debug(this.root.toString());
}

// decrease worker count
exports.DomainTree.prototype.decRefs = function(domain, style, count) {
    var a = this.get(domain);
    if (a != undefined) {
        a.refCounts[style] -= count;
    }
   //console.debug(this.root.toString());
}

// return our node for the domain, or undefined if we don't know it
exports.DomainTree.prototype.get = function(domain) {
    var x = domain.split(".").reverse();
    var [y, n] = this.closestAncestor(x);

    if (n != x.length) {
        // not found
        return undefined;
    }
    return y;
}

// return refcounts for the domain, or undefined if we don't know
exports.DomainTree.prototype.getRefCounts = function(domain) {
    var a = this.get(domain);
    if (a == undefined) return undefined;
    return a.refCounts;
}

// remove a domain from the tree
exports.DomainTree.prototype.remove = function(domain) {
    var a = this.get(domain);
    if (a == undefined) return;

    // we can only remove those segments that have no children and no references
    // walk upwards until we hit a segment that is still in use, or the root
    while (a.childCount == 0 && a.refCounts[STYLE_TOP] == 0 && a.refCounts[STYLE_FRAME] == 0 && a.parent != null) {
        a.parent.childCount -= 1;
        delete a.parent.children[a.segment];
        a = a.parent;
    }
}

// return all subdomains with a reference, including the domain itself
exports.DomainTree.prototype.allSubDomains = function(domain, node) {
    var subdomains = [];
    if (node == undefined) {
        // top call
        node = this.get(domain);
        if (node == undefined) return undefined;
        if (node.refCounts[STYLE_TOP] > 0 || node.refCounts[STYLE_FRAME] > 0) subdomains = [domain];
    }

    for (var c in node.children) {
        if (node.children[c].refCounts[STYLE_TOP] > 0 || node.children[c].refCounts[STYLE_FRAME] > 0) subdomains.push(c + "." + domain);
        subdomains = subdomains.concat(this.allSubDomains(c + "." + domain, node.children[c]));
    }

    return subdomains;
}

// return true iff the domain has no references
exports.DomainTree.prototype.allZero = function(domain) {
    var a = this.get(domain);
    if (a == undefined) return undefined;
    return (a.refCounts[STYLE_TOP] == 0 && a.refCounts[STYLE_FRAME] == 0);
}

// count and return the number of all domain segments in the tree
exports.DomainTree.prototype.countDomains = function(node) {
    var count = 0;
    if (node == undefined) {
        // top call, let's not count the empty root node
        count = -1;
        node = this.root;
    }

    for (var c in node.children) {
        count += this.countDomains(node.children[c]);
    }

    return count + 1;
}

// the closest node we have to the argument segment list
exports.DomainTree.prototype.closestAncestor = function(segments) {
    var x = this.root;
    var i = 0;
    while (x.children[segments[i]] != undefined) {
        x = x.children[segments[i]];
        i += 1;
    }
    return [x, i];
}

// create a new empty domain object
exports.DomainTree.prototype.makeDomain = function(parent, segment) {
    return {
        children: {},
        childCount: 0,
        parent: parent,
        segment: segment,
        refCounts: [0, 0],
        toString: function() {
            var s = "";
            for (var i in this.children) {
                s = s + i + "[" + this.children[i].refCounts + "]" + this.children[i].toString() + " ";
            }
            return " { "+s+"}";
        }
    };
}

// for debugging
exports.DomainTree.prototype.toString = function() {
    return this.root.toString();
}