Add auconenable config check.

Ignores all autocontain directives unless config variable is set to
"true".
This commit is contained in:
Anton Vilhelm Ásgeirsson 2018-07-31 21:56:18 +00:00
parent 876050d410
commit e7524f191c
2 changed files with 15 additions and 10 deletions

View file

@ -179,7 +179,6 @@ const DEFAULTS = o({
DocLoad: o({}),
DocStart: o({
// "addons.mozilla.org": "mode ignore",
// "github.com": "reopenincontainer Work",
}),
DocEnd: o({
// "emacs.org": "sanitise history",
@ -356,7 +355,10 @@ const DEFAULTS = o({
// If moodeindicator is enabled, containerindicator will color the border of the mode indicator with the container color.
containerindicator: "true",
// AutoContain directives create a container if it doesn't exist already.
// Enable Autocontainers
auconenable: "false",
// Autocontain directives create a container if it doesn't exist already.
auconcreatecontainer: "true",
// Performance related settings

View file

@ -71,18 +71,22 @@ export class AutoContain implements IAutoContain {
autoContain = async (
details: IDetails,
): Promise<browser.webRequest.BlockingResponse> => {
// Lets not break everyone's user experience ok?
let enabled = Config.get("auconenable")
if (enabled === "false") return { cancel: false }
// Do not handle private tabs or invalid tabIds.
if (details.tabId === -1) return
if (details.tabId === -1) return { cancel: false}
let tab = await browser.tabs.get(details.tabId)
if (tab.incognito) return
if (tab.incognito) return { cancel: false }
// Only handle http requests.
if (details.url.search("^https?://") < 0) return
if (details.url.search("^https?://") < 0) return { cancel: false }
let cookieStoreId = await this.parseAucons(details)
// Silently return if we're already in the correct container.
if (tab.cookieStoreId === cookieStoreId) return
if (tab.cookieStoreId === cookieStoreId) return { cancel: false }
if (this.cancelEarly(tab, details)) return { cancel: true }
@ -110,14 +114,13 @@ export class AutoContain implements IAutoContain {
this.cancelRequest(tab, details)
} else {
let cancel = false
let cr = this.getCancelledRequest(tab.id)
if (cr.requestIds[details.requestId] || cr.urls[details.url]) {
if (this.cancelledRequests[tab.id].requestIds[details.requestId] || this.cancelledRequests[tab.id].urls[details.url]) {
cancel = true
}
cr.requestIds[details.requestId] = true
cr.urls[details.url] = true
this.cancelledRequests[tab.id].requestIds[details.requestId] = true
this.cancelledRequests[tab.id].urls[details.url] = true
return cancel
}