Skip to content

Commit b1e0713

Browse files
Jeroen EvensManvel
authored andcommitted
Cookie whitelist (#31)
* added whitelist to cookie deletion logic on startup removed standard cookie deletion and replaced it with a loop deleting all cookies not found in whitelist storage of list and UI still needed * added cookieWhitelist for getting and setting whitelist * added button to add cookiedomain + name to whitelist added image to represent whitelist button add update whitelist with cookiedomain change delete info to detect whitelisted cookies properly TODO: fix button styling TODO: fix button if whitelisted TODO: remove from whitelist if clicked on button of whitelisted cookie-whitelist TODO: don't place duplicate whitelist items TODO: make whitelist a dictionary instead of an array * implement feedback making whitelist into a dict removing item from whitelist if clicked on button of whitelisted item changing location of cookie deletion on startup (not only deleted if delete all option is set) * fixing setting cookiewhitelist dict on startup refactoring code to extract cookiedeletion to separate function fixing dictionary handling in deletecookie method rewriting whitelist to cookie comparison logic making logic more compact * updated code to reuse the delete cookie logic on cookie tab * allowing whitelisting of domains fixing logic that removes item from whitelist updating code to use includes instead of indexOf >=0 replace regex dot removal with function * fixup! added whitelist to cookie deletion logic on startup * fixup! fixing setting cookiewhitelist dict on startup refactoring code to extract cookiedeletion to separate function fixing dictionary handling in deletecookie method rewriting whitelist to cookie comparison logic making logic more compact * improved code based on feedback changed structure of cookiewhitelist adapted whitelisting and deleting logic accordingly * update UI to update whitelist code for both domain and sublist cookies * update whitelist ckeckbox for subitems adding logic to update whitelist checkboxes on tab load and on domain cookie load * added validation before updating sublist items fixing buttons to image in view instead of using switches updating css to fix scaling of buttons * moved check for new whitelist data outside of the updateWhitelistInList method cleaned up calls to updateWhitelistInList * filter out unchanged domains and cookies from whitelist before modifying tree * moved filtering of cookiewhitelistchanges out of updateWhitelistInList logic fixed up code updated getcookies to only update whitelist status for that domain * fix issue deleting whitelist fix error on opening cookies from domain without data in whitelist * adding message for whitelist buttons adding data-i18n to button * reducing complexity of method checking changes in whitelist * fix spaces and whitelist icon size * fixing title message displayed when hovering over whitelist button * update version in manifest * adding constant for whitelistbutton titles and added comment for createDomainObj
1 parent 0b1c06e commit b1e0713

10 files changed

Lines changed: 262 additions & 37 deletions

File tree

_locales/en_US/messages.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,14 @@
355355
"description": "text in Cookies 'delete all' dialog",
356356
"message": "You are about to delete all cookies, are you sure ?"
357357
},
358+
"whitelistCookieDomain": {
359+
"description": "text when hovering over Whitelist button for Cookie Domain",
360+
"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"
361+
},
362+
"whitelistSublistCookie": {
363+
"description": "text when hovering over Whitelist button for Sublist Cookies",
364+
"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"
365+
},
358366
"additionalPermissions": {
359367
"description": "Label for requesting additional permission setting",
360368
"message": "Additional permissions"

css/img/check-mark-circle.svg

Lines changed: 1 addition & 0 deletions
Loading

css/img/check-mark-filled.svg

Lines changed: 1 addition & 0 deletions
Loading

css/main.css

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,10 @@ button[role="checkbox"][aria-checked="true"] > span:last-child
288288
#dialog[data-dialog="cookie-edit"] #dialog-content-cookie-form,
289289
#dialog[data-dialog="cookies-delete-all"] #dialog-content-cookie-delete-all,
290290
#dialog[data-dialog="setting-info"] #dialog-content-setting-info
291+
{
292+
display: block;
293+
}#dialog[data-dialog="cookies-delete-all"] #dialog-content-cookie-delete-all,
294+
#dialog[data-dialog="setting-info"] #dialog-content-setting-info
291295
{
292296
display: block;
293297
}
@@ -527,6 +531,34 @@ button.icon.edit:after
527531
background-image: url(/css/img/edit.svg);
528532
}
529533

