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

#303: Reset cookies in site manager #2654

Merged
merged 5 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
20 changes: 16 additions & 4 deletions src/css/popup.css
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ body {

/* Hack for menu icons to use a light color without affecting container icons */
[data-theme="light"] img.delete-assignment,
[data-theme="dark"] img.reset-assignment,
[data-theme="dark"] .trash-button,
[data-theme="dark"] img.menu-icon,
[data-theme="dark"] .menu-icon > img,
Expand Down Expand Up @@ -287,7 +288,7 @@ table {

/* effect borrowed from tabs in firefox, ensure that the element flexes to the full width */
.truncate-text {
inline-size: calc(100vw - 80px);
inline-size: calc(100vw - 100px);
overflow: hidden;
position: relative;
white-space: nowrap;
Expand Down Expand Up @@ -2314,7 +2315,8 @@ input {
* rules grouped together at the beginning of the file
*/
/* stylelint-disable no-descending-specificity */
.trash-button {
.trash-button,
.reset-button {
display: inline-block;
block-size: 20px;
inline-size: 20px;
Expand All @@ -2323,11 +2325,21 @@ input {
text-align: center;
}

tr > td > .trash-button {
.reset-button {
margin-right: 8px;
}

.tooltip-wrapper:hover .site-settings-tooltip {
display: block;
}

tr > td > .trash-button,
tr > td > .reset-button {
display: none;
}

tr:hover > td > .trash-button {
tr:hover > td > .trash-button,
tr:hover > td > .reset-button {
display: block;
}

Expand Down
12 changes: 12 additions & 0 deletions src/js/background/assignManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
}
const site = siteConfigs[urlKey];
// In hindsight we should have stored this
// TODO file a follow up to clean the storage onLoad

Check warning on line 122 in src/js/background/assignManager.js

View workflow job for this annotation

GitHub Actions / Run tests

Unexpected 'todo' comment: 'TODO file a follow up to clean the...'
site.hostname = urlKey.replace(/^siteContainerMap@@_/, "");
sites[urlKey] = site;
}
Expand Down Expand Up @@ -571,6 +571,18 @@
return true;
},

async _resetCookiesForSite(pageUrl, cookieStoreId) {
const url = new URL(pageUrl);
// Remove 'www.' from the domain value
const domain = url.hostname.replace(/^www\./, "");
const cookies = await browser.cookies.getAll({domain: domain, storeId: cookieStoreId});
for (const cookie of cookies) {
const domain = cookie.domain.startsWith(".") ? cookie.domain.slice(1) : cookie.domain;
const cookieUrl = `${cookie.secure ? "https" : "http"}://${domain}${cookie.path}`;
await browser.cookies.remove({ url: cookieUrl, name: cookie.name, storeId: cookie.storeId });
rafeerahman marked this conversation as resolved.
Show resolved Hide resolved
}
},

async _setOrRemoveAssignment(tabId, pageUrl, userContextId, remove) {
let actionName;
// https://github.com/mozilla/testpilot-containers/issues/626
Expand Down
3 changes: 3 additions & 0 deletions src/js/background/messageHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
// m.url is the assignment to be removed/added
response = assignManager._setOrRemoveAssignment(m.tabId, m.url, m.userContextId, m.value);
break;
case "resetCookiesForSite":
response = assignManager._resetCookiesForSite(m.pageUrl, m.cookieStoreId);
break;
case "sortTabs":
backgroundLogic.sortTabs();
break;
Expand All @@ -58,7 +61,7 @@
});
break;
case "checkIncompatibleAddons":
// TODO

Check warning on line 64 in src/js/background/messageHandler.js

View workflow job for this annotation

GitHub Actions / Run tests

Unexpected 'todo' comment: 'TODO'
break;
case "moveTabsToWindow":
response = backgroundLogic.moveTabsToWindow({
Expand Down
11 changes: 10 additions & 1 deletion src/js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@
const td = document.createElement("td");
const openTabs = identity.numberOfOpenTabs || "" ;

// TODO get UX and content decision on how to message and block clicks to containers with Mozilla VPN proxy configs

Check warning on line 821 in src/js/popup.js

View workflow job for this annotation

GitHub Actions / Run tests

Unexpected 'todo' comment: 'TODO get UX and content decision on how...'
// when Mozilla VPN app is disconnected.

td.innerHTML = Utils.escaped`
Expand Down Expand Up @@ -1450,11 +1450,14 @@
/* As we don't have the full or correct path the best we can assume is the path is HTTPS and then replace with a broken icon later if it doesn't load.
This is pending a better solution for favicons from web extensions */
const assumedUrl = `https://${site.hostname}/favicon.ico`;
const resetSiteCookiesInfo = browser.i18n.getMessage("resetSiteCookiesTooltipInfo");
const deleteSiteInfo = browser.i18n.getMessage("deleteSiteTooltipInfo");
trElement.innerHTML = Utils.escaped`
<td>
<div class="favicon"></div>
<span title="${site.hostname}" class="menu-text truncate-text">${site.hostname}</span>
<img class="trash-button delete-assignment" src="/img/container-delete.svg" />
<img title="${resetSiteCookiesInfo}" class="reset-button reset-assignment" src="/img/refresh-16.svg" />
<img title="${deleteSiteInfo}" class="trash-button delete-assignment" src="/img/container-delete.svg" />
</td>`;
trElement.getElementsByClassName("favicon")[0].appendChild(Utils.createFavIconElement(assumedUrl));
const deleteButton = trElement.querySelector(".trash-button");
Expand All @@ -1466,6 +1469,12 @@
delete assignments[siteKey];
this.showAssignedContainers(assignments);
});
const resetButton = trElement.querySelector(".reset-button");
Utils.addEnterHandler(resetButton, async () => {
const pageUrl = `https://${site.hostname}`;
const cookieStoreId = Logic.currentCookieStoreId();
Utils.resetCookiesForSite(pageUrl, cookieStoreId);
});
rafeerahman marked this conversation as resolved.
Show resolved Hide resolved
trElement.classList.add("menu-item", "hover-highlight", "keyboard-nav");
tableElement.appendChild(trElement);
});
Expand Down
8 changes: 8 additions & 0 deletions src/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// eslint-disable-next-line
const CONTAINER_ORDER_STORAGE_KEY = "container-order";

// TODO use export here instead of globals

Check warning on line 8 in src/js/utils.js

View workflow job for this annotation

GitHub Actions / Run tests

Unexpected 'todo' comment: 'TODO use export here instead of globals'
const Utils = {

createFavIconElement(url) {
Expand Down Expand Up @@ -138,6 +138,14 @@
});
},

resetCookiesForSite(pageUrl, cookieStoreId) {
return browser.runtime.sendMessage({
method: "resetCookiesForSite",
pageUrl,
cookieStoreId,
});
},

async reloadInContainer(url, currentUserContextId, newUserContextId, tabIndex, active) {
return await browser.runtime.sendMessage({
method: "reloadInContainer",
Expand Down
Loading