2019-06-19 10:44:03 -04:00
|
|
|
function getChrome() {
|
2019-07-13 22:07:24 -04:00
|
|
|
if (browser.runtime.getBrowserInfo == undefined) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
2019-06-19 10:44:03 -04:00
|
|
|
}
|
|
|
|
|
2019-03-16 11:28:20 -04:00
|
|
|
function isDroid() {
|
2019-07-13 22:07:24 -04:00
|
|
|
if (!getChrome()) {
|
|
|
|
var gettingInfo = browser.runtime.getPlatformInfo();
|
|
|
|
gettingInfo.then((got) => {
|
|
|
|
if (got.os == "android") {
|
|
|
|
console.log("android detected")
|
|
|
|
return true
|
|
|
|
} else {
|
|
|
|
console.log("desktop detected")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return false
|
2019-03-16 11:28:20 -04:00
|
|
|
}
|
|
|
|
|
2019-06-19 10:44:03 -04:00
|
|
|
if (!getChrome()) {
|
2019-07-13 22:07:24 -04:00
|
|
|
browser.privacy.network.peerConnectionEnabled.set({
|
|
|
|
value: false
|
|
|
|
});
|
2019-06-19 10:44:03 -04:00
|
|
|
}
|
2019-06-17 19:17:11 -04:00
|
|
|
|
2019-06-27 15:40:43 -04:00
|
|
|
chrome.privacy.network.networkPredictionEnabled.set({
|
2019-07-13 22:07:24 -04:00
|
|
|
value: false
|
2019-06-27 15:40:43 -04:00
|
|
|
});
|
|
|
|
chrome.privacy.network.webRTCIPHandlingPolicy.set({
|
2019-07-13 22:07:24 -04:00
|
|
|
value: "disable_non_proxied_udp"
|
2019-06-27 15:40:43 -04:00
|
|
|
});
|
2019-02-05 17:38:38 -05:00
|
|
|
|
2019-02-05 21:50:25 -05:00
|
|
|
console.log("Preliminarily disabled WebRTC.")
|
|
|
|
|
2019-05-03 18:40:46 -04:00
|
|
|
function shouldProxyRequest(requestInfo) {
|
2019-07-13 22:07:24 -04:00
|
|
|
return requestInfo.parentFrameId != -1;
|
2019-06-17 19:17:11 -04:00
|
|
|
}
|
|
|
|
|
2019-07-13 22:07:24 -04:00
|
|
|
|
2019-07-21 14:00:07 -04:00
|
|
|
|
2019-10-06 13:38:11 -04:00
|
|
|
var onError = function(e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
var handleContextProxyRequest = async function(requestDetails) {
|
2019-10-06 13:56:50 -04:00
|
|
|
console.log("(proxy)Searching for proxy by context");
|
2019-07-13 22:07:24 -04:00
|
|
|
try {
|
2019-10-06 13:38:11 -04:00
|
|
|
var handleProxyRequest = function(context) {
|
|
|
|
proxy = {
|
|
|
|
failoverTimeout: 0,
|
|
|
|
type: "direct",
|
|
|
|
proxyDns: false
|
|
|
|
}
|
|
|
|
if (context.name == "i2pbrowser") {
|
|
|
|
proxy = {
|
|
|
|
type: getScheme(),
|
|
|
|
host: getHost(),
|
|
|
|
port: getPort(),
|
2019-07-13 22:07:24 -04:00
|
|
|
}
|
2019-10-06 13:56:50 -04:00
|
|
|
console.log("(proxy)Using", proxy.type, "proxy ", proxy.host + ":" + proxy.port);
|
2019-10-06 13:38:11 -04:00
|
|
|
return proxy
|
2019-07-13 22:07:24 -04:00
|
|
|
}
|
2019-10-06 13:38:11 -04:00
|
|
|
return proxy
|
2019-07-13 22:07:24 -04:00
|
|
|
}
|
2019-10-06 13:38:11 -04:00
|
|
|
var contextGet = async function(tabInfo){
|
|
|
|
try {
|
2019-10-06 13:56:50 -04:00
|
|
|
console.log("(proxy)Tab info from Function", tabInfo)
|
2019-10-06 13:38:11 -04:00
|
|
|
context = await browser.contextualIdentities.get(tabInfo.cookieStoreId)
|
|
|
|
return context
|
|
|
|
} catch(error) {
|
2019-10-06 13:56:50 -04:00
|
|
|
console.log("(proxy)Conext Error", error)
|
2019-10-06 13:38:11 -04:00
|
|
|
}
|
2019-07-13 22:07:24 -04:00
|
|
|
}
|
2019-10-06 13:38:11 -04:00
|
|
|
var tabGet = async function(tabId) {
|
|
|
|
try {
|
2019-10-06 13:56:50 -04:00
|
|
|
console.log("(proxy)Tab ID from Request", tabId)
|
2019-10-06 13:38:11 -04:00
|
|
|
let tabInfo = await browser.tabs.get(tabId)
|
|
|
|
return tabInfo
|
|
|
|
}catch(error){
|
2019-10-06 13:56:50 -04:00
|
|
|
console.log("(proxy)Tab error", error)
|
2019-07-13 22:07:24 -04:00
|
|
|
}
|
|
|
|
}
|
2019-10-06 13:38:11 -04:00
|
|
|
if (requestDetails.tabId > 0) {
|
|
|
|
var tab = tabGet(requestDetails.tabId)
|
|
|
|
var context = tab.then(contextGet)
|
|
|
|
var proxy = await context.then(handleProxyRequest)
|
2019-10-06 13:56:50 -04:00
|
|
|
console.log("(proxy)Returning I2P Proxy", proxy)
|
2019-10-06 13:38:11 -04:00
|
|
|
return proxy
|
2019-07-13 22:07:24 -04:00
|
|
|
}
|
|
|
|
} catch (error) {
|
2019-10-06 13:56:50 -04:00
|
|
|
console.log("(proxy)Not using I2P Proxy.", error);
|
2019-07-13 22:07:24 -04:00
|
|
|
}
|
2019-06-17 19:17:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
var proxy_scheme = "HTTP"
|
|
|
|
|
|
|
|
function getScheme() {
|
2019-07-13 22:07:24 -04:00
|
|
|
if (proxy_scheme == undefined) {
|
|
|
|
proxy_scheme = "http"
|
|
|
|
}
|
|
|
|
if (proxy_scheme == "HTTP") {
|
|
|
|
proxy_scheme = "http"
|
|
|
|
}
|
|
|
|
if (proxy_scheme == "SOCKS") {
|
|
|
|
proxy_scheme = "socks"
|
|
|
|
}
|
|
|
|
if (proxy_scheme != "http" && proxy_scheme != "socks") {
|
|
|
|
proxy_scheme = "http"
|
|
|
|
}
|
|
|
|
//console.log("Got i2p proxy scheme:", proxy_scheme);
|
|
|
|
return proxy_scheme;
|
2019-06-17 19:17:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
var proxy_host = "127.0.0.1"
|
2019-07-13 22:07:24 -04:00
|
|
|
var proxy_port = "4444"
|
|
|
|
var control_host = "127.0.0.1"
|
|
|
|
var control_port = "4444"
|
2019-06-17 19:17:11 -04:00
|
|
|
|
|
|
|
function getHost() {
|
2019-07-13 22:07:24 -04:00
|
|
|
if (proxy_host == undefined) {
|
|
|
|
proxy_host = "127.0.0.1"
|
|
|
|
}
|
|
|
|
return proxy_host;
|
2019-06-17 19:17:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function getPort() {
|
2019-07-13 22:07:24 -04:00
|
|
|
if (proxy_port == undefined) {
|
|
|
|
var scheme = getScheme()
|
|
|
|
if (scheme == "socks") {
|
|
|
|
proxy_port = "4446"
|
|
|
|
} else {
|
|
|
|
proxy_port = "4444"
|
|
|
|
}
|
2019-06-17 19:17:11 -04:00
|
|
|
}
|
2019-07-13 22:07:24 -04:00
|
|
|
return proxy_port;
|
2019-06-17 19:17:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function getControlHost() {
|
2019-07-13 22:07:24 -04:00
|
|
|
if (control_host == undefined) {
|
|
|
|
return "127.0.0.1"
|
|
|
|
}
|
|
|
|
return control_host;
|
2019-06-17 19:17:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function getControlPort() {
|
2019-07-13 22:07:24 -04:00
|
|
|
if (control_port == undefined) {
|
|
|
|
return "4444"
|
|
|
|
}
|
|
|
|
return control_port;
|
2019-05-03 18:40:46 -04:00
|
|
|
}
|
|
|
|
|
2019-02-07 17:25:06 -05:00
|
|
|
function setupProxy() {
|
2019-07-13 22:07:24 -04:00
|
|
|
var controlHost = getControlHost()
|
|
|
|
var controlPort = getControlPort();
|
|
|
|
var Host = getHost()
|
|
|
|
var Port = getPort()
|
|
|
|
var Scheme = getScheme()
|
|
|
|
if (!getChrome()) {
|
|
|
|
/**/
|
|
|
|
console.log("Setting up Firefox WebExtension proxy")
|
|
|
|
browser.proxy.onRequest.addListener(handleContextProxyRequest, {
|
|
|
|
urls: ["<all_urls>"]
|
|
|
|
});
|
|
|
|
console.log("i2p settings created for WebExtension Proxy")
|
|
|
|
/**/
|
|
|
|
} else {
|
|
|
|
var config = {
|
|
|
|
mode: "fixed_servers",
|
|
|
|
rules: {
|
|
|
|
singleProxy: {
|
|
|
|
scheme: Scheme,
|
|
|
|
host: Host,
|
|
|
|
port: parseInt(Port),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
};
|
|
|
|
chrome.proxy.settings.set({
|
|
|
|
value: config,
|
|
|
|
scope: 'regular'
|
|
|
|
}, function() {});
|
2019-02-07 17:09:31 -05:00
|
|
|
}
|
2019-07-13 22:07:24 -04:00
|
|
|
}
|
|
|
|
|
2019-06-17 19:17:11 -04:00
|
|
|
function checkStoredSettings(storedSettings) {
|
2019-07-13 22:07:24 -04:00
|
|
|
let defaultSettings = {};
|
|
|
|
if (!storedSettings.proxy_scheme) {
|
|
|
|
defaultSettings["proxy_scheme"] = "http"
|
|
|
|
}
|
|
|
|
if (!storedSettings.proxy_host) {
|
|
|
|
defaultSettings["proxy_host"] = "127.0.0.1"
|
|
|
|
}
|
|
|
|
if (!storedSettings.proxy_port) {
|
|
|
|
defaultSettings["proxy_port"] = 4444
|
|
|
|
}
|
|
|
|
if (!storedSettings.control_host) {
|
|
|
|
defaultSettings["control_host"] = "127.0.0.1"
|
|
|
|
}
|
|
|
|
if (!storedSettings.control_port) {
|
|
|
|
defaultSettings["control_port"] = 4444
|
|
|
|
}
|
|
|
|
chrome.storage.local.set(defaultSettings);
|
2019-03-15 21:45:59 -04:00
|
|
|
}
|
2019-05-02 17:31:04 -04:00
|
|
|
|
2019-06-17 19:17:11 -04:00
|
|
|
function update(restoredSettings) {
|
2019-07-13 22:07:24 -04:00
|
|
|
proxy_scheme = restoredSettings.proxy_scheme
|
|
|
|
console.log("restoring proxy scheme:", proxy_scheme)
|
|
|
|
proxy_host = restoredSettings.proxy_host
|
|
|
|
console.log("restoring proxy host:", proxy_host)
|
|
|
|
proxy_port = restoredSettings.proxy_port
|
|
|
|
console.log("restoring proxy port:", proxy_port)
|
|
|
|
control_host = restoredSettings.control_host
|
|
|
|
console.log("restoring control host:", control_host)
|
|
|
|
control_port = restoredSettings.control_port
|
|
|
|
console.log("restoring control port:", control_port)
|
2019-06-17 19:17:11 -04:00
|
|
|
}
|
|
|
|
|
2019-06-27 15:40:43 -04:00
|
|
|
chrome.storage.local.get(function(got) {
|
2019-07-13 22:07:24 -04:00
|
|
|
checkStoredSettings(got)
|
|
|
|
update(got)
|
|
|
|
setupProxy()
|
2019-06-17 19:17:11 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
// Theme all currently open windows
|
2019-06-19 10:44:03 -04:00
|
|
|
if (!getChrome()) {
|
2019-07-13 22:07:24 -04:00
|
|
|
if (!isDroid()) {
|
|
|
|
browser.windows.getAll().then(wins => wins.forEach(themeWindow));
|
|
|
|
}
|
2019-05-02 17:31:04 -04:00
|
|
|
}
|