feat #303: ask for browsing data permission dynamically

This commit is contained in:
Rafee
2024-08-27 16:53:11 -04:00
parent 2cd38299e2
commit c644a60e46
5 changed files with 27 additions and 16 deletions
+12 -8
View File
@@ -294,11 +294,11 @@ table {
border-radius: 4px; border-radius: 4px;
font-size: 12px; font-size: 12px;
position: absolute; position: absolute;
inset-block-start: 0; inset-block-start: 0;
inset-inline-start: 0; inset-inline-start: 0;
padding-block: 8px; padding-block: 8px;
padding-inline: 8px; padding-inline: 8px;
margin-block: 8px; margin-block: 8px;
margin-inline: 8px; margin-inline: 8px;
inline-size: calc(100vw - 25px); inline-size: calc(100vw - 25px);
background-color: var(--button-bg-active-color-secondary); background-color: var(--button-bg-active-color-secondary);
@@ -1531,7 +1531,8 @@ input[type=text] {
min-block-size: 500px; min-block-size: 500px;
} }
.delete-container-panel, .clear-container-storage-panel { .delete-container-panel,
.clear-container-storage-panel {
min-block-size: 500px; min-block-size: 500px;
} }
@@ -1820,12 +1821,14 @@ manage things like container crud */
margin-inline-end: 0; margin-inline-end: 0;
} }
.delete-container-confirm, .clear-container-storage-confirm { .delete-container-confirm,
.clear-container-storage-confirm {
padding-inline-end: 20px; padding-inline-end: 20px;
padding-inline-start: 20px; padding-inline-start: 20px;
} }
.delete-container-confirm-title, .clear-container-storage-confirm-title { .delete-container-confirm-title,
.clear-container-storage-confirm-title {
color: var(--text-color-primary); color: var(--text-color-primary);
font-size: var(--font-size-heading); font-size: var(--font-size-heading);
} }
@@ -2334,7 +2337,8 @@ input {
font-weight: bolder; font-weight: bolder;
} }
.delete-warning, .clear-container-storage-warning { .delete-warning,
.clear-container-storage-warning {
padding-block-end: 8px; padding-block-end: 8px;
padding-block-start: 8px; padding-block-start: 8px;
padding-inline-end: 0; padding-inline-end: 0;
+1 -1
View File
@@ -572,7 +572,7 @@ window.assignManager = {
}, },
async _resetCookiesForSite(hostname, cookieStoreId) { async _resetCookiesForSite(hostname, cookieStoreId) {
const hostNameTruncated = hostname.replace(/^www\./, ''); // Remove "www." from the hostname const hostNameTruncated = hostname.replace(/^www\./, ""); // Remove "www." from the hostname
await browser.browsingData.removeCookies({ await browser.browsingData.removeCookies({
cookieStoreId: cookieStoreId, cookieStoreId: cookieStoreId,
hostnames: [hostNameTruncated] // This does not remove cookies from associated domains. To remove all cookies, we have a container storage removal option. hostnames: [hostNameTruncated] // This does not remove cookies from associated domains. To remove all cookies, we have a container storage removal option.
+12 -5
View File
@@ -980,7 +980,7 @@ Logic.registerPanel(P_CONTAINER_INFO, {
Utils.alwaysOpenInContainer(identity); Utils.alwaysOpenInContainer(identity);
window.close(); window.close();
}); });
// Show or not the has-tabs section. // Show or not the has-tabs section.
for (let trHasTabs of document.getElementsByClassName("container-info-has-tabs")) { // eslint-disable-line prefer-const for (let trHasTabs of document.getElementsByClassName("container-info-has-tabs")) { // eslint-disable-line prefer-const
trHasTabs.style.display = !identity.hasHiddenTabs && !identity.hasOpenTabs ? "none" : ""; trHasTabs.style.display = !identity.hasHiddenTabs && !identity.hasOpenTabs ? "none" : "";
@@ -1005,8 +1005,11 @@ Logic.registerPanel(P_CONTAINER_INFO, {
Logic.showPanel(P_CONTAINER_EDIT, identity); Logic.showPanel(P_CONTAINER_EDIT, identity);
}); });
const clearContainerStorageButton = document.getElementById("clear-container-storage-info"); const clearContainerStorageButton = document.getElementById("clear-container-storage-info");
Utils.addEnterHandler(clearContainerStorageButton, () => { Utils.addEnterHandler(clearContainerStorageButton, async () => {
Logic.showPanel(P_CLEAR_CONTAINER_STORAGE, identity); const granted = await browser.permissions.request({ permissions: ["browsingData"] });
if (granted) {
Logic.showPanel(P_CLEAR_CONTAINER_STORAGE, identity);
}
}); });
return this.buildOpenTabTable(tabs); return this.buildOpenTabTable(tabs);
}, },
@@ -1491,6 +1494,10 @@ Logic.registerPanel(P_CONTAINER_ASSIGNMENTS, {
const resetButton = trElement.querySelector(".reset-button"); const resetButton = trElement.querySelector(".reset-button");
Utils.addEnterHandler(resetButton, async () => { Utils.addEnterHandler(resetButton, async () => {
const cookieStoreId = Logic.currentCookieStoreId(); const cookieStoreId = Logic.currentCookieStoreId();
const granted = await browser.permissions.request({ permissions: ["browsingData"] });
if (!granted) {
return;
}
const result = await Utils.resetCookiesForSite(site.hostname, cookieStoreId); const result = await Utils.resetCookiesForSite(site.hostname, cookieStoreId);
if (result === true) { if (result === true) {
Logic.notify({messageId: "cookiesClearedSuccess", placeholders: [site.hostname]}); Logic.notify({messageId: "cookiesClearedSuccess", placeholders: [site.hostname]});
@@ -2292,7 +2299,7 @@ Logic.registerPanel(P_CLEAR_CONTAINER_STORAGE, {
}); });
Utils.addEnterHandler(document.querySelector("#clear-container-storage-ok-link"), async () => { Utils.addEnterHandler(document.querySelector("#clear-container-storage-ok-link"), async () => {
const identity = Logic.currentIdentity(); const identity = Logic.currentIdentity();
const userContextId = Utils.userContextId(identity.cookieStoreId) const userContextId = Utils.userContextId(identity.cookieStoreId);
const result = await browser.runtime.sendMessage({ const result = await browser.runtime.sendMessage({
method: "deleteContainerDataOnly", method: "deleteContainerDataOnly",
message: { userContextId } message: { userContextId }
@@ -2300,7 +2307,7 @@ Logic.registerPanel(P_CLEAR_CONTAINER_STORAGE, {
if (result.done === true) { if (result.done === true) {
Logic.notify({messageId: "storageWasClearedConfirmation", placeholders: [identity.name]}); Logic.notify({messageId: "storageWasClearedConfirmation", placeholders: [identity.name]});
} }
Logic.showPanel(P_CONTAINER_INFO, identity, false, false) Logic.showPanel(P_CONTAINER_INFO, identity, false, false);
}); });
}, },
+1 -1
View File
@@ -13,7 +13,6 @@
"<all_urls>", "<all_urls>",
"activeTab", "activeTab",
"cookies", "cookies",
"browsingData",
"contextMenus", "contextMenus",
"contextualIdentities", "contextualIdentities",
"history", "history",
@@ -27,6 +26,7 @@
], ],
"optional_permissions": [ "optional_permissions": [
"bookmarks", "bookmarks",
"browsingData",
"nativeMessaging", "nativeMessaging",
"proxy" "proxy"
], ],