Add FireFox 60 support (for testing, part 1)

Some error notifications are broken. Not thoroughly tested.
This commit is contained in:
ilyaigpetrov 2020-10-12 17:08:26 +00:00
parent 8145f5f04a
commit 7037af70ca
4 changed files with 120 additions and 87 deletions

View File

@ -76,7 +76,7 @@
const json = JSON.stringify(errors, errorJsonReplacer, 0); const json = JSON.stringify(errors, errorJsonReplacer, 0);
openAndFocus( openAndFocus(
'http://rebrand.ly/ac-error/?json=' + encodeURIComponent(json) + 'https://rebrand.ly/ac-error/?json=' + encodeURIComponent(json) +
(type ? '&type=' + encodeURIComponent(type) : '') + (type ? '&type=' + encodeURIComponent(type) : '') +
'&version=' + chrome.runtime.getManifest().version + '&version=' + chrome.runtime.getManifest().version +
'&useragent=' + encodeURIComponent(navigator.userAgent) + '&useragent=' + encodeURIComponent(navigator.userAgent) +
@ -252,7 +252,7 @@
handlers.installListenersOn(window, 'BG'); handlers.installListenersOn(window, 'BG');
chrome.proxy.onProxyError.addListener( timeouted( (details) => { (chrome.proxy.onProxyError || chrome.proxy.onError).addListener( timeouted( (details) => {
if (!handlers.ifControlled) { if (!handlers.ifControlled) {
return; return;

View File

@ -541,9 +541,11 @@ ${
).then((details) => { ).then((details) => {
console.log('DEEETAILS:', details); // TODO:
if ( if (
details && details.levelOfControl === 'controlled_by_this_extension' details && details.levelOfControl === 'controlled_by_this_extension'
) { ) {
console.log('TODODOODODODOD:', details); // TODO:
const pac = window.utils.getProp(details, 'value.pacScript'); const pac = window.utils.getProp(details, 'value.pacScript');
if (pac && pac.data) { if (pac && pac.data) {
return chrome.proxy.settings.set(details, chromified(cb)); return chrome.proxy.settings.set(details, chromified(cb));
@ -551,6 +553,7 @@ ${
} }
kitchenState(ifIncontinence, true); kitchenState(ifIncontinence, true);
console.log('TYYYYPE ERRROR');
cb(null, null, new TypeError( cb(null, null, new TypeError(
'Не найдено активного PAC-скрипта! Изменения будут применены при возвращении контроля настроек прокси или установке нового PAC-скрипта.' 'Не найдено активного PAC-скрипта! Изменения будут применены при возвращении контроля настроек прокси или установке нового PAC-скрипта.'
)); ));
@ -562,7 +565,7 @@ ${
checkIncontinence(details) { checkIncontinence(details) {
if ( kitchenState(ifIncontinence) ) { if ( kitchenState(ifIncontinence) ) {
this.setNowAsync(details, () => {/* Swallow. */}); this.setNowAsync(details, (err) => { if (err) { throw err; } }); // TODO: suppress?
} }
}, },
@ -625,19 +628,44 @@ ${
chrome.proxy.settings.set = function(details, cb) { chrome.proxy.settings.set = function(details, cb) {
const pac = window.utils.getProp(details, 'value.pacScript'); const pac = window.utils.getProp(details, 'value.pacScript') || {};
if (!(pac && pac.data)) { const autoConfigUrl = window.utils.getProp(details, 'value.autoConfigUrl');
const ifNothingToCook = !(pac && pac.data || autoConfigUrl);
if (ifNothingToCook) {
return originalSet(details, cb); return originalSet(details, cb);
} }
const getPacData = (cb) =>
pac.data ? cb(null, pac.data) : window.apis.httpLib.get(autoConfigUrl, cb);
getPacData((err, pacData) => {
if (err) {
cb(err);
return;
}
const pacMods = getCurrentConfigs(); const pacMods = getCurrentConfigs();
pac.data = pacKitchen.cook( pac.data, pacMods ); const cookedData = pacKitchen.cook( pacData, pacMods );
if (window.apis.platform.ifFirefox) {
const autoConfigUrl = URL.createObjectURL(new Blob([cookedData], {
type: 'application/x-ns-proxy-autoconfig',
}));
originalSet({
value: {
proxyType: 'autoConfig',
autoConfigUrl,
},
}, chromified(cb));
return;
}
details.value.pacScript.data = cookedData;
originalSet({value: details.value}, (/* No args. */) => { originalSet({value: details.value}, (/* No args. */) => {
kitchenState(ifIncontinence, null); kitchenState(ifIncontinence, null);
cb && cb(); cb && cb();
}); });
});
}; };
pacKitchen.checkIncontinence(); pacKitchen.checkIncontinence();

View File

@ -59,10 +59,39 @@
}; };
const doWithoutProxyAsync = (createPromise) => new Promise((resolve, reject) => {
chrome.proxy.settings.get({}, chromified((getErr, settings) => {
if (getErr) {
reject(getErr);
return;
}
delete settings.levelOfControl;
const setProxyAsync = () => new Promise((setResolve, setReject) =>
chrome.proxy.settings.set(
settings,
chromified((err) => err ? setReject(err) : setResolve()),
),
);
chrome.proxy.settings.clear({}, chromified((clearErr) => {
if (clearErr) {
reject(clearErr);
return;
}
return createPromise().then((actionResult) => setProxyAsync().then(() => resolve(actionResult)));
}));
}));
});
const setPacAsync = function setPacAsync( const setPacAsync = function setPacAsync(
pacData = mandatory(), cb = throwIfError, pacData = mandatory(), cb = throwIfError,
) { ) {
console.log('Clearing chrome proxy settings...');
chrome.proxy.settings.clear({}, chromified((clearErr) => {
if (clearErr) {
return cb(clearErr);
}
const config = { const config = {
mode: 'pac_script', mode: 'pac_script',
pacScript: { pacScript: {
@ -71,7 +100,7 @@
}, },
}; };
console.log('Setting chrome proxy settings...'); console.log('Setting chrome proxy settings...');
chrome.proxy.settings.set( {value: config}, chromified((err) => { chrome.proxy.settings.set( { value: config }, chromified((err) => {
if (err) { if (err) {
return cb(err); return cb(err);
@ -92,7 +121,7 @@
}); });
})); }));
}));
}; };
const updatePacProxyIps = function updatePacProxyIps( const updatePacProxyIps = function updatePacProxyIps(
@ -143,33 +172,11 @@
} }
httpLib.ifModifiedSince(pacUrl, lastModifiedStr, (err, newLastModifiedStr) => { console.log('Clearing chrome proxy settings...');
const pacDataPromise = doWithoutProxyAsync(
/*
TODO: Get rid of this dirty hack
IPFS used by AntiZapret always returns last-modified date as new Date(1000) which is 1 sec since unix epoch.
Last-modified isn't changed but target redireciton URL is and this URL should be compared to the last cached URL.
Hack here is to consider 5 seconds since epoch time the same way as the unix epoch start.
If you think etags are the solution then know that etags can't be read from the fetch API, see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers.
*/
/*
TODO: I turn off caching for now because I see no easy way out.
const ifWasEverModified = new Date(lastModifiedStr) - new Date(0) > 5000;
if (!newLastModifiedStr && ifWasEverModified) {
addWarning(
(ifRu
? 'Ваш PAC-скрипт не нуждается в обновлении. Его дата: '
: 'Your PAC-script doesn\\'t need to be updated. It\\'s date: '
) + lastModifiedStr,
);
const res = {lastModified: lastModifiedStr};
return cb(null, res);
}
*/
// Employ all urls, the latter are fallbacks for the former. // Employ all urls, the latter are fallbacks for the former.
const pacDataPromise = provider.pacUrls.reduce( () =>
provider.pacUrls.reduce(
(promise, url) => promise.catch( (promise, url) => promise.catch(
() => new Promise( () => new Promise(
(resolve, reject) => httpLib.get( (resolve, reject) => httpLib.get(
@ -179,6 +186,7 @@
), ),
), ),
Promise.reject(), Promise.reject(),
),
); );
pacDataPromise.then( pacDataPromise.then(
@ -189,7 +197,7 @@
pacData, pacData,
(err, res) => cb( (err, res) => cb(
err, err,
Object.assign(res || {}, {lastModified: newLastModifiedStr}), Object.assign(res || {}, {lastModified: lastModifiedStr}),
), ),
); );
@ -202,9 +210,6 @@
), ),
); );
});
}; };
window.apis.antiCensorRu = { window.apis.antiCensorRu = {

View File

@ -40,7 +40,7 @@ chrome.runtime.getBackgroundPage( (bgWindow) =>
([tab]) => resolve(tab), ([tab]) => resolve(tab),
) )
); );
winChrome.runtime.sendMessage({ currentTab, eventName: 'POPUP_OPENED' }); // winChrome.runtime.sendMessage({ currentTab, eventName: 'POPUP_OPENED' });
theState.flags.ifInsideOptionsPage = !currentTab || /.*:\/\/extensions\/\?options=/g.test(currentTab.url) || currentTab.url.startsWith('about:addons'); theState.flags.ifInsideOptionsPage = !currentTab || /.*:\/\/extensions\/\?options=/g.test(currentTab.url) || currentTab.url.startsWith('about:addons');
theState.flags.ifInsideEdgeOptionsPage = theState.flags.ifInsideOptionsPage && currentTab.url.startsWith('edge://'); theState.flags.ifInsideEdgeOptionsPage = theState.flags.ifInsideOptionsPage && currentTab.url.startsWith('edge://');