Bug 1379927 - Make sure init gets called when about:networking is loaded from the bfcache r=jaws
authorValentin Gosu <valentin.gosu@gmail.com>
Wed, 12 Jul 2017 15:03:18 +0200
changeset 368405 50bb4bb1902f84a7335754f62e7a124ca9b5c732
parent 368404 960a0dc9092fdba8ef5a367a42ddb3f9a3ec3398
child 368406 b688e3b2b82be84285f0c8c268b31ab87298d680
push id92473
push uservalentin.gosu@gmail.com
push dateWed, 12 Jul 2017 13:03:35 +0000
treeherdermozilla-inbound@50bb4bb1902f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs1379927
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1379927 - Make sure init gets called when about:networking is loaded from the bfcache r=jaws MozReview-Commit-ID: 8DdhaEm88Nb
toolkit/content/aboutNetworking.js
--- a/toolkit/content/aboutNetworking.js
+++ b/toolkit/content/aboutNetworking.js
@@ -170,17 +170,22 @@ function requestAllNetworkingData() {
   for (let id in gRequestNetworkingData)
     requestNetworkingDataForTab(id);
 }
 
 function requestNetworkingDataForTab(id) {
   gRequestNetworkingData[id](gDashboardCallbacks[id]);
 }
 
+let gInited = false;
 function init() {
+  if (gInited) {
+    return;
+  }
+  gInited = true;
   gDashboard.enableLogging = true;
   if (Services.prefs.getBoolPref("network.warnOnAboutNetworking")) {
     let div = document.getElementById("warning_message");
     div.classList.add("active");
     div.hidden = false;
     document.getElementById("confpref").addEventListener("click", confirm);
   }
 
@@ -427,19 +432,23 @@ function show(button) {
 
 function setAutoRefreshInterval(checkBox) {
   let active_tab = document.querySelector(".active");
   checkBox.interval = setInterval(function() {
     requestNetworkingDataForTab(active_tab.id);
   }, REFRESH_INTERVAL_MS);
 }
 
-window.addEventListener("DOMContentLoaded", function() {
+// We use the pageshow event instead of onload. This is needed because sometimes
+// the page is loaded via session-restore/bfcache. In such cases we need to call
+// init() to keep the page behaviour consistent with the ticked checkboxes.
+// Mostly the issue is with the autorefresh checkbox.
+window.addEventListener("pageshow", function() {
   init();
-}, {once: true});
+});
 
 function doLookup() {
   let host = document.getElementById("host").value;
   if (host) {
     gDashboard.requestDNSLookup(host, displayDNSLookup);
   }
 }