From 1d282b52a29b3cc8cf54a5d4959c4412efe295f1 Mon Sep 17 00:00:00 2001 From: stoically Date: Tue, 8 May 2018 15:16:48 +0200 Subject: [PATCH] Implement Per Domain Navigation Target Exclusion Part of #104 --- package.json | 2 +- src/background/log.js | 2 +- src/background/request.js | 24 +++++++++++++++++----- src/background/storage.js | 5 +++-- src/ui/options.html | 2 +- src/ui/shared.js | 15 +++++++------- test/background.isolation.test.js | 34 +++++++++++++++++++++++++++++++ 7 files changed, 67 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 9d50eb2c..1923d515 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "build-sign": "rm -rf web-ext-artifacts && cp README.md LICENSE src && node build-sign.js && npm run lint && npm test && web-ext sign --channel unlisted -s src && git checkout -- src/manifest.json && ncu", "lint": "eslint src", "test": "nyc --reporter=html --reporter=text mocha --reporter=dot ./test/setup.js test/*.test.js --timeout 60000", - "test-watch": "mocha ./test/setup.js test/*.test.js --watch --tmp-debug", + "test-watch": "mocha ./test/setup.js test/*.test.js --watch --inspect --tmp-debug", "test-functional": "mocha ./test/functional/*.test.js --timeout 10000", "check-dependencies": "ncu" }, diff --git a/src/background/log.js b/src/background/log.js index 40abda5d..0c3e4960 100644 --- a/src/background/log.js +++ b/src/background/log.js @@ -24,4 +24,4 @@ class Log { window.log = new Log; // eslint-disable-next-line -window.debug = log.debug; \ No newline at end of file +window.debug = log.debug; diff --git a/src/background/request.js b/src/background/request.js index cd37b5b0..8db660c6 100644 --- a/src/background/request.js +++ b/src/background/request.js @@ -440,21 +440,35 @@ class Request { for (let domainPattern in this.storage.local.preferences.isolation.domain) { if (!this.isolation.matchDomainPattern(tab.url, domainPattern)) { + debug('[shouldIsolate] pattern not matching', tab.url, domainPattern); continue; } - const preferences = this.storage.local.preferences.isolation.domain[domainPattern].navigation; - if (!preferences) { + + const patternPreferences = this.storage.local.preferences.isolation.domain[domainPattern]; + if (patternPreferences.excluded) { + for (const excludedDomainPattern of Object.keys(patternPreferences.excluded)) { + if (!this.isolation.matchDomainPattern(request.url, excludedDomainPattern)) { + debug('[shouldIsolate] excluded domain pattern not matching', request.url, excludedDomainPattern); + continue; + } + debug('[shouldIsolate] not isolating because excluded domain pattern matches', request.url, excludedDomainPattern); + return false; + } + } + + const navigationPreferences = patternPreferences.navigation; + if (!navigationPreferences) { continue; } - debug('[shouldIsolate] found pattern', domainPattern, preferences); + debug('[shouldIsolate] found pattern', domainPattern, navigationPreferences); - if (preferences.action === 'global') { + if (navigationPreferences.action === 'global') { debug('[shouldIsolate] breaking because "global"'); break; } return await this.checkIsolationPreferenceAgainstUrl( - preferences.action, parsedTabURL.hostname, parsedRequestURL.hostname, tab + navigationPreferences.action, parsedTabURL.hostname, parsedRequestURL.hostname, tab ); } diff --git a/src/background/storage.js b/src/background/storage.js index 89b17426..4dca7bec 100644 --- a/src/background/storage.js +++ b/src/background/storage.js @@ -37,7 +37,8 @@ class Storage { action: 'never', container: 'default' } - } + }, + excluded: {} }, domain: {}, mac: { @@ -211,4 +212,4 @@ class Storage { } } -window.Storage = Storage; \ No newline at end of file +window.Storage = Storage; diff --git a/src/ui/options.html b/src/ui/options.html index 99dbc33e..49910a6e 100644 --- a/src/ui/options.html +++ b/src/ui/options.html @@ -212,7 +212,7 @@

- Exclude Target Domains + Exclude Target/Link Domains

diff --git a/src/ui/shared.js b/src/ui/shared.js index 7227f3d2..0d318304 100644 --- a/src/ui/shared.js +++ b/src/ui/shared.js @@ -116,7 +116,8 @@ const isolationDomainAddRule = async () => { left: { action: document.querySelector('#isolationDomainMouseClickLeft').value } - } + }, + excluded: isolationDomainExcludeDomains }; await savePreferences(); @@ -165,12 +166,12 @@ window.updateIsolationDomains = () => { 'Mouse Clicks
' + `Middle: ${preferences.isolation.domain[domainPattern].mouseClick.middle.action}
` + `Ctrl+Left: ${preferences.isolation.domain[domainPattern].mouseClick.ctrlleft.action}
` + - `Left: ${preferences.isolation.domain[domainPattern].mouseClick.left.action}


`; - // 'Excluded Target Domains:
' + - // (preferences.isolation.domain[domainPattern].excluded && - // preferences.isolation.domain[domainPattern].excluded.length) ? - // `${preferences.isolation.domain[domainPattern].excluded.join('
')}` : - // 'No Target Domains excluded'; + `Left: ${preferences.isolation.domain[domainPattern].mouseClick.left.action}
` + + 'Excluded Target/Link Domains:
' + + (preferences.isolation.domain[domainPattern].excluded && + Object.keys(preferences.isolation.domain[domainPattern].excluded).length > 0 ? + `${Object.keys(preferences.isolation.domain[domainPattern].excluded).join('
')}` : + 'No Target/Link Domains excluded'); el.find('#infoDomainRule').popup({ html: domainRuleTooltip, inline: true diff --git a/test/background.isolation.test.js b/test/background.isolation.test.js index ea0d3044..187b2339 100644 --- a/test/background.isolation.test.js +++ b/test/background.isolation.test.js @@ -151,6 +151,40 @@ preferencesTestSet.map(preferences => { describe(`preferences: ${JSON.stringify( browser.tabs.create.should.have.been.calledOnce; }); }); + + describe('if the target domain is excluded', () => { + beforeEach(async () => { + switch (navigatingIn) { + case 'sametab.global': + case 'newtab.global': + background.storage.local.preferences.isolation.global.excluded['excluded.com'] = {}; + break; + + case 'sametab.perdomain': + case 'newtab.perdomain': + background.storage.local.preferences.isolation.domain['example.com'] = defaultIsolationDomainPreferences; + background.storage.local.preferences.isolation.domain['example.com'].excluded['excluded.com'] = {}; + break; + } + + await navigateTo('https://excluded.com'); + }); + + it('should not open a new Temporary Container', async () => { + switch (navigatingIn) { + case 'sametab.global': + case 'newtab.global': + // TODO: implement me + expect(true).to.be.true; + break; + + case 'sametab.perdomain': + case 'newtab.perdomain': + browser.tabs.create.should.not.have.been.called; + break; + } + }); + }); }); describe('navigating with preference "notsamedomain"', () => {