Skip to content

Commit

Permalink
Cover isolation feature with tests and deactivate when navigation tar…
Browse files Browse the repository at this point in the history
…get is MAC assigned

Part of #56
  • Loading branch information
stoically committed Mar 7, 2018
1 parent 2cd16ca commit a25c559
Show file tree
Hide file tree
Showing 6 changed files with 389 additions and 37 deletions.
1 change: 0 additions & 1 deletion src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ class TemporaryContainers {
const splittedTarget = target.split('.');
const checkHostname = '.' + (splittedTarget.splice(-2).join('.'));
const dottedOrigin = '.' + origin;

if (target.length > 1 &&
(dottedOrigin.endsWith(checkHostname) ||
checkHostname.endsWith(dottedOrigin))) {
Expand Down
80 changes: 53 additions & 27 deletions src/background/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,9 @@ class Request {

this.container.removeBrowserActionBadge(request.tabId);


if (request.url.startsWith('http://addons.mozilla.org') || request.url.startsWith('https://addons.mozilla.org')) {
debug('[webRequestOnBeforeRequest] we are ignoring requests to addons.mozilla.org because we arent allowed to cancel requests anyway', request);
return;
if (this.shouldCancelRequest(request)) {
debug('[webRequestOnBeforeRequest] canceling', request);
return { cancel: true };
}

let macAssignment;
Expand All @@ -96,18 +95,6 @@ class Request {
debug('[webRequestOnBeforeRequest] contacting mac failed, either not installed or old version', error);
}

if (this.shouldCancelRequest(request)) {
debug('[webRequestOnBeforeRequest] canceling', request);
return { cancel: true };
}

if (request.url.startsWith('https://getpocket.com')) {
// TODO consider "Decontain Websites" in the preferences
// getpocket.com is ignored because of #52
debug('[webRequestOnBeforeRequest] we are ignoring requests to getpocket.com because of #52', request);
return;
}

let tab;
if (macAssignment) {
if (macAssignment.neverAsk) {
Expand All @@ -131,13 +118,22 @@ class Request {

this.container.maybeAddHistory(tab, request.url);

/*
if (request.url.startsWith('http://addons.mozilla.org') || request.url.startsWith('https://addons.mozilla.org')) {
debug('[webRequestOnBeforeRequest] we are ignoring requests to addons.mozilla.org because we arent allowed to cancel requests anyway', request);
return;
}

if (request.url.startsWith('https://getpocket.com')) {
// TODO consider "Exclude Websites" in the preferences
debug('[webRequestOnBeforeRequest] we are ignoring requests to getpocket.com because of #52', request);
return;
}

const isolated = await this.maybeIsolate(tab, request, macAssignment);
if (isolated) {
debug('[webRequestOnBeforeRequest] we decided to isolate and open new tmpcontainer', request);
return isolated;
}
*/

const alwaysOpenIn = !macAssignment && await this.maybeAlwaysOpenInTemporaryContainer(tab, request);
if (alwaysOpenIn) {
Expand Down Expand Up @@ -362,9 +358,23 @@ class Request {
debug('[maybeIsolate] isolating', tab, request);
this.cancelRequest(request);

let deletesHistoryContainer = false;
if (this.storage.local.preferences.deletesHistoryContainer === 'automatic') {
deletesHistoryContainer = true;
}

if (requestMacAssignment && tab.cookieStoreId !== requestMacAssignment.cookieStoreId) {
if (tab && tab.cookieStoreId && this.storage.local.tempContainers[tab.cookieStoreId]) {
debug('[maybeIsolate] mac assigned but we are already in a tmp container, we do nothing', request, tab, requestMacAssignment);
return;
}
debug('[maybeIsolate] decided to isolate but mac assigned and not loading in the target container, maybe reopen confirmpage', request, tab, requestMacAssignment);
return this.mac.maybeReopenConfirmPage(requestMacAssignment, request, tab, deletesHistoryContainer);
}

const params = {
tab,
active: true,
active: tab.active,
url: request.url,
request
};
Expand All @@ -390,18 +400,33 @@ class Request {
return true;
}

if (tab.url === 'about:blank' && !tab.openerTabId) {
debug('[shouldIsolate] not isolating because the tab url is blank and no openerTabId');
if (requestMacAssignment) {
debug('[shouldIsolate] requested url is mac assigned, we do nothing (yet)');
return false;
}

if (!openerCheck && tab.url === 'about:blank' && tab.openerTabId) {
if (!openerCheck && tab.openerTabId) {
const openerTab = await browser.tabs.get(tab.openerTabId);
debug('[shouldIsolate] we have to check the opener against the request', openerTab);
if (this.shouldIsolate(openerTab, request, requestMacAssignment, true)) {

if (this.container.isPermanentContainer(tab.cookieStoreId) &&
openerTab.cookieStoreId !== tab.cookieStoreId) {
debug('[shouldIsolate] the tab loads a permanent container that is different from the openerTab, probaby explicitly selected in the context menu');
return false;
}

if (await this.shouldIsolate(openerTab, request, requestMacAssignment, true)) {
debug('[shouldIsolate] decided to isolate because of opener', openerTab);
return true;
}

debug('[shouldIsolate] decided to not isolate because of opener', openerTab);
return false;
}

if (tab.url === 'about:blank' && !tab.openerTabId) {
debug('[shouldIsolate] not isolating because the tab url is blank and no openerTabId');
return false;
}

if (tab.url === 'about:blank' && this.requestsSeen[request.requestId]) {
Expand Down Expand Up @@ -451,30 +476,31 @@ class Request {
return true;
}
if (this.container.isPermanentContainer(tab.cookieStoreId) && requestMacAssignment &&
tab.cookieStoreId !== `firefox-container-${requestMacAssignment.userContextId}`) {
tab.cookieStoreId !== requestMacAssignment.cookieStoreId) {
debug('[shouldIsolateMac] mac isolating because request url is assigned to a different container then the tabs permanent container');
return true;
}
return false;
}

async checkIsolationPreferenceAgainstUrl(preference, origin, target, tab) {
debug('[checkIsolationPreferenceAgainstUrl]', preference, origin, target, tab);
switch (preference) {
case 'always':
debug('[shouldIsolate] isolating based on global "always"');
debug('[checkIsolationPreferenceAgainstUrl] isolating based on global "always"');
return true;

case 'notsamedomainexact':
if (target !== origin) {
debug('[shouldIsolate] isolating based on global "notsamedomainexact"');
debug('[checkIsolationPreferenceAgainstUrl] isolating based on global "notsamedomainexact"');
return true;
}
break;

case 'notsamedomain':
if (!this.background.sameDomain(origin, target) &&
(!tab.openerTabId || !await this.background.sameDomainTabUrl(tab.openerTabId, target))) {
debug('[shouldIsolate] isolating based on global "notsamedomain"');
debug('[checkIsolationPreferenceAgainstUrl] isolating based on global "notsamedomain"');
return true;
}
break;
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"description": "Open tabs, websites, and links in automatically managed disposable containers. Containers isolate the data websites store (cookies, cache, and more) from each other, further enhancing your privacy while you browse.",
"manifest_version": 2,
"name": "Temporary Containers",
"version": "0.68",
"version": "0.69beta1",
"homepage_url": "https://github.com/stoically/firefox-add-on-temporary-containers",
"icons": {
"48": "icons/tmpcontainer-48.png"
Expand Down
16 changes: 9 additions & 7 deletions src/ui/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<div class="ui menu">
<a class="item active" data-tab="general">General</a>
<a class="item" data-tab="alwaysopenin">Always per Website</a>
<!--<a class="item" data-tab="isolation">Isolation</a>-->
<a class="item" data-tab="isolation">Isolation</a>
<a class="item" data-tab="mouseclicks">Mouse Clicks</a>
<a class="item" data-tab="advanced">Advanced</a>
<a class="item" data-tab="statistics">Statistics</a>
Expand Down Expand Up @@ -118,12 +118,14 @@
</div>
<div class="ui bottom attached active tab segment" data-tab="isolation/global">
<form class="ui form">
<h4>When navigating should open new Temporary Containers</h4>
<h4 data-tooltip="Will not work if the navigation target is assigned with Multi-Account Containers">
When navigating on Websites should open new Temporary Containers [?]
</h4>
<div class="field">
<select id="isolationGlobal" class="ui fluid dropdown">
<option value="always">Always</option>
<option value="notsamedomainexact">If the navigation target doesn't exactly match the Tabs Website Domain</option>
<option value="notsamedomain">If the navigation target doesn't match the Tabs Website Domain (includes Subdomains)</option>
<option value="notsamedomainexact">If the navigation target doesn't exactly match the current Tabs Website Domain</option>
<option value="notsamedomain">If the navigation target doesn't match the current Tabs Website Domain (includes Subdomains)</option>
<option value="never">Never</option>
</select>
</div>
Expand All @@ -144,8 +146,8 @@ <h4 data-tooltip="Website Rules overwrite Global Preferences">
<div class="field">
<select id="isolationDomainAction" class="ui fluid dropdown">
<option value="always">Always</option>
<option value="notsamedomainexact" selected="selected">If the navigation target doesn't exactly match the Tabs Website Domain</option>
<option value="notsamedomain">If the navigation target doesn't match the Tabs Website Domain (includes Subdomains)</option>
<option value="notsamedomainexact" selected="selected">If the navigation target doesn't exactly match the current Tabs Website Domain</option>
<option value="notsamedomain">If the navigation target doesn't match the current Tabs Website Domain (includes Subdomains)</option>
<option value="never">Never</option>
</select>
</div>
Expand Down Expand Up @@ -197,7 +199,7 @@ <h4>When Mouse Clicks on Links should open new Temporary Containers</h4>
which might open another website or a new tab without opening it in a new Temporary Container.<br>
<br>
If you want to make 100% sure that all tabs or websites are opened in a new Temporary
Container you should use the Isolation feature instead.
Container you should additionally configure the Isolation feature.
</div>
<div class="field">
<label>Middle Mouse</label>
Expand Down
Loading

0 comments on commit a25c559

Please sign in to comment.