Compare commits

...

320 Commits

Author SHA1 Message Date
luke crouch ae1f80b8b5 Merge pull request #1667 from mozilla/more-bugfixes
Made selector for keyboard shortcuts more specific to fix #1666
2020-02-28 10:39:28 -06:00
Kendall Werts 358551feda Made selector for keyboard shortcuts more specific to fix #1666
Bumped version for release
2020-02-28 10:19:42 -06:00
luke crouch ca98b56ad7 Merge pull request #1663 from mozilla/bugfixes
Removed Enter Key Handler (fix for #1656, #1643, and #1637)
2020-02-27 14:44:34 -06:00
Kendall Werts 5bbf902b47 fix for #1656, #1643, and #1637
removes enter key listener in favor of focus highlighting to notify user that there
is keyboard navigation available for the onboarding panels. (enter key listener was added
 as keyboard navication for onboarding panels).

bumped version
2020-02-26 17:16:45 -06:00
luke crouch d654810d41 Merge pull request #1635 from mozilla/pinned-tabs
Fix for #1632: Pinned tabs cannot be loaded as 'discarded'
2020-02-14 09:05:15 -06:00
Kendall Werts 8172f291dd bumped version 2020-02-13 17:26:31 -06:00
Kendall Werts 9e12014c07 Fix for #1632: Pinned tabs cannot be loaded as 'discarded' 2020-02-13 16:54:18 -06:00
luke crouch da79841201 Merge pull request #1611 from kendallcorner/new-sync-file
Sync Feature
2020-02-11 08:36:02 -06:00
Kendall Werts 00ace352e8 upped version and added action badge 2020-02-10 17:09:20 -06:00
Kendall Werts 8cdfe0191f fixed url for syn setup 2020-02-10 16:55:48 -06:00
Kendall Werts f56f9b0ea8 fixed tests 2020-02-10 16:00:47 -06:00
Kendall Werts 4bc6fad83a added second onboarding panel 2020-02-10 15:19:41 -06:00
Kendall Werts beb027f1a1 updated readme 2020-02-10 12:38:57 -06:00
Kendall Werts 06b43c47c0 added new oboarding panel 2020-02-10 12:38:45 -06:00
Kendall Werts 7ed5085f10 changed window attachment of sync to be more clear 2020-02-10 12:38:17 -06:00
Kendall Werts c300751958 moved test to mocha tests 2020-02-06 11:58:53 -06:00
Kendall Werts e6f5bf76c2 Merge pull request #1 from stoically/sync-tests
Add sync tests to mocha suite
2020-02-03 11:25:31 -06:00
Kendall Werts 88d8edce7e fixed initial container sync entry dupe 2020-01-29 21:54:04 -06:00
stoically 419be23c9c Add sync tests to mocha suite 2020-01-28 11:33:20 +01:00
stoically 405e605ba3 Refactor tests to not rely on globals 2020-01-28 11:33:17 +01:00
Kendall Werts d7b1e7274f verison bump for beta 2020-01-24 17:18:31 -06:00
Kendall Werts 53baee1d5c swapped cookieStoreId and storekey 2020-01-24 17:02:29 -06:00
Kendall Werts 0447e54b1c review fedback 2020-01-23 13:47:56 -06:00
Kendall Werts 5b8cfa14ae Update src/js/background/sync.js
Co-Authored-By: Jonathan Kingston <jonathan@jooped.co.uk>
2020-01-23 13:47:56 -06:00
Kendall Werts d35712e9f9 Update src/js/background/sync.js
Co-Authored-By: Jonathan Kingston <jonathan@jooped.co.uk>
2020-01-23 13:47:56 -06:00
Kendall Werts f981200921 Update src/js/background/identityState.js
Co-Authored-By: Jonathan Kingston <jonathan@jooped.co.uk>
2020-01-23 13:47:56 -06:00
Kendall Werts 85c403bef5 made some suggested changes 2020-01-23 13:47:45 -06:00
Kendall Werts 268c638508 added onboarding panel 2020-01-23 00:27:05 -06:00
Kendall Werts 61b5c2e4b2 updated tests to match new formatting" 2020-01-22 23:50:19 -06:00
Kendall Werts 3aa2902cde added on/off switch and expiration date on instanceKeys in sync
on/off is in settings.
when instanceKey date is 30 days old, it is deleted

fixed bug
2020-01-22 22:46:36 -06:00
Kendall Werts d7b66eca52 added key to sync for each install of MAC.
Keeps a list of installed identities and site assignments of reach MAC install
2020-01-22 10:57:27 -06:00
Kendall Werts 361e49d553 bumped version for beta 2020-01-16 10:04:38 -06:00
Kendall Werts 60bfdffdd6 fixed race condition while upgrading containers and site assignments. 2020-01-15 16:54:24 -06:00
Kendall Werts d7c0a3d9e1 Fixed infinite loop in updating uuid for identities. 2020-01-15 10:03:40 -06:00
Kendall Werts a7d3d6d848 fixed linting 2020-01-14 11:21:19 -06:00
Kendall Werts 26028cac20 added UUIDs of containers to site assignments 2020-01-14 11:21:09 -06:00
Kendall Werts 33909d147a fixed cookiestoreIDmap 2020-01-14 11:21:09 -06:00
Kendall Werts 10d08f2ac9 changed confusing language on sync data check 2020-01-14 11:21:09 -06:00
Kendall Werts 5ae7a395a1 added some checks on sync and some error handling for bad site assignment info 2020-01-14 11:21:00 -06:00
Kendall Werts 9de6df6157 fixed bug that was showing all assigned site in the create new container panel 2020-01-14 11:20:51 -06:00
Kendall Werts 6184dbb656 fixed bug that was showing all assigned site in the create new container panel 2020-01-09 13:52:40 -06:00
Kendall Werts 34180aa2d5 worked on the duplicate bug 2020-01-08 23:38:01 -06:00
Kendall Werts 3a7744b41b wrote tests tests for browser use 2020-01-08 18:33:02 -06:00
Kendall Werts 53f7dc4915 added some tests in the browser html 2020-01-08 15:37:08 -06:00
Kendall Werts 53a901d023 saving to do some work 2020-01-08 13:32:02 -06:00
Kendall Werts c522d36a66 error handling 2020-01-08 13:23:35 -06:00
Kendall Werts f7b20f97b8 working with tests 2020-01-07 14:14:19 -06:00
Kendall Werts d033292784 pulled in sync tests 2020-01-06 13:27:57 -06:00
stoically 26cd3c3cc8 Feature test container sync initialization 2020-01-06 10:58:27 -06:00
Kendall Werts be3904cee8 package.json testing scripts 2020-01-06 10:50:00 -06:00
Kendall Werts 0252f9d1c3 refactored runSync and following functions 2020-01-05 14:32:11 -06:00
Kendall Werts 19dce3ba45 refactor and fixed site assignment reconcilding 2020-01-05 14:32:11 -06:00
Kendall Werts 0bdf8558f6 Syncs deletion of site assignments and reassignments 2020-01-05 14:32:11 -06:00
Kendall Werts 0e45f06338 deletes containers, and adds and deletes site assignments. 2020-01-05 14:32:11 -06:00
Kendall Werts 063b7509bd removed awaits that were causing issues with error handling 2020-01-05 14:32:11 -06:00
Kendall Werts 136aa3ce0e wip: cleaning up storage before sync 2020-01-05 14:32:11 -06:00
Kendall Werts a7f6659204 added check for uuid in updateUUID 2020-01-05 14:32:11 -06:00
Kendall Werts f4024bba66 re-enabled listeners 2020-01-05 14:32:11 -06:00
Kendall Werts e65c88cde2 updated with comments fixes from review 2020-01-05 14:32:11 -06:00
Kendall Werts 27225df281 added restore on previously synced browser 2020-01-05 14:32:11 -06:00
Kendall Werts 88e32fc72f added second run restore 2020-01-05 14:32:11 -06:00
Kendall Werts d61ea16db1 broke up restoreFristRun 2020-01-05 14:32:11 -06:00
Kendall Werts adc1f5ffe6 made some requested changes 2020-01-05 14:32:11 -06:00
Kendall Werts e8f8123c4c combined getByContainer and getAllAssignedSites 2020-01-05 14:29:53 -06:00
Kendall Werts 9788e159ae cleanup of old code 2020-01-05 14:29:53 -06:00
Kendall Werts d98d0f1697 a little linting, but not all the linting 2020-01-05 14:29:53 -06:00
Kendall Werts efb83255fd syncs on first run 2020-01-05 14:29:53 -06:00
Kendall Werts f5993add6f added uuids to contextualIdentities within MAC for comparison with other browsers 2020-01-05 14:29:53 -06:00
Kendall Werts 24c960bed0 first pass at container sync 2020-01-05 14:29:53 -06:00
stoically dc9e8f6399 Add test for unresolved issue
See: https://github.com/mozilla/multi-account-containers/issues/1168#issuecomment-378394091
2020-01-02 23:25:07 +00:00
stoically e37440720f Add container feature test 2020-01-02 23:25:07 +00:00
stoically 703a7cd3c2 Add test coverage with nyc 2020-01-02 23:25:07 +00:00
stoically 5eb79949e9 Adapt existing tests to use webextensions-jsdom 2020-01-02 23:25:07 +00:00
stoically 77fd843b3d Replace manual mock/jsdom with webextensions-jsdom 2020-01-02 23:25:07 +00:00
stoically 96ab4685e9 Bump test dependencies 2020-01-02 23:25:07 +00:00
stoically 426e81b88b Fix eslint errors after bump to 6.6.0 (#1595)
* Bump eslint from 3.19.0 to 6.6.0

Bumps [eslint](https://github.com/eslint/eslint) from 3.19.0 to 6.6.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/master/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v3.19.0...v6.6.0)

Signed-off-by: dependabot[bot] <support@github.com>

* Fix (and suppress) eslint errors
2019-12-18 09:02:02 +01:00
Kendall Werts 3c2dda5100 Merge pull request #1565 from kendallcorner/bookmark-menu-updates
fixed #1564: cleanup updates requested for bookmark context menu
2019-12-17 15:44:58 -06:00
luke crouch fca5caaa00 Merge pull request #1601 from mozilla/fix-odd-edit-arrow-alignment
fix odd edit arrow alignment
2019-12-09 15:59:15 -06:00
revealtheweb b0661f79aa fix odd edit arrow alignment 2019-12-09 15:55:57 -06:00
stoically e44fcdf606 Merge pull request #1574 from dnahol/readme-typo-fix
Fix README typo
2019-12-06 06:29:30 +01:00
dnahol 645fb6832c fix 'License' typo 2019-11-02 22:49:31 -07:00
Kendall Werts f653b5420f fixed #1564: cleanup updates requested for bookmark context menu 2019-10-31 14:16:23 -05:00
luke crouch f159e42029 Merge pull request #1539 from dnahol/1538-onboarding
added keyboard nav to onboarding popups
2019-10-25 13:34:56 -05:00
luke crouch a8aafc7064 Merge pull request #1540 from oksmelnik/duplicated-tabs
#950: don't unhide duplicates of already opened tab
2019-10-25 13:30:24 -05:00
Dalia Nahol 3284bfd7f3 Merge branch 'master' into 1538-onboarding 2019-10-25 10:56:06 -07:00
luke crouch da24febe6e Merge branch 'master' into duplicated-tabs 2019-10-25 10:49:11 -05:00
luke crouch 3e5334e9b0 Merge pull request #1524 from dnahol/1009-arrows
added right and left arrow shortcuts for container submenu tabs
2019-10-25 10:42:57 -05:00
luke crouch 8dd9927539 Merge pull request #1537 from kendallcorner/bookmark-context
Adds a bookmark context menu for opening bookmarks in container tabs #323
2019-10-25 10:14:01 -05:00
Oksana Melnik c3da573722 cleanup 2019-10-25 08:08:04 +02:00
Dalia Nahol f40fd82518 Merge branch 'master' into 1009-arrows 2019-10-24 20:32:09 -07:00
dnahol ef894d847e merge upstream commit 'remove HTML entities from tooltip' 2019-10-24 20:25:47 -07:00
Kendall Werts 7c08cf3190 Merge branch 'bookmark-context' of github.com:kendallcorner/multi-account-containers into bookmark-context 2019-10-24 16:46:54 -05:00
Kendall Werts 6f94ae1500 updated testing setup to understand my api calls 2019-10-24 16:42:19 -05:00
Kendall Werts bd579fe907 added changes requested 2019-10-24 16:32:49 -05:00
Kendall Werts 87a2aa5f1e added url checks for edge case urls 2019-10-24 16:16:02 -05:00
dnahol 1133d48103 left arrow now works without changing focus in right arrow case 2019-10-24 14:02:28 -07:00
Maxx Crawford dda5c9eeff Merge branch 'master' into bookmark-context 2019-10-24 14:33:15 -05:00
Kendall Werts e7824f367b added bookmarks as optional_permission and added checkbox in preferences menu. 2019-10-24 14:14:30 -05:00
dnahol 29a0277398 change getCurrentPanel to getCurrentPanelElement 2019-10-24 10:17:32 -07:00
luke crouch 510a188dee Merge pull request #1541 from Karskaya/iss1041
Fix #1041- [Feature request] Open previously hidden tabs in the background
2019-10-24 08:17:33 -05:00
luke crouch 7fa2d494c4 Merge pull request #1512 from romanrodriguez/patch-1
Fix #930 - Disable extension in incognito mode
2019-10-24 06:39:11 -05:00
Kendall Werts 7e4950b184 menu updates when containers are changed, added, or deleted. Tests need to be updated 2019-10-23 15:48:43 -05:00
Kendall Werts c832cf73aa edits from input 2019-10-19 22:31:12 -05:00
Karskaja 9ff1a14e0e Fix issue #1041- [Feature request] Open previously hidden tabs in the background
Add 'noload' property to openNewTab options, add 'discarded' parameter to browser.tabs.create. New tabs opened from showTabs will be discarded.
2019-10-19 10:04:48 -04:00
Oksana Melnik 384ac486d9 duplitated-tabs: don't unhide duplicates of already opened tab 2019-10-19 14:43:03 +02:00
dnahol 2cddbefb63 added keyboard nav to onboarding popups 2019-10-18 13:47:54 -07:00
dnahol dae376500b added right and left arrow shortcuts for container submenu tabs
change focus to whole panel element after right arrow press, allows navigation without pressing tab
2019-10-18 00:08:51 -07:00
Kendall Werts c4650d12bd added ability to open folders as well. issue #323 2019-10-17 15:25:58 -05:00
Kendall Werts 18bc8eb5aa added bookmark context menu ref: issue #323 2019-10-17 14:15:45 -05:00
Roman Rodriguez 8eceb0d298 Fix #930 - Disable extension in incognito mode 2019-10-16 13:07:59 -05:00
luke crouch 27d51f89c7 Merge pull request #1532 from scar45/fix/dark-mode-redirect-url-color
Explicitly set foreground color of #redirect-url in dark mode
2019-10-16 11:25:43 -05:00
luke crouch d04252a5ad Merge pull request #1517 from Jo-IE/edit-tooltip-html
remove HTML entities from tooltip
2019-10-16 10:42:38 -05:00
luke crouch 6b02258295 Merge pull request #1530 from kendallcorner/patch-1
Updated test instructions
2019-10-16 10:28:15 -05:00
luke crouch 97169d6f17 Merge pull request #1535 from kendallcorner/urldecode
Fix for double decoding on confirm page issue #1361
2019-10-16 07:13:24 -05:00
Kendall Werts a874c9c628 fix for double decoding on confirm page issue #1361 2019-10-15 14:19:18 -05:00
George Merlocco c28d77e7cd Explicitly set foreground color of #redirect-url in dark mode 2019-10-12 18:54:54 -04:00
Kendall Werts 397a3e4970 updated test info 2019-10-11 10:38:33 -05:00
luke crouch a4c578adde Merge pull request #1519 from jonathanKingston/updated-icons
Updating to sharper icon. Fixes #1518
2019-10-08 14:34:10 -05:00
Jonathan Kingston db8b7ea05f Updating to sharper icon. Fixes #1518 2019-10-08 17:06:05 +01:00
Jo IE f33b3b39c0 remove HTML entities from tooltip 2019-10-07 18:02:40 +01:00
luke crouch a328e5bf91 Merge pull request #1509 from mozilla/october-2019-dot-release
Updated add-on to version 6.1.1
2019-10-02 16:35:19 -05:00
Maxx Crawford 46a55da277 Updated to version 6.1.1 2019-10-02 16:22:54 -05:00
Francis McKenzie 1746d8379b Improved comments in CSS 2019-09-23 23:09:05 +01:00
Francis McKenzie f57cf92f41 Bugfix: incorrect scrollbars/spacing when editing container with many assignments 2019-09-23 23:09:05 +01:00
Harry Twyford 54659f5c77 #1375 - Correct colors on confirmation page 2019-09-23 17:34:46 +01:00
Maxx Crawford 2badd22f41 Merge pull request #1485 from kendallcorner/master
Fixed #766 — Popup display expands to fit overflow menu
2019-09-20 16:54:47 -05:00
Kendall Werts 21b7386a94 probably a better solution than using a timeout 2019-08-28 08:39:53 -05:00
Kendall Werts 529b9bb482 forgot a semicolon 2019-08-27 12:22:25 -05:00
Kendall Werts 3adb333022 solving linter issue without breaking the fix. 2019-08-27 11:54:16 -05:00
Kendall Werts cc988a303e lack of px on the zero appears to break it. 2019-08-27 11:06:40 -05:00
Kendall Werts 46349e1a70 linted 2019-08-27 10:42:58 -05:00
Kendall Werts acff80a234 Merge branch 'master' of github.com:mozilla/multi-account-containers 2019-08-26 17:12:22 -05:00
Kendall Werts bbe655d879 fixed first panel issue 2019-08-26 17:06:48 -05:00
Kendall Werts 7cbace9cc9 fix for #766 issues with display in overflow menu 2019-08-26 14:47:02 -05:00
luke crouch 9372899bfa Merge pull request #1470 from kendallcorner/master
Default favicon now displays for Edit Containers panel (issue #1314)
2019-08-07 10:41:30 -05:00
Kendall Werts 4d42a74e66 Added class to empty div as requested 2019-08-06 20:39:46 -05:00
Kendall Werts 76f7a64cb8 fixed favicon url 2019-07-26 08:50:22 -05:00
Kendall Werts 1af8cf8222 fix for issue #1314 2019-07-25 13:38:17 -05:00
stoically 11a3b2facd Merge pull request #1435 from silverwind/dark-mode-icon
Support dark themes on icon - Fixes #1424
2019-07-17 16:47:41 +02:00
stoically bd993d2f84 Merge pull request #1451 from Arthaey/patch-1
Fix typo in a comment.
2019-07-17 16:42:28 +02:00
Arthaey Angosii cf9683174d Fix typo in a comment. 2019-07-07 18:01:33 -07:00
silverwind f617ca26bb Support dark themes on icon - Fixes #1424 2019-06-09 18:45:41 +02:00
ctgardner 41686fdf6c Revert "Increase timeout on flakey async test"
This reverts commit 154df62687.
2019-05-07 02:23:00 +01:00
ctgardner c67a985847 Increase timeout on flakey async test 2019-05-07 02:23:00 +01:00
ctgardner 639399925c Refactor async anonymous functions into arrow functions
- fixes #972
2019-05-07 02:23:00 +01:00
stoically 2ded900188 Reduce noise in issue template 2019-05-07 01:36:02 +01:00
Jonathan Kingston 3ae1803420 Bug 1539507 - Fix targeting of button click when button element isn't clicked. 2019-05-07 01:32:28 +01:00
luke crouch 17b2d8c773 Merge pull request #1371 from gliptak/patch-1
Bring CODE_OF_CONDUCT.md current
2019-04-23 12:14:45 -05:00
Gábor Lipták 7025c98e7b Bring CODE_OF_CONDUCT.md current 2019-04-15 14:24:16 -04:00
luke crouch 6f4d3c4327 Merge pull request #1329 from ShivangiKakkar/new-release
Fixes #1328: Adding new version
2019-01-23 13:59:19 -06:00
shivangikakkar 7833a6a79f adding new version 2019-01-23 23:30:04 +05:30
luke crouch c2f2d69ba1 Merge pull request #1327 from ShivangiKakkar/fixes-985
exempting `always open in` functionality for non-standard ports
2019-01-22 20:21:57 -06:00
shivangikakkar 42b0312790 exempting always open in functionality for non-standard ports 2019-01-19 02:02:27 +09:00
Jonathan Kingston cc42beeb5a Merge branch 'ShivangiKakkar-fixes-168' 2019-01-12 23:30:02 +00:00
Jonathan Kingston ea5669911b Merge branch 'fixes-168' of https://github.com/ShivangiKakkar/multi-account-containers into ShivangiKakkar-fixes-168 2019-01-12 23:28:49 +00:00
Shivangi Kakkar b4c2da5474 Merge branch 'master' into fixes-168 2019-01-11 10:33:54 +09:00
shivangikakkar 6d7086d541 added functions and cosmetic changes 2019-01-11 09:25:00 +09:00
shivangikakkar db0dba66b2 dynamically added close image icon in the title column 2019-01-11 04:06:08 +09:00
shivangikakkar 5b58168999 Refactored the logic to form warning message 2019-01-07 23:08:59 +00:00
groovecoder 4ed453d58e save ajv at 6.6.2 2019-01-07 23:08:59 +00:00
mingchia-andy-liu 66a9116524 Fix delete warning message #1051
- Include the number of tabs that will be closed when container is deleted
- Insert the warning message to the `span` tag that was originally there
2019-01-07 23:08:59 +00:00
Jonathan Kingston cb7ac6ca5e Merge pull request #1298 from aabbi/duplicate-tabs-791
Fixes #1109 , rest of #791
2019-01-04 14:40:46 +00:00
luke crouch a2995b6c66 Merge pull request #1292 from jonathanKingston/fix-missing-favicon
Add in missing favicon. Fixes #1285
2018-12-05 12:41:43 -06:00
luke crouch ed383c8dfc Merge pull request #1294 from jonathanKingston/badge-background-error
Remove badge background error. Fixes #1293
2018-12-05 09:09:34 -06:00
luke crouch df9b900db6 Merge pull request #1297 from jonathanKingston/6.0.1
Bump release to 6.0.1
2018-12-05 08:48:50 -06:00
luke crouch 8e611de605 Merge pull request #1295 from jonathanKingston/fix-missing-check-image
Fix missing assignment check mark. Fixes #1271
2018-12-05 08:47:02 -06:00
shivangikakkar 8af4c36fd0 removing inline css 2018-10-29 16:32:10 +05:30
shivangikakkar abc4e0cdcf review changes 2018-10-23 15:13:41 +05:30
aabbi b6dd32f683 moved unhiding container to background logic 2018-10-22 20:05:03 -04:00
Jonathan Kingston 0a437ff303 Bump release to 6.0.1. Fixes #1296 2018-10-21 22:33:08 +01:00
Jonathan Kingston f7f4c320a6 Fix missing assignment check mark. Fixes #1271 2018-10-21 22:22:48 +01:00
Jonathan Kingston 5813621fb9 Remove badge background error. Fixes #1293 2018-10-21 21:25:55 +01:00
Jonathan Kingston 56fc7407da Add in missing favicon. Fixes #1285 2018-10-21 21:13:57 +01:00
Jonathan Kingston 220b902144 Merge pull request #1275 from ShivangiKakkar/fixes-256
#256 disables edit-container button when no container is present
2018-10-21 19:45:44 +01:00
shivangikakkar c15eee22c6 implemented remove individual tabs just for visible state 2018-10-21 23:24:18 +05:30
shivangikakkar dcc3b76cda simplifying the solution 2018-10-21 17:12:56 +05:30
shivangikakkar 752d18ffca prevent event handler when edit containers disabled 2018-10-18 21:33:48 +05:30
luke crouch 97559dd08a Merge pull request #1281 from hritvi/npm_fixes
Fixes vulnerabilities in npm
2018-10-03 07:00:14 -05:00
hritvi 0e7363a87f npm fixes 2018-10-03 16:16:44 +05:30
hritvi 6c62c2f599 fixes vulnerabilities in npm 2018-10-03 16:14:36 +05:30
Jonathan Kingston 884e419a7c Merge pull request #1265 from ShivangiKakkar/fixes-1028
#1028 resolves focus name field on opening new container sub-panel
2018-10-02 18:18:05 +01:00
shivangikakkar d7586dd4c2 resolves #256 disables edit-container button when no container is present
resolve lint errors

review changes
2018-10-01 00:01:50 +05:30
shivangikakkar aada0419eb removing event loop and using requestAnimationFrame 2018-09-30 18:17:01 +05:30
shivangikakkar 1ea04587d9 resolves lint errors 2018-09-25 17:47:17 +05:30
luke crouch 3d1dcd33d1 Merge pull request #1262 from ShivangiKakkar/fixes-885
#885 disables move tab to a new window when only one tab is opened
2018-09-24 14:05:27 -05:00
shivangikakkar bfdbd8199f fixes-168, added ability to close a tab individually 2018-09-25 00:21:46 +05:30
shivangikakkar fe0810b048 restructuring the code acc to the review 2018-09-23 00:42:43 +05:30
shivangikakkar e1c1ac4bd9 adds back the unnecessarily removed new line 2018-09-21 14:31:54 +05:30
shivangikakkar 7f7f221a79 fix-#1028 resolves focus name field on opening new container sub-panel 2018-09-21 14:04:43 +05:30
shivangikakkar e57c556427 review changes 2018-09-20 23:40:22 +05:30
shivangikakkar dd57158ab5 #885 disables move tab to a new window when only one tab is opened 2018-09-20 21:34:19 +05:30
stoically 99db192792 Merge pull request #1170 from real-or-random/master
Update GitHub URLs
2018-03-31 00:04:37 +02:00
stoically fcbee854d0 Merge pull request #1172 from stoically/add-issue-template
Add ISSUE_TEMPLATE
2018-03-30 16:46:22 +02:00
stoically fae1336467 Add ISSUE_TEMPLATE 2018-03-30 16:43:24 +02:00
Tim Ruffing 655d8f3791 Update GitHub URLs 2018-03-29 13:45:05 +02:00
luke crouch dcc852bf17 Merge pull request #1120 from stoically/cancel-redirects-tabid-url
Cancel redirects for the same requestIds and urls if originating from the same tabId
2018-03-01 14:23:29 -06:00
stoically dab3005c6f Cancel redirects for the same requestIds and urls if originating from the same tabId
Fixes #940
2018-02-23 15:33:32 +01:00
luke crouch ee6a54ffa2 Merge pull request #1116 from mozilla/testing-6.0.0
Version 6.0.0
2018-02-22 14:44:12 -06:00
Jonathan Kingston 601056406a Merge pull request #1118 from stoically/tests-6.0.0
Add and fix tests for 6.0.0
2018-02-22 16:57:08 +00:00
stoically fd72ce12b4 Fix assignment test to check for the new openerTabId property 2018-02-10 00:51:13 +01:00
stoically 6e45532f58 Add tests for external webextensions feature 2018-02-10 00:50:29 +01:00
Jonathan Kingston 61da6b5e99 Merge pull request #1117 from mozilla/jonathanKingston-patch-1
Adding an s://
2018-02-09 18:37:45 +00:00
Jonathan Kingston e0156388e8 Adding an s:// 2018-02-09 18:37:29 +00:00
Jonathan Kingston 16f1d47bf2 Merge pull request #1115 from jonathanKingston/6.0.0
Bumping version to 6.0.0 to account for latest fixes
2018-02-09 18:34:54 +00:00
Jonathan Kingston ee647344a1 Bumping version to 6.0.0 to account for latest fixes 2018-02-09 18:33:54 +00:00
Jonathan Kingston 40426ca936 Merge pull request #1107 from stoically/tests
Adding assignment feature tests
2018-02-09 18:07:20 +00:00
Jonathan Kingston d1e9c2d1e3 Merge pull request #1066 from LoveIsGrief/1065_-_Feature_Request]_Pass_openerTabId_when_creating_tabs_in_order_to_know_the_parent
Pass opener tab id when creating tabs in order to know the parent
2018-02-09 18:06:56 +00:00
Jonathan Kingston 3bd33cda99 Merge branch 'testing-6.0.0' into 1065_-_Feature_Request]_Pass_openerTabId_when_creating_tabs_in_order_to_know_the_parent 2018-02-09 18:04:58 +00:00
stoically 609f62ac7a Allow webextensions with contextualIdentities permission to get assignment
Closes #1095
2018-02-09 18:00:26 +00:00
stoically ce84665e3a Add management permission to manifest.json
Part of #1095
2018-02-09 18:00:26 +00:00
stoically 7dceaf6679 Cancel requests with the same requestId
Prevents potential redirects from opening two tabs
Closes #1114
2018-02-09 17:59:23 +00:00
stoically b6bcd99dc8 Add test for issue #940 2018-02-09 12:02:41 +01:00
stoically 9bc9509316 Added assignment feature test
Part of #1107
2018-02-02 19:05:40 +01:00
luke crouch 22ec01d565 Merge pull request #1106 from timendum/master
Fix for siteSettings is null
2018-01-30 14:03:06 -06:00
Timendum a16cae0342 Fix for siteSettings is null
siteSettings can be null, with this change we can avoid an exception.
2018-01-30 10:51:38 +01:00
luke crouch f17ff7168f Merge pull request #1055 from ericlathrop/fix-moving-pinned-tabs-to-new-window
Fix #1053.
2018-01-29 11:02:14 -06:00
luke crouch d3b22faf65 Merge pull request #1097 from crenwick/fix-unwanted-shortcut-bug
Fixes #1084.
2018-01-29 10:27:16 -06:00
Charles Renwick 30e5a27eb4 Fixes #1084.
Before opening a container with the `1-9` shortcut, it ensures that the current pannel is the "containersList"
2018-01-26 13:44:46 -05:00
luke crouch 0f720ec11d Merge pull request #1073 from tiagonbotelho/tb-fix-readme-code-wrapping
Fixes code markdown wrapping under Development in the README section
2018-01-18 14:19:57 -06:00
groovecoder 0ddee7f9d0 id:@testpilot-containers to manifest.json; 5.0.1 2018-01-08 22:59:52 +00:00
Tiago Botelho 1e16e203dc Fixes code markdown wrapping under Development in the README section 2018-01-08 20:37:35 +00:00
LoveIsGrief af986e8880 Set the openerTabId to a tab that won't be removed/closed
The tab might be removed before we can create the tab making the parent
 invalid.

#1065 - [Feature Request] Pass openerTabId when creating tabs in order to know the parent
2018-01-05 13:51:47 +01:00
LoveIsGrief 7e04c46070 Pass the openerTabId when automatically opening tabs in containers
the `openerTabId` can also be seen as the tab's parent.
This is useful for extensions like https://github.com/piroor/treestyletab

#1065 - [Feature Request] Pass openerTabId when creating tabs in order to know the parent
2018-01-05 13:05:32 +01:00
LoveIsGrief 166420dd86 Ignore JetBrains IDE files
#1065 - [Feature Request] Pass openerTabId when creating tabs in order to know the parent
2018-01-05 13:01:43 +01:00
Eric Lathrop d7a2b43b07 Fix #1053.
Create the new window with the default tab rather than an existing tab,
then pin the default tab. This allows any pinned tabs to be moved to the
new window because they're not allowed to be moved after a un-pinned
tab. The default tab is automatically closed later in `moveTabsToWindow`
because it's not a part of the container.
2017-12-22 11:51:11 -05:00
groovecoder bea201a389 update README & package.json to match web-ext flow 2017-12-05 19:06:13 +00:00
Jonathan Kingston d944116e3e Move to a Web Extension only. Fixes #1005 2017-12-05 19:06:13 +00:00
luke crouch 4a1597c87f Merge pull request #1021 from gaborluk/maintain-tab-active-state
Maintain the active state of the redirected tab
2017-12-04 09:20:02 -06:00
Gabor Luk f87bf2a861 Maintain the active state of the redirected tab 2017-12-02 15:25:32 +01:00
luke crouch ef45cde290 Merge pull request #992 from crenwick/open-containers-shortcut
Adds shortcut to open containers.
2017-11-28 15:59:19 -06:00
Charles Renwick 752b1c3b27 Removes shortcut for the tenth container. 2017-11-28 16:17:48 -05:00
Charles Renwick cf26d8547a Consolidates switch pattern for shortcut keys.
Applies @groovecoder suggestions to consolidate a long switch statement.
2017-11-28 11:40:10 -05:00
Charles Renwick 1d78febafc fixes keyCodes 2017-11-21 10:51:29 -05:00
Charles Renwick f483119a40 Adds shortcut to open containers.
Makes it more effective to open the first ten containers in the
containers list. Keys 1-0 will open containers 1-10, if that container
exists.

Note: the plugin's popup panel does not autofocus when opened. This
requires the user to focus on the panel by either clicking or pressing
TAB before using shortcut keys. This behavior is consistent with the previous shortcuts for
this addon.
2017-11-21 10:26:30 -05:00
groovecoder abd2b73fca ignore all *.sw* files for jpm and git 2017-11-17 09:59:29 -06:00
luke crouch 31ac365e6d Merge pull request #974 from mozilla/bump-version-to-4.1.0
bump version to 4.1.0
2017-11-16 09:50:59 -06:00
groovecoder df8471a4dd bump version to 4.1.0 2017-11-16 09:47:18 -06:00
groovecoder 18539f2540 ignore webextension/web-ext-artifacts 2017-11-16 15:38:34 +00:00
Jonathan Kingston 7c1105a2b7 Change (un)install changes to only work for >57. Fixes #858 and Fixes #900 2017-11-16 15:38:34 +00:00
groovecoder 31298146f3 when user reaches container tab count, show achievement panel 2017-11-16 15:30:02 +00:00
groovecoder 4e6eee220c start containerTabsOpened counter 2017-11-16 15:30:02 +00:00
baku a7be3c9935 TextEncoder/TextDecoder from Cu.importGlobalProperties - #949 2017-11-14 19:36:34 +00:00
luke crouch f512473986 Merge pull request #882 from mozilla/update-README-distribute-steps
add steps for signing, AMO, and GitHub to README
2017-09-29 14:21:22 -05:00
groovecoder 8166a37722 add steps for signing, AMO, and GitHub to README 2017-09-29 13:15:16 -05:00
groovecoder adadb98482 bump version to 4.0.3 2017-09-29 18:04:53 +01:00
luke crouch 25e760cd64 Merge pull request #879 from jonathanKingston/fix-disable-notice
Clean up disabled Private Mode notice. Fixes #878
2017-09-29 11:24:24 -05:00
luke crouch 0ff8e17005 Merge pull request #870 from jonathanKingston/delete-non-existent-container
Fix assignment of stale containers. Fixes #803
2017-09-29 11:06:03 -05:00
Jonathan Kingston c433c6b39e Clean up disabled Private Mode notice. Fixes #878 2017-09-29 16:59:51 +01:00
Jonathan Kingston 1c09c29104 Fix assignment of stale containers. Fixes #803 Fixes #827 2017-09-27 13:51:40 +01:00
luke crouch c1e9cc3c56 Merge pull request #859 from jonathanKingston/prevent-enter-handler-calling-click
Preventing default on enter handler as it seems to call click handler…
2017-09-26 10:46:53 -05:00
luke crouch 27296d24c5 Merge pull request #857 from jonathanKingston/change-wording
Change delete title to remove. Fixes #700
2017-09-26 10:38:57 -05:00
luke crouch 030e635417 Merge pull request #853 from jonathanKingston/bump-version-and-min-ff-version
Add strict min version and extension id and bump version to 4.0.2. Fixes
2017-09-26 10:37:21 -05:00
Jonathan Kingston 07711aaecc Preventing default on enter handler as it seems to call click handlers now. Fixes #856 2017-09-26 11:16:58 +01:00
Jonathan Kingston 16ed8992e2 Change delete title to remove. Fixes #700 2017-09-26 02:50:10 +01:00
Jonathan Kingston 88e6dc7a05 Add strict min version and extension id and bump version to 4.0.2. Fixes #692. Fixes #852 2017-09-23 23:36:24 +01:00
luke crouch 28e8d46743 Merge pull request #834 from jonathanKingston/storage-clean
Store only one of the current version opened. Fixes #833
2017-09-20 15:47:06 -05:00
Jonathan Kingston 77ba1b723f Store only one of the current version opened. Fixes #833 2017-09-20 02:26:50 +01:00
Jonathan Kingston b0cc6e7c2f Merge pull request #818 from jonathanKingston/update-readme-launch-notice
Minor README edit
2017-09-15 00:17:42 +01:00
Jonathan Kingston e84e482130 Minor README edit 2017-09-15 00:17:05 +01:00
Jonathan Kingston b5ae20b874 Merge pull request #817 from jonathanKingston/update-readme-launch-notice
Add launch notice in README
2017-09-14 23:16:55 +01:00
Jonathan Kingston 3ec81e3d1f Add launch notice in README 2017-09-14 23:15:01 +01:00
luke crouch fb5436c287 Merge pull request #815 from jonathanKingston/blob-image
Fix dumping UUID image into the page. Fixes #812
2017-09-13 20:04:05 -05:00
Jonathan Kingston 01a628822b Fix dumping UUID image into the page. Fixes #812 2017-09-14 01:48:32 +01:00
Jonathan Kingston 66e2c8e297 Merge pull request #811 from mozilla/bump-version-4.0.2
bump version to 4.0.2
2017-09-13 22:32:54 +01:00
groovecoder 80661d68f2 fix #809: use "Containers" for name for context menu 2017-09-13 16:16:43 -05:00
groovecoder ef8aa3be75 bump version to 4.0.2 2017-09-13 10:07:56 -05:00
luke crouch 6bc056e019 Merge pull request #794 from jonathanKingston/hide-button-in-queue
Add show button to use showing queue to prevent dupes. Fixes #793
2017-09-07 14:28:47 -05:00
Jonathan Kingston 75deab139b Fix a moving hidden tabs to a new window. Fixes #797 2017-09-07 12:03:28 -07:00
Jonathan Kingston ae79f0a303 Ignore non permissible urls when hiding as we can't open them which causes issues. Fixes #793 2017-09-07 10:12:25 -07:00
Jonathan Kingston 9b83068234 Add show button to use showing queue to prevent dupes. Fixes #791 2017-09-07 09:25:13 -07:00
luke crouch fec2be9429 Merge pull request #789 from jonathanKingston/encode-url-fix
Encode non conforming chars that break moz-extension urls. Fixes #787
2017-09-07 09:05:16 -05:00
luke crouch 9f1b06ddd3 Merge pull request #790 from jonathanKingston/jpm-ignore-more
Ignore more files with .jpmignore
2017-09-06 14:46:45 -05:00
Jonathan Kingston ad2198e8b5 Encode non conforming chars that break moz-extension urls. Fixes #787 2017-09-05 17:10:07 -07:00
Jonathan Kingston 1791fdf0ef Ignore more files with .jpmignore 2017-09-05 17:09:36 -07:00
luke crouch 4ab705081e Merge pull request #788 from mozilla/bump-version-to-4.0.0
bump version to 4 for AMO
2017-09-05 14:25:57 -05:00
groovecoder 15b9dce1a9 AMO needs another version bump 2017-09-05 14:23:33 -05:00
groovecoder da3fc2ede2 bump version to 4.0.0 2017-09-05 13:33:34 -05:00
luke crouch 385c585888 Merge pull request #784 from jonathanKingston/fix-new-tab
Simplify new tab creation in the popup fixing issues. Fixes #781
2017-09-05 13:30:34 -05:00
luke crouch 734b97beb0 Merge pull request #786 from jonathanKingston/name-change
Name change. Fixes #763
2017-09-05 10:15:53 -05:00
Jonathan Kingston 3aa311a3c1 Name change. Fixes #763 2017-09-01 15:16:56 -07:00
Jonathan Kingston df7d7f9c38 Simplify new tab creation in the popup fixing issues. Fixes #781 2017-09-01 12:27:40 -07:00
luke crouch 65be77665a Merge pull request #783 from jonathanKingston/reset-prefs-on-uninstall
Reset prefs on uninstall
2017-09-01 11:08:06 -05:00
luke crouch 44548659db Merge pull request #780 from jonathanKingston/apply-styles-to-legacy
Add styles for 55+56 versions of Firefox so everyone gets a consisten…
2017-09-01 11:01:02 -05:00
Jonathan Kingston 10c4395efd Reset prefs for new users on uninstall. Fixes #782 2017-08-31 15:00:40 -07:00
Jonathan Kingston 27b2a4b5f2 Add styles for 55+56 versions of Firefox so everyone gets a consistent underline. Fixes #779 2017-08-31 11:58:03 -07:00
luke crouch 6f54e7ff7f Merge pull request #776 from jonathanKingston/context-menu-neaten
Add move and hide to context menu and neaten using checkboxes. Fixes …
2017-08-30 15:48:38 -05:00
Jonathan Kingston cb6726b667 Add move and hide to context menu and neaten using checkboxes. Fixes #711 2017-08-30 13:20:57 -07:00
luke crouch 0964311fa1 Merge pull request #778 from jonathanKingston/web-ext-advice
Add web extension specific advice on building. Fixes #751
2017-08-30 15:13:44 -05:00
luke crouch 2831d019f5 Merge pull request #777 from jonathanKingston/container-removal-fixes
Handle removing containers to refresh menus and remove assignments. F…
2017-08-30 15:13:03 -05:00
luke crouch 1cc58cad9b Merge pull request #775 from jonathanKingston/remove-unusable-paths-on-show
Remove about: paths from showTabs as it prevents the tabs being creat…
2017-08-30 15:00:26 -05:00
luke crouch bc9660f76e Merge pull request #774 from jonathanKingston/hidden-tab-open
Add a tab observer to show hidden tabs as there are many tab creation…
2017-08-30 14:55:06 -05:00
Jonathan Kingston f526caca50 Add web extension specific advice on building. Fixes #751 2017-08-30 11:12:55 -07:00
Jonathan Kingston b6a98fb83e Handle removing containers to refresh menus and remove assignments. Fixes: #761, Fixes: #752 2017-08-28 21:55:29 -07:00
Jonathan Kingston af2b4b79a9 Remove about: paths from showTabs as it prevents the tabs being created. Fixes #773 2017-08-28 17:46:55 -07:00
Jonathan Kingston a762b5eca2 Add a tab observer to show hidden tabs as there are many tab creation routes. Uses a queue to prevent multiple triggers. Fixes #765 2017-08-28 17:07:46 -07:00
luke crouch 3cc40344af Merge pull request #760 from jonathanKingston/removalOfTabPageCounter
Removal of tab page counter code. Fixes #759
2017-08-25 11:44:51 -05:00
luke crouch 278cdb7f69 Merge pull request #762 from jonathanKingston/change-to-window-only
Remove tab counting code as also not needed, change tab counting to b…
2017-08-25 11:27:45 -05:00
Jonathan Kingston 0be03ebeb7 Remove tab counting code as also not needed, change tab counting to be per window. Prevent reopening of hidden tabs doesn't call itself. Fixes #750, Fixes #753, Fixes #756 2017-08-24 16:05:14 +01:00
Jonathan Kingston c69f37a2de Removal of tab page counter code. Fixes #759 2017-08-24 15:04:47 +01:00
Jonathan Kingston b20ac8169a Merge pull request #758 from mozilla/move-to-AMO-665
for #665: update title, desc, version for AMO
2017-08-24 15:02:43 +01:00
groovecoder 9e98d35b45 for #665: update title, desc, version for AMO 2017-08-23 12:53:23 -05:00
luke crouch 17f2781e07 Merge pull request #757 from jonathanKingston/remove-pb-mode
Extension shouldn't be enabled in pb mode as it's currently not worki…
2017-08-23 12:48:38 -05:00
luke crouch 0acf9cc0e6 Merge pull request #754 from jonathanKingston/move-containers-fix
Fix moving of more than one tab to a new window. Fixes #746
2017-08-23 12:40:11 -05:00
Jonathan Kingston 70573d0559 Extension shouldn't be enabled in pb mode as it's currently not working in many places. Fixes #756 2017-08-23 15:23:49 +01:00
Jonathan Kingston da239237f7 Fix moving of more than one tab to a new window. Fixes #746 2017-08-22 18:54:32 +01:00
luke crouch 29f078d2c9 Merge pull request #726 from jonathanKingston/bootstrapify
Bootstrapify
2017-08-15 16:31:13 -05:00
Jonathan Kingston 5704a21c97 Merge remote-tracking branch 'upstream/master' into bootstrapify 2017-08-15 22:24:32 +01:00
Jonathan Kingston 57a31f7f97 Remove legacy telemetry code as non functional now 2017-08-15 19:30:57 +01:00
Jonathan Kingston d685a58d74 Bootstrapify extension to work for Firefox Nightly 57 SDK removal. Fixes #725 2017-08-15 16:53:43 +01:00
Jonathan Kingston a44bf21582 Merge pull request #713 from jonathanKingston/svg-icon-context-change
Svg icon context change
2017-08-15 10:50:44 +01:00
luke crouch 8f8fc322eb Merge pull request #715 from jonathanKingston/remove-legacy-css
Removal of legacy CSS for builds after 2015-08-06. Fixes #714
2017-08-07 14:05:51 -05:00
Jonathan Kingston f03404ad9e Removal of legacy CSS for builds after 2015-08-06. Fixes #714 2017-08-07 19:50:37 +01:00
Jonathan Kingston 78b5de3b44 Adding in SVG icon for context-fill colours. Fixes #710 2017-08-05 10:28:27 +01:00
Jonathan Kingston e78f49bec5 Making icons sharper since hand crafting your own svg was cool. 2017-08-05 09:59:45 +01:00
luke crouch ee8c69b73e Merge pull request #605 from jonathanKingston/sdk-mamoth-breakage
Shirk my SDK code
2017-08-04 20:13:20 +00:00
Jonathan Kingston 4dfffb8c34 Merge remote-tracking branch 'upstream/master' into sdk-mamoth-breakage 2017-08-04 18:21:48 +01:00
Jonathan Kingston fe77c891cd Adding back in legacy code without message passing code. 2017-08-04 16:28:53 +01:00
Jonathan Kingston 12a6bb3b9b Break web extensions code 2017-08-02 14:20:59 +01:00
Jonathan Kingston 175cdc1a6b Break my SDK code 2017-08-02 14:20:59 +01:00
Jonathan Kingston 0ec7e4aee3 Use new theme_icons manifest for specifying light and dark icons. Fixes #603 2017-08-02 14:20:59 +01:00
84 changed files with 3978 additions and 3993 deletions
+1 -2
View File
@@ -1,3 +1,2 @@
testpilot-metrics.js
lib/shield/*.js
lib/testpilot/*.js
coverage
+6 -1
View File
@@ -13,7 +13,12 @@ module.exports = {
"CustomizableUI": true,
"CustomizableWidgets": true,
"SessionStore": true,
"Services": true
"Services": true,
"Components": true,
"XPCOMUtils": true,
"OS": true,
"ADDON_UNINSTALL": true,
"ADDON_DISABLE": true
},
"plugins": [
"promise",
+27
View File
@@ -0,0 +1,27 @@
<!--
Feel free to ignore this Issue template if you just want to ask or suggest something. If you experience an Issue then please provide all asked information.
Also please make sure that:
- "Firefox will: Never remember history" in the Firefox Preferences/Options under "Privacy & Security > History" is NOT selected
- You are NOT using Firefox in a Private Window
- You can see a grayed out but ticked Checkbox with the description "Enable Container Tabs" in the Firefox Preferences/Options under "Tabs"
-->
- Multi-Account Containers Version:
- Operating System + Version:
- Firefox Version:
- Other installed Add-ons + Version + Enabled/Disabled-Status:
<!-- To be able to copy & paste the full list of your Add-ons navigate to "about:support" and scroll down to "Extensions" -->
### Actual behavior
### Expected behavior
### Steps to reproduce
1.
2.
3.
### Notes
+10 -2
View File
@@ -3,8 +3,16 @@ package-lock.json
node_modules
README.html
*.xpi
*.swp
*.swo
*.sw*
.vimrc
.env
addon.env
src/web-ext-artifacts/*
# JetBrains IDE files
.idea
# IstanbulJS
.nyc_output
coverage
+3
View File
@@ -3,6 +3,7 @@ docs/
test/
.npm/
node_modules/
bin/
.env
.eslintrc.js
@@ -14,6 +15,8 @@ node_modules/
.stylelintrc
.travis.yml
*.xpi
*.md
.vimrc
.DS_Store
.gdb_history
*.sw*
+1 -1
View File
@@ -5,7 +5,7 @@
"extends": "stylelint-config-standard",
"ignoreFiles": ["webextension/css/*.min.css"],
"ignoreFiles": ["src/css/*.min.css"],
"rules": {
"declaration-block-no-duplicate-properties": true,
+1 -1
View File
@@ -1,6 +1,6 @@
language: node_js
node_js:
- "6.1"
- "lts/*"
notifications:
irc:
+14 -2
View File
@@ -1,3 +1,15 @@
# Code Of Conduct
# Community Participation Guidelines
This add-on follows the [Mozilla Community Participation Guidelines](https://www.mozilla.org/en-US/about/governance/policies/participation/) for our code of conduct.
This repository is governed by Mozilla's code of conduct and etiquette guidelines.
For more details, please read the
[Mozilla Community Participation Guidelines](https://www.mozilla.org/about/governance/policies/participation/).
## How to Report
For more information on how to report violations of the Community Participation Guidelines, please read our '[How to Report](https://www.mozilla.org/about/governance/policies/participation/reporting/)' page.
<!--
## Project Specific Etiquette
In some cases, there will be additional project etiquette i.e.: (https://bugzilla.mozilla.org/page.cgi?id=etiquette.html).
Please update for your project.
-->
+2 -2
View File
@@ -9,9 +9,9 @@ Everyone is welcome to contribute to containers. Reach out to team members if yo
If you find a bug with containers, please file a issue.
Check first if the bug might already exist: https://github.com/mozilla/testpilot-containers/issues
Check first if the bug might already exist: https://github.com/mozilla/multi-account-containers/issues
[Open an issue](https://github.com/mozilla/testpilot-containers/issues/new)
[Open an issue](https://github.com/mozilla/multi-account-containers/issues/new)
1. Visit about:support
2. Click "Copy raw data to clipboard" and paste into the bug. Alternatively copy the following sections into the issue:
+39 -63
View File
@@ -1,11 +1,8 @@
# Containers Add-on
# Multi-Account Containers
[![Available on Test Pilot](https://img.shields.io/badge/available_on-Test_Pilot-0996F8.svg)](https://testpilot.firefox.com/experiments/containers)
The Firefox Multi-Account Containers extension lets you carve out a separate box for each of your online lives no more opening a different browser just to check your work email! [Learn More Here](https://blog.mozilla.org/firefox/introducing-firefox-multi-account-containers/)
[Embedded Web Extension](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Embedded_WebExtensions) to build [Containers](https://blog.mozilla.org/tanvi/2016/06/16/contextual-identities-on-the-web/) as a Firefox [Test Pilot](https://testpilot.firefox.com/) Experiment and [Shield Study](https://wiki.mozilla.org/Firefox/Shield/Shield_Studies) to learn:
* Will a general Firefox audience understand the Containers feature?
* Is the UI as currently implemented in Nightly clear or discoverable?
[Available on addons.mozilla.org](https://addons.mozilla.org/en-GB/firefox/addon/multi-account-containers/)
For more info, see:
@@ -16,73 +13,52 @@ For more info, see:
## Requirements
* node 7+ (for jpm)
* Firefox 53+
* Firefox 57+
## Development
### Development Environment
Add-on development is better with [a particular environment](https://developer.mozilla.org/en-US/Add-ons/Setting_up_extension_development_environment). One simple way to get that environment set up is to install the [DevPrefs add-on](https://addons.mozilla.org/en-US/firefox/addon/devprefs/). You can make a custom Firefox profile that includes the DevPrefs add-on, and use that profile when you run the code in this repository.
1. Make a new profile by running `/path/to/firefox -P`, which launches the profile editor. "Create Profile" -- name it whatever you wish (e.g. 'addon_dev') and store it in the default location. It's probably best to deselect the option to "Use without asking," since you probably don't want to use this as your default profile.
2. Once you've created your profile, click "Start Firefox". A new instance of Firefox should launch. Go to Tools->Add-ons and search for "DevPrefs". Install it. Quit Firefox.
3. Now you have a new, vanilla Firefox profile with the DevPrefs add-on installed. You can use your new profile with the code in _this_ repository like so:
#### Run the `.xpi` file in an unbranded build
Release & Beta channels do not allow un-signed add-ons, even with the DevPrefs. So, you must run the add-on in an [unbranded build](https://wiki.mozilla.org/Add-ons/Extension_Signing#Unbranded_Builds):
1. Download and install an un-branded build of Firefox
2. Download the latest `.xpi` from this repository's releases
3. Run the un-branded build of Firefox with your DevPrefs profile
4. Go to `about:addons`
5. Click the gear, and select "Install Add-on From File..."
6. Select the `.xpi` file
#### Run the TxP experiment with `jpm`
1. `git clone git@github.com:mozilla/testpilot-containers.git`
2. `cd testpilot-containers`
3. `npm install`
4. `./node_modules/.bin/jpm run -p /Path/To/Firefox/Profiles/{junk}.addon_dev -b FirefoxBeta` (where FirefoxBeta might be: ~/<reponame>/obj-x86_64-pc-linux-gnu/dist/bin/firefox or ~/<downloadedFirefoxBeta>/firefox)
Check out the [Browser Toolbox](https://developer.mozilla.org/en-US/docs/Tools/Browser_Toolbox) for more information about debugging add-on code.
#### Run the shield study with `shield`
1. `git clone git@github.com:mozilla/testpilot-containers.git`
2. `cd testpilot-containers`
3. `npm install`
4. `npm install -g shield-study-cli`
5. `shield run . -- --binary Nightly`
### Building .xpi
To build a local testpilot-containers.xpi, use the plain [`jpm
xpi`](https://developer.mozilla.org/en-US/Add-ons/SDK/Tools/jpm#jpm_xpi) command,
or run `npm run build`.
#### Building a shield .xpi
To build a local shield-study-containers.xpi, run `npm run build-shield`.
### Signing an .xpi
To sign an .xpi, use [`jpm
sign`](https://developer.mozilla.org/en-US/Add-ons/SDK/Tools/jpm#jpm_sign)
command.
Note: You will need to be [an author on the AMO
add-on](https://addons.mozilla.org/en-US/developers/addon/containers-experiment/ownership).
1. `npm install`
2. `./node_modules/web-ext/bin/web-ext run -s src/`
### Testing
TBD
`npm run test`
or
`npm run lint`
for just the linter
There is a timeout test that sometimes fails on certain machines, so make sure to run the tests on your clone before you make any changes to see if you have this problem.
### Distributing
TBD
#### Make the new version
1. Bump the version number in `package.json` and `manifest.json`
2. Commit the version number bump
3. Create a git tag for the version: `git tag <version>`
4. Push the tag up to GitHub: `git push --tags`
#### Publish to AMO
1. `npm run-script build`
2. [Upload the `.zip` to AMO](https://addons.mozilla.org/en-US/developers/addon/multi-account-containers/versions/submit/)
#### Publish to GitHub
Finally, we also publish the release to GitHub for those followers.
1. Download the signed `.xpi` from [the addon versions page](https://addons.mozilla.org/en-US/developers/addon/multi-account-containers/versions)
2. [Make the new release on
GitHub](https://github.com/mozilla/multi-account-containers/releases/new)
* Use the version number for "Tag version" and "Release title"
* Release notes: copy the output of `git log --no-merges --pretty=format:"%h %s" <previous-version>..<new-version>`
* Attach binaries: select the signed `.xpi` file
### Links
- [Licence](./LICENSE.txt)
Facebook & Twitter icons CC-Attrib https://fairheadcreative.com.
- [License](./LICENSE.txt)
- [Contributing](./CONTRIBUTING.md)
- [Code Of Conduct](./CODE_OF_CONDUCT.md)
-118
View File
@@ -1,108 +1,3 @@
/* HACK: Custom Container vars do not propigate correctly
until the container tab is blurred and refocused,
adding the data-identity-color with the default hex
value, or chrome url path as an alternate selector mitiages this bug.*/
[data-identity-color="blue"],
[data-identity-color="#00a7e0"] {
--identity-tab-color: #37adff;
--identity-icon-color: #37adff;
}
[data-identity-color="turquoise"],
[data-identity-color="#01bdad"] {
--identity-tab-color: #00c79a;
--identity-icon-color: #00c79a;
}
[data-identity-color="green"],
[data-identity-color="#7dc14c"] {
--identity-tab-color: #51cd00;
--identity-icon-color: #51cd00;
}
[data-identity-color="yellow"],
[data-identity-color="#ffcb00"] {
--identity-tab-color: #ffcb00;
--identity-icon-color: #ffcb00;
}
[data-identity-color="orange"],
[data-identity-color="#f89c24"] {
--identity-tab-color: #ff9f00;
--identity-icon-color: #ff9f00;
}
[data-identity-color="red"],
[data-identity-color="#d92215"] {
--identity-tab-color: #ff613d;
--identity-icon-color: #ff613d;
}
[data-identity-color="pink"],
[data-identity-color="#ee5195"] {
--identity-tab-color: #ff4bda;
--identity-icon-color: #ff4bda;
}
[data-identity-color="purple"],
[data-identity-color="#7a2f7a"] {
--identity-tab-color: #af51f5;
--identity-icon-color: #af51f5;
}
[data-identity-icon="fingerprint"],
[data-identity-icon="chrome://browser/skin/usercontext/personal.svg"] {
--identity-icon: url("/data/usercontext.svg#fingerprint");
}
[data-identity-icon="briefcase"],
[data-identity-icon="chrome://browser/skin/usercontext/work.svg"] {
--identity-icon: url("/data/usercontext.svg#briefcase");
}
[data-identity-icon="dollar"],
[data-identity-icon="chrome://browser/skin/usercontext/banking.svg"] {
--identity-icon: url("/data/usercontext.svg#dollar");
}
[data-identity-icon="cart"],
[data-identity-icon="chrome://browser/skin/usercontext/cart.svg"],
[data-identity-icon="chrome://browser/skin/usercontext/shopping.svg"] {
--identity-icon: url("/data/usercontext.svg#cart");
}
[data-identity-icon="circle"] {
--identity-icon: url("/data/usercontext.svg#circle");
}
[data-identity-icon="gift"] {
--identity-icon: url("/data/usercontext.svg#gift");
}
[data-identity-icon="vacation"] {
--identity-icon: url("/data/usercontext.svg#vacation");
}
[data-identity-icon="food"] {
--identity-icon: url("/data/usercontext.svg#food");
}
[data-identity-icon="fruit"] {
--identity-icon: url("/data/usercontext.svg#fruit");
}
[data-identity-icon="pet"] {
--identity-icon: url("/data/usercontext.svg#pet");
}
[data-identity-icon="tree"] {
--identity-icon: url("/data/usercontext.svg#tree");
}
[data-identity-icon="chill"] {
--identity-icon: url("/data/usercontext.svg#chill");
}
#userContext-indicator {
height: 16px;
list-style-image: none !important;
@@ -129,19 +24,6 @@ value, or chrome url path as an alternate selector mitiages this bug.*/
display: none;
}
.userContext-icon,
.menuitem-iconic[data-usercontextid] > .menu-iconic-left > .menu-iconic-icon,
.subviewbutton[usercontextid] > .toolbarbutton-icon,
#userContext-indicator {
background-image: var(--identity-icon) !important;
background-position: center center;
background-repeat: no-repeat;
background-size: contain;
fill: var(--identity-icon-color) !important;
filter: url(/img/filters.svg#fill);
filter: url(/data/filters.svg#fill);
}
/* containers experiment */
/* reset nightly containers */
-285
View File
@@ -1,285 +0,0 @@
# METRICS
## Data Analysis
The collected data will primarily be used to answer the following questions.
Images are used for visualization and are not composed of actual data.
### Do users install and run this?
What is the overall engagement of the Containers experiment?
**This is the standard Daily Active User (DAU) and Monthly Active User (MAU) analysis.**
This captures data from the users who have the add-on installed, regardless of
whether they are actively interacting with it.
![](kpi-1.png)
### Immediate Questions
* Do people use the containers feature & how do people create new container tabs?
* Click to create new container tab
* \+ `entry-point` value: "tab-bar" or "pop-up"
* Do people who use the containers feature continue to use it?
* Retention: opening a second container tab (second tab in the same container, or a tab in a second container?)
* What containers do people use?
* userContextId
* \+ Number of tabs in the container (when should we measure this? on every tab open?)
* Do people edit their containers?
* Click on "Edit Containers"
* Click to edit a single container
* Click "OK"
* Click to delete a single container
* Click "OK"
* Click to add a container
* Click "OK"
* Do people sort the tabs?
* Click sort
* \+ Number of tabs when clicked
* Average number of container tabs when sort was clicked
* Do users show and hide container tabs?
* Click hide
* \+ Number of tabs when clicked
* \+ Number of hidden containers when clicked
* Click show
* \+ Number of tabs when clicked
* \+ Number of shown containers when clicked
* Do users move container tabs to new windows?
* Click move
* \+ Number of tabs when clicked
* Average number of container tabs when new window was clicked
* How many containers do users have hidden at the same time? (when should we measure this? each time a container is hidden?)
* Do users pin container tabs? (do we have existing Telemetry for pinning?)
* Do users visit more pages in container tabs than non-container tabs?
### Follow-up Questions
What are some follow-up questions we anticipate we will ask based on any of the
above answers/data?
* What is the average lifespan of a container tab? Is that longer or shorter than a regular tab? (if we don't have data on the latter, the former probably isn't worth gathering data on since we will have nothing to compare it to).
## Data Collection
### Server Side
There is currently no server side component to Containers.
### Client Side
Containers will use Test Pilot Telemetry with no batching of data. Details
of when pings are sent are below, along with examples of the `payload` portion
of a `testpilottest` telemetry ping for each scenario.
* The user shows the new tab menu
```js
{
"uuid": <uuid>,
"event": "show-plus-button-menu",
"eventSource": ["plus-button"]
}
```
* The user clicks on a container name to open a tab in that container
```js
{
"uuid": <uuid>,
"userContextId": <userContextId>,
"clickedContainerTabCount": <number-of-tabs-in-the-container>,
"event": "open-tab",
"eventSource": ["tab-bar"|"pop-up"|"file-menu"|"alltabs-menu"|"plus-button"]
}
```
* The user clicks "Edit Containers" in the pop-up
```js
{
"uuid": <uuid>,
"event": "edit-containers"
}
```
* The user clicks OK after clicking on a container edit icon in the pop-up
```js
{
"uuid": <uuid>,
"userContextId": <userContextId>,
"event": "edit-container"
}
```
* The user clicks OK after clicking on a container delete icon in the pop-up
```js
{
"uuid": <uuid>,
"userContextId": <userContextId>,
"event": "delete-container"
}
```
* The user clicks OK after clicking to add a container in the pop-up
```js
{
"uuid": <uuid>,
"event": "add-container"
}
```
* The user clicks the sort button/icon in the pop-up
```js
{
"uuid": <uuid>,
"event": "sort-tabs",
"shownContainersCount": <number-of-containers-with-tabs-shown>,
"totalContainerTabsCount": <number-of-all-container-tabs>,
"totalNonContainerTabsCount": <number-of-all-non-container-tabs>
}
```
* The user clicks "Hide these container tabs" in the popup
```js
{
"uuid": <uuid>,
"userContextId": <userContextId>,
"clickedContainerTabCount": <number-of-tabs-in-the-container>,
"event": "hide-tabs",
"hiddenContainersCount": <number-of-containers-with-tabs-hidden>,
"shownContainersCount": <number-of-containers-with-tabs-shown>,
"totalContainersCount": <number-of-containers-with-tabs-hidden-or-shown>
}
```
* The user clicks "Show these container tabs" in the popup
```js
{
"uuid": <uuid>,
"userContextId": <userContextId>,
"clickedContainerTabCount": <number-of-tabs-in-the-container>,
"event": "show-tabs",
"hiddenContainersCount": <number-of-containers-with-tabs-hidden>,
"shownContainersCount": <number-of-containers-with-tabs-shown>,
"totalContainersCount": <number-of-containers-with-tabs-hidden-or-shown>
}
```
* The user clicks "Move tabs to a new window" in the popup
```js
{
"uuid": <uuid>,
"userContextId": <userContextId>,
"clickedContainerTabCount": <number-of-tabs-in-the-container>,
"event": "move-tabs-to-window"
}
```
* When a user encounters the disabled "move" feature because of incompatible add-ons
```js
{
"uuid": <uuid>,
"event": "incompatible-addons-detected"
}
```
* The user closes a tab
```js
{
"uuid": <uuid>,
"userContextId": <userContextId>,
"event": "page-requests-completed-per-tab",
"pageRequestCount": <pageRequestCount>
}
```
* The user goes idle
```js
{
"uuid": <uuid>,
"userContextId": <userContextId>,
"event": "page-requests-completed-per-activity",
"pageRequestCount": <pageRequestCount>
}
```
* The user chooses "Always Open in this Container" context menu option. (Note: We send two separate event names: one for assigning a site to a container, one for removing a site from a container.)
```js
{
"uuid": <uuid>,
"userContextId": <userContextId>,
"event": "[added|removed]-container-assignment"
}
```
* Firefox prompts the user to reload a site into a container after the user picked "Always Open in this Container".
```js
{
"uuid": <uuid>,
"userContextId": <userContextId>,
"event": "prompt-reload-page-in-container"
}
```
* The user clicks "Open in *assigned* container" to reload a site into a container after the user picked "Always Open in this Container".
```js
{
"uuid": <uuid>,
"event": "click-to-reload-page-in-container"
}
```
* The user clicks "Open in *Current* container" to reload a site into a container after the user picked "Always Open in this Container".
```js
{
"uuid": <uuid>,
"event": "click-to-reload-page-in-same-container"
}
```
* Firefox automatically reloads a site into a container after the user picked "Always Open in this Container".
```js
{
"uuid": <uuid>,
"userContextId": <userContextId>,
"event": "auto-reload-page-in-container"
}
```
### A Redshift schema for the payload:
```lua
local schema = {
-- column name field type length attributes field name
{"uuid", "VARCHAR", 255, nil, "Fields[payload.uuid]"},
{"userContextId", "INTEGER", 255, nil, "Fields[payload.userContextId]"},
{"clickedContainerTabCount", "INTEGER", 255, nil, "Fields[payload.clickedContainerTabCount]"},
{"eventSource", "VARCHAR", 255, nil, "Fields[payload.eventSource]"},
{"event", "VARCHAR", 255, nil, "Fields[payload.event]"},
{"pageRequestCount", "INTEGER", 255, nil, "Fields[payload.pageRequestCount]"}
{"hiddenContainersCount", "INTEGER", 255, nil, "Fields[payload.hiddenContainersCount]"},
{"shownContainersCount", "INTEGER", 255, nil, "Fields[payload.shownContainersCount]"},
{"totalContainersCount", "INTEGER", 255, nil, "Fields[payload.totalContainersCount]"},
{"totalContainerTabsCount", "INTEGER", 255, nil, "Fields[payload.totalContainerTabsCount]"},
{"totalNonContainerTabsCount", "INTEGER", 255, nil, "Fields[payload.totalNonContainerTabsCount]"}
}
```
### Valid data should be enforced on the server side:
* `eventSource` should be one of `tab-bar`, `pop-up`, `file-menu`, "alltabs-nmenu" or "plus-button".
All Mozilla data is kept by default for 180 days and in accordance with our
privacy policies.
-1443
View File
File diff suppressed because it is too large Load Diff
-55
View File
@@ -1,55 +0,0 @@
/**
* Drop-in replacement for {@link external:sdk/event/target.EventTarget} for use
* with es6 classes.
* @module event-target
* @author Martin Giger
* @license MPL-2.0
*/
/**
* An SDK class that add event reqistration methods
* @external sdk/event/target
* @requires sdk/event/target
*/
/**
* @class EventTarget
* @memberof external:sdk/event/target
* @see {@link https://developer.mozilla.org/en-US/Add-ons/SDK/Low-Level_APIs/event_target#EventTarget}
*/
// slightly modified from: https://raw.githubusercontent.com/freaktechnik/justintv-stream-notifications/master/lib/event-target.js
"use strict";
const { on, once, off, setListeners } = require("sdk/event/core");
/* istanbul ignore next */
/**
* @class
*/
class EventTarget {
constructor(options) {
setListeners(this, options);
}
on(...args) {
on(this, ...args);
return this;
}
once(...args) {
once(this, ...args);
return this;
}
off(...args) {
off(this, ...args);
return this;
}
removeListener(...args) {
off(this, ...args);
return this;
}
}
exports.EventTarget = EventTarget;
-428
View File
@@ -1,428 +0,0 @@
"use strict";
// Chrome privileged
const {Cu} = require("chrome");
const { Services } = Cu.import("resource://gre/modules/Services.jsm");
const { TelemetryController } = Cu.import("resource://gre/modules/TelemetryController.jsm");
const CID = Cu.import("resource://gre/modules/ClientID.jsm");
// sdk
const { merge } = require("sdk/util/object");
const querystring = require("sdk/querystring");
const { prefs } = require("sdk/simple-prefs");
const prefSvc = require("sdk/preferences/service");
const { setInterval } = require("sdk/timers");
const tabs = require("sdk/tabs");
const { URL } = require("sdk/url");
const { EventTarget } = require("./event-target");
const { emit } = require("sdk/event/core");
const self = require("sdk/self");
const DAY = 86400*1000;
// ongoing within-addon fuses / timers
let lastDailyPing = Date.now();
/* Functional, self-contained utils */
// equal probability choices from a list "choices"
function chooseVariation(choices,rng=Math.random()) {
let l = choices.length;
return choices[Math.floor(l*Math.random())];
}
function dateToUTC(date) {
return Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds());
}
function generateTelemetryIdIfNeeded() {
let id = TelemetryController.clientID;
/* istanbul ignore next */
if (id == undefined) {
return CID.ClientIDImpl._doLoadClientID()
} else {
return Promise.resolve(id)
}
}
function userId () {
return prefSvc.get("toolkit.telemetry.cachedClientID","unknown");
}
var Reporter = new EventTarget().on("report",
(d) => prefSvc.get('shield.debug') && console.log("report",d)
);
function report(data, src="addon", bucket="shield-study") {
data = merge({}, data , {
study_version: self.version,
about: {
_src: src,
_v: 2
}
});
if (prefSvc.get('shield.testing')) data.testing = true
emit(Reporter, "report", data);
let telOptions = {addClientId: true, addEnvironment: true}
return TelemetryController.submitExternalPing(bucket, data, telOptions);
}
function survey (url, queryArgs={}) {
if (! url) return
let U = new URL(url);
let q = U.search;
if (q) {
url = U.href.split(q)[0];
q = querystring.parse(querystring.unescape(q.slice(1)));
} else {
q = {};
}
// get user info.
let newArgs = merge({},
q,
queryArgs
);
let searchstring = querystring.stringify(newArgs);
url = url + "?" + searchstring;
return url;
}
function setOrGetFirstrun () {
let firstrun = prefs["shield.firstrun"];
if (firstrun === undefined) {
firstrun = prefs["shield.firstrun"] = String(dateToUTC(new Date())) // in utc, user set
}
return Number(firstrun)
}
function reuseVariation (choices) {
return prefs["shield.variation"];
}
function setVariation (choice) {
prefs["shield.variation"] = choice
return choice
}
function die (addonId=self.id) {
/* istanbul ignore else */
if (prefSvc.get("shield.fakedie")) return;
/* istanbul ignore next */
require("sdk/addon/installer").uninstall(addonId);
}
// TODO: GRL vulnerable to clock time issues #1
function expired (xconfig, now = Date.now() ) {
return ((now - Number(xconfig.firstrun))/ DAY) > xconfig.days;
}
function resetShieldPrefs () {
delete prefs['shield.firstrun'];
delete prefs['shield.variation'];
}
function cleanup () {
prefSvc.keys(`extensions.${self.preferencesBranch}`).forEach (
(p) => {
delete prefs[p];
})
}
function telemetrySubset (xconfig) {
return {
study_name: xconfig.name,
branch: xconfig.variation,
}
}
class Study extends EventTarget {
constructor (config) {
super();
this.config = merge({
name: self.addonId,
variations: {'observe-only': () => {}},
surveyUrls: {},
days: 7
},config);
this.config.firstrun = setOrGetFirstrun();
let variation = reuseVariation();
if (variation === undefined) {
variation = this.decideVariation();
if (!(variation in this.config.variations)) {
// chaijs doesn't think this is an instanceof Error
// freaktechnik and gregglind debugged for a while.
// sdk errors might not be 'Errors' or chai is wack, who knows.
// https://dxr.mozilla.org/mozilla-central/search?q=regexp%3AError%5Cs%3F(%3A%7C%3D)+path%3Aaddon-sdk%2Fsource%2F&redirect=false would list
throw new Error("Study Error: chosen variation must be in config.variations")
}
setVariation(variation);
}
this.config.variation = variation;
this.flags = {
ineligibleDie: undefined
};
this.states = [];
// all these work, but could be cleaner. I hate the `bind` stuff.
this.on(
"change", (function (newstate) {
prefSvc.get('shield.debug') && console.log(newstate, this.states);
this.states.push(newstate);
emit(this, newstate); // could have checks here.
}).bind(this)
)
this.on(
"starting", (function () {
this.changeState("modifying");
}).bind(this)
)
this.on(
"maybe-installing", (function () {
if (!this.isEligible()) {
this.changeState("ineligible-die");
} else {
this.changeState("installed")
}
}).bind(this)
)
this.on(
"ineligible-die", (function () {
try {this.whenIneligible()} catch (err) {/*ok*/} finally { /*ok*/ }
this.flags.ineligibleDie = true;
this.report(merge({}, telemetrySubset(this.config), {study_state: "ineligible"}), "shield");
this.final();
die();
}).bind(this)
)
this.on(
"installed", (function () {
try {this.whenInstalled()} catch (err) {/*ok*/} finally { /*ok*/ }
this.report(merge({}, telemetrySubset(this.config), {study_state: "install"}), "shield");
this.changeState("modifying");
}).bind(this)
)
this.on(
"modifying", (function () {
var mybranchname = this.variation;
this.config.variations[mybranchname](); // do the effect
this.changeState("running");
}).bind(this)
)
this.on( // the one 'many'
"running", (function () {
// report success
this.report(merge({}, telemetrySubset(this.config), {study_state: "running"}), "shield");
this.final();
}).bind(this)
)
this.on(
"normal-shutdown", (function () {
this.flags.dying = true;
this.report(merge({}, telemetrySubset(this.config), {study_state: "shutdown"}), "shield");
this.final();
}).bind(this)
)
this.on(
"end-of-study", (function () {
if (this.flags.expired) { // safe to call multiple times
this.final();
return;
} else {
// first time seen.
this.flags.expired = true;
try {this.whenComplete()} catch (err) { /*ok*/ } finally { /*ok*/ }
this.report(merge({}, telemetrySubset(this.config) ,{study_state: "end-of-study"}), "shield");
// survey for end of study
let that = this;
generateTelemetryIdIfNeeded().then(()=>that.showSurvey("end-of-study"));
try {this.cleanup()} catch (err) {/*ok*/} finally { /*ok*/ }
this.final();
die();
}
}).bind(this)
)
this.on(
"user-uninstall-disable", (function () {
if (this.flags.dying) {
this.final();
return;
}
this.flags.dying = true;
this.report(merge({}, telemetrySubset(this.config), {study_state: "user-ended-study"}), "shield");
let that = this;
generateTelemetryIdIfNeeded().then(()=>that.showSurvey("user-ended-study"));
try {this.cleanup()} catch (err) {/*ok*/} finally { /*ok*/ }
this.final();
die();
}).bind(this)
)
}
get state () {
let n = this.states.length;
return n ? this.states[n-1] : undefined
}
get variation () {
return this.config.variation;
}
get firstrun () {
return this.config.firstrun;
}
dieIfExpired () {
let xconfig = this.config;
if (expired(xconfig)) {
emit(this, "change", "end-of-study");
return true
} else {
return false
}
}
alivenessPulse (last=lastDailyPing) {
// check for new day, phone home if true.
let t = Date.now();
if ((t - last) >= DAY) {
lastDailyPing = t;
// phone home
emit(this,"change","running");
}
// check expiration, and die with report if needed
return this.dieIfExpired();
}
changeState (newstate) {
emit(this,'change', newstate);
}
final () {
emit(this,'final', {});
}
startup (reason) {
// https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials/Listening_for_load_and_unload
// check expiry first, before anything, quit and die if so
// check once, right away, short circuit both install and startup
// to prevent modifications from happening.
if (this.dieIfExpired()) return this
switch (reason) {
case "install":
emit(this, "change", "maybe-installing");
break;
case "enable":
case "startup":
case "upgrade":
case "downgrade":
emit(this, "change", "starting");
}
if (! this._pulseTimer) this._pulseTimer = setInterval(this.alivenessPulse.bind(this), 5*60*1000 /*5 minutes */)
return this;
}
shutdown (reason) {
// https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials/Listening_for_load_and_unload
if (this.flags.ineligibleDie ||
this.flags.expired ||
this.flags.dying
) { return this } // special cases.
switch (reason) {
case "uninstall":
case "disable":
emit(this, "change", "user-uninstall-disable");
break;
// 5. usual end of session.
case "shutdown":
case "upgrade":
case "downgrade":
emit(this, "change", "normal-shutdown")
break;
}
return this;
}
cleanup () {
// do the simple prefs and simplestorage cleanup
// extend by extension
resetShieldPrefs();
cleanup();
}
isEligible () {
return true;
}
whenIneligible () {
// empty function unless overrided
}
whenInstalled () {
// empty unless overrided
}
whenComplete () {
// when the study expires
}
/**
* equal choice from varations, by default. override to get unequal
*/
decideVariation (rng=Math.random()) {
return chooseVariation(Object.keys(this.config.variations), rng);
}
get surveyQueryArgs () {
return {
variation: this.variation,
xname: this.config.name,
who: userId(),
updateChannel: Services.appinfo.defaultUpdateChannel,
fxVersion: Services.appinfo.version,
}
}
showSurvey(reason) {
let partial = this.config.surveyUrls[reason];
let queryArgs = this.surveyQueryArgs;
queryArgs.reason = reason;
if (partial) {
let url = survey(partial, queryArgs);
tabs.open(url);
return url
} else {
return
}
}
report () { // convenience only
return report.apply(null, arguments);
}
}
module.exports = {
chooseVariation: chooseVariation,
die: die,
expired: expired,
generateTelemetryIdIfNeeded: generateTelemetryIdIfNeeded,
report: report,
Reporter: Reporter,
resetShieldPrefs: resetShieldPrefs,
Study: Study,
cleanup: cleanup,
survey: survey
}
-95
View File
@@ -1,95 +0,0 @@
const { AddonManager } = require('resource://gre/modules/AddonManager.jsm');
const { ClientID } = require('resource://gre/modules/ClientID.jsm');
const Events = require('sdk/system/events');
const { Services } = require('resource://gre/modules/Services.jsm');
const { storage } = require('sdk/simple-storage');
const {
TelemetryController
} = require('resource://gre/modules/TelemetryController.jsm');
const { Request } = require('sdk/request');
const EVENT_SEND_METRIC = 'testpilot::send-metric';
const startTime = (Services.startup.getStartupInfo().process);
function makeTimestamp(timestamp) {
return Math.round((timestamp - startTime) / 1000);
}
function experimentPing(event) {
const timestamp = new Date();
const { subject, data } = event;
let parsed;
try {
parsed = JSON.parse(data);
} catch (err) {
// eslint-disable-next-line no-console
return console.error(`Dropping bad metrics packet: ${err}`);
}
AddonManager.getAddonByID(subject, addon => {
const payload = {
test: subject,
version: addon.version,
timestamp: makeTimestamp(timestamp),
variants: storage.experimentVariants &&
subject in storage.experimentVariants
? storage.experimentVariants[subject]
: null,
payload: parsed
};
TelemetryController.submitExternalPing('testpilottest', payload, {
addClientId: true,
addEnvironment: true
});
// TODO: DRY up this ping centre code here and in lib/Telemetry.
const pcPing = TelemetryController.getCurrentPingData();
pcPing.type = 'testpilot';
pcPing.payload = payload;
const pcPayload = {
// 'method' is used by testpilot-metrics library.
// 'event' was used before that library existed.
event_type: parsed.event || parsed.method,
client_time: makeTimestamp(parsed.timestamp || timestamp),
addon_id: subject,
addon_version: addon.version,
firefox_version: pcPing.environment.build.version,
os_name: pcPing.environment.system.os.name,
os_version: pcPing.environment.system.os.version,
locale: pcPing.environment.settings.locale,
// Note: these two keys are normally inserted by the ping-centre client.
client_id: ClientID.getCachedClientID(),
topic: 'testpilot'
};
// Add any other extra top-level keys = require(the payload, possibly including
// 'object' or 'category', among others.
Object.keys(parsed).forEach(f => {
// Ignore the keys we've already added to `pcPayload`.
const ignored = ['event', 'method', 'timestamp'];
if (!ignored.includes(f)) {
pcPayload[f] = parsed[f];
}
});
const req = new Request({
url: 'https://tiles.services.mozilla.com/v3/links/ping-centre',
contentType: 'application/json',
content: JSON.stringify(pcPayload)
});
req.post();
});
}
function Experiment() {
// If the user has @testpilot-addon, it already bound
// experimentPing to testpilot::send-metric,
// so we don't need to bind this one
AddonManager.getAddonByID('@testpilot-addon', addon => {
if (!addon) {
Events.on(EVENT_SEND_METRIC, experimentPing);
}
});
}
module.exports = Experiment;
+28 -34
View File
@@ -1,58 +1,52 @@
{
"name": "testpilot-containers",
"title": "Containers Experiment",
"description": "Containers works by isolating cookie jars using separate origin-attributes defined visually by colored Container Tabs. This add-on is a modified version of the containers feature for Firefox Test Pilot.",
"version": "2.5.0",
"title": "Multi-Account Containers",
"description": "Containers helps you keep all the parts of your online life contained in different tabs. Custom labels and color-coded tabs help keep different activities — like online shopping, travel planning, or checking work email — separate.",
"version": "6.2.3",
"author": "Andrea Marchesini, Luke Crouch and Jonathan Kingston",
"bugs": {
"url": "https://github.com/mozilla/testpilot-containers/issues"
"url": "https://github.com/mozilla/multi-account-containers/issues"
},
"dependencies": {},
"devDependencies": {
"addons-linter": "^0.15.14",
"deploy-txp": "^1.0.7",
"eslint": "^3.17.1",
"addons-linter": "^1.3.2",
"ajv": "^6.6.3",
"chai": "^4.2.0",
"eslint": "^6.6.0",
"eslint-plugin-no-unsanitized": "^2.0.0",
"eslint-plugin-promise": "^3.4.0",
"htmllint-cli": "^0.0.5",
"jpm": "^1.2.2",
"htmllint-cli": "0.0.7",
"json": "^9.0.6",
"mocha": "^6.2.2",
"npm-run-all": "^4.0.0",
"shield-studies-addon-utils": "^2.0.0",
"nyc": "^15.0.0",
"sinon": "^7.5.0",
"sinon-chai": "^3.3.0",
"stylelint": "^7.9.0",
"stylelint-config-standard": "^16.0.0",
"stylelint-order": "^0.3.0",
"testpilot-metrics": "^2.1.0"
"web-ext": "^2.9.3",
"webextensions-jsdom": "^1.2.1"
},
"engines": {
"firefox": ">=51.0"
},
"permissions": {
"multiprocess": true
},
"hasEmbeddedWebExtension": true,
"homepage": "https://github.com/mozilla/testpilot-containers#readme",
"keywords": [
"jetpack"
],
"homepage": "https://github.com/mozilla/multi-account-containers#readme",
"license": "MPL-2.0",
"main": "index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/mozilla/testpilot-containers.git"
"url": "git+https://github.com/mozilla/multi-account-containers.git"
},
"scripts": {
"build": "npm test && jpm xpi",
"build-shield": "npm test && npm run package-shield",
"deploy": "deploy-txp",
"build": "npm test && cd src && web-ext build --overwrite-dest",
"webext": "web-ext run -s src/",
"lint": "npm-run-all lint:*",
"lint:addon": "addons-linter webextension --self-hosted",
"lint:css": "stylelint webextension/css/*.css",
"lint:html": "htmllint webextension/*.html",
"lint:addon": "addons-linter src --self-hosted",
"lint:css": "stylelint src/css/*.css",
"lint:html": "htmllint *.html",
"lint:js": "eslint .",
"package": "npm run build && mv testpilot-containers.xpi addon.xpi",
"package-shield": "./node_modules/.bin/json -I -f package.json -e 'this.name=\"shield-study-containers\"' && jpm xpi && ./node_modules/.bin/json -I -f package.json -e 'this.name=\"testpilot-containers\"'",
"test": "npm run lint"
},
"updateURL": "https://testpilot.firefox.com/files/@testpilot-containers/updates.json"
"package": "rm -rf src/web-ext-artifacts && npm run build && mv src/web-ext-artifacts/firefox_multi-account_containers-*.zip addon.xpi",
"test": "npm run lint && npm run coverage",
"test:once": "mocha test/**/*.test.js",
"test:watch": "npm run test:once -- --watch",
"coverage": "nyc --reporter=html --reporter=text mocha test/**/*.test.js --timeout 60000"
}
}
@@ -1,7 +1,7 @@
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Containers confirm navigation</title>
<title>Multi-Account Containers Confirm Navigation</title>
<link xmlns="http://www.w3.org/1999/xhtml" rel="stylesheet" href="chrome://browser/skin/aboutNetError.css" type="text/css" media="all" />
<link rel="stylesheet" href="/css/confirm-page.css" />
</head>
@@ -47,7 +47,7 @@ html {
}
#redirect-url {
background: #efefef;
background: #efedf0; /* Grey 20 */
border-radius: 2px;
line-height: 1.5;
padding-block-end: 0.5rem;
@@ -56,6 +56,15 @@ html {
padding-inline-start: 0.5rem;
}
/* stylelint-disable media-feature-name-no-unknown */
@media (prefers-color-scheme: dark) {
#redirect-url {
background: #38383d; /* Grey 70 */
color: #eee; /* White 20 */
}
}
/* stylelint-enable */
#redirect-url img {
block-size: 16px;
inline-size: 16px;
+142 -21
View File
@@ -19,8 +19,13 @@ html {
body {
font-family: Roboto, Noto, "San Francisco", Ubuntu, "Segoe UI", "Fira Sans", message-box, Arial, sans-serif;
inline-size: 300px;
max-inline-size: 300px;
inline-size: calc(var(--overflow-size) + 299px);
max-inline-size: calc(var(--overflow-size) + 299px);
}
html,
body {
block-size: 100%; /* Bugfix: issue 948 */
}
:root {
@@ -45,6 +50,10 @@ body {
--small-text-size: 0.833rem; /* 10px */
--small-radius: 3px;
--icon-button-size: calc(calc(var(--block-line-separation-size) * 2) + 1.66rem); /* 20px */
--column-panel-inline-size: calc(var(--overflow-size) + 267px);
--inactive-opacity: 0.3;
--overflow-size: 1px;
--icon-fit: 8;
}
@media (min-resolution: 1dppx) {
@@ -234,7 +243,7 @@ table {
text-decoration: underline;
}
/* Panels keep everything togethert */
/* Panels keep everything together */
.panel {
display: flex;
flex-direction: column;
@@ -242,7 +251,8 @@ table {
min-block-size: 400px;
}
.panel.onboarding {
.panel.onboarding,
.achievement-panel {
align-items: center;
block-size: 360px;
margin-block-end: 16px;
@@ -265,7 +275,7 @@ table {
.column-panel-content {
display: flex;
flex-direction: column;
inline-size: 268px;
inline-size: var(--column-panel-inline-size);
}
.column-panel-content .panel-footer {
@@ -346,11 +356,45 @@ table {
transition: background-color 75ms;
}
.half-button-wrapper {
align-items: center;
display: flex;
flex-direction: row;
height: 44px;
inline-size: 100%;
}
.half-onboarding-button {
align-items: center;
background-color: #0996f8;
border-radius: 3px;
color: white;
display: flex;
flex: 1 0 auto;
font-size: 14px;
height: 44px;
inline-size: 50%;
justify-content: center;
margin-inline-end: 4px;
text-decoration: none;
transition: background-color 75ms;
}
.grey-button {
background-color: #e3e3e3;
color: #000;
}
.onboarding-button:hover,
.onboarding-button:active {
background-color: #0675d3;
}
.onboarding-button:focus,
.half-onboarding-button:focus {
box-shadow: 0 0 0 1px #0a84ff inset, 0 0 0 1px #0a84ff, 0 0 0 4px rgba(10, 132, 255, 0.3);
}
/* Pop buttons are the square shaped buttons used to
manage things like container crud */
.pop-button {
@@ -536,7 +580,7 @@ span ~ .panel-header-text {
}
#current-tab > label > input:checked {
background-image: url("chrome://global/skin/in-content/check.svg#check-native");
background-image: url("/img/check.svg");
background-position: -1px -1px;
background-size: var(--icon-size);
}
@@ -574,7 +618,12 @@ span ~ .panel-header-text {
}
.edit-containers-panel .userContext-wrapper {
max-inline-size: 204px;
max-inline-size: calc(var(--overflow-size) + 203px);
}
.disable-edit-containers {
opacity: var(--inactive-opacity);
pointer-events: none;
}
.userContext-wrapper {
@@ -652,7 +701,11 @@ span ~ .panel-header-text {
/* Container info list */
.container-info-tab-title {
flex: 1;
display: flex;
}
.container-info-tab-row:hover .container-info-tab-title .truncate-text {
inline-size: calc(var(--column-panel-inline-size) - 58px);
}
#container-info-hideorshow {
@@ -669,6 +722,21 @@ span ~ .panel-header-text {
opacity: 0.3;
}
.container-close-tab {
transform: scale(0.7);
visibility: collapse;
}
.container-info-tab-row:hover .container-close-tab {
opacity: 0.5;
visibility: visible;
}
.container-info-tab-row .container-close-tab:hover {
opacity: 1;
visibility: visible;
}
.container-info-has-tabs,
.container-info-tab-row {
align-items: center;
@@ -695,10 +763,6 @@ span ~ .panel-header-text {
margin-inline-end: 0;
}
.container-info-tab-row td {
max-inline-size: 200px;
}
.container-info-list {
display: flex;
flex-direction: column;
@@ -724,21 +788,24 @@ span ~ .panel-header-text {
background: var(--primary-action-color);
block-size: 100%;
color: #fff;
display: flex;
flex: 1;
display: inline-block;
justify-content: center;
padding-block-start: 6px;
padding-inline-start: 30%;
}
.exit-edit-mode-link::before {
background: url('/img/container-arrow.svg') no-repeat;
.edit-containers-panel-footer {
background: var(--primary-action-color);
}
.exit-edit-mode-link img {
block-size: 16px;
content: "";
display: block;
display: inline;
filter: grayscale(100%) brightness(5);
float: left;
inline-size: 16px;
margin-inline-end: 5px;
transform: scaleX(-1);
vertical-align: bottom;
}
.delete-container-confirm {
@@ -760,8 +827,12 @@ span ~ .panel-header-text {
padding-inline-start: 16px;
}
.edit-container-panel .columns {
overflow: hidden; /* Bugfix: issue 948 */
}
#edit-sites-assigned {
flex: 1;
flex: 1000; /* Bugfix: issue 948 */
}
#edit-sites-assigned h3 {
@@ -799,7 +870,7 @@ span ~ .panel-header-text {
align-items: center;
block-size: 29px;
display: flex;
flex: 0 0 calc(100% / 8);
flex: 0 0 calc(100% / var(--icon-fit));
}
.radio-choice > .radio-container > label {
@@ -887,3 +958,53 @@ span ~ .panel-header-text {
font-size: 14px !important;
padding-block-end: 6px;
}
/* Achievement panel elements */
.share-ctas {
padding-block-end: 0.5em;
padding-block-start: 0.5em;
padding-inline-end: 0.5em;
padding-inline-start: 0.5em;
text-align: center;
}
.cta-link {
text-decoration: none;
}
.cta {
color: #fff;
font-size: 0.7em;
font-weight: bold;
margin-block-end: 0.4em;
margin-block-start: 0.4em;
margin-inline-end: 0.4em;
margin-inline-start: 0.4em;
padding-block-end: 0.5em;
padding-block-start: 0.5em;
padding-inline-end: 0.5em;
padding-inline-start: 0.5em;
text-transform: uppercase;
}
.cta-icon {
height: 18px;
padding-right: 0.5em;
vertical-align: middle;
}
.fb-share-cta {
background: #375496;
}
.fb-share-cta .cta-icon {
margin-block-start: -5px;
}
.tweet-cta {
background: #37bae7;
}
.amo-rate-cta {
background: #0f1126;
}
+1
View File
@@ -0,0 +1 @@
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 220 160"><defs><style>.cls-1{fill:#6a57a5;}.cls-2{fill:#5a4a9e;}.cls-3{fill:#e7dfff;}</style></defs><title>account</title><path class="cls-1" d="M110,138.89A58.89,58.89,0,1,1,168.89,80,59,59,0,0,1,110,138.89Z"/><path class="cls-2" d="M110,130.27A50.27,50.27,0,1,1,160.27,80,50.33,50.33,0,0,1,110,130.27Z"/><circle class="cls-3" cx="110.39" cy="65.12" r="23.27" transform="translate(-12.01 27.1) rotate(-13.28)"/><path class="cls-3" d="M141.78,92.87c-8.2-9.46-19.58,3.28-31.39,3.28S87.2,83.41,79,92.87a7.83,7.83,0,0,0-.53,9.53,38.43,38.43,0,0,0,63.83,0A7.83,7.83,0,0,0,141.78,92.87Z"/></svg>

After

Width:  |  Height:  |  Size: 676 B

+1
View File
@@ -0,0 +1 @@
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 220 160"><defs><style>.cls-1{fill:#9f9fad;}.cls-2{fill:#5a4a9e;}.cls-3{fill:#6a57a5;}.cls-4{fill:#8f8f9d;}.cls-5{fill:none;stroke:#80808e;stroke-linecap:round;stroke-linejoin:round;stroke-width:1.6px;}.cls-6{fill:#231f20;opacity:0.4;}.cls-7{fill:#ee3389;}.cls-8{fill:#7661aa;}</style></defs><title>Sync</title><path class="cls-1" d="M119.16,122.69v4.81H19.76v-4.81l12.83-3.21h72.15Z"/><rect class="cls-1" x="24.57" y="55.35" width="89.79" height="67.34" rx="3"/><path class="cls-2" d="M79.08,65l-49.7,49.7a1.61,1.61,0,0,0,1.6,1.61h77a1.62,1.62,0,0,0,1.61-1.61V65Z"/><polygon class="cls-3" points="29.38 64.97 29.38 114.67 79.08 64.97 29.38 64.97"/><path class="cls-2" d="M107.94,60.16H31a1.6,1.6,0,0,0-1.6,1.6V65h80.17V61.76A1.61,1.61,0,0,0,107.94,60.16Z"/><path class="cls-4" d="M108.74,121.09H30.18a.81.81,0,0,1,0-1.61h78.56a.81.81,0,1,1,0,1.61Z"/><line class="cls-5" x1="63.61" y1="124.18" x2="74.83" y2="124.18"/><path class="cls-6" d="M114.35,127.35H102.2V71.64a5.53,5.53,0,0,1,5.52-5.53h6.63Z"/><path class="cls-1" d="M200.24,134.72v4.81h-99.4v-4.81l12.82-3.21h72.15Z"/><rect class="cls-1" x="105.65" y="67.38" width="89.79" height="67.34" rx="3"/><path class="cls-2" d="M160.16,77l-49.71,49.7a1.61,1.61,0,0,0,1.61,1.6h77a1.6,1.6,0,0,0,1.6-1.6V77Z"/><polygon class="cls-3" points="110.45 77 110.45 126.7 160.16 77 110.45 77"/><path class="cls-2" d="M189,72.19h-77a1.61,1.61,0,0,0-1.61,1.6V77h80.17V73.79A1.6,1.6,0,0,0,189,72.19Z"/><path class="cls-4" d="M189.82,133.11H111.26a.8.8,0,1,1,0-1.6h78.56a.8.8,0,0,1,0,1.6Z"/><line class="cls-5" x1="144.69" y1="136.2" x2="155.91" y2="136.2"/><path class="cls-7" d="M136.85,50l-3-.55a3,3,0,0,0-3.51,2.37l-.27,1.45c-1.59,8.36-9.86,14.42-19.66,14.42a21,21,0,0,1-15.93-6.89H103a3,3,0,0,0,3-3v-3a3,3,0,0,0-3-3H84.86a3,3,0,0,0-3,3V73.64a3,3,0,0,0,3,3h3a3,3,0,0,0,3-3V69.72a30.8,30.8,0,0,0,19.57,6.87c14.15,0,26.15-9.11,28.54-21.66l.27-1.45A2.94,2.94,0,0,0,136.85,50Z"/><path class="cls-8" d="M84.06,47l3,.54a3.41,3.41,0,0,0,.55,0,3,3,0,0,0,3-2.41l.27-1.45h0c1.59-8.36,9.86-14.42,19.65-14.42a21,21,0,0,1,15.94,6.89H117.9a3,3,0,0,0-3,3v3a3,3,0,0,0,3,3h18.15a3,3,0,0,0,3-3V23.43a3,3,0,0,0-3-3h-3a3,3,0,0,0-3,3v3.92a30.82,30.82,0,0,0-19.58-6.88c-14.14,0-26.14,9.11-28.53,21.67l-.27,1.45A3,3,0,0,0,84.06,47Z"/></svg>

After

Width:  |  Height:  |  Size: 2.3 KiB

+1
View File
@@ -0,0 +1 @@
<svg width="32px" height="33px" viewBox="0 0 32 33" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <!-- Generator: Sketch 46.2 (44496) - http://www.bohemiancoding.com/sketch --> <desc>Created with Sketch.</desc> <defs> <linearGradient x1="74.0423237%" y1="18.5882821%" x2="0%" y2="100%" id="linearGradient-1"> <stop stop-color="#00FEFF" offset="0%"/> <stop stop-color="#3D85FF" offset="100%"/> </linearGradient> </defs> <g id="Specs" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"> <g id="Header-Copy" transform="translate(-182.000000, -152.000000)" fill="url(#linearGradient-1)"> <path d="M205.58574,176.859518 L205.58574,169.287998 C205.58574,169.287998 205.800116,167.315137 207.086372,167.315137 C208.372629,167.315137 208.265441,169.394639 210.677171,169.394639 C211.909834,169.394639 214,168.754792 214,165.022352 C214,161.289912 211.909834,160.810027 210.677171,160.810027 C208.265441,160.810027 208.372629,162.782888 207.086372,162.782888 C205.800116,162.782888 205.58574,160.756707 205.58574,160.756707 L205.58574,157.664114 C205.58574,156.491061 204.621048,155.531291 203.44198,155.531291 L197.814608,155.531291 C197.814608,155.531291 195.992412,155.211368 195.992412,153.931674 C195.992412,152.65198 198.028985,152.545339 198.028985,150.145914 C198.028985,148.91954 197.332262,147 193.580682,147 C189.829101,147 189.293161,148.91954 189.293161,150.145914 C189.293161,152.545339 191.115357,152.65198 191.115357,153.931674 C191.115357,155.211368 189.293161,155.531291 189.293161,155.531291 L184.148135,155.531291 C182.969067,155.531291 182.004375,156.491061 182.004375,157.664114 L182.004375,161.823118 C182.004375,161.823118 181.789999,165.022352 184.362512,165.022352 C186.023926,165.022352 186.07752,162.836209 188.274874,162.836209 C189.346755,162.836209 190.418635,163.8493 190.418635,166.035443 C190.418635,168.274907 189.346755,169.394639 188.274874,169.394639 C186.131114,169.394639 186.023926,167.208496 184.362512,167.208496 C181.789999,167.208496 182.004375,170.301089 182.004375,170.301089 L182.004375,176.859518 C182.004375,178.032571 182.969067,178.992341 184.148135,178.992341 L191.115357,178.992341 C191.115357,178.992341 194.49178,179.205623 194.49178,176.646236 C194.49178,174.993299 192.348019,174.726696 192.348019,172.540552 C192.348019,171.474141 193.527088,170.141127 195.778036,170.141127 C198.028985,170.141127 199.315241,171.474141 199.315241,172.540552 C199.315241,174.673375 197.225074,174.993299 197.225074,176.646236 C197.225074,179.258944 200.601497,178.992341 200.601497,178.992341 L203.44198,178.992341 C204.621048,178.992341 205.58574,178.032571 205.58574,176.859518 Z" id="Shape-Copy-23" transform="translate(198.000000, 163.000000) rotate(-42.000000) translate(-198.000000, -163.000000) "/> </g> </g> </svg>

After

Width:  |  Height:  |  Size: 2.7 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 61 KiB

Before

Width:  |  Height:  |  Size: 307 B

After

Width:  |  Height:  |  Size: 307 B

+6
View File
@@ -0,0 +1,6 @@
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<path fill="#3c3c3c" d="M6 14a1 1 0 0 1-.707-.293l-3-3a1 1 0 0 1 1.414-1.414l2.157 2.157 6.316-9.023a1 1 0 0 1 1.639 1.146l-7 10a1 1 0 0 1-.732.427A.863.863 0 0 1 6 14z"/>
</svg>

After

Width:  |  Height:  |  Size: 477 B

Before

Width:  |  Height:  |  Size: 595 B

After

Width:  |  Height:  |  Size: 595 B

Before

Width:  |  Height:  |  Size: 520 B

After

Width:  |  Height:  |  Size: 520 B

+3
View File
@@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 7 7">
<polygon fill="#4c4c4c" points="5.8,0 3.5,2.4 1.2,0 0,1.2 2.4,3.5 0.1,5.8 1.2,7 3.5,4.7 5.8,7 7,5.8 4.7,3.5 7,1.2"/>
</svg>

After

Width:  |  Height:  |  Size: 183 B

Before

Width:  |  Height:  |  Size: 626 B

After

Width:  |  Height:  |  Size: 626 B

Before

Width:  |  Height:  |  Size: 603 B

After

Width:  |  Height:  |  Size: 603 B

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Before

Width:  |  Height:  |  Size: 883 B

After

Width:  |  Height:  |  Size: 883 B

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Before

Width:  |  Height:  |  Size: 342 B

After

Width:  |  Height:  |  Size: 342 B

Before

Width:  |  Height:  |  Size: 578 B

After

Width:  |  Height:  |  Size: 578 B

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

+1
View File
@@ -0,0 +1 @@
<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><g fill="rgba(249, 249, 250, 0.8)" fill-rule="evenodd"><rect height="6" rx="1" width="6" x="1" y="1"/><path d="m11 1h2v6h-2z" transform="matrix(0 1 -1 0 16 -8)"/><path d="m11 1h2v6h-2z"/><rect height="6" rx="1" width="6" x="1" y="9"/><rect height="6" rx="1" width="6" x="9" y="9"/></g></svg>

After

Width:  |  Height:  |  Size: 375 B

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Before

Width:  |  Height:  |  Size: 307 B

After

Width:  |  Height:  |  Size: 307 B

Before

Width:  |  Height:  |  Size: 534 B

After

Width:  |  Height:  |  Size: 534 B

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

+1
View File
@@ -0,0 +1 @@
<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><g fill="rgba(12, 12, 13, 0.8)" fill-rule="evenodd"><rect height="6" rx="1" width="6" x="1" y="1"/><path d="m11 1h2v6h-2z" transform="matrix(0 1 -1 0 16 -8)"/><path d="m11 1h2v6h-2z"/><rect height="6" rx="1" width="6" x="1" y="9"/><rect height="6" rx="1" width="6" x="9" y="9"/></g></svg>

After

Width:  |  Height:  |  Size: 372 B

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Before

Width:  |  Height:  |  Size: 755 B

After

Width:  |  Height:  |  Size: 755 B

Before

Width:  |  Height:  |  Size: 399 B

After

Width:  |  Height:  |  Size: 399 B

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

Before

Width:  |  Height:  |  Size: 7.3 KiB

After

Width:  |  Height:  |  Size: 7.3 KiB

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 48 KiB

Before

Width:  |  Height:  |  Size: 9.5 KiB

After

Width:  |  Height:  |  Size: 9.5 KiB

+14
View File
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Icon" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="-14 -14 48 48" enable-background="new -14 -14 48 48" xml:space="preserve">
<linearGradient id="SVGID_1_" gradientUnits="userSpaceOnUse" x1="90.0527" y1="-99.7603" x2="90.0527" y2="-106.3809" gradientTransform="matrix(7.2338 0 0 -7.2338 -641.4998 -735.5619)">
<stop offset="0" style="stop-color:#4B71B8"/>
<stop offset="1" style="stop-color:#293F7E"/>
</linearGradient>
<path fill="url(#SVGID_1_)" d="M33.931,27.993c0,3.304-2.689,5.983-6.002,5.983H-8.082c-3.315,0-6.001-2.683-6.001-5.983V-7.928
c0-3.308,2.687-5.988,6.001-5.988h36.011c3.312,0,6.002,2.681,6.002,5.988V27.993z"/>
<path fill="#FFFFFF" d="M25.613-4.557c0,0-3.707,0-6.166,0c-3.662,0-7.732,1.535-7.732,6.835c0.019,1.845,0,3.613,0,5.603H7.481
v6.728h4.366v19.37h8.021V14.48h5.295l0.479-6.618h-5.913c0,0,0.016-2.946,0-3.8c0-2.093,2.184-1.974,2.312-1.974
c1.042,0,3.059,0.003,3.578,0v-6.646H25.613z"/>
</svg>

After

Width:  |  Height:  |  Size: 1.1 KiB

+24
View File
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Icon" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 48 48" enable-background="new 0 0 48 48" xml:space="preserve">
<linearGradient id="SVGID_1_" gradientUnits="userSpaceOnUse" x1="23.9995" y1="0" x2="23.9995" y2="48.0005">
<stop offset="0" style="stop-color:#4BD0EF"/>
<stop offset="1" style="stop-color:#29AAE1"/>
</linearGradient>
<path fill-rule="evenodd" clip-rule="evenodd" fill="url(#SVGID_1_)" d="M48,42c0,3.313-2.687,6-6,6H6c-3.313,0-6-2.687-6-6V6
c0-3.313,2.687-6,6-6h36c3.313,0,6,2.687,6,6V42z"/>
<path fill="#29AAE1" d="M40.231,13.413c-1.12,0.497-2.323,0.833-3.588,0.984c1.291-0.774,2.28-1.998,2.747-3.457
c-1.206,0.716-2.543,1.236-3.968,1.516c-1.139-1.214-2.763-1.972-4.56-1.972c-3.449,0-6.246,2.796-6.246,6.247
c0,0.49,0.055,0.966,0.161,1.424c-5.192-0.261-9.795-2.749-12.876-6.528c-0.538,0.923-0.846,1.996-0.846,3.141
c0,2.167,1.103,4.08,2.779,5.199c-1.024-0.032-1.987-0.313-2.83-0.781c0,0.026,0,0.053,0,0.079c0,3.026,2.153,5.551,5.011,6.125
c-0.525,0.143-1.076,0.219-1.646,0.219c-0.403,0-0.794-0.038-1.176-0.11c0.795,2.48,3.102,4.287,5.835,4.338
c-2.138,1.675-4.832,2.675-7.758,2.675c-0.504,0-1.002-0.03-1.491-0.089c2.765,1.773,6.048,2.808,9.576,2.808
c11.49,0,17.774-9.519,17.774-17.774c0-0.271-0.006-0.54-0.019-0.809C38.334,15.766,39.394,14.666,40.231,13.413z"/>
<path fill="#FFFFFF" d="M40.231,14.739c-1.12,0.497-2.323,0.833-3.588,0.984c1.291-0.773,2.28-1.998,2.747-3.456
c-1.206,0.716-2.543,1.236-3.968,1.516c-1.139-1.214-2.763-1.972-4.56-1.972c-3.449,0-6.246,2.796-6.246,6.247
c0,0.489,0.055,0.966,0.161,1.424c-5.192-0.261-9.795-2.748-12.876-6.527c-0.538,0.923-0.846,1.996-0.846,3.141
c0,2.167,1.103,4.079,2.779,5.199c-1.024-0.032-1.987-0.313-2.83-0.781c0,0.026,0,0.052,0,0.079c0,3.027,2.153,5.551,5.011,6.125
c-0.525,0.144-1.076,0.219-1.646,0.219c-0.403,0-0.794-0.038-1.176-0.11c0.795,2.481,3.102,4.287,5.835,4.338
c-2.138,1.676-4.832,2.675-7.758,2.675c-0.504,0-1.002-0.03-1.491-0.089c2.765,1.773,6.048,2.808,9.576,2.808
c11.49,0,17.774-9.519,17.774-17.774c0-0.271-0.006-0.54-0.019-0.808C38.334,17.092,39.394,15.992,40.231,14.739z"/>
</svg>

After

Width:  |  Height:  |  Size: 2.3 KiB

+13
View File
@@ -0,0 +1,13 @@
module.exports = {
"extends": [
"../../.eslintrc.js"
],
"globals": {
"assignManager": true,
"badge": true,
"backgroundLogic": true,
"identityState": true,
"messageHandler": true,
"sync": true
}
};
+648
View File
@@ -0,0 +1,648 @@
window.assignManager = {
MENU_ASSIGN_ID: "open-in-this-container",
MENU_REMOVE_ID: "remove-open-in-this-container",
MENU_SEPARATOR_ID: "separator",
MENU_HIDE_ID: "hide-container",
MENU_MOVE_ID: "move-to-new-window-container",
OPEN_IN_CONTAINER: "open-bookmark-in-container-tab",
storageArea: {
area: browser.storage.local,
exemptedTabs: {},
getSiteStoreKey(pageUrlorUrlKey) {
if (pageUrlorUrlKey.includes("siteContainerMap@@_")) return pageUrlorUrlKey;
const url = new window.URL(pageUrlorUrlKey);
const storagePrefix = "siteContainerMap@@_";
if (url.port === "80" || url.port === "443") {
return `${storagePrefix}${url.hostname}`;
} else {
return `${storagePrefix}${url.hostname}${url.port}`;
}
},
setExempted(pageUrlorUrlKey, tabId) {
const siteStoreKey = this.getSiteStoreKey(pageUrlorUrlKey);
if (!(siteStoreKey in this.exemptedTabs)) {
this.exemptedTabs[siteStoreKey] = [];
}
this.exemptedTabs[siteStoreKey].push(tabId);
},
removeExempted(pageUrlorUrlKey) {
const siteStoreKey = this.getSiteStoreKey(pageUrlorUrlKey);
this.exemptedTabs[siteStoreKey] = [];
},
isExempted(pageUrlorUrlKey, tabId) {
const siteStoreKey = this.getSiteStoreKey(pageUrlorUrlKey);
if (!(siteStoreKey in this.exemptedTabs)) {
return false;
}
return this.exemptedTabs[siteStoreKey].includes(tabId);
},
get(pageUrlorUrlKey) {
const siteStoreKey = this.getSiteStoreKey(pageUrlorUrlKey);
return this.getByUrlKey(siteStoreKey);
},
async getSyncEnabled() {
const { syncEnabled } = await browser.storage.local.get("syncEnabled");
return !!syncEnabled;
},
getByUrlKey(siteStoreKey) {
return new Promise((resolve, reject) => {
this.area.get([siteStoreKey]).then((storageResponse) => {
if (storageResponse && siteStoreKey in storageResponse) {
resolve(storageResponse[siteStoreKey]);
}
resolve(null);
}).catch((e) => {
reject(e);
});
});
},
async set(pageUrlorUrlKey, data, exemptedTabIds, backup = true) {
const siteStoreKey = this.getSiteStoreKey(pageUrlorUrlKey);
if (exemptedTabIds) {
exemptedTabIds.forEach((tabId) => {
this.setExempted(pageUrlorUrlKey, tabId);
});
}
// eslint-disable-next-line require-atomic-updates
data.identityMacAddonUUID =
await identityState.lookupMACaddonUUID(data.userContextId);
await this.area.set({
[siteStoreKey]: data
});
const syncEnabled = await this.getSyncEnabled();
if (backup && syncEnabled) {
await sync.storageArea.backup({undeleteSiteStoreKey: siteStoreKey});
}
return;
},
async remove(pageUrlorUrlKey) {
const siteStoreKey = this.getSiteStoreKey(pageUrlorUrlKey);
// When we remove an assignment we should clear all the exemptions
this.removeExempted(pageUrlorUrlKey);
await this.area.remove([siteStoreKey]);
const syncEnabled = await this.getSyncEnabled();
if (syncEnabled) await sync.storageArea.backup({siteStoreKey});
return;
},
async deleteContainer(userContextId) {
const sitesByContainer = await this.getAssignedSites(userContextId);
this.area.remove(Object.keys(sitesByContainer));
},
async getAssignedSites(userContextId = null) {
const sites = {};
const siteConfigs = await this.area.get();
for(const urlKey of Object.keys(siteConfigs)) {
if (urlKey.includes("siteContainerMap@@_")) {
// For some reason this is stored as string... lets check
// them both as that
if (!!userContextId &&
String(siteConfigs[urlKey].userContextId)
!== String(userContextId)) {
continue;
}
const site = siteConfigs[urlKey];
// In hindsight we should have stored this
// TODO file a follow up to clean the storage onLoad
site.hostname = urlKey.replace(/^siteContainerMap@@_/, "");
sites[urlKey] = site;
}
}
return sites;
},
/*
* Looks for abandoned site assignments. If there is no identity with
* the site assignment's userContextId (cookieStoreId), then the assignment
* is removed.
*/
async upgradeData() {
const identitiesList = await browser.contextualIdentities.query({});
const macConfigs = await this.area.get();
for(const configKey of Object.keys(macConfigs)) {
if (configKey.includes("siteContainerMap@@_")) {
const cookieStoreId =
"firefox-container-" + macConfigs[configKey].userContextId;
const match = identitiesList.find(
localIdentity => localIdentity.cookieStoreId === cookieStoreId
);
if (!match) {
await this.remove(configKey);
continue;
}
const updatedSiteAssignment = macConfigs[configKey];
updatedSiteAssignment.identityMacAddonUUID =
await identityState.lookupMACaddonUUID(match.cookieStoreId);
await this.set(
configKey,
updatedSiteAssignment,
false,
false
);
}
}
}
},
_neverAsk(m) {
const pageUrl = m.pageUrl;
if (m.neverAsk === true) {
// If we have existing data and for some reason it hasn't been
// deleted etc lets update it
this.storageArea.get(pageUrl).then((siteSettings) => {
if (siteSettings) {
siteSettings.neverAsk = true;
this.storageArea.set(pageUrl, siteSettings);
}
}).catch((e) => {
throw e;
});
}
},
// We return here so the confirm page can load the tab when exempted
async _exemptTab(m) {
const pageUrl = m.pageUrl;
await this.storageArea.setExempted(pageUrl, m.tabId);
return true;
},
// Before a request is handled by the browser we decide if we should
// route through a different container
async onBeforeRequest(options) {
if (options.frameId !== 0 || options.tabId === -1) {
return {};
}
this.removeContextMenu();
const [tab, siteSettings] = await Promise.all([
browser.tabs.get(options.tabId),
this.storageArea.get(options.url)
]);
let container;
try {
container = await browser.contextualIdentities
.get(backgroundLogic.cookieStoreId(siteSettings.userContextId));
} catch (e) {
container = false;
}
// The container we have in the assignment map isn't present any
// more so lets remove it then continue the existing load
if (siteSettings && !container) {
this.deleteContainer(siteSettings.userContextId);
return {};
}
const userContextId = this.getUserContextIdFromCookieStore(tab);
if (!siteSettings
|| userContextId === siteSettings.userContextId
|| this.storageArea.isExempted(options.url, tab.id)) {
return {};
}
const removeTab = backgroundLogic.NEW_TAB_PAGES.has(tab.url)
|| (messageHandler.lastCreatedTab
&& messageHandler.lastCreatedTab.id === tab.id);
const openTabId = removeTab ? tab.openerTabId : tab.id;
if (!this.canceledRequests[tab.id]) {
// we decided to cancel the request at this point, register
// canceled request
this.canceledRequests[tab.id] = {
requestIds: {
[options.requestId]: true
},
urls: {
[options.url]: true
}
};
// since webRequest onCompleted and onErrorOccurred are not 100%
// reliable (see #1120)
// we register a timer here to cleanup canceled requests, just to
// make sure we don't
// end up in a situation where certain urls in a tab.id stay canceled
setTimeout(() => {
if (this.canceledRequests[tab.id]) {
delete this.canceledRequests[tab.id];
}
}, 2000);
} else {
let cancelEarly = false;
if (this.canceledRequests[tab.id].requestIds[options.requestId] ||
this.canceledRequests[tab.id].urls[options.url]) {
// same requestId or url from the same tab
// this is a redirect that we have to cancel early to prevent
// opening two tabs
cancelEarly = true;
}
// we decided to cancel the request at this point, register canceled
// request
this.canceledRequests[tab.id].requestIds[options.requestId] = true;
this.canceledRequests[tab.id].urls[options.url] = true;
if (cancelEarly) {
return {
cancel: true
};
}
}
this.reloadPageInContainer(
options.url,
userContextId,
siteSettings.userContextId,
tab.index + 1,
tab.active,
siteSettings.neverAsk,
openTabId
);
this.calculateContextMenu(tab);
/* Removal of existing tabs:
We aim to open the new assigned container tab / warning prompt in
it's own tab:
- As the history won't span from one container to another it
seems most sane to not try and reopen a tab on history.back()
- When users open a new tab themselves we want to make sure we
don't end up with three tabs as per:
https://github.com/mozilla/testpilot-containers/issues/421
If we are coming from an internal url that are used for the new
tab page (NEW_TAB_PAGES), we can safely close as user is unlikely
losing history
Detecting redirects on "new tab" opening actions is pretty hard
as we don't get tab history:
- Redirects happen from Short URLs and tracking links that act as
a gateway
- Extensions don't provide a way to history crawl for tabs, we
could inject content scripts to do this
however they don't run on about:blank so this would likely be
just as hacky.
We capture the time the tab was created and close if it was within
the timeout to try to capture pages which haven't had user
interaction or history.
*/
if (removeTab) {
browser.tabs.remove(tab.id);
}
return {
cancel: true,
};
},
init() {
browser.contextMenus.onClicked.addListener((info, tab) => {
info.bookmarkId ?
this._onClickedBookmark(info) :
this._onClickedHandler(info, tab);
});
// Before a request is handled by the browser we decide if we should
// route through a different container
this.canceledRequests = {};
browser.webRequest.onBeforeRequest.addListener((options) => {
return this.onBeforeRequest(options);
},{urls: ["<all_urls>"], types: ["main_frame"]}, ["blocking"]);
// Clean up canceled requests
browser.webRequest.onCompleted.addListener((options) => {
if (this.canceledRequests[options.tabId]) {
delete this.canceledRequests[options.tabId];
}
},{urls: ["<all_urls>"], types: ["main_frame"]});
browser.webRequest.onErrorOccurred.addListener((options) => {
if (this.canceledRequests[options.tabId]) {
delete this.canceledRequests[options.tabId];
}
},{urls: ["<all_urls>"], types: ["main_frame"]});
this.resetBookmarksMenuItem();
},
async resetBookmarksMenuItem() {
const hasPermission = await browser.permissions.contains({
permissions: ["bookmarks"]
});
if (this.hadBookmark === hasPermission) {
return;
}
this.hadBookmark = hasPermission;
if (hasPermission) {
this.initBookmarksMenu();
browser.contextualIdentities.onCreated
.addListener(this.contextualIdentityCreated);
browser.contextualIdentities.onUpdated
.addListener(this.contextualIdentityUpdated);
browser.contextualIdentities.onRemoved
.addListener(this.contextualIdentityRemoved);
} else {
this.removeBookmarksMenu();
browser.contextualIdentities.onCreated
.removeListener(this.contextualIdentityCreated);
browser.contextualIdentities.onUpdated
.removeListener(this.contextualIdentityUpdated);
browser.contextualIdentities.onRemoved
.removeListener(this.contextualIdentityRemoved);
}
},
contextualIdentityCreated(changeInfo) {
browser.contextMenus.create({
parentId: assignManager.OPEN_IN_CONTAINER,
id: changeInfo.contextualIdentity.cookieStoreId,
title: changeInfo.contextualIdentity.name,
icons: { "16": `img/usercontext.svg#${
changeInfo.contextualIdentity.icon
}` }
});
},
contextualIdentityUpdated(changeInfo) {
browser.contextMenus.update(
changeInfo.contextualIdentity.cookieStoreId, {
title: changeInfo.contextualIdentity.name,
icons: { "16": `img/usercontext.svg#${
changeInfo.contextualIdentity.icon}` }
});
},
contextualIdentityRemoved(changeInfo) {
browser.contextMenus.remove(
changeInfo.contextualIdentity.cookieStoreId
);
},
async _onClickedHandler(info, tab) {
const userContextId = this.getUserContextIdFromCookieStore(tab);
// Mapping ${URL(info.pageUrl).hostname} to ${userContextId}
let remove;
if (userContextId) {
switch (info.menuItemId) {
case this.MENU_ASSIGN_ID:
case this.MENU_REMOVE_ID:
if (info.menuItemId === this.MENU_ASSIGN_ID) {
remove = false;
} else {
remove = true;
}
await this._setOrRemoveAssignment(
tab.id, info.pageUrl, userContextId, remove
);
break;
case this.MENU_MOVE_ID:
backgroundLogic.moveTabsToWindow({
cookieStoreId: tab.cookieStoreId,
windowId: tab.windowId,
});
break;
case this.MENU_HIDE_ID:
backgroundLogic.hideTabs({
cookieStoreId: tab.cookieStoreId,
windowId: tab.windowId,
});
break;
}
}
},
async _onClickedBookmark(info) {
async function _getBookmarksFromInfo(info) {
const [bookmarkTreeNode] =
await browser.bookmarks.get(info.bookmarkId);
if (bookmarkTreeNode.type === "folder") {
return browser.bookmarks.getChildren(bookmarkTreeNode.id);
}
return [bookmarkTreeNode];
}
const bookmarks = await _getBookmarksFromInfo(info);
for (const bookmark of bookmarks) {
// Some checks on the urls from
// https://github.com/Rob--W/bookmark-container-tab/ thanks!
if ( !/^(javascript|place):/i.test(bookmark.url) &&
bookmark.type !== "folder") {
const openInReaderMode = bookmark.url.startsWith("about:reader");
if(openInReaderMode) {
try {
const parsed = new URL(bookmark.url);
bookmark.url = parsed.searchParams.get("url") + parsed.hash;
} catch (err) {
return err.message;
}
}
browser.tabs.create({
cookieStoreId: info.menuItemId,
url: bookmark.url,
openInReaderMode: openInReaderMode
});
}
}
},
deleteContainer(userContextId) {
this.storageArea.deleteContainer(userContextId);
},
getUserContextIdFromCookieStore(tab) {
if (!("cookieStoreId" in tab)) {
return false;
}
return backgroundLogic.getUserContextIdFromCookieStoreId(
tab.cookieStoreId
);
},
isTabPermittedAssign(tab) {
// Ensure we are not an important about url
const url = new URL(tab.url);
if (url.protocol === "about:"
|| url.protocol === "moz-extension:") {
return false;
}
return true;
},
async _setOrRemoveAssignment(tabId, pageUrl, userContextId, remove) {
let actionName;
// https://github.com/mozilla/testpilot-containers/issues/626
// Context menu has stored context IDs as strings, so we need to coerce
// the value to a string for accurate checking
userContextId = String(userContextId);
if (!remove) {
const tabs = await browser.tabs.query({});
const assignmentStoreKey = this.storageArea.getSiteStoreKey(pageUrl);
const exemptedTabIds = tabs.filter((tab) => {
const tabStoreKey = this.storageArea.getSiteStoreKey(tab.url);
/* Auto exempt all tabs that exist for this hostname that are not in the same container */
if (tabStoreKey === assignmentStoreKey &&
this.getUserContextIdFromCookieStore(tab) !== userContextId) {
return true;
}
return false;
}).map((tab) => {
return tab.id;
});
await this.storageArea.set(pageUrl, {
userContextId,
neverAsk: false
}, exemptedTabIds);
actionName = "added";
} else {
await this.storageArea.remove(pageUrl);
actionName = "removed";
}
browser.tabs.sendMessage(tabId, {
text: `Successfully ${actionName} site to always open in this container`
});
const tab = await browser.tabs.get(tabId);
this.calculateContextMenu(tab);
},
async _getAssignment(tab) {
const cookieStore = this.getUserContextIdFromCookieStore(tab);
// Ensure we have a cookieStore to assign to
if (cookieStore
&& this.isTabPermittedAssign(tab)) {
return this.storageArea.get(tab.url);
}
return false;
},
_getByContainer(userContextId) {
return this.storageArea.getAssignedSites(userContextId);
},
removeContextMenu() {
// There is a focus issue in this menu where if you change window with a context menu click
// you get the wrong menu display because of async
// See: https://bugzilla.mozilla.org/show_bug.cgi?id=1215376#c16
// We also can't change for always private mode
// See: https://bugzilla.mozilla.org/show_bug.cgi?id=1352102
browser.contextMenus.remove(this.MENU_ASSIGN_ID);
browser.contextMenus.remove(this.MENU_REMOVE_ID);
browser.contextMenus.remove(this.MENU_SEPARATOR_ID);
browser.contextMenus.remove(this.MENU_HIDE_ID);
browser.contextMenus.remove(this.MENU_MOVE_ID);
},
async calculateContextMenu(tab) {
this.removeContextMenu();
const siteSettings = await this._getAssignment(tab);
// Return early and not add an item if we have false
// False represents assignment is not permitted
if (siteSettings === false) {
return false;
}
let checked = false;
let menuId = this.MENU_ASSIGN_ID;
const tabUserContextId = this.getUserContextIdFromCookieStore(tab);
if (siteSettings &&
Number(siteSettings.userContextId) === Number(tabUserContextId)) {
checked = true;
menuId = this.MENU_REMOVE_ID;
}
browser.contextMenus.create({
id: menuId,
title: "Always Open in This Container",
checked,
type: "checkbox",
contexts: ["all"],
});
browser.contextMenus.create({
id: this.MENU_SEPARATOR_ID,
type: "separator",
contexts: ["all"],
});
browser.contextMenus.create({
id: this.MENU_HIDE_ID,
title: "Hide This Container",
contexts: ["all"],
});
browser.contextMenus.create({
id: this.MENU_MOVE_ID,
title: "Move Tabs to a New Window",
contexts: ["all"],
});
},
encodeURLProperty(url) {
return encodeURIComponent(url).replace(/[!'()*]/g, (c) => {
const charCode = c.charCodeAt(0).toString(16);
return `%${charCode}`;
});
},
reloadPageInContainer(url, currentUserContextId, userContextId, index, active, neverAsk = false, openerTabId = null) {
const cookieStoreId = backgroundLogic.cookieStoreId(userContextId);
const loadPage = browser.extension.getURL("confirm-page.html");
// False represents assignment is not permitted
// If the user has explicitly checked "Never Ask Again" on the warning page we will send them straight there
if (neverAsk) {
browser.tabs.create({url, cookieStoreId, index, active, openerTabId});
} else {
let confirmUrl = `${loadPage}?url=${this.encodeURLProperty(url)}&cookieStoreId=${cookieStoreId}`;
let currentCookieStoreId;
if (currentUserContextId) {
currentCookieStoreId = backgroundLogic.cookieStoreId(currentUserContextId);
confirmUrl += `&currentCookieStoreId=${currentCookieStoreId}`;
}
browser.tabs.create({
url: confirmUrl,
cookieStoreId: currentCookieStoreId,
openerTabId,
index,
active
}).then(() => {
// We don't want to sync this URL ever nor clutter the users history
browser.history.deleteUrl({url: confirmUrl});
}).catch((e) => {
throw e;
});
}
},
async initBookmarksMenu() {
browser.contextMenus.create({
id: this.OPEN_IN_CONTAINER,
title: "Open Bookmark in Container Tab",
contexts: ["bookmark"],
});
const identities = await browser.contextualIdentities.query({});
for (const identity of identities) {
browser.contextMenus.create({
parentId: this.OPEN_IN_CONTAINER,
id: identity.cookieStoreId,
title: identity.name,
icons: { "16": `img/usercontext.svg#${identity.icon}` }
});
}
},
async removeBookmarksMenu() {
browser.contextMenus.remove(this.OPEN_IN_CONTAINER);
const identities = await browser.contextualIdentities.query({});
for (const identity of identities) {
browser.contextMenus.remove(identity.cookieStoreId);
}
},
};
assignManager.init();
+334
View File
@@ -0,0 +1,334 @@
const DEFAULT_TAB = "about:newtab";
const backgroundLogic = {
NEW_TAB_PAGES: new Set([
"about:startpage",
"about:newtab",
"about:home",
"about:blank"
]),
unhideQueue: [],
async getExtensionInfo() {
const manifestPath = browser.extension.getURL("manifest.json");
const response = await fetch(manifestPath);
const extensionInfo = await response.json();
return extensionInfo;
},
getUserContextIdFromCookieStoreId(cookieStoreId) {
if (!cookieStoreId) {
return false;
}
const container = cookieStoreId.replace("firefox-container-", "");
if (container !== cookieStoreId) {
return container;
}
return false;
},
async deleteContainer(userContextId, removed = false) {
await this._closeTabs(userContextId);
if (!removed) {
await browser.contextualIdentities.remove(this.cookieStoreId(userContextId));
}
assignManager.deleteContainer(userContextId);
return {done: true, userContextId};
},
async createOrUpdateContainer(options) {
let donePromise;
if (options.userContextId !== "new") {
donePromise = browser.contextualIdentities.update(
this.cookieStoreId(options.userContextId),
options.params
);
} else {
donePromise = browser.contextualIdentities.create(options.params);
}
await donePromise;
},
async openNewTab(options) {
let url = options.url || undefined;
const userContextId = ("userContextId" in options) ? options.userContextId : 0;
const active = ("nofocus" in options) ? options.nofocus : true;
const discarded = ("noload" in options) ? options.noload : false;
const cookieStoreId = backgroundLogic.cookieStoreId(userContextId);
// Autofocus url bar will happen in 54: https://bugzilla.mozilla.org/show_bug.cgi?id=1295072
// We can't open new tab pages, so open a blank tab. Used in tab un-hide
if (this.NEW_TAB_PAGES.has(url)) {
url = undefined;
}
if (!this.isPermissibleURL(url)) {
return;
}
return browser.tabs.create({
url,
active,
discarded,
pinned: options.pinned || false,
cookieStoreId
});
},
isPermissibleURL(url) {
const protocol = new URL(url).protocol;
// We can't open these we just have to throw them away
if (protocol === "about:"
|| protocol === "chrome:"
|| protocol === "moz-extension:") {
return false;
}
return true;
},
checkArgs(requiredArguments, options, methodName) {
requiredArguments.forEach((argument) => {
if (!(argument in options)) {
return new Error(`${methodName} must be called with ${argument} argument.`);
}
});
},
async getTabs(options) {
const requiredArguments = ["cookieStoreId", "windowId"];
this.checkArgs(requiredArguments, options, "getTabs");
const { cookieStoreId, windowId } = options;
const list = [];
const tabs = await browser.tabs.query({
cookieStoreId,
windowId
});
tabs.forEach((tab) => {
list.push(identityState._createTabObject(tab));
});
const containerState = await identityState.storageArea.get(cookieStoreId);
return list.concat(containerState.hiddenTabs);
},
async unhideContainer(cookieStoreId, alreadyShowingUrl) {
if (!this.unhideQueue.includes(cookieStoreId)) {
this.unhideQueue.push(cookieStoreId);
await this.showTabs({
cookieStoreId,
alreadyShowingUrl
});
this.unhideQueue.splice(this.unhideQueue.indexOf(cookieStoreId), 1);
}
},
async moveTabsToWindow(options) {
const requiredArguments = ["cookieStoreId", "windowId"];
this.checkArgs(requiredArguments, options, "moveTabsToWindow");
const { cookieStoreId, windowId } = options;
const list = await browser.tabs.query({
cookieStoreId,
windowId
});
const containerState = await identityState.storageArea.get(cookieStoreId);
// Nothing to do
if (list.length === 0 &&
containerState.hiddenTabs.length === 0) {
return;
}
let newWindowObj;
let hiddenDefaultTabToClose;
if (list.length) {
newWindowObj = await browser.windows.create();
// Pin the default tab in the new window so existing pinned tabs can be moved after it.
// From the docs (https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/tabs/move):
// Note that you can't move pinned tabs to a position after any unpinned tabs in a window, or move any unpinned tabs to a position before any pinned tabs.
await browser.tabs.update(newWindowObj.tabs[0].id, { pinned: true });
browser.tabs.move(list.map((tab) => tab.id), {
windowId: newWindowObj.id,
index: -1
});
} else {
//As we get a blank tab here we will need to await the tabs creation
newWindowObj = await browser.windows.create({
});
hiddenDefaultTabToClose = true;
}
const showHiddenPromises = [];
// Let's show the hidden tabs.
if (!this.unhideQueue.includes(cookieStoreId)) {
this.unhideQueue.push(cookieStoreId);
for (let object of containerState.hiddenTabs) { // eslint-disable-line prefer-const
showHiddenPromises.push(browser.tabs.create({
url: object.url || DEFAULT_TAB,
windowId: newWindowObj.id,
cookieStoreId
}));
}
}
if (hiddenDefaultTabToClose) {
// Lets wait for hidden tabs to show before closing the others
await showHiddenPromises;
}
containerState.hiddenTabs = [];
// Let's close all the normal tab in the new window. In theory it
// should be only the first tab, but maybe there are addons doing
// crazy stuff.
const tabs = await browser.tabs.query({windowId: newWindowObj.id});
for (let tab of tabs) { // eslint-disable-line prefer-const
if (tab.cookieStoreId !== cookieStoreId) {
browser.tabs.remove(tab.id);
}
}
const rv = await identityState.storageArea.set(cookieStoreId, containerState);
this.unhideQueue.splice(this.unhideQueue.indexOf(cookieStoreId), 1);
return rv;
},
async _closeTabs(userContextId, windowId = false) {
const cookieStoreId = this.cookieStoreId(userContextId);
let tabs;
/* if we have no windowId we are going to close all this container (used for deleting) */
if (windowId !== false) {
tabs = await browser.tabs.query({
cookieStoreId,
windowId
});
} else {
tabs = await browser.tabs.query({
cookieStoreId
});
}
const tabIds = tabs.map((tab) => tab.id);
return browser.tabs.remove(tabIds);
},
async queryIdentitiesState(windowId) {
const identities = await browser.contextualIdentities.query({});
const identitiesOutput = {};
const identitiesPromise = identities.map(async (identity) => {
const { cookieStoreId } = identity;
const containerState = await identityState.storageArea.get(cookieStoreId);
const openTabs = await browser.tabs.query({
cookieStoreId,
windowId
});
identitiesOutput[cookieStoreId] = {
hasHiddenTabs: !!containerState.hiddenTabs.length,
hasOpenTabs: !!openTabs.length,
numberOfHiddenTabs: containerState.hiddenTabs.length,
numberOfOpenTabs: openTabs.length
};
return;
});
await Promise.all(identitiesPromise);
return identitiesOutput;
},
async sortTabs() {
const windows = await browser.windows.getAll();
for (let windowObj of windows) { // eslint-disable-line prefer-const
// First the pinned tabs, then the normal ones.
await this._sortTabsInternal(windowObj, true);
await this._sortTabsInternal(windowObj, false);
}
},
async _sortTabsInternal(windowObj, pinnedTabs) {
const tabs = await browser.tabs.query({windowId: windowObj.id});
let pos = 0;
// Let's collect UCIs/tabs for this window.
const map = new Map;
for (const tab of tabs) {
if (pinnedTabs && !tab.pinned) {
// We don't have, or we already handled all the pinned tabs.
break;
}
if (!pinnedTabs && tab.pinned) {
// pinned tabs must be consider as taken positions.
++pos;
continue;
}
const userContextId = backgroundLogic.getUserContextIdFromCookieStoreId(tab.cookieStoreId);
if (!map.has(userContextId)) {
map.set(userContextId, []);
}
map.get(userContextId).push(tab);
}
// Let's sort the map.
const sortMap = new Map([...map.entries()].sort((a, b) => a[0] > b[0]));
// Let's move tabs.
sortMap.forEach(tabs => {
for (const tab of tabs) {
++pos;
browser.tabs.move(tab.id, {
windowId: windowObj.id,
index: pos
});
}
});
},
async hideTabs(options) {
const requiredArguments = ["cookieStoreId", "windowId"];
this.checkArgs(requiredArguments, options, "hideTabs");
const { cookieStoreId, windowId } = options;
const userContextId = backgroundLogic.getUserContextIdFromCookieStoreId(cookieStoreId);
const containerState = await identityState.storeHidden(cookieStoreId, windowId);
await this._closeTabs(userContextId, windowId);
return containerState;
},
async showTabs(options) {
if (!("cookieStoreId" in options)) {
return Promise.reject("showTabs must be called with cookieStoreId argument.");
}
const userContextId = backgroundLogic.getUserContextIdFromCookieStoreId(options.cookieStoreId);
const promises = [];
const containerState = await identityState.storageArea.get(options.cookieStoreId);
for (let object of containerState.hiddenTabs) { // eslint-disable-line prefer-const
// do not show already opened url
const noload = !object.pinned;
if (object.url !== options.alreadyShowingUrl) {
promises.push(this.openNewTab({
userContextId: userContextId,
url: object.url,
nofocus: options.nofocus || false,
noload: noload,
pinned: object.pinned,
}));
}
}
containerState.hiddenTabs = [];
await Promise.all(promises);
return identityState.storageArea.set(options.cookieStoreId, containerState);
},
cookieStoreId(userContextId) {
return `firefox-container-${userContextId}`;
}
};
+20
View File
@@ -0,0 +1,20 @@
const MAJOR_VERSIONS = ["2.3.0", "2.4.0", "6.2.0"];
const badge = {
async init() {
const currentWindow = await browser.windows.getCurrent();
this.displayBrowserActionBadge(currentWindow);
},
async displayBrowserActionBadge() {
const extensionInfo = await backgroundLogic.getExtensionInfo();
const storage = await browser.storage.local.get({ browserActionBadgesClicked: [] });
if (MAJOR_VERSIONS.indexOf(extensionInfo.version) > -1 &&
storage.browserActionBadgesClicked.indexOf(extensionInfo.version) < 0) {
browser.browserAction.setBadgeBackgroundColor({ color: "rgba(0,217,0,255)" });
browser.browserAction.setBadgeText({ text: "NEW" });
}
}
};
badge.init();
+163
View File
@@ -0,0 +1,163 @@
window.identityState = {
storageArea: {
area: browser.storage.local,
getContainerStoreKey(cookieStoreId) {
const storagePrefix = "identitiesState@@_";
return `${storagePrefix}${cookieStoreId}`;
},
async get(cookieStoreId) {
const storeKey = this.getContainerStoreKey(cookieStoreId);
const storageResponse = await this.area.get([storeKey]);
if (storageResponse && storeKey in storageResponse) {
if (!storageResponse[storeKey].macAddonUUID){
storageResponse[storeKey].macAddonUUID = uuidv4();
await this.set(cookieStoreId, storageResponse[storeKey]);
}
return storageResponse[storeKey];
}
// If local storage doesn't have an entry, look it up to make sure it's
// an in-use identity.
const identities = await browser.contextualIdentities.query({});
const match = identities.find(
(identity) => identity.cookieStoreId === cookieStoreId);
if (match) {
const defaultContainerState = identityState._createIdentityState();
await this.set(cookieStoreId, defaultContainerState);
return defaultContainerState;
}
throw new Error (`${cookieStoreId} not found`);
},
set(cookieStoreId, data) {
const storeKey = this.getContainerStoreKey(cookieStoreId);
return this.area.set({
[storeKey]: data
});
},
async remove(cookieStoreId) {
const storeKey = this.getContainerStoreKey(cookieStoreId);
return this.area.remove([storeKey]);
},
/*
* Looks for abandoned identity keys in local storage, and makes sure all
* identities registered in the browser are also in local storage. (this
* appears to not always be the case based on how this.get() is written)
*/
async upgradeData() {
const identitiesList = await browser.contextualIdentities.query({});
for (const identity of identitiesList) {
// ensure all identities have an entry in local storage
await identityState.addUUID(identity.cookieStoreId);
}
const macConfigs = await this.area.get();
for(const configKey of Object.keys(macConfigs)) {
if (configKey.includes("identitiesState@@_")) {
const cookieStoreId = String(configKey).replace(/^identitiesState@@_/, "");
const match = identitiesList.find(
localIdentity => localIdentity.cookieStoreId === cookieStoreId
);
if (cookieStoreId === "firefox-default") continue;
if (!match) {
await this.remove(cookieStoreId);
continue;
}
if (!macConfigs[configKey].macAddonUUID) {
await identityState.storageArea.get(cookieStoreId);
}
}
}
}
},
_createTabObject(tab) {
return Object.assign({}, tab);
},
async getCookieStoreIDuuidMap() {
const containers = {};
const identities = await browser.contextualIdentities.query({});
for(const identity of identities) {
const containerInfo = await this.storageArea.get(identity.cookieStoreId);
containers[identity.cookieStoreId] = containerInfo.macAddonUUID;
}
return containers;
},
async storeHidden(cookieStoreId, windowId) {
const containerState = await this.storageArea.get(cookieStoreId);
const tabsByContainer = await browser.tabs.query({cookieStoreId, windowId});
tabsByContainer.forEach((tab) => {
const tabObject = this._createTabObject(tab);
if (!backgroundLogic.isPermissibleURL(tab.url)) {
return;
}
// This tab is going to be closed. Let's mark this tabObject as
// non-active.
tabObject.active = false;
tabObject.hiddenState = true;
containerState.hiddenTabs.push(tabObject);
});
return this.storageArea.set(cookieStoreId, containerState);
},
async updateUUID(cookieStoreId, uuid) {
if (!cookieStoreId || !uuid) {
throw new Error ("cookieStoreId or uuid missing");
}
const containerState = await this.storageArea.get(cookieStoreId);
containerState.macAddonUUID = uuid;
await this.storageArea.set(cookieStoreId, containerState);
return uuid;
},
async addUUID(cookieStoreId) {
await this.storageArea.get(cookieStoreId);
},
async lookupMACaddonUUID(cookieStoreId) {
// This stays a lookup, because if the cookieStoreId doesn't
// exist, this.get() will create it, which is not what we want.
const cookieStoreIdKey = cookieStoreId.includes("firefox-container-") ?
cookieStoreId : "firefox-container-" + cookieStoreId;
const macConfigs = await this.storageArea.area.get();
for(const configKey of Object.keys(macConfigs)) {
if (configKey === this.storageArea.getContainerStoreKey(cookieStoreIdKey)) {
return macConfigs[configKey].macAddonUUID;
}
}
return false;
},
async lookupCookieStoreId(macAddonUUID) {
const macConfigs = await this.storageArea.area.get();
for(const configKey of Object.keys(macConfigs)) {
if (configKey.includes("identitiesState@@_")) {
if(macConfigs[configKey].macAddonUUID === macAddonUUID) {
return String(configKey).replace(/^identitiesState@@_/, "");
}
}
}
return false;
},
_createIdentityState() {
return {
hiddenTabs: [],
macAddonUUID: uuidv4()
};
},
};
function uuidv4() {
// https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
);
}
+23
View File
@@ -0,0 +1,23 @@
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<!--
This didn't work for debugging in the manifest.
"scripts": [
"js/background/backgroundLogic.js",
"js/background/assignManager.js",
"js/background/badge.js",
"js/background/identityState.js",
"js/background/messageHandler.js",
]
-->
<script type="text/javascript" src="backgroundLogic.js"></script>
<script type="text/javascript" src="assignManager.js"></script>
<script type="text/javascript" src="badge.js"></script>
<script type="text/javascript" src="identityState.js"></script>
<script type="text/javascript" src="messageHandler.js"></script>
<script type="text/javascript" src="sync.js"></script>
</body>
</html>
+223
View File
@@ -0,0 +1,223 @@
const messageHandler = {
// After the timer completes we assume it's a tab the user meant to keep open
// We use this to catch redirected tabs that have just opened
// If this were in platform we would change how the tab opens based on "new tab" link navigations such as ctrl+click
LAST_CREATED_TAB_TIMER: 2000,
init() {
// Handles messages from webextension code
browser.runtime.onMessage.addListener((m) => {
let response;
switch (m.method) {
case "resetSync":
response = sync.resetSync();
break;
case "resetBookmarksContext":
response = assignManager.resetBookmarksMenuItem();
break;
case "deleteContainer":
response = backgroundLogic.deleteContainer(m.message.userContextId);
break;
case "createOrUpdateContainer":
response = backgroundLogic.createOrUpdateContainer(m.message);
break;
case "neverAsk":
assignManager._neverAsk(m);
break;
case "getAssignment":
response = browser.tabs.get(m.tabId).then((tab) => {
return assignManager._getAssignment(tab);
});
break;
case "getAssignmentObjectByContainer":
response = assignManager._getByContainer(m.message.userContextId);
break;
case "setOrRemoveAssignment":
// m.tabId is used for where to place the in content message
// m.url is the assignment to be removed/added
response = browser.tabs.get(m.tabId).then((tab) => {
return assignManager._setOrRemoveAssignment(tab.id, m.url, m.userContextId, m.value);
});
break;
case "sortTabs":
backgroundLogic.sortTabs();
break;
case "showTabs":
backgroundLogic.unhideContainer(m.cookieStoreId);
break;
case "hideTabs":
backgroundLogic.hideTabs({
cookieStoreId: m.cookieStoreId,
windowId: m.windowId
});
break;
case "checkIncompatibleAddons":
// TODO
break;
case "moveTabsToWindow":
response = backgroundLogic.moveTabsToWindow({
cookieStoreId: m.cookieStoreId,
windowId: m.windowId
});
break;
case "getTabs":
response = backgroundLogic.getTabs({
cookieStoreId: m.cookieStoreId,
windowId: m.windowId
});
break;
case "queryIdentitiesState":
response = backgroundLogic.queryIdentitiesState(m.message.windowId);
break;
case "exemptContainerAssignment":
response = assignManager._exemptTab(m);
break;
}
return response;
});
// Handles external messages from webextensions
const externalExtensionAllowed = {};
browser.runtime.onMessageExternal.addListener(async (message, sender) => {
if (!externalExtensionAllowed[sender.id]) {
const extensionInfo = await browser.management.get(sender.id);
if (!extensionInfo.permissions.includes("contextualIdentities")) {
throw new Error("Missing contextualIdentities permission");
}
// eslint-disable-next-line require-atomic-updates
externalExtensionAllowed[sender.id] = true;
}
let response;
switch (message.method) {
case "getAssignment":
if (typeof message.url === "undefined") {
throw new Error("Missing message.url");
}
response = assignManager.storageArea.get(message.url);
break;
default:
throw new Error("Unknown message.method");
}
return response;
});
// Delete externalExtensionAllowed if add-on installs/updates; permissions might change
browser.management.onInstalled.addListener(extensionInfo => {
if (externalExtensionAllowed[extensionInfo.id]) {
delete externalExtensionAllowed[extensionInfo.id];
}
});
// Delete externalExtensionAllowed if add-on uninstalls; not needed anymore
browser.management.onUninstalled.addListener(extensionInfo => {
if (externalExtensionAllowed[extensionInfo.id]) {
delete externalExtensionAllowed[extensionInfo.id];
}
});
if (browser.contextualIdentities.onRemoved) {
browser.contextualIdentities.onRemoved.addListener(({contextualIdentity}) => {
const userContextId = backgroundLogic.getUserContextIdFromCookieStoreId(contextualIdentity.cookieStoreId);
backgroundLogic.deleteContainer(userContextId, true);
});
}
browser.tabs.onActivated.addListener((info) => {
assignManager.removeContextMenu();
browser.tabs.get(info.tabId).then((tab) => {
assignManager.calculateContextMenu(tab);
}).catch((e) => {
throw e;
});
});
browser.windows.onFocusChanged.addListener((windowId) => {
this.onFocusChangedCallback(windowId);
});
browser.webRequest.onCompleted.addListener((details) => {
if (details.frameId !== 0 || details.tabId === -1) {
return {};
}
assignManager.removeContextMenu();
browser.tabs.get(details.tabId).then((tab) => {
assignManager.calculateContextMenu(tab);
}).catch((e) => {
throw e;
});
}, {urls: ["<all_urls>"], types: ["main_frame"]});
browser.tabs.onCreated.addListener((tab) => {
// lets remember the last tab created so we can close it if it looks like a redirect
this.lastCreatedTab = tab;
if (tab.cookieStoreId) {
// Don't count firefox-default, firefox-private, nor our own confirm page loads
if (tab.cookieStoreId !== "firefox-default" &&
tab.cookieStoreId !== "firefox-private" &&
!tab.url.startsWith("moz-extension")) {
// increment the counter of container tabs opened
this.incrementCountOfContainerTabsOpened();
this.tabUpdateHandler = (tabId, changeInfo) => {
if (tabId === tab.id && changeInfo.status === "complete") {
// get current tab's url to not open the same one from hidden tabs
browser.tabs.get(tabId).then(loadedTab => {
backgroundLogic.unhideContainer(tab.cookieStoreId, loadedTab.url);
}).catch((e) => {
throw e;
});
browser.tabs.onUpdated.removeListener(this.tabUpdateHandler);
}
};
// if it's a container tab wait for it to complete and
// unhide other tabs from this container
if (tab.cookieStoreId.startsWith("firefox-container")) {
browser.tabs.onUpdated.addListener(this.tabUpdateHandler);
}
}
}
setTimeout(() => {
this.lastCreatedTab = null;
}, this.LAST_CREATED_TAB_TIMER);
});
},
async incrementCountOfContainerTabsOpened() {
const key = "containerTabsOpened";
const count = await browser.storage.local.get({[key]: 0});
const countOfContainerTabsOpened = ++count[key];
browser.storage.local.set({[key]: countOfContainerTabsOpened});
// When the user opens their _ tab, give them the achievement
if (countOfContainerTabsOpened === 100) {
const storage = await browser.storage.local.get({achievements: []});
storage.achievements.push({"name": "manyContainersOpened", "done": false});
// use set and spread to create a unique array
const achievements = [...new Set(storage.achievements)];
browser.storage.local.set({achievements});
browser.browserAction.setBadgeBackgroundColor({color: "rgba(0,217,0,255)"});
browser.browserAction.setBadgeText({text: "NEW"});
}
},
async onFocusChangedCallback(windowId) {
assignManager.removeContextMenu();
// browserAction loses background color in new windows ...
// https://bugzil.la/1314674
// https://github.com/mozilla/testpilot-containers/issues/608
// ... so re-call displayBrowserActionBadge on window changes
badge.displayBrowserActionBadge();
browser.tabs.query({active: true, windowId}).then((tabs) => {
if (tabs && tabs[0]) {
assignManager.calculateContextMenu(tabs[0]);
}
}).catch((e) => {
throw e;
});
}
};
// Lets do this last as theme manager did a check before connecting before
messageHandler.init();
+580
View File
@@ -0,0 +1,580 @@
const SYNC_DEBUG = false;
const sync = {
storageArea: {
area: browser.storage.sync,
async get(){
return this.area.get();
},
async set(options) {
return this.area.set(options);
},
async deleteIdentity(deletedIdentityUUID) {
const deletedIdentityList =
await sync.storageArea.getDeletedIdentityList();
if (
! deletedIdentityList.find(element => element === deletedIdentityUUID)
) {
deletedIdentityList.push(deletedIdentityUUID);
await sync.storageArea.set({ deletedIdentityList });
}
await this.removeIdentityKeyFromSync(deletedIdentityUUID);
},
async removeIdentityKeyFromSync(deletedIdentityUUID) {
await sync.storageArea.area.remove( "identity@@_" + deletedIdentityUUID);
},
async deleteSite(siteStoreKey) {
const deletedSiteList =
await sync.storageArea.getDeletedSiteList();
if (deletedSiteList.find(element => element === siteStoreKey)) return;
deletedSiteList.push(siteStoreKey);
await sync.storageArea.set({ deletedSiteList });
await sync.storageArea.area.remove(siteStoreKey);
},
async getDeletedIdentityList() {
const storedArray = await this.getStoredItem("deletedIdentityList");
return storedArray || [];
},
async getIdentities() {
const allSyncStorage = await this.get();
const identities = [];
for (const storageKey of Object.keys(allSyncStorage)) {
if (storageKey.includes("identity@@_")) {
identities.push(allSyncStorage[storageKey]);
}
}
return identities;
},
async getDeletedSiteList() {
const storedArray = await this.getStoredItem("deletedSiteList");
return (storedArray) ? storedArray : [];
},
async getAssignedSites() {
const allSyncStorage = await this.get();
const sites = {};
for (const storageKey of Object.keys(allSyncStorage)) {
if (storageKey.includes("siteContainerMap@@_")) {
sites[storageKey] = allSyncStorage[storageKey];
}
}
return sites;
},
async getStoredItem(objectKey) {
const outputObject = await this.get(objectKey);
if (outputObject && outputObject[objectKey])
return outputObject[objectKey];
return false;
},
async getAllInstanceInfo() {
const instanceList = {};
const allSyncInfo = await this.get();
for (const objectKey of Object.keys(allSyncInfo)) {
if (objectKey.includes("MACinstance")) {
instanceList[objectKey] = allSyncInfo[objectKey]; }
}
return instanceList;
},
getInstanceKey() {
return browser.runtime.getURL("")
.replace(/moz-extension:\/\//, "MACinstance:")
.replace(/\//, "");
},
async removeInstance(installUUID) {
if (SYNC_DEBUG) console.log("removing", installUUID);
await this.area.remove(installUUID);
return;
},
async removeThisInstanceFromSync() {
const installUUID = this.getInstanceKey();
await this.removeInstance(installUUID);
return;
},
async hasSyncStorage(){
const inSync = await this.get();
return !(Object.entries(inSync).length === 0);
},
async backup(options) {
// remove listeners to avoid an infinite loop!
await sync.checkForListenersMaybeRemove();
const identities = await updateSyncIdentities();
const siteAssignments = await updateSyncSiteAssignments();
await updateInstanceInfo(identities, siteAssignments);
if (options && options.uuid)
await this.deleteIdentity(options.uuid);
if (options && options.undeleteUUID)
await removeFromDeletedIdentityList(options.undeleteUUID);
if (options && options.siteStoreKey)
await this.deleteSite(options.siteStoreKey);
if (options && options.undeleteSiteStoreKey)
await removeFromDeletedSitesList(options.undeleteSiteStoreKey);
if (SYNC_DEBUG) console.log("Backed up!");
await sync.checkForListenersMaybeAdd();
async function updateSyncIdentities() {
const identities = await browser.contextualIdentities.query({});
for (const identity of identities) {
delete identity.colorCode;
delete identity.iconUrl;
identity.macAddonUUID = await identityState.lookupMACaddonUUID(identity.cookieStoreId);
if(identity.macAddonUUID) {
const storageKey = "identity@@_" + identity.macAddonUUID;
await sync.storageArea.set({ [storageKey]: identity });
}
}
//await sync.storageArea.set({ identities });
return identities;
}
async function updateSyncSiteAssignments() {
const assignedSites =
await assignManager.storageArea.getAssignedSites();
for (const siteKey of Object.keys(assignedSites)) {
await sync.storageArea.set({ [siteKey]: assignedSites[siteKey] });
}
return assignedSites;
}
async function updateInstanceInfo(identitiesInput, siteAssignmentsInput) {
const date = new Date();
const timestamp = date.getTime();
const installUUID = sync.storageArea.getInstanceKey();
if (SYNC_DEBUG) console.log("adding", installUUID);
const identities = [];
const siteAssignments = [];
for (const identity of identitiesInput) {
identities.push(identity.macAddonUUID);
}
for (const siteAssignmentKey of Object.keys(siteAssignmentsInput)) {
siteAssignments.push(siteAssignmentKey);
}
await sync.storageArea.set({ [installUUID]: { timestamp, identities, siteAssignments } });
}
async function removeFromDeletedIdentityList(identityUUID) {
const deletedIdentityList =
await sync.storageArea.getDeletedIdentityList();
const newDeletedIdentityList = deletedIdentityList
.filter(element => element !== identityUUID);
await sync.storageArea.set({ deletedIdentityList: newDeletedIdentityList });
}
async function removeFromDeletedSitesList(siteStoreKey) {
const deletedSiteList =
await sync.storageArea.getDeletedSiteList();
const newDeletedSiteList = deletedSiteList
.filter(element => element !== siteStoreKey);
await sync.storageArea.set({ deletedSiteList: newDeletedSiteList });
}
},
onChangedListener(changes, areaName) {
if (areaName === "sync") sync.errorHandledRunSync();
},
async addToDeletedList(changeInfo) {
const identity = changeInfo.contextualIdentity;
const deletedUUID =
await identityState.lookupMACaddonUUID(identity.cookieStoreId);
await identityState.storageArea.remove(identity.cookieStoreId);
sync.storageArea.backup({uuid: deletedUUID});
}
},
async init() {
const syncEnabled = await assignManager.storageArea.getSyncEnabled();
if (syncEnabled) {
// Add listener to sync storage and containers.
// Works for all installs that have any sync storage.
// Waits for sync storage change before kicking off the restore/backup
// initial sync must be kicked off by user.
this.checkForListenersMaybeAdd();
return;
}
this.checkForListenersMaybeRemove();
},
async errorHandledRunSync () {
await sync.runSync().catch( async (error)=> {
if (SYNC_DEBUG) console.error("Error from runSync", error);
await sync.checkForListenersMaybeAdd();
});
},
async checkForListenersMaybeAdd() {
const hasStorageListener =
await browser.storage.onChanged.hasListener(
sync.storageArea.onChangedListener
);
const hasCIListener = await sync.hasContextualIdentityListeners();
if (!hasCIListener) {
await sync.addContextualIdentityListeners();
}
if (!hasStorageListener) {
await browser.storage.onChanged.addListener(
sync.storageArea.onChangedListener);
}
},
async checkForListenersMaybeRemove() {
const hasStorageListener =
await browser.storage.onChanged.hasListener(
sync.storageArea.onChangedListener
);
const hasCIListener = await sync.hasContextualIdentityListeners();
if (hasCIListener) {
await sync.removeContextualIdentityListeners();
}
if (hasStorageListener) {
await browser.storage.onChanged.removeListener(
sync.storageArea.onChangedListener);
}
},
async runSync() {
if (SYNC_DEBUG) {
const syncInfo = await sync.storageArea.get();
const localInfo = await browser.storage.local.get();
const idents = await browser.contextualIdentities.query({});
console.log("Initial State:", {syncInfo, localInfo, idents});
}
await sync.checkForListenersMaybeRemove();
if (SYNC_DEBUG) console.log("runSync");
await identityState.storageArea.upgradeData();
await assignManager.storageArea.upgradeData();
const hasSyncStorage = await sync.storageArea.hasSyncStorage();
if (hasSyncStorage) await restore();
await sync.storageArea.backup();
await removeOldDeletedItems();
return;
},
async addContextualIdentityListeners() {
await browser.contextualIdentities.onCreated.addListener(sync.storageArea.backup);
await browser.contextualIdentities.onRemoved.addListener(sync.storageArea.addToDeletedList);
await browser.contextualIdentities.onUpdated.addListener(sync.storageArea.backup);
},
async removeContextualIdentityListeners() {
await browser.contextualIdentities.onCreated.removeListener(sync.storageArea.backup);
await browser.contextualIdentities.onRemoved.removeListener(sync.storageArea.addToDeletedList);
await browser.contextualIdentities.onUpdated.removeListener(sync.storageArea.backup);
},
async hasContextualIdentityListeners() {
return (
await browser.contextualIdentities.onCreated.hasListener(sync.storageArea.backup) &&
await browser.contextualIdentities.onRemoved.hasListener(sync.storageArea.addToDeletedList) &&
await browser.contextualIdentities.onUpdated.hasListener(sync.storageArea.backup)
);
},
async resetSync() {
const syncEnabled = await assignManager.storageArea.getSyncEnabled();
if (syncEnabled) {
this.errorHandledRunSync();
return;
}
await this.checkForListenersMaybeRemove();
await this.storageArea.removeThisInstanceFromSync();
}
};
// attaching to window for use in mocha tests
window.sync = sync;
sync.init();
async function restore() {
if (SYNC_DEBUG) console.log("restore");
await reconcileIdentities();
await reconcileSiteAssignments();
return;
}
/*
* Checks for the container name. If it exists, they are assumed to be the
* same container, and the color and icon are overwritten from sync, if
* different.
*/
async function reconcileIdentities(){
if (SYNC_DEBUG) console.log("reconcileIdentities");
// first delete any from the deleted list
const deletedIdentityList =
await sync.storageArea.getDeletedIdentityList();
// first remove any deleted identities
for (const deletedUUID of deletedIdentityList) {
const deletedCookieStoreId =
await identityState.lookupCookieStoreId(deletedUUID);
if (deletedCookieStoreId){
try{
await browser.contextualIdentities.remove(deletedCookieStoreId);
} catch (error) {
// if the identity we are deleting is not there, that's fine.
console.error("Error deleting contextualIdentity", deletedCookieStoreId);
continue;
}
}
}
const localIdentities = await browser.contextualIdentities.query({});
const syncIdentitiesRemoveDupes =
await sync.storageArea.getIdentities();
// find any local dupes created on sync storage and delete from sync storage
for (const localIdentity of localIdentities) {
const syncIdentitiesOfName = syncIdentitiesRemoveDupes
.filter(identity => identity.name === localIdentity.name);
if (syncIdentitiesOfName.length > 1) {
const identityMatchingContextId = syncIdentitiesOfName
.find(identity => identity.cookieStoreId === localIdentity.cookieStoreId);
if (identityMatchingContextId)
await sync.storageArea.removeIdentityKeyFromSync(identityMatchingContextId.macAddonUUID);
}
}
const syncIdentities =
await sync.storageArea.getIdentities();
// now compare all containers for matching names.
for (const syncIdentity of syncIdentities) {
if (syncIdentity.macAddonUUID){
const localMatch = localIdentities.find(
localIdentity => localIdentity.name === syncIdentity.name
);
if (!localMatch) {
// if there's no name match found, check on uuid,
const localCookieStoreID =
await identityState.lookupCookieStoreId(syncIdentity.macAddonUUID);
if (localCookieStoreID) {
await ifUUIDMatch(syncIdentity, localCookieStoreID);
continue;
}
await ifNoMatch(syncIdentity);
continue;
}
// Names match, so use the info from Sync
await updateIdentityWithSyncInfo(syncIdentity, localMatch);
continue;
}
// if no macAddonUUID, there is a problem with the sync info and it needs to be ignored.
}
await updateSiteAssignmentUUIDs();
async function updateSiteAssignmentUUIDs(){
const sites = assignManager.storageArea.getAssignedSites();
for (const siteKey of Object.keys(sites)) {
await assignManager.storageArea.set(siteKey, sites[siteKey]);
}
}
}
async function updateIdentityWithSyncInfo(syncIdentity, localMatch) {
// Sync is truth. if there is a match, compare data and update as needed
if (syncIdentity.color !== localMatch.color
|| syncIdentity.icon !== localMatch.icon) {
await browser.contextualIdentities.update(
localMatch.cookieStoreId, {
name: syncIdentity.name,
color: syncIdentity.color,
icon: syncIdentity.icon
});
if (SYNC_DEBUG) {
if (localMatch.color !== syncIdentity.color) {
console.log(localMatch.name, "Change color: ", syncIdentity.color);
}
if (localMatch.icon !== syncIdentity.icon) {
console.log(localMatch.name, "Change icon: ", syncIdentity.icon);
}
}
}
// Sync is truth. If all is the same, update the local uuid to match sync
if (localMatch.macAddonUUID !== syncIdentity.macAddonUUID) {
await identityState.updateUUID(
localMatch.cookieStoreId,
syncIdentity.macAddonUUID
);
}
// TODOkmw: update any site assignment UUIDs
}
async function ifUUIDMatch(syncIdentity, localCookieStoreID) {
// if there's an identical local uuid, it's the same container. Sync is truth
const identityInfo = {
name: syncIdentity.name,
color: syncIdentity.color,
icon: syncIdentity.icon
};
if (SYNC_DEBUG) {
try {
const getIdent =
await browser.contextualIdentities.get(localCookieStoreID);
if (getIdent.name !== identityInfo.name) {
console.log(getIdent.name, "Change name: ", identityInfo.name);
}
if (getIdent.color !== identityInfo.color) {
console.log(getIdent.name, "Change color: ", identityInfo.color);
}
if (getIdent.icon !== identityInfo.icon) {
console.log(getIdent.name, "Change icon: ", identityInfo.icon);
}
} catch (error) {
//if this fails, there is probably differing sync info.
console.error("Error getting info on CI", error);
}
}
try {
// update the local container with the sync data
await browser.contextualIdentities
.update(localCookieStoreID, identityInfo);
return;
} catch (error) {
// If this fails, sync info is off.
console.error("Error udpating CI", error);
}
}
async function ifNoMatch(syncIdentity){
// if no uuid match either, make new identity
if (SYNC_DEBUG) console.log("create new ident: ", syncIdentity.name);
const newIdentity =
await browser.contextualIdentities.create({
name: syncIdentity.name,
color: syncIdentity.color,
icon: syncIdentity.icon
});
await identityState.updateUUID(
newIdentity.cookieStoreId,
syncIdentity.macAddonUUID
);
return;
}
/*
* Checks for site previously assigned. If it exists, and has the same
* container assignment, the assignment is kept. If it exists, but has
* a different assignment, the user is prompted (not yet implemented).
* If it does not exist, it is created.
*/
async function reconcileSiteAssignments() {
if (SYNC_DEBUG) console.log("reconcileSiteAssignments");
const assignedSitesLocal =
await assignManager.storageArea.getAssignedSites();
const assignedSitesFromSync =
await sync.storageArea.getAssignedSites();
const deletedSiteList =
await sync.storageArea.getDeletedSiteList();
for(const siteStoreKey of deletedSiteList) {
if (Object.prototype.hasOwnProperty.call(assignedSitesLocal,siteStoreKey)) {
assignManager
.storageArea
.remove(siteStoreKey);
}
}
for(const urlKey of Object.keys(assignedSitesFromSync)) {
const assignedSite = assignedSitesFromSync[urlKey];
try{
if (assignedSite.identityMacAddonUUID) {
// Sync is truth.
// Not even looking it up. Just overwrite
if (SYNC_DEBUG){
const isInStorage = await assignManager.storageArea.getByUrlKey(urlKey);
if (!isInStorage)
console.log("new assignment ", assignedSite);
}
await setAssignmentWithUUID(assignedSite, urlKey);
continue;
}
} catch (error) {
// this is probably old or incorrect site info in Sync
// skip and move on.
}
}
}
const MILISECONDS_IN_THIRTY_DAYS = 2592000000;
async function removeOldDeletedItems() {
const instanceList = await sync.storageArea.getAllInstanceInfo();
const deletedSiteList = await sync.storageArea.getDeletedSiteList();
const deletedIdentityList = await sync.storageArea.getDeletedIdentityList();
for (const instanceKey of Object.keys(instanceList)) {
const date = new Date();
const currentTimestamp = date.getTime();
if (instanceList[instanceKey].timestamp < currentTimestamp - MILISECONDS_IN_THIRTY_DAYS) {
delete instanceList[instanceKey];
sync.storageArea.removeInstance(instanceKey);
continue;
}
}
for (const siteStoreKey of deletedSiteList) {
let hasMatch = false;
for (const instance of Object.values(instanceList)) {
const match = instance.siteAssignments.find(element => element === siteStoreKey);
if (!match) continue;
hasMatch = true;
}
if (!hasMatch) {
await sync.storageArea.backup({undeleteSiteStoreKey: siteStoreKey});
}
}
for (const identityUUID of deletedIdentityList) {
let hasMatch = false;
for (const instance of Object.values(instanceList)) {
const match = instance.identities.find(element => element === identityUUID);
if (!match) continue;
hasMatch = true;
}
if (!hasMatch) {
await sync.storageArea.backup({undeleteUUID: identityUUID});
}
}
}
async function setAssignmentWithUUID(assignedSite, urlKey) {
const uuid = assignedSite.identityMacAddonUUID;
const cookieStoreId = await identityState.lookupCookieStoreId(uuid);
if (cookieStoreId) {
// eslint-disable-next-line require-atomic-updates
assignedSite.userContextId = cookieStoreId
.replace(/^firefox-container-/, "");
await assignManager.storageArea.set(
urlKey,
assignedSite,
false,
false
);
return;
}
throw new Error (`No cookieStoreId found for: ${uuid}, ${urlKey}`);
}
@@ -1,6 +1,6 @@
async function load() {
const searchParams = new URL(window.location).searchParams;
const redirectUrl = decodeURIComponent(searchParams.get("url"));
const redirectUrl = searchParams.get("url");
const cookieStoreId = searchParams.get("cookieStoreId");
const currentCookieStoreId = searchParams.get("currentCookieStoreId");
const redirectUrlElement = document.getElementById("redirect-url");
@@ -20,14 +20,21 @@ async function load() {
document.getElementById("redirect-form").addEventListener("submit", (e) => {
e.preventDefault();
const buttonTarget = e.explicitOriginalTarget;
switch (buttonTarget.id) {
case "confirm":
confirmSubmit(redirectUrl, cookieStoreId);
break;
let button = "confirm"; // Confirm is the form default.
let buttonTarget = e.explicitOriginalTarget;
if (buttonTarget.tagName !== "BUTTON") {
buttonTarget = buttonTarget.closest("button");
}
if (buttonTarget && buttonTarget.id) {
button = buttonTarget.id;
}
switch (button) {
case "deny":
denySubmit(redirectUrl);
break;
case "confirm":
confirmSubmit(redirectUrl, cookieStoreId);
break;
}
});
}
@@ -49,10 +56,6 @@ function confirmSubmit(redirectUrl, cookieStoreId) {
pageUrl: redirectUrl
});
}
browser.runtime.sendMessage({
method: "sendTelemetryPayload",
event: "click-to-reload-page-in-container",
});
openInContainer(redirectUrl, cookieStoreId);
}
@@ -70,10 +73,6 @@ async function denySubmit(redirectUrl) {
tabId: tab[0].id,
pageUrl: redirectUrl
});
browser.runtime.sendMessage({
method: "sendTelemetryPayload",
event: "click-to-reload-page-in-same-container",
});
document.location.replace(redirectUrl);
}
@@ -20,11 +20,15 @@ async function doAnimation(element, property, value) {
async function addMessage(message) {
const divElement = document.createElement("div");
divElement.classList.add("container-notification");
// For the eager eyed, this is an experiment. It is however likely that a website will know it is "contained" anyway
// Ideally we would use https://bugzilla.mozilla.org/show_bug.cgi?id=1340930 when this is available
divElement.innerText = message.text;
const imageElement = document.createElement("img");
imageElement.src = browser.extension.getURL("/img/container-site-d-24.png");
const imagePath = browser.extension.getURL("/img/container-site-d-24.png");
const response = await fetch(imagePath);
const blob = await response.blob();
const objectUrl = URL.createObjectURL(blob);
imageElement.src = objectUrl;
divElement.prepend(imageElement);
document.body.appendChild(divElement);
+41
View File
@@ -0,0 +1,41 @@
async function requestPermissions() {
const checkbox = document.querySelector("#bookmarksPermissions");
if (checkbox.checked) {
const granted = await browser.permissions.request({permissions: ["bookmarks"]});
if (!granted) {
checkbox.checked = false;
return;
}
} else {
await browser.permissions.remove({permissions: ["bookmarks"]});
}
browser.runtime.sendMessage({ method: "resetBookmarksContext" });
}
async function enableDisableSync() {
const checkbox = document.querySelector("#syncCheck");
if (checkbox.checked) {
await browser.storage.local.set({syncEnabled: true});
} else {
await browser.storage.local.set({syncEnabled: false});
}
browser.runtime.sendMessage({ method: "resetSync" });
}
async function restoreOptions() {
const hasPermission = await browser.permissions.contains({permissions: ["bookmarks"]});
const { syncEnabled } = await browser.storage.local.get("syncEnabled");
if (hasPermission) {
document.querySelector("#bookmarksPermissions").checked = true;
}
if (syncEnabled) {
document.querySelector("#syncCheck").checked = true;
} else {
document.querySelector("#syncCheck").checked = false;
}
}
document.addEventListener("DOMContentLoaded", restoreOptions);
document.querySelector("#bookmarksPermissions").addEventListener( "change", requestPermissions);
document.querySelector("#syncCheck").addEventListener( "change", enableDisableSync);
+427 -196
View File
@@ -12,16 +12,19 @@ const NEW_CONTAINER_ID = "new";
const ONBOARDING_STORAGE_KEY = "onboarding-stage";
// List of panels
const P_ONBOARDING_1 = "onboarding1";
const P_ONBOARDING_2 = "onboarding2";
const P_ONBOARDING_3 = "onboarding3";
const P_ONBOARDING_4 = "onboarding4";
const P_ONBOARDING_5 = "onboarding5";
const P_CONTAINERS_LIST = "containersList";
const P_CONTAINERS_EDIT = "containersEdit";
const P_CONTAINER_INFO = "containerInfo";
const P_CONTAINER_EDIT = "containerEdit";
const P_ONBOARDING_1 = "onboarding1";
const P_ONBOARDING_2 = "onboarding2";
const P_ONBOARDING_3 = "onboarding3";
const P_ONBOARDING_4 = "onboarding4";
const P_ONBOARDING_5 = "onboarding5";
const P_ONBOARDING_6 = "onboarding6";
const P_ONBOARDING_7 = "onboarding7";
const P_CONTAINERS_LIST = "containersList";
const P_CONTAINERS_EDIT = "containersEdit";
const P_CONTAINER_INFO = "containerInfo";
const P_CONTAINER_EDIT = "containerEdit";
const P_CONTAINER_DELETE = "containerDelete";
const P_CONTAINERS_ACHIEVEMENT = "containersAchievement";
/**
* Escapes any occurances of &, ", <, > or / with XML entities.
@@ -31,7 +34,7 @@ const P_CONTAINER_DELETE = "containerDelete";
* @return {string} The escaped string.
*/
function escapeXML(str) {
const replacements = {"&": "&amp;", "\"": "&quot;", "'": "&apos;", "<": "&lt;", ">": "&gt;", "/": "&#x2F;"};
const replacements = { "&": "&amp;", "\"": "&quot;", "'": "&apos;", "<": "&lt;", ">": "&gt;", "/": "&#x2F;" };
return String(str).replace(/[&"'<>/]/g, m => replacements[m]);
}
@@ -81,38 +84,31 @@ const Logic = {
// Retrieve the list of identities.
const identitiesPromise = this.refreshIdentities();
// Get the onboarding variation
const variationPromise = this.getShieldStudyVariation();
try {
await Promise.all([identitiesPromise, variationPromise]);
} catch(e) {
await identitiesPromise;
} catch (e) {
throw new Error("Failed to retrieve the identities or variation. We cannot continue. ", e.message);
}
// Routing to the correct panel.
// If localStorage is disabled, we don't show the onboarding.
const data = await browser.storage.local.get([ONBOARDING_STORAGE_KEY]);
let onboarded = data[ONBOARDING_STORAGE_KEY];
const onboardingData = await browser.storage.local.get([ONBOARDING_STORAGE_KEY]);
let onboarded = onboardingData[ONBOARDING_STORAGE_KEY];
if (!onboarded) {
// Legacy local storage used before panel 5
if (localStorage.getItem("onboarded4")) {
onboarded = 4;
} else if (localStorage.getItem("onboarded3")) {
onboarded = 3;
} else if (localStorage.getItem("onboarded2")) {
onboarded = 2;
} else if (localStorage.getItem("onboarded1")) {
onboarded = 1;
} else {
onboarded = 0;
}
onboarded = 0;
this.setOnboardingStage(onboarded);
}
switch (onboarded) {
case 7:
this.showAchievementOrContainersListPanel();
break;
case 6:
this.showPanel(P_ONBOARDING_7);
break;
case 5:
this.showPanel(P_CONTAINERS_LIST);
this.showPanel(P_ONBOARDING_6);
break;
case 4:
this.showPanel(P_ONBOARDING_5);
@@ -134,6 +130,37 @@ const Logic = {
},
async showAchievementOrContainersListPanel() {
// Do we need to show an achievement panel?
let showAchievements = false;
const achievementsStorage = await browser.storage.local.get({ achievements: [] });
for (const achievement of achievementsStorage.achievements) {
if (!achievement.done) {
showAchievements = true;
}
}
if (showAchievements) {
this.showPanel(P_CONTAINERS_ACHIEVEMENT);
} else {
this.showPanel(P_CONTAINERS_LIST);
}
},
// In case the user wants to click multiple actions,
// they have to click the "Done" button to stop the panel
// from showing
async setAchievementDone(achievementName) {
const achievementsStorage = await browser.storage.local.get({ achievements: [] });
const achievements = achievementsStorage.achievements;
achievements.forEach((achievement, index, achievementsArray) => {
if (achievement.name === achievementName) {
achievement.done = true;
achievementsArray[index] = achievement;
}
});
browser.storage.local.set({ achievements });
},
setOnboardingStage(stage) {
return browser.storage.local.set({
[ONBOARDING_STORAGE_KEY]: stage
@@ -142,21 +169,32 @@ const Logic = {
async clearBrowserActionBadge() {
const extensionInfo = await getExtensionInfo();
const storage = await browser.storage.local.get({browserActionBadgesClicked: []});
browser.browserAction.setBadgeBackgroundColor({color: ""});
browser.browserAction.setBadgeText({text: ""});
const storage = await browser.storage.local.get({ browserActionBadgesClicked: [] });
browser.browserAction.setBadgeBackgroundColor({ color: null });
browser.browserAction.setBadgeText({ text: "" });
storage.browserActionBadgesClicked.push(extensionInfo.version);
browser.storage.local.set({browserActionBadgesClicked: storage.browserActionBadgesClicked});
// use set and spread to create a unique array
const browserActionBadgesClicked = [...new Set(storage.browserActionBadgesClicked)];
browser.storage.local.set({
browserActionBadgesClicked
});
},
async identity(cookieStoreId) {
const identity = await browser.contextualIdentities.get(cookieStoreId);
return identity || {
const defaultContainer = {
name: "Default",
cookieStoreId,
icon: "default-tab",
color: "default-tab"
color: "default-tab",
numberOfHiddenTabs: 0,
numberOfOpenTabs: 0
};
// Handle old style rejection with null and also Promise.reject new style
try {
return await browser.contextualIdentities.get(cookieStoreId) || defaultContainer;
} catch (e) {
return defaultContainer;
}
},
addEnterHandler(element, handler) {
@@ -165,6 +203,7 @@ const Logic = {
});
element.addEventListener("keydown", (e) => {
if (e.keyCode === 13) {
e.preventDefault();
handler(e);
}
});
@@ -176,34 +215,60 @@ const Logic = {
},
async currentTab() {
const activeTabs = await browser.tabs.query({active: true, windowId: browser.windows.WINDOW_ID_CURRENT});
const activeTabs = await browser.tabs.query({ active: true, windowId: browser.windows.WINDOW_ID_CURRENT });
if (activeTabs.length > 0) {
return activeTabs[0];
}
return false;
},
refreshIdentities() {
return Promise.all([
async numTabs() {
const activeTabs = await browser.tabs.query({ windowId: browser.windows.WINDOW_ID_CURRENT });
return activeTabs.length;
},
_disableMoveTabs(message) {
const moveTabsEl = document.querySelector("#container-info-movetabs");
const fragment = document.createDocumentFragment();
const incompatEl = document.createElement("div");
moveTabsEl.classList.remove("clickable");
moveTabsEl.setAttribute("title", message);
fragment.appendChild(incompatEl);
incompatEl.setAttribute("id", "container-info-movetabs-incompat");
incompatEl.textContent = message;
incompatEl.classList.add("container-info-tab-row");
moveTabsEl.parentNode.insertBefore(fragment, moveTabsEl.nextSibling);
},
async refreshIdentities() {
const [identities, state] = await Promise.all([
browser.contextualIdentities.query({}),
browser.runtime.sendMessage({
method: "queryIdentitiesState"
})
]).then(([identities, state]) => {
this._identities = identities.map((identity) => {
const stateObject = state[Logic.userContextId(identity.cookieStoreId)];
if (stateObject) {
identity.hasOpenTabs = stateObject.hasOpenTabs;
identity.hasHiddenTabs = stateObject.hasHiddenTabs;
method: "queryIdentitiesState",
message: {
windowId: browser.windows.WINDOW_ID_CURRENT
}
return identity;
});
}).catch((e) => {throw e;});
})
]);
this._identities = identities.map((identity) => {
const stateObject = state[identity.cookieStoreId];
if (stateObject) {
identity.hasOpenTabs = stateObject.hasOpenTabs;
identity.hasHiddenTabs = stateObject.hasHiddenTabs;
identity.numberOfHiddenTabs = stateObject.numberOfHiddenTabs;
identity.numberOfOpenTabs = stateObject.numberOfOpenTabs;
}
return identity;
});
},
getPanelSelector(panel) {
if (this._onboardingVariation === "securityOnboarding" &&
panel.hasOwnProperty("securityPanelSelector")) {
// eslint-disable-next-line no-prototype-builtins
panel.hasOwnProperty("securityPanelSelector")) {
return panel.securityPanelSelector;
} else {
return panel.panelSelector;
@@ -233,7 +298,13 @@ const Logic = {
}
}
});
document.querySelector(this.getPanelSelector(this._panels[panel])).classList.remove("hide");
const panelEl = document.querySelector(this.getPanelSelector(this._panels[panel]));
panelEl.classList.remove("hide");
const focusEl = panelEl.querySelector(".firstTabindex");
if(focusEl) {
focusEl.focus();
}
},
showPreviousPanel() {
@@ -265,12 +336,9 @@ const Logic = {
return Logic.userContextId(identity.cookieStoreId);
},
sendTelemetryPayload(message = {}) {
if (!message.event) {
throw new Error("Missing event name for telemetry");
}
message.method = "sendTelemetryPayload";
browser.runtime.sendMessage(message);
currentCookieStoreId() {
const identity = Logic.currentIdentity();
return identity.cookieStoreId;
},
removeIdentity(userContextId) {
@@ -280,7 +348,7 @@ const Logic = {
return browser.runtime.sendMessage({
method: "deleteContainer",
message: {userContextId}
message: { userContextId }
});
},
@@ -292,9 +360,12 @@ const Logic = {
},
getAssignmentObjectByContainer(userContextId) {
if (!userContextId) {
return {};
}
return browser.runtime.sendMessage({
method: "getAssignmentObjectByContainer",
message: {userContextId}
message: { userContextId }
});
},
@@ -308,14 +379,6 @@ const Logic = {
});
},
getShieldStudyVariation() {
return browser.runtime.sendMessage({
method: "getShieldStudyVariation"
}).then(variation => {
this._onboardingVariation = variation;
});
},
generateIdentityName() {
const defaultName = "Container #";
const ids = [];
@@ -331,12 +394,17 @@ const Logic = {
});
// Here we find the first valid id.
for (let id = 1;; ++id) {
for (let id = 1; ; ++id) {
if (ids.indexOf(id) === -1) {
return defaultName + (id < 10 ? "0" : "") + id;
}
}
},
getCurrentPanelElement() {
const panelItem = this._panels[this._currentPanel];
return document.querySelector(this.getPanelSelector(panelItem));
},
};
// P_ONBOARDING_1: First page for Onboarding.
@@ -350,7 +418,7 @@ Logic.registerPanel(P_ONBOARDING_1, {
initialize() {
// Let's move to the next panel.
[...document.querySelectorAll(".onboarding-start-button")].forEach(startElement => {
Logic.addEnterHandler(startElement, async function () {
Logic.addEnterHandler(startElement, async () => {
await Logic.setOnboardingStage(1);
Logic.showPanel(P_ONBOARDING_2);
});
@@ -374,7 +442,7 @@ Logic.registerPanel(P_ONBOARDING_2, {
initialize() {
// Let's move to the containers list panel.
[...document.querySelectorAll(".onboarding-next-button")].forEach(nextElement => {
Logic.addEnterHandler(nextElement, async function () {
Logic.addEnterHandler(nextElement, async () => {
await Logic.setOnboardingStage(2);
Logic.showPanel(P_ONBOARDING_3);
});
@@ -398,7 +466,7 @@ Logic.registerPanel(P_ONBOARDING_3, {
initialize() {
// Let's move to the containers list panel.
[...document.querySelectorAll(".onboarding-almost-done-button")].forEach(almostElement => {
Logic.addEnterHandler(almostElement, async function () {
Logic.addEnterHandler(almostElement, async () => {
await Logic.setOnboardingStage(3);
Logic.showPanel(P_ONBOARDING_4);
});
@@ -420,7 +488,7 @@ Logic.registerPanel(P_ONBOARDING_4, {
// This method is called when the object is registered.
initialize() {
// Let's move to the containers list panel.
Logic.addEnterHandler(document.querySelector("#onboarding-done-button"), async function () {
Logic.addEnterHandler(document.querySelector("#onboarding-done-button"), async () => {
await Logic.setOnboardingStage(4);
Logic.showPanel(P_ONBOARDING_5);
});
@@ -441,8 +509,41 @@ Logic.registerPanel(P_ONBOARDING_5, {
// This method is called when the object is registered.
initialize() {
// Let's move to the containers list panel.
Logic.addEnterHandler(document.querySelector("#onboarding-longpress-button"), async function () {
Logic.addEnterHandler(document.querySelector("#onboarding-longpress-button"), async () => {
await Logic.setOnboardingStage(5);
Logic.showPanel(P_ONBOARDING_6);
});
},
// This method is called when the panel is shown.
prepare() {
return Promise.resolve(null);
},
});
// P_ONBOARDING_6: Sixth page for Onboarding: new tab long-press behavior
// ----------------------------------------------------------------------------
Logic.registerPanel(P_ONBOARDING_6, {
panelSelector: ".onboarding-panel-6",
// This method is called when the object is registered.
initialize() {
// Let's move to the containers list panel.
Logic.addEnterHandler(document.querySelector("#start-sync-button"), async () => {
await Logic.setOnboardingStage(6);
await browser.storage.local.set({syncEnabled: true});
await browser.runtime.sendMessage({
method: "resetSync"
});
Logic.showPanel(P_ONBOARDING_7);
});
Logic.addEnterHandler(document.querySelector("#no-sync"), async () => {
await Logic.setOnboardingStage(7);
await browser.storage.local.set({syncEnabled: false});
await browser.runtime.sendMessage({
method: "resetSync"
});
Logic.showPanel(P_CONTAINERS_LIST);
});
},
@@ -453,6 +554,33 @@ Logic.registerPanel(P_ONBOARDING_5, {
},
});
// P_ONBOARDING_6: Sixth page for Onboarding: new tab long-press behavior
// ----------------------------------------------------------------------------
Logic.registerPanel(P_ONBOARDING_7, {
panelSelector: ".onboarding-panel-7",
// This method is called when the object is registered.
initialize() {
// Let's move to the containers list panel.
Logic.addEnterHandler(document.querySelector("#sign-in"), async () => {
browser.tabs.create({
url: "https://accounts.firefox.com/?service=sync&action=email&context=fx_desktop_v3&entrypoint=multi-account-containers&utm_source=addon&utm_medium=panel&utm_campaign=container-sync",
});
await Logic.setOnboardingStage(7);
Logic.showPanel(P_CONTAINERS_LIST);
});
Logic.addEnterHandler(document.querySelector("#no-sign-in"), async () => {
await Logic.setOnboardingStage(7);
Logic.showPanel(P_CONTAINERS_LIST);
});
},
// This method is called when the panel is shown.
prepare() {
return Promise.resolve(null);
},
});
// P_CONTAINERS_LIST: The list of containers. The main page.
// ----------------------------------------------------------------------------
@@ -460,40 +588,42 @@ Logic.registerPanel(P_CONTAINERS_LIST, {
panelSelector: "#container-panel",
// This method is called when the object is registered.
initialize() {
async initialize() {
Logic.addEnterHandler(document.querySelector("#container-add-link"), () => {
Logic.showPanel(P_CONTAINER_EDIT, { name: Logic.generateIdentityName() });
});
Logic.addEnterHandler(document.querySelector("#edit-containers-link"), () => {
Logic.sendTelemetryPayload({
event: "edit-containers"
});
Logic.showPanel(P_CONTAINERS_EDIT);
Logic.addEnterHandler(document.querySelector("#edit-containers-link"), (e) => {
if (!e.target.classList.contains("disable-edit-containers")) {
Logic.showPanel(P_CONTAINERS_EDIT);
}
});
Logic.addEnterHandler(document.querySelector("#sort-containers-link"), () => {
browser.runtime.sendMessage({
method: "sortTabs"
}).then(() => {
Logic.addEnterHandler(document.querySelector("#sort-containers-link"), async () => {
try {
await browser.runtime.sendMessage({
method: "sortTabs"
});
window.close();
}).catch(() => {
} catch (e) {
window.close();
});
}
});
document.addEventListener("keydown", (e) => {
const selectables = [...document.querySelectorAll(".open-newtab[tabindex='0']")];
const element = document.activeElement;
const index = selectables.indexOf(element) || 0;
function next() {
const nextElement = element.nextElementSibling;
const nextElement = selectables[index + 1];
if (nextElement) {
nextElement.querySelector("td[tabindex=0]").focus();
nextElement.focus();
}
}
function previous() {
const previousElement = element.previousElementSibling;
const previousElement = selectables[index - 1];
if (previousElement) {
previousElement.querySelector("td[tabindex=0]").focus();
previousElement.focus();
}
}
switch (e.keyCode) {
@@ -503,6 +633,31 @@ Logic.registerPanel(P_CONTAINERS_LIST, {
case 38:
previous();
break;
case 39:
{
const showTabs = element.parentNode.querySelector(".show-tabs");
if(showTabs) {
showTabs.click();
}
break;
}
case 37:
{
const hideTabs = document.querySelector(".panel-back-arrow");
if(hideTabs) {
hideTabs.click();
}
break;
}
default:
if ((e.keyCode >= 49 && e.keyCode <= 57) &&
Logic._currentPanel === "containersList") {
const element = selectables[e.keyCode - 49];
if (element) {
element.click();
}
}
break;
}
});
@@ -579,11 +734,11 @@ Logic.registerPanel(P_CONTAINERS_LIST, {
tr.classList.add("container-panel-row");
context.classList.add("userContext-wrapper", "open-newtab", "clickable");
context.classList.add("userContext-wrapper", "open-newtab", "clickable", "firstTabindex");
manage.classList.add("show-tabs", "pop-button");
manage.title = escaped`View ${identity.name} container`;
manage.setAttribute("title", `View ${identity.name} container`);
context.setAttribute("tabindex", "0");
context.title = escaped`Create ${identity.name} tab`;
context.setAttribute("title", `Create ${identity.name} tab`);
context.innerHTML = escaped`
<div class="userContext-icon-wrapper open-newtab">
<div class="usercontext-icon"
@@ -603,21 +758,18 @@ Logic.registerPanel(P_CONTAINERS_LIST, {
tr.appendChild(manage);
}
Logic.addEnterHandler(tr, e => {
Logic.addEnterHandler(tr, async (e) => {
if (e.target.matches(".open-newtab")
|| e.target.parentNode.matches(".open-newtab")
|| e.type === "keydown") {
browser.runtime.sendMessage({
method: "openTab",
message: {
userContextId: Logic.userContextId(identity.cookieStoreId),
source: "pop-up"
}
}).then(() => {
|| e.target.parentNode.matches(".open-newtab")
|| e.type === "keydown") {
try {
browser.tabs.create({
cookieStoreId: identity.cookieStoreId
});
window.close();
}).catch(() => {
} catch (e) {
window.close();
});
}
} else if (hasTabs) {
Logic.showPanel(P_CONTAINER_INFO, identity);
}
@@ -632,14 +784,25 @@ Logic.registerPanel(P_CONTAINERS_LIST, {
however it allows us to have a tabindex before the first selected item
*/
const focusHandler = () => {
list.querySelector("tr .clickable").focus();
document.removeEventListener("focus", focusHandler);
const identityList = list.querySelector("tr .clickable");
if (identityList) {
// otherwise this throws an error when there are no containers present.
identityList.focus();
document.removeEventListener("focus", focusHandler);
}
};
document.addEventListener("focus", focusHandler);
/* If the user mousedown's first then remove the focus handler */
document.addEventListener("mousedown", () => {
document.removeEventListener("focus", focusHandler);
});
/* If no container is present disable the Edit Containers button */
const editContainer = document.querySelector("#edit-containers-link");
if (Logic.identities().length === 0) {
editContainer.classList.add("disable-edit-containers");
} else {
editContainer.classList.remove("disable-edit-containers");
}
return Promise.resolve();
},
@@ -652,58 +815,60 @@ Logic.registerPanel(P_CONTAINER_INFO, {
panelSelector: "#container-info-panel",
// This method is called when the object is registered.
initialize() {
Logic.addEnterHandler(document.querySelector("#close-container-info-panel"), () => {
async initialize() {
const closeContEl = document.querySelector("#close-container-info-panel");
closeContEl.setAttribute("tabindex", "0");
closeContEl.classList.add("firstTabindex");
Logic.addEnterHandler(closeContEl, () => {
Logic.showPreviousPanel();
});
Logic.addEnterHandler(document.querySelector("#container-info-hideorshow"), () => {
const hideContEl = document.querySelector("#container-info-hideorshow");
hideContEl.setAttribute("tabindex", "0");
Logic.addEnterHandler(hideContEl, async () => {
const identity = Logic.currentIdentity();
browser.runtime.sendMessage({
method: identity.hasHiddenTabs ? "showTabs" : "hideTabs",
userContextId: Logic.currentUserContextId()
}).then(() => {
try {
browser.runtime.sendMessage({
method: identity.hasHiddenTabs ? "showTabs" : "hideTabs",
windowId: browser.windows.WINDOW_ID_CURRENT,
cookieStoreId: Logic.currentCookieStoreId()
});
window.close();
}).catch(() => {
} catch (e) {
window.close();
});
}
});
// Check if the user has incompatible add-ons installed
browser.runtime.sendMessage({
method: "checkIncompatibleAddons"
}).then(incompatible => {
const moveTabsEl = document.querySelector("#container-info-movetabs");
if (incompatible) {
const fragment = document.createDocumentFragment();
const incompatEl = document.createElement("div");
moveTabsEl.classList.remove("clickable");
moveTabsEl.setAttribute("title", "Moving container tabs is incompatible with Pulse, PageShot, and SnoozeTabs.");
fragment.appendChild(incompatEl);
incompatEl.setAttribute("id", "container-info-movetabs-incompat");
incompatEl.textContent = "Incompatible with other Experiments.";
incompatEl.classList.add("container-info-tab-row");
moveTabsEl.parentNode.insertBefore(fragment, moveTabsEl.nextSibling);
} else {
Logic.addEnterHandler(moveTabsEl, () => {
browser.runtime.sendMessage({
method: "moveTabsToWindow",
userContextId: Logic.userContextId(Logic.currentIdentity().cookieStoreId),
}).then(() => {
window.close();
}).catch((e) => { throw e; });
});
}
}).catch(() => {
let incompatible = false;
try {
incompatible = await browser.runtime.sendMessage({
method: "checkIncompatibleAddons"
});
} catch (e) {
throw new Error("Could not check for incompatible add-ons.");
}
const moveTabsEl = document.querySelector("#container-info-movetabs");
moveTabsEl.setAttribute("tabindex","0");
const numTabs = await Logic.numTabs();
if (incompatible) {
Logic._disableMoveTabs("Moving container tabs is incompatible with Pulse, PageShot, and SnoozeTabs.");
return;
} else if (numTabs === 1) {
Logic._disableMoveTabs("Cannot move a tab from a single-tab window.");
return;
}
Logic.addEnterHandler(moveTabsEl, async () => {
await browser.runtime.sendMessage({
method: "moveTabsToWindow",
windowId: browser.windows.WINDOW_ID_CURRENT,
cookieStoreId: Logic.currentIdentity().cookieStoreId,
});
window.close();
});
},
// This method is called when the panel is shown.
prepare() {
async prepare() {
const identity = Logic.currentIdentity();
// Populating the panel: name and icon
@@ -731,10 +896,12 @@ Logic.registerPanel(P_CONTAINER_INFO, {
}
// Let's retrieve the list of tabs.
return browser.runtime.sendMessage({
const tabs = await browser.runtime.sendMessage({
method: "getTabs",
userContextId: Logic.currentUserContextId(),
}).then(this.buildInfoTable);
windowId: browser.windows.WINDOW_ID_CURRENT,
cookieStoreId: Logic.currentIdentity().cookieStoreId
});
return this.buildInfoTable(tabs);
},
buildInfoTable(tabs) {
@@ -746,26 +913,45 @@ Logic.registerPanel(P_CONTAINER_INFO, {
tr.classList.add("container-info-tab-row");
tr.innerHTML = escaped`
<td></td>
<td class="container-info-tab-title truncate-text" title="${tab.url}" >${tab.title}</td>`;
tr.querySelector("td").appendChild(Utils.createFavIconElement(tab.favicon));
<td class="container-info-tab-title truncate-text" title="${tab.url}" ><div class="container-tab-title">${tab.title}</div></td>`;
tr.querySelector("td").appendChild(Utils.createFavIconElement(tab.favIconUrl));
tr.setAttribute("tabindex", "0");
document.getElementById("container-info-table").appendChild(fragment);
// On click, we activate this tab. But only if this tab is active.
if (tab.active) {
if (!tab.hiddenState) {
const closeImage = document.createElement("img");
closeImage.src = "/img/container-close-tab.svg";
closeImage.className = "container-close-tab";
closeImage.title = "Close tab";
closeImage.id = tab.id;
const tabTitle = tr.querySelector(".container-info-tab-title");
tabTitle.appendChild(closeImage);
// On hover, we add truncate-text class to add close-tab-image after tab title truncates
const tabTitleHoverEvent = () => {
tabTitle.classList.toggle("truncate-text");
tr.querySelector(".container-tab-title").classList.toggle("truncate-text");
};
tr.addEventListener("mouseover", tabTitleHoverEvent);
tr.addEventListener("mouseout", tabTitleHoverEvent);
tr.classList.add("clickable");
Logic.addEnterHandler(tr, () => {
browser.runtime.sendMessage({
method: "showTab",
tabId: tab.id,
}).then(() => {
window.close();
}).catch(() => {
Logic.addEnterHandler(tr, async () => {
await browser.tabs.update(tab.id, { active: true });
window.close();
});
const closeTab = document.getElementById(tab.id);
if (closeTab) {
Logic.addEnterHandler(closeTab, async (e) => {
await browser.tabs.remove(Number(e.target.id));
window.close();
});
});
}
}
}
document.getElementById("container-info-table").appendChild(fragment);
},
});
@@ -812,7 +998,7 @@ Logic.registerPanel(P_CONTAINERS_EDIT, {
</td>`;
tr.querySelector(".container-name").textContent = identity.name;
tr.querySelector(".edit-container").setAttribute("title", `Edit ${identity.name} container`);
tr.querySelector(".remove-container").setAttribute("title", `Delete ${identity.name} container`);
tr.querySelector(".remove-container").setAttribute("title", `Remove ${identity.name} container`);
Logic.addEnterHandler(tr, e => {
@@ -871,25 +1057,25 @@ Logic.registerPanel(P_CONTAINER_EDIT, {
},
_submitForm() {
async _submitForm() {
const formValues = new FormData(this._editForm);
return browser.runtime.sendMessage({
method: "createOrUpdateContainer",
message: {
userContextId: formValues.get("container-id") || NEW_CONTAINER_ID,
params: {
name: document.getElementById("edit-container-panel-name-input").value || Logic.generateIdentityName(),
icon: formValues.get("container-icon") || DEFAULT_ICON,
color: formValues.get("container-color") || DEFAULT_COLOR,
try {
await browser.runtime.sendMessage({
method: "createOrUpdateContainer",
message: {
userContextId: formValues.get("container-id") || NEW_CONTAINER_ID,
params: {
name: document.getElementById("edit-container-panel-name-input").value || Logic.generateIdentityName(),
icon: formValues.get("container-icon") || DEFAULT_ICON,
color: formValues.get("container-color") || DEFAULT_COLOR,
}
}
}
}).then(() => {
return Logic.refreshIdentities();
}).then(() => {
});
await Logic.refreshIdentities();
Logic.showPreviousPanel();
}).catch(() => {
} catch (e) {
Logic.showPanel(P_CONTAINERS_LIST);
});
}
},
showAssignedContainers(assignments) {
@@ -903,14 +1089,15 @@ Logic.registerPanel(P_CONTAINER_EDIT, {
while (tableElement.firstChild) {
tableElement.firstChild.remove();
}
assignmentKeys.forEach((siteKey) => {
const site = assignments[siteKey];
const trElement = document.createElement("div");
/* As we don't have the full or correct path the best we can assume is the path is HTTPS and then replace with a broken icon later if it doesn't load.
This is pending a better solution for favicons from web extensions */
const assumedUrl = `https://${site.hostname}`;
const assumedUrl = `https://${site.hostname}/favicon.ico`;
trElement.innerHTML = escaped`
<img class="icon" src="${assumedUrl}/favicon.ico">
<div class="favicon"></div>
<div title="${site.hostname}" class="truncate-text hostname">
${site.hostname}
</div>
@@ -918,18 +1105,17 @@ Logic.registerPanel(P_CONTAINER_EDIT, {
class="pop-button-image delete-assignment"
src="/img/container-delete.svg"
/>`;
trElement.getElementsByClassName("favicon")[0].appendChild(Utils.createFavIconElement(assumedUrl));
const deleteButton = trElement.querySelector(".delete-assignment");
Logic.addEnterHandler(deleteButton, () => {
const that = this;
Logic.addEnterHandler(deleteButton, async () => {
const userContextId = Logic.currentUserContextId();
// Lets show the message to the current tab
// TODO remove then when firefox supports arrow fn async
Logic.currentTab().then((currentTab) => {
Logic.setOrRemoveAssignment(currentTab.id, assumedUrl, userContextId, true);
delete assignments[siteKey];
this.showAssignedContainers(assignments);
}).catch((e) => {
throw e;
});
const currentTab = await Logic.currentTab();
Logic.setOrRemoveAssignment(currentTab.id, assumedUrl, userContextId, true);
delete assignments[siteKey];
that.showAssignedContainers(assignments);
});
trElement.classList.add("container-info-tab-row", "clickable");
tableElement.appendChild(trElement);
@@ -942,7 +1128,7 @@ Logic.registerPanel(P_CONTAINER_EDIT, {
return escaped`<input type="radio" value="${containerColor}" name="container-color" id="edit-container-panel-choose-color-${containerColor}" />
<label for="edit-container-panel-choose-color-${containerColor}" class="usercontext-icon choose-color-icon" data-identity-icon="circle" data-identity-color="${containerColor}">`;
};
const colors = ["blue", "turquoise", "green", "yellow", "orange", "red", "pink", "purple" ];
const colors = ["blue", "turquoise", "green", "yellow", "orange", "red", "pink", "purple"];
const colorRadioFieldset = document.getElementById("edit-container-panel-choose-color");
colors.forEach((containerColor) => {
const templateInstance = document.createElement("div");
@@ -978,6 +1164,11 @@ Logic.registerPanel(P_CONTAINER_EDIT, {
document.querySelector("#edit-container-panel-name-input").value = identity.name || "";
document.querySelector("#edit-container-panel-usercontext-input").value = userContextId || NEW_CONTAINER_ID;
const containerName = document.querySelector("#edit-container-panel-name-input");
window.requestAnimationFrame(() => {
containerName.select();
containerName.focus();
});
[...document.querySelectorAll("[name='container-color']")].forEach(colorInput => {
colorInput.checked = colorInput.value === identity.color;
});
@@ -1002,19 +1193,19 @@ Logic.registerPanel(P_CONTAINER_DELETE, {
Logic.showPreviousPanel();
});
Logic.addEnterHandler(document.querySelector("#delete-container-ok-link"), () => {
Logic.addEnterHandler(document.querySelector("#delete-container-ok-link"), async () => {
/* This promise wont resolve if the last tab was removed from the window.
as the message async callback stops listening, this isn't an issue for us however it might be in future
if you want to do anything post delete do it in the background script.
Browser console currently warns about not listening also.
*/
Logic.removeIdentity(Logic.userContextId(Logic.currentIdentity().cookieStoreId)).then(() => {
return Logic.refreshIdentities();
}).then(() => {
try {
await Logic.removeIdentity(Logic.userContextId(Logic.currentIdentity().cookieStoreId));
await Logic.refreshIdentities();
Logic.showPreviousPanel();
}).catch(() => {
} catch (e) {
Logic.showPanel(P_CONTAINERS_LIST);
});
}
});
},
@@ -1022,9 +1213,17 @@ Logic.registerPanel(P_CONTAINER_DELETE, {
prepare() {
const identity = Logic.currentIdentity();
// Populating the panel: name and icon
// Populating the panel: name, icon, and warning message
document.getElementById("delete-container-name").textContent = identity.name;
const totalNumberOfTabs = identity.numberOfHiddenTabs + identity.numberOfOpenTabs;
let warningMessage = "";
if (totalNumberOfTabs > 0) {
const grammaticalNumTabs = totalNumberOfTabs > 1 ? "tabs" : "tab";
warningMessage = `If you remove this container now, ${totalNumberOfTabs} container ${grammaticalNumTabs} will be closed.`;
}
document.getElementById("delete-container-tab-warning").textContent = warningMessage;
const icon = document.getElementById("delete-container-icon");
icon.setAttribute("data-identity-icon", identity.icon);
icon.setAttribute("data-identity-color", identity.color);
@@ -1033,4 +1232,36 @@ Logic.registerPanel(P_CONTAINER_DELETE, {
},
});
// P_CONTAINERS_ACHIEVEMENT: Page for achievement.
// ----------------------------------------------------------------------------
Logic.registerPanel(P_CONTAINERS_ACHIEVEMENT, {
panelSelector: ".achievement-panel",
// This method is called when the object is registered.
initialize() {
// Set done and move to the containers list panel.
Logic.addEnterHandler(document.querySelector("#achievement-done-button"), async () => {
await Logic.setAchievementDone("manyContainersOpened");
Logic.showPanel(P_CONTAINERS_LIST);
});
},
// This method is called when the panel is shown.
prepare() {
return Promise.resolve(null);
},
});
Logic.init();
window.addEventListener("resize", function () {
//for overflow menu
const difference = window.innerWidth - document.body.offsetWidth;
if (difference > 2) {
//if popup is in the overflow menu, window will be larger than 300px
const root = document.documentElement;
root.style.setProperty("--overflow-size", difference + "px");
root.style.setProperty("--icon-fit", "12");
}
});
+1 -1
View File
@@ -1,4 +1,4 @@
const DEFAULT_FAVICON = "moz-icon://goat?size=16";
const DEFAULT_FAVICON = "/img/blank-favicon.svg";
// TODO use export here instead of globals
window.Utils = {
+80
View File
@@ -0,0 +1,80 @@
{
"manifest_version": 2,
"name": "Firefox Multi-Account Containers",
"version": "6.2.3",
"incognito": "not_allowed",
"description": "Multi-Account Containers helps you keep all the parts of your online life contained in different tabs. Custom labels and color-coded tabs help keep different activities — like online shopping, travel planning, or checking work email — separate.",
"icons": {
"48": "img/container-site-d-48.png",
"96": "img/container-site-d-96.png"
},
"applications": {
"gecko": {
"id": "@testpilot-containers",
"strict_min_version": "67.0"
}
},
"homepage_url": "https://github.com/mozilla/multi-account-containers#readme",
"permissions": [
"<all_urls>",
"activeTab",
"cookies",
"contextMenus",
"contextualIdentities",
"history",
"idle",
"management",
"storage",
"tabs",
"webRequestBlocking",
"webRequest"
],
"optional_permissions": [
"bookmarks"
],
"commands": {
"_execute_browser_action": {
"suggested_key": {
"default": "Ctrl+Period",
"mac": "MacCtrl+Period"
},
"description": "Open containers panel"
}
},
"browser_action": {
"browser_style": true,
"default_icon": "img/container-site.svg",
"default_title": "Multi-Account Containers",
"default_popup": "popup.html",
"theme_icons": [
{
"light": "img/container-site-light.svg",
"dark": "img/container-site.svg",
"size": 32
}
]
},
"background": {
"page": "js/background/index.html"
},
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": [
"js/content-script.js"
],
"css": [
"css/content.css"
],
"run_at": "document_start"
}
],
"web_accessible_resources": [
"/img/container-site-d-24.png"
],
"options_ui": {
"page": "options.html"
}
}
+23
View File
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<form>
<label>
<input type="checkbox" id="bookmarksPermissions">
Enable Bookmark Menus
</label>
<p>This setting allows you to open a bookmark or folder of bookmarks in a container.</p>
<label>
<input type="checkbox" id="syncCheck">
Enable Sync
</label>
<p>This setting allows you to sync your containers and site assignments across devices.</p>
</form>
<script src="js/options.js"></script>
</body>
</html>
+62 -13
View File
@@ -1,8 +1,8 @@
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Containers browserAction Popup</title>
<link rel="stylesheet" href="/css/popup.css">
<title>Multi-Account Containers</title>
<link rel="stylesheet" href="css/popup.css">
</head>
<body>
@@ -13,7 +13,7 @@
<p>
Use containers to organize tasks, manage accounts, and keep your focus where you want it.
</p>
<a href="#" class="onboarding-button onboarding-start-button">Get Started</a>
<a href="#" class="onboarding-button onboarding-start-button" tabindex="0">Get Started</a>
</div>
<div class="hide panel onboarding security-onboarding-panel-1">
@@ -22,49 +22,97 @@
<p>
Use containers to organize tasks, manage accounts, and store sensitive data.
</p>
<a href="#" class="onboarding-button onboarding-start-button">Get Started</a>
<a href="#" class="onboarding-button onboarding-start-button" tabindex="0">Get Started</a>
</div>
<div class="panel onboarding onboarding-panel-2 hide">
<img class="onboarding-img" alt="How Containers Work" src="/img/onboarding-2.png" />
<h3 class="onboarding-title">Put containers to work for you.</h3>
<p>Features like color-coding and separate container tabs help you find things easily, focus your attention, and minimize distractions.</p>
<a href="#" class="onboarding-button onboarding-next-button">Next</a>
<a href="#" class="onboarding-button onboarding-next-button" tabindex="0">Next</a>
</div>
<div class="panel onboarding security-onboarding-panel-2 hide">
<img class="onboarding-img" alt="How Containers Work" src="/img/onboarding-2.png" />
<h3 class="onboarding-title">Put containers to work for you.</h3>
<p>Color-coding helps you categorize your online life, find things easily, and minimize distractions.</p>
<a href="#" class="onboarding-button onboarding-next-button">Next</a>
<a href="#" class="onboarding-button onboarding-next-button" tabindex="0">Next</a>
</div>
<div class="panel onboarding onboarding-panel-3 hide">
<img class="onboarding-img" alt="How Containers Work" src="/img/onboarding-3.png" />
<h3 class="onboarding-title">A place for everything, and everything in its place.</h3>
<p>Start with the containers we've created, or create your own.</p>
<a href="#" class="onboarding-button onboarding-almost-done-button">Next</a>
<a href="#" class="onboarding-button onboarding-almost-done-button" tabindex="0">Next</a>
</div>
<div class="panel onboarding security-onboarding-panel-3 hide">
<img class="onboarding-img" alt="How Containers Work" src="/img/onboarding-3-security.png" />
<h3 class="onboarding-title">Set boundaries for your browsing.</h3>
<p>Cookies are stored within a container, so you can segment sensitive data and browsing history to stay organized and to limit the impact of online trackers.</p>
<a href="#" class="onboarding-button onboarding-almost-done-button">Next</a>
<a href="#" class="onboarding-button onboarding-almost-done-button" tabindex="0">Next</a>
</div>
<div class="panel onboarding onboarding-panel-4 hide" id="onboarding-panel-4">
<img class="onboarding-img" alt="How to assign sites to containers" src="/img/onboarding-4.png" />
<h3 class="onboarding-title">Always open sites in the containers you want.</h3>
<p>Right-click inside a container tab to assign the site to always open in the container.</p>
<a href="#" id="onboarding-done-button" class="onboarding-button">Next</a>
<a href="#" id="onboarding-done-button" class="onboarding-button" tabindex="0">Next</a>
</div>
<div class="panel onboarding onboarding-panel-5 hide" id="onboarding-panel-5">
<img class="onboarding-img" alt="Long-press the New Tab button to create a new container tab." src="/img/onboarding-3.png" />
<h3 class="onboarding-title">Container tabs when you need them.</h3>
<p>Long-press the New Tab button to create a new container tab.</p>
<a href="#" id="onboarding-longpress-button" class="onboarding-button">Done</a>
<a href="#" id="onboarding-longpress-button" class="onboarding-button" tabindex="0">Next</a>
</div>
<div class="panel onboarding onboarding-panel-6 hide" id="onboarding-panel-6">
<img class="onboarding-img" alt="Syncing Containers is now Available!" src="/img/Sync.svg" />
<h3 class="onboarding-title">Syncing Containers is now Available!</h3>
<p>Turn on Sync to share container and site assignments with any computer connected to your Firefox Account.</p>
<div class="half-button-wrapper">
<a herf="#" id="no-sync" class="half-onboarding-button grey-button" tabindex="0">Not Now</a>
<a href="#" id="start-sync-button" class="half-onboarding-button" tabindex="0">Start Syncing</a>
</div>
</div>
<div class="panel onboarding onboarding-panel-7 hide" id="onboarding-panel-7">
<img class="onboarding-img" alt="Firefox Account is required to sync" src="/img/Account.svg" />
<h3 class="onboarding-title">Firefox Account is required to sync.</h3>
<p>Click Sign In to confirm that your Firefox Account is active.</p>
<div class="half-button-wrapper">
<a herf="#" id="no-sign-in" class="half-onboarding-button grey-button" tabindex="0">Not Now</a>
<a href="#" id="sign-in" class="half-onboarding-button" tabindex="0">Sign In</a>
</div>
</div>
<div class="panel achievement-panel hide" id="achievement-panel">
<img class="onboarding-img" alt="You achieved a Containers milestone!" src="/img/onboarding-3.png" />
<h3 class="onboarding-title">100 tabs!</h3>
<p>You've opened 100 Container tabs.</p>
<p>If you enjoy Containers, help us spread the word!</p>
<p class="share-ctas">
<a class="cta-link" href="https://mzl.la/2gJtIZ4" id="achievement-rate-button" target="_blank">
<span class="cta amo-rate-cta">
<img src="/img/amo-icon.svg" class="cta-icon" alt="addons.mozilla.org Icon">
Rate
</span>
</a>
<a class="cta-link" href="https://bit.ly/fb-share-mac-addon" target="_blank">
<span class="cta fb-share-cta">
<img src="/img/webicon-facebook.svg" class="cta-icon" alt="Facebook Icon">
Share
</span>
</a>
<a class="cta-link" href="http://bit.ly/tweet-100-tabs-mac-addon" target="_blank">
<span class="cta tweet-cta">
<img src="/img/webicon-twitter.svg" class="cta-icon" alt="Twitter Icon">
Tweet
</span>
</a>
</p>
<a href="#" id="achievement-done-button" class="onboarding-button">Done</a>
</div>
<div class="panel container-panel hide" id="container-panel">
@@ -132,8 +180,9 @@
</table>
</div>
<div class="panel-footer edit-containers-panel-footer">
<a href="#" id="exit-edit-mode-link" class="exit-edit-mode-link edit-containers-exit-text">Exit Edit Mode</a>
</div>
<a href="#" id="exit-edit-mode-link" class="exit-edit-mode-link edit-containers-exit-text">
<img src="/img/container-arrow.svg"/>Exit Edit Mode</a>
</div>
</div>
@@ -176,7 +225,7 @@
</div>
<div class="panel-content delete-container-confirm">
<h4 class="delete-container-confirm-title">Remove This Container</h4>
<p>If you remove this container now, <span id="delete-container-tab-count"></span> container tabs will be closed. Are you sure you want to remove this Container?</p>
<p><span id="delete-container-tab-warning"></span> Are you sure you want to remove this Container?</p>
</div>
<div class="panel-footer">
<a href="#" class="button expanded secondary footer-button cancel-button" id="delete-container-cancel-link">Cancel</a>
-40
View File
@@ -1,40 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
const self = require("sdk/self");
const { when: unload } = require("sdk/system/unload");
const shield = require("./lib/shield/index");
const surveyUrl = "https://www.surveygizmo.com/s3/3621810/shield-txp-containers";
const studyConfig = {
name: self.addonId,
days: 28,
surveyUrls: {
"end-of-study": surveyUrl,
"user-ended-study": surveyUrl,
ineligible: null,
},
variations: {
"control": () => {},
"securityOnboarding": () => {}
}
};
class ContainersStudy extends shield.Study {
isEligible () {
// If the user already has testpilot-containers extension, they are in the
// Test Pilot experiment, so exclude them.
return super.isEligible();
}
}
const thisStudy = new ContainersStudy(studyConfig);
if (self.id === "@shield-study-containers") {
unload((reason) => thisStudy.shutdown(reason));
}
exports.study = thisStudy;
+12
View File
@@ -0,0 +1,12 @@
module.exports = {
env: {
"node": true,
"mocha": true
},
"parserOptions": {
"ecmaVersion": 2018
},
"rules": {
"no-restricted-globals": ["error", "browser"]
}
}
+111
View File
@@ -0,0 +1,111 @@
if (!process.listenerCount("unhandledRejection")) {
// eslint-disable-next-line no-console
process.on("unhandledRejection", r => console.log(r));
}
const path = require("path");
const chai = require("chai");
const sinonChai = require("sinon-chai");
const crypto = require("crypto");
const sinon = require("sinon");
const expect = chai.expect;
chai.should();
chai.use(sinonChai);
const nextTick = () => {
return new Promise(resolve => {
setTimeout(() => {
process.nextTick(resolve);
});
});
};
const webExtensionsJSDOM = require("webextensions-jsdom");
const manifestPath = path.resolve(path.join(__dirname, "../src/manifest.json"));
const buildDom = async ({background = {}, popup = {}}) => {
background = {
...background,
jsdom: {
...background.jsom,
beforeParse(window) {
window.browser.permissions.getAll.resolves({permissions: ["bookmarks"]});
window.crypto = {
getRandomValues: arr => crypto.randomBytes(arr.length),
};
}
}
};
popup = {
...popup,
jsdom: {
...popup.jsdom,
pretendToBeVisual: true
}
};
const webExtension = await webExtensionsJSDOM.fromManifest(manifestPath, {
apiFake: true,
wiring: true,
sinon: global.sinon,
background,
popup
});
webExtension.browser = webExtension.background.browser;
return webExtension;
};
const buildBackgroundDom = background => {
return buildDom({
background,
popup: false
});
};
const buildPopupDom = popup => {
return buildDom({
popup,
background: false
});
};
const initializeWithTab = async (details = {
cookieStoreId: "firefox-default"
}) => {
let tab;
const webExtension = await buildDom({
background: {
async afterBuild(background) {
tab = await background.browser.tabs._create(details);
}
},
popup: {
jsdom: {
beforeParse(window) {
window.browser.storage.local.set({
"browserActionBadgesClicked": [],
"onboarding-stage": 7,
"achievements": [],
"syncEnabled": true
});
window.browser.storage.local.set.resetHistory();
window.browser.storage.sync.clear();
}
}
}
});
webExtension.tab = tab;
return webExtension;
};
module.exports = {
buildDom,
buildBackgroundDom,
buildPopupDom,
initializeWithTab,
sinon,
expect,
nextTick,
};
+77
View File
@@ -0,0 +1,77 @@
const {initializeWithTab} = require("../common");
describe("Assignment Feature", function () {
const url = "http://example.com";
beforeEach(async function () {
this.webExt = await initializeWithTab({
cookieStoreId: "firefox-container-1",
url
});
});
afterEach(function () {
this.webExt.destroy();
});
describe("click the 'Always open in' checkbox in the popup", function () {
beforeEach(async function () {
// popup click to set assignment for activeTab.url
await this.webExt.popup.helper.clickElementById("container-page-assigned");
});
describe("open new Tab with the assigned URL in the default container", function () {
let newTab;
beforeEach(async function () {
// new Tab opening activeTab.url in default container
newTab = await this.webExt.background.browser.tabs._create({
cookieStoreId: "firefox-default",
url
}, {
options: {
webRequestError: true // because request is canceled due to reopening
}
});
});
it("should open the confirm page", async function () {
// should have created a new tab with the confirm page
this.webExt.background.browser.tabs.create.should.have.been.calledWithMatch({
url: "moz-extension://fake/confirm-page.html?" +
`url=${encodeURIComponent(url)}` +
`&cookieStoreId=${this.webExt.tab.cookieStoreId}`,
cookieStoreId: undefined,
openerTabId: null,
index: 2,
active: true
});
});
it("should remove the new Tab that got opened in the default container", function () {
this.webExt.background.browser.tabs.remove.should.have.been.calledWith(newTab.id);
});
});
describe("click the 'Always open in' checkbox in the popup again", function () {
beforeEach(async function () {
// popup click to remove assignment for activeTab.url
await this.webExt.popup.helper.clickElementById("container-page-assigned");
});
describe("open new Tab with the no longer assigned URL in the default container", function () {
beforeEach(async function () {
// new Tab opening activeTab.url in default container
await this.webExt.background.browser.tabs._create({
cookieStoreId: "firefox-default",
url
});
});
it("should not open the confirm page", async function () {
// should not have created a new tab
this.webExt.background.browser.tabs.create.should.not.have.been.called;
});
});
});
});
});
+34
View File
@@ -0,0 +1,34 @@
const {initializeWithTab} = require("../common");
describe("Containers Management", function () {
beforeEach(async function () {
this.webExt = await initializeWithTab();
});
afterEach(function () {
this.webExt.destroy();
});
describe("creating a new container", function () {
beforeEach(async function () {
await this.webExt.popup.helper.clickElementById("container-add-link");
await this.webExt.popup.helper.clickElementById("edit-container-ok-link");
});
it("should create it in the browser as well", function () {
this.webExt.background.browser.contextualIdentities.create.should.have.been.calledOnce;
});
describe("removing it afterwards", function () {
beforeEach(async function () {
await this.webExt.popup.helper.clickElementById("edit-containers-link");
await this.webExt.popup.helper.clickElementByQuerySelectorAll(".delete-container-icon", "last");
await this.webExt.popup.helper.clickElementById("delete-container-ok-link");
});
it("should remove it in the browser as well", function () {
this.webExt.background.browser.contextualIdentities.remove.should.have.been.calledOnce;
});
});
});
});
@@ -0,0 +1,63 @@
const {expect, initializeWithTab} = require("../common");
describe("External Webextensions", function () {
const url = "http://example.com";
beforeEach(async function () {
this.webExt = await initializeWithTab({
cookieStoreId: "firefox-container-1",
url
});
await this.webExt.popup.helper.clickElementById("container-page-assigned");
});
afterEach(function () {
this.webExt.destroy();
});
describe("with contextualIdentities permissions", function () {
it("should be able to get assignments", async function () {
this.webExt.background.browser.management.get.resolves({
permissions: ["contextualIdentities"]
});
const message = {
method: "getAssignment",
url
};
const sender = {
id: "external-webextension"
};
const [promise] = this.webExt.background.browser.runtime.onMessageExternal.addListener.yield(message, sender);
const answer = await promise;
expect(answer.userContextId === "1").to.be.true;
expect(answer.neverAsk === false).to.be.true;
expect(
Object.prototype.hasOwnProperty.call(
answer, "identityMacAddonUUID")).to.be.true;
});
});
describe("without contextualIdentities permissions", function () {
it("should throw an error", async function () {
this.webExt.background.browser.management.get.resolves({
permissions: []
});
const message = {
method: "getAssignment",
url
};
const sender = {
id: "external-webextension"
};
const [promise] = this.webExt.background.browser.runtime.onMessageExternal.addListener.yield(message, sender);
return promise.catch(error => {
expect(error.message).to.equal("Missing contextualIdentities permission");
});
});
});
});
+465
View File
@@ -0,0 +1,465 @@
const {initializeWithTab} = require("../common");
describe("Sync", function() {
beforeEach(async function() {
this.webExt = await initializeWithTab();
this.syncHelper = new SyncTestHelper(this.webExt);
});
afterEach(function() {
this.webExt.destroy();
delete this.syncHelper;
});
it("testIdentityStateCleanup", async function() {
await this.syncHelper.stopSyncListeners();
await this.syncHelper.setState({}, LOCAL_DATA, TEST_CONTAINERS, []);
await this.webExt.browser.storage.local.set({
"identitiesState@@_firefox-container-5": {
"hiddenTabs": []
}
});
await this.webExt.background.window.identityState.storageArea.upgradeData();
const macConfigs = await this.webExt.browser.storage.local.get();
const identities = [];
for(const configKey of Object.keys(macConfigs)) {
if (configKey.includes("identitiesState@@_") && !configKey.includes("default")) {
identities.push(macConfigs[configKey]);
}
}
identities.should.have.lengthOf(5, "There should be 5 identity entries");
for (const identity of identities) {
(!!identity.macAddonUUID).should.be.true;
}
});
it("testAssignManagerCleanup", async function() {
await this.syncHelper.stopSyncListeners();
await this.syncHelper.setState({}, LOCAL_DATA, TEST_CONTAINERS, TEST_ASSIGNMENTS);
await this.webExt.browser.storage.local.set({
"siteContainerMap@@_www.goop.com": {
"userContextId": "999",
"neverAsk": true
}
});
await this.webExt.background.window.identityState.storageArea.upgradeData();
await this.webExt.background.window.assignManager.storageArea.upgradeData();
const macConfigs = await this.webExt.browser.storage.local.get();
const assignments = [];
for(const configKey of Object.keys(macConfigs)) {
if (configKey.includes("siteContainerMap@@_")) {
macConfigs[configKey].configKey = configKey;
assignments.push(macConfigs[configKey]);
}
}
assignments.should.have.lengthOf(5, "There should be 5 site assignments");
for (const assignment of assignments) {
(!!assignment.identityMacAddonUUID).should.be.true;
}
});
it("testReconcileSiteAssignments", async function() {
await this.syncHelper.stopSyncListeners();
await this.syncHelper.setState(
DUPE_TEST_SYNC,
LOCAL_DATA,
TEST_CONTAINERS,
SITE_ASSIGNMENT_TEST
);
// add 200ok (bad data).
const testSites = {
"siteContainerMap@@_developer.mozilla.org": {
"userContextId": "588",
"neverAsk": true,
"identityMacAddonUUID": "d20d7af2-9866-468e-bb43-541efe8c2c2e",
"hostname": "developer.mozilla.org"
},
"siteContainerMap@@_reddit.com": {
"userContextId": "592",
"neverAsk": true,
"identityMacAddonUUID": "3dc916fb-8c0a-4538-9758-73ef819a45f7",
"hostname": "reddit.com"
},
"siteContainerMap@@_twitter.com": {
"userContextId": "589",
"neverAsk": true,
"identityMacAddonUUID": "cdd73c20-c26a-4c06-9b17-735c1f5e9187",
"hostname": "twitter.com"
},
"siteContainerMap@@_www.facebook.com": {
"userContextId": "590",
"neverAsk": true,
"identityMacAddonUUID": "32cc4a9b-05ed-4e54-8e11-732468de62f4",
"hostname": "www.facebook.com"
},
"siteContainerMap@@_www.linkedin.com": {
"userContextId": "591",
"neverAsk": true,
"identityMacAddonUUID": "9ff381e3-4c11-420d-8e12-e352a3318be1",
"hostname": "www.linkedin.com"
},
"siteContainerMap@@_200ok.us": {
"userContextId": "1",
"neverAsk": true,
"identityMacAddonUUID": "b5f5f794-b37e-4cec-9f4e-6490df620336",
"hostname": "www.linkedin.com"
}
};
for (const site of Object.keys(testSites)) {
await this.webExt.browser.storage.sync.set({[site]:testSites[site]});
}
await this.webExt.browser.storage.sync.set({
deletedSiteList: ["siteContainerMap@@_www.google.com"]
});
await this.webExt.background.window.sync.runSync();
const assignedSites = await this.webExt.background.window.assignManager.storageArea.getAssignedSites();
Object.keys(assignedSites).should.have.lengthOf(6);
});
it("testInitialSync", async function() {
await this.syncHelper.stopSyncListeners();
await this.syncHelper.setState({}, LOCAL_DATA, TEST_CONTAINERS, []);
await this.webExt.background.window.sync.runSync();
const getAssignedSites =
await this.webExt.background.window.assignManager.storageArea.getAssignedSites();
const identities = await this.webExt.browser.contextualIdentities.query({});
identities.should.have.lengthOf(5, "There should be 5 identity entries");
Object.keys(getAssignedSites).should.have.lengthOf(0, "There should be no site assignments");
});
it("test2", async function() {
await this.syncHelper.stopSyncListeners();
await this.syncHelper.setState(SYNC_DATA, LOCAL_DATA, TEST_CONTAINERS, TEST_ASSIGNMENTS);
await this.webExt.background.window.sync.runSync();
const getAssignedSites =
await this.webExt.background.window.assignManager.storageArea.getAssignedSites();
const identities = await this.webExt.browser.contextualIdentities.query({});
identities.should.have.lengthOf(6, "There should be 6 identity entries");
Object.keys(getAssignedSites).should.have.lengthOf(5, "There should be 5 site assignments");
});
it("dupeTest", async function() {
await this.syncHelper.stopSyncListeners();
await this.syncHelper.setState(
DUPE_TEST_SYNC,
DUPE_TEST_LOCAL,
DUPE_TEST_IDENTS,
DUPE_TEST_ASSIGNMENTS
);
await this.webExt.background.window.sync.runSync();
const getAssignedSites =
await this.webExt.background.window.assignManager.storageArea.getAssignedSites();
const identities = await this.webExt.browser.contextualIdentities.query({});
identities.should.have.lengthOf(7, "There should be 7 identity entries");
Object.keys(getAssignedSites).should.have.lengthOf(5, "There should be 5 identity entries");
const personalContainer =
this.syncHelper.lookupIdentityBy(identities, {name: "Personal"});
(personalContainer.color === "red").should.be.true;
const mozillaContainer =
this.syncHelper.lookupIdentityBy(identities, {name: "Mozilla"});
(mozillaContainer.icon === "pet").should.be.true;
});
});
class SyncTestHelper {
constructor(webExt) {
this.webExt = webExt;
}
async stopSyncListeners() {
await this.webExt.browser.storage.onChanged.removeListener(this.webExt.background.window.sync.storageArea.onChangedListener);
await this.webExt.background.window.sync.removeContextualIdentityListeners();
}
async setState(syncData, localData, identityData, assignmentData){
await this.removeAllContainers();
await this.webExt.browser.storage.sync.clear();
await this.webExt.browser.storage.sync.set(syncData);
await this.webExt.browser.storage.local.clear();
await this.webExt.browser.storage.local.set(localData);
for (let i=0; i < identityData.length; i++) {
//build identities
const newIdentity =
await this.webExt.browser.contextualIdentities.create(identityData[i]);
// fill identies with site assignments
if (assignmentData && assignmentData[i]) {
const data = {
"userContextId":
String(
newIdentity.cookieStoreId.replace(/^firefox-container-/, "")
),
"neverAsk": true
};
await this.webExt.browser.storage.local.set({[assignmentData[i]]: data});
}
}
return;
}
async removeAllContainers() {
const identities = await this.webExt.browser.contextualIdentities.query({});
for (const identity of identities) {
await this.webExt.browser.contextualIdentities.remove(identity.cookieStoreId);
}
}
lookupIdentityBy(identities, options) {
for (const identity of identities) {
if (options && options.name) {
if (identity.name === options.name) return identity;
}
if (options && options.color) {
if (identity.color === options.color) return identity;
}
if (options && options.color) {
if (identity.color === options.color) return identity;
}
}
return false;
}
}
const TEST_CONTAINERS = [
{
name: "Personal",
color: "blue",
icon: "fingerprint"
},
{
name: "Banking",
color: "green",
icon: "dollar"
},
{
name: "Mozilla",
color: "red",
icon: "briefcase"
},
{
name: "Groceries, obviously",
color: "yellow",
icon: "cart"
},
{
name: "Facebook",
color: "toolbar",
icon: "fence"
},
];
const TEST_ASSIGNMENTS = [
"siteContainerMap@@_developer.mozilla.org",
"siteContainerMap@@_twitter.com",
"siteContainerMap@@_www.facebook.com",
"siteContainerMap@@_www.linkedin.com",
"siteContainerMap@@_reddit.com"
];
const LOCAL_DATA = {
"browserActionBadgesClicked": [ "6.2.0" ],
"containerTabsOpened": 7,
"identitiesState@@_firefox-default": { "hiddenTabs": [] },
"onboarding-stage": 5
};
const SYNC_DATA = {
"identity@@_22ded543-5173-44a5-a47a-8813535945ca": {
"name": "Personal",
"icon": "fingerprint",
"color": "red",
"cookieStoreId": "firefox-container-146",
"macAddonUUID": "22ded543-5173-44a5-a47a-8813535945ca"
},
"identity@@_63e5212f-0858-418e-b5a3-09c2dea61fcd": {
"name": "Oscar",
"icon": "dollar",
"color": "green",
"cookieStoreId": "firefox-container-147",
"macAddonUUID": "3e5212f-0858-418e-b5a3-09c2dea61fcd"
},
"identity@@_71335417-158e-4d74-a55b-e9e9081601ec": {
"name": "Mozilla",
"icon": "pet",
"color": "red",
"cookieStoreId": "firefox-container-148",
"macAddonUUID": "71335417-158e-4d74-a55b-e9e9081601ec"
},
"identity@@_59c4e5f7-fe3b-435a-ae60-1340db31a91b": {
"name": "Groceries, obviously",
"icon": "cart",
"color": "pink",
"cookieStoreId": "firefox-container-149",
"macAddonUUID": "59c4e5f7-fe3b-435a-ae60-1340db31a91b"
},
"identity@@_3dc916fb-8c0a-4538-9758-73ef819a45f7": {
"name": "Facebook",
"icon": "fence",
"color": "toolbar",
"cookieStoreId": "firefox-container-150",
"macAddonUUID": "3dc916fb-8c0a-4538-9758-73ef819a45f7"
}
};
const DUPE_TEST_SYNC = {
"identity@@_d20d7af2-9866-468e-bb43-541efe8c2c2e": {
"name": "Personal",
"icon": "fingerprint",
"color": "red",
"cookieStoreId": "firefox-container-588",
"macAddonUUID": "d20d7af2-9866-468e-bb43-541efe8c2c2e"
},
"identity@@_cdd73c20-c26a-4c06-9b17-735c1f5e9187": {
"name": "Big Bird",
"icon": "pet",
"color": "yellow",
"cookieStoreId": "firefox-container-589",
"macAddonUUID": "cdd73c20-c26a-4c06-9b17-735c1f5e9187"
},
"identity@@_32cc4a9b-05ed-4e54-8e11-732468de62f4": {
"name": "Mozilla",
"icon": "pet",
"color": "red",
"cookieStoreId": "firefox-container-590",
"macAddonUUID": "32cc4a9b-05ed-4e54-8e11-732468de62f4"
},
"identity@@_9ff381e3-4c11-420d-8e12-e352a3318be1": {
"name": "Groceries, obviously",
"icon": "cart",
"color": "pink",
"cookieStoreId": "firefox-container-591",
"macAddonUUID": "9ff381e3-4c11-420d-8e12-e352a3318be1"
},
"identity@@_3dc916fb-8c0a-4538-9758-73ef819a45f7": {
"name": "Facebook",
"icon": "fence",
"color": "toolbar",
"cookieStoreId": "firefox-container-592",
"macAddonUUID": "3dc916fb-8c0a-4538-9758-73ef819a45f7"
},
"identity@@_63e5212f-0858-418e-b5a3-09c2dea61fcd": {
"name": "Oscar",
"icon": "dollar",
"color": "green",
"cookieStoreId": "firefox-container-593",
"macAddonUUID": "63e5212f-0858-418e-b5a3-09c2dea61fcd"
},
"siteContainerMap@@_developer.mozilla.org": {
"userContextId": "588",
"neverAsk": true,
"identityMacAddonUUID": "d20d7af2-9866-468e-bb43-541efe8c2c2e",
"hostname": "developer.mozilla.org"
},
"siteContainerMap@@_reddit.com": {
"userContextId": "592",
"neverAsk": true,
"identityMacAddonUUID": "3dc916fb-8c0a-4538-9758-73ef819a45f7",
"hostname": "reddit.com"
},
"siteContainerMap@@_twitter.com": {
"userContextId": "589",
"neverAsk": true,
"identityMacAddonUUID": "cdd73c20-c26a-4c06-9b17-735c1f5e9187",
"hostname": "twitter.com"
},
"siteContainerMap@@_www.facebook.com": {
"userContextId": "590",
"neverAsk": true,
"identityMacAddonUUID": "32cc4a9b-05ed-4e54-8e11-732468de62f4",
"hostname": "www.facebook.com"
},
"siteContainerMap@@_www.linkedin.com": {
"userContextId": "591",
"neverAsk": true,
"identityMacAddonUUID": "9ff381e3-4c11-420d-8e12-e352a3318be1",
"hostname": "www.linkedin.com"
}
};
const DUPE_TEST_LOCAL = {
"beenSynced": true,
"browserActionBadgesClicked": [
"6.2.0"
],
"containerTabsOpened": 7,
"identitiesState@@_firefox-default": {
"hiddenTabs": []
},
"onboarding-stage": 5,
};
const DUPE_TEST_ASSIGNMENTS = [
"siteContainerMap@@_developer.mozilla.org",
"siteContainerMap@@_reddit.com",
"siteContainerMap@@_twitter.com",
"siteContainerMap@@_www.facebook.com",
"siteContainerMap@@_www.linkedin.com"
];
const SITE_ASSIGNMENT_TEST = [
"siteContainerMap@@_developer.mozilla.org",
"siteContainerMap@@_www.facebook.com",
"siteContainerMap@@_www.google.com",
"siteContainerMap@@_bugzilla.mozilla.org"
];
const DUPE_TEST_IDENTS = [
{
"name": "Personal",
"icon": "fingerprint",
"color": "blue",
},
{
"name": "Banking",
"icon": "pet",
"color": "green",
},
{
"name": "Mozilla",
"icon": "briefcase",
"color": "red",
},
{
"name": "Groceries, obviously",
"icon": "cart",
"color": "orange",
},
{
"name": "Facebook",
"icon": "fence",
"color": "toolbar",
},
{
"name": "Big Bird",
"icon": "dollar",
"color": "yellow",
}
];
+38
View File
@@ -0,0 +1,38 @@
const {expect, sinon, initializeWithTab} = require("../common");
describe("#1168", function () {
describe("when navigation happens too slow after opening new tab to a page which then redirects", function () {
let clock, tab, background;
beforeEach(async function () {
this.webExt = await initializeWithTab({
cookieStoreId: "firefox-container-1",
url: "https://bugzilla.mozilla.org"
});
await this.webExt.popup.helper.clickElementById("container-page-assigned");
clock = sinon.useFakeTimers();
tab = await this.webExt.browser.tabs._create({});
clock.tick(2000);
await background.browser.tabs._navigate(tab.id, "https://duckduckgo.com/?q=%21bugzilla+thing&t=ffab");
await background.browser.tabs._redirect(tab.id, [
"https://bugzilla.mozilla.org"
]);
});
afterEach(function () {
this.webExt.destroy();
clock.restore();
});
// Not solved yet
// See: https://github.com/mozilla/multi-account-containers/issues/1168#issuecomment-378394091
it.skip("should remove the old tab", async function () {
expect(background.browser.tabs.create).to.have.been.calledOnce;
expect(background.browser.tabs.remove).to.have.been.calledWith(tab.id);
});
});
});
+176
View File
@@ -0,0 +1,176 @@
const {expect, sinon, initializeWithTab} = require("../common");
describe("#940", function () {
describe("when other onBeforeRequestHandlers are faster and redirect with the same requestId", function () {
it("should not open two confirm pages", async function () {
const webExtension = await initializeWithTab({
cookieStoreId: "firefox-container-1",
url: "http://example.com"
});
await webExtension.popup.helper.clickElementById("container-page-assigned");
const responses = {};
await webExtension.background.browser.tabs._create({
url: "https://example.com"
}, {
options: {
webRequestRedirects: ["https://example.com"],
webRequestError: true,
instantRedirects: true
},
responses
});
const result = await responses.webRequest.onBeforeRequest[1];
expect(result).to.deep.equal({
cancel: true
});
webExtension.browser.tabs.create.should.have.been.calledOnce;
webExtension.destroy();
});
});
describe("when redirects change requestId midflight", function () {
beforeEach(async function () {
this.webExt = await initializeWithTab({
cookieStoreId: "firefox-container-1",
url: "https://www.youtube.com"
});
await this.webExt.popup.helper.clickElementById("container-page-assigned");
global.clock = sinon.useFakeTimers();
this.redirectedRequest = async (options = {}) => {
const newTabResponses = {};
const newTab = await this.webExt.browser.tabs._create({
url: "http://youtube.com"
}, {
options: Object.assign({
webRequestRedirects: [
"https://youtube.com",
"https://www.youtube.com",
{
url: "https://www.youtube.com",
webRequest: {
requestId: 2
}
}
],
webRequestError: true,
instantRedirects: true
}, options),
responses: newTabResponses
});
return [newTabResponses, newTab];
};
});
afterEach(function () {
this.webExt.destroy();
global.clock.restore();
});
it("should not open two confirm pages", async function () {
const [newTabResponses] = await this.redirectedRequest();
// http://youtube.com is not assigned, no cancel, no reopening
expect(await newTabResponses.webRequest.onBeforeRequest[0]).to.deep.equal({});
// https://youtube.com is not assigned, no cancel, no reopening
expect(await newTabResponses.webRequest.onBeforeRequest[1]).to.deep.equal({});
// https://www.youtube.com is assigned, this triggers reopening, cancel
expect(await newTabResponses.webRequest.onBeforeRequest[2]).to.deep.equal({
cancel: true
});
// https://www.youtube.com is assigned, this was a redirect, cancel early, no reopening
expect(await newTabResponses.webRequest.onBeforeRequest[3]).to.deep.equal({
cancel: true
});
this.webExt.background.browser.tabs.create.should.have.been.calledOnce;
});
it("should uncancel after webRequest.onCompleted", async function () {
const [newTabResponses, newTab] = await this.redirectedRequest();
// remove onCompleted listeners because in the real world this request would never complete
// and thus might trigger unexpected behavior because the tab gets removed when reopening
this.webExt.background.browser.webRequest.onCompleted.addListener = sinon.stub();
this.webExt.background.browser.tabs.create.resetHistory();
// we create a tab with the same id and use the same request id to see if uncanceled
await this.webExt.browser.tabs._create({
id: newTab.id,
url: "https://www.youtube.com"
}, {
options: {
webRequest: {
requestId: newTabResponses.webRequest.request.requestId
}
}
});
this.webExt.background.browser.tabs.create.should.have.been.calledOnce;
});
it("should uncancel after webRequest.onErrorOccurred", async function () {
const [newTabResponses, newTab] = await this.redirectedRequest();
this.webExt.background.browser.tabs.create.resetHistory();
// we create a tab with the same id and use the same request id to see if uncanceled
await this.webExt.browser.tabs._create({
id: newTab.id,
url: "https://www.youtube.com"
}, {
options: {
webRequest: {
requestId: newTabResponses.webRequest.request.requestId
},
webRequestError: true
}
});
this.webExt.background.browser.tabs.create.should.have.been.calledOnce;
});
it("should uncancel after 2 seconds", async function () {
const [newTabResponses, newTab] = await this.redirectedRequest({
webRequestDontYield: ["onCompleted", "onErrorOccurred"]
});
global.clock.tick(2000);
this.webExt.background.browser.tabs.create.resetHistory();
// we create a tab with the same id and use the same request id to see if uncanceled
await this.webExt.browser.tabs._create({
id: newTab.id,
url: "https://www.youtube.com"
}, {
options: {
webRequest: {
requestId: newTabResponses.webRequest.request.requestId
},
webRequestError: true
}
});
this.webExt.background.browser.tabs.create.should.have.been.calledOnce;
});
it("should not influence the canceled url in other tabs", async function () {
await this.redirectedRequest();
this.webExt.background.browser.tabs.create.resetHistory();
await this.webExt.browser.tabs._create({
cookieStoreId: "firefox-default",
url: "https://www.youtube.com"
}, {
options: {
webRequestError: true
}
});
this.webExt.background.browser.tabs.create.should.have.been.calledOnce;
});
});
});
-19
View File
@@ -1,19 +0,0 @@
const main = require("../");
exports["test main"] = function(assert) {
assert.pass("Unit test running!");
};
exports["test main async"] = function(assert, done) {
assert.pass("async Unit test running!");
done();
};
exports["test dummy"] = function(assert, done) {
main.dummy("foo", function(text) {
assert.ok((text === "foo"), "Is the text actually 'foo'");
done();
});
};
require("sdk/test").run(exports);
-336
View File
@@ -1,336 +0,0 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
const Experiment = require('./lib/testpilot/experiment');
const experiment = new Experiment();
/**
* Class that represents a metrics event broker. Events are sent to Google
* Analytics if the `tid` parameter is set. Events are sent to Mozilla's
* data pipeline via the Test Pilot add-on. No metrics code changes are
* needed when the experiment is added to or removed from Test Pilot.
* @constructor
* @param {string} $0.id - addon ID, e.g. '@testpilot-addon'. See https://mdn.io/add_on_id.
* @param {string} $0.version - addon version, e.g. '1.0.2'.
* @param {string} [$0.uid] - unique identifier for a specific instance of an addon.
* Optional, but required to send events to Google Analytics. Sent to Google Analytics
* but not Mozilla services.
* @param {string} [$0.tid] - Google Analytics tracking ID. Optional, but required
* to send events to Google Analytics.
* @param {string} [$0.type=webextension] - addon type. one of: 'webextension',
* 'sdk', 'bootstrapped'.
* @param {boolean} [$0.debug=false] - if true, enables logging. Note that this
* value can be changed on a running instance, by modifying its `debug` property.
* @throws {SyntaxError} If the required properties are missing, or if the
* 'type' property is unrecognized.
* @throws {Error} if initializing the transports fails.
*/
function Metrics({id, version, uid, tid = null, type = 'webextension', debug = false}) {
if (!id) {
throw new SyntaxError(`'id' property is required.`);
} else if (!version) {
throw new SyntaxError(`'version' property is required.`);
} else if (tid && !uid) {
throw new SyntaxError(`'uid' property is required to send events to Google Analytics.`);
}
if (!['webextension', 'sdk', 'bootstrapped'].includes(type)) {
throw new SyntaxError(`'type' property must be one of: 'webextension', 'sdk', or 'bootstrapped'`);
}
Object.assign(this, {id, uid, version, tid, type, debug});
// The test pilot add-on uses its own nsIObserverService topic for sending
// pings to Telemetry. Otherwise, the topic is based on add-on type.
if (id === '@testpilot-addon') {
this.topic = 'testpilot';
} else if (type === 'webextension') {
this.topic = 'testpilot-telemetry';
} else {
this.topic = 'testpilottest';
}
// NOTE: order is important here. _initTransports uses console.log, which may
// not be available before _initConsole has run.
this._initConsole();
this._initTransports();
this.sendEvent = this.sendEvent.bind(this);
this._log(`Initialized topic to ${this.topic}`);
if (!tid) {
this._log(`Google Analytics disabled: 'tid' value not passed to constructor.`);
} else {
this._log(`Google Analytics enabled for Tracking ID ${tid}.`);
}
this._log('Constructor finished successfully.');
}
Metrics.prototype = {
/**
* Sends an event to the Mozilla data pipeline (and Google Analytics, if
* a `tid` was passed to the constructor). Note: to avoid breaking callers,
* if sending the event fails, no Errors will be thrown. Instead, the message
* will be silently dropped, and, if debug mode is enabled, an error will be
* logged to the Browser Console.
*
* If you want to pass extra fields to GA, or use a GA hit type other than
* `Event`, you can transform the output data object yourself using the
* `transform` parameter. You will need to add Custom Dimensions to GA for any
* extra fields: https://support.google.com/analytics/answer/2709828. Note
* that, by convention, the `variant` argument is mapped to the first Custom
* Dimension (`cd1`) when constructing the GA Event hit.
*
* Note: the data object format is currently different for each experiment,
* and should be defined based on the result of conversations with the Mozilla
* data team.
*
* A suggested default format is:
* @param {string} [$0.method] - What is happening? e.g. `click`
* @param {string} [$0.object] - What is being affected? e.g. `home-button-1`
* @param {string} [$0.category=interactions] - If you want to add a category
* for easy reporting later. e.g. `mainmenu`
* @param {string} [$0.variant=null] - An identifying string if you're running
* different variants. e.g. `cohort-A`
* @param {function} [transform] - Transform function used to alter the
* parameters sent to GA. The `transform` function signature is
* `transform(input, output)`, where `input` is the object passed to
* `sendEvent` (excluding `transform`), and `output` is the default GA
* object generated by the `_gaTransform` method. The `transform` function
* should return an object whose keys are GA Measurement Protocol parameters.
* The returned object will be form encoded and sent to GA.
*/
sendEvent: function(params = {}, transform) {
const args = this._clone(params);
args.object = params.object || null;
args.category = params.category || 'interactions';
args.variant = params.variant || null;
this._log(`sendEvent called with method = ${args.method}, object = ${args.object}, category = ${args.category}, variant = ${args.variant}.`);
const clientData = this._clone(args);
const gaData = this._clone(args);
if (!clientData) {
this._error(`Unable to process data object. Dropping packet.`);
return;
}
this._sendToClient(clientData);
if (this.tid && this.uid) {
const defaultEvent = this._gaTransform(gaData);
let userEvent;
if (transform) {
userEvent = transform.call(null, gaData, defaultEvent);
}
this._gaSend(userEvent || defaultEvent);
}
},
/**
* Clone a data object by serializing / deserializing it.
* @private
* @param {object} o - Object to be cloned.
* @returns A clone of the object, or `null` if cloning failed.
*/
_clone: function(o) {
let cloned;
try {
cloned = JSON.parse(JSON.stringify(o));
} catch (ex) {
this._error(`Unable to clone object: ${ex}.`);
return null;
}
return cloned;
},
/**
* Sends an event to the Mozilla data pipeline via the Test Pilot add-on.
* Uses BroadcastChannel for WebExtensions, and nsIObserverService for other
* add-on types.
* @private
* @param {object} params - Entire object sent to `sendEvent`.
*/
_sendToClient: function(params) {
if (this.type === 'webextension') {
this._channel.postMessage(params);
this._log(`Sent client message via postMessage: ${params}`);
} else {
let stringified;
try {
stringified = JSON.stringify(params);
} catch(ex) {
this._error(`Unable to serialize metrics event: ${ex}`);
return;
}
const subject = {
wrappedJSObject: {
observersModuleSubjectWrapper: true,
object: this.id
}
};
try {
Services.obs.notifyObservers(subject, 'testpilot::send-metric', stringified);
this._log(`Sent client message via nsIObserverService: ${stringified}`);
} catch (ex) {
this._error(`Failed to send nsIObserver client ping: ${ex}`);
return;
}
}
},
/**
* Transforms `sendEvent()` arguments into a Google Analytics `Event` hit.
* @private
* @param {string} method - see `sendEvent` docs
* @param {string} [object] - see `sendEvent` docs
* @param {string} category - see `sendEvent` docs. Note that `category` is
* required here, assuming the default value was filled in by `sendEvent()`.
* @param {string} variant - see `sendEvent` docs. Note that `variant` is
* required here, assuming the default value was filled in by `sendEvent()`.
*/
_gaTransform: function({method, object, category, variant}) {
const data = {
v: 1,
an: this.id,
av: this.version,
tid: this.tid,
uid: this.uid,
t: 'event',
ec: category,
ea: method
};
if (object) {
data.el = object;
}
if (variant) {
data.cd1 = variant;
}
return data;
},
/**
* Encodes and sends an event message to Google Analytics.
* @private
* @param {object} msg - An object whose keys correspond to parameters in the
* Google Analytics Measurement Protocol.
*/
_gaSend: function(msg) {
const encoded = this._formEncode(msg);
const GA_URL = 'https://ssl.google-analytics.com/collect';
if (this.type === 'webextension') {
navigator.sendBeacon(GA_URL, encoded);
} else {
// SDK and bootstrapped types might not have a window reference, so get
// the sendBeacon DOM API from the hidden window.
Services.appShell.hiddenDOMWindow.navigator.sendBeacon(GA_URL, encoded);
}
this._log(`Sent GA message: ${encoded}`);
},
/**
* URL encodes an object. Encodes spaces as '%20', not '+', following the
* GA docs.
*
* @example
* // returns 'a=b&foo=b%20ar'
* metrics._formEncode({a: 'b', foo: 'b ar'});
* @private
* @param {Object} obj - Any JS object
* @returns {string}
*/
_formEncode: function(obj) {
const params = [];
if (!obj) { return ''; }
Object.keys(obj).forEach(item => {
const encoded = encodeURIComponent(item) + '=' + encodeURIComponent(obj[item]);
params.push(encoded);
});
return params.join('&');
},
/**
* Initializes transports used for sending messages. For WebExtensions,
* creates a `BroadcastChannel` (transport for client pings). WebExtensions
* use navigator.sendBeacon for GA transport, and they always have access
* to DOM APIs, so there's no setup work required. For other types, loads
* `Services.jsm`, which exposes the nsIObserverService (transport for client
* pings), and exposes the navigator.sendBeacon API (GA transport) via the
* appShell service's hidden window.
* @private
* @throws {Error} if transport setup unexpectedly fails
*/
_initTransports: function() {
if (this.type === 'webextension') {
try {
this._channel = new BroadcastChannel(this.topic);
} catch(ex) {
throw new Error(`Unable to create BroadcastChannel: ${ex}`);
}
} else if (this.type === 'sdk') {
try {
const { Cu } = require('chrome');
Cu.import('resource://gre/modules/Services.jsm');
} catch(ex) {
throw new Error(`Unable to load Services.jsm: ${ex}`);
}
} else { /* this.type === 'bootstrapped' */
try {
Components.utils.import('resource://gre/modules/Services.jsm');
} catch(ex) {
throw new Error(`Unable to load Services.jsm: ${ex}`);
}
}
this._log('Successfully initialized transports.');
},
/**
* Initializes a console for 'bootstrapped' add-ons.
* @private
*/
_initConsole: function() {
if (this.type === 'bootstrapped') {
try {
Components.utils.import('resource://gre/modules/Console.jsm');
this._log('Successfully initialized console.');
} catch(ex) {
throw new Error(`Unable to initialize console: ${ex}`);
}
}
},
/**
* Logs messages to the console. Only enabled if `this.debug` is truthy.
* @private
* @param {string} msg - A message
*/
_log: function(msg) {
if (this.debug) {
console.log(msg); // eslint-disable-line no-console
}
},
/**
* Logs errors to the console. Only enabled if `this.debug` is truthy.
* @private
* @param {string} msg - An error message
*/
_error: function(msg) {
if (this.debug) {
console.error(msg); // eslint-disable-line no-console
}
}
};
// WebExtensions don't support CommonJS module style, so 'module' might not be
// defined.
if (typeof module !== 'undefined') {
module.exports = Metrics;
}
// Export the Metrics constructor in Gecko JSM style, for legacy addons
// that use the JSM loader. See also: https://mdn.io/jsm/using
const EXPORTED_SYMBOLS = ['Metrics']; // eslint-disable-line no-unused-vars
-746
View File
@@ -1,746 +0,0 @@
const MAJOR_VERSIONS = ["2.3.0", "2.4.0"];
const LOOKUP_KEY = "$ref";
const assignManager = {
MENU_ASSIGN_ID: "open-in-this-container",
MENU_REMOVE_ID: "remove-open-in-this-container",
storageArea: {
area: browser.storage.local,
exemptedTabs: {},
getSiteStoreKey(pageUrl) {
const url = new window.URL(pageUrl);
const storagePrefix = "siteContainerMap@@_";
return `${storagePrefix}${url.hostname}`;
},
setExempted(pageUrl, tabId) {
const siteStoreKey = this.getSiteStoreKey(pageUrl);
if (!(siteStoreKey in this.exemptedTabs)) {
this.exemptedTabs[siteStoreKey] = [];
}
this.exemptedTabs[siteStoreKey].push(tabId);
},
removeExempted(pageUrl) {
const siteStoreKey = this.getSiteStoreKey(pageUrl);
this.exemptedTabs[siteStoreKey] = [];
},
isExempted(pageUrl, tabId) {
const siteStoreKey = this.getSiteStoreKey(pageUrl);
if (!(siteStoreKey in this.exemptedTabs)) {
return false;
}
return this.exemptedTabs[siteStoreKey].includes(tabId);
},
get(pageUrl) {
const siteStoreKey = this.getSiteStoreKey(pageUrl);
return new Promise((resolve, reject) => {
this.area.get([siteStoreKey]).then((storageResponse) => {
if (storageResponse && siteStoreKey in storageResponse) {
resolve(storageResponse[siteStoreKey]);
}
resolve(null);
}).catch((e) => {
reject(e);
});
});
},
set(pageUrl, data, exemptedTabIds) {
const siteStoreKey = this.getSiteStoreKey(pageUrl);
if (exemptedTabIds) {
exemptedTabIds.forEach((tabId) => {
this.setExempted(pageUrl, tabId);
});
}
return this.area.set({
[siteStoreKey]: data
});
},
remove(pageUrl) {
const siteStoreKey = this.getSiteStoreKey(pageUrl);
// When we remove an assignment we should clear all the exemptions
this.removeExempted(pageUrl);
return this.area.remove([siteStoreKey]);
},
async deleteContainer(userContextId) {
const sitesByContainer = await this.getByContainer(userContextId);
this.area.remove(Object.keys(sitesByContainer));
},
async getByContainer(userContextId) {
const sites = {};
const siteConfigs = await this.area.get();
Object.keys(siteConfigs).forEach((key) => {
// For some reason this is stored as string... lets check them both as that
if (String(siteConfigs[key].userContextId) === String(userContextId)) {
const site = siteConfigs[key];
// In hindsight we should have stored this
// TODO file a follow up to clean the storage onLoad
site.hostname = key.replace(/^siteContainerMap@@_/, "");
sites[key] = site;
}
});
return sites;
}
},
_neverAsk(m) {
const pageUrl = m.pageUrl;
if (m.neverAsk === true) {
// If we have existing data and for some reason it hasn't been deleted etc lets update it
this.storageArea.get(pageUrl).then((siteSettings) => {
if (siteSettings) {
siteSettings.neverAsk = true;
this.storageArea.set(pageUrl, siteSettings);
}
}).catch((e) => {
throw e;
});
}
},
// We return here so the confirm page can load the tab when exempted
async _exemptTab(m) {
const pageUrl = m.pageUrl;
this.storageArea.setExempted(pageUrl, m.tabId);
return true;
},
init() {
browser.contextMenus.onClicked.addListener((info, tab) => {
this._onClickedHandler(info, tab);
});
// Before a request is handled by the browser we decide if we should route through a different container
browser.webRequest.onBeforeRequest.addListener((options) => {
if (options.frameId !== 0 || options.tabId === -1) {
return {};
}
this.removeContextMenu();
return Promise.all([
browser.tabs.get(options.tabId),
this.storageArea.get(options.url)
]).then(([tab, siteSettings]) => {
const userContextId = this.getUserContextIdFromCookieStore(tab);
if (!siteSettings
|| userContextId === siteSettings.userContextId
|| tab.incognito
|| this.storageArea.isExempted(options.url, tab.id)) {
return {};
}
this.reloadPageInContainer(options.url, userContextId, siteSettings.userContextId, tab.index + 1, siteSettings.neverAsk);
this.calculateContextMenu(tab);
/* Removal of existing tabs:
We aim to open the new assigned container tab / warning prompt in it's own tab:
- As the history won't span from one container to another it seems most sane to not try and reopen a tab on history.back()
- When users open a new tab themselves we want to make sure we don't end up with three tabs as per: https://github.com/mozilla/testpilot-containers/issues/421
If we are coming from an internal url that are used for the new tab page (NEW_TAB_PAGES), we can safely close as user is unlikely losing history
Detecting redirects on "new tab" opening actions is pretty hard as we don't get tab history:
- Redirects happen from Short URLs and tracking links that act as a gateway
- Extensions don't provide a way to history crawl for tabs, we could inject content scripts to do this
however they don't run on about:blank so this would likely be just as hacky.
We capture the time the tab was created and close if it was within the timeout to try to capture pages which haven't had user interaction or history.
*/
if (backgroundLogic.NEW_TAB_PAGES.has(tab.url)
|| (messageHandler.lastCreatedTab
&& messageHandler.lastCreatedTab.id === tab.id)) {
browser.tabs.remove(tab.id);
}
return {
cancel: true,
};
}).catch((e) => {
throw e;
});
},{urls: ["<all_urls>"], types: ["main_frame"]}, ["blocking"]);
},
async _onClickedHandler(info, tab) {
const userContextId = this.getUserContextIdFromCookieStore(tab);
// Mapping ${URL(info.pageUrl).hostname} to ${userContextId}
if (userContextId) {
// let actionName;
let remove;
if (info.menuItemId === this.MENU_ASSIGN_ID) {
remove = false;
} else {
remove = true;
}
await this._setOrRemoveAssignment(tab.id, info.pageUrl, userContextId, remove);
}
},
deleteContainer(userContextId) {
this.storageArea.deleteContainer(userContextId);
},
getUserContextIdFromCookieStore(tab) {
if (!("cookieStoreId" in tab)) {
return false;
}
const cookieStore = tab.cookieStoreId;
const container = cookieStore.replace("firefox-container-", "");
if (container !== cookieStore) {
return container;
}
return false;
},
isTabPermittedAssign(tab) {
// Ensure we are not an important about url
// Ensure we are not in incognito mode
const url = new URL(tab.url);
if (url.protocol === "about:"
|| url.protocol === "moz-extension:"
|| tab.incognito) {
return false;
}
return true;
},
async _setOrRemoveAssignment(tabId, pageUrl, userContextId, remove) {
let actionName;
// https://github.com/mozilla/testpilot-containers/issues/626
// Context menu has stored context IDs as strings, so we need to coerce
// the value to a string for accurate checking
userContextId = String(userContextId);
if (!remove) {
const tabs = await browser.tabs.query({});
const assignmentStoreKey = this.storageArea.getSiteStoreKey(pageUrl);
const exemptedTabIds = tabs.filter((tab) => {
const tabStoreKey = this.storageArea.getSiteStoreKey(tab.url);
/* Auto exempt all tabs that exist for this hostname that are not in the same container */
if (tabStoreKey === assignmentStoreKey &&
this.getUserContextIdFromCookieStore(tab) !== userContextId) {
return true;
}
return false;
}).map((tab) => {
return tab.id;
});
await this.storageArea.set(pageUrl, {
userContextId,
neverAsk: false
}, exemptedTabIds);
actionName = "added";
} else {
await this.storageArea.remove(pageUrl);
actionName = "removed";
}
browser.tabs.sendMessage(tabId, {
text: `Successfully ${actionName} site to always open in this container`
});
backgroundLogic.sendTelemetryPayload({
event: `${actionName}-container-assignment`,
userContextId: userContextId,
});
const tab = await browser.tabs.get(tabId);
this.calculateContextMenu(tab);
},
async _getAssignment(tab) {
const cookieStore = this.getUserContextIdFromCookieStore(tab);
// Ensure we have a cookieStore to assign to
if (cookieStore
&& this.isTabPermittedAssign(tab)) {
return await this.storageArea.get(tab.url);
}
return false;
},
_getByContainer(userContextId) {
return this.storageArea.getByContainer(userContextId);
},
removeContextMenu() {
// There is a focus issue in this menu where if you change window with a context menu click
// you get the wrong menu display because of async
// See: https://bugzilla.mozilla.org/show_bug.cgi?id=1215376#c16
// We also can't change for always private mode
// See: https://bugzilla.mozilla.org/show_bug.cgi?id=1352102
browser.contextMenus.remove(this.MENU_ASSIGN_ID);
browser.contextMenus.remove(this.MENU_REMOVE_ID);
},
async calculateContextMenu(tab) {
this.removeContextMenu();
const siteSettings = await this._getAssignment(tab);
// Return early and not add an item if we have false
// False represents assignment is not permitted
if (siteSettings === false) {
return false;
}
// ✓ This is to mitigate https://bugzilla.mozilla.org/show_bug.cgi?id=1351418
let prefix = " "; // Alignment of non breaking space, unknown why this requires so many spaces to align with the tick
let menuId = this.MENU_ASSIGN_ID;
const tabUserContextId = this.getUserContextIdFromCookieStore(tab);
if (siteSettings &&
Number(siteSettings.userContextId) === Number(tabUserContextId)) {
prefix = "✓";
menuId = this.MENU_REMOVE_ID;
}
browser.contextMenus.create({
id: menuId,
title: `${prefix} Always Open in This Container`,
checked: true,
contexts: ["all"],
});
},
reloadPageInContainer(url, currentUserContextId, userContextId, index, neverAsk = false) {
const cookieStoreId = backgroundLogic.cookieStoreId(userContextId);
const loadPage = browser.extension.getURL("confirm-page.html");
// False represents assignment is not permitted
// If the user has explicitly checked "Never Ask Again" on the warning page we will send them straight there
if (neverAsk) {
browser.tabs.create({url, cookieStoreId, index});
backgroundLogic.sendTelemetryPayload({
event: "auto-reload-page-in-container",
userContextId: userContextId,
});
} else {
backgroundLogic.sendTelemetryPayload({
event: "prompt-to-reload-page-in-container",
userContextId: userContextId,
});
let confirmUrl = `${loadPage}?url=${encodeURIComponent(url)}&cookieStoreId=${cookieStoreId}`;
let currentCookieStoreId;
if (currentUserContextId) {
currentCookieStoreId = backgroundLogic.cookieStoreId(currentUserContextId);
confirmUrl += `&currentCookieStoreId=${currentCookieStoreId}`;
}
browser.tabs.create({
url: confirmUrl,
cookieStoreId: currentCookieStoreId,
index
}).then(() => {
// We don't want to sync this URL ever nor clutter the users history
browser.history.deleteUrl({url: confirmUrl});
}).catch((e) => {
throw e;
});
}
}
};
const backgroundLogic = {
NEW_TAB_PAGES: new Set([
"about:startpage",
"about:newtab",
"about:home",
"about:blank"
]),
deleteContainer(userContextId) {
this.sendTelemetryPayload({
event: "delete-container",
userContextId
});
const removeTabsPromise = this._containerTabs(userContextId).then((tabs) => {
const tabIds = tabs.map((tab) => tab.id);
return browser.tabs.remove(tabIds);
});
return new Promise((resolve) => {
removeTabsPromise.then(() => {
const removed = browser.contextualIdentities.remove(this.cookieStoreId(userContextId));
removed.then(() => {
assignManager.deleteContainer(userContextId);
browser.runtime.sendMessage({
method: "forgetIdentityAndRefresh"
}).then(() => {
resolve({done: true, userContextId});
}).catch((e) => {throw e;});
}).catch((e) => {throw e;});
}).catch((e) => {throw e;});
});
},
createOrUpdateContainer(options) {
let donePromise;
if (options.userContextId !== "new") {
donePromise = browser.contextualIdentities.update(
this.cookieStoreId(options.userContextId),
options.params
);
this.sendTelemetryPayload({
event: "edit-container",
userContextId: options.userContextId
});
} else {
donePromise = browser.contextualIdentities.create(options.params);
this.sendTelemetryPayload({
event: "add-container"
});
}
return donePromise.then(() => {
browser.runtime.sendMessage({
method: "refreshNeeded"
});
});
},
openTab(options) {
let url = options.url || undefined;
const userContextId = ("userContextId" in options) ? options.userContextId : 0;
const active = ("nofocus" in options) ? options.nofocus : true;
const source = ("source" in options) ? options.source : null;
// Only send telemetry for tabs opened by UI - i.e., not via showTabs
if (source && userContextId) {
this.sendTelemetryPayload({
"event": "open-tab",
"eventSource": source,
"userContextId": userContextId,
"clickedContainerTabCount": LOOKUP_KEY
});
}
// Autofocus url bar will happen in 54: https://bugzilla.mozilla.org/show_bug.cgi?id=1295072
// We can't open new tab pages, so open a blank tab. Used in tab un-hide
if (this.NEW_TAB_PAGES.has(url)) {
url = undefined;
}
// Unhide all hidden tabs
browser.runtime.sendMessage({
method: "showTabs",
userContextId: options.userContextId
});
return browser.tabs.create({
url,
active,
pinned: options.pinned || false,
cookieStoreId: backgroundLogic.cookieStoreId(options.userContextId)
});
},
sendTelemetryPayload(message = {}) {
if (!message.event) {
throw new Error("Missing event name for telemetry");
}
message.method = "sendTelemetryPayload";
browser.runtime.sendMessage(message);
},
cookieStoreId(userContextId) {
return `firefox-container-${userContextId}`;
},
_containerTabs(userContextId) {
return browser.tabs.query({
cookieStoreId: this.cookieStoreId(userContextId)
}).catch((e) => {throw e;});
},
};
const messageHandler = {
// After the timer completes we assume it's a tab the user meant to keep open
// We use this to catch redirected tabs that have just opened
// If this were in platform we would change how the tab opens based on "new tab" link navigations such as ctrl+click
LAST_CREATED_TAB_TIMER: 2000,
init() {
// Handles messages from webextension code
browser.runtime.onMessage.addListener((m) => {
let response;
switch (m.method) {
case "deleteContainer":
response = backgroundLogic.deleteContainer(m.message.userContextId);
break;
case "createOrUpdateContainer":
response = backgroundLogic.createOrUpdateContainer(m.message);
break;
case "openTab":
// Same as open-tab for index.js
response = backgroundLogic.openTab(m.message);
break;
case "neverAsk":
assignManager._neverAsk(m);
break;
case "getAssignment":
response = browser.tabs.get(m.tabId).then((tab) => {
return assignManager._getAssignment(tab);
});
break;
case "getAssignmentObjectByContainer":
response = assignManager._getByContainer(m.message.userContextId);
break;
case "setOrRemoveAssignment":
// m.tabId is used for where to place the in content message
// m.url is the assignment to be removed/added
response = browser.tabs.get(m.tabId).then((tab) => {
return assignManager._setOrRemoveAssignment(tab.id, m.url, m.userContextId, m.value);
});
break;
case "exemptContainerAssignment":
response = assignManager._exemptTab(m);
break;
}
return response;
});
// Handles messages from sdk code
const port = browser.runtime.connect();
port.onMessage.addListener(m => {
switch (m.type) {
case "lightweight-theme-changed":
themeManager.update(m.message);
break;
case "open-tab":
backgroundLogic.openTab(m.message);
break;
default:
throw new Error(`Unhandled message type: ${m.message}`);
}
});
browser.tabs.onCreated.addListener((tab) => {
// This works at capturing the tabs as they are created
// However we need onFocusChanged and onActivated to capture the initial tab
if (tab.id === -1) {
return {};
}
tabPageCounter.initTabCounter(tab);
});
browser.tabs.onRemoved.addListener((tabId) => {
if (tabId === -1) {
return {};
}
tabPageCounter.sendTabCountAndDelete(tabId);
});
browser.tabs.onActivated.addListener((info) => {
assignManager.removeContextMenu();
browser.tabs.get(info.tabId).then((tab) => {
tabPageCounter.initTabCounter(tab);
assignManager.calculateContextMenu(tab);
}).catch((e) => {
throw e;
});
});
browser.windows.onFocusChanged.addListener((windowId) => {
assignManager.removeContextMenu();
// browserAction loses background color in new windows ...
// https://bugzil.la/1314674
// https://github.com/mozilla/testpilot-containers/issues/608
// ... so re-call displayBrowserActionBadge on window changes
displayBrowserActionBadge();
browser.tabs.query({active: true, windowId}).then((tabs) => {
if (tabs && tabs[0]) {
tabPageCounter.initTabCounter(tabs[0]);
assignManager.calculateContextMenu(tabs[0]);
}
}).catch((e) => {
throw e;
});
});
browser.idle.onStateChanged.addListener((newState) => {
browser.tabs.query({}).then(tabs => {
for (let tab of tabs) { // eslint-disable-line prefer-const
if (newState === "idle") {
tabPageCounter.sendTabCountAndDelete(tab.id, "user-went-idle");
} else if (newState === "active" && tab.active) {
tabPageCounter.initTabCounter(tab);
}
}
}).catch(e => {
throw e;
});
});
browser.webRequest.onCompleted.addListener((details) => {
if (details.frameId !== 0 || details.tabId === -1) {
return {};
}
assignManager.removeContextMenu();
browser.tabs.get(details.tabId).then((tab) => {
tabPageCounter.incrementTabCount(tab);
assignManager.calculateContextMenu(tab);
}).catch((e) => {
throw e;
});
}, {urls: ["<all_urls>"], types: ["main_frame"]});
// lets remember the last tab created so we can close it if it looks like a redirect
browser.tabs.onCreated.addListener((details) => {
this.lastCreatedTab = details;
setTimeout(() => {
this.lastCreatedTab = null;
}, this.LAST_CREATED_TAB_TIMER);
});
}
};
const themeManager = {
existingTheme: null,
init() {
this.check();
},
setPopupIcon(theme) {
let icons = {
16: "img/container-site-d-24.png",
32: "img/container-site-d-48.png"
};
if (theme === "firefox-compact-dark@mozilla.org") {
icons = {
16: "img/container-site-w-24.png",
32: "img/container-site-w-48.png"
};
}
browser.browserAction.setIcon({
path: icons
});
},
check() {
browser.runtime.sendMessage({
method: "getTheme"
}).then((theme) => {
this.update(theme);
}).catch(() => {
throw new Error("Unable to get theme");
});
},
update(theme) {
if (this.existingTheme !== theme) {
this.setPopupIcon(theme);
this.existingTheme = theme;
}
}
};
const tabPageCounter = {
counters: {},
initTabCounter(tab) {
if (tab.id in this.counters) {
if (!("activity" in this.counters[tab.id])) {
this.counters[tab.id].activity = {
"cookieStoreId": tab.cookieStoreId,
"pageRequests": 0
};
}
if (!("tab" in this.counters[tab.id])) {
this.counters[tab.id].tab = {
"cookieStoreId": tab.cookieStoreId,
"pageRequests": 0
};
}
} else {
this.counters[tab.id] = {};
this.counters[tab.id].tab = {
"cookieStoreId": tab.cookieStoreId,
"pageRequests": 0
};
this.counters[tab.id].activity = {
"cookieStoreId": tab.cookieStoreId,
"pageRequests": 0
};
}
},
sendTabCountAndDelete(tabId, why = "user-closed-tab") {
if (!(this.counters[tabId])) {
return;
}
if (why === "user-closed-tab" && this.counters[tabId].tab) {
backgroundLogic.sendTelemetryPayload({
event: "page-requests-completed-per-tab",
userContextId: this.counters[tabId].tab.cookieStoreId,
pageRequestCount: this.counters[tabId].tab.pageRequests
});
// When we send the ping because the user closed the tab,
// delete both the 'tab' and 'activity' counters
delete this.counters[tabId];
} else if (why === "user-went-idle" && this.counters[tabId].activity) {
backgroundLogic.sendTelemetryPayload({
event: "page-requests-completed-per-activity",
userContextId: this.counters[tabId].activity.cookieStoreId,
pageRequestCount: this.counters[tabId].activity.pageRequests
});
// When we send the ping because the user went idle,
// only reset the 'activity' counter
this.counters[tabId].activity = {
"cookieStoreId": this.counters[tabId].tab.cookieStoreId,
"pageRequests": 0
};
}
},
incrementTabCount(tab) {
this.counters[tab.id].tab.pageRequests++;
this.counters[tab.id].activity.pageRequests++;
}
};
assignManager.init();
themeManager.init();
// Lets do this last as theme manager did a check before connecting before
messageHandler.init();
browser.runtime.sendMessage({
method: "getPreference",
pref: "browser.privatebrowsing.autostart"
}).then(pbAutoStart => {
// We don't want to disable the addon if we are in auto private-browsing.
if (!pbAutoStart) {
browser.tabs.onCreated.addListener(tab => {
if (tab.incognito) {
disableAddon(tab.id);
}
});
browser.tabs.query({}).then(tabs => {
for (let tab of tabs) { // eslint-disable-line prefer-const
if (tab.incognito) {
disableAddon(tab.id);
}
}
}).catch(() => {});
}
}).catch(() => {});
function disableAddon(tabId) {
browser.browserAction.disable(tabId);
browser.browserAction.setTitle({ tabId, title: "Containers disabled in Private Browsing Mode" });
}
async function getExtensionInfo() {
const manifestPath = browser.extension.getURL("manifest.json");
const response = await fetch(manifestPath);
const extensionInfo = await response.json();
return extensionInfo;
}
async function displayBrowserActionBadge() {
const extensionInfo = await getExtensionInfo();
const storage = await browser.storage.local.get({browserActionBadgesClicked: []});
if (MAJOR_VERSIONS.indexOf(extensionInfo.version) > -1 &&
storage.browserActionBadgesClicked.indexOf(extensionInfo.version) < 0) {
browser.browserAction.setBadgeBackgroundColor({color: "rgba(0,217,0,255)"});
browser.browserAction.setBadgeText({text: "NEW"});
}
}
displayBrowserActionBadge();
-71
View File
@@ -1,71 +0,0 @@
{
"manifest_version": 2,
"name": "Containers Experiment",
"version": "2.5.0",
"description": "Containers works by isolating cookie jars using separate origin-attributes defined visually by colored Container Tabs. This add-on is a modified version of the containers feature for Firefox Test Pilot.",
"icons": {
"48": "img/container-site-d-48.png",
"96": "img/container-site-d-96.png"
},
"applications": {
"gecko": {
"strict_min_version": "51.0",
"update_url": "https://testpilot.firefox.com/files/@testpilot-containers/updates.json"
}
},
"homepage_url": "https://testpilot.firefox.com/",
"permissions": [
"<all_urls>",
"activeTab",
"cookies",
"contextMenus",
"contextualIdentities",
"history",
"idle",
"storage",
"tabs",
"webRequestBlocking",
"webRequest"
],
"commands": {
"_execute_browser_action": {
"suggested_key": {
"default": "Ctrl+Period",
"mac": "MacCtrl+Period"
},
"description": "Open containers panel"
}
},
"browser_action": {
"browser_style": true,
"default_icon": {
"16": "img/container-site-d-24.png",
"32": "img/container-site-d-48.png"
},
"default_title": "Containers",
"default_popup": "popup.html"
},
"background": {
"scripts": ["background.js"]
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["js/content-script.js"],
"css": ["css/content.css"],
"run_at": "document_start"
}
],
"web_accessible_resources": [
"/img/container-site-d-24.png"
]
}