1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-19 15:57:42 +01:00

never option on save login notification

closes #85
This commit is contained in:
Kyle Spearrin 2017-06-13 13:59:16 -04:00
parent a598f08dce
commit 34696ed85f
8 changed files with 115 additions and 9 deletions

View File

@ -655,6 +655,10 @@
"message": "Yes, Save Now", "message": "Yes, Save Now",
"description": "Yes, Save Now" "description": "Yes, Save Now"
}, },
"notificationNeverSave": {
"message": "Never for this website",
"description": "Never for this website"
},
"disableContextMenuItem": { "disableContextMenuItem": {
"message": "Disable Context Menu Options", "message": "Disable Context Menu Options",
"description": "Disable Context Menu Options" "description": "Disable Context Menu Options"

View File

@ -72,6 +72,9 @@ chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
else if (msg.command === 'bgAddSave') { else if (msg.command === 'bgAddSave') {
saveAddLogin(sender.tab); saveAddLogin(sender.tab);
} }
else if (msg.command === 'bgNeverSave') {
saveNever(sender.tab);
}
else if (msg.command === 'collectPageDetailsResponse') { else if (msg.command === 'collectPageDetailsResponse') {
if (msg.contentScript) { if (msg.contentScript) {
var forms = autofillService.getFormsWithPasswordFields(msg.details); var forms = autofillService.getFormsWithPasswordFields(msg.details);
@ -487,6 +490,22 @@ function saveAddLogin(tab) {
} }
} }
function saveNever(tab) {
for (var i = loginsToAdd.length - 1; i >= 0; i--) {
if (loginsToAdd[i].tabId === tab.id) {
var loginToAdd = loginsToAdd[i];
var tabDomain = utilsService.getDomain(tab.url);
if (tabDomain && tabDomain === loginToAdd.domain) {
loginsToAdd.splice(i, 1);
var hostname = utilsService.getHostname(tab.url);
loginService.saveNeverDomain(hostname);
messageTab(tab.id, 'closeNotificationBar');
}
}
}
}
function checkLoginsToAdd(tab, callback) { function checkLoginsToAdd(tab, callback) {
if (!loginsToAdd.length) { if (!loginsToAdd.length) {
if (callback) { if (callback) {

View File

@ -4,6 +4,12 @@
barType = null; barType = null;
if (window.location.hostname.indexOf('bitwarden.com') === -1) { if (window.location.hostname.indexOf('bitwarden.com') === -1) {
chrome.storage.local.get('neverDomains', function (obj) {
var domains = obj['neverDomains'];
if (domains && domains.hasOwnProperty(window.location.hostname)) {
return;
}
chrome.storage.local.get('disableAddLoginNotification', function (obj) { chrome.storage.local.get('disableAddLoginNotification', function (obj) {
if (!obj || !obj['disableAddLoginNotification']) { if (!obj || !obj['disableAddLoginNotification']) {
chrome.runtime.sendMessage({ chrome.runtime.sendMessage({
@ -11,6 +17,7 @@
}); });
} }
}); });
});
} }
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) { chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {

View File

@ -54,7 +54,7 @@ img {
padding: 5px 0; padding: 5px 0;
} }
button { button:not(.link) {
background-color: #3c8dbc; background-color: #3c8dbc;
padding: 5px 15px; padding: 5px 15px;
border-radius: 3px; border-radius: 3px;
@ -62,7 +62,20 @@ button {
border: 0; border: 0;
} }
button:hover { button:not(.link):hover {
cursor: pointer; cursor: pointer;
background-color: #3681ad; background-color: #3681ad;
} }
button.link {
background: none;
padding: 5px 15px;
color: #3c8dbc;
border: 0;
}
button.link:hover {
cursor: pointer;
background: none;
text-decoration: underline;
}

View File

@ -28,7 +28,8 @@
<tbody> <tbody>
<tr> <tr>
<td class="add-text"></td> <td class="add-text"></td>
<td align="right" width="150"> <td align="right" width="300">
<button class="never-save link"></button>
<button class="add-save"></button> <button class="add-save"></button>
</td> </td>
</tr> </tr>

View File

@ -6,13 +6,15 @@
$('#logo-link').attr('title', chrome.i18n.getMessage('appName')); $('#logo-link').attr('title', chrome.i18n.getMessage('appName'));
closeButton.attr('title', chrome.i18n.getMessage('close')); closeButton.attr('title', chrome.i18n.getMessage('close'));
$('#template-add .add-save').text(chrome.i18n.getMessage('notificationAddSave')); $('#template-add .add-save').text(chrome.i18n.getMessage('notificationAddSave'));
$('#template-add .never-save').text(chrome.i18n.getMessage('notificationNeverSave'));
$('#template-add .add-text').text(chrome.i18n.getMessage('notificationAddDesc')); $('#template-add .add-text').text(chrome.i18n.getMessage('notificationAddDesc'));
if (getQueryVariable('add')) { if (getQueryVariable('add')) {
setContent(document.getElementById('template-add')); setContent(document.getElementById('template-add'));
var add = $('#template-add-clone'), var add = $('#template-add-clone'),
addButton = $('#template-add-clone .add-save'); addButton = $('#template-add-clone .add-save'),
neverButton = $('#template-add-clone .never-save');
$(addButton).click(function (e) { $(addButton).click(function (e) {
e.preventDefault(); e.preventDefault();
@ -20,6 +22,13 @@
command: 'bgAddSave' command: 'bgAddSave'
}); });
}); });
$(neverButton).click(function (e) {
e.preventDefault();
chrome.runtime.sendMessage({
command: 'bgNeverSave'
});
});
} }
else if (getQueryVariable('info')) { else if (getQueryVariable('info')) {
setContent(document.getElementById('template-alert')); setContent(document.getElementById('template-alert'));

View File

@ -323,6 +323,32 @@ function initLoginService() {
return deferred.promise; return deferred.promise;
}; };
LoginService.prototype.saveNeverDomain = function (domain) {
var deferred = Q.defer();
var neverKey = 'neverDomains';
if (!domain) {
deferred.resolve();
}
else {
chrome.storage.local.get(neverKey, function (obj) {
var domains = obj[neverKey];
if (!domains) {
domains = {};
}
domains[domain] = null;
obj[neverKey] = domains;
chrome.storage.local.set(obj, function () {
deferred.resolve();
});
});
}
return deferred.promise;
};
function handleError(error, deferred) { function handleError(error, deferred) {
deferred.reject(error); deferred.reject(error);
} }

View File

@ -173,6 +173,33 @@ function initUtilsService() {
return null; return null;
} }
UtilsService.prototype.getHostname = function (uriString) {
if (!uriString) {
return null;
}
uriString = uriString.trim();
if (uriString === '') {
return null;
}
if (uriString.startsWith('http://') || uriString.startsWith('https://')) {
try {
var url = new URL(uriString);
if (!url || !url.hostname) {
return null;
}
return url.hostname;
}
catch (e) {
return null;
}
}
return null;
}
function validIpAddress(ipString) { function validIpAddress(ipString) {
var ipRegex = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/; var ipRegex = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
return ipRegex.test(ipString); return ipRegex.test(ipString);