From 1d7d45764251147ffd7969851b6a759de3196c55 Mon Sep 17 00:00:00 2001 From: Ibrahim Hasaan Date: Sun, 29 Oct 2023 21:22:46 -0400 Subject: [PATCH 1/5] Adding send message and on message functions --- root-cert-stats/background.js | 9 +++++++++ root-cert-stats/popup.js | 3 +++ 2 files changed, 12 insertions(+) diff --git a/root-cert-stats/background.js b/root-cert-stats/background.js index 24edf50e..15e2559f 100644 --- a/root-cert-stats/background.js +++ b/root-cert-stats/background.js @@ -39,3 +39,12 @@ browser.webRequest.onHeadersReceived.addListener(logRootCert, {urls: [""]}, ["blocking"] ); + +/* +Send the rootCertStats object to popup.js when requested. +*/ +browser.runtime.onMessage.addListener((message, sender, sendResponse) => { + if (message.action === "getRootCertStats") { + sendResponse({ rootCertStats: rootCertStats }); + } +}); diff --git a/root-cert-stats/popup.js b/root-cert-stats/popup.js index a7a582f8..c958ae98 100644 --- a/root-cert-stats/popup.js +++ b/root-cert-stats/popup.js @@ -13,6 +13,9 @@ Each row contains the name of the CA and the number of times it has been used as a trust root. */ if (entries.length > 0) { +browser.runtime.sendMessage({ action: "getRootCertStats" }, response => { + displayTable(response.rootCertStats); +}); let noData = document.querySelector(".no-data"); noData.classList.add("hidden"); From 7d1b798dc729d97ccadbfeb14ca9a6e182cf9428 Mon Sep 17 00:00:00 2001 From: Ibrahim Hasaan Date: Sun, 29 Oct 2023 21:23:31 -0400 Subject: [PATCH 2/5] moving table displaying into a new function --- root-cert-stats/popup.js | 48 +++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/root-cert-stats/popup.js b/root-cert-stats/popup.js index c958ae98..2c44f294 100644 --- a/root-cert-stats/popup.js +++ b/root-cert-stats/popup.js @@ -3,34 +3,36 @@ /* Get the background page to access the rootCertStats object */ -const backgroundPage = browser.extension.getBackgroundPage(); - -let entries = Object.keys(backgroundPage.rootCertStats); - -/* -If there are any stats, show the table, and append one row for each entry. -Each row contains the name of the CA and the number of times it has been -used as a trust root. -*/ -if (entries.length > 0) { browser.runtime.sendMessage({ action: "getRootCertStats" }, response => { displayTable(response.rootCertStats); }); - let noData = document.querySelector(".no-data"); - noData.classList.add("hidden"); - let entryTable = document.querySelector(".root-cert-table"); - entryTable.classList.remove("hidden"); +const backgroundPage = browser.extension.getBackgroundPage(); - for (let entry of entries) { - let entryTR = document.createElement("tr"); - let entryName = document.createElement("td"); - let entryValue = document.createElement("td"); - entryName.textContent = entry; - entryValue.textContent = backgroundPage.rootCertStats[entry]; +function displayTable(rootCertStats) { + /* + If there are any stats, show the table, and append one row for each entry. + Each row contains the name of the CA and the number of times it has been + used as a trust root. + */ + let entries = Object.keys(rootCertStats); - entryTR.appendChild(entryName); - entryTR.appendChild(entryValue); - entryTable.appendChild(entryTR); + if (entries.length > 0) { + let noData = document.querySelector(".no-data"); + noData.classList.add("hidden"); + let entryTable = document.querySelector(".root-cert-table"); + entryTable.classList.remove("hidden"); + + for (let entry of entries) { + let entryTR = document.createElement("tr"); + let entryName = document.createElement("td"); + let entryValue = document.createElement("td"); + entryName.textContent = entry; + entryValue.textContent = rootCertStats[entry]; + + entryTR.appendChild(entryName); + entryTR.appendChild(entryValue); + entryTable.appendChild(entryTR); + } } } From 2f30d297b829d8f47e41c6fff1ee0892aa82473e Mon Sep 17 00:00:00 2001 From: Ibrahim Hasaan Date: Sun, 29 Oct 2023 21:23:51 -0400 Subject: [PATCH 3/5] updating rootCertStats from var to let --- root-cert-stats/background.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/root-cert-stats/background.js b/root-cert-stats/background.js index 15e2559f..abd86bf4 100644 --- a/root-cert-stats/background.js +++ b/root-cert-stats/background.js @@ -3,7 +3,7 @@ // Note: declared with "var" because popup.js references this global variable. // If this were to be declared with "const" or "let", then the variable would // still be available to this file, but not to popup.js. -var rootCertStats = {}; +let rootCertStats = {}; /* On an onHeadersReceived event, if there was a successful TLS connection From 2a9326a125254f27bc3ec35e39ef332893974145 Mon Sep 17 00:00:00 2001 From: Ibrahim Hasaan Date: Sun, 29 Oct 2023 21:24:00 -0400 Subject: [PATCH 4/5] updating comments --- root-cert-stats/background.js | 3 --- root-cert-stats/popup.js | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/root-cert-stats/background.js b/root-cert-stats/background.js index abd86bf4..d60989ea 100644 --- a/root-cert-stats/background.js +++ b/root-cert-stats/background.js @@ -1,8 +1,5 @@ "use strict"; -// Note: declared with "var" because popup.js references this global variable. -// If this were to be declared with "const" or "let", then the variable would -// still be available to this file, but not to popup.js. let rootCertStats = {}; /* diff --git a/root-cert-stats/popup.js b/root-cert-stats/popup.js index 2c44f294..e9ef1694 100644 --- a/root-cert-stats/popup.js +++ b/root-cert-stats/popup.js @@ -1,7 +1,7 @@ "use strict"; /* -Get the background page to access the rootCertStats object +Send message to the background page to get the rootCertStats object */ browser.runtime.sendMessage({ action: "getRootCertStats" }, response => { displayTable(response.rootCertStats); From 9fa1356fb6d9ad10d959f66f873ebbce6bdbfc5a Mon Sep 17 00:00:00 2001 From: rebloor Date: Sun, 5 Nov 2023 06:12:20 +1300 Subject: [PATCH 5/5] Apply Linter change, unused const Co-authored-by: Rob Wu --- root-cert-stats/popup.js | 1 - 1 file changed, 1 deletion(-) diff --git a/root-cert-stats/popup.js b/root-cert-stats/popup.js index e9ef1694..e90d2524 100644 --- a/root-cert-stats/popup.js +++ b/root-cert-stats/popup.js @@ -7,7 +7,6 @@ browser.runtime.sendMessage({ action: "getRootCertStats" }, response => { displayTable(response.rootCertStats); }); -const backgroundPage = browser.extension.getBackgroundPage(); function displayTable(rootCertStats) { /*