2020-06-22 21:49:14 -04:00
|
|
|
var titlepref = chrome.i18n.getMessage('titlePreface');
|
|
|
|
var webpref = chrome.i18n.getMessage('webPreface');
|
|
|
|
var routerpref = chrome.i18n.getMessage('routerPreface');
|
|
|
|
var mailpref = chrome.i18n.getMessage('mailPreface');
|
|
|
|
var torrentpref = chrome.i18n.getMessage('torrentPreface');
|
|
|
|
var tunnelpref = chrome.i18n.getMessage('i2ptunnelPreface');
|
|
|
|
var localpref = chrome.i18n.getMessage('localPreface');
|
|
|
|
var extensionpref = chrome.i18n.getMessage('extensionPreface');
|
|
|
|
var muwirepref = chrome.i18n.getMessage('muwirePreface');
|
2019-11-11 23:31:37 -05:00
|
|
|
|
2019-10-06 13:58:26 -04:00
|
|
|
var contextScrub = async function(requestDetails) {
|
2020-01-02 15:43:24 -05:00
|
|
|
function onHeaderError() {
|
2020-06-22 21:49:14 -04:00
|
|
|
console.log('Header scrub error');
|
2020-01-02 15:43:24 -05:00
|
|
|
}
|
2020-01-14 23:31:41 -05:00
|
|
|
//console.log("(scrub)Scrubbing info from contextualized request");
|
2019-10-06 15:18:10 -04:00
|
|
|
try {
|
|
|
|
var headerScrub = function(context) {
|
2020-06-22 21:49:14 -04:00
|
|
|
var ua = 'MYOB/6.66 (AN/ON)';
|
2019-10-06 15:18:10 -04:00
|
|
|
if (!context) {
|
2019-11-11 23:31:37 -05:00
|
|
|
} else if (context.name == titlepref) {
|
2019-11-10 20:28:31 -05:00
|
|
|
if (i2pHost(requestDetails.url)) {
|
|
|
|
for (var header of requestDetails.requestHeaders) {
|
2020-06-22 21:49:14 -04:00
|
|
|
if (header.name.toLowerCase() === 'user-agent') {
|
2019-11-10 20:28:31 -05:00
|
|
|
header.value = ua;
|
2020-06-22 21:49:14 -04:00
|
|
|
console.log('(scrub)User-Agent header modified', header.value);
|
2019-10-06 13:58:26 -04:00
|
|
|
}
|
2019-10-06 15:18:10 -04:00
|
|
|
}
|
2019-10-06 13:58:26 -04:00
|
|
|
}
|
2019-11-10 20:28:31 -05:00
|
|
|
return {
|
|
|
|
requestHeaders: requestDetails.requestHeaders
|
|
|
|
};
|
2019-11-11 23:31:37 -05:00
|
|
|
} else if (context.name == routerpref) {
|
2019-11-10 20:28:31 -05:00
|
|
|
if (i2pHost(requestDetails.url)) {
|
|
|
|
for (var header of requestDetails.requestHeaders) {
|
2020-06-22 21:49:14 -04:00
|
|
|
if (header.name.toLowerCase() === 'user-agent') {
|
2019-11-10 20:28:31 -05:00
|
|
|
header.value = ua;
|
2020-06-22 21:49:14 -04:00
|
|
|
console.log('(scrub)User-Agent header modified', header.value);
|
2019-11-10 20:28:31 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
requestHeaders: requestDetails.requestHeaders
|
|
|
|
};
|
2019-10-06 15:18:10 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
var contextGet = async function(tabInfo) {
|
|
|
|
try {
|
2020-01-14 23:31:41 -05:00
|
|
|
//console.log("(scrub)Tab info from Function", tabInfo);
|
2019-12-24 20:58:53 -05:00
|
|
|
let context = await browser.contextualIdentities.get(
|
|
|
|
tabInfo.cookieStoreId
|
|
|
|
);
|
2019-10-06 15:18:10 -04:00
|
|
|
return context;
|
|
|
|
} catch (error) {
|
2019-12-24 21:14:40 -05:00
|
|
|
return undefined;
|
2019-10-06 15:18:10 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
var tabGet = async function(tabId) {
|
|
|
|
try {
|
2020-01-14 23:31:41 -05:00
|
|
|
//console.log("(scrub)Tab ID from Request", tabId);
|
2019-10-06 15:18:10 -04:00
|
|
|
let tabInfo = await browser.tabs.get(tabId);
|
|
|
|
return tabInfo;
|
|
|
|
} catch (error) {
|
2019-12-24 21:18:28 -05:00
|
|
|
return undefined;
|
2019-10-06 15:18:10 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
if (requestDetails.tabId > 0) {
|
2019-11-10 20:28:31 -05:00
|
|
|
var tab = {};
|
|
|
|
var context = {};
|
|
|
|
var req = {};
|
2019-10-08 19:10:13 -04:00
|
|
|
if (i2pHost(requestDetails.url)) {
|
2020-01-14 23:31:41 -05:00
|
|
|
//console.log("(scrub)I2P URL detected, ");
|
2019-11-10 20:28:31 -05:00
|
|
|
tab = tabGet(requestDetails.tabId);
|
2020-01-02 15:43:24 -05:00
|
|
|
context = tab.then(contextGet, onHeaderError);
|
|
|
|
req = await context.then(headerScrub, onHeaderError);
|
2020-01-14 23:31:41 -05:00
|
|
|
//console.log("(scrub)Scrubbing I2P Request", req);
|
2019-10-07 20:52:03 -04:00
|
|
|
return req;
|
2019-11-11 16:34:41 -05:00
|
|
|
} else if (routerHost(requestDetails.url)) {
|
2019-11-10 20:28:31 -05:00
|
|
|
tab = tabGet(requestDetails.tabId);
|
2020-01-02 15:43:24 -05:00
|
|
|
context = tab.then(contextGet, onHeaderError);
|
|
|
|
req = await context.then(headerScrub, onHeaderError);
|
2020-01-14 23:31:41 -05:00
|
|
|
//console.log("(scrub)Scrubbing non-I2P Request", req);
|
2019-10-07 18:45:52 -04:00
|
|
|
return req;
|
|
|
|
}
|
2019-11-11 16:34:41 -05:00
|
|
|
return req;
|
2019-10-06 13:58:26 -04:00
|
|
|
}
|
2019-10-06 15:18:10 -04:00
|
|
|
} catch (error) {
|
2020-06-22 21:49:14 -04:00
|
|
|
console.log('(scrub)Not scrubbing non-I2P request.', error);
|
2019-10-07 20:52:03 -04:00
|
|
|
}
|
2020-06-22 21:49:14 -04:00
|
|
|
}
|
2019-10-07 20:52:03 -04:00
|
|
|
|
2020-03-02 17:35:49 -05:00
|
|
|
var notMyContextNotMyProblem = async function() {
|
|
|
|
var contexts = await browser.contextualIdentities.query({});
|
2020-03-02 17:34:39 -05:00
|
|
|
var context1 = await browser.contextualIdentities.query({
|
|
|
|
name: titlepref
|
|
|
|
});
|
|
|
|
var context2 = await browser.contextualIdentities.query({
|
|
|
|
name: routerpref
|
|
|
|
});
|
|
|
|
var context3 = await browser.contextualIdentities.query({
|
|
|
|
name: mailpref
|
|
|
|
});
|
|
|
|
var context4 = await browser.contextualIdentities.query({
|
|
|
|
name: torrentpref
|
|
|
|
});
|
|
|
|
var context5 = await browser.contextualIdentities.query({
|
|
|
|
name: tunnelpref
|
|
|
|
});
|
|
|
|
var context6 = await browser.contextualIdentities.query({
|
|
|
|
name: localpref
|
|
|
|
});
|
2020-03-23 18:02:23 -04:00
|
|
|
var context7 = await browser.contextualIdentities.query({
|
|
|
|
name: muwirepref
|
|
|
|
});
|
2020-03-02 17:35:49 -05:00
|
|
|
var othercontexts = [];
|
2020-06-22 21:49:14 -04:00
|
|
|
console.log('Contexts:', contexts);
|
2020-03-02 17:34:39 -05:00
|
|
|
for (context in contexts) {
|
2020-03-02 17:35:49 -05:00
|
|
|
if (
|
|
|
|
contexts[context].cookieStoreId == context1[0].cookieStoreId ||
|
|
|
|
contexts[context].cookieStoreId == context2[0].cookieStoreId ||
|
|
|
|
contexts[context].cookieStoreId == context3[0].cookieStoreId ||
|
|
|
|
contexts[context].cookieStoreId == context4[0].cookieStoreId ||
|
|
|
|
contexts[context].cookieStoreId == context5[0].cookieStoreId ||
|
2020-03-23 18:02:23 -04:00
|
|
|
contexts[context].cookieStoreId == context6[0].cookieStoreId ||
|
|
|
|
contexts[context].cookieStoreId == context7[0].cookieStoreId
|
2020-03-02 17:35:49 -05:00
|
|
|
) {
|
|
|
|
console.log(
|
2020-06-22 21:49:14 -04:00
|
|
|
'Context found',
|
2020-03-02 17:35:49 -05:00
|
|
|
contexts[context].cookieStoreId,
|
2020-06-22 21:49:14 -04:00
|
|
|
'is my responsibility'
|
2020-03-02 17:35:49 -05:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
//console.log("Context found", contexts[context].cookieStoreId, "is not my responsibility")
|
|
|
|
othercontexts.push(contexts[context]);
|
2020-03-02 17:34:39 -05:00
|
|
|
}
|
|
|
|
}
|
2020-03-02 17:35:49 -05:00
|
|
|
return othercontexts;
|
2020-06-22 21:49:14 -04:00
|
|
|
}
|
2020-03-02 17:34:39 -05:00
|
|
|
|
2020-01-04 10:29:41 -05:00
|
|
|
var contextSetup = function(requestDetails) {
|
2020-01-02 15:43:24 -05:00
|
|
|
function onContextError() {
|
2020-06-22 21:49:14 -04:00
|
|
|
console.log('Context launcher error');
|
2020-01-02 15:43:24 -05:00
|
|
|
}
|
2020-01-14 23:31:41 -05:00
|
|
|
//console.log("(isolate)Forcing I2P requests into context");
|
2019-10-07 20:52:03 -04:00
|
|
|
try {
|
2019-11-24 23:29:06 -05:00
|
|
|
var i2pTabFind = async function(tabId) {
|
2019-10-07 20:52:03 -04:00
|
|
|
try {
|
2019-11-10 20:28:31 -05:00
|
|
|
var context = await browser.contextualIdentities.query({
|
2019-11-11 23:31:37 -05:00
|
|
|
name: titlepref
|
2019-10-07 21:26:52 -04:00
|
|
|
});
|
2019-10-07 20:52:03 -04:00
|
|
|
if (tabId.cookieStoreId != context[0].cookieStoreId) {
|
2020-01-02 15:43:24 -05:00
|
|
|
function Create() {
|
2019-10-07 21:26:52 -04:00
|
|
|
function onCreated(tab) {
|
2020-01-02 15:43:24 -05:00
|
|
|
function closeOldTab() {
|
|
|
|
if (tabId.id != tab.id) {
|
2020-06-22 21:49:14 -04:00
|
|
|
console.log('(isolate) Closing un-isolated tab', tabId.id);
|
|
|
|
console.log('in favor of', tab.id);
|
|
|
|
console.log('with context', tab.cookieStoreId);
|
2020-01-02 15:43:24 -05:00
|
|
|
browser.tabs.remove(tabId.id);
|
2019-12-24 22:21:04 -05:00
|
|
|
}
|
2020-02-26 13:03:09 -05:00
|
|
|
browser.pageAction.setPopup({
|
2020-03-05 23:25:08 -05:00
|
|
|
tabId: tabId.id,
|
2020-06-22 21:49:14 -04:00
|
|
|
popup: 'security.html'
|
2020-02-26 13:03:09 -05:00
|
|
|
});
|
2020-02-26 13:00:51 -05:00
|
|
|
browser.pageAction.show(tabId.id);
|
2019-11-27 00:58:53 -05:00
|
|
|
}
|
2019-12-24 22:21:04 -05:00
|
|
|
closeOldTab(tab);
|
2019-10-08 19:10:13 -04:00
|
|
|
}
|
2019-11-10 20:28:31 -05:00
|
|
|
var created = browser.tabs.create({
|
2019-10-08 19:10:13 -04:00
|
|
|
active: true,
|
|
|
|
cookieStoreId: context[0].cookieStoreId,
|
2019-11-27 00:34:48 -05:00
|
|
|
url: requestDetails.url
|
2019-10-08 19:10:13 -04:00
|
|
|
});
|
2020-01-02 15:43:24 -05:00
|
|
|
created.then(onCreated, onContextError);
|
2019-10-08 19:10:13 -04:00
|
|
|
}
|
2019-12-24 21:23:37 -05:00
|
|
|
var gettab = browser.tabs.get(tabId.id);
|
2020-01-02 15:43:24 -05:00
|
|
|
gettab.then(Create, onContextError);
|
2019-10-08 19:10:13 -04:00
|
|
|
return tabId;
|
|
|
|
}
|
|
|
|
} catch (error) {
|
2020-06-22 21:49:14 -04:00
|
|
|
console.log('(isolate)Context Error', error);
|
2019-10-08 19:10:13 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
var routerTabFind = async function(tabId) {
|
|
|
|
try {
|
2019-11-10 20:28:31 -05:00
|
|
|
var context = await browser.contextualIdentities.query({
|
2019-11-11 23:31:37 -05:00
|
|
|
name: routerpref
|
2019-10-08 19:10:13 -04:00
|
|
|
});
|
|
|
|
if (tabId.cookieStoreId != context[0].cookieStoreId) {
|
2020-01-02 15:43:24 -05:00
|
|
|
function Create() {
|
2019-11-11 16:34:41 -05:00
|
|
|
function onCreated(tab) {
|
2020-03-17 04:42:24 -04:00
|
|
|
function closeOldTab(tabs) {
|
2020-01-02 15:43:24 -05:00
|
|
|
if (tabId.id != tab.id) {
|
2020-06-22 21:49:14 -04:00
|
|
|
console.log('(isolate) Closing un-isolated tab', tabId.id);
|
|
|
|
console.log('in favor of', tab.id);
|
|
|
|
console.log('with context', tab.cookieStoreId);
|
2020-01-02 15:43:24 -05:00
|
|
|
browser.tabs.remove(tabId.id);
|
2020-07-08 17:53:21 -04:00
|
|
|
browser.tabs.move(tab.id, {index:0});
|
2019-12-24 22:21:04 -05:00
|
|
|
}
|
2020-03-17 04:42:24 -04:00
|
|
|
for (index = 0; index < tabs.length; index++) {
|
|
|
|
if (index != tabs.length - 1)
|
|
|
|
browser.tabs.remove(tabs[index].id);
|
|
|
|
}
|
2019-11-27 00:58:53 -05:00
|
|
|
}
|
2020-03-17 04:42:24 -04:00
|
|
|
var pins = browser.tabs.query({
|
|
|
|
cookieStoreId: context[0].cookieStoreId
|
|
|
|
});
|
|
|
|
pins.then(closeOldTab, onError);
|
2019-11-11 16:34:41 -05:00
|
|
|
}
|
|
|
|
var created = browser.tabs.create({
|
|
|
|
active: true,
|
2020-03-17 04:42:24 -04:00
|
|
|
pinned: true,
|
2019-11-11 16:34:41 -05:00
|
|
|
cookieStoreId: context[0].cookieStoreId,
|
2019-11-27 00:34:48 -05:00
|
|
|
url: requestDetails.url
|
2019-11-11 16:34:41 -05:00
|
|
|
});
|
2020-01-02 15:43:24 -05:00
|
|
|
created.then(onCreated, onContextError);
|
2019-11-11 16:34:41 -05:00
|
|
|
}
|
2019-12-24 21:23:37 -05:00
|
|
|
var gettab = browser.tabs.get(tabId.id);
|
2020-01-02 15:43:24 -05:00
|
|
|
gettab.then(Create, onContextError);
|
2019-11-11 16:34:41 -05:00
|
|
|
return tabId;
|
|
|
|
}
|
|
|
|
} catch (error) {
|
2020-06-22 21:49:14 -04:00
|
|
|
console.log('(isolate)Context Error', error);
|
2019-11-11 16:34:41 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
var i2ptunnelTabFind = async function(tabId) {
|
|
|
|
try {
|
|
|
|
var context = await browser.contextualIdentities.query({
|
2019-11-11 23:31:37 -05:00
|
|
|
name: tunnelpref
|
2019-11-11 16:34:41 -05:00
|
|
|
});
|
|
|
|
if (tabId.cookieStoreId != context[0].cookieStoreId) {
|
2020-01-02 15:43:24 -05:00
|
|
|
function Create() {
|
2019-11-11 16:34:41 -05:00
|
|
|
function onCreated(tab) {
|
2020-03-17 04:42:24 -04:00
|
|
|
function closeOldTab(tabs) {
|
2020-01-02 15:43:24 -05:00
|
|
|
if (tabId.id != tab.id) {
|
2020-06-22 21:49:14 -04:00
|
|
|
console.log('(isolate) Closing un-isolated tab', tabId.id);
|
|
|
|
console.log('in favor of', tab.id);
|
|
|
|
console.log('with context', tab.cookieStoreId);
|
2020-01-02 15:43:24 -05:00
|
|
|
browser.tabs.remove(tabId.id);
|
2020-07-08 17:53:21 -04:00
|
|
|
browser.tabs.move(tab.id, {index:1});
|
2019-12-24 22:21:04 -05:00
|
|
|
}
|
2020-03-17 04:42:24 -04:00
|
|
|
for (index = 0; index < tabs.length; index++) {
|
|
|
|
if (index != tabs.length - 1)
|
|
|
|
browser.tabs.remove(tabs[index].id);
|
|
|
|
}
|
2019-11-27 00:58:53 -05:00
|
|
|
}
|
2020-03-17 04:42:24 -04:00
|
|
|
var pins = browser.tabs.query({
|
|
|
|
cookieStoreId: context[0].cookieStoreId
|
|
|
|
});
|
|
|
|
pins.then(closeOldTab, onError);
|
2019-11-11 16:34:41 -05:00
|
|
|
}
|
|
|
|
var created = browser.tabs.create({
|
|
|
|
active: true,
|
2020-03-17 04:42:24 -04:00
|
|
|
pinned: true,
|
2019-11-11 16:34:41 -05:00
|
|
|
cookieStoreId: context[0].cookieStoreId,
|
2019-11-27 00:34:48 -05:00
|
|
|
url: requestDetails.url
|
2019-11-11 16:34:41 -05:00
|
|
|
});
|
2020-01-02 15:43:24 -05:00
|
|
|
created.then(onCreated, onContextError);
|
2019-11-11 16:34:41 -05:00
|
|
|
}
|
2019-12-24 21:23:37 -05:00
|
|
|
var gettab = browser.tabs.get(tabId.id);
|
2020-01-02 15:43:24 -05:00
|
|
|
gettab.then(Create, onContextError);
|
2019-11-11 16:34:41 -05:00
|
|
|
return tabId;
|
|
|
|
}
|
|
|
|
} catch (error) {
|
2020-06-22 21:49:14 -04:00
|
|
|
console.log('(isolate)Context Error', error);
|
2019-11-11 16:34:41 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
var snarkTabFind = async function(tabId) {
|
|
|
|
try {
|
|
|
|
var context = await browser.contextualIdentities.query({
|
2019-11-11 23:31:37 -05:00
|
|
|
name: torrentpref
|
2019-11-11 16:34:41 -05:00
|
|
|
});
|
|
|
|
if (tabId.cookieStoreId != context[0].cookieStoreId) {
|
2020-01-02 15:43:24 -05:00
|
|
|
function Create() {
|
2019-11-11 16:34:41 -05:00
|
|
|
function onCreated(tab) {
|
2020-03-17 04:42:24 -04:00
|
|
|
function closeOldTab(tabs) {
|
2020-01-02 15:43:24 -05:00
|
|
|
if (tabId.id != tab.id) {
|
2020-06-22 21:49:14 -04:00
|
|
|
console.log('(isolate) Closing un-isolated tab', tabId.id);
|
|
|
|
console.log('in favor of', tab.id);
|
|
|
|
console.log('with context', tab.cookieStoreId);
|
2020-01-02 15:43:24 -05:00
|
|
|
browser.tabs.remove(tabId.id);
|
2020-07-08 17:53:21 -04:00
|
|
|
browser.tabs.move(tab.id, {index:2});
|
2019-12-24 22:21:04 -05:00
|
|
|
}
|
2020-03-17 04:42:24 -04:00
|
|
|
for (index = 0; index < tabs.length; index++) {
|
|
|
|
if (index != tabs.length - 1)
|
|
|
|
browser.tabs.remove(tabs[index].id);
|
|
|
|
}
|
2019-11-27 00:58:53 -05:00
|
|
|
}
|
2020-03-17 04:42:24 -04:00
|
|
|
var pins = browser.tabs.query({
|
|
|
|
cookieStoreId: context[0].cookieStoreId
|
|
|
|
});
|
|
|
|
pins.then(closeOldTab, onError);
|
2019-11-11 16:34:41 -05:00
|
|
|
}
|
|
|
|
var created = browser.tabs.create({
|
|
|
|
active: true,
|
2020-03-17 04:42:24 -04:00
|
|
|
pinned: true,
|
2019-11-11 16:34:41 -05:00
|
|
|
cookieStoreId: context[0].cookieStoreId,
|
2019-11-27 00:34:48 -05:00
|
|
|
url: requestDetails.url
|
2019-11-11 16:34:41 -05:00
|
|
|
});
|
2020-01-02 15:43:24 -05:00
|
|
|
created.then(onCreated, onContextError);
|
2019-11-11 16:34:41 -05:00
|
|
|
}
|
2019-12-24 21:23:37 -05:00
|
|
|
var gettab = browser.tabs.get(tabId.id);
|
2020-01-02 15:43:24 -05:00
|
|
|
gettab.then(Create, onContextError);
|
2019-11-11 16:34:41 -05:00
|
|
|
return tabId;
|
|
|
|
}
|
|
|
|
} catch (error) {
|
2020-06-22 21:49:14 -04:00
|
|
|
console.log('(isolate)Context Error', error);
|
2019-11-11 16:34:41 -05:00
|
|
|
}
|
|
|
|
};
|
2020-03-23 18:02:23 -04:00
|
|
|
var muwireTabFind = async function(tabId) {
|
|
|
|
try {
|
|
|
|
var context = await browser.contextualIdentities.query({
|
|
|
|
name: muwirepref
|
|
|
|
});
|
|
|
|
if (tabId.cookieStoreId != context[0].cookieStoreId) {
|
|
|
|
function Create() {
|
|
|
|
function onCreated(tab) {
|
|
|
|
function closeOldTab(tabs) {
|
|
|
|
if (tabId.id != tab.id) {
|
2020-06-22 21:49:14 -04:00
|
|
|
console.log('(isolate) Closing un-isolated tab', tabId.id);
|
|
|
|
console.log('in favor of', tab.id);
|
|
|
|
console.log('with context', tab.cookieStoreId);
|
2020-03-23 18:02:23 -04:00
|
|
|
browser.tabs.remove(tabId.id);
|
2020-07-08 17:53:21 -04:00
|
|
|
browser.tabs.move(tab.id, {index:4});
|
2020-03-23 18:02:23 -04:00
|
|
|
}
|
|
|
|
for (index = 0; index < tabs.length; index++) {
|
|
|
|
if (index != tabs.length - 1)
|
|
|
|
browser.tabs.remove(tabs[index].id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var pins = browser.tabs.query({
|
|
|
|
cookieStoreId: context[0].cookieStoreId
|
|
|
|
});
|
|
|
|
pins.then(closeOldTab, onError);
|
|
|
|
}
|
|
|
|
var created = browser.tabs.create({
|
|
|
|
active: true,
|
|
|
|
pinned: true,
|
|
|
|
cookieStoreId: context[0].cookieStoreId,
|
|
|
|
url: requestDetails.url
|
|
|
|
});
|
|
|
|
created.then(onCreated, onContextError);
|
|
|
|
}
|
|
|
|
var gettab = browser.tabs.get(tabId.id);
|
|
|
|
gettab.then(Create, onContextError);
|
|
|
|
return tabId;
|
|
|
|
}
|
|
|
|
} catch (error) {
|
2020-06-22 21:49:14 -04:00
|
|
|
console.log('(isolate)Context Error', error);
|
2020-03-23 18:02:23 -04:00
|
|
|
}
|
|
|
|
};
|
2019-11-11 16:34:41 -05:00
|
|
|
var mailTabFind = async function(tabId) {
|
|
|
|
try {
|
|
|
|
var context = await browser.contextualIdentities.query({
|
2019-11-11 23:31:37 -05:00
|
|
|
name: mailpref
|
2019-11-11 16:34:41 -05:00
|
|
|
});
|
|
|
|
if (tabId.cookieStoreId != context[0].cookieStoreId) {
|
2020-01-02 15:43:24 -05:00
|
|
|
function Create() {
|
2019-10-08 19:10:13 -04:00
|
|
|
function onCreated(tab) {
|
2020-03-17 04:42:24 -04:00
|
|
|
function closeOldTab(tabs) {
|
2020-01-02 15:43:24 -05:00
|
|
|
if (tabId.id != tab.id) {
|
2020-06-22 21:49:14 -04:00
|
|
|
console.log('(isolate) Closing un-isolated tab', tabId.id);
|
|
|
|
console.log('in favor of', tab.id);
|
|
|
|
console.log('with context', tab.cookieStoreId);
|
2020-01-02 15:43:24 -05:00
|
|
|
browser.tabs.remove(tabId.id);
|
2020-07-08 17:53:21 -04:00
|
|
|
browser.tabs.move(tab.id, {index:3});
|
2019-12-24 22:21:04 -05:00
|
|
|
}
|
2020-03-17 04:42:24 -04:00
|
|
|
for (index = 0; index < tabs.length; index++) {
|
|
|
|
if (index != tabs.length - 1)
|
|
|
|
browser.tabs.remove(tabs[index].id);
|
|
|
|
}
|
2019-11-27 00:58:53 -05:00
|
|
|
}
|
2020-03-17 04:42:24 -04:00
|
|
|
var pins = browser.tabs.query({
|
|
|
|
cookieStoreId: context[0].cookieStoreId
|
|
|
|
});
|
|
|
|
pins.then(closeOldTab, onError);
|
2019-10-07 21:26:52 -04:00
|
|
|
}
|
2019-11-10 20:28:31 -05:00
|
|
|
var created = browser.tabs.create({
|
2019-10-07 21:26:52 -04:00
|
|
|
active: true,
|
2020-03-17 04:42:24 -04:00
|
|
|
pinned: true,
|
2019-10-07 21:26:52 -04:00
|
|
|
cookieStoreId: context[0].cookieStoreId,
|
2019-11-27 00:34:48 -05:00
|
|
|
url: requestDetails.url
|
2019-10-07 21:26:52 -04:00
|
|
|
});
|
2020-01-02 15:43:24 -05:00
|
|
|
created.then(onCreated, onContextError);
|
2019-10-07 20:52:03 -04:00
|
|
|
}
|
2019-12-24 21:23:37 -05:00
|
|
|
var gettab = browser.tabs.get(tabId.id);
|
2020-01-02 15:43:24 -05:00
|
|
|
gettab.then(Create, onContextError);
|
2019-10-07 20:52:03 -04:00
|
|
|
return tabId;
|
|
|
|
}
|
|
|
|
} catch (error) {
|
2020-06-22 21:49:14 -04:00
|
|
|
console.log('(isolate)Context Error', error);
|
2019-10-07 20:52:03 -04:00
|
|
|
}
|
|
|
|
};
|
2019-12-24 18:31:44 -05:00
|
|
|
var localTabFind = async function(tabId) {
|
|
|
|
try {
|
|
|
|
var context = await browser.contextualIdentities.query({
|
|
|
|
name: localpref
|
|
|
|
});
|
|
|
|
if (tabId.cookieStoreId != context[0].cookieStoreId) {
|
2020-01-02 15:43:24 -05:00
|
|
|
function Create() {
|
2019-12-24 18:31:44 -05:00
|
|
|
function onCreated(tab) {
|
2020-01-02 15:43:24 -05:00
|
|
|
function closeOldTab() {
|
|
|
|
if (tabId.id != tab.id) {
|
2020-06-22 21:49:14 -04:00
|
|
|
console.log('(isolate) Closing un-isolated tab', tabId.id);
|
|
|
|
console.log('in favor of', tab.id);
|
|
|
|
console.log('with context', tab.cookieStoreId);
|
2020-01-02 15:43:24 -05:00
|
|
|
browser.tabs.remove(tabId.id);
|
2019-12-24 22:21:04 -05:00
|
|
|
}
|
2019-12-24 18:31:44 -05:00
|
|
|
}
|
2019-12-24 22:21:04 -05:00
|
|
|
closeOldTab(tab);
|
2019-12-24 18:31:44 -05:00
|
|
|
}
|
|
|
|
var created = browser.tabs.create({
|
|
|
|
active: true,
|
|
|
|
cookieStoreId: context[0].cookieStoreId,
|
|
|
|
url: requestDetails.url
|
|
|
|
});
|
2020-01-02 15:43:24 -05:00
|
|
|
created.then(onCreated, onContextError);
|
2019-12-24 18:31:44 -05:00
|
|
|
}
|
2019-12-24 21:23:37 -05:00
|
|
|
var gettab = browser.tabs.get(tabId.id);
|
2020-01-02 15:43:24 -05:00
|
|
|
gettab.then(Create, onContextError);
|
2019-12-24 18:31:44 -05:00
|
|
|
return tabId;
|
|
|
|
}
|
|
|
|
} catch (error) {
|
2020-06-22 21:49:14 -04:00
|
|
|
console.log('(isolate)Context Error', error);
|
2019-12-24 18:31:44 -05:00
|
|
|
}
|
|
|
|
};
|
2020-02-25 15:19:15 -05:00
|
|
|
var normalTabFind = async function(tabId) {
|
2020-02-25 16:51:39 -05:00
|
|
|
if (tabId == undefined) {
|
|
|
|
return;
|
|
|
|
}
|
2019-11-10 22:24:10 -05:00
|
|
|
try {
|
2020-02-25 15:19:15 -05:00
|
|
|
var anoncontext = await browser.contextualIdentities.query({
|
|
|
|
name: titlepref
|
|
|
|
});
|
|
|
|
var localcontext = await browser.contextualIdentities.query({
|
|
|
|
name: localpref
|
2019-11-10 22:24:10 -05:00
|
|
|
});
|
2020-03-02 17:34:39 -05:00
|
|
|
var othercontexts = await notMyContextNotMyProblem();
|
|
|
|
var nmp = false;
|
2020-03-02 17:35:49 -05:00
|
|
|
for (context in othercontexts) {
|
|
|
|
if (tabId.cookieStoreId == othercontexts[context].cookieStoreId) {
|
2020-06-22 21:49:14 -04:00
|
|
|
console.log('Not my problem');
|
2020-03-02 17:35:49 -05:00
|
|
|
nmp = true;
|
|
|
|
}
|
2020-03-02 17:34:39 -05:00
|
|
|
}
|
2019-11-11 16:34:41 -05:00
|
|
|
if (
|
2020-06-22 21:49:14 -04:00
|
|
|
tabId.cookieStoreId == 'firefox-default' ||
|
|
|
|
tabId.cookieStoreId == 'firefox-private' ||
|
2020-02-26 01:57:07 -05:00
|
|
|
tabId.cookieStoreId == anoncontext[0].cookieStoreId ||
|
2020-03-02 17:34:39 -05:00
|
|
|
tabId.cookieStoreId == localcontext[0].cookieStoreId ||
|
|
|
|
nmp
|
2020-02-25 16:51:39 -05:00
|
|
|
) {
|
|
|
|
console.log(
|
2020-06-22 21:49:14 -04:00
|
|
|
'(ISOLATE)',
|
2020-02-25 16:51:39 -05:00
|
|
|
tabId.cookieStoreId,
|
2020-06-22 21:49:14 -04:00
|
|
|
'not',
|
2020-02-25 16:51:39 -05:00
|
|
|
anoncontext[0].cookieStoreId,
|
|
|
|
localcontext[0].cookieStoreId
|
|
|
|
);
|
|
|
|
return;
|
2020-02-26 01:57:07 -05:00
|
|
|
} else {
|
2020-02-25 15:19:15 -05:00
|
|
|
function Create() {
|
|
|
|
function onCreated(tab) {
|
|
|
|
function closeOldTab() {
|
2020-02-25 16:51:39 -05:00
|
|
|
if (
|
|
|
|
tabId.id != tab.id &&
|
|
|
|
tabId.cookieStoreId != tab.cookieStoreId
|
|
|
|
) {
|
|
|
|
console.log(
|
2020-06-22 21:49:14 -04:00
|
|
|
'(isolate) Closing isolated tab',
|
2020-02-25 16:51:39 -05:00
|
|
|
tabId.id,
|
2020-06-22 21:49:14 -04:00
|
|
|
'with context',
|
2020-02-25 16:51:39 -05:00
|
|
|
tabId.cookieStoreId
|
|
|
|
);
|
|
|
|
console.log(
|
2020-06-22 21:49:14 -04:00
|
|
|
'(isolate) in favor of',
|
2020-02-25 16:51:39 -05:00
|
|
|
tab.id,
|
2020-06-22 21:49:14 -04:00
|
|
|
'with context',
|
2020-02-25 16:51:39 -05:00
|
|
|
tab.cookieStoreId
|
|
|
|
);
|
2020-02-25 15:19:15 -05:00
|
|
|
browser.tabs.remove(tabId.id);
|
2019-11-27 00:58:53 -05:00
|
|
|
}
|
2019-11-11 00:03:24 -05:00
|
|
|
}
|
2020-02-25 15:19:15 -05:00
|
|
|
closeOldTab(tab);
|
2019-11-10 22:24:10 -05:00
|
|
|
}
|
2020-02-25 15:19:15 -05:00
|
|
|
var created = browser.tabs.create({
|
|
|
|
active: true,
|
2020-06-22 21:49:14 -04:00
|
|
|
cookieStoreId: 'firefox-default',
|
2020-02-25 15:19:15 -05:00
|
|
|
url: requestDetails.url
|
|
|
|
});
|
|
|
|
created.then(onCreated, onContextError);
|
2019-11-10 22:24:10 -05:00
|
|
|
}
|
2020-02-25 15:19:15 -05:00
|
|
|
var gettab = browser.tabs.get(tabId.id);
|
|
|
|
gettab.then(Create, onContextError);
|
|
|
|
return tabId;
|
2019-11-10 22:24:10 -05:00
|
|
|
}
|
|
|
|
} catch (error) {
|
2020-06-22 21:49:14 -04:00
|
|
|
console.log('(isolate)Context Error', error);
|
2019-11-10 22:24:10 -05:00
|
|
|
}
|
|
|
|
};
|
2019-10-07 20:52:03 -04:00
|
|
|
var tabGet = async function(tabId) {
|
|
|
|
try {
|
2020-01-14 23:31:41 -05:00
|
|
|
//console.log("(isolate)Tab ID from Request", tabId);
|
2019-10-07 20:52:03 -04:00
|
|
|
let tabInfo = await browser.tabs.get(tabId);
|
|
|
|
return tabInfo;
|
|
|
|
} catch (error) {
|
2020-06-22 21:49:14 -04:00
|
|
|
console.log('(isolate)Tab error', error);
|
2019-10-07 20:52:03 -04:00
|
|
|
}
|
|
|
|
};
|
2019-11-26 22:45:49 -05:00
|
|
|
if (requestDetails == undefined) {
|
|
|
|
return requestDetails;
|
|
|
|
}
|
2020-01-13 17:14:08 -05:00
|
|
|
if (proxyHost(requestDetails.url)) {
|
|
|
|
setcookie = browser.cookies.set({
|
|
|
|
firstPartyDomain: i2pHostName(requestDetails.url),
|
|
|
|
url: requestDetails.url,
|
|
|
|
secure: true
|
|
|
|
});
|
|
|
|
setcookie.then(onContextGotLog, onContextError);
|
|
|
|
return requestDetails;
|
|
|
|
}
|
2020-01-14 10:26:35 -05:00
|
|
|
|
2019-10-07 20:52:03 -04:00
|
|
|
if (requestDetails.tabId > 0) {
|
2020-01-02 15:43:24 -05:00
|
|
|
var tab = tabGet(requestDetails.tabId);
|
2019-10-08 19:10:13 -04:00
|
|
|
if (i2pHost(requestDetails.url)) {
|
2019-12-25 00:42:16 -05:00
|
|
|
var setcookie = browser.cookies.set({
|
2019-11-22 13:24:19 -05:00
|
|
|
firstPartyDomain: i2pHostName(requestDetails.url),
|
|
|
|
url: requestDetails.url,
|
|
|
|
secure: true
|
|
|
|
});
|
2020-01-02 15:43:24 -05:00
|
|
|
setcookie.then(onContextGotLog, onContextError);
|
|
|
|
var i2ptab = tab.then(i2pTabFind, onContextError);
|
2019-10-07 20:52:03 -04:00
|
|
|
return requestDetails;
|
2019-10-08 19:10:13 -04:00
|
|
|
}
|
2020-01-14 10:26:35 -05:00
|
|
|
if (extensionHost(requestDetails)) {
|
|
|
|
return requestDetails;
|
|
|
|
}
|
2019-12-24 18:31:44 -05:00
|
|
|
let localhost = localHost(requestDetails.url);
|
2019-11-11 16:34:41 -05:00
|
|
|
let routerhost = routerHost(requestDetails.url);
|
|
|
|
if (routerhost) {
|
2020-06-22 21:49:14 -04:00
|
|
|
if (routerhost === 'i2ptunnelmgr') {
|
2020-01-02 15:43:24 -05:00
|
|
|
var tunneltab = tab.then(i2ptunnelTabFind, onContextError);
|
2019-11-11 16:34:41 -05:00
|
|
|
return requestDetails;
|
2020-06-22 21:49:14 -04:00
|
|
|
} else if (routerhost === 'i2psnark') {
|
2020-01-02 15:43:24 -05:00
|
|
|
var snarktab = tab.then(snarkTabFind, onContextError);
|
2019-11-11 16:34:41 -05:00
|
|
|
return requestDetails;
|
2020-06-22 21:49:14 -04:00
|
|
|
} else if (routerhost === 'webmail') {
|
2020-01-02 15:43:24 -05:00
|
|
|
var mailtab = tab.then(mailTabFind, onContextError);
|
2019-11-11 16:34:41 -05:00
|
|
|
return requestDetails;
|
2020-06-22 21:49:14 -04:00
|
|
|
} else if (routerhost === 'muwire') {
|
2020-03-23 18:02:23 -04:00
|
|
|
var routertab = tab.then(muwireTabFind, onContextError);
|
|
|
|
return requestDetails;
|
2020-06-22 21:49:14 -04:00
|
|
|
} else if (routerhost === 'routerconsole') {
|
2020-03-24 18:51:47 -04:00
|
|
|
var routertab = tab.then(routerTabFind, onContextError);
|
|
|
|
return requestDetails;
|
2020-03-24 18:53:27 -04:00
|
|
|
}
|
2019-11-11 16:34:41 -05:00
|
|
|
} else {
|
2020-02-25 16:51:39 -05:00
|
|
|
if (localhost) {
|
|
|
|
var localtab = tab.then(localTabFind, onContextError);
|
|
|
|
return requestDetails;
|
|
|
|
}
|
|
|
|
var normalTab = tab.then(normalTabFind, onContextError);
|
2019-10-07 20:52:03 -04:00
|
|
|
return requestDetails;
|
2020-02-25 16:51:39 -05:00
|
|
|
//return requestDetails;
|
2019-10-07 20:52:03 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (error) {
|
2020-06-22 21:49:14 -04:00
|
|
|
console.log('(isolate)Not an I2P request, blackholing', error);
|
2019-10-06 15:18:10 -04:00
|
|
|
}
|
|
|
|
};
|
2019-10-06 13:58:26 -04:00
|
|
|
|
2019-10-07 20:52:03 -04:00
|
|
|
browser.webRequest.onBeforeRequest.addListener(
|
|
|
|
contextSetup,
|
2020-06-22 21:49:14 -04:00
|
|
|
{ urls: ['<all_urls>'] },
|
|
|
|
['blocking']
|
2019-10-07 20:52:03 -04:00
|
|
|
);
|
|
|
|
|
2019-10-06 13:58:26 -04:00
|
|
|
browser.webRequest.onBeforeSendHeaders.addListener(
|
2019-10-06 15:18:10 -04:00
|
|
|
contextScrub,
|
2020-06-22 21:49:14 -04:00
|
|
|
{ urls: ['<all_urls>'] },
|
|
|
|
['blocking', 'requestHeaders']
|
2019-10-06 13:58:26 -04:00
|
|
|
);
|