1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-30 13:03:53 +01:00

centralize fillByOpid

This commit is contained in:
Kyle Spearrin 2019-04-20 21:29:13 -04:00
parent bfb87dbd15
commit 200fa80260
2 changed files with 18 additions and 22 deletions

2
jslib

@ -1 +1 @@
Subproject commit bc43c68eb98799c8b9e30a1dd8f60431dc1236c6 Subproject commit a0a1142f1f3152aea2abf3ca51feffa21e60e9a9

View File

@ -263,9 +263,7 @@ export default class AutofillService implements AutofillServiceInterface {
} }
filledFields[field.opid] = field; filledFields[field.opid] = field;
fillScript.script.push(['click_on_opid', field.opid]); this.fillByOpid(fillScript, field, val);
fillScript.script.push(['focus_by_opid', field.opid]);
fillScript.script.push(['fill_by_opid', field.opid, val]);
} }
}); });
} }
@ -379,9 +377,7 @@ export default class AutofillService implements AutofillServiceInterface {
} }
filledFields[u.opid] = u; filledFields[u.opid] = u;
fillScript.script.push(['click_on_opid', u.opid]); this.fillByOpid(fillScript, u, login.username);
fillScript.script.push(['focus_by_opid', u.opid]);
fillScript.script.push(['fill_by_opid', u.opid, login.username]);
}); });
passwords.forEach((p) => { passwords.forEach((p) => {
@ -390,10 +386,7 @@ export default class AutofillService implements AutofillServiceInterface {
} }
filledFields[p.opid] = p; filledFields[p.opid] = p;
fillScript.script.push(['click_on_opid', p.opid]); this.fillByOpid(fillScript, p, login.password);
fillScript.script.push(['focus_by_opid', p.opid]);
const passwordLength: number = p.maxLength && p.maxLength > 0 ? p.maxLength : login.password.length;
fillScript.script.push(['fill_by_opid', p.opid, login.password.substring(0, passwordLength)]);
}); });
fillScript = this.setFillScriptForFocus(filledFields, fillScript); fillScript = this.setFillScriptForFocus(filledFields, fillScript);
@ -507,9 +500,7 @@ export default class AutofillService implements AutofillServiceInterface {
} }
filledFields[fillFields.expMonth.opid] = fillFields.expMonth; filledFields[fillFields.expMonth.opid] = fillFields.expMonth;
fillScript.script.push(['click_on_opid', fillFields.expMonth.opid]); this.fillByOpid(fillScript, fillFields.expMonth, expMonth);
fillScript.script.push(['focus_by_opid', fillFields.expMonth.opid]);
fillScript.script.push(['fill_by_opid', fillFields.expMonth.opid, expMonth]);
} }
if (fillFields.expYear && this.hasValue(card.expYear)) { if (fillFields.expYear && this.hasValue(card.expYear)) {
@ -545,9 +536,7 @@ export default class AutofillService implements AutofillServiceInterface {
} }
filledFields[fillFields.expYear.opid] = fillFields.expYear; filledFields[fillFields.expYear.opid] = fillFields.expYear;
fillScript.script.push(['click_on_opid', fillFields.expYear.opid]); this.fillByOpid(fillScript, fillFields.expYear, expYear);
fillScript.script.push(['focus_by_opid', fillFields.expYear.opid]);
fillScript.script.push(['fill_by_opid', fillFields.expYear.opid, expYear]);
} }
if (fillFields.exp && this.hasValue(card.expMonth) && this.hasValue(card.expYear)) { if (fillFields.exp && this.hasValue(card.expMonth) && this.hasValue(card.expYear)) {
@ -852,9 +841,7 @@ export default class AutofillService implements AutofillServiceInterface {
if (doFill) { if (doFill) {
filledFields[field.opid] = field; filledFields[field.opid] = field;
fillScript.script.push(['click_on_opid', field.opid]); this.fillByOpid(fillScript, field, dataValue);
fillScript.script.push(['focus_by_opid', field.opid]);
fillScript.script.push(['fill_by_opid', field.opid, dataValue]);
} }
} }
@ -1050,4 +1037,13 @@ export default class AutofillService implements AutofillServiceInterface {
return fillScript; return fillScript;
} }
private fillByOpid(fillScript: AutofillScript, field: AutofillField, value: string): void {
if (field.maxLength && value.length > field.maxLength) {
value = value.substr(0, value.length);
}
fillScript.script.push(['click_on_opid', field.opid]);
fillScript.script.push(['focus_by_opid', field.opid]);
fillScript.script.push(['fill_by_opid', field.opid, value]);
}
} }