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

Cookie whitelist #31

Merged
merged 23 commits into from
Jan 6, 2019
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
739abd6
added whitelist to cookie deletion logic on startup
jeroenev Nov 5, 2018
b7ed06d
added cookieWhitelist for getting and setting whitelist
jeroenev Nov 5, 2018
623f4fc
added button to add cookiedomain + name to whitelist
jeroenev Nov 6, 2018
1813414
implement feedback
jeroenev Nov 7, 2018
d2e5df1
fixing setting cookiewhitelist dict on startup
jeroenev Nov 21, 2018
c87944f
updated code to reuse the delete cookie logic on cookie tab
jeroenev Nov 21, 2018
9e406e5
allowing whitelisting of domains
jeroenev Nov 21, 2018
9e2c93b
fixup! added whitelist to cookie deletion logic on startup
jeroenev Nov 22, 2018
9e66b77
fixup! fixing setting cookiewhitelist dict on startup refactoring cod…
jeroenev Nov 22, 2018
3ae061a
improved code based on feedback
jeroenev Nov 24, 2018
aa943ba
update UI to update whitelist code for both domain and sublist cookies
jeroenev Nov 28, 2018
43a8e39
update whitelist ckeckbox for subitems
jeroenev Nov 29, 2018
a4bd548
added validation before updating sublist items
jeroenev Dec 1, 2018
70ec957
moved check for new whitelist data outside of the updateWhitelistInLi…
jeroenev Dec 1, 2018
c031845
filter out unchanged domains and cookies from whitelist before modify…
jeroenev Dec 1, 2018
076e9d9
moved filtering of cookiewhitelistchanges out of updateWhitelistInLis…
jeroenev Dec 1, 2018
558603e
fix issue deleting whitelist
jeroenev Dec 4, 2018
a9bda9e
adding message for whitelist buttons
jeroenev Dec 4, 2018
39df11d
reducing complexity of method checking changes in whitelist
jeroenev Dec 8, 2018
6037a4a
fix spaces and whitelist icon size
jeroenev Dec 16, 2018
d0da771
fixing title message displayed when hovering over whitelist button
jeroenev Dec 29, 2018
018daa0
update version in manifest
jeroenev Dec 29, 2018
db2c87c
adding constant for whitelistbutton titles and added comment for crea…
jeroenev Jan 6, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions _locales/en_US/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,14 @@
"description": "text in Cookies 'delete all' dialog",
"message": "You are about to delete all cookies, are you sure ?"
},
"whitelistCookieDomain": {
"description": "text when hovering over Whitelist button for Cookie Domain",
"message": "This button adds all cookies from a domain to a Whitelist, preventing them from being automatically deleted, usefull if you want to stay logged in to some websites but still want all other cookies to be deleted"
},
"whitelistSublistCookie": {
"description": "text when hovering over Whitelist button for Sublist Cookies",
"message": "This button adds a specific cookie to a Whitelist, preventing them from being automatically deleted, usefull if you want to stay logged in to some websites but still want all other cookies to be deleted"
},
"additionalPermissions": {
"description": "Label for requesting additional permission setting",
"message": "Additional permissions"
Expand Down
1 change: 1 addition & 0 deletions css/img/check-mark-circle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions css/img/check-mark-filled.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ button[role="checkbox"][aria-checked="true"] > span:last-child
#dialog[data-dialog="cookie-edit"] #dialog-content-cookie-form,
#dialog[data-dialog="cookies-delete-all"] #dialog-content-cookie-delete-all,
#dialog[data-dialog="setting-info"] #dialog-content-setting-info
{
display: block;
}#dialog[data-dialog="cookies-delete-all"] #dialog-content-cookie-delete-all,
#dialog[data-dialog="setting-info"] #dialog-content-setting-info
{
display: block;
}
Expand Down Expand Up @@ -527,6 +531,34 @@ button.icon.edit:after
background-image: url(/css/img/edit.svg);
}

.tableList > li > div .icon.whitelist::after
{
background-image: url(/css/img/check-mark-circle.svg);
background-size: 100%;
background-repeat: no-repeat;
}

.tableList li > ul li > div .icon.whitelist::after
{
background-image: url(/css/img/check-mark-circle.svg);
background-size: 100%;
background-repeat: no-repeat;
}

.tableList > li[data-whitelist="true"] > div .icon.whitelist::after
{
background-image: url(/css/img/check-mark-filled.svg);
background-size: 100%;
background-repeat: no-repeat;
}

.tableList li > ul li[data-whitelist="true"] > div .icon.whitelist::after
{
background-image: url(/css/img/check-mark-filled.svg);
background-size: 100%;
background-repeat: no-repeat;
}

