@@ -30,11 +30,13 @@ var log = {};
30
30
// Array to maintain connections to any pages running collusion UI:
31
31
var workers = [ ] ;
32
32
33
+ // Whitelist of sites that user has told us they don't care about tracking them:
34
+ var whitelist = [ ] ;
35
+
33
36
var startTime = new Date ( ) ;
34
37
var collusionPanel = null ;
35
38
36
39
37
-
38
40
function attachToCollusionPage ( worker ) {
39
41
/* Set up channel of communcation between this add-on and the script (index-content-script.js)
40
42
* that we attached to the web page running the Collusion UI. */
@@ -78,6 +80,12 @@ function attachToCollusionPage(worker) {
78
80
startTime = new Date ( ) - maxTime ;
79
81
log = graph ;
80
82
} ) ;
83
+ worker . port . on ( "blockDomain" , function ( data ) {
84
+ blockDomain ( data . domain ) ;
85
+ } ) ;
86
+ worker . port . on ( "whitelistDomain" , function ( data ) {
87
+ whitelistDomain ( data . domain ) ;
88
+ } ) ;
81
89
}
82
90
83
91
@@ -138,6 +146,57 @@ function getDomain(host) {
138
146
}
139
147
}
140
148
149
+ function blockDomain ( domain ) {
150
+ console . log ( "Blocking domain " + domain ) ;
151
+ deleteNode ( domain ) ;
152
+ // Clear all current cookies to this domain, and block them so they don't come back
153
+ // TODO: are we blocking cookies TO this domain or blocking cookies FROM this domain?
154
+ var cookieEnumerator = cookieMgr . getCookiesFromHost ( ) ;
155
+ while ( cookieEnumerator . hasMoreElements ( ) ) {
156
+ var cookie = cookieEnumerator . getNext ( ) . QueryInterface ( Ci . nsICookie2 ) ;
157
+ cookieMgr . remove ( cookie . host , cookie . name , cookie . path , true ) ;
158
+ // The final true argument means cookies from this host are permanently blocked
159
+ // TODO does this also block first-party cookies? we don't want that.
160
+ // Look into nsICookiePermission...
161
+ }
162
+
163
+ /* See https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsICookieManager2#getCookiesFromHost%28%29
164
+ * and see https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsICookieManager
165
+ */
166
+ }
167
+
168
+ function whitelistDomain ( domain ) {
169
+ console . log ( "Whitelisting domain " + domain ) ;
170
+ deleteNode ( domain ) ;
171
+ whitelist . push ( domain ) ; // TODO TEST
172
+ storage . whitelist = whitelist ;
173
+ }
174
+
175
+ function deleteNode ( nodeDomain ) {
176
+ for ( var domain in log ) {
177
+ if ( log [ domain ] . referrers [ nodeDomain ] ) {
178
+ console . log ( "Removed link to " + domain + " from " + nodeDomain ) ;
179
+ delete log [ domain ] . referrers [ nodeDomain ] ;
180
+ }
181
+ }
182
+ if ( log [ nodeDomain ] ) {
183
+ delete log [ nodeDomain ] ;
184
+ console . log ( "Removed all links to " + nodeDomain ) ;
185
+ }
186
+
187
+ /* TODO it doesn't look like sending the newly-reduced log back to graphrunner.js
188
+ * does anything - even though I call node.exit().remove(), I think the way the data is passed
189
+ * around over there (it was not expected for nodes to ever leave the graph, seems like) means
190
+ * that nothing is removed. However, reloading the page results in a graph without the removed
191
+ * node, so that much at least works.
192
+ */
193
+
194
+ workers . forEach ( function ( worker ) {
195
+ worker . port . emit ( "log" , JSON . stringify ( log ) ) ;
196
+ } ) ;
197
+ }
198
+
199
+
141
200
// Main entry point. Will be called when Firefox starts or when Collusion is installed:
142
201
function initCollusion ( ) {
143
202
@@ -178,7 +237,7 @@ function initCollusion() {
178
237
} ) ;
179
238
180
239
// Set up the status bar button to open the main UI page:
181
- require ( "widget" ) . Widget ( {
240
+ var widget = require ( "widget" ) . Widget ( {
182
241
id : "collusion" ,
183
242
label : "Display Collusion Diagram" ,
184
243
contentURL : data . url ( "favicon.ico" ) ,
@@ -192,6 +251,12 @@ function initCollusion() {
192
251
log = JSON . parse ( storage . graph ) ;
193
252
}
194
253
254
+ // Load any whitelist we have stored from last time
255
+ if ( storage . whitelist ) {
256
+ whitelist = JSON . parse ( storage . whitelist ) ;
257
+ }
258
+
259
+
195
260
// Set up an observer to record third-party cookies. This callback
196
261
// right here is the crux of Collusion.
197
262
obSvc . add ( "http-on-examine-response" , function ( subject , topic , data ) {
@@ -207,6 +272,10 @@ function initCollusion() {
207
272
if ( channel . referrer . host in baseHosts )
208
273
return ;
209
274
275
+ // Ignore cookies from whitelisted sites. TODO: Or is that cookies TO whitelisted sites?
276
+ if ( channel . referrer . host in whitelist )
277
+ return ;
278
+
210
279
if ( domain != referrerDomain ) {
211
280
try {
212
281
type = subject . getResponseHeader ( "Content-Type" ) ;
@@ -298,5 +367,7 @@ function initCollusion() {
298
367
attachToExistingCollusionPages ( ) ;
299
368
}
300
369
370
+
301
371
// Start!
302
- initCollusion ( ) ;
372
+ initCollusion ( ) ;
373
+
0 commit comments