update Panel via nsIWebProgressListener; cleanup

This commit is contained in:
Garrett Robinson 2014-06-17 16:12:27 +02:00
Родитель f7d5143e6d
Коммит 5897dbe511
3 изменённых файлов: 38 добавлений и 15 удалений

Просмотреть файл

@ -4,7 +4,13 @@ document.querySelector("a#openGlobalTab").addEventListener("click", function() {
self.port.emit("openGlobalTab", {});
});
self.port.on('change', function onChange(wInfo) {
console.log("Panel switches to aggregate for " + wInfo.host);
});
/*
self.port.on("winInfo", function(winInfo) {
console.log("host", winInfo.host);
console.log("connections", winInfo.connections);
});
*/

Просмотреть файл

@ -31,7 +31,8 @@ events.on("http-on-examine-response", function (subject) {
addConnection(connection);
// Pass the message on to the UI
ui.emitForWorker('connection', connection.toLog());
ui.updateWindow(subject);
// Update the connections list for this specific window
ui.updateWindow(subject, connection);
}
}, true);

Просмотреть файл

@ -291,10 +291,17 @@ lbPanel.port.on("openGlobalTab", function() {
});
function handleOnShow() {
// TODO: fill in (send data to the content script so it can render the panel)
// This code updates the panel when it is opened. Unfortunately, this leads
// to a perciptible delay between the user seeing the panel and seeing the
// fully rendered visualization. A better technique is to update the Panel
// in the background, using the nsIWebProgressListener.
//
// However, this code is instructive so it's left in for now, commented out.
/*
let topContentWindow = utils.getMostRecentContentWindow();
let winInfo = windowsMap.get(topContentWindow, {});
let winInfo = windowMap.get(topContentWindow, {});
lbPanel.port.emit("winInfo", winInfo);
*/
};
let button;
@ -344,30 +351,39 @@ if (usingAustralis) {
/**
* Track the connections graph for each open window
*/
let windowsMap = new WeakMap();
let windowMap = new WeakMap();
let updateWindowsMap = function(aWin) {
let updateWindowMap = function(aWin) {
// We received a location change for this window. This could be from a page
// load in a new nsIDOMWindow or an existing one. Either way, we reset the
// associated data structures so they always reflect the most recent load.
// TODO is this always correct? what about iframes?
aWin = aWin.top;
windowsMap.set(aWin, {
windowMap.set(aWin, {
host: aWin.location.host,
connections: []
});
// Update the panel for the current location
// TODO use the Aggregate, instead of a connection list
// XXX what's the best way to maintain the aggregates between the
// add-on's windowMap and the Panel?
let wInfo = windowMap.get(aWin);
lbPanel.port.emit('change', wInfo);
};
let updateWindow = function(event) {
let updateWindow = function(event, connection) {
// Determine the corresponding window for the channel
let chan = event.subject.QueryInterface(Ci.nsIHttpChannel);
let chanWin = utils.getTopWindowForChannel(chan);
if (windowsMap.has(chanWin)) {
if (windowMap.has(chanWin)) {
console.log("Got a load with an associated window, updating the connections list");
let winObj = windowsMap.get(chanWin);
// TODO: What should be stored here? URI, or origin? Timestamp? Type of request?
winObj.connections.push(chan.URI.host);
windowsMap.set(chanWin, winObj);
} else {
console.log("Got a load WITHOUT an associated window in the window map:", chan.URI);
let wInfo = windowMap.get(chanWin);
// TODO `connections` should be an Aggregate
wInfo.connections.push(connection);
windowMap.set(chanWin, wInfo);
}
};
exports.updateWindow = updateWindow;
@ -385,7 +401,7 @@ let LBListener = Class({
!(aFlags === Ci.nsIWebProgressListener.LOCATION_CHANGE_SAME_DOCUMENT)) {
console.log("GOT LOCATION CHANGE: " + aURI.spec);
let win = aProgress.DOMWindow;
updateWindowsMap(win);
updateWindowMap(win);
}
},