1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 15:53:27 +00:00

refactor autofill. add auto-fill on page load

This commit is contained in:
Kyle Spearrin
2017-08-28 13:00:46 -04:00
parent c40465f292
commit ad544e5240
12 changed files with 225 additions and 111 deletions

View File

@@ -6,7 +6,6 @@ angular
$scope.i18n = i18nService;
var pageDetails = [],
tabId = null,
url = null,
domain = null,
canAutofill = false;
@@ -22,7 +21,6 @@ angular
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
if (tabs.length > 0) {
url = tabs[0].url;
tabId = tabs[0].id;
}
else {
$scope.loaded = true;
@@ -37,9 +35,10 @@ angular
return;
}
chrome.tabs.sendMessage(tabId, { command: 'collectPageDetails', tabId: tabId }, function () {
canAutofill = true;
});
chrome.tabs.sendMessage(tabs[0].id,
{ command: 'collectPageDetails', tab: tabs[0], sender: 'currentController' }, function () {
canAutofill = true;
});
$q.when(loginService.getAllDecryptedForDomain(domain)).then(function (logins) {
$scope.loaded = true;
@@ -68,49 +67,18 @@ angular
};
$scope.fillLogin = function (login) {
var didAutofill = false;
if (login && canAutofill && pageDetails && pageDetails.length) {
for (var i = 0; i < pageDetails.length; i++) {
if (pageDetails[i].tabId !== tabId) {
continue;
}
var fillScript = autofillService.generateFillScript(pageDetails[i].details, login.username, login.password);
if (tabId && fillScript && fillScript.script && fillScript.script.length) {
didAutofill = true;
$analytics.eventTrack('Autofilled');
chrome.tabs.sendMessage(tabId, {
command: 'fillForm',
fillScript: fillScript
}, { frameId: pageDetails[i].frameId }, function () {
if (login.totp && tokenService.getPremium()) {
totpService.isAutoCopyEnabled().then(function (enabled) {
if (enabled) {
return totpService.getCode(login.totp);
}
return null;
}).then(function (code) {
if (code) {
utilsService.copyToClipboard(code);
}
$window.close();
});
}
else {
$window.close();
}
});
}
}
}
if (!didAutofill) {
if (!canAutofill) {
$analytics.eventTrack('Autofilled Error');
toastr.error(i18nService.autofillError);
}
autofillService.doAutoFill(login, pageDetails, false).then(function () {
$analytics.eventTrack('Autofilled');
$window.close();
}, function () {
$analytics.eventTrack('Autofilled Error');
toastr.error(i18nService.autofillError);
});
};
$scope.viewLogin = function (login) {

View File

@@ -38,7 +38,7 @@ angular
else if (msg.command === 'collectPageDetailsResponse') {
$scope.$broadcast('collectPageDetailsResponse', {
frameId: sender.frameId,
tabId: msg.tabId,
tab: msg.tab,
details: msg.details
});
}

View File

@@ -7,6 +7,14 @@
$scope.disableGa = false;
$scope.disableAddLoginNotification = false;
$scope.disableContextMenuItem = false;
$scope.disableAutoTotpCopy = false;
$scope.enableAutoFillOnPageLoad = false;
chrome.storage.local.get(constantsService.enableAutoFillOnPageLoadKey, function (obj) {
$timeout(function () {
$scope.enableAutoFillOnPageLoad = obj && obj[constantsService.enableAutoFillOnPageLoadKey] === true;
});
});
chrome.storage.local.get(constantsService.disableGaKey, function (obj) {
$timeout(function () {
@@ -145,4 +153,27 @@
});
});
};
$scope.updateAutoFillOnPageLoad = function () {
chrome.storage.local.get(constantsService.enableAutoFillOnPageLoadKey, function (obj) {
if (obj[constantsService.enableAutoFillOnPageLoadKey]) {
// disable
obj[constantsService.enableAutoFillOnPageLoadKey] = false;
}
else {
// enable
$analytics.eventTrack('Enable Auto-fill Page Load');
obj[constantsService.enableAutoFillOnPageLoadKey] = true;
}
chrome.storage.local.set(obj, function () {
$timeout(function () {
$scope.enableAutoFillOnPageLoad = obj[constantsService.enableAutoFillOnPageLoadKey];
});
if (!obj[constantsService.enableAutoFillOnPageLoadKey]) {
$analytics.eventTrack('Disable Auto-fill Page Load');
}
});
});
};
});

View File

@@ -6,6 +6,19 @@
</div>
<div class="content">
<div class="list">
<div class="list-section">
<div class="list-section-items">
<div class="list-section-item list-section-item-checkbox">
<label for="totp-copy">{{i18n.enableAutoFillOnPageLoad}}</label>
<input id="totp-copy" type="checkbox" ng-model="enableAutoFillOnPageLoad"
ng-change="updateAutoFillOnPageLoad()">
</div>
</div>
<div class="list-section-footer">
{{i18n.enableAutoFillOnPageLoadDesc}}
<b>{{i18n.warning}}</b>: {{i18n.experimentalFeature}}
</div>
</div>
<div class="list-section">
<div class="list-section-items">
<div class="list-section-item list-section-item-checkbox">