Add "isIsolated" to JSON backups
This commit is contained in:
parent
407cfaa21b
commit
b8cf955e1f
1 changed files with 35 additions and 12 deletions
|
@ -277,9 +277,21 @@ const backgroundLogic = {
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
identities.map(async ({ cookieStoreId, color, icon, name }) => {
|
identities.map(async ({ cookieStoreId, color, icon, name }) => {
|
||||||
const userContextId = this.getUserContextIdFromCookieStoreId(cookieStoreId);
|
const userContextId = this.getUserContextIdFromCookieStoreId(cookieStoreId);
|
||||||
const sitesByContainer = await assignManager.storageArea.getAssignedSites(userContextId);
|
const [
|
||||||
|
{ isIsolated },
|
||||||
|
sitesByContainer
|
||||||
|
] = await Promise.all([
|
||||||
|
identityState.storageArea.get(cookieStoreId),
|
||||||
|
assignManager.storageArea.getAssignedSites(userContextId)
|
||||||
|
]);
|
||||||
const sites = Object.values(sitesByContainer).map(({ neverAsk, hostname }) => ({ neverAsk, hostname }));
|
const sites = Object.values(sitesByContainer).map(({ neverAsk, hostname }) => ({ neverAsk, hostname }));
|
||||||
return ({ color, icon, name, sites });
|
return ({
|
||||||
|
color,
|
||||||
|
icon,
|
||||||
|
name,
|
||||||
|
isolated: isIsolated && true, // either `true` or `undefined`
|
||||||
|
sites
|
||||||
|
});
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -288,13 +300,19 @@ const backgroundLogic = {
|
||||||
const backup = await browser.contextualIdentities.query({});
|
const backup = await browser.contextualIdentities.query({});
|
||||||
const incomplete = [];
|
const incomplete = [];
|
||||||
let allSucceed = true;
|
let allSucceed = true;
|
||||||
const identitiesPromise = identities.map(async ({ color, icon, name, sites }) => {
|
const identitiesPromise = identities.map(async ({ color, icon, name, isolated, sites }) => {
|
||||||
try {
|
try {
|
||||||
if (typeof color !== "string" || typeof icon !== "string" || typeof name !== "string" || !Array.isArray((sites)))
|
if (
|
||||||
|
typeof color !== "string" ||
|
||||||
|
typeof icon !== "string" ||
|
||||||
|
typeof name !== "string" ||
|
||||||
|
(isolated !== true && isolated !== undefined) ||
|
||||||
|
!Array.isArray((sites))
|
||||||
|
)
|
||||||
throw new Error("Corrupted container backup");
|
throw new Error("Corrupted container backup");
|
||||||
const identity = await browser.contextualIdentities.create({ color, icon, name });
|
const identity = await browser.contextualIdentities.create({ color, icon, name });
|
||||||
try {
|
try {
|
||||||
await identityState.storageArea.get(identity.cookieStoreId);
|
await identityState.storageArea.get(identity.cookieStoreId); // to create identity state
|
||||||
const userContextId = this.getUserContextIdFromCookieStoreId(identity.cookieStoreId);
|
const userContextId = this.getUserContextIdFromCookieStoreId(identity.cookieStoreId);
|
||||||
for (const { neverAsk, hostname } of sites) {
|
for (const { neverAsk, hostname } of sites) {
|
||||||
if (typeof neverAsk !== "boolean" || typeof hostname !== "string" || hostname === "")
|
if (typeof neverAsk !== "boolean" || typeof hostname !== "string" || hostname === "")
|
||||||
|
@ -305,6 +323,8 @@ const backgroundLogic = {
|
||||||
userContextId
|
userContextId
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (isolated)
|
||||||
|
await identityState.storageArea.set(identity.cookieStoreId, { isIsolated: "locked" });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
incomplete.push(name); // site association damaged
|
incomplete.push(name); // site association damaged
|
||||||
}
|
}
|
||||||
|
@ -314,6 +334,7 @@ const backgroundLogic = {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const created = await Promise.all(identitiesPromise);
|
const created = await Promise.all(identitiesPromise);
|
||||||
if (!allSucceed) { // Importation failed, restore previous state
|
if (!allSucceed) { // Importation failed, restore previous state
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
|
@ -325,14 +346,16 @@ const backgroundLogic = {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
throw new Error("Some containers couldn't be created");
|
throw new Error("Some containers couldn't be created");
|
||||||
} else { // Importation succeed, remove old identities
|
|
||||||
await Promise.all(
|
|
||||||
backup.map(async (identity) => {
|
|
||||||
await identityState.storageArea.remove(identity.cookieStoreId);
|
|
||||||
await browser.contextualIdentities.remove(identity.cookieStoreId);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Importation succeed, remove old identities
|
||||||
|
await Promise.all(
|
||||||
|
backup.map(async (identity) => {
|
||||||
|
await identityState.storageArea.remove(identity.cookieStoreId);
|
||||||
|
await browser.contextualIdentities.remove(identity.cookieStoreId);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
return { created: created.length, incomplete };
|
return { created: created.length, incomplete };
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue