mirror of
https://github.com/bitwarden/browser
synced 2025-12-19 17:53:39 +00:00
[PM-8027] Inlin menu appears within input fields that do not relate to user login
This commit is contained in:
@@ -4,41 +4,51 @@ import AutofillPageDetails from "../models/autofill-page-details";
|
|||||||
import { AutoFillConstants } from "./autofill-constants";
|
import { AutoFillConstants } from "./autofill-constants";
|
||||||
|
|
||||||
export class AutofillFieldQualificationService {
|
export class AutofillFieldQualificationService {
|
||||||
autofillPageDetails: AutofillPageDetails;
|
|
||||||
private searchFieldNamesSet = new Set(AutoFillConstants.SearchFieldNames);
|
private searchFieldNamesSet = new Set(AutoFillConstants.SearchFieldNames);
|
||||||
private excludedAutofillLoginTypesSet = new Set(AutoFillConstants.ExcludedAutofillLoginTypes);
|
private excludedAutofillLoginTypesSet = new Set(AutoFillConstants.ExcludedAutofillLoginTypes);
|
||||||
|
private usernameFieldTypes = new Set(["text", "email", "tel"]);
|
||||||
private fieldIgnoreListString = AutoFillConstants.FieldIgnoreList.join(",");
|
private fieldIgnoreListString = AutoFillConstants.FieldIgnoreList.join(",");
|
||||||
private passwordFieldExcludeListString = AutoFillConstants.PasswordFieldExcludeList.join(",");
|
private passwordFieldExcludeListString = AutoFillConstants.PasswordFieldExcludeList.join(",");
|
||||||
|
private autofillFieldKeywordsMap: WeakMap<AutofillField, string> = new WeakMap();
|
||||||
|
|
||||||
setAutofillPageDetails(autofillPageDetails: AutofillPageDetails): void {
|
isFieldForLoginForm(field: AutofillField, pageDetails: AutofillPageDetails): boolean {
|
||||||
this.autofillPageDetails = autofillPageDetails;
|
// Check if the field
|
||||||
}
|
|
||||||
|
|
||||||
isLoginUsernameField(field: AutofillField): boolean {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
isLoginPasswordField(field: AutofillField): boolean {
|
isUsernameField(field: AutofillField): boolean {
|
||||||
if (
|
if (
|
||||||
field.type !== "password" ||
|
!this.usernameFieldTypes.has(field.type) ||
|
||||||
field.autoComplete === "new-password" ||
|
|
||||||
this.isExcludedFieldType(field, this.excludedAutofillLoginTypesSet)
|
this.isExcludedFieldType(field, this.excludedAutofillLoginTypesSet)
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.fieldHasDisqualifyingAttributeValue(field)) {
|
return this.keywordsFoundInFieldData(field, AutoFillConstants.UsernameFieldNames);
|
||||||
|
}
|
||||||
|
|
||||||
|
isExistingPasswordField(field: AutofillField): boolean {
|
||||||
|
if (field.autoComplete === "new-password") {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (field.type === "password") {
|
return this.isPasswordField(field);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.isPseudoPasswordField(field);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private isPseudoPasswordField(field: AutofillField): boolean {
|
isPasswordField(field: AutofillField): boolean {
|
||||||
|
const isInputPasswordType = field.type === "password";
|
||||||
|
if (
|
||||||
|
!isInputPasswordType ||
|
||||||
|
this.isExcludedFieldType(field, this.excludedAutofillLoginTypesSet) ||
|
||||||
|
this.fieldHasDisqualifyingAttributeValue(field)
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return isInputPasswordType || this.isLikePasswordField(field);
|
||||||
|
}
|
||||||
|
|
||||||
|
private isLikePasswordField(field: AutofillField): boolean {
|
||||||
if (field.type !== "text") {
|
if (field.type !== "text") {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -113,4 +123,36 @@ export class AutofillFieldQualificationService {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private keywordsFoundInFieldData(autofillFieldData: AutofillField, keywords: string[]) {
|
||||||
|
const searchedString = this.getAutofillFieldDataKeywords(autofillFieldData);
|
||||||
|
return keywords.some((keyword) => searchedString.includes(keyword));
|
||||||
|
}
|
||||||
|
|
||||||
|
private getAutofillFieldDataKeywords(autofillFieldData: AutofillField) {
|
||||||
|
if (this.autofillFieldKeywordsMap.has(autofillFieldData)) {
|
||||||
|
return this.autofillFieldKeywordsMap.get(autofillFieldData);
|
||||||
|
}
|
||||||
|
|
||||||
|
const keywordValues = [
|
||||||
|
autofillFieldData.htmlID,
|
||||||
|
autofillFieldData.htmlName,
|
||||||
|
autofillFieldData.htmlClass,
|
||||||
|
autofillFieldData.type,
|
||||||
|
autofillFieldData.title,
|
||||||
|
autofillFieldData.placeholder,
|
||||||
|
autofillFieldData.autoCompleteType,
|
||||||
|
autofillFieldData["label-data"],
|
||||||
|
autofillFieldData["label-aria"],
|
||||||
|
autofillFieldData["label-left"],
|
||||||
|
autofillFieldData["label-right"],
|
||||||
|
autofillFieldData["label-tag"],
|
||||||
|
autofillFieldData["label-top"],
|
||||||
|
]
|
||||||
|
.join(",")
|
||||||
|
.toLowerCase();
|
||||||
|
this.autofillFieldKeywordsMap.set(autofillFieldData, keywordValues);
|
||||||
|
|
||||||
|
return keywordValues;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user