Review + QA updates - Part 1

This commit is contained in:
Lesley Norton 2021-10-21 23:02:27 -05:00
parent 0a772c8f04
commit 2f6e49bec0
No known key found for this signature in database
GPG key ID: E98FBAEE3F13956E
5 changed files with 59 additions and 92 deletions

View file

@ -1490,7 +1490,7 @@ manage things like container crud */
}
#edit-container-panel-choose-icon .radio-container:hover .usercontext-icon::before {
fill: #fff !important;
fill: var(--grey50) !important;
}
.mac-icon {
@ -2182,4 +2182,8 @@ tr:hover > td > .trash-button {
.radio-choice > .radio-container > [type="radio"]:checked + label {
background: var(--bgDark);
}
#edit-container-panel-choose-icon .radio-container:hover .usercontext-icon::before {
fill: #fff !important;
}
}

View file

@ -55,23 +55,13 @@ const backgroundLogic = {
},
async createOrUpdateContainer(options) {
let donePromise;
if (options.userContextId !== "new") {
donePromise = browser.contextualIdentities.update(
return await browser.contextualIdentities.update(
this.cookieStoreId(options.userContextId),
options.params
);
} else {
donePromise = browser.contextualIdentities.create(options.params);
// We cannot yet access the new cookieStoreId via this.cookieStoreId(...), so we take this from the resolved promise
donePromise.then((identity) => {
(identity.cookieStoreId, options.proxy);
}).catch(() => {
// Empty because this should never happen theoretically.
});
}
await donePromise;
return await browser.contextualIdentities.create(options.params);
},
async openNewTab(options) {

View file

@ -12,6 +12,10 @@ const MozillaVPN = {
for (const el of document.querySelectorAll("[data-cookie-store-id]")) {
const cookieStoreId = el.dataset.cookieStoreId;
if (!proxies[cookieStoreId]) {
continue;
}
const { proxy } = proxies[cookieStoreId];
if (typeof(proxy) !== "undefined") {
@ -139,7 +143,7 @@ const MozillaVPN = {
return proxies;
},
getMozillaProxyInfoObj () {
getMozillaProxyInfoObj() {
return {
countryCode: undefined,
cityName: undefined,
@ -211,7 +215,7 @@ const MozillaVPN = {
return `socks://${socksName}.mullvad.net:1080`;
},
async pickRandomServer() {
async pickRandomLocation() {
const { mozillaVpnServers } = await browser.storage.local.get("mozillaVpnServers");
const randomInteger = this.getRandomInteger(0, mozillaVpnServers.length - 1);
const randomServerCountry = mozillaVpnServers[randomInteger];

View file

@ -1474,7 +1474,7 @@ Logic.registerPanel(P_CONTAINER_EDIT, {
} else {
// No saved Mozilla VPN proxy information. Get something new.
const { randomServerCountryCode, randomServerCityName } = await MozillaVPN.pickRandomServer();
const { randomServerCountryCode, randomServerCityName } = await MozillaVPN.pickRandomLocation();
proxy = MozillaVPN.getProxy(
randomServerCountryCode,

View file

@ -3,19 +3,12 @@ proxifiedContainers = {
// Slightly modified version of 'retrieve' which returns a direct proxy whenever an error is met.
async retrieveFromBackground(cookieStoreId = null) {
return new Promise((resolve, reject) => {
proxifiedContainers.retrieve(cookieStoreId).then((success) => {
// TODO consider better methods of handling containers with MozillaVPN proxy
// configs when MozillaVPN is not connected. Currently we are only messaging this
// in the main panel.
// if (mozProxyIsEnabled && !mozillaVpnConnected) { something better here ? }
resolve(success.proxy);
}, function() {
resolve(Utils.DEFAULT_PROXY);
}).catch((error) => {
reject(error);
});
});
try {
const success = await proxifiedContainers.retrieve(cookieStoreId);
return success.proxy;
} catch (e) {
return Utils.DEFAULT_PROXY;
}
},
report_proxy_error(error, identifier = null) {
@ -66,53 +59,40 @@ proxifiedContainers = {
});
},
set(cookieStoreId, proxy, initialize = false) {
return new Promise((resolve, reject) => {
if (initialize === true) {
const proxifiedContainersStore = [];
proxifiedContainersStore.push({
cookieStoreId: cookieStoreId,
proxy: proxy
});
browser.storage.local.set({
proxifiedContainersKey: proxifiedContainersStore
});
resolve(proxy);
}
// Assumes proxy is a properly formatted object
proxifiedContainers.retrieve().then((proxifiedContainersStore) => {
let index = proxifiedContainersStore.findIndex(i => i.cookieStoreId === cookieStoreId);
if (index === -1) {
proxifiedContainersStore.push({
cookieStoreId: cookieStoreId,
proxy: proxy
});
index = proxifiedContainersStore.length - 1;
} else {
proxifiedContainersStore[index] = {
cookieStoreId: cookieStoreId,
proxy: proxy
};
}
browser.storage.local.set({
proxifiedContainersKey: proxifiedContainersStore
});
resolve(proxifiedContainersStore[index]);
}, (errorObj) => {
reject(errorObj);
}).catch((error) => {
throw error;
async set(cookieStoreId, proxy, initialize = false) {
if (initialize === true) {
const proxifiedContainersStore = [];
proxifiedContainersStore.push({
cookieStoreId: cookieStoreId,
proxy: proxy
});
await browser.storage.local.set({
proxifiedContainersKey: proxifiedContainersStore
});
return proxy;
}
// Assumes proxy is a properly formatted object
const proxifiedContainersStore = await proxifiedContainers.retrieve();
let index = proxifiedContainersStore.findIndex(i => i.cookieStoreId === cookieStoreId);
if (index === -1) {
proxifiedContainersStore.push({
cookieStoreId: cookieStoreId,
proxy: proxy
});
index = proxifiedContainersStore.length - 1;
} else {
proxifiedContainersStore[index] = {
cookieStoreId: cookieStoreId,
proxy: proxy
};
}
await browser.storage.local.set({
proxifiedContainersKey: proxifiedContainersStore
});
return proxifiedContainersStore[index];
},
//Parses a proxy description string of the format type://host[:port] or type://username:password@host[:port] (port is optional)
parseProxy(proxy_str, mozillaVpnData = null) {
const proxyRegexp = /(?<type>(https?)|(socks4?)):\/\/(\b(?<username>\w+):(?<password>\w+)@)?(?<host>((?:\d{1,3}\.){3}\d{1,3}\b)|(\b([\w.-]+)(\.([\w.-]+))+))(:(?<port>\d+))?/;
@ -133,26 +113,15 @@ proxifiedContainers = {
},
// Deletes the proxy information object for a specified cookieStoreId [useful for cleaning]
delete(cookieStoreId) {
return new Promise((resolve, reject) => {
// Assumes proxy is a properly formatted object
proxifiedContainers.retrieve().then((proxifiedContainersStore) => {
const index = proxifiedContainersStore.findIndex(i => i.cookieStoreId === cookieStoreId);
if (index !== -1) {
proxifiedContainersStore.splice(index, 1);
}
browser.storage.local.set({
proxifiedContainersKey: proxifiedContainersStore
});
resolve();
}, (errorObj) => {
reject(errorObj);
}).catch((error) => {
throw error;
});
async delete(cookieStoreId) {
// Assumes proxy is a properly formatted object
const proxifiedContainersStore = await proxifiedContainers.retrieve();
const index = proxifiedContainersStore.findIndex(i => i.cookieStoreId === cookieStoreId);
if (index !== -1) {
proxifiedContainersStore.splice(index, 1);
}
await browser.storage.local.set({
proxifiedContainersKey: proxifiedContainersStore
});
}
};