Skip to content

Commit

Permalink
Add management permission and containerise compatibility
Browse files Browse the repository at this point in the history
Part of #15
  • Loading branch information
stoically committed May 9, 2018
1 parent 91c7d48 commit bcd53f1
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/background.js
Expand Up @@ -5,6 +5,7 @@ class TemporaryContainers {
this.storage = new window.Storage;
this.utils = new window.Utils(this);
this.runtime = new window.Runtime(this);
this.management = new window.Management(this);
this.request = new window.Request(this);
this.container = new window.Container(this);
this.mouseclick = new window.MouseClick(this);
Expand Down Expand Up @@ -46,6 +47,8 @@ class TemporaryContainers {
this.cookies.initialize();
this.statistics.initialize();
this.mac.initialize();

await this.management.initialize();
await this.tabs.initialize();

this.initialized = true;
Expand Down
72 changes: 72 additions & 0 deletions src/background/management.js
@@ -0,0 +1,72 @@
class Management {

constructor() {
this.addons = {
'@testpilot-containers': {
name: 'Firefox Multi-Account Containers',
enabled: false,
version: false
},
'@contain-facebook': {
name: 'Facebook Container',
enabled: false,
version: false
},
'@contain-google': {
name: 'Google Container',
enabled: false,
version: false
},
'@contain-twitter': {
name: 'Twitter Container',
enabled: false,
version: false
},
'@contain-youtube': {
name: 'YouTube Container',
enabled: false,
version: false
},
'containerise@kinte.sh': {
name: 'Containerise',
enabled: false,
version: false
},
};
}


async initialize() {
try {
const extensions = await browser.management.getAll();
extensions.map(extension => {
if (!this.addons[extension.id]) {
return;
}
this.addons[extension.id].enabled = extension.enabled;
this.addons[extension.id].version = extension.version;
});
} catch (error) {
debug('[management:initialize] couldnt getAll extensions', error);
}

browser.management.onDisabled.addListener(this.disable.bind(this));
browser.management.onUninstalled.addListener(this.disable.bind(this));
browser.management.onEnabled.addListener(this.enable.bind(this));
browser.management.onInstalled.addListener(this.enable.bind(this));
}


disable(extension) {
this.addons[extension.id].enabled = false;
this.addons[extension.id].version = extension.version;
}


enable(extension) {
this.addons[extension.id].enabled = true;
this.addons[extension.id].version = extension.version;
}
}

window.Management = Management;
34 changes: 27 additions & 7 deletions src/background/request.js
Expand Up @@ -16,6 +16,7 @@ class Request {
this.utils = this.background.utils;
this.tabs = this.background.tabs;
this.isolation = this.background.isolation;
this.management = this.background.management;

// Clean up canceled requests
browser.webRequest.onCompleted.addListener((request) => {
Expand Down Expand Up @@ -89,13 +90,13 @@ class Request {
}

let macAssignment;
try {
macAssignment = await this.mac.getAssignment(request.url);
} catch (error) {
debug('[webRequestOnBeforeRequest] contacting mac failed, either not installed or old version', error);
if (this.management.addons['@testpilot-containers'].enabled) {
try {
macAssignment = await this.mac.getAssignment(request.url);
} catch (error) {
debug('[webRequestOnBeforeRequest] contacting mac failed, probably old version', error);
}
}

let tab;
if (macAssignment) {
if (macAssignment.neverAsk) {
debug('[webRequestOnBeforeRequest] mac neverask assigned, we do nothing', macAssignment);
Expand All @@ -104,6 +105,25 @@ class Request {
debug('[webRequestOnBeforeRequest] mac assigned', macAssignment);
}
}

if (this.management.addons['containerise@kinte.sh'].enabled) {
try {
const hostmap = await browser.runtime.sendMessage('containerise@kinte.sh', {
method: 'getHostMap',
url: request.url
});
if (typeof hostmap === 'object' && hostmap.cookieStoreId && hostmap.enabled) {
debug('[webRequestOnBeforeRequest] assigned with containerise we do nothing', hostmap);
return;
} else {
debug('[webRequestOnBeforeRequest] not assigned with containerise', hostmap);
}
} catch (error) {
debug('[webRequestOnBeforeRequest] contacting containerise failed, probably old version', error);
}
}

let tab;
try {
tab = await browser.tabs.get(request.tabId);
debug('[webRequestOnBeforeRequest] onbeforeRequest requested tab information', tab);
Expand Down Expand Up @@ -443,7 +463,7 @@ class Request {
debug('[shouldIsolate] pattern not matching', tab.url, domainPattern);
continue;
}

const patternPreferences = this.storage.local.preferences.isolation.domain[domainPattern];
if (patternPreferences.excluded) {
for (const excludedDomainPattern of Object.keys(patternPreferences.excluded)) {
Expand Down
2 changes: 2 additions & 0 deletions src/manifest.json
Expand Up @@ -77,6 +77,7 @@
"contextMenus",
"contextualIdentities",
"cookies",
"management",
"storage",
"tabs",
"webRequest",
Expand Down Expand Up @@ -110,6 +111,7 @@
"background/cookies.js",
"background/isolation.js",
"background/mac.js",
"background/management.js",
"background/migration.js",
"background/mouseclick.js",
"background/pageaction.js",
Expand Down
7 changes: 6 additions & 1 deletion test/setup.js
Expand Up @@ -63,8 +63,13 @@ const buildWebExtension = async (build = {}) => {
webExtension.background.browser.tabs.query.resolves([{},{}]);
webExtension.background.browser.storage.local.get.resolves({});
webExtension.background.browser.contextualIdentities.get.resolves({});
webExtension.background.browser.cookies.getAll.resolves([]);
}
webExtension.background.browser.cookies.getAll.resolves([]);
webExtension.background.browser.management.getAll.resolves([{
id: '@testpilot-containers',
enabled: true,
version: '6.0.0'
}]);

if (process.argv[process.argv.length-1] === '--tmp-debug') {
webExtension.background.window.log.DEBUG = true;
Expand Down

0 comments on commit bcd53f1

Please sign in to comment.