2020-12-03 12:20:43 -05: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 ircpref = chrome.i18n.getMessage('ircPreface');
|
|
|
|
var extensionpref = chrome.i18n.getMessage('extensionPreface');
|
|
|
|
var muwirepref = chrome.i18n.getMessage('muwirePreface');
|
|
|
|
var botepref = chrome.i18n.getMessage('botePreface');
|
2019-11-11 23:31:37 -05:00
|
|
|
|
2020-12-03 12:20:43 -05:00
|
|
|
var contextScrub = async function(requestDetails) {
|
2020-01-02 15:43:24 -05:00
|
|
|
function onHeaderError() {
|
2020-12-03 12:20:43 -05: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 {
|
2020-12-03 12:20:43 -05:00
|
|
|
var headerScrub = function(context) {
|
|
|
|
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-12-03 12:20:43 -05:00
|
|
|
if (header.name.toLowerCase() === 'user-agent') {
|
2019-11-10 20:28:31 -05:00
|
|
|
header.value = ua;
|
2020-12-03 12:20:43 -05: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 {
|
2020-11-10 21:48:08 -05:00
|
|
|
requestHeaders: requestDetails.requestHeaders,
|
2019-11-10 20:28:31 -05:00
|
|
|
};
|
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-12-03 12:20:43 -05:00
|
|
|
if (header.name.toLowerCase() === 'user-agent') {
|
2019-11-10 20:28:31 -05:00
|
|
|
header.value = ua;
|
2020-12-03 12:20:43 -05:00
|
|
|
console.log('(scrub)User-Agent header modified', header.value);
|
2019-11-10 20:28:31 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {
|
2020-11-10 21:48:08 -05:00
|
|
|
requestHeaders: requestDetails.requestHeaders,
|
2019-11-10 20:28:31 -05:00
|
|
|
};
|
2019-10-06 15:18:10 -04:00
|
|
|
}
|
|
|
|
};
|
2020-12-03 12:20:43 -05:00
|
|
|
var contextGet = async function(tabInfo) {
|
2019-10-06 15:18:10 -04:00
|
|
|
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
|
|
|
}
|
|
|
|
};
|
2020-12-03 12:20:43 -05:00
|
|
|
var tabGet = async function(tabId) {
|
2019-10-06 15:18:10 -04:00
|
|
|
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-12-03 12:20:43 -05:00
|
|
|
console.log('(scrub)Not scrubbing non-I2P request.', error);
|
2019-10-07 20:52:03 -04:00
|
|
|
}
|
2020-12-03 12:20:43 -05:00
|
|
|
}
|
2019-10-07 20:52:03 -04:00
|
|
|
|
2020-12-03 12:20:43 -05:00
|
|
|
var notMyContextNotMyProblem = async function() {
|
2020-03-02 17:35:49 -05:00
|
|
|
var contexts = await browser.contextualIdentities.query({});
|
2020-03-02 17:34:39 -05:00
|
|
|
var context1 = await browser.contextualIdentities.query({
|
2020-11-10 21:48:08 -05:00
|
|
|
name: titlepref,
|
2020-03-02 17:34:39 -05:00
|
|
|
});
|
|
|
|
var context2 = await browser.contextualIdentities.query({
|
2020-11-10 21:48:08 -05:00
|
|
|
name: routerpref,
|
2020-03-02 17:34:39 -05:00
|
|
|
});
|
|
|
|
var context3 = await browser.contextualIdentities.query({
|
2020-11-10 21:48:08 -05:00
|
|
|
name: mailpref,
|
2020-03-02 17:34:39 -05:00
|
|
|
});
|
|
|
|
var context4 = await browser.contextualIdentities.query({
|
2020-11-10 21:48:08 -05:00
|
|
|
name: torrentpref,
|
2020-03-02 17:34:39 -05:00
|
|
|
});
|
|
|
|
var context5 = await browser.contextualIdentities.query({
|
2020-11-10 21:48:08 -05:00
|
|
|
name: tunnelpref,
|
2020-03-02 17:34:39 -05:00
|
|
|
});
|
|
|
|
var context6 = await browser.contextualIdentities.query({
|
2020-11-10 21:48:08 -05:00
|
|
|
name: ircpref,
|
2020-03-02 17:34:39 -05:00
|
|
|
});
|
2020-03-23 18:02:23 -04:00
|
|
|
var context7 = await browser.contextualIdentities.query({
|
2020-11-10 21:48:08 -05:00
|
|
|
name: muwirepref,
|
2020-03-23 18:02:23 -04:00
|
|
|
});
|
2020-12-01 18:07:25 -05:00
|
|
|
var context7 = await browser.contextualIdentities.query({
|
|
|
|
name: botepref,
|
|
|
|
});
|
2020-03-02 17:35:49 -05:00
|
|
|
var othercontexts = [];
|
2020-12-03 12:20:43 -05: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-12-03 12:20:43 -05:00
|
|
|
'Context found',
|
2020-03-02 17:35:49 -05:00
|
|
|
contexts[context].cookieStoreId,
|
2020-12-03 12:20:43 -05: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-12-03 12:20:43 -05:00
|
|
|
}
|
2020-03-02 17:34:39 -05:00
|
|
|
|
2020-12-03 12:20:43 -05:00
|
|
|
var contextSetup = function(requestDetails) {
|
2020-01-02 15:43:24 -05:00
|
|
|
function onContextError() {
|
2020-12-03 12:20:43 -05:00
|
|
|
console.log('Context launcher error');
|
2020-01-02 15:43:24 -05:00
|
|
|
}
|
2020-12-05 22:06:15 -05:00
|
|
|
console.log('(scrub) host', requestDetails.url);
|
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 {
|
2020-12-03 12:20:43 -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({
|
2020-11-10 21:48:08 -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-12-03 12:20:43 -05: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-12-03 12:20:43 -05: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,
|
2020-11-10 21:48:08 -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-12-03 12:20:43 -05:00
|
|
|
console.log('(isolate)Context Error', error);
|
2019-10-08 19:10:13 -04:00
|
|
|
}
|
|
|
|
};
|
2020-12-03 12:20:43 -05:00
|
|
|
var routerTabFind = async function(tabId) {
|
2019-10-08 19:10:13 -04:00
|
|
|
try {
|
2019-11-10 20:28:31 -05:00
|
|
|
var context = await browser.contextualIdentities.query({
|
2020-11-10 21:48:08 -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-12-03 12:20:43 -05: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-11-10 21:48:08 -05: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({
|
2020-11-10 21:48:08 -05:00
|
|
|
cookieStoreId: context[0].cookieStoreId,
|
2020-03-17 04:42:24 -04:00
|
|
|
});
|
|
|
|
pins.then(closeOldTab, onError);
|
2019-11-11 16:34:41 -05:00
|
|
|
}
|
2020-12-03 12:20:43 -05:00
|
|
|
if (requestDetails.url.endsWith('xhr1.html')) {
|
|
|
|
hostname = url.split('/')[2];
|
|
|
|
let prefix = url.substr(0, url.indexOf('://') + 3);
|
|
|
|
requestDetails.url = prefix + hostname + '/home';
|
2020-09-21 00:20:44 -04:00
|
|
|
}
|
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,
|
2020-11-10 21:48:08 -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-12-03 12:20:43 -05:00
|
|
|
console.log('(isolate)Context Error', error);
|
2019-11-11 16:34:41 -05:00
|
|
|
}
|
|
|
|
};
|
2020-12-03 12:20:43 -05:00
|
|
|
var i2ptunnelTabFind = async function(tabId) {
|
2019-11-11 16:34:41 -05:00
|
|
|
try {
|
|
|
|
var context = await browser.contextualIdentities.query({
|
2020-11-10 21:48:08 -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-12-03 12:20:43 -05: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-12-05 22:06:15 -05: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({
|
2020-11-10 21:48:08 -05:00
|
|
|
cookieStoreId: context[0].cookieStoreId,
|
2020-03-17 04:42:24 -04:00
|
|
|
});
|
|
|
|
pins.then(closeOldTab, onError);
|
2019-11-11 16:34:41 -05:00
|
|
|
}
|
2020-12-03 12:20:43 -05:00
|
|
|
if (requestDetails.url.endsWith('xhr1.html')) {
|
|
|
|
hostname = url.split('/')[2];
|
|
|
|
let prefix = url.substr(0, url.indexOf('://') + 3);
|
|
|
|
requestDetails.url = prefix + hostname + '/i2ptunnelmgr/';
|
2020-09-21 00:20:44 -04:00
|
|
|
}
|
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,
|
2020-11-10 21:48:08 -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-12-03 12:20:43 -05:00
|
|
|
console.log('(isolate)Context Error', error);
|
2019-11-11 16:34:41 -05:00
|
|
|
}
|
|
|
|
};
|
2020-12-03 12:20:43 -05:00
|
|
|
var snarkTabFind = async function(tabId) {
|
2019-11-11 16:34:41 -05:00
|
|
|
try {
|
|
|
|
var context = await browser.contextualIdentities.query({
|
2020-11-10 21:48:08 -05:00
|
|
|
name: torrentpref,
|
2019-11-11 16:34:41 -05:00
|
|
|
});
|
|
|
|
if (tabId.cookieStoreId != context[0].cookieStoreId) {
|
2020-10-07 16:47:22 -04:00
|
|
|
var exemptContext = await browser.contextualIdentities.query({
|
2020-11-10 21:48:08 -05:00
|
|
|
name: titlepref,
|
2020-10-07 16:47:22 -04:00
|
|
|
});
|
|
|
|
let tmp = new URL(tabId.url);
|
2020-12-03 12:20:43 -05:00
|
|
|
console.log('(isolate)tabid host', tmp.host);
|
|
|
|
if (!requestDetails.url.includes('snark/' + tmp.host)) {
|
2020-11-10 21:48:08 -05:00
|
|
|
// if (tabId.cookieStoreId != exemptContext[0].cookieStoreId){
|
2020-10-07 16:47:22 -04:00
|
|
|
function Create() {
|
|
|
|
function onCreated(tab) {
|
|
|
|
function closeOldTab(tabs) {
|
|
|
|
if (tabId.id != tab.id) {
|
2020-12-03 12:20:43 -05:00
|
|
|
console.log('(isolate) Closing un-isolated tab', tabId.id);
|
|
|
|
console.log('in favor of', tab.id);
|
|
|
|
console.log('with context', tab.cookieStoreId);
|
2020-10-07 16:47:22 -04:00
|
|
|
browser.tabs.remove(tabId.id);
|
2020-12-05 22:06:15 -05:00
|
|
|
browser.tabs.move(tab.id, { index: 0 });
|
2020-10-07 16:47:22 -04:00
|
|
|
}
|
|
|
|
for (index = 0; index < tabs.length; index++) {
|
|
|
|
if (index != tabs.length - 1)
|
|
|
|
browser.tabs.remove(tabs[index].id);
|
|
|
|
}
|
2020-03-17 04:42:24 -04:00
|
|
|
}
|
2020-10-07 16:47:22 -04:00
|
|
|
var pins = browser.tabs.query({
|
2020-11-10 21:48:08 -05:00
|
|
|
cookieStoreId: context[0].cookieStoreId,
|
2020-10-07 16:47:22 -04:00
|
|
|
});
|
|
|
|
pins.then(closeOldTab, onError);
|
2019-11-27 00:58:53 -05:00
|
|
|
}
|
2020-12-03 12:20:43 -05:00
|
|
|
if (requestDetails.url.endsWith('xhr1.html')) {
|
|
|
|
hostname = url.split('/')[2];
|
|
|
|
let prefix = url.substr(0, url.indexOf('://') + 3);
|
|
|
|
requestDetails.url = prefix + hostname + '/i2psnark/';
|
2020-10-07 16:47:22 -04:00
|
|
|
}
|
|
|
|
var created = browser.tabs.create({
|
|
|
|
active: true,
|
|
|
|
pinned: true,
|
|
|
|
cookieStoreId: context[0].cookieStoreId,
|
2020-11-10 21:48:08 -05:00
|
|
|
url: requestDetails.url,
|
2020-03-17 04:42:24 -04:00
|
|
|
});
|
2020-10-07 16:47:22 -04:00
|
|
|
created.then(onCreated, onContextError);
|
2019-11-11 16:34:41 -05:00
|
|
|
}
|
2020-10-07 16:47:22 -04:00
|
|
|
var gettab = browser.tabs.get(tabId.id);
|
|
|
|
gettab.then(Create, onContextError);
|
|
|
|
return tabId;
|
2019-11-11 16:34:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (error) {
|
2020-12-03 12:20:43 -05:00
|
|
|
console.log('(isolate)Context Error', error);
|
2019-11-11 16:34:41 -05:00
|
|
|
}
|
|
|
|
};
|
2020-12-03 12:20:43 -05:00
|
|
|
var muwireTabFind = async function(tabId) {
|
2020-03-23 18:02:23 -04:00
|
|
|
try {
|
|
|
|
var context = await browser.contextualIdentities.query({
|
2020-11-10 21:48:08 -05:00
|
|
|
name: muwirepref,
|
2020-03-23 18:02:23 -04:00
|
|
|
});
|
|
|
|
if (tabId.cookieStoreId != context[0].cookieStoreId) {
|
|
|
|
function Create() {
|
|
|
|
function onCreated(tab) {
|
|
|
|
function closeOldTab(tabs) {
|
|
|
|
if (tabId.id != tab.id) {
|
2020-12-03 12:20:43 -05: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-12-05 22:06:15 -05:00
|
|
|
browser.tabs.move(tab.id, { index: 0 });
|
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({
|
2020-11-10 21:48:08 -05:00
|
|
|
cookieStoreId: context[0].cookieStoreId,
|
2020-03-23 18:02:23 -04:00
|
|
|
});
|
|
|
|
pins.then(closeOldTab, onError);
|
|
|
|
}
|
2020-12-03 12:20:43 -05:00
|
|
|
if (requestDetails.url.endsWith('xhr1.html')) {
|
|
|
|
hostname = url.split('/')[2];
|
|
|
|
let prefix = url.substr(0, url.indexOf('://') + 3);
|
|
|
|
requestDetails.url = prefix + hostname + '/muwire/';
|
2020-12-01 18:07:25 -05:00
|
|
|
}
|
|
|
|
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-12-03 12:20:43 -05:00
|
|
|
console.log('(isolate)Context Error', error);
|
2020-12-01 18:07:25 -05:00
|
|
|
}
|
|
|
|
};
|
2020-12-03 12:20:43 -05:00
|
|
|
var i2pboteTabFind = async function(tabId) {
|
2020-12-01 18:07:25 -05:00
|
|
|
try {
|
|
|
|
var context = await browser.contextualIdentities.query({
|
|
|
|
name: botepref,
|
|
|
|
});
|
|
|
|
if (tabId.cookieStoreId != context[0].cookieStoreId) {
|
|
|
|
function Create() {
|
|
|
|
function onCreated(tab) {
|
|
|
|
function closeOldTab(tabs) {
|
|
|
|
if (tabId.id != tab.id) {
|
2020-12-03 12:20:43 -05:00
|
|
|
console.log('(isolate) Closing un-isolated tab', tabId.id);
|
|
|
|
console.log('in favor of', tab.id);
|
|
|
|
console.log('with context', tab.cookieStoreId);
|
2020-12-01 18:07:25 -05:00
|
|
|
browser.tabs.remove(tabId.id);
|
2020-12-05 22:06:15 -05:00
|
|
|
browser.tabs.move(tab.id, { index: 0 });
|
2020-12-01 18:07:25 -05: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);
|
|
|
|
}
|
2020-12-03 12:20:43 -05:00
|
|
|
if (requestDetails.url.endsWith('xhr1.html')) {
|
|
|
|
hostname = url.split('/')[2];
|
|
|
|
let prefix = url.substr(0, url.indexOf('://') + 3);
|
|
|
|
requestDetails.url = prefix + hostname + '/i2pbote/';
|
2020-09-21 00:20:44 -04:00
|
|
|
}
|
2020-03-23 18:02:23 -04:00
|
|
|
var created = browser.tabs.create({
|
|
|
|
active: true,
|
|
|
|
pinned: true,
|
|
|
|
cookieStoreId: context[0].cookieStoreId,
|
2020-11-10 21:48:08 -05:00
|
|
|
url: requestDetails.url,
|
2020-03-23 18:02:23 -04:00
|
|
|
});
|
|
|
|
created.then(onCreated, onContextError);
|
|
|
|
}
|
|
|
|
var gettab = browser.tabs.get(tabId.id);
|
|
|
|
gettab.then(Create, onContextError);
|
|
|
|
return tabId;
|
|
|
|
}
|
|
|
|
} catch (error) {
|
2020-12-03 12:20:43 -05:00
|
|
|
console.log('(isolate)Context Error', error);
|
2020-03-23 18:02:23 -04:00
|
|
|
}
|
|
|
|
};
|
2020-12-03 12:20:43 -05:00
|
|
|
var mailTabFind = async function(tabId) {
|
2019-11-11 16:34:41 -05:00
|
|
|
try {
|
|
|
|
var context = await browser.contextualIdentities.query({
|
2020-11-10 21:48:08 -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-12-03 12:20:43 -05: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-12-05 22:06:15 -05: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({
|
2020-11-10 21:48:08 -05:00
|
|
|
cookieStoreId: context[0].cookieStoreId,
|
2020-03-17 04:42:24 -04:00
|
|
|
});
|
|
|
|
pins.then(closeOldTab, onError);
|
2019-10-07 21:26:52 -04:00
|
|
|
}
|
2020-12-03 12:20:43 -05:00
|
|
|
if (requestDetails.url.endsWith('xhr1.html')) {
|
|
|
|
hostname = url.split('/')[2];
|
|
|
|
let prefix = url.substr(0, url.indexOf('://') + 3);
|
|
|
|
requestDetails.url = prefix + hostname + '/webmail/';
|
2020-09-21 00:20:44 -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,
|
2020-11-10 21:48:08 -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-12-03 12:20:43 -05:00
|
|
|
console.log('(isolate)Context Error', error);
|
2019-10-07 20:52:03 -04:00
|
|
|
}
|
|
|
|
};
|
2020-12-03 12:20:43 -05:00
|
|
|
var ircTabFind = async function(tabId) {
|
2019-12-24 18:31:44 -05:00
|
|
|
try {
|
|
|
|
var context = await browser.contextualIdentities.query({
|
2020-11-10 21:48:08 -05:00
|
|
|
name: ircpref,
|
2019-12-24 18:31:44 -05:00
|
|
|
});
|
|
|
|
if (tabId.cookieStoreId != context[0].cookieStoreId) {
|
2020-12-03 12:20:43 -05:00
|
|
|
if (requestDetails.url.includes(':7669')) {
|
2020-11-10 20:59:04 -05:00
|
|
|
function Create() {
|
|
|
|
function onCreated(tab) {
|
|
|
|
function closeOldTab(tabs) {
|
|
|
|
if (tabId.id != tab.id) {
|
2020-12-03 12:20:43 -05:00
|
|
|
console.log('(isolate) Closing un-isolated tab', tabId.id);
|
|
|
|
console.log('in favor of', tab.id);
|
|
|
|
console.log('with context', tab.cookieStoreId);
|
2020-11-10 20:59:04 -05:00
|
|
|
browser.tabs.remove(tabId.id);
|
2020-12-05 22:06:15 -05:00
|
|
|
browser.tabs.move(tab.id, { index: 0 });
|
2020-11-10 20:59:04 -05:00
|
|
|
}
|
|
|
|
for (index = 0; index < tabs.length; index++) {
|
|
|
|
if (index != tabs.length - 1)
|
|
|
|
browser.tabs.remove(tabs[index].id);
|
|
|
|
}
|
2019-12-24 22:21:04 -05:00
|
|
|
}
|
2020-11-10 20:59:04 -05:00
|
|
|
var pins = browser.tabs.query({
|
2020-11-10 21:48:08 -05:00
|
|
|
cookieStoreId: context[0].cookieStoreId,
|
2020-11-10 20:59:04 -05:00
|
|
|
});
|
|
|
|
pins.then(closeOldTab, onError);
|
2019-12-24 18:31:44 -05:00
|
|
|
}
|
2020-11-10 20:59:04 -05:00
|
|
|
var created = browser.tabs.create({
|
|
|
|
active: true,
|
|
|
|
pinned: true,
|
|
|
|
cookieStoreId: context[0].cookieStoreId,
|
2020-11-10 21:48:08 -05:00
|
|
|
url: requestDetails.url,
|
2020-11-10 20:59:04 -05:00
|
|
|
});
|
|
|
|
created.then(onCreated, onContextError);
|
2019-12-24 18:31:44 -05:00
|
|
|
}
|
2020-11-10 20:59:04 -05:00
|
|
|
var gettab = browser.tabs.get(tabId.id);
|
|
|
|
gettab.then(Create, onContextError);
|
|
|
|
return tabId;
|
2019-12-24 18:31:44 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (error) {
|
2020-12-03 12:20:43 -05:00
|
|
|
console.log('(isolate)Context Error', error);
|
2019-12-24 18:31:44 -05:00
|
|
|
}
|
2020-11-10 20:59:04 -05:00
|
|
|
};
|
2020-12-03 12:20:43 -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({
|
2020-11-10 21:48:08 -05:00
|
|
|
name: titlepref,
|
2020-02-25 15:19:15 -05:00
|
|
|
});
|
2020-11-10 20:59:04 -05:00
|
|
|
var irccontext = await browser.contextualIdentities.query({
|
2020-11-10 21:48:08 -05:00
|
|
|
name: ircpref,
|
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-12-03 12:20:43 -05: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-12-03 12:20:43 -05:00
|
|
|
tabId.cookieStoreId == 'firefox-default' ||
|
|
|
|
tabId.cookieStoreId == 'firefox-private' ||
|
2020-02-26 01:57:07 -05:00
|
|
|
tabId.cookieStoreId == anoncontext[0].cookieStoreId ||
|
2020-11-10 20:59:04 -05:00
|
|
|
tabId.cookieStoreId == irccontext[0].cookieStoreId ||
|
2020-03-02 17:34:39 -05:00
|
|
|
nmp
|
2020-02-25 16:51:39 -05:00
|
|
|
) {
|
|
|
|
console.log(
|
2020-12-03 12:20:43 -05:00
|
|
|
'(ISOLATE)',
|
2020-02-25 16:51:39 -05:00
|
|
|
tabId.cookieStoreId,
|
2020-12-03 12:20:43 -05:00
|
|
|
'not',
|
2020-02-25 16:51:39 -05:00
|
|
|
anoncontext[0].cookieStoreId,
|
2020-11-10 20:59:04 -05:00
|
|
|
irccontext[0].cookieStoreId
|
2020-02-25 16:51:39 -05:00
|
|
|
);
|
|
|
|
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-12-03 12:20:43 -05:00
|
|
|
'(isolate) Closing isolated tab',
|
2020-02-25 16:51:39 -05:00
|
|
|
tabId.id,
|
2020-12-03 12:20:43 -05:00
|
|
|
'with context',
|
2020-02-25 16:51:39 -05:00
|
|
|
tabId.cookieStoreId
|
|
|
|
);
|
|
|
|
console.log(
|
2020-12-03 12:20:43 -05:00
|
|
|
'(isolate) in favor of',
|
2020-02-25 16:51:39 -05:00
|
|
|
tab.id,
|
2020-12-03 12:20:43 -05: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-12-03 12:20:43 -05:00
|
|
|
cookieStoreId: 'firefox-default',
|
2020-11-10 21:48:08 -05:00
|
|
|
url: requestDetails.url,
|
2020-02-25 15:19:15 -05:00
|
|
|
});
|
|
|
|
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-12-03 12:20:43 -05:00
|
|
|
console.log('(isolate)Context Error', error);
|
2019-11-10 22:24:10 -05:00
|
|
|
}
|
|
|
|
};
|
2020-12-03 12:20:43 -05:00
|
|
|
var tabGet = async function(tabId) {
|
2019-10-07 20:52:03 -04:00
|
|
|
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-12-03 12:20:43 -05: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,
|
2020-11-10 21:48:08 -05:00
|
|
|
secure: true,
|
2020-01-13 17:14:08 -05:00
|
|
|
});
|
|
|
|
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)) {
|
2020-12-05 22:06:15 -05:00
|
|
|
var thn = i2pHostName(requestDetails.url);
|
|
|
|
if (requestDetails.url.includes('=' + thn)) {
|
|
|
|
console.log('(scrub)checking search hostnames =' + thn);
|
|
|
|
var tpt = requestDetails.url.split('=' + thn, 2);
|
2020-12-05 23:53:24 -05:00
|
|
|
requestDetails.url =
|
|
|
|
'http://' + thn + '/' + tpt[1].replace('%2F', '');
|
2020-12-05 22:06:15 -05:00
|
|
|
}
|
2020-12-05 23:53:24 -05:00
|
|
|
console.log('(scrub) new hostname', 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,
|
2020-11-10 21:48:08 -05:00
|
|
|
secure: true,
|
2019-11-22 13:24:19 -05:00
|
|
|
});
|
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-12-03 12:20:43 -05: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-12-03 12:20:43 -05: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-12-03 12:20:43 -05: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-12-03 12:20:43 -05:00
|
|
|
} else if (routerhost === 'muwire') {
|
2020-03-23 18:02:23 -04:00
|
|
|
var routertab = tab.then(muwireTabFind, onContextError);
|
|
|
|
return requestDetails;
|
2020-12-03 12:20:43 -05:00
|
|
|
} else if (routerhost === 'i2pbote') {
|
2020-12-01 18:07:25 -05:00
|
|
|
var routertab = tab.then(i2pboteTabFind, onContextError);
|
|
|
|
return requestDetails;
|
2020-12-03 12:20:43 -05: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-11-10 20:59:04 -05:00
|
|
|
if (localhost) {
|
|
|
|
var irctab = tab.then(ircTabFind, onContextError);
|
2020-02-25 16:51:39 -05:00
|
|
|
return requestDetails;
|
2020-11-10 20:59:04 -05:00
|
|
|
}
|
2020-02-25 16:51:39 -05:00
|
|
|
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-12-03 12:20:43 -05: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
|
|
|
|
2020-12-03 12:20:43 -05:00
|
|
|
var coolheadersSetup = function(e) {
|
2020-09-15 19:01:05 -04:00
|
|
|
var asyncSetPageAction = new Promise((resolve, reject) => {
|
2020-08-23 00:22:31 -04:00
|
|
|
window.setTimeout(() => {
|
2020-09-15 23:31:06 -04:00
|
|
|
for (i = 0; i < e.responseHeaders.length; i++) {
|
|
|
|
let header = e.responseHeaders[i];
|
2020-12-03 12:20:43 -05:00
|
|
|
if (e.url.startsWith('https')) {
|
2020-11-10 21:48:08 -05:00
|
|
|
if (
|
2020-12-03 12:20:43 -05:00
|
|
|
header.name.toUpperCase() === 'I2P-LOCATION' ||
|
|
|
|
header.name.toUpperCase() === 'X-I2P-LOCATION'
|
2020-11-10 21:48:08 -05:00
|
|
|
) {
|
2020-09-25 23:20:30 -04:00
|
|
|
browser.pageAction.setPopup({
|
|
|
|
tabId: e.tabId,
|
2020-12-03 12:20:43 -05:00
|
|
|
popup: 'location.html',
|
2020-11-10 21:48:08 -05:00
|
|
|
});
|
|
|
|
browser.pageAction.setIcon({
|
2020-12-03 12:20:43 -05:00
|
|
|
path: 'icons/i2plogo.png',
|
2020-11-10 21:48:08 -05:00
|
|
|
tabId: e.tabId,
|
2020-09-25 23:20:30 -04:00
|
|
|
});
|
|
|
|
browser.pageAction.setTitle({
|
|
|
|
tabId: e.tabId,
|
2020-11-10 21:48:08 -05:00
|
|
|
title: header.value,
|
2020-09-25 23:20:30 -04:00
|
|
|
});
|
|
|
|
browser.pageAction.show(e.tabId);
|
|
|
|
break;
|
|
|
|
}
|
2020-11-10 21:48:08 -05:00
|
|
|
if (
|
2020-12-03 12:20:43 -05:00
|
|
|
header.name.toUpperCase() === 'I2P-TORRENTLOCATION' ||
|
|
|
|
header.name.toUpperCase() === 'X-I2P-TORRENTLOCATION'
|
2020-11-10 21:48:08 -05:00
|
|
|
) {
|
2020-12-03 12:20:43 -05:00
|
|
|
var imgs = document.getElementsByTagName('img');
|
2020-10-07 16:47:22 -04:00
|
|
|
for (let img of imgs) {
|
|
|
|
if (tmpsrc.host == location.host) {
|
2020-11-10 21:48:08 -05:00
|
|
|
img.src =
|
2020-12-03 12:20:43 -05:00
|
|
|
'http://127.0.0.1:7657/i2psnark/' +
|
2020-11-10 21:48:08 -05:00
|
|
|
tmpsrc.host +
|
|
|
|
tmpsrc.pathname;
|
2020-12-03 12:20:43 -05:00
|
|
|
img.onerror = function() {
|
2020-10-08 00:25:38 -04:00
|
|
|
img.src = tmpsrc;
|
2020-10-07 16:47:22 -04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2020-12-03 12:20:43 -05:00
|
|
|
var videos = document.getElementsByTagName('video');
|
2020-10-08 22:53:18 -04:00
|
|
|
for (let video of videos) {
|
|
|
|
let tmpsrc = new URL(video.currentSrc);
|
|
|
|
if (tmpsrc.host == location.host) {
|
2020-12-03 12:20:43 -05:00
|
|
|
if (!video.innerHTML.includes('127.0.0.1')) {
|
2020-12-06 13:01:02 -05:00
|
|
|
innerHTML = video.innerHTML;
|
|
|
|
topInnerHTML = video.innerHTML.replace(
|
|
|
|
'src="',
|
|
|
|
'src="http://127.0.0.1:7657/i2psnark/' + location.host + '/'
|
|
|
|
);
|
|
|
|
video.innerHTML = topInnerHTML; // + innerHTML;
|
|
|
|
video.onerror = function() {
|
|
|
|
video.innerHTML = topInnerHTML + innerHTML;
|
|
|
|
};
|
2020-10-08 23:14:48 -04:00
|
|
|
}
|
2020-10-08 22:53:18 -04:00
|
|
|
}
|
|
|
|
}
|
2020-12-03 12:20:43 -05:00
|
|
|
var audios = document.getElementsByTagName('audio');
|
2020-10-08 22:53:18 -04:00
|
|
|
for (let audio of audios) {
|
|
|
|
let tmpsrc = new URL(audio.currentSrc);
|
|
|
|
if (tmpsrc.host == location.host) {
|
2020-12-03 12:20:43 -05:00
|
|
|
if (!audio.innerHTML.includes('127.0.0.1')) {
|
2020-10-08 23:14:48 -04:00
|
|
|
innerHTML = audio.innerHTML;
|
2020-11-10 21:48:08 -05:00
|
|
|
topInnerHTML = audio.innerHTML.replace(
|
|
|
|
'src="',
|
2020-12-03 12:20:43 -05:00
|
|
|
'src="http://127.0.0.1:7657/i2psnark/' + location.host + '/'
|
2020-11-10 21:48:08 -05:00
|
|
|
);
|
2020-12-06 13:00:11 -05:00
|
|
|
audio.innerHTML = topInnerHTML; // + innerHTML;
|
|
|
|
audio.onerror = function() {
|
|
|
|
audio.innerHTML = topInnerHTML + innerHTML;
|
|
|
|
};
|
2020-10-08 23:14:48 -04:00
|
|
|
}
|
2020-10-08 22:53:18 -04:00
|
|
|
}
|
|
|
|
}
|
2020-09-25 23:20:30 -04:00
|
|
|
browser.pageAction.setPopup({
|
|
|
|
tabId: tabId.id,
|
2020-12-03 12:20:43 -05:00
|
|
|
popup: 'torrent.html',
|
2020-11-10 21:48:08 -05:00
|
|
|
});
|
|
|
|
browser.pageAction.setIcon({
|
2020-12-03 12:20:43 -05:00
|
|
|
path: 'icons/i2plogo.png',
|
2020-11-10 21:48:08 -05:00
|
|
|
tabId: e.tabId,
|
2020-09-25 23:20:30 -04:00
|
|
|
});
|
|
|
|
browser.pageAction.setTitle({
|
|
|
|
tabId: e.tabId,
|
2020-11-10 21:48:08 -05:00
|
|
|
title: header.value,
|
2020-09-25 23:20:30 -04:00
|
|
|
});
|
2020-10-07 16:47:22 -04:00
|
|
|
browser.pageAction.show(e.tabId);
|
2020-09-25 23:20:30 -04:00
|
|
|
break;
|
|
|
|
}
|
2020-11-10 21:48:08 -05:00
|
|
|
} else {
|
|
|
|
if (
|
2020-12-03 12:20:43 -05:00
|
|
|
header.name.toUpperCase() === 'I2P-TORRENTLOCATION' ||
|
|
|
|
header.name.toUpperCase() === 'X-I2P-TORRENTLOCATION'
|
2020-11-10 21:48:08 -05:00
|
|
|
) {
|
2020-12-03 12:20:43 -05:00
|
|
|
var imgs = document.getElementsByTagName('img');
|
2020-10-07 16:47:22 -04:00
|
|
|
for (let img of imgs) {
|
|
|
|
if (tmpsrc.host == location.host) {
|
2020-11-10 21:48:08 -05:00
|
|
|
img.src =
|
2020-12-03 12:20:43 -05:00
|
|
|
'http://127.0.0.1:7657/i2psnark/' +
|
2020-11-10 21:48:08 -05:00
|
|
|
tmpsrc.host +
|
|
|
|
tmpsrc.pathname;
|
2020-12-03 12:20:43 -05:00
|
|
|
img.onerror = function() {
|
2020-10-08 00:25:38 -04:00
|
|
|
img.src = tmpsrc;
|
2020-10-07 16:47:22 -04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2020-12-03 12:20:43 -05:00
|
|
|
var videos = document.getElementsByTagName('video');
|
2020-10-08 22:53:18 -04:00
|
|
|
for (let video of videos) {
|
|
|
|
let tmpsrc = new URL(video.currentSrc);
|
|
|
|
if (tmpsrc.host == location.host) {
|
2020-12-03 12:20:43 -05:00
|
|
|
if (!video.innerHTML.includes('127.0.0.1')) {
|
2020-12-06 13:01:02 -05:00
|
|
|
innerHTML = video.innerHTML;
|
|
|
|
topInnerHTML = video.innerHTML.replace(
|
|
|
|
'src="',
|
|
|
|
'src="http://127.0.0.1:7657/i2psnark/' + location.host + '/'
|
|
|
|
);
|
|
|
|
video.innerHTML = topInnerHTML; // + innerHTML;
|
|
|
|
video.onerror = function() {
|
|
|
|
video.innerHTML = topInnerHTML + innerHTML;
|
|
|
|
};
|
2020-10-08 23:14:48 -04:00
|
|
|
}
|
2020-10-08 22:53:18 -04:00
|
|
|
}
|
|
|
|
}
|
2020-12-03 12:20:43 -05:00
|
|
|
var audios = document.getElementsByTagName('audio');
|
2020-10-08 22:53:18 -04:00
|
|
|
for (let audio of audios) {
|
|
|
|
let tmpsrc = new URL(audio.currentSrc);
|
|
|
|
if (tmpsrc.host == location.host) {
|
2020-12-03 12:20:43 -05:00
|
|
|
if (!audio.innerHTML.includes('127.0.0.1')) {
|
2020-12-06 13:01:02 -05:00
|
|
|
innerHTML = audio.innerHTML;
|
|
|
|
topInnerHTML = audio.innerHTML.replace(
|
|
|
|
'src="',
|
|
|
|
'src="http://127.0.0.1:7657/i2psnark/' + location.host + '/'
|
|
|
|
);
|
|
|
|
audio.innerHTML = topInnerHTML; // + innerHTML;
|
|
|
|
audio.onerror = function() {
|
|
|
|
audio.innerHTML = topInnerHTML + innerHTML;
|
|
|
|
};
|
2020-10-08 23:14:48 -04:00
|
|
|
}
|
2020-10-08 22:53:18 -04:00
|
|
|
}
|
|
|
|
}
|
2020-10-07 12:55:26 -04:00
|
|
|
browser.pageAction.setPopup({
|
|
|
|
tabId: tabId.id,
|
2020-12-03 12:20:43 -05:00
|
|
|
popup: 'torrent.html',
|
2020-11-10 21:48:08 -05:00
|
|
|
});
|
|
|
|
browser.pageAction.setIcon({
|
2020-12-03 12:20:43 -05:00
|
|
|
path: 'icons/i2plogo.png',
|
2020-11-10 21:48:08 -05:00
|
|
|
tabId: e.tabId,
|
2020-10-07 12:55:26 -04:00
|
|
|
});
|
|
|
|
browser.pageAction.setTitle({
|
|
|
|
tabId: e.tabId,
|
2020-11-10 21:48:08 -05:00
|
|
|
title: header.value,
|
2020-10-07 12:55:26 -04:00
|
|
|
});
|
2020-10-07 16:47:22 -04:00
|
|
|
browser.pageAction.show(e.tabId);
|
2020-10-07 12:55:26 -04:00
|
|
|
break;
|
|
|
|
}
|
2020-08-23 00:22:31 -04:00
|
|
|
}
|
|
|
|
}
|
2020-11-10 21:48:08 -05:00
|
|
|
resolve({ responseHeaders: e.responseHeaders });
|
2020-08-23 00:22:31 -04:00
|
|
|
}, 2000);
|
|
|
|
});
|
2020-09-15 19:01:05 -04:00
|
|
|
return asyncSetPageAction;
|
2020-11-10 21:48:08 -05:00
|
|
|
};
|
2020-08-23 00:22:31 -04:00
|
|
|
|
2020-12-06 02:12:01 -05:00
|
|
|
function getTabURL(tab) {
|
|
|
|
console.log("(scrub)", tab);
|
|
|
|
if (tab.url.startsWith("https")) {
|
|
|
|
browser.tabs
|
|
|
|
.sendMessage(tab.id, { req: "i2p-location" })
|
|
|
|
.then((response) => {
|
|
|
|
if (response.content.toUpperCase() != "NO-ALT-LOCATION") {
|
|
|
|
browser.pageAction.setPopup({
|
|
|
|
tabId: tab.id,
|
|
|
|
popup: "location.html",
|
|
|
|
});
|
|
|
|
browser.pageAction.setIcon({
|
|
|
|
path: "icons/i2plogo.png",
|
|
|
|
tabId: tab.id,
|
|
|
|
});
|
|
|
|
browser.pageAction.setTitle({
|
|
|
|
tabId: tab.id,
|
|
|
|
title: response.content,
|
|
|
|
});
|
|
|
|
browser.pageAction.show(tab.id);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
console.log("(pageaction)", tab.id, tab.url);
|
|
|
|
} else {
|
|
|
|
browser.tabs
|
|
|
|
.sendMessage(tab.id, { req: "i2p-torrentlocation" })
|
|
|
|
.then((response) => {
|
|
|
|
if (response.content.toUpperCase() != "NO-ALT-LOCATION") {
|
|
|
|
browser.pageAction.setPopup({
|
|
|
|
tabId: tab.id,
|
|
|
|
popup: "torrent.html",
|
|
|
|
});
|
|
|
|
browser.pageAction.setIcon({
|
|
|
|
path: "icons/i2plogo.png",
|
|
|
|
tabId: tab.id,
|
|
|
|
});
|
|
|
|
browser.pageAction.setTitle({
|
|
|
|
tabId: tab.id,
|
|
|
|
title: response.content,
|
|
|
|
});
|
|
|
|
browser.pageAction.show(tab.id);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
console.log("(pageaction)", tab.id, tab.url);
|
2020-09-24 20:06:24 -04:00
|
|
|
}
|
2020-12-06 02:12:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function getClearTab(tobj) {
|
2020-11-10 21:48:08 -05:00
|
|
|
if (typeof tobj == "number") {
|
|
|
|
browser.tabs.get(tobj).then(getTabURL, onError);
|
2020-12-06 02:12:01 -05:00
|
|
|
}
|
|
|
|
if (typeof tobj.tabId == "number") {
|
|
|
|
console.log("(scrub) tobj", tobj);
|
2020-11-10 21:48:08 -05:00
|
|
|
browser.tabs.get(tobj.tabId).then(getTabURL, onError);
|
2020-12-06 02:12:01 -05:00
|
|
|
} else {
|
|
|
|
for (let tab in tobj.tabIds) {
|
|
|
|
console.log("(scrub) tab", tobj, tab, tobj.tabIds[tab]);
|
|
|
|
browser.tabs.get(tobj.tabIds[tab]).then(getTabURL, onError);
|
|
|
|
}
|
2020-10-11 23:43:14 -04:00
|
|
|
}
|
2020-09-24 20:06:24 -04:00
|
|
|
}
|
|
|
|
|
2020-12-06 02:12:01 -05:00
|
|
|
const filter = {
|
|
|
|
url: [{ hostContains: ".i2p" }],
|
|
|
|
};
|
|
|
|
|
|
|
|
function logOnDOMContentLoaded(details) {
|
|
|
|
console.log(`onDOMContentLoaded: ${details.url}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
browser.webNavigation.onDOMContentLoaded.addListener(getClearTab, filter);
|
|
|
|
|
2020-09-24 20:06:24 -04:00
|
|
|
browser.tabs.onActivated.addListener(getClearTab);
|
2020-10-09 01:03:27 -04:00
|
|
|
browser.tabs.onUpdated.addListener(getClearTab);
|
2020-12-06 02:12:01 -05:00
|
|
|
browser.tabs.onAttached.addListener(getClearTab);
|
|
|
|
browser.tabs.onCreated.addListener(getClearTab);
|
|
|
|
browser.tabs.onDetached.addListener(getClearTab);
|
|
|
|
browser.tabs.onHighlighted.addListener(getClearTab);
|
|
|
|
browser.tabs.onMoved.addListener(getClearTab);
|
|
|
|
browser.tabs.onRemoved.addListener(getClearTab);
|
|
|
|
browser.tabs.onReplaced.addListener(getClearTab);
|
|
|
|
browser.tabs.onZoomChange.addListener(getClearTab);
|
2020-08-23 00:22:31 -04:00
|
|
|
|
2020-09-21 13:44:26 -04:00
|
|
|
function reloadTabs(tabs) {
|
|
|
|
for (let tab of tabs) {
|
2020-11-10 21:48:08 -05:00
|
|
|
browser.tabs.reload(tab.id);
|
2020-09-21 13:44:26 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function reloadError(error) {
|
|
|
|
console.log(`Error: ${error}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
let querying = browser.tabs.query({});
|
|
|
|
querying.then(reloadTabs, onError);
|
|
|
|
|
2020-08-23 00:22:31 -04:00
|
|
|
// Listen for onHeaderReceived for the target page.
|
|
|
|
// Set "blocking" and "responseHeaders".
|
|
|
|
browser.webRequest.onHeadersReceived.addListener(
|
|
|
|
coolheadersSetup,
|
2020-11-10 21:48:08 -05:00
|
|
|
{ urls: ["<all_urls>"] },
|
2020-12-06 02:12:01 -05:00
|
|
|
["responseHeaders"]
|
2020-08-23 00:22:31 -04:00
|
|
|
);
|
|
|
|
|
2020-12-06 13:00:11 -05:00
|
|
|
browser.webNavigation.onDOMContentLoaded.addListener(getClearTab, filter);
|
|
|
|
browser.webNavigation.onBeforeNavigate.addListener(getClearTab, filter);
|
|
|
|
browser.webNavigation.onCommitted.addListener(getClearTab, filter);
|
|
|
|
browser.webNavigation.onCompleted.addListener(getClearTab, filter);
|
2020-12-06 02:12:01 -05:00
|
|
|
|
2019-10-07 20:52:03 -04:00
|
|
|
browser.webRequest.onBeforeRequest.addListener(
|
|
|
|
contextSetup,
|
2020-11-10 21:48:08 -05: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-11-10 21:48:08 -05:00
|
|
|
{ urls: ["<all_urls>"] },
|
|
|
|
["blocking", "requestHeaders"]
|
2019-10-06 13:58:26 -04:00
|
|
|
);
|