Skip to content

Commit

Permalink
feat #303: reset cookies in site manager
Browse files Browse the repository at this point in the history
  • Loading branch information
rafeerahman committed Aug 1, 2024
1 parent 1537e9f commit dfcbe63
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 7 deletions.
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 @@ -571,6 +571,18 @@ window.assignManager = {
return true;
},

async _resetCookiesForSite(pageUrl, cookieStoreId) {
const url = new URL(pageUrl);
// Remove 'www.' from the domain value
const domain = url.hostname.replace(/^www\./, '');

Check failure on line 577 in src/js/background/assignManager.js

View workflow job for this annotation

GitHub Actions / Run tests

Strings must use doublequote
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;

Check failure on line 580 in src/js/background/assignManager.js

View workflow job for this annotation

GitHub Actions / Run tests

Expected indentation of 6 spaces but found 8

Check failure on line 580 in src/js/background/assignManager.js

View workflow job for this annotation

GitHub Actions / Run tests

Strings must use doublequote
const cookieUrl = `${cookie.secure ? 'https' : 'http'}://${domain}${cookie.path}`;

Check failure on line 581 in src/js/background/assignManager.js

View workflow job for this annotation

GitHub Actions / Run tests

Expected indentation of 6 spaces but found 8

Check failure on line 581 in src/js/background/assignManager.js

View workflow job for this annotation

GitHub Actions / Run tests

Strings must use doublequote

Check failure on line 581 in src/js/background/assignManager.js

View workflow job for this annotation

GitHub Actions / Run tests

Strings must use doublequote
await browser.cookies.remove({ url: cookieUrl, name: cookie.name, storeId: cookie.storeId });

Check failure on line 582 in src/js/background/assignManager.js

View workflow job for this annotation

GitHub Actions / Run tests

Expected indentation of 6 spaces but found 8
}
},

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 @@ const messageHandler = {
// 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 Down
11 changes: 10 additions & 1 deletion src/js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -1450,11 +1450,14 @@ Logic.registerPanel(P_CONTAINER_ASSIGNMENTS, {
/* 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 @@ Logic.registerPanel(P_CONTAINER_ASSIGNMENTS, {
delete assignments[siteKey];
this.showAssignedContainers(assignments);
});
const resetButton = trElement.querySelector(".reset-button");
Utils.addEnterHandler(resetButton, async () => {
const pageUrl = `https://${site.hostname}`

Check failure on line 1474 in src/js/popup.js

View workflow job for this annotation

GitHub Actions / Run tests

Missing semicolon
const cookieStoreId = Logic.currentCookieStoreId()

Check failure on line 1475 in src/js/popup.js

View workflow job for this annotation

GitHub Actions / Run tests

Missing semicolon
Utils.resetCookiesForSite(pageUrl, cookieStoreId);
});
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 @@ -138,6 +138,14 @@ const Utils = {
});
},

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
2 changes: 1 addition & 1 deletion src/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ <h3 class="title" id="edit-assignments-title" data-i18n-message-id="default"></h
<tr class="menu-item hover-highlight" tabindex="0">
<td>
<div class="favicon"><img class="menu-icon" src="https://www.mozilla.org/favicon.ico" /></div>
<span class="menu-text truncate-text">www.mozillllllllllllllllllllllllllllla.org</span>
<span class="menu-text truncate-text">www.mozillllllllllllllllllllllllllllllllllllla.org</span>
<img class="trash-button" src="/img/container-delete.svg" />
</td>
</tr>
Expand Down

0 comments on commit dfcbe63

Please sign in to comment.