Bug 905325 - about:networking tab auto-refresh, global refresh button. r=ttaubert

This commit is contained in:
Robert Bindar 2013-08-26 11:27:28 -04:00
parent f8985f80ad
commit a91c08b8d1

View File

@ -12,6 +12,18 @@ const gDashboard = Cc['@mozilla.org/network/dashboard;1'].
getService(Ci.nsIDashboard);
const gPrefs = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefService).getBranch("network.");
const gRequestNetworkingData = {
"http": gDashboard.requestHttpConnections,
"sockets": gDashboard.requestSockets,
"dns": gDashboard.requestDNSInfo,
"websockets": gDashboard.requestWebsocketConnections
};
const gDashboardCallbacks = {
"http": displayHttp,
"sockets": displaySockets,
"dns": displayDns,
"websockets": displayWebsockets
};
const REFRESH_INTERVAL_MS = 3000;
@ -107,11 +119,13 @@ function displayWebsockets(data) {
parent.replaceChild(new_cont, cont);
}
function requestNetworkingData() {
gDashboard.requestSockets(displaySockets);
gDashboard.requestHttpConnections(displayHttp);
gDashboard.requestWebsocketConnections(displayWebsockets);
gDashboard.requestDNSInfo(displayDns);
function requestAllNetworkingData() {
for (let id in gRequestNetworkingData)
requestNetworkingDataForTab(id);
}
function requestNetworkingDataForTab(id) {
gRequestNetworkingData[id](gDashboardCallbacks[id]);
}
function init() {
@ -122,12 +136,16 @@ function init() {
document.getElementById("confpref").addEventListener("click", confirm);
}
requestNetworkingData();
requestAllNetworkingData();
document.getElementById("autorefcheck").addEventListener("click", function() {
let autoRefresh = document.getElementById("autorefcheck");
if (autoRefresh.checked)
setAutoRefreshInterval(autoRefresh);
autoRefresh.addEventListener("click", function() {
let refrButton = document.getElementById("refreshButton");
if (this.checked) {
this.interval = setInterval(requestNetworkingData, REFRESH_INTERVAL_MS);
setAutoRefreshInterval(this);
refrButton.disabled = "disabled";
} else {
clearInterval(this.interval);
@ -136,7 +154,7 @@ function init() {
});
let refr = document.getElementById("refreshButton");
refr.addEventListener("click", requestNetworkingData);
refr.addEventListener("click", requestAllNetworkingData);
if (document.getElementById("autorefcheck").checked)
refr.disabled = "disabled";
@ -166,6 +184,19 @@ function show(button) {
let current_button = document.querySelector(".selected");
current_button.classList.remove("selected");
button.classList.add("selected");
let autoRefresh = document.getElementById("autorefcheck");
if (autoRefresh.checked) {
clearInterval(autoRefresh.interval);
setAutoRefreshInterval(autoRefresh);
}
}
function setAutoRefreshInterval(checkBox) {
let active_tab = document.querySelector(".active");
checkBox.interval = setInterval(function() {
requestNetworkingDataForTab(active_tab.id);
}, REFRESH_INTERVAL_MS);
}
window.addEventListener("DOMContentLoaded", function load() {