toolkit/content/aboutNetworking.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 'use strict';
michael@0 6
michael@0 7 const Ci = Components.interfaces;
michael@0 8 const Cc = Components.classes;
michael@0 9 const Cu = Components.utils;
michael@0 10
michael@0 11 const gDashboard = Cc['@mozilla.org/network/dashboard;1'].
michael@0 12 getService(Ci.nsIDashboard);
michael@0 13 const gPrefs = Cc["@mozilla.org/preferences-service;1"].
michael@0 14 getService(Ci.nsIPrefService).getBranch("network.");
michael@0 15 const gRequestNetworkingData = {
michael@0 16 "http": gDashboard.requestHttpConnections,
michael@0 17 "sockets": gDashboard.requestSockets,
michael@0 18 "dns": gDashboard.requestDNSInfo,
michael@0 19 "websockets": gDashboard.requestWebsocketConnections
michael@0 20 };
michael@0 21 const gDashboardCallbacks = {
michael@0 22 "http": displayHttp,
michael@0 23 "sockets": displaySockets,
michael@0 24 "dns": displayDns,
michael@0 25 "websockets": displayWebsockets
michael@0 26 };
michael@0 27
michael@0 28 const REFRESH_INTERVAL_MS = 3000;
michael@0 29
michael@0 30 function col(element) {
michael@0 31 let col = document.createElement('td');
michael@0 32 let content = document.createTextNode(element);
michael@0 33 col.appendChild(content);
michael@0 34 return col;
michael@0 35 }
michael@0 36
michael@0 37 function displayHttp(data) {
michael@0 38 let cont = document.getElementById('http_content');
michael@0 39 let parent = cont.parentNode;
michael@0 40 let new_cont = document.createElement('tbody');
michael@0 41 new_cont.setAttribute('id', 'http_content');
michael@0 42
michael@0 43 for (let i = 0; i < data.connections.length; i++) {
michael@0 44 let row = document.createElement('tr');
michael@0 45 row.appendChild(col(data.connections[i].host));
michael@0 46 row.appendChild(col(data.connections[i].port));
michael@0 47 row.appendChild(col(data.connections[i].spdy));
michael@0 48 row.appendChild(col(data.connections[i].ssl));
michael@0 49 row.appendChild(col(data.connections[i].active.length));
michael@0 50 row.appendChild(col(data.connections[i].idle.length));
michael@0 51 new_cont.appendChild(row);
michael@0 52 }
michael@0 53
michael@0 54 parent.replaceChild(new_cont, cont);
michael@0 55 }
michael@0 56
michael@0 57 function displaySockets(data) {
michael@0 58 let cont = document.getElementById('sockets_content');
michael@0 59 let parent = cont.parentNode;
michael@0 60 let new_cont = document.createElement('tbody');
michael@0 61 new_cont.setAttribute('id', 'sockets_content');
michael@0 62
michael@0 63 for (let i = 0; i < data.sockets.length; i++) {
michael@0 64 let row = document.createElement('tr');
michael@0 65 row.appendChild(col(data.sockets[i].host));
michael@0 66 row.appendChild(col(data.sockets[i].port));
michael@0 67 row.appendChild(col(data.sockets[i].tcp));
michael@0 68 row.appendChild(col(data.sockets[i].active));
michael@0 69 row.appendChild(col(data.sockets[i].sent));
michael@0 70 row.appendChild(col(data.sockets[i].received));
michael@0 71 new_cont.appendChild(row);
michael@0 72 }
michael@0 73
michael@0 74 parent.replaceChild(new_cont, cont);
michael@0 75 }
michael@0 76
michael@0 77 function displayDns(data) {
michael@0 78 let cont = document.getElementById('dns_content');
michael@0 79 let parent = cont.parentNode;
michael@0 80 let new_cont = document.createElement('tbody');
michael@0 81 new_cont.setAttribute('id', 'dns_content');
michael@0 82
michael@0 83 for (let i = 0; i < data.entries.length; i++) {
michael@0 84 let row = document.createElement('tr');
michael@0 85 row.appendChild(col(data.entries[i].hostname));
michael@0 86 row.appendChild(col(data.entries[i].family));
michael@0 87 let column = document.createElement('td');
michael@0 88
michael@0 89 for (let j = 0; j < data.entries[i].hostaddr.length; j++) {
michael@0 90 column.appendChild(document.createTextNode(data.entries[i].hostaddr[j]));
michael@0 91 column.appendChild(document.createElement('br'));
michael@0 92 }
michael@0 93
michael@0 94 row.appendChild(column);
michael@0 95 row.appendChild(col(data.entries[i].expiration));
michael@0 96 new_cont.appendChild(row);
michael@0 97 }
michael@0 98
michael@0 99 parent.replaceChild(new_cont, cont);
michael@0 100 }
michael@0 101
michael@0 102 function displayWebsockets(data) {
michael@0 103 let cont = document.getElementById('websockets_content');
michael@0 104 let parent = cont.parentNode;
michael@0 105 let new_cont = document.createElement('tbody');
michael@0 106 new_cont.setAttribute('id', 'websockets_content');
michael@0 107
michael@0 108 for (let i = 0; i < data.websockets.length; i++) {
michael@0 109 let row = document.createElement('tr');
michael@0 110 row.appendChild(col(data.websockets[i].hostport));
michael@0 111 row.appendChild(col(data.websockets[i].encrypted));
michael@0 112 row.appendChild(col(data.websockets[i].msgsent));
michael@0 113 row.appendChild(col(data.websockets[i].msgreceived));
michael@0 114 row.appendChild(col(data.websockets[i].sentsize));
michael@0 115 row.appendChild(col(data.websockets[i].receivedsize));
michael@0 116 new_cont.appendChild(row);
michael@0 117 }
michael@0 118
michael@0 119 parent.replaceChild(new_cont, cont);
michael@0 120 }
michael@0 121
michael@0 122 function requestAllNetworkingData() {
michael@0 123 for (let id in gRequestNetworkingData)
michael@0 124 requestNetworkingDataForTab(id);
michael@0 125 }
michael@0 126
michael@0 127 function requestNetworkingDataForTab(id) {
michael@0 128 gRequestNetworkingData[id](gDashboardCallbacks[id]);
michael@0 129 }
michael@0 130
michael@0 131 function init() {
michael@0 132 gDashboard.enableLogging = true;
michael@0 133 if (gPrefs.getBoolPref("warnOnAboutNetworking")) {
michael@0 134 let div = document.getElementById("warning_message");
michael@0 135 div.classList.add("active");
michael@0 136 document.getElementById("confpref").addEventListener("click", confirm);
michael@0 137 }
michael@0 138
michael@0 139 requestAllNetworkingData();
michael@0 140
michael@0 141 let autoRefresh = document.getElementById("autorefcheck");
michael@0 142 if (autoRefresh.checked)
michael@0 143 setAutoRefreshInterval(autoRefresh);
michael@0 144
michael@0 145 autoRefresh.addEventListener("click", function() {
michael@0 146 let refrButton = document.getElementById("refreshButton");
michael@0 147 if (this.checked) {
michael@0 148 setAutoRefreshInterval(this);
michael@0 149 refrButton.disabled = "disabled";
michael@0 150 } else {
michael@0 151 clearInterval(this.interval);
michael@0 152 refrButton.disabled = null;
michael@0 153 }
michael@0 154 });
michael@0 155
michael@0 156 let refr = document.getElementById("refreshButton");
michael@0 157 refr.addEventListener("click", requestAllNetworkingData);
michael@0 158 if (document.getElementById("autorefcheck").checked)
michael@0 159 refr.disabled = "disabled";
michael@0 160
michael@0 161 // Event delegation on #menu element
michael@0 162 let menu = document.getElementById("menu");
michael@0 163 menu.addEventListener("click", function click(e) {
michael@0 164 if (e.target && e.target.parentNode == menu)
michael@0 165 show(e.target);
michael@0 166 });
michael@0 167 }
michael@0 168
michael@0 169 function confirm () {
michael@0 170 let div = document.getElementById("warning_message");
michael@0 171 div.classList.remove("active");
michael@0 172 let warnBox = document.getElementById("warncheck");
michael@0 173 gPrefs.setBoolPref("warnOnAboutNetworking", warnBox.checked);
michael@0 174 }
michael@0 175
michael@0 176 function show(button) {
michael@0 177 let current_tab = document.querySelector(".active");
michael@0 178 let content = document.getElementById(button.value);
michael@0 179 if (current_tab == content)
michael@0 180 return;
michael@0 181 current_tab.classList.remove("active");
michael@0 182 content.classList.add("active");
michael@0 183
michael@0 184 let current_button = document.querySelector(".selected");
michael@0 185 current_button.classList.remove("selected");
michael@0 186 button.classList.add("selected");
michael@0 187
michael@0 188 let autoRefresh = document.getElementById("autorefcheck");
michael@0 189 if (autoRefresh.checked) {
michael@0 190 clearInterval(autoRefresh.interval);
michael@0 191 setAutoRefreshInterval(autoRefresh);
michael@0 192 }
michael@0 193 }
michael@0 194
michael@0 195 function setAutoRefreshInterval(checkBox) {
michael@0 196 let active_tab = document.querySelector(".active");
michael@0 197 checkBox.interval = setInterval(function() {
michael@0 198 requestNetworkingDataForTab(active_tab.id);
michael@0 199 }, REFRESH_INTERVAL_MS);
michael@0 200 }
michael@0 201
michael@0 202 window.addEventListener("DOMContentLoaded", function load() {
michael@0 203 window.removeEventListener("DOMContentLoaded", load);
michael@0 204 init();
michael@0 205 });

mercurial