From e3dcbfc16c23eb8dcdf798d44692e618889d068b Mon Sep 17 00:00:00 2001 From: Valentin Gosu Date: Wed, 7 Aug 2013 20:15:28 -0400 Subject: [PATCH] Bug 865850 - Integrate about:networking into Firefox. r=ttaubert --- browser/app/profile/firefox.js | 3 + docshell/base/nsAboutRedirector.cpp | 2 + docshell/build/nsDocShellModule.cpp | 1 + toolkit/content/aboutNetworking.css | 60 ++++++ toolkit/content/aboutNetworking.js | 174 ++++++++++++++++++ toolkit/content/aboutNetworking.xhtml | 102 ++++++++++ toolkit/content/jar.mn | 3 + .../en-US/chrome/global/aboutNetworking.dtd | 31 ++++ toolkit/locales/jar.mn | 1 + 9 files changed, 377 insertions(+) create mode 100644 toolkit/content/aboutNetworking.css create mode 100644 toolkit/content/aboutNetworking.js create mode 100644 toolkit/content/aboutNetworking.xhtml create mode 100644 toolkit/locales/en-US/chrome/global/aboutNetworking.dtd diff --git a/browser/app/profile/firefox.js b/browser/app/profile/firefox.js index 2a143c12d6a6..f19d33bda7b1 100644 --- a/browser/app/profile/firefox.js +++ b/browser/app/profile/firefox.js @@ -624,6 +624,9 @@ pref("network.protocol-handler.expose.news", false); pref("network.protocol-handler.expose.snews", false); pref("network.protocol-handler.expose.nntp", false); +// Warning for about:networking page +pref("network.warnOnAboutNetworking", true); + pref("accessibility.typeaheadfind", false); pref("accessibility.typeaheadfind.timeout", 5000); pref("accessibility.typeaheadfind.linksonly", false); diff --git a/docshell/base/nsAboutRedirector.cpp b/docshell/base/nsAboutRedirector.cpp index 4ab1ccdd03da..58af8dad3168 100644 --- a/docshell/base/nsAboutRedirector.cpp +++ b/docshell/base/nsAboutRedirector.cpp @@ -65,6 +65,8 @@ static RedirEntry kRedirMap[] = { nsIAboutModule::ALLOW_SCRIPT }, { "telemetry", "chrome://global/content/aboutTelemetry.xhtml", nsIAboutModule::ALLOW_SCRIPT }, + { "networking", "chrome://global/content/aboutNetworking.xhtml", + nsIAboutModule::ALLOW_SCRIPT }, // about:srcdoc is unresolvable by specification. It is included here // because the security manager would disallow srcdoc iframes otherwise. { "srcdoc", "about:blank", diff --git a/docshell/build/nsDocShellModule.cpp b/docshell/build/nsDocShellModule.cpp index 0490f43c448d..791868b24bb6 100644 --- a/docshell/build/nsDocShellModule.cpp +++ b/docshell/build/nsDocShellModule.cpp @@ -183,6 +183,7 @@ const mozilla::Module::ContractIDEntry kDocShellContracts[] = { { NS_ABOUT_MODULE_CONTRACTID_PREFIX "newaddon", &kNS_ABOUT_REDIRECTOR_MODULE_CID }, { NS_ABOUT_MODULE_CONTRACTID_PREFIX "support", &kNS_ABOUT_REDIRECTOR_MODULE_CID }, { NS_ABOUT_MODULE_CONTRACTID_PREFIX "telemetry", &kNS_ABOUT_REDIRECTOR_MODULE_CID }, + { NS_ABOUT_MODULE_CONTRACTID_PREFIX "networking", &kNS_ABOUT_REDIRECTOR_MODULE_CID }, { NS_ABOUT_MODULE_CONTRACTID_PREFIX "srcdoc", &kNS_ABOUT_REDIRECTOR_MODULE_CID }, { NS_URI_LOADER_CONTRACTID, &kNS_URI_LOADER_CID }, { NS_DOCUMENTLOADER_SERVICE_CONTRACTID, &kNS_DOCUMENTLOADER_SERVICE_CID }, diff --git a/toolkit/content/aboutNetworking.css b/toolkit/content/aboutNetworking.css new file mode 100644 index 000000000000..517c2a7c1d5e --- /dev/null +++ b/toolkit/content/aboutNetworking.css @@ -0,0 +1,60 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +body { + min-width: 330px; + max-width: 100%; + min-height: 330px; + max-height: 100%; +} + +#menu { + position: absolute; + top: 5px; + color: gray; +} + +.warningBackground { + display: none; + background: -moz-Dialog; + width:100%; + height:100%; + z-index:10; + top:0; + left:0; + position:fixed; +} + +.warningMessage { + color: -moz-FieldText; + position: relative; + min-width: 330px; + max-width: 50em; + margin: 4em auto; + border: 1px solid ThreeDShadow; + border-radius: 10px; + padding: 3em; + -moz-padding-start: 30px; + background: -moz-Field; + margin-left: auto; + text-align: center; +} + +.tab { + display: none; +} + +.active { + display: block; +} + +#menu .selected { + color: blue; +} + +#refreshdiv { + top: 5px; + position: absolute; + right: 30px; +} diff --git a/toolkit/content/aboutNetworking.js b/toolkit/content/aboutNetworking.js new file mode 100644 index 000000000000..da6e352e1e8c --- /dev/null +++ b/toolkit/content/aboutNetworking.js @@ -0,0 +1,174 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +'use strict'; + +const Ci = Components.interfaces; +const Cc = Components.classes; +const Cu = Components.utils; + +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 REFRESH_INTERVAL_MS = 3000; + +function col(element) { + let col = document.createElement('td'); + let content = document.createTextNode(element); + col.appendChild(content); + return col; +} + +function displayHttp(data) { + let cont = document.getElementById('http_content'); + let parent = cont.parentNode; + let new_cont = document.createElement('tbody'); + new_cont.setAttribute('id', 'http_content'); + + for (let i = 0; i < data.host.length; i++) { + let row = document.createElement('tr'); + row.appendChild(col(data.host[i])); + row.appendChild(col(data.port[i])); + row.appendChild(col(data.spdy[i])); + row.appendChild(col(data.ssl[i])); + row.appendChild(col(data.active[i].rtt.length)); + row.appendChild(col(data.idle[i].rtt.length)); + new_cont.appendChild(row); + } + + parent.replaceChild(new_cont, cont); +} + +function displaySockets(data) { + let cont = document.getElementById('sockets_content'); + let parent = cont.parentNode; + let new_cont = document.createElement('tbody'); + new_cont.setAttribute('id', 'sockets_content'); + + for (let i = 0; i < data.host.length; i++) { + let row = document.createElement('tr'); + row.appendChild(col(data.host[i])); + row.appendChild(col(data.port[i])); + row.appendChild(col(data.tcp[i])); + row.appendChild(col(data.active[i])); + row.appendChild(col(data.socksent[i])); + row.appendChild(col(data.sockreceived[i])); + new_cont.appendChild(row); + } + + parent.replaceChild(new_cont, cont); +} + +function displayDns(data) { + let cont = document.getElementById('dns_content'); + let parent = cont.parentNode; + let new_cont = document.createElement('tbody'); + new_cont.setAttribute('id', 'dns_content'); + + for (let i = 0; i < data.hostname.length; i++) { + let row = document.createElement('tr'); + row.appendChild(col(data.hostname[i])); + row.appendChild(col(data.family[i])); + let column = document.createElement('td'); + + for (let j = 0; j< data.hostaddr[i].length; j++) { + column.appendChild(document.createTextNode(data.hostaddr[i][j])); + column.appendChild(document.createElement('br')); + } + + row.appendChild(column); + row.appendChild(col(data.expiration[i])); + new_cont.appendChild(row); + } + + parent.replaceChild(new_cont, cont); +} + +function displayWebsockets(data) { + let cont = document.getElementById('websockets_content'); + let parent = cont.parentNode; + let new_cont = document.createElement('tbody'); + new_cont.setAttribute('id', 'websockets_content'); + + for (let i = 0; i < data.hostport.length; i++) { + let row = document.createElement('tr'); + row.appendChild(col(data.hostport[i])); + row.appendChild(col(data.encrypted[i])); + row.appendChild(col(data.msgsent[i])); + row.appendChild(col(data.msgreceived[i])); + row.appendChild(col(data.sentsize[i])); + row.appendChild(col(data.receivedsize[i])); + new_cont.appendChild(row); + } + + parent.replaceChild(new_cont, cont); +} + +function requestNetworkingData() { + gDashboard.requestSockets(displaySockets); + gDashboard.requestHttpConnections(displayHttp); + gDashboard.requestWebsocketConnections(displayWebsockets); + gDashboard.requestDNSInfo(displayDns); +} + +function init() { + gDashboard.enableLogging = true; + if (gPrefs.getBoolPref("warnOnAboutNetworking")) { + let div = document.getElementById("warning_message"); + div.classList.add("active"); + document.getElementById("confpref").addEventListener("click", confirm); + } + + requestNetworkingData(); + + document.getElementById("autorefcheck").addEventListener("click", function() { + let refrButton = document.getElementById("refreshButton"); + if (this.checked) { + this.interval = setInterval(requestNetworkingData, REFRESH_INTERVAL_MS); + refrButton.disabled = "disabled"; + } else { + clearInterval(this.interval); + refrButton.disabled = null; + } + }); + + let refr = document.getElementById("refreshButton"); + refr.addEventListener("click", requestNetworkingData); + if (document.getElementById("autorefcheck").checked) + refr.disabled = "disabled"; + + // Event delegation on #menu element + let menu = document.getElementById("menu"); + menu.addEventListener("click", function click(e) { + if (e.target) + show(e.target); + }); +} + +function confirm () { + let div = document.getElementById("warning_message"); + div.classList.remove("active"); + let warnBox = document.getElementById("warncheck"); + gPrefs.setBoolPref("warnOnAboutNetworking", warnBox.checked); +} + +function show(button) { + let current_tab = document.querySelector(".active"); + let content = document.getElementById(button.value); + if (current_tab == content) + return; + current_tab.classList.remove("active"); + content.classList.add("active"); + + let current_button = document.querySelector(".selected"); + current_button.classList.remove("selected"); + button.classList.add("selected"); +} + +window.addEventListener("DOMContentLoaded", function load() { + window.removeEventListener("DOMContentLoaded", load); + init(); +}); diff --git a/toolkit/content/aboutNetworking.xhtml b/toolkit/content/aboutNetworking.xhtml new file mode 100644 index 000000000000..d1c0203aeda9 --- /dev/null +++ b/toolkit/content/aboutNetworking.xhtml @@ -0,0 +1,102 @@ + + + + + %htmlDTD; + %globalDTD; + %brandDTD; + %networkingDTD; +]> + + + + &aboutNetworking.title; + + +