Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firefox MV3 Migration #462

Merged
merged 17 commits into from
May 22, 2024
Prev Previous commit
Next Next commit
Website response changes
  • Loading branch information
OliverWang13 committed May 4, 2024
commit 0d7e86c4dc1cd719f02e8ba96e7db921e7ed705e
4 changes: 4 additions & 0 deletions src/background/protection/listeners-firefox.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function enableListeners(callbacks) {
onHeadersReceived,
onBeforeNavigate,
onCommitted,
onCompleted,
} = callbacks;

// (4) global Firefox listeners
Expand All @@ -47,6 +48,7 @@ function enableListeners(callbacks) {
);
chrome.webNavigation.onBeforeNavigate.addListener(onBeforeNavigate);
chrome.webNavigation.onCommitted.addListener(onCommitted);
chrome.webNavigation.onCompleted.addListener(onCompleted);
}

/**
Expand All @@ -58,12 +60,14 @@ function disableListeners(callbacks) {
onHeadersReceived,
onBeforeNavigate,
onCommitted,
onCompleted,
} = callbacks;

chrome.webRequest.onBeforeSendHeaders.removeListener(onBeforeSendHeaders);
chrome.webRequest.onHeadersReceived.removeListener(onHeadersReceived);
chrome.webNavigation.onBeforeNavigate.removeListener(onBeforeNavigate);
chrome.webNavigation.onCommitted.removeListener(onCommitted);
chrome.webNavigation.onCompleted.removeListener(onCompleted);
}

export { enableListeners, disableListeners };
73 changes: 46 additions & 27 deletions src/background/protection/protection.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,17 @@ const listenerCallbacks = {
* @param {object} details - retrieved info passed into callback
* @returns {array}
*/
onBeforeSendHeaders: (details) => {
updateDomainlist(details);
onBeforeSendHeaders: async (details) => {
await updateDomainlist(details);
},

/**
* @param {object} details - retrieved info passed into callback
*/
onHeadersReceived: (details) => {
logData(details);
onHeadersReceived: async (details) => {
await logData(details);



},

Expand All @@ -94,8 +96,12 @@ const listenerCallbacks = {
* @param {object} details - retrieved info passed into callback
*/
onCommitted: async (details) => {
updateDomainlist(details);
await updateDomainlist(details);
},
onCompleted: async (details) => {
await sendData();
}

}; // closes listenerCallbacks object

/******************************************************************************/
Expand All @@ -105,6 +111,35 @@ const listenerCallbacks = {
/******************************************************************************/


async function sendData(){
let currentDomain = await getCurrentParsedDomain();
// console.log("activeTabID: ",activeTabID);
// console.log("DP3P: ", domPrev3rdParties);
console.log("tabs: ", tabs);
let info = await tabs[activeTabID]["REQUEST_DOMAINS"];
let data = Object.keys(info);
console.log("test test1: ", tabs[activeTabID]);
console.log("test test2: ", tabs[activeTabID]["REQUEST_DOMAINS"]);
console.log("test test3: ", tabs[activeTabID]["REQUEST_DOMAINS"][currentDomain]);

console.log("keys test: ", Object.keys(tabs[activeTabID]["REQUEST_DOMAINS"]));

//initialize the objects
// if (!(activeTabID in domPrev3rdParties)){
// domPrev3rdParties[activeTabID] = {};
// }
// if (!(currentDomain in domPrev3rdParties[activeTabID]) ){
// domPrev3rdParties[activeTabID][currentDomain] = {};
// }
// //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(data);
console.log("setting to storage under ", currentDomain, ": ", data);
await storage.set(stores.thirdParties, data, currentDomain);
}


function getCurrentParsedDomain() {
return new Promise((resolve, reject) => {
try {
Expand Down Expand Up @@ -144,27 +179,6 @@ async function updateDomainlist(details) {
}

//get the current parsed domain--this is used to store 3rd parties (using globalParsedDomain variable)

let currentDomain = await getCurrentParsedDomain();
// console.log("activeTabID: ",activeTabID);
// console.log("DP3P: ", domPrev3rdParties);
console.log("tabs: ", tabs);
let info = tabs[activeTabID]["REQUEST_DOMAINS"];
let data = Object.keys(info);

//initialize the objects
// if (!(activeTabID in domPrev3rdParties)){
// domPrev3rdParties[activeTabID] = {};
// }
// if (!(currentDomain in domPrev3rdParties[activeTabID]) ){
// domPrev3rdParties[activeTabID][currentDomain] = {};
// }
// //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(data);
console.log("setting to storage under ", currentDomain, ": ", data);
await storage.set(stores.thirdParties, data, currentDomain);

}

Expand All @@ -175,7 +189,7 @@ function updatePopupIcon(tabId) {
});
}

function logData(details) {
async function logData(details) {
let url = new URL(details.url);
let parsed = psl.parse(url.hostname);

Expand Down Expand Up @@ -425,6 +439,11 @@ async function onMessageHandlerAsync(message, sender, sendResponse) {
wellknown[tabID] = message.data;
let wellknownData = message.data;

console.log("setting WKD at ", domain, ": ", wellknownData);
await storage.set(stores.wellknownInformation, wellknownData, domain);

//await sendData();

initIAB(!sendSignal);

if (wellknown[tabID] === null && sendSignal == null) {
Expand Down
2 changes: 2 additions & 0 deletions src/background/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const stores = Object.freeze({
settings: "SETTINGS",
domainlist: "DOMAINLIST",
thirdParties: "THIRDPARTIES",
wellknownInformation: "WELLKNOWNDATA",
});

/******************************************************************************/
Expand All @@ -38,6 +39,7 @@ const dbPromise = openDB("extensionDB", 1, {
db.createObjectStore(stores.domainlist);
db.createObjectStore(stores.settings);
db.createObjectStore(stores.thirdParties);
db.createObjectStore(stores.wellknownInformation);
},
});

Expand Down
7 changes: 5 additions & 2 deletions src/popup/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,15 @@ async function showProtectionInfo() {

let domain = await getCurrentParsedDomain();
let parties = await storage.get(stores.thirdParties, domain);
let wellknown = await storage.get(stores.wellknownInformation, domain);
//parties = JSON.parse(parties);
console.log("parties under ", domain, ": ", parties);

let requestsData = parties;
console.log("request data: ", requestsData);
buildDomains(requestsData);
buildWellKnown(wellknown);



// chrome.runtime.sendMessage({
Expand Down Expand Up @@ -667,8 +670,8 @@ chrome.runtime.onMessage.addListener(function (message, _, __) {
console.log("info received PPD");
domainsInfo = requests;
wellknownInfo = wellknown;
buildDomains(requests);
buildWellKnown(wellknown);
//buildDomains(requests);
//buildWellKnown(wellknown);
}
if (message.msg === "POPUP_PROTECTION_DATA_REQUESTS") {
console.log("info received PPDR");
Expand Down