Skip to content

Commit

Permalink
Add FireFox 60 support (for testing, part 1)
Browse files Browse the repository at this point in the history
Some error notifications are broken. Not thoroughly tested.
  • Loading branch information
ilyaigpetrov committed Oct 12, 2020
1 parent 8145f5f commit 7037af7
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
const json = JSON.stringify(errors, errorJsonReplacer, 0);

openAndFocus(
'http://rebrand.ly/ac-error/?json=' + encodeURIComponent(json) +
'https://rebrand.ly/ac-error/?json=' + encodeURIComponent(json) +
(type ? '&type=' + encodeURIComponent(type) : '') +
'&version=' + chrome.runtime.getManifest().version +
'&useragent=' + encodeURIComponent(navigator.userAgent) +
Expand Down Expand Up @@ -252,7 +252,7 @@

handlers.installListenersOn(window, 'BG');

chrome.proxy.onProxyError.addListener( timeouted( (details) => {
(chrome.proxy.onProxyError || chrome.proxy.onError).addListener( timeouted( (details) => {

if (!handlers.ifControlled) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,16 +541,19 @@ ${

).then((details) => {

console.log('DEEETAILS:', details); // TODO:
if (
details && details.levelOfControl === 'controlled_by_this_extension'
) {
console.log('TODODOODODODOD:', details); // TODO:
const pac = window.utils.getProp(details, 'value.pacScript');
if (pac && pac.data) {
return chrome.proxy.settings.set(details, chromified(cb));
}
}

kitchenState(ifIncontinence, true);
console.log('TYYYYPE ERRROR');
cb(null, null, new TypeError(
'Не найдено активного PAC-скрипта! Изменения будут применены при возвращении контроля настроек прокси или установке нового PAC-скрипта.'
));
Expand All @@ -562,7 +565,7 @@ ${
checkIncontinence(details) {

if ( kitchenState(ifIncontinence) ) {
this.setNowAsync(details, () => {/* Swallow. */});
this.setNowAsync(details, (err) => { if (err) { throw err; } }); // TODO: suppress?
}

},
Expand Down Expand Up @@ -625,19 +628,44 @@ ${

chrome.proxy.settings.set = function(details, cb) {

const pac = window.utils.getProp(details, 'value.pacScript');
if (!(pac && pac.data)) {
const pac = window.utils.getProp(details, 'value.pacScript') || {};
const autoConfigUrl = window.utils.getProp(details, 'value.autoConfigUrl');
const ifNothingToCook = !(pac && pac.data || autoConfigUrl);
if (ifNothingToCook) {
return originalSet(details, cb);
}
const pacMods = getCurrentConfigs();
pac.data = pacKitchen.cook( pac.data, pacMods );
originalSet({value: details.value}, (/* No args. */) => {
const getPacData = (cb) =>
pac.data ? cb(null, pac.data) : window.apis.httpLib.get(autoConfigUrl, cb);

kitchenState(ifIncontinence, null);
cb && cb();
getPacData((err, pacData) => {
if (err) {
cb(err);
return;
}
const pacMods = getCurrentConfigs();
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. */) => {

kitchenState(ifIncontinence, null);
cb && cb();

});
});
};

pacKitchen.checkIncontinence();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,40 +59,69 @@

};

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(
pacData = mandatory(), cb = throwIfError,
) {

const config = {
mode: 'pac_script',
pacScript: {
mandatory: false,
data: pacData,
},
};
console.log('Setting chrome proxy settings...');
chrome.proxy.settings.set( {value: config}, chromified((err) => {
console.log('Clearing chrome proxy settings...');
chrome.proxy.settings.clear({}, chromified((clearErr) => {

if (err) {
return cb(err);
if (clearErr) {
return cb(clearErr);
}
handlers.updateControlState( () => {
const config = {
mode: 'pac_script',
pacScript: {
mandatory: false,
data: pacData,
},
};
console.log('Setting chrome proxy settings...');
chrome.proxy.settings.set( { value: config }, chromified((err) => {

if ( !handlers.ifControlled ) {
if (err) {
return cb(err);
}
handlers.updateControlState( () => {

console.warn('Failed, other extension is in control.');
return cb(
new Error( window.utils.messages.whichExtensionHtml() ),
);
if ( !handlers.ifControlled ) {

}
console.log('Successfuly set PAC in proxy settings..');
cb();
console.warn('Failed, other extension is in control.');
return cb(
new Error( window.utils.messages.whichExtensionHtml() ),
);

});
}
console.log('Successfuly set PAC in proxy settings..');
cb();

}));
});

}));
}));
};

const updatePacProxyIps = function updatePacProxyIps(
Expand Down Expand Up @@ -143,68 +172,44 @@

}

httpLib.ifModifiedSince(pacUrl, lastModifiedStr, (err, newLastModifiedStr) => {

/*
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);
}
*/

console.log('Clearing chrome proxy settings...');
const pacDataPromise = doWithoutProxyAsync(
// Employ all urls, the latter are fallbacks for the former.
const pacDataPromise = provider.pacUrls.reduce(
(promise, url) => promise.catch(
() => new Promise(
(resolve, reject) => httpLib.get(
url,
(newErr, pacData) => newErr ? reject(newErr) : resolve(pacData),
() =>
provider.pacUrls.reduce(
(promise, url) => promise.catch(
() => new Promise(
(resolve, reject) => httpLib.get(
url,
(newErr, pacData) => newErr ? reject(newErr) : resolve(pacData),
),
),
),
Promise.reject(),
),
Promise.reject(),
);

pacDataPromise.then(

(pacData) => {
);

setPacAsync(
pacData,
(err, res) => cb(
err,
Object.assign(res || {}, {lastModified: newLastModifiedStr}),
),
);
pacDataPromise.then(

},
(pacData) => {

clarifyThen(
chrome.i18n.getMessage('FailedToDownloadPacScriptFromAddresses') + ': [ '
+ provider.pacUrls.join(' , ') + ' ].',
cb,
),
setPacAsync(
pacData,
(err, res) => cb(
err,
Object.assign(res || {}, {lastModified: lastModifiedStr}),
),
);

);
},

});
clarifyThen(
chrome.i18n.getMessage('FailedToDownloadPacScriptFromAddresses') + ': [ '
+ provider.pacUrls.join(' , ') + ' ].',
cb,
),

);
};

window.apis.antiCensorRu = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ chrome.runtime.getBackgroundPage( (bgWindow) =>
([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.ifInsideEdgeOptionsPage = theState.flags.ifInsideOptionsPage && currentTab.url.startsWith('edge://');
Expand Down

0 comments on commit 7037af7

Please sign in to comment.