Backed out 3 changesets (bug 1759418) for causing bp-hybrid bustages on FormAutofillNative.

Backed out changeset 7feecbf279d4 (bug 1759418)
Backed out changeset dbf65a66ad3f (bug 1759418)
Backed out changeset 013930ed617f (bug 1759418)
This commit is contained in:
Iulian Moraru 2022-05-24 01:13:43 +03:00
Родитель dee86961d5
Коммит bf6a1a7827
9 изменённых файлов: 780 добавлений и 857 удалений

Просмотреть файл

@ -2,7 +2,7 @@
* By default this test only tests 1 sample. This is to avoid publishing all samples we have
* to the codebase. If you update the Fathom CC model, please follow the instruction below
* and run the test. Doing this makes sure the optimized (Native implementation) CC fathom model produces
* exactly the same result as the non-optimized model (JS implementation, See CreditCardRuleset.jsm).
* exactly the same result as the non-optimized model (JS implementation, See creditCardRuleset.jsm).
*
* To test this:
* 1. Run the test setup script (fathom/test-setup.sh) to download all samples to the local
@ -101,23 +101,14 @@ async function run_test(path, dirs) {
);
}
// This value should sync with the number of supported types in
// CreditCardRuleset.jsm (See `get types()` in `this.creditCardRulesets`).
const EXPECTED_NUM_OF_CONFIDENCE = 1;
for (let i = 0; i < eligibleFields.length; i++) {
if (
Object.keys(nativeConfidencesKeyedByType[i]).length !=
EXPECTED_NUM_OF_CONFIDENCE
) {
if (Object.keys(nativeConfidencesKeyedByType[i]).length != 6) {
ok(
false,
`Native CC model doesn't get confidence value for all types`
);
}
if (
Object.keys(jsConfidencesKeyedByType[i]).length !=
EXPECTED_NUM_OF_CONFIDENCE
) {
if (Object.keys(jsConfidencesKeyedByType[i]).length != 6) {
ok(
false,
`JS CC model doesn't get confidence value for all types`

Просмотреть файл

@ -195,12 +195,12 @@ runHeuristicsTest(
},
// FIXME: bug 1392950 - the membership number should not be detected
// as cc-number.
//{
//section: "",
//addressType: "",
//contactType: "",
//fieldName: "cc-number",
//},
{
section: "",
addressType: "",
contactType: "",
fieldName: "cc-number",
},
],
],
],

Просмотреть файл

@ -41,14 +41,14 @@ runHeuristicsTest(
},
// {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-csc"},
],
//[
//{
//section: "",
//addressType: "",
//contactType: "",
//fieldName: "cc-number", // txtQvcGiftCardNumber
//},
//],
[
{
section: "",
addressType: "",
contactType: "",
fieldName: "cc-number",
},
],
],
[
[
@ -104,14 +104,14 @@ runHeuristicsTest(
},
// {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-csc"},
],
//[
//{
//section: "",
//addressType: "",
//contactType: "",
//fieldName: "cc-number", // txtQvcGiftCardNumber
//}, // ac-off
//],
[
{
section: "",
addressType: "",
contactType: "",
fieldName: "cc-number",
}, // ac-off
],
],
[
[

Просмотреть файл

@ -1,8 +1,5 @@
"use strict";
const { FieldScanner } = ChromeUtils.import(
"resource://autofill/FormAutofillHeuristics.jsm"
);
var FormAutofillHeuristics, LabelUtils, FormAutofill;
add_task(async function() {
({ FormAutofillHeuristics } = ChromeUtils.import(
@ -287,10 +284,7 @@ TESTCASES.forEach(testcase => {
);
let element = doc.getElementById(testcase.elementId);
let value = FormAutofillHeuristics.getInfo(
element,
new FieldScanner([element], {})
);
let value = FormAutofillHeuristics.getInfo(element);
Assert.deepEqual(value, testcase.expectedReturnValue);
LabelUtils.clearLabelMap();
@ -343,10 +337,7 @@ add_task(async function test_regexp_list() {
);
let element = doc.getElementById(testcase.elementId);
let value = FormAutofillHeuristics.getInfo(
element,
new FieldScanner([element], {})
);
let value = FormAutofillHeuristics.getInfo(element);
Assert.deepEqual(value, testcase.expectedReturnValue, label);
}
@ -369,10 +360,7 @@ add_task(async function test_autofill_creditCards_autocomplete_off_pref() {
document
);
let element = doc.getElementById("targetElement");
let value = FormAutofillHeuristics.getInfo(
element,
new FieldScanner([element], {})
);
let value = FormAutofillHeuristics.getInfo(element);
Assert.deepEqual(value, expected);
document = `<form>
@ -397,10 +385,7 @@ add_task(async function test_autofill_creditCards_autocomplete_off_pref() {
document
);
element = doc.getElementById("targetElement");
value = FormAutofillHeuristics.getInfo(
element,
new FieldScanner([element], {})
);
value = FormAutofillHeuristics.getInfo(element);
Assert.deepEqual(value, expected);
Services.prefs.clearUserPref(
@ -423,10 +408,7 @@ add_task(async function test_autofill_addresses_autocomplete_off_pref() {
document
);
let element = doc.getElementById("given-name");
let value = FormAutofillHeuristics.getInfo(
element,
new FieldScanner([element], {})
);
let value = FormAutofillHeuristics.getInfo(element);
Assert.deepEqual(value, expected);
document = `<form>
@ -448,10 +430,7 @@ add_task(async function test_autofill_addresses_autocomplete_off_pref() {
document
);
element = doc.getElementById("given-name");
value = FormAutofillHeuristics.getInfo(
element,
new FieldScanner([element], {})
);
value = FormAutofillHeuristics.getInfo(element);
Assert.deepEqual(value, expected);
Services.prefs.clearUserPref(

Просмотреть файл

@ -61,12 +61,13 @@ dictionary InteractionData {
unsigned long scrollingDistanceInPixels = 0;
};
/**
* Confidence value of credit card fields. This is used by the native
* Fathom Credit Card model to return the score to JS.
*/
dictionary FormAutofillConfidences {
double ccNumber = 0;
double ccName = 0;
double ccType = 0;
double ccExp = 0;
double ccExpMonth = 0;
double ccExpYear = 0;
};
/**

Просмотреть файл

@ -4434,9 +4434,8 @@ pref("extensions.formautofill.creditCards.supportedCountries", "US,CA,GB,FR,DE")
pref("extensions.formautofill.creditCards.hideui", false);
// Algorithm used by formautofill while determine whether a field is a credit card field
// 0:Heurstics based on regular expression string matching
// 1:Fathom in js implementation
// 2:Fathom in c++ implementation
pref("extensions.formautofill.creditCards.heuristics.mode", 2);
// 1:Fathom in js implementation, 2:Fathom in c++ implementation
pref("extensions.formautofill.creditCards.heuristics.mode", 0);
pref("extensions.formautofill.creditCards.heuristics.confidenceThreshold", "0.5");
// Pref for shield/heartbeat to recognize users who have used Credit Card
// Autofill. The valid values can be:

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -881,10 +881,7 @@ this.FormAutofillHeuristics = {
// The heuristic below should be covered by fathom rules, so we can skip doing
// it.
if (
FormAutofillUtils.isFathomCreditCardsEnabled() &&
creditCardRulesets.types.includes(detail.fieldName)
) {
if (FormAutofillUtils.isFathomCreditCardsEnabled()) {
fieldScanner.parsingIndex++;
return true;
}
@ -1154,10 +1151,10 @@ this.FormAutofillHeuristics = {
let fathomFields = fields.filter(r =>
creditCardRulesets.types.includes(r)
);
let matchedFieldName = scanner.getFathomField(element, fathomFields);
let fathomField = scanner.getFathomField(element, fathomFields);
// At this point, use fathom's recommendation if it has one
if (matchedFieldName) {
return infoRecordWithFieldName(matchedFieldName);
if (fathomField) {
return infoRecordWithFieldName(fathomField);
}
// TODO: Do we want to run old heuristics for fields that fathom isn't confident?

Просмотреть файл

@ -74,7 +74,6 @@ enum class RegexKey : uint8_t {
enum class CCNumberParams : uint8_t {
idOrNameMatchNumberRegExp,
labelsMatchNumberRegExp,
closestLabelMatchesNumberRegExp,
placeholderMatchesNumberRegExp,
ariaLabelMatchesNumberRegExp,
idOrNameMatchGift,
@ -84,6 +83,7 @@ enum class CCNumberParams : uint8_t {
idOrNameMatchSubscription,
idOrNameMatchDwfrmAndBml,
hasTemplatedValue,
isNotVisible,
inputTypeNotNumbery,
Count,
@ -92,7 +92,6 @@ enum class CCNumberParams : uint8_t {
enum class CCNameParams : uint8_t {
idOrNameMatchNameRegExp,
labelsMatchNameRegExp,
closestLabelMatchesNameRegExp,
placeholderMatchesNameRegExp,
ariaLabelMatchesNameRegExp,
idOrNameMatchFirst,
@ -107,6 +106,7 @@ enum class CCNameParams : uint8_t {
idOrNameMatchSubscription,
idOrNameMatchDwfrmAndBml,
hasTemplatedValue,
isNotVisible,
Count,
};
@ -114,7 +114,6 @@ enum class CCNameParams : uint8_t {
enum class CCTypeParams : uint8_t {
idOrNameMatchTypeRegExp,
labelsMatchTypeRegExp,
closestLabelMatchesTypeRegExp,
idOrNameMatchVisaCheckout,
ariaLabelMatchesVisaCheckout,
isSelectWithCreditCardOptions,
@ -128,7 +127,6 @@ enum class CCTypeParams : uint8_t {
enum class CCExpParams : uint8_t {
labelsMatchExpRegExp,
closestLabelMatchesExpRegExp,
placeholderMatchesExpRegExp,
labelsMatchExpWith2Or4DigitYear,
placeholderMatchesExpWith2Or4DigitYear,
@ -151,7 +149,6 @@ enum class CCExpParams : uint8_t {
enum class CCExpMonthParams : uint8_t {
idOrNameMatchExpMonthRegExp,
labelsMatchExpMonthRegExp,
closestLabelMatchesExpMonthRegExp,
placeholderMatchesExpMonthRegExp,
ariaLabelMatchesExpMonthRegExp,
idOrNameMatchMonth,
@ -182,7 +179,6 @@ enum class CCExpMonthParams : uint8_t {
enum class CCExpYearParams : uint8_t {
idOrNameMatchExpYearRegExp,
labelsMatchExpYearRegExp,
closestLabelMatchesExpYearRegExp,
placeholderMatchesExpYearRegExp,
ariaLabelMatchesExpYearRegExp,
idOrNameMatchYear,
@ -221,138 +217,131 @@ struct AutofillParams {
mCCExpYearParams;
};
// clang-format off
constexpr AutofillParams kCoefficents{
.mCCNumberParams = {
/* idOrNameMatchNumberRegExp */ 7.679469585418701,
/* labelsMatchNumberRegExp */ 5.122580051422119,
/* closestLabelMatchesNumberRegExp */ 2.1256935596466064,
/* placeholderMatchesNumberRegExp */ 9.471800804138184,
/* ariaLabelMatchesNumberRegExp */ 6.067715644836426,
/* idOrNameMatchGift */ -22.946273803710938,
/* labelsMatchGift */ -7.852959632873535,
/* placeholderMatchesGift */ -2.355496406555176,
/* ariaLabelMatchesGift */ -2.940307855606079,
/* idOrNameMatchSubscription */ 0.11255314946174622,
/* idOrNameMatchDwfrmAndBml */ -0.0006645023822784424,
/* hasTemplatedValue */ -0.11370040476322174,
/* inputTypeNotNumbery */ -3.750155210494995
/* idOrNameMatchNumberRegExp */ 6.3039140701293945,
/* labelsMatchNumberRegExp */ 2.8916432857513428,
/* placeholderMatchesNumberRegExp */ 5.505742073059082,
/* ariaLabelMatchesNumberRegExp */ 4.561432361602783,
/* idOrNameMatchGift */ -3.803224563598633,
/* labelsMatchGift */ -4.524861812591553,
/* placeholderMatchesGift */ -1.8712525367736816,
/* ariaLabelMatchesGift */ -3.674055576324463,
/* idOrNameMatchSubscription */ -0.7810876369476318,
/* idOrNameMatchDwfrmAndBml */ -1.095906138420105,
/* hasTemplatedValue */ -6.368256568908691,
/* isNotVisible */ -3.0330028533935547,
/* inputTypeNotNumbery */ -2.300889253616333,
},
.mCCNameParams = {
/* idOrNameMatchNameRegExp */ 7.496212959289551,
/* labelsMatchNameRegExp */ 6.081472873687744,
/* closestLabelMatchesNameRegExp */ 2.600574254989624,
/* placeholderMatchesNameRegExp */ 5.750874042510986,
/* ariaLabelMatchesNameRegExp */ 5.162227153778076,
/* idOrNameMatchFirst */ -6.742659091949463,
/* labelsMatchFirst */ -0.5234538912773132,
/* placeholderMatchesFirst */ -3.4615235328674316,
/* ariaLabelMatchesFirst */ -1.3145145177841187,
/* idOrNameMatchLast */ -12.561869621276855,
/* labelsMatchLast */ -0.27417105436325073,
/* placeholderMatchesLast */ -1.434966802597046,
/* ariaLabelMatchesLast */ -2.9319725036621094,
/* idOrNameMatchFirstAndLast */ 24.123435974121094,
/* idOrNameMatchSubscription */ 0.08349418640136719,
/* idOrNameMatchDwfrmAndBml */ 0.01882520318031311,
/* hasTemplatedValue */ 0.182317852973938
/* idOrNameMatchNameRegExp */ 7.953818321228027,
/* labelsMatchNameRegExp */ 11.784907341003418,
/* placeholderMatchesNameRegExp */ 9.202799797058105,
/* ariaLabelMatchesNameRegExp */ 9.627416610717773,
/* idOrNameMatchFirst */ -6.200107574462891,
/* labelsMatchFirst */ -14.77401065826416,
/* placeholderMatchesFirst */ -10.258772850036621,
/* ariaLabelMatchesFirst */ -2.1574606895446777,
/* idOrNameMatchLast */ -5.508854389190674,
/* labelsMatchLast */ -14.563374519348145,
/* placeholderMatchesLast */ -8.281961441040039,
/* ariaLabelMatchesLast */ -7.915995121002197,
/* idOrNameMatchFirstAndLast */ 17.586633682250977,
/* idOrNameMatchSubscription */ -1.3862149715423584,
/* idOrNameMatchDwfrmAndBml */ -1.154863953590393,
/* hasTemplatedValue */ -1.3476886749267578,
/* isNotVisible */ -20.619457244873047,
},
.mCCTypeParams = {
/* idOrNameMatchTypeRegExp */ 2.0581533908843994,
/* labelsMatchTypeRegExp */ 1.0784518718719482,
/* closestLabelMatchesTypeRegExp */ 0.6995877623558044,
/* idOrNameMatchVisaCheckout */ -3.320356845855713,
/* ariaLabelMatchesVisaCheckout */ -3.4196767807006836,
/* isSelectWithCreditCardOptions */ 10.337477684020996,
/* isRadioWithCreditCardText */ 4.530318737030029,
/* idOrNameMatchSubscription */ -3.7206356525421143,
/* idOrNameMatchDwfrmAndBml */ -0.08782318234443665,
/* hasTemplatedValue */ 0.1772511601448059
/* idOrNameMatchTypeRegExp */ 2.815537691116333,
/* labelsMatchTypeRegExp */ -2.6969387531280518,
/* idOrNameMatchVisaCheckout */ -4.888851165771484,
/* ariaLabelMatchesVisaCheckout */ -5.0021514892578125,
/* isSelectWithCreditCardOptions */ 7.633410453796387,
/* isRadioWithCreditCardText */ 9.72647762298584,
/* idOrNameMatchSubscription */ -2.540968179702759,
/* idOrNameMatchDwfrmAndBml */ -2.4342823028564453,
/* hasTemplatedValue */ -2.134981155395508,
},
.mCCExpParams = {
/* labelsMatchExpRegExp */ 7.588159561157227,
/* closestLabelMatchesExpRegExp */ 1.41484534740448,
/* placeholderMatchesExpRegExp */ 8.759064674377441,
/* labelsMatchExpWith2Or4DigitYear */ -3.876218795776367,
/* placeholderMatchesExpWith2Or4DigitYear */ 2.8364884853363037,
/* labelsMatchMMYY */ 8.836017608642578,
/* placeholderMatchesMMYY */ -0.5231751799583435,
/* maxLengthIs7 */ 1.3565447330474854,
/* idOrNameMatchSubscription */ 0.1779913753271103,
/* idOrNameMatchDwfrmAndBml */ 0.21037884056568146,
/* hasTemplatedValue */ 0.14900512993335724,
/* isExpirationMonthLikely */ -3.223409652709961,
/* isExpirationYearLikely */ -2.536919593811035,
/* idOrNameMatchMonth */ -3.6893014907836914,
/* idOrNameMatchYear */ -3.108184337615967,
/* idOrNameMatchExpMonthRegExp */ -2.264357089996338,
/* idOrNameMatchExpYearRegExp */ -2.7957723140716553,
/* idOrNameMatchValidation */ -2.29402756690979
/* labelsMatchExpRegExp */ 7.235990524291992,
/* placeholderMatchesExpRegExp */ 3.7828152179718018,
/* labelsMatchExpWith2Or4DigitYear */ 3.28702449798584,
/* placeholderMatchesExpWith2Or4DigitYear */ 0.9417413473129272,
/* labelsMatchMMYY */ 8.527382850646973,
/* placeholderMatchesMMYY */ 6.976727485656738,
/* maxLengthIs7 */ -1.6640985012054443,
/* idOrNameMatchSubscription */ -1.7390238046646118,
/* idOrNameMatchDwfrmAndBml */ -1.8697377443313599,
/* hasTemplatedValue */ -2.2890148162841797,
/* isExpirationMonthLikely */ -2.7287368774414062,
/* isExpirationYearLikely */ -2.1379034519195557,
/* idOrNameMatchMonth */ -2.9298980236053467,
/* idOrNameMatchYear */ -2.423668622970581,
/* idOrNameMatchExpMonthRegExp */ -2.224165916442871,
/* idOrNameMatchExpYearRegExp */ -2.4124796390533447,
/* idOrNameMatchValidation */ -6.64445686340332,
},
.mCCExpMonthParams = {
/* idOrNameMatchExpMonthRegExp */ 0.2787344455718994,
/* labelsMatchExpMonthRegExp */ 1.298413634300232,
/* closestLabelMatchesExpMonthRegExp */ -11.206244468688965,
/* placeholderMatchesExpMonthRegExp */ 1.2605619430541992,
/* ariaLabelMatchesExpMonthRegExp */ 1.1330018043518066,
/* idOrNameMatchMonth */ 6.1464314460754395,
/* labelsMatchMonth */ 0.7051732540130615,
/* placeholderMatchesMonth */ 0.7463492751121521,
/* ariaLabelMatchesMonth */ 1.8244760036468506,
/* nextFieldIdOrNameMatchExpYearRegExp */ 0.06347066164016724,
/* nextFieldLabelsMatchExpYearRegExp */ -0.1692247837781906,
/* nextFieldPlaceholderMatchExpYearRegExp */ 1.0434566736221313,
/* nextFieldAriaLabelMatchExpYearRegExp */ 1.751156210899353,
/* nextFieldIdOrNameMatchYear */ -0.532447338104248,
/* nextFieldLabelsMatchYear */ 1.3248541355133057,
/* nextFieldPlaceholderMatchesYear */ 0.604235827922821,
/* nextFieldAriaLabelMatchesYear */ 1.5364223718643188,
/* nextFieldMatchesExpYearAutocomplete */ 6.285938262939453,
/* isExpirationMonthLikely */ 13.117807388305664,
/* nextFieldIsExpirationYearLikely */ 7.182341575622559,
/* maxLengthIs2 */ 4.477289199829102,
/* placeholderMatchesMM */ 14.403288841247559,
/* roleIsMenu */ 5.770959854125977,
/* idOrNameMatchSubscription */ -0.043085768818855286,
/* idOrNameMatchDwfrmAndBml */ 0.02823038399219513,
/* hasTemplatedValue */ 0.07234494388103485
/* idOrNameMatchExpMonthRegExp */ 3.1759495735168457,
/* labelsMatchExpMonthRegExp */ 0.6333072781562805,
/* placeholderMatchesExpMonthRegExp */ -1.0211261510849,
/* ariaLabelMatchesExpMonthRegExp */ -0.12013287842273712,
/* idOrNameMatchMonth */ 0.8069844245910645,
/* labelsMatchMonth */ 2.8041117191314697,
/* placeholderMatchesMonth */ -0.7963107228279114,
/* ariaLabelMatchesMonth */ -0.18894313275814056,
/* nextFieldIdOrNameMatchExpYearRegExp */ 1.3703272342681885,
/* nextFieldLabelsMatchExpYearRegExp */ 0.4734393060207367,
/* nextFieldPlaceholderMatchExpYearRegExp */ -0.9648597240447998,
/* nextFieldAriaLabelMatchExpYearRegExp */ 2.3334436416625977,
/* nextFieldIdOrNameMatchYear */ 0.7225953936576843,
/* nextFieldLabelsMatchYear */ 0.47795572876930237,
/* nextFieldPlaceholderMatchesYear */ -1.032015085220337,
/* nextFieldAriaLabelMatchesYear */ 2.5017199516296387,
/* nextFieldMatchesExpYearAutocomplete */ 1.4952502250671387,
/* isExpirationMonthLikely */ 5.659104347229004,
/* nextFieldIsExpirationYearLikely */ 2.5078020095825195,
/* maxLengthIs2 */ -0.5410940051078796,
/* placeholderMatchesMM */ 7.3071208000183105,
/* roleIsMenu */ 5.595693111419678,
/* idOrNameMatchSubscription */ -5.626739978790283,
/* idOrNameMatchDwfrmAndBml */ -7.236949920654297,
/* hasTemplatedValue */ -6.055515289306641,
},
.mCCExpYearParams = {
/* idOrNameMatchExpYearRegExp */ 5.426016807556152,
/* labelsMatchExpYearRegExp */ 1.3240209817886353,
/* closestLabelMatchesExpYearRegExp */ -8.702284812927246,
/* placeholderMatchesExpYearRegExp */ 0.9059725999832153,
/* ariaLabelMatchesExpYearRegExp */ 0.5550334453582764,
/* idOrNameMatchYear */ 5.362994194030762,
/* labelsMatchYear */ 2.7185044288635254,
/* placeholderMatchesYear */ 0.7883157134056091,
/* ariaLabelMatchesYear */ 0.311492383480072,
/* previousFieldIdOrNameMatchExpMonthRegExp */ 1.8155208826065063,
/* previousFieldLabelsMatchExpMonthRegExp */ -0.46133187413215637,
/* previousFieldPlaceholderMatchExpMonthRegExp */ 1.0374903678894043,
/* previousFieldAriaLabelMatchExpMonthRegExp */ -0.5901495814323425,
/* previousFieldIdOrNameMatchMonth */ -5.960310935974121,
/* previousFieldLabelsMatchMonth */ 0.6495584845542908,
/* previousFieldPlaceholderMatchesMonth */ 0.7198042273521423,
/* previousFieldAriaLabelMatchesMonth */ 3.4590985774993896,
/* previousFieldMatchesExpMonthAutocomplete */ 2.986003875732422,
/* isExpirationYearLikely */ 4.021566390991211,
/* previousFieldIsExpirationMonthLikely */ 9.298635482788086,
/* placeholderMatchesYYOrYYYY */ 10.457176208496094,
/* roleIsMenu */ 1.1051956415176392,
/* idOrNameMatchSubscription */ 0.000688597559928894,
/* idOrNameMatchDwfrmAndBml */ 0.15687309205532074,
/* hasTemplatedValue */ -0.19141331315040588
}
};
// clang-format off
/* idOrNameMatchExpYearRegExp */ 2.456799268722534,
/* labelsMatchExpYearRegExp */ 0.9488120675086975,
/* placeholderMatchesExpYearRegExp */ -0.6318328380584717,
/* ariaLabelMatchesExpYearRegExp */ -0.16433487832546234,
/* idOrNameMatchYear */ 2.0227997303009033,
/* labelsMatchYear */ 0.7777050733566284,
/* placeholderMatchesYear */ -0.6191908121109009,
/* ariaLabelMatchesYear */ -0.5337049961090088,
/* previousFieldIdOrNameMatchExpMonthRegExp */ 0.2529127597808838,
/* previousFieldLabelsMatchExpMonthRegExp */ 0.5853790044784546,
/* previousFieldPlaceholderMatchExpMonthRegExp */ -0.710956871509552,
/* previousFieldAriaLabelMatchExpMonthRegExp */ 2.2874839305877686,
/* previousFieldIdOrNameMatchMonth */ -1.99709153175354,
/* previousFieldLabelsMatchMonth */ 1.114603042602539,
/* previousFieldPlaceholderMatchesMonth */ -0.4987318515777588,
/* previousFieldAriaLabelMatchesMonth */ 2.1683783531188965,
/* previousFieldMatchesExpMonthAutocomplete */ 1.2016327381134033,
/* isExpirationYearLikely */ 5.7863616943359375,
/* previousFieldIsExpirationMonthLikely */ 6.4013848304748535,
/* placeholderMatchesYYOrYYYY */ 8.81661605834961,
/* roleIsMenu */ 3.7794034481048584,
/* idOrNameMatchSubscription */ -4.7467498779296875,
/* idOrNameMatchDwfrmAndBml */ -5.523425102233887,
/* hasTemplatedValue */ -6.14529275894165,
}};
constexpr float kCCNumberBias = -4.948795795440674;
constexpr float kCCNameBias = -5.3578081130981445;
constexpr float kCCTypeBias = -5.979659557342529;
constexpr float kCCExpBias = -5.849575996398926;
constexpr float kCCExpMonthBias = -8.844199180603027;
constexpr float kCCExpYearBias = -6.499860763549805;
constexpr float kCCNumberBias = -4.422344207763672;
constexpr float kCCNameBias = -5.876968860626221;
constexpr float kCCTypeBias = -5.410860061645508;
constexpr float kCCExpBias = -5.439330577850342;
constexpr float kCCExpMonthBias = -5.99984073638916;
constexpr float kCCExpYearBias = -6.0192646980285645;
struct Rule {
RegexKey key;
@ -360,6 +349,12 @@ struct Rule {
};
const Rule kFirefoxRules[] = {
{RegexKey::CC_NAME, "account.*holder.*name"},
{RegexKey::CC_NUMBER, "(cc|kk)nr"}, // de-DE
{RegexKey::CC_EXP_MONTH, "(cc|kk)month"}, // de-DE
{RegexKey::CC_EXP_YEAR, "(cc|kk)year"}, // de-DE
{RegexKey::CC_TYPE, "type"},
{RegexKey::MM_MONTH, "^mm$|\\(mm\\)"},
{RegexKey::YY_OR_YYYY, "^(yy|yyyy)$|\\(yy\\)|\\(yyyy\\)"},
{RegexKey::MONTH, "month"},
@ -391,45 +386,18 @@ const Rule kFirefoxRules[] = {
// These are the rules used by Bitwarden [0], converted into RegExp form.
// [0]
// https://github.com/bitwarden/browser/blob/c2b8802201fac5e292d55d5caf3f1f78088d823c/src/services/autofill.service.ts#L436
const Rule kCreditCardRules[] = {
const Rule kBitwardenRules[] = {
/* eslint-disable */
// Let us keep our consistent wrapping.
{RegexKey::CC_NAME,
// Firefox-specific rules
"account.*holder.*name"
// de-DE
"|^(kredit)?(karten|konto)inhaber"
"|^(name).*karte"
// fr-FR
"|nom.*(titulaire|détenteur)"
"|(titulaire|détenteur).*(carte)"
// Rules from Bitwarden
"|cc-?name"
"cc-?name"
"|card-?name"
"|cardholder-?name"
"|(^nom$)"
// Rules are from Chromium source codes
"|card.?(?:holder|owner)|name.*(\\b)?on(\\b)?.*card"
"|(?:card|cc).?name|cc.?full.?name"
"|(?:card|cc).?owner"
"|nombre.*tarjeta" // es
"|nom.*carte" // fr-FR
"|nome.*cart" // it-IT
"|名前" // ja-JP
"|Имя.*карты" // ru
"|信用卡开户名|开户名|持卡人姓名" // zh-CN
"|持卡人姓名"}, // zh-TW
"|(^nom$)"},
/* eslint-enable */
{RegexKey::CC_NUMBER,
// Firefox-specific rules
// de-DE
"(cc|kk)nr"
"|(kredit)?(karten)(nummer|nr)"
// fr-FR
"|(numero|número|numéro).*(carte)"
// Rules from Bitwarden
"|cc-?number"
"cc-?number"
"|cc-?num"
"|card-?number"
"|card-?num"
@ -437,23 +405,10 @@ const Rule kCreditCardRules[] = {
"|card-?no"
"|numero-?carte"
"|num-?carte"
"|cb-?num"
// Rules are from Chromium source codes
"|(add)?(?:card|cc|acct).?(?:number|#|no|num)"
"|カード番号" // ja-JP
"|Номер.*карты" // ru
"|信用卡号|信用卡号码" // zh-CN
"|信用卡卡號" // zh-TW
"|카드"}, // ko-KR
"|cb-?num"},
{RegexKey::CC_EXP,
// Firefox-specific rules
"mm\\s*(/|\\|-)\\s*(yy|jj|aa)"
"|(month|mois)\\s*(/|\\|-|et)\\s*(year|année)"
// de-DE
// fr-FR
// Rules from Bitwarden
"|(^cc-?exp$)"
"(^cc-?exp$)"
"|(^card-?exp$)"
"|(^cc-?expiration$)"
"|(^card-?expiration$)"
@ -470,22 +425,10 @@ const Rule kCreditCardRules[] = {
"|yyyy-?mm"
"|expiration-?date"
"|payment-?card-?expiration"
"|(^payment-?cc-?date$)"
// Rules are from Chromium source codes
"|expir|exp.*date|^expfield$"
"|ablaufdatum|gueltig|gültig" // de-DE
"|fecha" // es
"|date.*exp" // fr-FR
"|scadenza" // it-IT
"|有効期限" // ja-JP
"|validade" // pt-BR, pt-PT
"|Срок действия карты"}, // ru
"|(^payment-?cc-?date$)"},
{RegexKey::CC_EXP_MONTH,
// Firefox-specific rules
"(cc|kk)month" // de-DE
// Rules from Bitwarden
"|(^exp-?month$)"
"(^exp-?month$)"
"|(^cc-?exp-?month$)"
"|(^cc-?month$)"
"|(^card-?month$)"
@ -523,23 +466,10 @@ const Rule kCreditCardRules[] = {
"|(^validity-?mo$)"
"|(^exp-?date-?mo$)"
"|(^cb-?date-?mois$)"
"|(^date-?m$)"
// Rules are from Chromium source codes
"|exp.*mo|ccmonth|cardmonth|addmonth"
"|monat" // de-DE
// "|fecha" // es
// "|date.*exp" // fr-FR
// "|scadenza" // it-IT
// "|有効期限" // ja-JP
// "|validade" // pt-BR, pt-PT
// "|Срок действия карты" // ru
"|月"}, // zh-CN
"|(^date-?m$)"},
{RegexKey::CC_EXP_YEAR,
// Firefox-specific rules
"(cc|kk)year" // de-DE
// Rules from Bitwarden
"|(^exp-?year$)"
"(^exp-?year$)"
"|(^cc-?exp-?year$)"
"|(^cc-?year$)"
"|(^card-?year$)"
@ -581,29 +511,84 @@ const Rule kCreditCardRules[] = {
"|(^expiration-?date-?yyyy$)"
"|(^validity-?year$)"
"|(^exp-?date-?year$)"
"|(^date-?y$)"
// Rules are from Chromium source codes
"|(add)?year"
"|jahr" // de-DE
// "|fecha" // es
// "|scadenza" // it-IT
// "|有効期限" // ja-JP
// "|validade" // pt-BR, pt-PT
// "|Срок действия карты" // ru
"|年|有效期"}, // zh-CN
"|(^date-?y$)"},
{RegexKey::CC_TYPE,
// Firefox-specific rules
"type"
// de-DE
"|Kartenmarke"
// Rules from Bitwarden
"|(^cc-?type$)"
"(^cc-?type$)"
"|(^card-?type$)"
"|(^card-?brand$)"
"|(^cc-?brand$)"
"|(^cb-?type$)"},
// Rules are from Chromium source codes
};
//=========================================================================
// These rules are from Chromium source codes [1]. Most of them
// converted to JS format have the same meaning with the original ones except
// the first line of "address-level1".
// [1]
// https://source.chromium.org/chromium/chromium/src/+/master:components/autofill/core/common/autofill_regex_constants.cc
const Rule kChromiumRules[] = {
// ==== Name Fields ====
{RegexKey::CC_NAME,
"card.?(?:holder|owner)|name.*(\\b)?on(\\b)?.*card"
"|(?:card|cc).?name|cc.?full.?name"
"|(?:card|cc).?owner"
"|nombre.*tarjeta" // es
"|nom.*carte" // fr-FR
"|nome.*cart" // it-IT
"|名前" // ja-JP
"|Имя.*карты" // ru
"|信用卡开户名|开户名|持卡人姓名" // zh-CN
"|持卡人姓名"}, // zh-TW
// ==== Credit Card Fields ====
// Note: `cc-name` expression has been moved up, above `name`, in
// order to handle specialization through ordering.
{
RegexKey::CC_NUMBER,
"(add)?(?:card|cc|acct).?(?:number|#|no|num)"
// TODO - lookbehind not supported
// "|(?<!telefon|haus|person|fødsels|zimmer)nummer" // de-DE,
// sv-SE, no
"|カード番号" // ja-JP
"|Номер.*карты" // ru
"|信用卡号|信用卡号码" // zh-CN
"|信用卡卡號" // zh-TW
"|카드" // ko-KR
// es/pt/fr (TODO: lookahead not supported)
// "|(numero|número|numéro)(?!.*(document|fono|phone|réservation))"
},
{RegexKey::CC_EXP_MONTH,
"exp.*mo|ccmonth|cardmonth|addmonth"
"|monat" // de-DE
// "|fecha" // es
// "|date.*exp" // fr-FR
// "|scadenza" // it-IT
// "|有効期限" // ja-JP
// "|validade" // pt-BR, pt-PT
// "|Срок действия карты" // ru
"|月"}, // zh-CN
{RegexKey::CC_EXP_YEAR,
"(add)?year"
"|jahr" // de-DE
// "|fecha" // es
// "|scadenza" // it-IT
// "|有効期限" // ja-JP
// "|validade" // pt-BR, pt-PT
// "|Срок действия карты" // ru
"|年|有效期"}, // zh-CN
{RegexKey::CC_EXP,
"expir|exp.*date|^expfield$"
"|ablaufdatum|gueltig|gültig" // de-DE
"|fecha" // es
"|date.*exp" // fr-FR
"|scadenza" // it-IT
"|有効期限" // ja-JP
"|validade" // pt-BR, pt-PT
"|Срок действия карты"}, // ru
};
static double Sigmoid(double x) { return 1.0 / (1.0 + exp(-x)); }
@ -621,15 +606,12 @@ class FormAutofillImpl {
bool StringMatchesRegExp(const nsACString& str, RegexKey key);
bool StringMatchesRegExp(const nsAString& str, RegexKey key);
bool TextContentMatchesRegExp(Element& element, RegexKey key);
size_t CountRegExpMatches(const nsACString& str, RegexKey key);
size_t CountRegExpMatches(const nsAString& str, RegexKey key);
bool IdOrNameMatchRegExp(Element& element, RegexKey key);
bool NextFieldMatchesExpYearAutocomplete(Element* aNextField);
bool PreviousFieldMatchesExpMonthAutocomplete(Element* aPrevField);
bool LabelMatchesRegExp(Element& element, const nsTArray<nsCString>* labels,
RegexKey key);
bool ClosestLabelMatchesRegExp(Element& aElement, RegexKey aKey);
bool LabelMatchesRegExp(const nsTArray<nsCString>* labels, RegexKey key);
bool PlaceholderMatchesRegExp(Element& element, RegexKey key);
bool AriaLabelMatchesRegExp(Element& element, RegexKey key);
bool AutocompleteStringMatches(Element& aElement, const nsAString& aKey);
@ -638,6 +620,7 @@ class FormAutofillImpl {
bool MaxLengthIs(Element& aElement, int32_t aValue);
bool IsExpirationMonthLikely(Element& element);
bool IsExpirationYearLikely(Element& element);
bool IsVisible(Element& element);
bool InputTypeNotNumbery(Element& element);
bool IsSelectWithCreditCardOptions(Element& element);
bool IsRadioWithCreditCardText(Element& element,
@ -669,9 +652,11 @@ class FormAutofillImpl {
};
FormAutofillImpl::FormAutofillImpl() {
const Rule* rulesets[] = {&kFirefoxRules[0], &kCreditCardRules[0]};
const Rule* rulesets[] = {&kFirefoxRules[0], &kBitwardenRules[0],
&kChromiumRules[0]};
size_t rulesetLengths[] = {ArrayLength(kFirefoxRules),
ArrayLength(kCreditCardRules)};
ArrayLength(kBitwardenRules),
ArrayLength(kChromiumRules)};
for (uint32_t i = 0; i < ArrayLength(rulesetLengths); ++i) {
for (uint32_t j = 0; j < rulesetLengths[i]; ++j) {
@ -701,18 +686,6 @@ bool FormAutofillImpl::StringMatchesRegExp(const nsAString& aStr,
return StringMatchesRegExp(NS_ConvertUTF16toUTF8(aStr), aKey);
}
bool FormAutofillImpl::TextContentMatchesRegExp(Element& element,
RegexKey key) {
ErrorResult rv;
nsAutoString text;
element.GetTextContent(text, rv);
if (rv.Failed()) {
return false;
}
return StringMatchesRegExp(text, key);
}
size_t FormAutofillImpl::CountRegExpMatches(const nsACString& aStr,
RegexKey aKey) {
return regex::ffi::regex_count_matches(&GetRegex(aKey), &aStr);
@ -744,7 +717,7 @@ bool FormAutofillImpl::IdOrNameMatchRegExp(Element& aElement, RegexKey key) {
}
bool FormAutofillImpl::LabelMatchesRegExp(
Element& aElement, const nsTArray<nsCString>* labelStrings, RegexKey key) {
const nsTArray<nsCString>* labelStrings, RegexKey key) {
if (!labelStrings) {
return false;
}
@ -754,41 +727,6 @@ bool FormAutofillImpl::LabelMatchesRegExp(
return true;
}
}
Element* parent = aElement.GetParentElement();
if (!parent) {
return false;
}
ErrorResult aRv;
if (parent->IsHTMLElement(nsGkAtoms::td)) {
Element* pp = parent->GetParentElement();
if (pp) {
return TextContentMatchesRegExp(*pp, key);
}
}
if (parent->IsHTMLElement(nsGkAtoms::td)) {
Element* pes = aElement.GetPreviousElementSibling();
if (pes) {
return TextContentMatchesRegExp(*pes, key);
}
}
return false;
}
bool FormAutofillImpl::ClosestLabelMatchesRegExp(Element& aElement,
RegexKey aKey) {
ErrorResult aRv;
Element* pes = aElement.GetPreviousElementSibling();
if (pes && pes->IsHTMLElement(nsGkAtoms::label)) {
return TextContentMatchesRegExp(*pes, aKey);
}
Element* nes = aElement.GetNextElementSibling();
if (nes && nes->IsHTMLElement(nsGkAtoms::label)) {
return TextContentMatchesRegExp(*nes, aKey);
}
return false;
}
@ -843,6 +781,58 @@ bool FormAutofillImpl::RoleIsMenu(Element& aElement) {
nsGkAtoms::menu, eCaseMatters);
}
/**
* This function transforms the js implementation of isVisible in fathom.js
* to C++
*/
bool FormAutofillImpl::IsVisible(Element& aElement) {
nsIFrame* frame = aElement.GetPrimaryFrame();
if (!frame) {
return false;
}
// Alternative to reading ``display: none`` due to Bug 1381071.
// We don't check whether the element is zero-sized and overflow !== 'hidden'
// like we do in fathom.jsm because if the element is display: none then the
// frame is null, which we've already checked in the beginning of this
// function.
// This corresponding to `if (elementStyle.visibility === 'hidden')` check
// in isVisible (fathom.jsm)
const ComputedStyle& style = *frame->Style();
if (!style.StyleVisibility()->IsVisible()) {
return false;
}
// Check if the element is irrevocably off-screen:
nsRect elementRect = frame->GetBoundingClientRect();
if (elementRect.XMost() < 0 || elementRect.YMost() < 0) {
return false;
}
// Below is the translation of how we travese the ancestor chain in
// `isVisible`
if (style.IsInOpacityZeroSubtree()) {
return false;
}
// Zero-sized ancestors dont make descendants hidden unless the
// descendant has ``overflow: hidden``
// FIXME: That's wrong, this should check whether the ancestor
// https://github.com/mozilla/fathom/issues/300
bool elementIsHidden =
style.StyleDisplay()->mOverflowX == StyleOverflow::Hidden &&
style.StyleDisplay()->mOverflowY == StyleOverflow::Hidden;
if (elementIsHidden) {
for (; frame; frame = frame->GetInFlowParent()) {
if (frame->GetRect().IsEmpty()) {
return false;
}
}
}
return true;
}
bool FormAutofillImpl::InputTypeNotNumbery(Element& aElement) {
auto* input = HTMLInputElement::FromNode(aElement);
if (!input) {
@ -1171,16 +1161,28 @@ void FormAutofillImpl::GetFormAutofillConfidences(
auto& params = paramSet[i];
const auto& element = aElements[i];
Element* nextFillableField = NextField(aElements, i);
Element* prevFillableField = PrevField(aElements, i);
const nsTArray<nsCString>* labelStrings = GetLabelStrings(
element, elementsToLabelStrings, elementsIdToLabelStrings);
const nsTArray<nsCString>* nextLabelStrings = GetLabelStrings(
nextFillableField, elementsToLabelStrings, elementsIdToLabelStrings);
const nsTArray<nsCString>* prevLabelStrings = GetLabelStrings(
prevFillableField, elementsToLabelStrings, elementsIdToLabelStrings);
bool idOrNameMatchDwfrmAndBml =
IdOrNameMatchRegExp(element, RegexKey::DWFRM) &&
IdOrNameMatchRegExp(element, RegexKey::BML);
bool idOrNameMatchFirstAndLast =
IdOrNameMatchRegExp(element, RegexKey::FIRST) &&
IdOrNameMatchRegExp(element, RegexKey::LAST);
bool hasTemplatedValue = HasTemplatedValue(element);
bool isNotVisible = !IsVisible(element);
bool inputTypeNotNumbery = InputTypeNotNumbery(element);
bool idOrNameMatchSubscription =
IdOrNameMatchRegExp(element, RegexKey::SUBSCRIPTION);
bool roleIsMenu = RoleIsMenu(element);
#define RULE_IMPL2(rule, type) params.m##type##Params[type##Params::rule]
#define RULE_IMPL(rule, type) RULE_IMPL2(rule, type)
@ -1191,16 +1193,13 @@ void FormAutofillImpl::GetFormAutofillConfidences(
RULE(idOrNameMatchNumberRegExp) =
IdOrNameMatchRegExp(element, RegexKey::CC_NUMBER);
RULE(labelsMatchNumberRegExp) =
LabelMatchesRegExp(element, labelStrings, RegexKey::CC_NUMBER);
RULE(closestLabelMatchesNumberRegExp) =
ClosestLabelMatchesRegExp(element, RegexKey::CC_NUMBER);
LabelMatchesRegExp(labelStrings, RegexKey::CC_NUMBER);
RULE(placeholderMatchesNumberRegExp) =
PlaceholderMatchesRegExp(element, RegexKey::CC_NUMBER);
RULE(ariaLabelMatchesNumberRegExp) =
AriaLabelMatchesRegExp(element, RegexKey::CC_NUMBER);
RULE(idOrNameMatchGift) = IdOrNameMatchRegExp(element, RegexKey::GIFT);
RULE(labelsMatchGift) =
LabelMatchesRegExp(element, labelStrings, RegexKey::GIFT);
RULE(labelsMatchGift) = LabelMatchesRegExp(labelStrings, RegexKey::GIFT);
RULE(placeholderMatchesGift) =
PlaceholderMatchesRegExp(element, RegexKey::GIFT);
RULE(ariaLabelMatchesGift) =
@ -1208,47 +1207,28 @@ void FormAutofillImpl::GetFormAutofillConfidences(
RULE(idOrNameMatchSubscription) = idOrNameMatchSubscription;
RULE(idOrNameMatchDwfrmAndBml) = idOrNameMatchDwfrmAndBml;
RULE(hasTemplatedValue) = hasTemplatedValue;
RULE(isNotVisible) = isNotVisible;
RULE(inputTypeNotNumbery) = inputTypeNotNumbery;
#undef RULE_TYPE
// We only use Fathom to detect credit card number field for now.
// Comment out code below instead of removing them to make it clear that
// the current design is to support multiple rules.
/*
Element* nextFillableField = NextField(aElements, i);
Element* prevFillableField = PrevField(aElements, i);
const nsTArray<nsCString>* nextLabelStrings = GetLabelStrings(
nextFillableField, elementsToLabelStrings, elementsIdToLabelStrings);
const nsTArray<nsCString>* prevLabelStrings = GetLabelStrings(
prevFillableField, elementsToLabelStrings, elementsIdToLabelStrings);
bool idOrNameMatchFirstAndLast =
IdOrNameMatchRegExp(element, RegexKey::FIRST) &&
IdOrNameMatchRegExp(element, RegexKey::LAST);
bool roleIsMenu = RoleIsMenu(element);
// cc-name
#define RULE_TYPE CCName
RULE(idOrNameMatchNameRegExp) =
IdOrNameMatchRegExp(element, RegexKey::CC_NAME);
RULE(labelsMatchNameRegExp) =
LabelMatchesRegExp(element, labelStrings, RegexKey::CC_NAME);
RULE(closestLabelMatchesNameRegExp) =
ClosestLabelMatchesRegExp(element, RegexKey::CC_NAME);
LabelMatchesRegExp(labelStrings, RegexKey::CC_NAME);
RULE(placeholderMatchesNameRegExp) =
PlaceholderMatchesRegExp(element, RegexKey::CC_NAME);
RULE(ariaLabelMatchesNameRegExp) =
AriaLabelMatchesRegExp(element, RegexKey::CC_NAME);
RULE(idOrNameMatchFirst) = IdOrNameMatchRegExp(element, RegexKey::FIRST);
RULE(labelsMatchFirst) =
LabelMatchesRegExp(element, labelStrings, RegexKey::FIRST);
RULE(labelsMatchFirst) = LabelMatchesRegExp(labelStrings, RegexKey::FIRST);
RULE(placeholderMatchesFirst) =
PlaceholderMatchesRegExp(element, RegexKey::FIRST);
RULE(ariaLabelMatchesFirst) =
AriaLabelMatchesRegExp(element, RegexKey::FIRST);
RULE(idOrNameMatchLast) = IdOrNameMatchRegExp(element, RegexKey::LAST);
RULE(labelsMatchLast) =
LabelMatchesRegExp(element, labelStrings, RegexKey::LAST);
RULE(labelsMatchLast) = LabelMatchesRegExp(labelStrings, RegexKey::LAST);
RULE(placeholderMatchesLast) =
PlaceholderMatchesRegExp(element, RegexKey::LAST);
RULE(ariaLabelMatchesLast) =
@ -1257,6 +1237,7 @@ void FormAutofillImpl::GetFormAutofillConfidences(
RULE(idOrNameMatchFirstAndLast) = idOrNameMatchFirstAndLast;
RULE(idOrNameMatchDwfrmAndBml) = idOrNameMatchDwfrmAndBml;
RULE(hasTemplatedValue) = hasTemplatedValue;
RULE(isNotVisible) = isNotVisible;
#undef RULE_TYPE
// cc-type
@ -1264,9 +1245,7 @@ void FormAutofillImpl::GetFormAutofillConfidences(
RULE(idOrNameMatchTypeRegExp) =
IdOrNameMatchRegExp(element, RegexKey::CC_TYPE);
RULE(labelsMatchTypeRegExp) =
LabelMatchesRegExp(element, labelStrings, RegexKey::CC_TYPE);
RULE(closestLabelMatchesTypeRegExp) =
ClosestLabelMatchesRegExp(element, RegexKey::CC_TYPE);
LabelMatchesRegExp(labelStrings, RegexKey::CC_TYPE);
RULE(idOrNameMatchVisaCheckout) =
IdOrNameMatchRegExp(element, RegexKey::VISA_CHECKOUT);
RULE(ariaLabelMatchesVisaCheckout) =
@ -1287,17 +1266,14 @@ void FormAutofillImpl::GetFormAutofillConfidences(
// cc-exp
#define RULE_TYPE CCExp
RULE(labelsMatchExpRegExp) =
LabelMatchesRegExp(element, labelStrings, RegexKey::CC_EXP);
RULE(closestLabelMatchesExpRegExp) =
ClosestLabelMatchesRegExp(element, RegexKey::CC_EXP);
LabelMatchesRegExp(labelStrings, RegexKey::CC_EXP);
RULE(placeholderMatchesExpRegExp) =
PlaceholderMatchesRegExp(element, RegexKey::CC_EXP);
RULE(labelsMatchExpWith2Or4DigitYear) = LabelMatchesRegExp(
element, labelStrings, RegexKey::TWO_OR_FOUR_DIGIT_YEAR);
RULE(labelsMatchExpWith2Or4DigitYear) =
LabelMatchesRegExp(labelStrings, RegexKey::TWO_OR_FOUR_DIGIT_YEAR);
RULE(placeholderMatchesExpWith2Or4DigitYear) =
PlaceholderMatchesRegExp(element, RegexKey::TWO_OR_FOUR_DIGIT_YEAR);
RULE(labelsMatchMMYY) =
LabelMatchesRegExp(element, labelStrings, RegexKey::MMYY);
RULE(labelsMatchMMYY) = LabelMatchesRegExp(labelStrings, RegexKey::MMYY);
RULE(placeholderMatchesMMYY) =
PlaceholderMatchesRegExp(element, RegexKey::MMYY);
RULE(maxLengthIs7) = MaxLengthIs(element, 7);
@ -1321,16 +1297,13 @@ void FormAutofillImpl::GetFormAutofillConfidences(
RULE(idOrNameMatchExpMonthRegExp) =
IdOrNameMatchRegExp(element, RegexKey::CC_EXP_MONTH);
RULE(labelsMatchExpMonthRegExp) =
LabelMatchesRegExp(element, labelStrings, RegexKey::CC_EXP_MONTH);
RULE(closestLabelMatchesExpMonthRegExp) =
ClosestLabelMatchesRegExp(element, RegexKey::CC_EXP_MONTH);
LabelMatchesRegExp(labelStrings, RegexKey::CC_EXP_MONTH);
RULE(placeholderMatchesExpMonthRegExp) =
PlaceholderMatchesRegExp(element, RegexKey::CC_EXP_MONTH);
RULE(ariaLabelMatchesExpMonthRegExp) =
AriaLabelMatchesRegExp(element, RegexKey::CC_EXP_MONTH);
RULE(idOrNameMatchMonth) = IdOrNameMatchRegExp(element, RegexKey::MONTH);
RULE(labelsMatchMonth) =
LabelMatchesRegExp(element, labelStrings, RegexKey::MONTH);
RULE(labelsMatchMonth) = LabelMatchesRegExp(labelStrings, RegexKey::MONTH);
RULE(placeholderMatchesMonth) =
PlaceholderMatchesRegExp(element, RegexKey::MONTH);
RULE(ariaLabelMatchesMonth) =
@ -1340,7 +1313,7 @@ void FormAutofillImpl::GetFormAutofillConfidences(
IdOrNameMatchRegExp(*nextFillableField, RegexKey::CC_EXP_YEAR);
RULE(nextFieldLabelsMatchExpYearRegExp) =
nextFillableField &&
LabelMatchesRegExp(element, nextLabelStrings, RegexKey::CC_EXP_YEAR);
LabelMatchesRegExp(nextLabelStrings, RegexKey::CC_EXP_YEAR);
RULE(nextFieldPlaceholderMatchExpYearRegExp) =
nextFillableField &&
PlaceholderMatchesRegExp(*nextFillableField, RegexKey::CC_EXP_YEAR);
@ -1352,7 +1325,7 @@ void FormAutofillImpl::GetFormAutofillConfidences(
IdOrNameMatchRegExp(*nextFillableField, RegexKey::YEAR);
RULE(nextFieldLabelsMatchYear) =
nextFillableField &&
LabelMatchesRegExp(element, nextLabelStrings, RegexKey::YEAR);
LabelMatchesRegExp(nextLabelStrings, RegexKey::YEAR);
RULE(nextFieldPlaceholderMatchesYear) =
nextFillableField &&
PlaceholderMatchesRegExp(*nextFillableField, RegexKey::YEAR);
@ -1379,16 +1352,13 @@ void FormAutofillImpl::GetFormAutofillConfidences(
RULE(idOrNameMatchExpYearRegExp) =
IdOrNameMatchRegExp(element, RegexKey::CC_EXP_YEAR);
RULE(labelsMatchExpYearRegExp) =
LabelMatchesRegExp(element, labelStrings, RegexKey::CC_EXP_YEAR);
RULE(closestLabelMatchesExpYearRegExp) =
ClosestLabelMatchesRegExp(element, RegexKey::CC_EXP_YEAR);
LabelMatchesRegExp(labelStrings, RegexKey::CC_EXP_YEAR);
RULE(placeholderMatchesExpYearRegExp) =
PlaceholderMatchesRegExp(element, RegexKey::CC_EXP_YEAR);
RULE(ariaLabelMatchesExpYearRegExp) =
AriaLabelMatchesRegExp(element, RegexKey::CC_EXP_YEAR);
RULE(idOrNameMatchYear) = IdOrNameMatchRegExp(element, RegexKey::YEAR);
RULE(labelsMatchYear) =
LabelMatchesRegExp(element, labelStrings, RegexKey::YEAR);
RULE(labelsMatchYear) = LabelMatchesRegExp(labelStrings, RegexKey::YEAR);
RULE(placeholderMatchesYear) =
PlaceholderMatchesRegExp(element, RegexKey::YEAR);
RULE(ariaLabelMatchesYear) =
@ -1398,7 +1368,7 @@ void FormAutofillImpl::GetFormAutofillConfidences(
IdOrNameMatchRegExp(*prevFillableField, RegexKey::CC_EXP_MONTH);
RULE(previousFieldLabelsMatchExpMonthRegExp) =
prevFillableField &&
LabelMatchesRegExp(element, prevLabelStrings, RegexKey::CC_EXP_MONTH);
LabelMatchesRegExp(prevLabelStrings, RegexKey::CC_EXP_MONTH);
RULE(previousFieldPlaceholderMatchExpMonthRegExp) =
prevFillableField &&
PlaceholderMatchesRegExp(*prevFillableField, RegexKey::CC_EXP_MONTH);
@ -1410,7 +1380,7 @@ void FormAutofillImpl::GetFormAutofillConfidences(
IdOrNameMatchRegExp(*prevFillableField, RegexKey::MONTH);
RULE(previousFieldLabelsMatchMonth) =
prevFillableField &&
LabelMatchesRegExp(element, prevLabelStrings, RegexKey::MONTH);
LabelMatchesRegExp(prevLabelStrings, RegexKey::MONTH);
RULE(previousFieldPlaceholderMatchesMonth) =
prevFillableField &&
PlaceholderMatchesRegExp(*prevFillableField, RegexKey::MONTH);
@ -1430,28 +1400,25 @@ void FormAutofillImpl::GetFormAutofillConfidences(
RULE(idOrNameMatchDwfrmAndBml) = idOrNameMatchDwfrmAndBml;
RULE(hasTemplatedValue) = hasTemplatedValue;
#undef RULE_TYPE
*/
#undef RULE_IMPL2
#undef RULE_IMPL
#undef RULE
// Calculating the final score of each rule
FormAutofillConfidences score;
#define CALCULATE_SCORE(type, score) \
for (auto i : MakeEnumeratedRange(type##Params::Count)) { \
(score) += params.m##type##Params[i] * kCoefficents.m##type##Params[i]; \
} \
(score) = Sigmoid(score + k##type##Bias);
// Calculating the final score of each rule
FormAutofillConfidences score;
CALCULATE_SCORE(CCNumber, score.mCcNumber)
// Comment out code that are used for other rules.
// CALCULATE_SCORE(CCName, score.mCcName)
// CALCULATE_SCORE(CCType, score.mCcType)
// CALCULATE_SCORE(CCExp, score.mCcExp)
// CALCULATE_SCORE(CCExpMonth, score.mCcExpMonth)
// CALCULATE_SCORE(CCExpYear, score.mCcExpYear)
CALCULATE_SCORE(CCName, score.mCcName)
CALCULATE_SCORE(CCType, score.mCcType)
CALCULATE_SCORE(CCExp, score.mCcExp)
CALCULATE_SCORE(CCExpMonth, score.mCcExpMonth)
CALCULATE_SCORE(CCExpYear, score.mCcExpYear)
#undef CALCULATE_SCORE