button.icon.edit:hover:after
{
background-image: url(/css/img/edit-hover.svg);
Expand Down
71 changes: 43 additions & 28 deletions js/back.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,22 @@
global.collectedRequests = [];
const requestCollectionLength = 500;

function profileStart()
{
getStorage("settingList", function(data)
function profileStart() {
getStorage("cookieWhitelist", function (data)
{
if (!data || !data.cookieWhitelist)
{
setStorage({"cookieWhitelist": {} })
}
})
getStorage("settingList", function (data)
{
deleteBrowsingData(data.settingList);
});
}

//TODO: Find a solution to avoide duplication
getStorage("settingList", function(data)
getStorage("settingList", function (data)
{
if (data.settingList && data.settingList.collectHeaders)
startCollectingRequests();
Expand All @@ -41,90 +47,98 @@
addBlockAgentListener();
});

function deleteBrowsingData(data)
function deleteBrowsingData(data)
{
if (!data)
return;

// Filter "data" object to only match properties from "browsingData".
var browsingDataObj = Object.keys(data).filter(function(key)
var browsingDataObj = Object.keys(data).filter(function (key)
{
return browsingData.includes(key);
}).reduce(function(accumulator, dataType)
}).reduce(function (accumulator, dataType)
{
accumulator[dataType] = data[dataType];
return accumulator;
}, {});

if (browsingDataObj.removeAll == true)
if (browsingDataObj.removeAll == true)
{
var browsingDataObj = browsingData.reduce(function(accumulator, dataType)
var browsingDataObj = browsingData.reduce(function (accumulator, dataType)
{
if (dataType != "removeAll")
accumulator[dataType] = true;

return accumulator;
}, {});

if (browsingDataObj.cookies)
{
deleteCookies()
}
browsingDataObj.cookies = false;
chrome.browsingData.remove({}, browsingDataObj);
}
else
{
delete browsingDataObj.removeAll;
else {
if (browsingDataObj.cookies)
{
deleteCookies()
}
browsingDataObj.cookies = false;
chrome.browsingData.remove({}, browsingDataObj);
}
}

global.startCollectingRequests = function()
global.startCollectingRequests = function ()
{
addRequestListener(onSendHeaders, onHeadersReceived);
};

global.stopCollectingRequests = function()
global.stopCollectingRequests = function ()
{
removeRequestListener(onSendHeaders, onHeadersReceived);
};

function onSendHeaders(details)
function onSendHeaders(details)
{
updateRequestObj(details, "send");
addToRequestArray(details);
}

function onHeadersReceived(details)
function onHeadersReceived(details)
{
updateRequestObj(details, "receive");
addToRequestArray(details);
}

function addToRequestArray(details)
function addToRequestArray(details)
{
if(collectedRequests.length > requestCollectionLength)
if (collectedRequests.length > requestCollectionLength)
collectedRequests.shift();

collectedRequests.push(details);
}

chrome.storage.onChanged.addListener(function(change)
chrome.storage.onChanged.addListener(function (change)
{
if (change.settingList)
{
chrome.permissions.contains(additionalPermission, function(result)
if (change.settingList) {
chrome.permissions.contains(additionalPermission, function (result)
{
var newValue = change.settingList.newValue.collectHeaders;
var oldValue = change.settingList.oldValue;
if (oldValue && newValue != oldValue.collectHeaders)
if (oldValue && newValue != oldValue.collectHeaders)
{
if(result && newValue)
if (result && newValue)
startCollectingRequests();
else
stopCollectingRequests();
}

var newValue = change.settingList.newValue.blockUserAgent;
var oldValue = change.settingList.oldValue;
if (oldValue && newValue != oldValue.blockUserAgent)
if (oldValue && newValue != oldValue.blockUserAgent)
{
if(result && newValue)
if (result && newValue)
addBlockAgentListener();
else
removeBlockAgentListener();
Expand All @@ -133,12 +147,13 @@
}
});

chrome.permissions.onRemoved.addListener(function(result)
{
chrome.permissions.onRemoved.addListener(function (result)
{
removeBlockAgentListener();
removeRequestListener(onSendHeaders, onHeadersReceived);
});

// Fired on a profile start up
chrome.runtime.onInstalled.addListener(profileStart);
chrome.runtime.onStartup.addListener(profileStart);
})(this);
34 changes: 34 additions & 0 deletions js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const browsingData = ["removeAll", "appcache", "cache", "cookies", "downloads",
"fileSystems", "formData", "history", "indexedDB",
"localStorage", "serverBoundCertificates", "passwords",
"pluginData", "serviceWorkers", "webSQL"];
const getAllCookies = chrome.cookies.getAll;
const removeCookie = chrome.cookies.remove;

function getStorage(keys, callback)
{
Expand All @@ -38,6 +40,10 @@ function setStorage(items, callback)
chrome.storage.local.set(items, callback);
}

function getUrl(domain, path, isSecure)
{
return "http" + (isSecure ? "s" : "") + "://" + domain + path;
}
function addRequestListener(onSendHeadersCallback, onHeadersReceivedCallback)
{
chrome.webRequest.onSendHeaders.addListener(onSendHeadersCallback,
Expand Down Expand Up @@ -84,3 +90,31 @@ function blockUserAgent(details)
}
return {requestHeaders: details.requestHeaders};
}

function removeStartDot(string)
{
return string.replace(/^\./, "");
}

function deleteCookies()
{
// delete cookies here + ignore whitelisted cookies
getStorage("cookieWhitelist", function (data)
{
let domainList = data.cookieWhitelist
getAllCookies({}, function (cookies)
{
let callbackCount = 0;
for (let cookie of cookies)
{
let url = getUrl(cookie.domain, cookie.path, cookie.secure);
// replace leading dots sometimes present in cookie domains
let domainWhitelist = domainList[removeStartDot(cookie.domain)]
if (!domainWhitelist || (!domainWhitelist.cookies.includes(cookie.name) && !domainWhitelist.domainWhitelist))
{
removeCookie({ "url": url, "name": cookie.name });
}
}
});
});
}
7 changes: 7 additions & 0 deletions js/ui/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,13 @@ TableList.prototype._updateListElem = function(itemObj, listElem)
if (textElement)
textElement.textContent = textsObj[name];
}
var titleObjs = itemObj.titles;
for (var title in titleObjs)
{
var titleElement = listElem.querySelector("[data-text='"+ title +"']");
if (titleElement)
titleElement.title = titleObjs[title];
}

// Set default tabindex to the first list Element
if (this.listElem.childElementCount == 0)
Expand Down
Loading