534+
.tableList > li > div .icon.whitelist::after
535+
{
536+
background-image: url(/css/img/check-mark-circle.svg);
537+
background-size: 100%;
538+
background-repeat: no-repeat;
539+
}
540+
541+
.tableList li > ul li > div .icon.whitelist::after
542+
{
543+
background-image: url(/css/img/check-mark-circle.svg);
544+
background-size: 100%;
545+
background-repeat: no-repeat;
546+
}
547+
548+
.tableList > li[data-whitelist="true"] > div .icon.whitelist::after
549+
{
550+
background-image: url(/css/img/check-mark-filled.svg);
551+
background-size: 100%;
552+
background-repeat: no-repeat;
553+
}
554+
555+
.tableList li > ul li[data-whitelist="true"] > div .icon.whitelist::after
556+
{
557+
background-image: url(/css/img/check-mark-filled.svg);
558+
background-size: 100%;
559+
background-repeat: no-repeat;
560+
}
561+
530562
button.icon.edit:hover:after
531563
{
532564
background-image: url(/css/img/edit-hover.svg);

js/back.js

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,22 @@
2323
global.collectedRequests = [];
2424
const requestCollectionLength = 500;
2525

26-
function profileStart()
27-
{
28-
getStorage("settingList", function(data)
26+
function profileStart() {
27+
getStorage("cookieWhitelist", function (data)
28+
{
29+
if (!data || !data.cookieWhitelist)
30+
{
31+
setStorage({"cookieWhitelist": {} })
32+
}
33+
})
34+
getStorage("settingList", function (data)
2935
{
3036
deleteBrowsingData(data.settingList);
3137
});
3238
}
3339

3440
//TODO: Find a solution to avoide duplication
35-
getStorage("settingList", function(data)
41+
getStorage("settingList", function (data)
3642
{
3743
if (data.settingList && data.settingList.collectHeaders)
3844
startCollectingRequests();
@@ -41,90 +47,98 @@
4147
addBlockAgentListener();
4248
});
4349

44-
function deleteBrowsingData(data)
50+
function deleteBrowsingData(data)
4551
{
4652
if (!data)
4753
return;
4854

4955
// Filter "data" object to only match properties from "browsingData".
50-
var browsingDataObj = Object.keys(data).filter(function(key)
56+
var browsingDataObj = Object.keys(data).filter(function (key)
5157
{
5258
return browsingData.includes(key);
53-
}).reduce(function(accumulator, dataType)
59+
}).reduce(function (accumulator, dataType)
5460
{
5561
accumulator[dataType] = data[dataType];
5662
return accumulator;
5763
}, {});
5864

59-
if (browsingDataObj.removeAll == true)
65+
if (browsingDataObj.removeAll == true)
6066
{
61-
var browsingDataObj = browsingData.reduce(function(accumulator, dataType)
67+
var browsingDataObj = browsingData.reduce(function (accumulator, dataType)
6268
{
6369
if (dataType != "removeAll")
6470
accumulator[dataType] = true;
6571

6672
return accumulator;
6773
}, {});
74+
75+
if (browsingDataObj.cookies)
76+
{
77+
deleteCookies()
78+
}
79+
browsingDataObj.cookies = false;
6880
chrome.browsingData.remove({}, browsingDataObj);
6981
}
70-
else
71-
{
72-
delete browsingDataObj.removeAll;
82+
else {
83+
if (browsingDataObj.cookies)
84+
{
85+
deleteCookies()
86+
}
87+
browsingDataObj.cookies = false;
7388
chrome.browsingData.remove({}, browsingDataObj);
7489
}
7590
}
7691

77-
global.startCollectingRequests = function()
92+
global.startCollectingRequests = function ()
7893
{
7994
addRequestListener(onSendHeaders, onHeadersReceived);
8095
};
8196

82-
global.stopCollectingRequests = function()
97+
global.stopCollectingRequests = function ()
8398
{
8499
removeRequestListener(onSendHeaders, onHeadersReceived);
85100
};
86101

87-
function onSendHeaders(details)
102+
function onSendHeaders(details)
88103
{
89104
updateRequestObj(details, "send");
90105
addToRequestArray(details);
91106
}
92107

93-
function onHeadersReceived(details)
108+
function onHeadersReceived(details)
94109
{
95110
updateRequestObj(details, "receive");
96111
addToRequestArray(details);
97112
}
98113

99-
function addToRequestArray(details)
114+
function addToRequestArray(details)
100115
{
101-
if(collectedRequests.length > requestCollectionLength)
116+
if (collectedRequests.length > requestCollectionLength)
102117
collectedRequests.shift();
103118

104119
collectedRequests.push(details);
105120
}
106121

107-
chrome.storage.onChanged.addListener(function(change)
122+
chrome.storage.onChanged.addListener(function (change)
108123
{
109-
if (change.settingList)
110-
{
111-
chrome.permissions.contains(additionalPermission, function(result)
124+
if (change.settingList) {
125+
chrome.permissions.contains(additionalPermission, function (result)
112126
{
113127
var newValue = change.settingList.newValue.collectHeaders;
114128
var oldValue = change.settingList.oldValue;
115-
if (oldValue && newValue != oldValue.collectHeaders)
129+
if (oldValue && newValue != oldValue.collectHeaders)
116130
{
117-
if(result && newValue)
131+
if (result && newValue)
118132
startCollectingRequests();
119133
else
120134
stopCollectingRequests();
121135
}
122136

123137
var newValue = change.settingList.newValue.blockUserAgent;
124138
var oldValue = change.settingList.oldValue;
125-
if (oldValue && newValue != oldValue.blockUserAgent)
139+
if (oldValue && newValue != oldValue.blockUserAgent)
126140
{
127-
if(result && newValue)
141+
if (result && newValue)
128142
addBlockAgentListener();
129143
else
130144
removeBlockAgentListener();
@@ -133,12 +147,13 @@
133147
}
134148
});
135149

136-
chrome.permissions.onRemoved.addListener(function(result)
137-
{
150+
chrome.permissions.onRemoved.addListener(function (result)
151+
{
138152
removeBlockAgentListener();
139153
removeRequestListener(onSendHeaders, onHeadersReceived);
140154
});
141155

142156
// Fired on a profile start up
157+
chrome.runtime.onInstalled.addListener(profileStart);
143158
chrome.runtime.onStartup.addListener(profileStart);
144159
})(this);

js/common.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ const browsingData = ["removeAll", "appcache", "cache", "cookies", "downloads",
2626
"fileSystems", "formData", "history", "indexedDB",
2727
"localStorage", "serverBoundCertificates", "passwords",
2828
"pluginData", "serviceWorkers", "webSQL"];
29+
const getAllCookies = chrome.cookies.getAll;
30+
const removeCookie = chrome.cookies.remove;
2931

3032
function getStorage(keys, callback)
3133
{
@@ -38,6 +40,10 @@ function setStorage(items, callback)
3840
chrome.storage.local.set(items, callback);
3941
}
4042

43+
function getUrl(domain, path, isSecure)
44+
{
45+
return "http" + (isSecure ? "s" : "") + "://" + domain + path;
46+
}
4147
function addRequestListener(onSendHeadersCallback, onHeadersReceivedCallback)
4248
{
4349
chrome.webRequest.onSendHeaders.addListener(onSendHeadersCallback,
@@ -84,3 +90,31 @@ function blockUserAgent(details)
8490
}
8591
return {requestHeaders: details.requestHeaders};
8692
}
93+
94+
function removeStartDot(string)
95+
{
96+
return string.replace(/^\./, "");
97+
}
98+
99+
function deleteCookies()
100+
{
101+
// delete cookies here + ignore whitelisted cookies
102+
getStorage("cookieWhitelist", function (data)
103+
{
104+
let domainList = data.cookieWhitelist
105+
getAllCookies({}, function (cookies)
106+
{
107+
let callbackCount = 0;
108+
for (let cookie of cookies)
109+
{
110+
let url = getUrl(cookie.domain, cookie.path, cookie.secure);
111+
// replace leading dots sometimes present in cookie domains
112+
let domainWhitelist = domainList[removeStartDot(cookie.domain)]
113+
if (!domainWhitelist || (!domainWhitelist.cookies.includes(cookie.name) && !domainWhitelist.domainWhitelist))
114+
{
115+
removeCookie({ "url": url, "name": cookie.name });
116+
}
117+
}
118+
});
119+
});
120+
}

js/ui/common.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,13 @@ TableList.prototype._updateListElem = function(itemObj, listElem)
709709
if (textElement)
710710
textElement.textContent = textsObj[name];
711711
}
712+
var titleObjs = itemObj.titles;
713+
for (var title in titleObjs)
714+
{
715+
var titleElement = listElem.querySelector("[data-text='"+ title +"']");
716+
if (titleElement)
717+
titleElement.title = titleObjs[title];
718+
}
712719

713720
// Set default tabindex to the first list Element
714721
if (this.listElem.childElementCount == 0)

0 commit comments

Comments
 (0)