зеркало из https://github.com/mozilla/lightbeam.git
Issue 35 - picture-in-picture can now be turned on via pref; it will pop up a panel in the center of the window whenever new connections are added to the graph. I'd prefer to have it in the corner instead of centered but Jetpack's panel API doesn't support that yet.
This commit is contained in:
Родитель
61d610ba0d
Коммит
07fcece4c8
|
@ -45,3 +45,9 @@ self.port.on("getSavedGraph", function(saved_graph) {
|
|||
self.port.emit('import', saved_graph);
|
||||
window.location.reload();
|
||||
});
|
||||
|
||||
self.port.on("setPanelSize", function(data) {
|
||||
if (unsafeWindow.makeGraphSizedToPanel) {
|
||||
unsafeWindow.makeGraphSizedToPanel(data);
|
||||
}
|
||||
});
|
|
@ -9,7 +9,8 @@ var CollusionAddon = (function() {
|
|||
saveGraph: window.saveGraph,
|
||||
getSavedGraph: window.getSavedGraph,
|
||||
blockDomain: window.blockDomain,
|
||||
whitelistDomain: window.whitelistDomain
|
||||
whitelistDomain: window.whitelistDomain,
|
||||
getPanelDimensions: window.getPanelDimensions
|
||||
};
|
||||
|
||||
return self;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
|
||||
<html> <head>
|
||||
<link href="index.css" rel="stylesheet" type="text/css"/>
|
||||
<link href="panel.css" rel="stylesheet" type="text/css"/>
|
||||
|
||||
<script src="d3.js"></script>
|
||||
<script src="d3.layout.js"></script>
|
||||
|
@ -25,27 +26,42 @@ function getJsonNoMatterWhat(url, callback) {
|
|||
}});
|
||||
}
|
||||
|
||||
$(window).ready(function() {
|
||||
console.log("Window ready");
|
||||
// This will be called in response to a message from the add-on when the add-on opens the panel
|
||||
// addon will calculate the size and tell us what size the panel should be
|
||||
function makeGraphSizedToPanel(data) {
|
||||
var addon = CollusionAddon;
|
||||
console.log("Addon is " + addon);
|
||||
// get list of known trackers from trackers.json file hosted on website:
|
||||
if (!data.width || !data.height) {
|
||||
return;
|
||||
}
|
||||
$("#panel-message").html(data.message);
|
||||
$("#chart").empty();
|
||||
getJsonNoMatterWhat("trackers.json", function(trackers) {
|
||||
console.log("Got trackers json");
|
||||
|
||||
var runner = GraphRunner.Runner({
|
||||
width: 500,
|
||||
height: 400,
|
||||
width: data.width,
|
||||
height: data.height,
|
||||
trackers: trackers,
|
||||
hideFavicons: false
|
||||
});
|
||||
|
||||
addon.onGraph(runner.updateGraph);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/* OK we have two problems:
|
||||
* 1. querying the window size always gives me 100 pixels regardless of actual panel size.
|
||||
* No matter what size I tell chart to be, it ends up being 100 pixels across too!!
|
||||
* IDE/Theory: when addon opens panel, it sends a panel size message to worker threads; recieve
|
||||
* that message inside the panel and use it to set some variables
|
||||
|
||||
* 2. GraphRunner.Runner is not resizable... make it so.
|
||||
* (Working around this by destroying old one, creating new one - makes graph regenerate)
|
||||
*/
|
||||
</script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div id="chart" width="500" height="400"></div>
|
||||
|
||||
<span id="panel-message">This is Collusion</span>
|
||||
<div id="chart" width="100%" height="100%"></div>
|
||||
</body> </html>
|
||||
|
|
34
lib/main.js
34
lib/main.js
|
@ -3,9 +3,11 @@ var prefs = require('simple-prefs').prefs;
|
|||
var url = require('url');
|
||||
var data = require("self").data;
|
||||
var tabs = require("tabs");
|
||||
var timers = require("timers");
|
||||
var privateBrowsing = require("private-browsing");
|
||||
var storage = require("simple-storage").storage;
|
||||
|
||||
// APIs not yet exposed through Jetpack libraries:
|
||||
var {Cc, Ci, Cr} = require('chrome');
|
||||
var eTLDSvc = Cc["@mozilla.org/network/effective-tld-service;1"].
|
||||
getService(Ci.nsIEffectiveTLDService);
|
||||
|
@ -13,7 +15,8 @@ var ioService = Cc["@mozilla.org/network/io-service;1"]
|
|||
.getService(Ci.nsIIOService);
|
||||
var cookieMgr = Cc["@mozilla.org/cookiemanager;1"]
|
||||
.getService(Ci.nsICookieManager2);
|
||||
|
||||
var windowMediator = Cc["@mozilla.org/appshell/window-mediator;1"].
|
||||
getService(Ci.nsIWindowMediator);
|
||||
|
||||
// Global variables:
|
||||
var deployment = {};
|
||||
|
@ -101,6 +104,22 @@ function attachToExistingCollusionPages() {
|
|||
});
|
||||
}
|
||||
|
||||
function showCollusionPanel() {
|
||||
// Open panel whenever new site is added to the graph...
|
||||
if (!collusionPanel.isShowing) {
|
||||
var frontWind = windowMediator.getMostRecentWindow("navigator:browser");
|
||||
var size = parseFloat(prefs["collusion.popup.size"]);
|
||||
var w = frontWind.innerWidth * size;
|
||||
var h = frontWind.innerHeight * size;
|
||||
var m = prefs["collusion.popup.message"];
|
||||
collusionPanel.resize(w, h);
|
||||
collusionPanel.show();
|
||||
workers.forEach(function(worker) {
|
||||
worker.port.emit("setPanelSize", {width: w, height: h, message: m});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function queueInfo(info) {
|
||||
var newSite = false;
|
||||
if (!(info.domain in log)) {
|
||||
|
@ -118,10 +137,7 @@ function queueInfo(info) {
|
|||
}
|
||||
|
||||
if (newSite && prefs["collusion.popup"]) {
|
||||
// Open panel whenever new site is added to the graph...
|
||||
if (!collusionPanel.isShowing) {
|
||||
collusionPanel.show();
|
||||
}
|
||||
showCollusionPanel();
|
||||
}
|
||||
|
||||
var types = referrers[info.referrer];
|
||||
|
@ -365,6 +381,14 @@ function initCollusion() {
|
|||
|
||||
// If any collusion UI pages are already open when we start, connect to them:
|
||||
attachToExistingCollusionPages();
|
||||
|
||||
// Init reset timer
|
||||
if (prefs["collusion.reset.timer"] > 0) {
|
||||
timers.setInterval(function() {
|
||||
startTime = new Date();
|
||||
log = {};
|
||||
}, prefs["collusion.reset.timer"]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
18
package.json
18
package.json
|
@ -25,6 +25,24 @@
|
|||
"title": "Always show graph in popup panel when new sites are added",
|
||||
"type": "bool",
|
||||
"value": false
|
||||
},
|
||||
{
|
||||
"name": "collusion.popup.size",
|
||||
"title": "Size of popup panel (as fraction of size of window)",
|
||||
"type": "string",
|
||||
"value": "0.5"
|
||||
},
|
||||
{
|
||||
"name": "collusion.popup.message",
|
||||
"title": "Message in popup panel",
|
||||
"type": "string",
|
||||
"value": "These sites are using third-party cookies to share data about your web activity."
|
||||
},
|
||||
{
|
||||
"name": "collusion.reset.timer",
|
||||
"title": "Time between automatic resets (milliseconds) - 0 for no reset",
|
||||
"type": "integer",
|
||||
"value": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче