зеркало из https://github.com/mozilla/lightbeam.git
Merge branch 'c2_fresh_start' of https://github.com/mozilla/collusion into c2_fresh_start
This commit is contained in:
Коммит
e2b79ada25
|
@ -21,8 +21,10 @@ const TARGET_SUB = 10;
|
|||
const METHOD = 11;
|
||||
const STATUS = 12;
|
||||
const CACHEABLE = 13;
|
||||
const FROM_PRIVATE_MODE = 14;
|
||||
|
||||
window.addEventListener('load', function(evt){
|
||||
addon.emit("privateWindowCheck");
|
||||
// Wire up events
|
||||
document.querySelector('.btn_group.visualization').click();
|
||||
document.querySelector('[data-value=' + (localStorage.visualization || 'Graph') + ']').click();
|
||||
|
@ -38,6 +40,18 @@ window.addEventListener('beforeunload', function(){
|
|||
}, false);
|
||||
|
||||
|
||||
addon.on("isPrivateWindow", function(isPrivate){
|
||||
if ( !localStorage.privateBrowsingMsgShown ){
|
||||
if ( isPrivate ){
|
||||
alert("You've launched Collusion in a Private Browsing Window. Data collected under Private Browsing Windows will not be perserved or stored. It will not appear again once the Window is close.");
|
||||
}else{
|
||||
alert("Data collected under Private Browsing Windows will not be perserved or stored. It will not appear again once the Collusion tab is close.");
|
||||
}
|
||||
}
|
||||
|
||||
localStorage.privateBrowsingMsgShown = true;
|
||||
});
|
||||
|
||||
function initCap(str){
|
||||
return str[0].toUpperCase() + str.slice(1);
|
||||
}
|
||||
|
@ -67,14 +81,14 @@ function switchVisualization(name){
|
|||
function saveConnections(){
|
||||
if ( localStorage.connections && localStorage.connections != "[]" ){
|
||||
var lastSaved = localStorage.lastSaved || 0;
|
||||
var connections = allConnections.filter(function(connection){
|
||||
return ( connection[TIMESTAMP] ) > lastSaved;
|
||||
var connections = excludePrivateConnection(allConnections).filter(function(connection){
|
||||
return ( connection[TIMESTAMP] > lastSaved);
|
||||
});
|
||||
if ( connections.length > 0 ){
|
||||
localStorage.connections = localStorage.connections.slice(0,-1) + "," + JSON.stringify(connections).slice(1);
|
||||
}
|
||||
}else{
|
||||
localStorage.connections = JSON.stringify(allConnections);
|
||||
localStorage.connections = JSON.stringify( excludePrivateConnection(allConnections) );
|
||||
}
|
||||
localStorage.lastSaved = Date.now();
|
||||
localStorage.totalNumConnections = JSON.parse(localStorage.connections).length;
|
||||
|
|
|
@ -19,7 +19,8 @@ self.port.on('init', function(collusionToken){
|
|||
localStorage.collusionToken = collusionToken;
|
||||
|
||||
if (unsafeWindow && unsafeWindow.currentVisualization){
|
||||
if ( localStorage.connections && localStorage.connections != "[]" ){
|
||||
if ( unsafeWindow.allConnections.length == 0 ){ // when the addon is initialized
|
||||
localStorage.connections = localStorage.connections || "[]";
|
||||
unsafeWindow.allConnections = JSON.parse(localStorage.connections);
|
||||
}
|
||||
unsafeWindow.currentVisualization.emit('init', unsafeWindow.allConnections);
|
||||
|
@ -28,21 +29,26 @@ self.port.on('init', function(collusionToken){
|
|||
}
|
||||
});
|
||||
|
||||
self.port.on("passTempConnections", function(message){
|
||||
localStorage.tempConnections = JSON.stringify(message);
|
||||
const FROM_PRIVATE_MODE = 14;
|
||||
|
||||
self.port.on("passTempConnections", function(connReceived){
|
||||
// connReceived can be an empty array [] or an array of connection arrays [ [], [], [] ]
|
||||
localStorage.tempConnections = JSON.stringify(connReceived);
|
||||
self.port.emit("tempConnectionTransferred", true);
|
||||
|
||||
var allConnectionsAsArray = connReceived;
|
||||
localStorage.lastSaved = Date.now();
|
||||
|
||||
if ( localStorage.connections && localStorage.connections != "[]" ){
|
||||
var allConnectionsAsString = localStorage.connections.slice(0,-1) + "," + localStorage.tempConnections.slice(1);
|
||||
localStorage.connections = allConnectionsAsString;
|
||||
unsafeWindow.allConnections = JSON.parse(allConnectionsAsString);
|
||||
}else{
|
||||
var parsedTempConnections = localStorage.tempConnections ? JSON.parse(localStorage.tempConnections) : [ [] ] ;
|
||||
localStorage.connections = localStorage.tempConnections;
|
||||
unsafeWindow.allConnections = parsedTempConnections;
|
||||
allConnectionsAsArray = JSON.parse(allConnectionsAsString);
|
||||
}
|
||||
var allNonPrivateConnections = allConnectionsAsArray.filter(function(connection){
|
||||
return (connection[FROM_PRIVATE_MODE] == null);
|
||||
});
|
||||
localStorage.connections = JSON.stringify(allNonPrivateConnections); // do not store connections collected in private mode
|
||||
localStorage.totalNumConnections = unsafeWindow.allConnections.length;
|
||||
unsafeWindow.allConnections = allConnectionsAsArray;
|
||||
});
|
||||
|
||||
|
||||
|
|
18
data/list.js
18
data/list.js
|
@ -107,22 +107,24 @@ function setUnfilteredBreadcrumb(){
|
|||
var text = document.createTextNode("All");
|
||||
link.appendChild(text);
|
||||
breadcrumb.appendChild(link);
|
||||
getSummary(function(result){
|
||||
var summaryDiv = document.createElement("div");
|
||||
var timeSinceText = "Based on the data we have gathered since " + result.localTimeSince + ", ";
|
||||
|
||||
var summaryDiv = document.createElement("div");
|
||||
if ( allConnections.length > 0 ){
|
||||
var timeSinceText = "Based on the data we have gathered since " + new Date(allConnections[0][TIMESTAMP]) + ", ";
|
||||
var timeSinceTextNode = document.createTextNode(timeSinceText);
|
||||
var timeSinceDiv = document.createElement("div");
|
||||
timeSinceDiv.appendChild(timeSinceTextNode);
|
||||
summaryDiv.appendChild(timeSinceDiv);
|
||||
var detailText = result.numConnections + " connections were set between " + (result.numVisited+result.numBoth) + " visited sites and " + (result.numThird+result.numBoth) + " third party sites";
|
||||
var detailText = allConnections.length + " connections were made between " + (aggregate.sitenodes.length+aggregate.bothnodes.length) + " visited sites and " + (aggregate.thirdnodes.length+aggregate.bothnodes.length) + " third party sites";
|
||||
var detailTextNode = document.createTextNode(detailText);
|
||||
var detailDiv = document.createElement("div");
|
||||
detailDiv.appendChild(detailTextNode);
|
||||
summaryDiv.appendChild(detailDiv);
|
||||
|
||||
header.appendChild(summaryDiv);
|
||||
});
|
||||
|
||||
}else{
|
||||
var msg = document.createTextNode("No data has been collected yet.");
|
||||
summaryDiv.appendChild(msg);
|
||||
}
|
||||
header.appendChild(summaryDiv);
|
||||
}
|
||||
|
||||
|
||||
|
|
25
data/ui.js
25
data/ui.js
|
@ -359,21 +359,6 @@ document.querySelector(".settings-page").addEventListener("click", function(even
|
|||
},false);
|
||||
|
||||
|
||||
/* Get data summary =============================== */
|
||||
|
||||
// to be fixed
|
||||
function getSummary(callback){
|
||||
var summary = {};
|
||||
summary.localTimeSince = "(to be fixed)";
|
||||
summary.numConnections = allConnections.length;
|
||||
summary.numAllSites = aggregate.allnodes.length;
|
||||
summary.numVisited = aggregate.sitenodes.length;
|
||||
summary.numThird = aggregate.thirdnodes.length;
|
||||
summary.numBoth = aggregate.bothnodes.length;
|
||||
callback(summary);
|
||||
}
|
||||
|
||||
|
||||
/* Clock View ===================================== */
|
||||
|
||||
function highlightColludedNode(selection){
|
||||
|
@ -433,9 +418,17 @@ function exportFormat(connections){
|
|||
format: 'Collusion Save File',
|
||||
version: '1.1',
|
||||
token: localStorage.collusionToken,
|
||||
connections: connections
|
||||
connections: excludePrivateConnection(connections)
|
||||
});
|
||||
}
|
||||
|
||||
/* Filter out connections collected in Private Mode */
|
||||
function excludePrivateConnection(connections){
|
||||
return connections.filter(function(connection){
|
||||
return (connection[FROM_PRIVATE_MODE] == null);
|
||||
})
|
||||
}
|
||||
|
||||
/* Info Panel Connections List ===================================== */
|
||||
|
||||
document.querySelector(".connections-list ul").addEventListener("click", function(event){
|
||||
|
|
|
@ -46,16 +46,12 @@ console.log('Current capacity is %s% of quota', Math.round(ss.quotaUsage * 100))
|
|||
/* END FLAG PERSISTENCE */
|
||||
|
||||
function addConnection(connection){
|
||||
// console.error("=== addConnection isPrivate = " + connection._sourceTab.isPrivate);
|
||||
Connection.emit("connection", connection.toLog()); // pass connection as array
|
||||
|
||||
if ( ! connection._sourceTab.isPrivate ){ // add it to the simple storage
|
||||
if ( !storage.tempConnections ) storage.tempConnections = [];
|
||||
if ( captureAndStoreConnections ){
|
||||
storage.tempConnections.push(connection.toLog());
|
||||
console.error("=====");
|
||||
console.error(connection.toLog());
|
||||
}
|
||||
if ( !storage.tempConnections ) storage.tempConnections = [];
|
||||
if ( captureAndStoreConnections ){
|
||||
storage.tempConnections.push(connection.toLog());
|
||||
console.error("=====");
|
||||
console.error(connection.toLog());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -228,6 +224,7 @@ Connection.TARGET_SUB = 10;
|
|||
Connection.METHOD = 11;
|
||||
Connection.STATUS = 12;
|
||||
Connection.CACHEABLE = 13;
|
||||
Connection.FROM_PRIVATE_MODE = 14;
|
||||
|
||||
// FIXME: Move data shaping into its own library?
|
||||
/* BEGIN FLAG SERIALIZATION */
|
||||
|
@ -235,7 +232,7 @@ Connection.prototype.toLog = function(){
|
|||
if (!this.valid){
|
||||
throw new Error('Do not log invalid connections: ' + this);
|
||||
}
|
||||
return [
|
||||
var connectionAsArray = [
|
||||
this.source,
|
||||
this.target,
|
||||
this.timestamp.valueOf(),
|
||||
|
@ -251,6 +248,12 @@ Connection.prototype.toLog = function(){
|
|||
this.status,
|
||||
this.cacheable
|
||||
];
|
||||
|
||||
if ( this._sourceTab.isPrivate ){
|
||||
connectionAsArray.push("fromPrivateMode");
|
||||
}
|
||||
|
||||
return connectionAsArray;
|
||||
};
|
||||
|
||||
/* END FLAG SERIALIZATION */
|
||||
|
|
|
@ -109,6 +109,11 @@ function attachToCollusionPage(worker) {
|
|||
|
||||
Connection.on('tempConnections', onTempConnections);
|
||||
|
||||
worker.port.on("privateWindowCheck", function(){
|
||||
var isPrivate = require("private-browsing").isPrivate( getCollusionTab() );
|
||||
worker.port.emit("isPrivateWindow", isPrivate);
|
||||
});
|
||||
|
||||
worker.port.on('uiready', function(){
|
||||
worker.port.emit('log', 'addon received uiready');
|
||||
Connection.on('restored', onRestored);
|
||||
|
|
Загрузка…
Ссылка в новой задаче