Fix race conditions (#371)

This commit is contained in:
Sami Vänttinen 2019-01-11 15:59:30 +02:00 committed by Janek Bevendorff
parent 36b33af6b4
commit c33f276e0a
3 changed files with 80 additions and 68 deletions

View file

@ -18,74 +18,6 @@ var _observerIds = [];
// Document URL
let _documentURL = document.location.href;
browser.runtime.onMessage.addListener(function(req, sender, callback) {
if ('action' in req) {
if (req.action === 'fill_user_pass_with_specific_login') {
if (cip.credentials[req.id]) {
let combination = null;
if (cip.u) {
cip.setValueWithChange(cip.u, cip.credentials[req.id].login);
combination = cipFields.getCombination('username', cip.u);
browser.runtime.sendMessage({
action: 'page_set_login_id', args: [req.id]
});
cip.u.focus();
}
if (cip.p) {
cip.setValueWithChange(cip.p, cip.credentials[req.id].password);
browser.runtime.sendMessage({
action: 'page_set_login_id', args: [req.id]
});
combination = cipFields.getCombination('password', cip.p);
}
let list = [];
if (cip.fillInStringFields(combination.fields, cip.credentials[req.id].stringFields, list)) {
cipForm.destroy(false, {'password': list.list[0], 'username': list.list[1]});
}
}
} else if (req.action === 'fill_user_pass') {
_called.manualFillRequested = 'both';
cip.receiveCredentialsIfNecessary().then((response) => {
cip.fillInFromActiveElement(false);
});
} else if (req.action === 'fill_pass_only') {
_called.manualFillRequested = 'pass';
cip.receiveCredentialsIfNecessary().then((response) => {
cip.fillInFromActiveElement(false, true); // passOnly to true
});
} else if (req.action === 'fill_totp') {
cip.receiveCredentialsIfNecessary().then((response) => {
cip.fillInFromActiveElementTOTPOnly(false);
});
} else if (req.action === 'activate_password_generator') {
cip.initPasswordGenerator(cipFields.getAllFields());
} else if (req.action === 'remember_credentials') {
cip.contextMenuRememberCredentials();
} else if (req.action === 'choose_credential_fields') {
cipDefine.init();
} else if (req.action === 'clear_credentials') {
cipEvents.clearCredentials();
return Promise.resolve();
} else if (req.action === 'activated_tab') {
cipEvents.triggerActivatedTab();
return Promise.resolve();
} else if (req.action === 'redetect_fields') {
browser.runtime.sendMessage({
action: 'load_settings',
}).then((response) => {
cip.settings = response;
cip.initCredentialFields(true);
});
} else if (req.action === 'ignore-site') {
cip.ignoreSite(req.args);
}
else if (req.action === 'check_database_hash' && 'hash' in req) {
cip.detectDatabaseChange(req.hash);
}
}
});
function _f(fieldId) {
const field = (fieldId) ? jQuery('input[data-cip-id=\''+fieldId+'\']:first') : [];
return (field.length > 0) ? field : null;
@ -1485,6 +1417,7 @@ cip.initCredentialFields = function(forceCall) {
}
if (cip.settings.autoRetrieveCredentials && _called.retrieveCredentials === false && (cip.url && cip.submitUrl)) {
_called.retrieveCredentials = true;
browser.runtime.sendMessage({
action: 'retrieve_credentials',
args: [ cip.url, cip.submitUrl ]

View file

@ -58,6 +58,16 @@
],
"run_at": "document_idle",
"all_frames": true
},
{
"matches": [
"<all_urls>"
],
"js": [
"requests.js"
],
"run_at": "document_idle",
"all_frames": false
}
],
"commands": {

View file

@ -0,0 +1,69 @@
'use strict';
browser.runtime.onMessage.addListener(function(req, sender) {
if ('action' in req) {
if (req.action === 'fill_user_pass_with_specific_login') {
if (cip.credentials[req.id]) {
let combination = null;
if (cip.u) {
cip.setValueWithChange(cip.u, cip.credentials[req.id].login);
combination = cipFields.getCombination('username', cip.u);
browser.runtime.sendMessage({
action: 'page_set_login_id', args: [req.id]
});
cip.u.focus();
}
if (cip.p) {
cip.setValueWithChange(cip.p, cip.credentials[req.id].password);
browser.runtime.sendMessage({
action: 'page_set_login_id', args: [req.id]
});
combination = cipFields.getCombination('password', cip.p);
}
let list = [];
if (cip.fillInStringFields(combination.fields, cip.credentials[req.id].stringFields, list)) {
cipForm.destroy(false, {'password': list.list[0], 'username': list.list[1]});
}
}
} else if (req.action === 'fill_user_pass') {
_called.manualFillRequested = 'both';
cip.receiveCredentialsIfNecessary().then((response) => {
cip.fillInFromActiveElement(false);
});
} else if (req.action === 'fill_pass_only') {
_called.manualFillRequested = 'pass';
cip.receiveCredentialsIfNecessary().then((response) => {
cip.fillInFromActiveElement(false, true); // passOnly to true
});
} else if (req.action === 'fill_totp') {
cip.receiveCredentialsIfNecessary().then((response) => {
cip.fillInFromActiveElementTOTPOnly(false);
});
} else if (req.action === 'activate_password_generator') {
cip.initPasswordGenerator(cipFields.getAllFields());
} else if (req.action === 'remember_credentials') {
cip.contextMenuRememberCredentials();
} else if (req.action === 'choose_credential_fields') {
cipDefine.init();
} else if (req.action === 'clear_credentials') {
cipEvents.clearCredentials();
return Promise.resolve();
} else if (req.action === 'activated_tab') {
cipEvents.triggerActivatedTab();
return Promise.resolve();
} else if (req.action === 'redetect_fields') {
browser.runtime.sendMessage({
action: 'load_settings',
}).then((response) => {
cip.settings = response;
cip.initCredentialFields(true);
});
} else if (req.action === 'ignore-site') {
cip.ignoreSite(req.args);
}
else if (req.action === 'check_database_hash' && 'hash' in req) {
cip.detectDatabaseChange(req.hash);
}
}
});