From 74dff3942729db495a718309d0c0353e24151a46 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 14 Sep 2016 00:16:43 -0400 Subject: [PATCH] Load filtered sites for current tab. setup content script to collect and fill form data via message passing. --- src/content.js | 1 + src/formDataContent.js | 85 ++++++++++++++++++++++ src/manifest.json | 13 ++++ src/popup/app/current/currentController.js | 76 ++++++++++++++++++- src/popup/app/current/currentModule.js | 2 +- src/popup/app/current/views/current.html | 20 ++++- src/popup/app/vault/vaultController.js | 2 +- 7 files changed, 193 insertions(+), 6 deletions(-) create mode 100644 src/content.js create mode 100644 src/formDataContent.js diff --git a/src/content.js b/src/content.js new file mode 100644 index 0000000000..26fda6942b --- /dev/null +++ b/src/content.js @@ -0,0 +1 @@ +console.log('content script for ' + document.URL); diff --git a/src/formDataContent.js b/src/formDataContent.js new file mode 100644 index 0000000000..6673a9e774 --- /dev/null +++ b/src/formDataContent.js @@ -0,0 +1,85 @@ +/* +1Password Extension + +Lovingly handcrafted by Dave Teare, Michael Fey, Rad Azzouz, and Roustem Karimov. +Copyright (c) 2014 AgileBits. All rights reserved. + +================================================================================ + +Copyright (c) 2014 AgileBits Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +function collect(document, undefined) { + document.elementsByOPID={};document.addEventListener('input',function(c){!1!==c.a&&'input'===c.target.tagName.toLowerCase()&&(c.target.dataset['com.agilebits.onepassword.userEdited']='yes')},!0); + function r(c,e){function b(a,g){var d=a[g];if('string'==typeof d)return d;d=a.getAttribute(g);return'string'==typeof d?d:null}function h(a,g){if(-1===['text','password'].indexOf(g.type.toLowerCase())||!(n.test(a.value)||n.test(a.htmlID)||n.test(a.htmlName)||n.test(a.placeholder)||n.test(a['label-tag'])||n.test(a['label-data'])||n.test(a['label-aria'])))return!1;if(!a.visible)return!0;if('password'==g.type.toLowerCase())return!1;var d=g.type;w(g,!0);return d!==g.type}function p(a){switch(q(a.type)){case 'checkbox':return a.checked? + '✓':'';case 'hidden':a=a.value;if(!a||'number'!=typeof a.length)return'';254\\?]/mg,''):null;return[d?d:null,a.value]}),{options:a}):null}function s(a){var c;for(a=a.parentElement||a.parentNode;a&&'td'!=q(a.tagName);)a=a.parentElement||a.parentNode;if(!a|| + void 0===a)return null;c=a.parentElement||a.parentNode;if('tr'!=c.tagName.toLowerCase())return null;c=c.previousElementSibling;if(!c||'tr'!=(c.tagName+'').toLowerCase()||c.cells&&a.cellIndex>=c.cells.length)return null;a=c.cells[a.cellIndex];a=a.textContent||a.innerText;return a=y(a)}function t(a){var g,d=[];if(a.labels&&a.labels.length&&0c.clientWidth||10>c.clientHeight)return!1;var t=c.getClientRects();if(0===t.length)return!1;for(var f=0;fh||0>s.right)return!1;if(0>m||m>h||0>e||e>p)return!1;for(b=c.ownerDocument.elementFromPoint(m+(b.right>window.innerWidth?(window.innerWidth-m)/2:b.width/2),e+(b.bottom>window.innerHeight? + (window.innerHeight-e)/2:b.height/2));b&&b!==c&&b!==document;){if(b.tagName&&'string'===typeof b.tagName&&'label'===b.tagName.toLowerCase()&&c.labels&&0 0) { + url = tabs[0].url + id = tabs[0].id + } + var domain = tldjs.getDomain(url); + $scope.sites = []; + if (!domain) { + return; + } + + chrome.tabs.sendMessage(id, { text: 'collectFormData' }, function (formData) { + var filteredPromises = [], + filteredSites = [], + promises = [], + decSites = []; + + siteService.getAll(function (sites) { + for (var i = 0; i < sites.length; i++) { + var uriPromise = cipherService.decrypt(sites[i].uri, i); + filteredPromises.push(uriPromise); + uriPromise.then(function (obj) { + if (!obj.val) { + return; + } + + var siteDomain = tldjs.getDomain(obj.val); + if (!siteDomain || siteDomain != domain) { + return; + } + + filteredSites.push(obj.index); + }); + } + + $q.all(filteredPromises).then(function () { + for (var j = 0; j < filteredSites.length; j++) { + var index = filteredSites[j]; + decSites.push({ + id: sites[index].id, + folderId: sites[index].folderId, + favorite: sites[index].favorite + }); + + var namePromise = cipherService.decrypt(sites[index].name, j); + promises.push(namePromise); + namePromise.then(function (obj) { + decSites[obj.index].name = obj.val; + }); + + var usernamePromise = cipherService.decrypt(sites[index].username, j); + promises.push(usernamePromise); + usernamePromise.then(function (obj) { + decSites[obj.index].username = obj.val; + }); + + var passwordPromise = cipherService.decrypt(sites[index].password, j); + promises.push(passwordPromise); + passwordPromise.then(function (obj) { + decSites[obj.index].password = obj.val; + }); + } + + $q.all(promises).then(function () { + $scope.sites = decSites; + }); + }); + }); + }); + }); }); diff --git a/src/popup/app/current/currentModule.js b/src/popup/app/current/currentModule.js index 8adaee27b3..3334a742ac 100644 --- a/src/popup/app/current/currentModule.js +++ b/src/popup/app/current/currentModule.js @@ -1,2 +1,2 @@ angular - .module('bit.current', []); + .module('bit.current', ['toastr', 'ngclipboard']); diff --git a/src/popup/app/current/views/current.html b/src/popup/app/current/views/current.html index e45e5d94b2..d85b154ab8 100644 --- a/src/popup/app/current/views/current.html +++ b/src/popup/app/current/views/current.html @@ -1,6 +1,22 @@ 
-
Current Sites
+
Current Tab Sites
- Some content for your current sites. +
+
+
+ + + + + + + {{site.name}} + {{site.username}} +
+
+
diff --git a/src/popup/app/vault/vaultController.js b/src/popup/app/vault/vaultController.js index 56ed20c3c1..d56d2eaad0 100644 --- a/src/popup/app/vault/vaultController.js +++ b/src/popup/app/vault/vaultController.js @@ -1,7 +1,7 @@ angular .module('bit.vault') - .controller('vaultController', function ($scope, $rootScope, siteService, folderService, $q, cipherService, $state, $stateParams, $uibModal, toastr) { + .controller('vaultController', function ($scope, $rootScope, siteService, folderService, $q, cipherService, $state, $stateParams, toastr) { $('#search').focus(); var delayLoad = true;