Skip to content

Commit

Permalink
some storage changes
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverWang13 committed Apr 10, 2024
1 parent ab05898 commit c6b6f8e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/background/protection/protection.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ async function updateDomainlist(details) {
let currDomainValue = await storage.get(stores.domainlist, parsedDomain);

if (currDomainValue === undefined) {
storage.set(stores.domainlist, null, parsedDomain); // Sets to storage async
await storage.set(stores.domainlist, null, parsedDomain); // Sets to storage async
}

//get the current parsed domain--this is used to store 3rd parties (using globalParsedDomain variable)
Expand All @@ -155,6 +155,11 @@ async function updateDomainlist(details) {
}
//as they come in, add the parsedDomain to the object with null value (just a placeholder)
domPrev3rdParties[activeTabID][currentDomain][parsedDomain] = null;

let data = JSON.stringify(domPrev3rdParties);
console.log("setting to storage: ", data);
await storage.set(stores.thirdParties, data, "parties");

}

function updatePopupIcon(tabId) {
Expand Down Expand Up @@ -282,20 +287,25 @@ function handleSendMessageError() {
console.warn(error.message);
}
}
function dataToPopupHelper(){
async function dataToPopupHelper(){
//data gets sent back every time the popup is clicked
let requestsData = {};

if (tabs[activeTabID] !== undefined) {

requestsData = domPrev3rdParties[activeTabID][globalParsedDomain];
let domain = await getCurrentParsedDomain();
let parties = await storage.get(stores.thirdParties, "parties");
parties = JSON.parse(parties);
console.log("parties: ", parties[activeTabID][domain]);

requestsData = parties[activeTabID][domain];
console.log("request data: ", requestsData);
}
return requestsData
}

// Info back to popup
function dataToPopup(wellknownData) {
let requestsData = dataToPopupHelper(); //get requests from the helper
async function dataToPopup(wellknownData) {
let requestsData = await dataToPopupHelper(); //get requests from the helper
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
let popupData = {
requests: requestsData,
Expand All @@ -312,9 +322,9 @@ function dataToPopup(wellknownData) {
});
}

function dataToPopupRequests() {
async function dataToPopupRequests() {

let requestsData = dataToPopupHelper(); //get requests from the helper
let requestsData = await dataToPopupHelper(); //get requests from the helper

chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
chrome.runtime.sendMessage(
Expand Down Expand Up @@ -388,6 +398,7 @@ async function onMessageHandlerAsync(message, sender, sendResponse) {
storage.set(stores.domainlist, key, domain); // Sets to long term storage
}
if (message.msg === "POPUP_PROTECTION_REQUESTS") {
console.log("info queried");
dataToPopupRequests();
}
if (message.msg === "CONTENT_SCRIPT_WELLKNOWN") {
Expand Down
2 changes: 2 additions & 0 deletions src/background/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const { saveAs } = pkg;
const stores = Object.freeze({
settings: "SETTINGS",
domainlist: "DOMAINLIST",
thirdParties: "THIRDPARTIES",
});

/******************************************************************************/
Expand All @@ -36,6 +37,7 @@ const dbPromise = openDB("extensionDB", 1, {
upgrade: function dbPromiseInternal(db) {
db.createObjectStore(stores.domainlist);
db.createObjectStore(stores.settings);
db.createObjectStore(stores.thirdParties);
},
});

Expand Down
1 change: 1 addition & 0 deletions src/popup/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ async function buildWellKnown(requests) {
chrome.runtime.onMessage.addListener(function (message, _, __) {
if (message.msg === "POPUP_PROTECTION_DATA") {
let { requests, wellknown } = message.data;
console.log("info received");
domainsInfo = requests;
wellknownInfo = wellknown;
buildDomains(requests);
Expand Down

0 comments on commit c6b6f8e

Please sign in to comment.