Commit a8d4c5d8 authored by Demetrios Papadopoulos's avatar Demetrios Papadopoulos Committed by Commit Bot

Fix ESLint no-var and prefer-const violations in components/autofill/.

Most of these have been fixed automatically with ESLint's --fix flag.

This is in preparation of turning on presubmit checks for no-var and prefer-const
for components/.

Bug: 792774,720034
Change-Id: I482ed8577bf260a6190fb646891194f8d533debc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1914496
Auto-Submit: Demetrios Papadopoulos <dpapad@chromium.org>
Commit-Queue: Moe Ahmadi <mahmadi@chromium.org>
Reviewed-by: default avatarMoe Ahmadi <mahmadi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#715885}
parent a6a21025
...@@ -25,14 +25,14 @@ function nodeToDomNode(node) { ...@@ -25,14 +25,14 @@ function nodeToDomNode(node) {
return document.createTextNode(node.value); return document.createTextNode(node.value);
} }
// Else the node is of type 'element'. // Else the node is of type 'element'.
var domNode = document.createElement(node.value); const domNode = document.createElement(node.value);
if ('children' in node) { if ('children' in node) {
node.children.forEach((child) => { node.children.forEach((child) => {
domNode.appendChild(nodeToDomNode(child)); domNode.appendChild(nodeToDomNode(child));
}); });
} }
if ('attributes' in node) { if ('attributes' in node) {
for (var attribute in node.attributes) { for (const attribute in node.attributes) {
domNode.setAttribute(attribute, node.attributes[attribute]); domNode.setAttribute(attribute, node.attributes[attribute]);
} }
} }
...@@ -84,12 +84,12 @@ function notifyAboutIncognito(isIncognito) { ...@@ -84,12 +84,12 @@ function notifyAboutIncognito(isIncognito) {
} }
function notifyAboutVariations(variations) { function notifyAboutVariations(variations) {
var list = document.createElement("div"); const list = document.createElement("div");
for (let item of variations) { for (const item of variations) {
list.appendChild(document.createTextNode(item)); list.appendChild(document.createTextNode(item));
list.appendChild(document.createElement("br")); list.appendChild(document.createElement("br"));
} }
var variationsList = document.getElementById("variations-list"); const variationsList = document.getElementById("variations-list");
variationsList.appendChild(list); variationsList.appendChild(list);
} }
......
...@@ -24,6 +24,7 @@ goog.provide('__crWeb.autofill'); ...@@ -24,6 +24,7 @@ goog.provide('__crWeb.autofill');
* fields: !Object<string, !Object<string, string>>, * fields: !Object<string, !Object<string, string>>,
* }} * }}
*/ */
// eslint-disable-next-line no-var
var FormData; var FormData;
/* Beginning of anonymous object. */ /* Beginning of anonymous object. */
...@@ -85,7 +86,7 @@ __gCrWeb.autofill.setDelay = function(delay) { ...@@ -85,7 +86,7 @@ __gCrWeb.autofill.setDelay = function(delay) {
* @return {boolean} Whether the element is inside a <form> or <fieldset>. * @return {boolean} Whether the element is inside a <form> or <fieldset>.
*/ */
function isElementInsideFormOrFieldSet(element) { function isElementInsideFormOrFieldSet(element) {
var parentNode = element.parentNode; let parentNode = element.parentNode;
while (parentNode) { while (parentNode) {
if ((parentNode.nodeType === Node.ELEMENT_NODE) && if ((parentNode.nodeType === Node.ELEMENT_NODE) &&
(__gCrWeb.fill.hasTagName(parentNode, 'form') || (__gCrWeb.fill.hasTagName(parentNode, 'form') ||
...@@ -121,7 +122,7 @@ function isFormInteresting_(form, numEditableElements, numFieldsRequired) { ...@@ -121,7 +122,7 @@ function isFormInteresting_(form, numEditableElements, numFieldsRequired) {
// If the form has at least one field with an autocomplete attribute, it is a // If the form has at least one field with an autocomplete attribute, it is a
// candidate for autofill. // candidate for autofill.
for (var i = 0; i < form.fields.length; ++i) { for (let i = 0; i < form.fields.length; ++i) {
if (form.fields[i]['autocomplete_attribute'] != null && if (form.fields[i]['autocomplete_attribute'] != null &&
form.fields[i]['autocomplete_attribute'].length > 0) { form.fields[i]['autocomplete_attribute'].length > 0) {
return true; return true;
...@@ -151,10 +152,10 @@ function isFormInteresting_(form, numEditableElements, numFieldsRequired) { ...@@ -151,10 +152,10 @@ function isFormInteresting_(form, numEditableElements, numFieldsRequired) {
* @return {number} The number of editable elements. * @return {number} The number of editable elements.
*/ */
function scanFormControlElements_(controlElements) { function scanFormControlElements_(controlElements) {
var numEditableElements = 0; let numEditableElements = 0;
for (var elementIndex = 0; elementIndex < controlElements.length; for (let elementIndex = 0; elementIndex < controlElements.length;
++elementIndex) { ++elementIndex) {
var element = controlElements[elementIndex]; const element = controlElements[elementIndex];
if (!__gCrWeb.fill.isCheckableElement(element)) { if (!__gCrWeb.fill.isCheckableElement(element)) {
++numEditableElements; ++numEditableElements;
} }
...@@ -182,8 +183,8 @@ function scanFormControlElements_(controlElements) { ...@@ -182,8 +183,8 @@ function scanFormControlElements_(controlElements) {
* @return {Array<FormControlElement>} The elements that are not part of a form. * @return {Array<FormControlElement>} The elements that are not part of a form.
*/ */
function getUnownedAutofillableFormFieldElements_(elements, fieldsets) { function getUnownedAutofillableFormFieldElements_(elements, fieldsets) {
var unownedFieldsetChildren = []; const unownedFieldsetChildren = [];
for (var i = 0; i < elements.length; ++i) { for (let i = 0; i < elements.length; ++i) {
if (__gCrWeb.form.isFormControlElement(elements[i])) { if (__gCrWeb.form.isFormControlElement(elements[i])) {
if (!elements[i].form) { if (!elements[i].form) {
unownedFieldsetChildren.push(elements[i]); unownedFieldsetChildren.push(elements[i]);
...@@ -213,7 +214,7 @@ function getUnownedAutofillableFormFieldElements_(elements, fieldsets) { ...@@ -213,7 +214,7 @@ function getUnownedAutofillableFormFieldElements_(elements, fieldsets) {
*/ */
__gCrWeb.autofill['extractForms'] = function( __gCrWeb.autofill['extractForms'] = function(
requiredFields, restrictUnownedFieldsToFormlessCheckout) { requiredFields, restrictUnownedFieldsToFormlessCheckout) {
var forms = __gCrWeb.autofill.extractNewForms( const forms = __gCrWeb.autofill.extractNewForms(
requiredFields, restrictUnownedFieldsToFormlessCheckout); requiredFields, restrictUnownedFieldsToFormlessCheckout);
return __gCrWeb.stringify(forms); return __gCrWeb.stringify(forms);
}; };
...@@ -224,7 +225,7 @@ __gCrWeb.autofill['extractForms'] = function( ...@@ -224,7 +225,7 @@ __gCrWeb.autofill['extractForms'] = function(
* @param {AutofillFormFieldData} data The data to fill in. * @param {AutofillFormFieldData} data The data to fill in.
*/ */
__gCrWeb.autofill['fillActiveFormField'] = function(data) { __gCrWeb.autofill['fillActiveFormField'] = function(data) {
var activeElement = document.activeElement; const activeElement = document.activeElement;
if (data['identifier'] !== __gCrWeb.form.getFieldIdentifier(activeElement)) { if (data['identifier'] !== __gCrWeb.form.getFieldIdentifier(activeElement)) {
return; return;
} }
...@@ -254,7 +255,7 @@ function controlElementInputListener_(evt) { ...@@ -254,7 +255,7 @@ function controlElementInputListener_(evt) {
__gCrWeb.autofill['fillForm'] = function(data, forceFillFieldIdentifier) { __gCrWeb.autofill['fillForm'] = function(data, forceFillFieldIdentifier) {
// Inject CSS to style the autofilled elements with a yellow background. // Inject CSS to style the autofilled elements with a yellow background.
if (!__gCrWeb.autofill.styleInjected) { if (!__gCrWeb.autofill.styleInjected) {
var style = document.createElement('style'); const style = document.createElement('style');
style.textContent = '[chrome-autofilled] {' + style.textContent = '[chrome-autofilled] {' +
'background-color:#E8F0FE !important;' + 'background-color:#E8F0FE !important;' +
'background-image:none !important;' + 'background-image:none !important;' +
...@@ -264,13 +265,13 @@ __gCrWeb.autofill['fillForm'] = function(data, forceFillFieldIdentifier) { ...@@ -264,13 +265,13 @@ __gCrWeb.autofill['fillForm'] = function(data, forceFillFieldIdentifier) {
__gCrWeb.autofill.styleInjected = true; __gCrWeb.autofill.styleInjected = true;
} }
var form = __gCrWeb.form.getFormElementFromIdentifier(data.formName); const form = __gCrWeb.form.getFormElementFromIdentifier(data.formName);
var controlElements = form ? const controlElements = form ?
__gCrWeb.form.getFormControlElements(form) : __gCrWeb.form.getFormControlElements(form) :
getUnownedAutofillableFormFieldElements_(document.all, /*fieldsets=*/[]); getUnownedAutofillableFormFieldElements_(document.all, /*fieldsets=*/[]);
for (var i = 0, delay = 0; i < controlElements.length; ++i) { for (let i = 0, delay = 0; i < controlElements.length; ++i) {
var element = controlElements[i]; const element = controlElements[i];
if (!__gCrWeb.fill.isAutofillableElement(element)) { if (!__gCrWeb.fill.isAutofillableElement(element)) {
continue; continue;
} }
...@@ -281,8 +282,8 @@ __gCrWeb.autofill['fillForm'] = function(data, forceFillFieldIdentifier) { ...@@ -281,8 +282,8 @@ __gCrWeb.autofill['fillForm'] = function(data, forceFillFieldIdentifier) {
} }
// Skip fields for which autofill data is missing. // Skip fields for which autofill data is missing.
var fieldIdentifier = __gCrWeb.form.getFieldIdentifier(element); const fieldIdentifier = __gCrWeb.form.getFieldIdentifier(element);
var fieldData = data.fields[fieldIdentifier]; const fieldData = data.fields[fieldIdentifier];
if (!fieldData) { if (!fieldData) {
continue; continue;
} }
...@@ -322,9 +323,9 @@ __gCrWeb.autofill['fillForm'] = function(data, forceFillFieldIdentifier) { ...@@ -322,9 +323,9 @@ __gCrWeb.autofill['fillForm'] = function(data, forceFillFieldIdentifier) {
// Remove Autofill styling when form receives 'reset' event. // Remove Autofill styling when form receives 'reset' event.
// Individual control elements may be left with 'input' event listeners but // Individual control elements may be left with 'input' event listeners but
// they are harmless. // they are harmless.
var formResetListener = function(evt) { const formResetListener = function(evt) {
var controlElements = __gCrWeb.form.getFormControlElements(evt.target); const controlElements = __gCrWeb.form.getFormControlElements(evt.target);
for (var i = 0; i < controlElements.length; ++i) { for (let i = 0; i < controlElements.length; ++i) {
controlElements[i].removeAttribute('chrome-autofilled'); controlElements[i].removeAttribute('chrome-autofilled');
controlElements[i].isAutofilled = false; controlElements[i].isAutofilled = false;
} }
...@@ -350,13 +351,13 @@ __gCrWeb.autofill['fillForm'] = function(data, forceFillFieldIdentifier) { ...@@ -350,13 +351,13 @@ __gCrWeb.autofill['fillForm'] = function(data, forceFillFieldIdentifier) {
*/ */
__gCrWeb.autofill['clearAutofilledFields'] = function( __gCrWeb.autofill['clearAutofilledFields'] = function(
formName, fieldIdentifier) { formName, fieldIdentifier) {
var form = __gCrWeb.form.getFormElementFromIdentifier(formName); const form = __gCrWeb.form.getFormElementFromIdentifier(formName);
var controlElements = form ? const controlElements = form ?
__gCrWeb.form.getFormControlElements(form) : __gCrWeb.form.getFormControlElements(form) :
getUnownedAutofillableFormFieldElements_(document.all, /*fieldsets=*/[]); getUnownedAutofillableFormFieldElements_(document.all, /*fieldsets=*/[]);
var formField = null; let formField = null;
for (var i = 0; i < controlElements.length; ++i) { for (let i = 0; i < controlElements.length; ++i) {
if (__gCrWeb.form.getFieldIdentifier(controlElements[i]) == if (__gCrWeb.form.getFieldIdentifier(controlElements[i]) ==
fieldIdentifier) { fieldIdentifier) {
formField = controlElements[i]; formField = controlElements[i];
...@@ -364,8 +365,8 @@ __gCrWeb.autofill['clearAutofilledFields'] = function( ...@@ -364,8 +365,8 @@ __gCrWeb.autofill['clearAutofilledFields'] = function(
} }
} }
for (var i = 0, delay = 0; i < controlElements.length; ++i) { for (let i = 0, delay = 0; i < controlElements.length; ++i) {
var element = controlElements[i]; const element = controlElements[i];
if (!element.isAutofilled || element.disabled) { if (!element.isAutofilled || element.disabled) {
continue; continue;
} }
...@@ -374,7 +375,7 @@ __gCrWeb.autofill['clearAutofilledFields'] = function( ...@@ -374,7 +375,7 @@ __gCrWeb.autofill['clearAutofilledFields'] = function(
continue; continue;
} }
var value = null; let value = null;
if (__gCrWeb.fill.isTextInput(element) || if (__gCrWeb.fill.isTextInput(element) ||
__gCrWeb.fill.isTextAreaElement(element)) { __gCrWeb.fill.isTextAreaElement(element)) {
value = ''; value = '';
...@@ -428,30 +429,30 @@ __gCrWeb.autofill['clearAutofilledFields'] = function( ...@@ -428,30 +429,30 @@ __gCrWeb.autofill['clearAutofilledFields'] = function(
*/ */
__gCrWeb.autofill.extractNewForms = function( __gCrWeb.autofill.extractNewForms = function(
minimumRequiredFields, restrictUnownedFieldsToFormlessCheckout) { minimumRequiredFields, restrictUnownedFieldsToFormlessCheckout) {
var forms = []; const forms = [];
// Protect against custom implementation of Array.toJSON in host pages. // Protect against custom implementation of Array.toJSON in host pages.
/** @suppress {checkTypes} */ (function() { /** @suppress {checkTypes} */ (function() {
forms.toJSON = null; forms.toJSON = null;
})(); })();
/** @type {HTMLCollection} */ /** @type {HTMLCollection} */
var webForms = document.forms; const webForms = document.forms;
var extractMask = const extractMask =
__gCrWeb.fill.EXTRACT_MASK_VALUE | __gCrWeb.fill.EXTRACT_MASK_OPTIONS; __gCrWeb.fill.EXTRACT_MASK_VALUE | __gCrWeb.fill.EXTRACT_MASK_OPTIONS;
var numFieldsSeen = 0; let numFieldsSeen = 0;
for (var formIndex = 0; formIndex < webForms.length; ++formIndex) { for (let formIndex = 0; formIndex < webForms.length; ++formIndex) {
/** @type {HTMLFormElement} */ /** @type {HTMLFormElement} */
var formElement = webForms[formIndex]; const formElement = webForms[formIndex];
var controlElements = const controlElements =
__gCrWeb.autofill.extractAutofillableElementsInForm(formElement); __gCrWeb.autofill.extractAutofillableElementsInForm(formElement);
var numEditableElements = scanFormControlElements_(controlElements); const numEditableElements = scanFormControlElements_(controlElements);
if (numEditableElements === 0) { if (numEditableElements === 0) {
continue; continue;
} }
var form = new __gCrWeb['common'].JSONSafeObject; const form = new __gCrWeb['common'].JSONSafeObject;
if (!__gCrWeb.fill.webFormElementToFormData( if (!__gCrWeb.fill.webFormElementToFormData(
window, formElement, null, extractMask, form, null /* field */)) { window, formElement, null, extractMask, form, null /* field */)) {
continue; continue;
...@@ -468,20 +469,20 @@ __gCrWeb.autofill.extractNewForms = function( ...@@ -468,20 +469,20 @@ __gCrWeb.autofill.extractNewForms = function(
} }
// Look for more parseable fields outside of forms. // Look for more parseable fields outside of forms.
var fieldsets = []; const fieldsets = [];
var unownedControlElements = const unownedControlElements =
getUnownedAutofillableFormFieldElements_(document.all, fieldsets); getUnownedAutofillableFormFieldElements_(document.all, fieldsets);
var numEditableUnownedElements = const numEditableUnownedElements =
scanFormControlElements_(unownedControlElements); scanFormControlElements_(unownedControlElements);
if (numEditableUnownedElements > 0) { if (numEditableUnownedElements > 0) {
var unownedForm = new __gCrWeb['common'].JSONSafeObject; const unownedForm = new __gCrWeb['common'].JSONSafeObject;
var hasUnownedForm = unownedFormElementsAndFieldSetsToFormData_( const hasUnownedForm = unownedFormElementsAndFieldSetsToFormData_(
window, fieldsets, unownedControlElements, extractMask, window, fieldsets, unownedControlElements, extractMask,
restrictUnownedFieldsToFormlessCheckout, unownedForm); restrictUnownedFieldsToFormlessCheckout, unownedForm);
if (hasUnownedForm) { if (hasUnownedForm) {
numFieldsSeen += unownedForm['fields'].length; numFieldsSeen += unownedForm['fields'].length;
if (numFieldsSeen <= __gCrWeb.fill.MAX_PARSEABLE_FIELDS) { if (numFieldsSeen <= __gCrWeb.fill.MAX_PARSEABLE_FIELDS) {
var interesting = isFormInteresting_( const interesting = isFormInteresting_(
unownedForm, numEditableUnownedElements, minimumRequiredFields); unownedForm, numEditableUnownedElements, minimumRequiredFields);
if (interesting) { if (interesting) {
forms.push(unownedForm); forms.push(unownedForm);
...@@ -562,17 +563,17 @@ function unownedFormElementsAndFieldSetsToFormData_( ...@@ -562,17 +563,17 @@ function unownedFormElementsAndFieldSetsToFormData_(
controlElements, extractMask, form, null /* field */); controlElements, extractMask, form, null /* field */);
} }
var title = document.title.toLowerCase(); const title = document.title.toLowerCase();
var path = document.location.pathname.toLowerCase(); const path = document.location.pathname.toLowerCase();
// The keywords are defined in // The keywords are defined in
// UnownedCheckoutFormElementsAndFieldSetsToFormData in // UnownedCheckoutFormElementsAndFieldSetsToFormData in
// components/autofill/content/renderer/form_autofill_util.cc // components/autofill/content/renderer/form_autofill_util.cc
var keywords = const keywords =
['payment', 'checkout', 'address', 'delivery', 'shipping', 'wallet']; ['payment', 'checkout', 'address', 'delivery', 'shipping', 'wallet'];
var count = keywords.length; const count = keywords.length;
for (var index = 0; index < count; index++) { for (let index = 0; index < count; index++) {
var keyword = keywords[index]; const keyword = keywords[index];
if (title.includes(keyword) || path.includes(keyword)) { if (title.includes(keyword) || path.includes(keyword)) {
form['is_formless_checkout'] = true; form['is_formless_checkout'] = true;
return __gCrWeb.fill.formOrFieldsetsToFormData( return __gCrWeb.fill.formOrFieldsetsToFormData(
...@@ -583,8 +584,8 @@ function unownedFormElementsAndFieldSetsToFormData_( ...@@ -583,8 +584,8 @@ function unownedFormElementsAndFieldSetsToFormData_(
// Since it's not a checkout flow, only add fields that have a non-"off" // Since it's not a checkout flow, only add fields that have a non-"off"
// autocomplete attribute to the formless autofill. // autocomplete attribute to the formless autofill.
var controlElementsWithAutocomplete = []; const controlElementsWithAutocomplete = [];
for (var index = 0; index < controlElements.length; index++) { for (let index = 0; index < controlElements.length; index++) {
if (controlElements[index].hasAttribute('autocomplete') && if (controlElements[index].hasAttribute('autocomplete') &&
controlElements[index].getAttribute('autocomplete') !== 'off') { controlElements[index].getAttribute('autocomplete') !== 'off') {
controlElementsWithAutocomplete.push(controlElements[index]); controlElementsWithAutocomplete.push(controlElements[index]);
...@@ -623,12 +624,12 @@ __gCrWeb.autofill.fillFormField = function(data, field) { ...@@ -623,12 +624,12 @@ __gCrWeb.autofill.fillFormField = function(data, field) {
if (__gCrWeb.fill.isTextInput(field) || if (__gCrWeb.fill.isTextInput(field) ||
__gCrWeb.fill.isTextAreaElement(field)) { __gCrWeb.fill.isTextAreaElement(field)) {
var sanitizedValue = data['value']; let sanitizedValue = data['value'];
if (__gCrWeb.fill.isTextInput(field)) { if (__gCrWeb.fill.isTextInput(field)) {
// If the 'max_length' attribute contains a negative value, the default // If the 'max_length' attribute contains a negative value, the default
// maxlength value is used. // maxlength value is used.
var maxLength = data['max_length']; let maxLength = data['max_length'];
if (maxLength < 0) { if (maxLength < 0) {
maxLength = __gCrWeb.fill.MAX_DATA_LENGTH; maxLength = __gCrWeb.fill.MAX_DATA_LENGTH;
} }
...@@ -658,9 +659,9 @@ __gCrWeb.autofill.fillFormField = function(data, field) { ...@@ -658,9 +659,9 @@ __gCrWeb.autofill.fillFormField = function(data, field) {
*/ */
__gCrWeb.autofill.extractAutofillableElementsFromSet = function( __gCrWeb.autofill.extractAutofillableElementsFromSet = function(
controlElements) { controlElements) {
var autofillableElements = []; const autofillableElements = [];
for (var i = 0; i < controlElements.length; ++i) { for (let i = 0; i < controlElements.length; ++i) {
var element = controlElements[i]; const element = controlElements[i];
if (!__gCrWeb.fill.isAutofillableElement(element)) { if (!__gCrWeb.fill.isAutofillableElement(element)) {
continue; continue;
} }
...@@ -681,7 +682,7 @@ __gCrWeb.autofill.extractAutofillableElementsFromSet = function( ...@@ -681,7 +682,7 @@ __gCrWeb.autofill.extractAutofillableElementsFromSet = function(
* @return {Array<FormControlElement>} The array of autofillable elements. * @return {Array<FormControlElement>} The array of autofillable elements.
*/ */
__gCrWeb.autofill.extractAutofillableElementsInForm = function(formElement) { __gCrWeb.autofill.extractAutofillableElementsInForm = function(formElement) {
var controlElements = __gCrWeb.form.getFormControlElements(formElement); const controlElements = __gCrWeb.form.getFormControlElements(formElement);
return __gCrWeb.autofill.extractAutofillableElementsFromSet(controlElements); return __gCrWeb.autofill.extractAutofillableElementsFromSet(controlElements);
}; };
...@@ -693,17 +694,17 @@ __gCrWeb.autofill.extractAutofillableElementsInForm = function(formElement) { ...@@ -693,17 +694,17 @@ __gCrWeb.autofill.extractAutofillableElementsInForm = function(formElement) {
* their prediction data. * their prediction data.
*/ */
__gCrWeb.autofill['fillPredictionData'] = function(data) { __gCrWeb.autofill['fillPredictionData'] = function(data) {
for (var formName in data) { for (const formName in data) {
var form = __gCrWeb.form.getFormElementFromIdentifier(formName); const form = __gCrWeb.form.getFormElementFromIdentifier(formName);
var formData = data[formName]; const formData = data[formName];
var controlElements = __gCrWeb.form.getFormControlElements(form); const controlElements = __gCrWeb.form.getFormControlElements(form);
for (var i = 0; i < controlElements.length; ++i) { for (let i = 0; i < controlElements.length; ++i) {
var element = controlElements[i]; const element = controlElements[i];
if (!__gCrWeb.fill.isAutofillableElement(element)) { if (!__gCrWeb.fill.isAutofillableElement(element)) {
continue; continue;
} }
var elementName = __gCrWeb.form.getFieldIdentifier(element); const elementName = __gCrWeb.form.getFieldIdentifier(element);
var value = formData[elementName]; const value = formData[elementName];
if (value) { if (value) {
element.placeholder = value; element.placeholder = value;
} }
......
...@@ -32,11 +32,11 @@ __gCrWeb['suggestion'] = __gCrWeb.suggestion; ...@@ -32,11 +32,11 @@ __gCrWeb['suggestion'] = __gCrWeb.suggestion;
* @param {string} name The name of the desired element. * @param {string} name The name of the desired element.
* @return {Element} The element if found, otherwise null; * @return {Element} The element if found, otherwise null;
*/ */
var getElementByNameWithParent = function(parent, name) { const getElementByNameWithParent = function(parent, name) {
if (parent.name === name) return parent; if (parent.name === name) return parent;
var el; let el;
for (var i = 0; i < parent.children.length; i++) { for (let i = 0; i < parent.children.length; i++) {
el = getElementByNameWithParent(parent.children[i], name); el = getElementByNameWithParent(parent.children[i], name);
if (el) return el; if (el) return el;
} }
...@@ -58,8 +58,8 @@ var getElementByNameWithParent = function(parent, name) { ...@@ -58,8 +58,8 @@ var getElementByNameWithParent = function(parent, name) {
*/ */
__gCrWeb.suggestion.getNextElementInTabOrder = function( __gCrWeb.suggestion.getNextElementInTabOrder = function(
elementToCompare, elementList) { elementToCompare, elementList) {
var elements = []; const elements = [];
for (var i = 0; i < elementList.length; ++i) { for (let i = 0; i < elementList.length; ++i) {
elements[i] = elementList[i]; elements[i] = elementList[i];
} }
// There is no defined behavior if the element is not reachable. Here the // There is no defined behavior if the element is not reachable. Here the
...@@ -69,12 +69,12 @@ __gCrWeb.suggestion.getNextElementInTabOrder = function( ...@@ -69,12 +69,12 @@ __gCrWeb.suggestion.getNextElementInTabOrder = function(
// TODO(chenyu): investigate and simulate Mobile Safari's behavior when // TODO(chenyu): investigate and simulate Mobile Safari's behavior when
// |elementToCompare| is the last one in DOM tree order. // |elementToCompare| is the last one in DOM tree order.
if (!__gCrWeb.suggestion.isSequentiallyReachable(elementToCompare)) { if (!__gCrWeb.suggestion.isSequentiallyReachable(elementToCompare)) {
var indexToCompare = elements.indexOf(elementToCompare); const indexToCompare = elements.indexOf(elementToCompare);
if (indexToCompare === elements.length - 1 || indexToCompare === -1) { if (indexToCompare === elements.length - 1 || indexToCompare === -1) {
return null; return null;
} }
for (var index = indexToCompare + 1; index < elements.length; ++index) { for (let index = indexToCompare + 1; index < elements.length; ++index) {
var element = elements[index]; const element = elements[index];
if (__gCrWeb.suggestion.isSequentiallyReachable(element)) { if (__gCrWeb.suggestion.isSequentiallyReachable(element)) {
return element; return element;
} }
...@@ -85,9 +85,9 @@ __gCrWeb.suggestion.getNextElementInTabOrder = function( ...@@ -85,9 +85,9 @@ __gCrWeb.suggestion.getNextElementInTabOrder = function(
// Returns true iff |element1| that has DOM tree position |index1| is after // Returns true iff |element1| that has DOM tree position |index1| is after
// |element2| that has DOM tree position |index2| in tab order. It is assumed // |element2| that has DOM tree position |index2| in tab order. It is assumed
// |index1 !== index2|. // |index1 !== index2|.
var comparator = function(element1, index1, element2, index2) { const comparator = function(element1, index1, element2, index2) {
var tabOrder1 = __gCrWeb.suggestion.getTabOrder(element1); const tabOrder1 = __gCrWeb.suggestion.getTabOrder(element1);
var tabOrder2 = __gCrWeb.suggestion.getTabOrder(element2); const tabOrder2 = __gCrWeb.suggestion.getTabOrder(element2);
return tabOrder1 > tabOrder2 || return tabOrder1 > tabOrder2 ||
(tabOrder1 === tabOrder2 && index1 > index2); (tabOrder1 === tabOrder2 && index1 > index2);
}; };
...@@ -110,20 +110,20 @@ __gCrWeb.suggestion.getNextElementInTabOrder = function( ...@@ -110,20 +110,20 @@ __gCrWeb.suggestion.getNextElementInTabOrder = function(
*/ */
__gCrWeb.suggestion.getPreviousElementInTabOrder = function( __gCrWeb.suggestion.getPreviousElementInTabOrder = function(
elementToCompare, elementList) { elementToCompare, elementList) {
var elements = []; const elements = [];
for (var i = 0; i < elementList.length; ++i) { for (let i = 0; i < elementList.length; ++i) {
elements[i] = elementList[i]; elements[i] = elementList[i];
} }
// There is no defined behavior if the element is not reachable. Here the // There is no defined behavior if the element is not reachable. Here the
// previous reachable element in DOM tree order is returned. // previous reachable element in DOM tree order is returned.
if (!__gCrWeb.suggestion.isSequentiallyReachable(elementToCompare)) { if (!__gCrWeb.suggestion.isSequentiallyReachable(elementToCompare)) {
var indexToCompare = elements.indexOf(elementToCompare); const indexToCompare = elements.indexOf(elementToCompare);
if (indexToCompare <= 0) { // Ignore if first or no element is found. if (indexToCompare <= 0) { // Ignore if first or no element is found.
return null; return null;
} }
for (var index = indexToCompare - 1; index >= 0; --index) { for (let index = indexToCompare - 1; index >= 0; --index) {
var element = elements[index]; const element = elements[index];
if (__gCrWeb.suggestion.isSequentiallyReachable(element)) { if (__gCrWeb.suggestion.isSequentiallyReachable(element)) {
return element; return element;
} }
...@@ -134,9 +134,9 @@ __gCrWeb.suggestion.getPreviousElementInTabOrder = function( ...@@ -134,9 +134,9 @@ __gCrWeb.suggestion.getPreviousElementInTabOrder = function(
// Returns true iff |element1| that has DOM tree position |index1| is before // Returns true iff |element1| that has DOM tree position |index1| is before
// |element2| that has DOM tree position |index2| in tab order. It is assumed // |element2| that has DOM tree position |index2| in tab order. It is assumed
// |index1 !== index2|. // |index1 !== index2|.
var comparator = function(element1, index1, element2, index2) { const comparator = function(element1, index1, element2, index2) {
var tabOrder1 = __gCrWeb.suggestion.getTabOrder(element1); const tabOrder1 = __gCrWeb.suggestion.getTabOrder(element1);
var tabOrder2 = __gCrWeb.suggestion.getTabOrder(element2); const tabOrder2 = __gCrWeb.suggestion.getTabOrder(element2);
return tabOrder1 < tabOrder2 || return tabOrder1 < tabOrder2 ||
(tabOrder1 === tabOrder2 && index1 < index2); (tabOrder1 === tabOrder2 && index1 < index2);
}; };
...@@ -167,18 +167,18 @@ __gCrWeb.suggestion.getPreviousElementInTabOrder = function( ...@@ -167,18 +167,18 @@ __gCrWeb.suggestion.getPreviousElementInTabOrder = function(
__gCrWeb.suggestion.getFormElementAfter = function( __gCrWeb.suggestion.getFormElementAfter = function(
elementToCompare, elements, comparator) { elementToCompare, elements, comparator) {
// Computes the index |indexToCompare| of |elementToCompare| in |element|. // Computes the index |indexToCompare| of |elementToCompare| in |element|.
var indexToCompare = elements.indexOf(elementToCompare); const indexToCompare = elements.indexOf(elementToCompare);
if (indexToCompare === -1) { if (indexToCompare === -1) {
return null; return null;
} }
var result = null; let result = null;
var resultIndex = -1; let resultIndex = -1;
for (var index = 0; index < elements.length; ++index) { for (let index = 0; index < elements.length; ++index) {
if (index === indexToCompare) { if (index === indexToCompare) {
continue; continue;
} }
var element = elements[index]; const element = elements[index];
if (!__gCrWeb.suggestion.isSequentiallyReachable(element)) { if (!__gCrWeb.suggestion.isSequentiallyReachable(element)) {
continue; continue;
} }
...@@ -205,7 +205,7 @@ __gCrWeb.suggestion.getFormElementAfter = function( ...@@ -205,7 +205,7 @@ __gCrWeb.suggestion.getFormElementAfter = function(
* @return {boolean} Whether an element is reachable in sequential navigation. * @return {boolean} Whether an element is reachable in sequential navigation.
*/ */
__gCrWeb.suggestion.isSequentiallyReachable = function(element) { __gCrWeb.suggestion.isSequentiallyReachable = function(element) {
var tabIndex = element.tabIndex; const tabIndex = element.tabIndex;
// It is proposed in W3C that if tabIndex is omitted or parsing the value // It is proposed in W3C that if tabIndex is omitted or parsing the value
// returns an error, the user agent should follow platform conventions to // returns an error, the user agent should follow platform conventions to
// determine whether the element can be reached using sequential focus // determine whether the element can be reached using sequential focus
...@@ -267,7 +267,7 @@ __gCrWeb.suggestion.isSequentiallyReachable = function(element) { ...@@ -267,7 +267,7 @@ __gCrWeb.suggestion.isSequentiallyReachable = function(element) {
* sequential navigation. * sequential navigation.
*/ */
__gCrWeb.suggestion.getTabOrder = function(element) { __gCrWeb.suggestion.getTabOrder = function(element) {
var tabIndex = element.tabIndex; const tabIndex = element.tabIndex;
if (tabIndex === 0) { if (tabIndex === 0) {
return Number.MAX_VALUE; return Number.MAX_VALUE;
} }
...@@ -283,7 +283,7 @@ __gCrWeb.suggestion.getTabOrder = function(element) { ...@@ -283,7 +283,7 @@ __gCrWeb.suggestion.getTabOrder = function(element) {
* @return {Element} The element if found, otherwise null. * @return {Element} The element if found, otherwise null.
*/ */
__gCrWeb.suggestion.getFormElement = function(formName, fieldName) { __gCrWeb.suggestion.getFormElement = function(formName, fieldName) {
var form = __gCrWeb.form.getFormElementFromIdentifier(formName); const form = __gCrWeb.form.getFormElementFromIdentifier(formName);
if (!form) return null; if (!form) return null;
return getElementByNameWithParent(form, fieldName); return getElementByNameWithParent(form, fieldName);
}; };
...@@ -293,10 +293,10 @@ __gCrWeb.suggestion.getFormElement = function(formName, fieldName) { ...@@ -293,10 +293,10 @@ __gCrWeb.suggestion.getFormElement = function(formName, fieldName) {
* if there is no such element. * if there is no such element.
*/ */
__gCrWeb.suggestion['selectNextElement'] = function(formName, fieldName) { __gCrWeb.suggestion['selectNextElement'] = function(formName, fieldName) {
var currentElement = formName ? const currentElement = formName ?
__gCrWeb.suggestion.getFormElement(formName, fieldName) : __gCrWeb.suggestion.getFormElement(formName, fieldName) :
document.activeElement; document.activeElement;
var nextElement = __gCrWeb.suggestion.getNextElementInTabOrder( const nextElement = __gCrWeb.suggestion.getNextElementInTabOrder(
currentElement, document.all); currentElement, document.all);
if (nextElement) { if (nextElement) {
nextElement.focus(); nextElement.focus();
...@@ -308,10 +308,10 @@ __gCrWeb.suggestion['selectNextElement'] = function(formName, fieldName) { ...@@ -308,10 +308,10 @@ __gCrWeb.suggestion['selectNextElement'] = function(formName, fieldName) {
* operation if there is no such element. * operation if there is no such element.
*/ */
__gCrWeb.suggestion['selectPreviousElement'] = function(formName, fieldName) { __gCrWeb.suggestion['selectPreviousElement'] = function(formName, fieldName) {
var currentElement = formName ? const currentElement = formName ?
__gCrWeb.suggestion.getFormElement(formName, fieldName) : __gCrWeb.suggestion.getFormElement(formName, fieldName) :
document.activeElement; document.activeElement;
var prevElement = __gCrWeb.suggestion.getPreviousElementInTabOrder( const prevElement = __gCrWeb.suggestion.getPreviousElementInTabOrder(
currentElement, document.all); currentElement, document.all);
if (prevElement) { if (prevElement) {
prevElement.focus(); prevElement.focus();
...@@ -325,7 +325,7 @@ __gCrWeb.suggestion['selectPreviousElement'] = function(formName, fieldName) { ...@@ -325,7 +325,7 @@ __gCrWeb.suggestion['selectPreviousElement'] = function(formName, fieldName) {
* after the currently active element. * after the currently active element.
*/ */
__gCrWeb.suggestion['hasNextElement'] = function(formName, fieldName) { __gCrWeb.suggestion['hasNextElement'] = function(formName, fieldName) {
var currentElement = formName ? const currentElement = formName ?
__gCrWeb.suggestion.getFormElement(formName, fieldName) : __gCrWeb.suggestion.getFormElement(formName, fieldName) :
document.activeElement; document.activeElement;
return __gCrWeb.suggestion.getNextElementInTabOrder( return __gCrWeb.suggestion.getNextElementInTabOrder(
...@@ -339,7 +339,7 @@ __gCrWeb.suggestion['hasNextElement'] = function(formName, fieldName) { ...@@ -339,7 +339,7 @@ __gCrWeb.suggestion['hasNextElement'] = function(formName, fieldName) {
* before the currently active element. * before the currently active element.
*/ */
__gCrWeb.suggestion['hasPreviousElement'] = function(formName, fieldName) { __gCrWeb.suggestion['hasPreviousElement'] = function(formName, fieldName) {
var currentElement = formName ? const currentElement = formName ?
__gCrWeb.suggestion.getFormElement(formName, fieldName) : __gCrWeb.suggestion.getFormElement(formName, fieldName) :
document.activeElement; document.activeElement;
return __gCrWeb.suggestion.getPreviousElementInTabOrder( return __gCrWeb.suggestion.getPreviousElementInTabOrder(
......
...@@ -24,7 +24,7 @@ goog.require('__crWeb.form'); ...@@ -24,7 +24,7 @@ goog.require('__crWeb.form');
* option_values: Array<string> * option_values: Array<string>
* }} * }}
*/ */
var AutofillFormFieldData; let AutofillFormFieldData;
/** /**
* @typedef {{ * @typedef {{
...@@ -34,7 +34,7 @@ var AutofillFormFieldData; ...@@ -34,7 +34,7 @@ var AutofillFormFieldData;
* fields: Array<AutofillFormFieldData> * fields: Array<AutofillFormFieldData>
* }} * }}
*/ */
var AutofillFormData; let AutofillFormData;
/** /**
* Namespace for this file. It depends on |__gCrWeb| having already been * Namespace for this file. It depends on |__gCrWeb| having already been
...@@ -173,21 +173,21 @@ function setInputElementAngularValue_(value, input) { ...@@ -173,21 +173,21 @@ function setInputElementAngularValue_(value, input) {
if (!input || !window['angular']) { if (!input || !window['angular']) {
return; return;
} }
var angularElement = const angularElement =
window['angular'].element && window['angular'].element(input); window['angular'].element && window['angular'].element(input);
if (!angularElement) { if (!angularElement) {
return; return;
} }
angularElement.val(value); angularElement.val(value);
var angularModel = angularElement.data && angularElement.data('ngModel'); const angularModel = angularElement.data && angularElement.data('ngModel');
var angularScope = angularElement.scope(); const angularScope = angularElement.scope();
if (!angularModel || !angularScope) { if (!angularModel || !angularScope) {
return; return;
} }
angularElement.injector().invoke([ angularElement.injector().invoke([
'$parse', '$parse',
function(parse) { function(parse) {
var setter = parse(angularModel); const setter = parse(angularModel);
setter.assign(angularScope, value); setter.assign(angularScope, value);
} }
]); ]);
...@@ -217,7 +217,7 @@ __gCrWeb.fill.setInputElementValue = function( ...@@ -217,7 +217,7 @@ __gCrWeb.fill.setInputElementValue = function(
value, input, callback = undefined) { value, input, callback = undefined) {
if (!input) return; if (!input) return;
var activeElement = document.activeElement; const activeElement = document.activeElement;
if (input != activeElement) { if (input != activeElement) {
__gCrWeb.fill.createAndDispatchHTMLEvent( __gCrWeb.fill.createAndDispatchHTMLEvent(
activeElement, value, 'blur', true, false); activeElement, value, 'blur', true, false);
...@@ -242,7 +242,7 @@ __gCrWeb.fill.setInputElementValue = function( ...@@ -242,7 +242,7 @@ __gCrWeb.fill.setInputElementValue = function(
* @param {Element} input The input element of which the value is set. * @param {Element} input The input element of which the value is set.
*/ */
function setInputElementValue_(value, input) { function setInputElementValue_(value, input) {
var propertyName = (input.type === 'checkbox' || input.type === 'radio') ? const propertyName = (input.type === 'checkbox' || input.type === 'radio') ?
'checked' : 'checked' :
'value'; 'value';
if (input.type !== 'select-one' && input.type !== 'checkbox' && if (input.type !== 'select-one' && input.type !== 'checkbox' &&
...@@ -272,14 +272,14 @@ function setInputElementValue_(value, input) { ...@@ -272,14 +272,14 @@ function setInputElementValue_(value, input) {
// The setter simply forwards the set to the older property descriptor. // The setter simply forwards the set to the older property descriptor.
// Once the setter has been called, just forward get and set calls. // Once the setter has been called, just forward get and set calls.
var oldPropertyDescriptor = /** @type {!Object} */ ( const oldPropertyDescriptor = /** @type {!Object} */ (
Object.getOwnPropertyDescriptor(input, propertyName)); Object.getOwnPropertyDescriptor(input, propertyName));
var overrideProperty = const overrideProperty =
oldPropertyDescriptor && oldPropertyDescriptor.configurable; oldPropertyDescriptor && oldPropertyDescriptor.configurable;
var setterCalled = false; let setterCalled = false;
if (overrideProperty) { if (overrideProperty) {
var newProperty = { const newProperty = {
get: function() { get: function() {
if (setterCalled && oldPropertyDescriptor.get) { if (setterCalled && oldPropertyDescriptor.get) {
return oldPropertyDescriptor.get.call(input); return oldPropertyDescriptor.get.call(input);
...@@ -369,13 +369,13 @@ __gCrWeb.fill.sanitizeValueForInputElement = function(proposedValue, element) { ...@@ -369,13 +369,13 @@ __gCrWeb.fill.sanitizeValueForInputElement = function(proposedValue, element) {
*/ */
__gCrWeb.fill.sanitizeValueForTextFieldInputType = function( __gCrWeb.fill.sanitizeValueForTextFieldInputType = function(
proposedValue, element) { proposedValue, element) {
var textFieldElementType = element.type; const textFieldElementType = element.type;
if (textFieldElementType === 'email') { if (textFieldElementType === 'email') {
return __gCrWeb.fill.sanitizeValueForEmailInputType(proposedValue, element); return __gCrWeb.fill.sanitizeValueForEmailInputType(proposedValue, element);
} else if (textFieldElementType === 'number') { } else if (textFieldElementType === 'number') {
return __gCrWeb.fill.sanitizeValueForNumberInputType(proposedValue); return __gCrWeb.fill.sanitizeValueForNumberInputType(proposedValue);
} }
var valueWithLineBreakRemoved = proposedValue.replace(/(\r\n|\n|\r)/gm, ''); const valueWithLineBreakRemoved = proposedValue.replace(/(\r\n|\n|\r)/gm, '');
// TODO(chenyu): Should we also implement numCharactersInGraphemeClusters() // TODO(chenyu): Should we also implement numCharactersInGraphemeClusters()
// in chromium/src/third_party/WebKit/Source/core/platform/text/ // in chromium/src/third_party/WebKit/Source/core/platform/text/
// TextBreakIterator.cpp and call it here when computing newLength? // TextBreakIterator.cpp and call it here when computing newLength?
...@@ -383,10 +383,10 @@ __gCrWeb.fill.sanitizeValueForTextFieldInputType = function( ...@@ -383,10 +383,10 @@ __gCrWeb.fill.sanitizeValueForTextFieldInputType = function(
// on the text length is considered due to // on the text length is considered due to
// https://bugs.webkit.org/show_bug.cgi?id=14536, no such limit is // https://bugs.webkit.org/show_bug.cgi?id=14536, no such limit is
// considered here for now. // considered here for now.
var newLength = valueWithLineBreakRemoved.length; let newLength = valueWithLineBreakRemoved.length;
// This logic is from method String limitLength() in TextFieldInputType.h // This logic is from method String limitLength() in TextFieldInputType.h
for (var i = 0; i < newLength; ++i) { for (let i = 0; i < newLength; ++i) {
var current = valueWithLineBreakRemoved[i]; const current = valueWithLineBreakRemoved[i];
if (current < ' ' && current != '\t') { if (current < ' ' && current != '\t') {
newLength = i; newLength = i;
break; break;
...@@ -411,13 +411,13 @@ __gCrWeb.fill.sanitizeValueForTextFieldInputType = function( ...@@ -411,13 +411,13 @@ __gCrWeb.fill.sanitizeValueForTextFieldInputType = function(
*/ */
__gCrWeb.fill.sanitizeValueForEmailInputType = function( __gCrWeb.fill.sanitizeValueForEmailInputType = function(
proposedValue, element) { proposedValue, element) {
var valueWithLineBreakRemoved = proposedValue.replace(/(\r\n|\n\r)/gm, ''); const valueWithLineBreakRemoved = proposedValue.replace(/(\r\n|\n\r)/gm, '');
if (!element.multiple) { if (!element.multiple) {
return __gCrWeb.common.trim(proposedValue); return __gCrWeb.common.trim(proposedValue);
} }
var addresses = valueWithLineBreakRemoved.split(','); const addresses = valueWithLineBreakRemoved.split(',');
for (var i = 0; i < addresses.length; ++i) { for (let i = 0; i < addresses.length; ++i) {
addresses[i] = __gCrWeb.common.trim(addresses[i]); addresses[i] = __gCrWeb.common.trim(addresses[i]);
} }
return addresses.join(','); return addresses.join(',');
...@@ -440,7 +440,7 @@ __gCrWeb.fill.sanitizeValueForEmailInputType = function( ...@@ -440,7 +440,7 @@ __gCrWeb.fill.sanitizeValueForEmailInputType = function(
* @return {string} The sanitized value. * @return {string} The sanitized value.
*/ */
__gCrWeb.fill.sanitizeValueForNumberInputType = function(proposedValue) { __gCrWeb.fill.sanitizeValueForNumberInputType = function(proposedValue) {
var sanitizedValue = Number(proposedValue); const sanitizedValue = Number(proposedValue);
if (isNaN(sanitizedValue)) { if (isNaN(sanitizedValue)) {
return ''; return '';
} }
...@@ -491,7 +491,7 @@ __gCrWeb.fill.notifyElementValueChanged = function(element, value) { ...@@ -491,7 +491,7 @@ __gCrWeb.fill.notifyElementValueChanged = function(element, value) {
*/ */
__gCrWeb.fill.createAndDispatchHTMLEvent = function( __gCrWeb.fill.createAndDispatchHTMLEvent = function(
element, value, type, bubbles, cancelable) { element, value, type, bubbles, cancelable) {
var event = const event =
new Event(type, {bubbles: bubbles, cancelable: cancelable, data: value}); new Event(type, {bubbles: bubbles, cancelable: cancelable, data: value});
if (type == 'input') { if (type == 'input') {
event.inputType = 'insertText'; event.inputType = 'insertText';
...@@ -506,8 +506,8 @@ __gCrWeb.fill.createAndDispatchHTMLEvent = function( ...@@ -506,8 +506,8 @@ __gCrWeb.fill.createAndDispatchHTMLEvent = function(
* @return {string} Canonical action. * @return {string} Canonical action.
*/ */
__gCrWeb.fill.getCanonicalActionForForm = function(formElement) { __gCrWeb.fill.getCanonicalActionForForm = function(formElement) {
var rawAction = formElement.getAttribute('action') || ''; const rawAction = formElement.getAttribute('action') || '';
var absoluteUrl = const absoluteUrl =
__gCrWeb.common.absoluteURL(formElement.ownerDocument, rawAction); __gCrWeb.common.absoluteURL(formElement.ownerDocument, rawAction);
return __gCrWeb.common.removeQueryAndReferenceFromURL(absoluteUrl); return __gCrWeb.common.removeQueryAndReferenceFromURL(absoluteUrl);
}; };
...@@ -543,19 +543,19 @@ __gCrWeb.fill.getCanonicalActionForForm = function(formElement) { ...@@ -543,19 +543,19 @@ __gCrWeb.fill.getCanonicalActionForForm = function(formElement) {
*/ */
function extractFieldsFromControlElements_( function extractFieldsFromControlElements_(
controlElements, extractMask, formFields, fieldsExtracted, elementArray) { controlElements, extractMask, formFields, fieldsExtracted, elementArray) {
for (var i = 0; i < controlElements.length; ++i) { for (let i = 0; i < controlElements.length; ++i) {
fieldsExtracted[i] = false; fieldsExtracted[i] = false;
elementArray[i] = null; elementArray[i] = null;
/** @type {FormControlElement} */ /** @type {FormControlElement} */
var controlElement = controlElements[i]; const controlElement = controlElements[i];
if (!__gCrWeb.fill.isAutofillableElement(controlElement)) { if (!__gCrWeb.fill.isAutofillableElement(controlElement)) {
continue; continue;
} }
// Create a new AutofillFormFieldData, fill it out and map it to the // Create a new AutofillFormFieldData, fill it out and map it to the
// field's name. // field's name.
var formField = new __gCrWeb['common'].JSONSafeObject; const formField = new __gCrWeb['common'].JSONSafeObject;
__gCrWeb.fill.webFormControlElementToFormField( __gCrWeb.fill.webFormControlElementToFormField(
controlElement, extractMask, formField); controlElement, extractMask, formField);
formFields.push(formField); formFields.push(formField);
...@@ -582,7 +582,7 @@ function isVisibleNode_(node) { ...@@ -582,7 +582,7 @@ function isVisibleNode_(node) {
if (!node) return false; if (!node) return false;
if (node.nodeType === Node.ELEMENT_NODE) { if (node.nodeType === Node.ELEMENT_NODE) {
var style = window.getComputedStyle(/** @type {Element} */ (node)); const style = window.getComputedStyle(/** @type {Element} */ (node));
if (style.visibility == 'hidden' || style.display == 'none') return false; if (style.visibility == 'hidden' || style.display == 'none') return false;
} }
...@@ -617,21 +617,21 @@ function isVisibleNode_(node) { ...@@ -617,21 +617,21 @@ function isVisibleNode_(node) {
*/ */
function matchLabelsAndFields_( function matchLabelsAndFields_(
labels, formElement, controlElements, elementArray) { labels, formElement, controlElements, elementArray) {
for (var index = 0; index < labels.length; ++index) { for (let index = 0; index < labels.length; ++index) {
var label = labels[index]; const label = labels[index];
var fieldElement = label.control; const fieldElement = label.control;
var fieldData = null; let fieldData = null;
if (!fieldElement) { if (!fieldElement) {
// Sometimes site authors will incorrectly specify the corresponding // Sometimes site authors will incorrectly specify the corresponding
// field element's name rather than its id, so we compensate here. // field element's name rather than its id, so we compensate here.
var elementName = label.htmlFor; const elementName = label.htmlFor;
if (!elementName) continue; if (!elementName) continue;
// Look through the list for elements with this name. There can actually // Look through the list for elements with this name. There can actually
// be more than one. In this case, the label may not be particularly // be more than one. In this case, the label may not be particularly
// useful, so just discard it. // useful, so just discard it.
for (var elementIndex = 0; elementIndex < elementArray.length; for (let elementIndex = 0; elementIndex < elementArray.length;
++elementIndex) { ++elementIndex) {
var currentFieldData = elementArray[elementIndex]; const currentFieldData = elementArray[elementIndex];
if (currentFieldData && currentFieldData['name'] === elementName) { if (currentFieldData && currentFieldData['name'] === elementName) {
if (fieldData !== null) { if (fieldData !== null) {
fieldData = null; fieldData = null;
...@@ -646,7 +646,7 @@ function matchLabelsAndFields_( ...@@ -646,7 +646,7 @@ function matchLabelsAndFields_(
continue; continue;
} else { } else {
// Typical case: look up |fieldData| in |elementArray|. // Typical case: look up |fieldData| in |elementArray|.
for (var elementIndex = 0; elementIndex < elementArray.length; for (let elementIndex = 0; elementIndex < elementArray.length;
++elementIndex) { ++elementIndex) {
if (controlElements[elementIndex] === fieldElement) { if (controlElements[elementIndex] === fieldElement) {
fieldData = elementArray[elementIndex]; fieldData = elementArray[elementIndex];
...@@ -660,7 +660,7 @@ function matchLabelsAndFields_( ...@@ -660,7 +660,7 @@ function matchLabelsAndFields_(
if (!('label' in fieldData)) { if (!('label' in fieldData)) {
fieldData['label'] = ''; fieldData['label'] = '';
} }
var labelText = __gCrWeb.fill.findChildText(label); const labelText = __gCrWeb.fill.findChildText(label);
// Concatenate labels because some sites might have multiple label // Concatenate labels because some sites might have multiple label
// candidates. // candidates.
if (fieldData['label'].length > 0 && labelText.length > 0) { if (fieldData['label'].length > 0 && labelText.length > 0) {
...@@ -709,14 +709,14 @@ __gCrWeb.fill.formOrFieldsetsToFormData = function( ...@@ -709,14 +709,14 @@ __gCrWeb.fill.formOrFieldsetsToFormData = function(
form, field) { form, field) {
// This should be a map from a control element to the AutofillFormFieldData. // This should be a map from a control element to the AutofillFormFieldData.
// However, without Map support, it's just an Array of AutofillFormFieldData. // However, without Map support, it's just an Array of AutofillFormFieldData.
var elementArray = []; const elementArray = [];
// The extracted FormFields. // The extracted FormFields.
var formFields = []; const formFields = [];
// A vector of bools that indicate whether each element in |controlElements| // A vector of bools that indicate whether each element in |controlElements|
// meets the requirements and thus will be in the resulting |form|. // meets the requirements and thus will be in the resulting |form|.
var fieldsExtracted = []; const fieldsExtracted = [];
if (!extractFieldsFromControlElements_( if (!extractFieldsFromControlElements_(
controlElements, extractMask, formFields, fieldsExtracted, controlElements, extractMask, formFields, fieldsExtracted,
...@@ -730,12 +730,12 @@ __gCrWeb.fill.formOrFieldsetsToFormData = function( ...@@ -730,12 +730,12 @@ __gCrWeb.fill.formOrFieldsetsToFormData = function(
// element along with |controlElements| and |elementArray| to find the // element along with |controlElements| and |elementArray| to find the
// previously created AutofillFormFieldData and set the // previously created AutofillFormFieldData and set the
// AutofillFormFieldData's label. // AutofillFormFieldData's label.
var labels = formElement.getElementsByTagName('label'); const labels = formElement.getElementsByTagName('label');
matchLabelsAndFields_(labels, formElement, controlElements, elementArray); matchLabelsAndFields_(labels, formElement, controlElements, elementArray);
} else { } else {
// Same as the if block, but for all the labels in fieldset // Same as the if block, but for all the labels in fieldset
for (var i = 0; i < fieldsets.length; ++i) { for (let i = 0; i < fieldsets.length; ++i) {
var labels = fieldsets[i].getElementsByTagName('label'); const labels = fieldsets[i].getElementsByTagName('label');
matchLabelsAndFields_(labels, formElement, controlElements, elementArray); matchLabelsAndFields_(labels, formElement, controlElements, elementArray);
} }
} }
...@@ -744,14 +744,14 @@ __gCrWeb.fill.formOrFieldsetsToFormData = function( ...@@ -744,14 +744,14 @@ __gCrWeb.fill.formOrFieldsetsToFormData = function(
// the DOM. We use the |fieldsExtracted| vector to make sure we assign the // the DOM. We use the |fieldsExtracted| vector to make sure we assign the
// extracted label to the correct field, as it's possible |form_fields| will // extracted label to the correct field, as it's possible |form_fields| will
// not contain all of the elements in |control_elements|. // not contain all of the elements in |control_elements|.
for (var i = 0, fieldIdx = 0; for (let i = 0, fieldIdx = 0;
i < controlElements.length && fieldIdx < formFields.length; ++i) { i < controlElements.length && fieldIdx < formFields.length; ++i) {
// This field didn't meet the requirements, so don't try to find a label // This field didn't meet the requirements, so don't try to find a label
// for it. // for it.
if (!fieldsExtracted[i]) continue; if (!fieldsExtracted[i]) continue;
var controlElement = controlElements[i]; const controlElement = controlElements[i];
var currentField = formFields[fieldIdx]; const currentField = formFields[fieldIdx];
if (!currentField['label']) { if (!currentField['label']) {
currentField['label'] = currentField['label'] =
__gCrWeb.fill.inferLabelForElement(controlElement); __gCrWeb.fill.inferLabelForElement(controlElement);
...@@ -825,7 +825,7 @@ __gCrWeb.fill.webFormElementToFormData = function( ...@@ -825,7 +825,7 @@ __gCrWeb.fill.webFormElementToFormData = function(
// valid, which is computed by creating a <a> element, and we don't check if // valid, which is computed by creating a <a> element, and we don't check if
// the action is valid. // the action is valid.
var controlElements = __gCrWeb.form.getFormControlElements(formElement); const controlElements = __gCrWeb.form.getFormControlElements(formElement);
return __gCrWeb.fill.formOrFieldsetsToFormData( return __gCrWeb.fill.formOrFieldsetsToFormData(
formElement, formControlElement, [] /* fieldsets */, controlElements, formElement, formControlElement, [] /* fieldsets */, controlElements,
...@@ -914,10 +914,10 @@ __gCrWeb.fill.trimWhitespaceTrailing = function(input) { ...@@ -914,10 +914,10 @@ __gCrWeb.fill.trimWhitespaceTrailing = function(input) {
*/ */
__gCrWeb.fill.combineAndCollapseWhitespace = function( __gCrWeb.fill.combineAndCollapseWhitespace = function(
prefix, suffix, forceWhitespace) { prefix, suffix, forceWhitespace) {
var prefixTrimmed = __gCrWeb.fill.trimWhitespaceTrailing(prefix); const prefixTrimmed = __gCrWeb.fill.trimWhitespaceTrailing(prefix);
var prefixTrailingWhitespace = prefixTrimmed != prefix; const prefixTrailingWhitespace = prefixTrimmed != prefix;
var suffixTrimmed = __gCrWeb.fill.trimWhitespaceLeading(suffix); const suffixTrimmed = __gCrWeb.fill.trimWhitespaceLeading(suffix);
var suffixLeadingWhitespace = suffixTrimmed != suffix; const suffixLeadingWhitespace = suffixTrimmed != suffix;
if (prefixTrailingWhitespace || suffixLeadingWhitespace || forceWhitespace) { if (prefixTrailingWhitespace || suffixLeadingWhitespace || forceWhitespace) {
return prefixTrimmed + ' ' + suffixTrimmed; return prefixTrimmed + ' ' + suffixTrimmed;
} else { } else {
...@@ -958,7 +958,7 @@ __gCrWeb.fill.findChildTextInner = function(node, depth, divsToSkip) { ...@@ -958,7 +958,7 @@ __gCrWeb.fill.findChildTextInner = function(node, depth, divsToSkip) {
return ''; return '';
} }
if (__gCrWeb.form.isFormControlElement(/** @type {Element} */ (node))) { if (__gCrWeb.form.isFormControlElement(/** @type {Element} */ (node))) {
var input = /** @type {FormControlElement} */ (node); const input = /** @type {FormControlElement} */ (node);
if (__gCrWeb.fill.isAutofillableElement(input)) { if (__gCrWeb.fill.isAutofillableElement(input)) {
return ''; return '';
} }
...@@ -966,7 +966,7 @@ __gCrWeb.fill.findChildTextInner = function(node, depth, divsToSkip) { ...@@ -966,7 +966,7 @@ __gCrWeb.fill.findChildTextInner = function(node, depth, divsToSkip) {
} }
if (node.tagName === 'DIV') { if (node.tagName === 'DIV') {
for (var i = 0; i < divsToSkip.length; ++i) { for (let i = 0; i < divsToSkip.length; ++i) {
if (node === divsToSkip[i]) { if (node === divsToSkip[i]) {
return ''; return '';
} }
...@@ -974,7 +974,7 @@ __gCrWeb.fill.findChildTextInner = function(node, depth, divsToSkip) { ...@@ -974,7 +974,7 @@ __gCrWeb.fill.findChildTextInner = function(node, depth, divsToSkip) {
} }
// Extract the text exactly at this node. // Extract the text exactly at this node.
var nodeText = __gCrWeb.fill.nodeValue(node); let nodeText = __gCrWeb.fill.nodeValue(node);
if (node.nodeType === Node.TEXT_NODE && !nodeText) { if (node.nodeType === Node.TEXT_NODE && !nodeText) {
// In the C++ version, this text node would have been stripped completely. // In the C++ version, this text node would have been stripped completely.
// Just pass the buck. // Just pass the buck.
...@@ -984,9 +984,9 @@ __gCrWeb.fill.findChildTextInner = function(node, depth, divsToSkip) { ...@@ -984,9 +984,9 @@ __gCrWeb.fill.findChildTextInner = function(node, depth, divsToSkip) {
// Recursively compute the children's text. // Recursively compute the children's text.
// Preserve inter-element whitespace separation. // Preserve inter-element whitespace separation.
var childText = const childText =
__gCrWeb.fill.findChildTextInner(node.firstChild, depth - 1, divsToSkip); __gCrWeb.fill.findChildTextInner(node.firstChild, depth - 1, divsToSkip);
var addSpace = node.nodeType === Node.TEXT_NODE && !nodeText; let addSpace = node.nodeType === Node.TEXT_NODE && !nodeText;
// Emulate apparently incorrect Chromium behavior tracked in // Emulate apparently incorrect Chromium behavior tracked in
// https://crbug.com/239819. // https://crbug.com/239819.
addSpace = false; addSpace = false;
...@@ -995,7 +995,7 @@ __gCrWeb.fill.findChildTextInner = function(node, depth, divsToSkip) { ...@@ -995,7 +995,7 @@ __gCrWeb.fill.findChildTextInner = function(node, depth, divsToSkip) {
// Recursively compute the siblings' text. // Recursively compute the siblings' text.
// Again, preserve inter-element whitespace separation. // Again, preserve inter-element whitespace separation.
var siblingText = const siblingText =
__gCrWeb.fill.findChildTextInner(node.nextSibling, depth - 1, divsToSkip); __gCrWeb.fill.findChildTextInner(node.nextSibling, depth - 1, divsToSkip);
addSpace = node.nodeType === Node.TEXT_NODE && !nodeText; addSpace = node.nodeType === Node.TEXT_NODE && !nodeText;
// Emulate apparently incorrect Chromium behavior tracked in // Emulate apparently incorrect Chromium behavior tracked in
...@@ -1023,9 +1023,9 @@ __gCrWeb.fill.findChildTextInner = function(node, depth, divsToSkip) { ...@@ -1023,9 +1023,9 @@ __gCrWeb.fill.findChildTextInner = function(node, depth, divsToSkip) {
__gCrWeb.fill.findChildTextWithIgnoreList = function(node, divsToSkip) { __gCrWeb.fill.findChildTextWithIgnoreList = function(node, divsToSkip) {
if (node.nodeType === Node.TEXT_NODE) return __gCrWeb.fill.nodeValue(node); if (node.nodeType === Node.TEXT_NODE) return __gCrWeb.fill.nodeValue(node);
var child = node.firstChild; const child = node.firstChild;
var kChildSearchDepth = 10; const kChildSearchDepth = 10;
var nodeText = let nodeText =
__gCrWeb.fill.findChildTextInner(child, kChildSearchDepth, divsToSkip); __gCrWeb.fill.findChildTextInner(child, kChildSearchDepth, divsToSkip);
nodeText = nodeText.trim(); nodeText = nodeText.trim();
return nodeText; return nodeText;
...@@ -1062,8 +1062,8 @@ __gCrWeb.fill.findChildText = function(node) { ...@@ -1062,8 +1062,8 @@ __gCrWeb.fill.findChildText = function(node) {
* sibling or no label. * sibling or no label.
*/ */
__gCrWeb.fill.inferLabelFromSibling = function(element, forward) { __gCrWeb.fill.inferLabelFromSibling = function(element, forward) {
var inferredLabel = ''; let inferredLabel = '';
var sibling = element; let sibling = element;
if (!sibling) { if (!sibling) {
return ''; return '';
} }
...@@ -1080,7 +1080,7 @@ __gCrWeb.fill.inferLabelFromSibling = function(element, forward) { ...@@ -1080,7 +1080,7 @@ __gCrWeb.fill.inferLabelFromSibling = function(element, forward) {
} }
// Skip over comments. // Skip over comments.
var nodeType = sibling.nodeType; const nodeType = sibling.nodeType;
if (nodeType === Node.COMMENT_NODE) { if (nodeType === Node.COMMENT_NODE) {
continue; continue;
} }
...@@ -1098,9 +1098,9 @@ __gCrWeb.fill.inferLabelFromSibling = function(element, forward) { ...@@ -1098,9 +1098,9 @@ __gCrWeb.fill.inferLabelFromSibling = function(element, forward) {
__gCrWeb.fill.hasTagName(sibling, 'strong') || __gCrWeb.fill.hasTagName(sibling, 'strong') ||
__gCrWeb.fill.hasTagName(sibling, 'span') || __gCrWeb.fill.hasTagName(sibling, 'span') ||
__gCrWeb.fill.hasTagName(sibling, 'font')) { __gCrWeb.fill.hasTagName(sibling, 'font')) {
var value = __gCrWeb.fill.findChildText(sibling); const value = __gCrWeb.fill.findChildText(sibling);
// A text node's value will be empty if it is for a line break. // A text node's value will be empty if it is for a line break.
var addSpace = nodeType === Node.TEXT_NODE && value.length === 0; const addSpace = nodeType === Node.TEXT_NODE && value.length === 0;
inferredLabel = __gCrWeb.fill.combineAndCollapseWhitespace( inferredLabel = __gCrWeb.fill.combineAndCollapseWhitespace(
value, inferredLabel, addSpace); value, inferredLabel, addSpace);
continue; continue;
...@@ -1108,7 +1108,7 @@ __gCrWeb.fill.inferLabelFromSibling = function(element, forward) { ...@@ -1108,7 +1108,7 @@ __gCrWeb.fill.inferLabelFromSibling = function(element, forward) {
// If we have identified a partial label and have reached a non-lightweight // If we have identified a partial label and have reached a non-lightweight
// element, consider the label to be complete. // element, consider the label to be complete.
var trimmedLabel = inferredLabel.trim(); const trimmedLabel = inferredLabel.trim();
if (trimmedLabel.length > 0) { if (trimmedLabel.length > 0) {
break; break;
} }
...@@ -1260,7 +1260,7 @@ __gCrWeb.fill.inferLabelFromListItem = function(element) { ...@@ -1260,7 +1260,7 @@ __gCrWeb.fill.inferLabelFromListItem = function(element) {
return ''; return '';
} }
var parentNode = element.parentNode; let parentNode = element.parentNode;
while (parentNode && parentNode.nodeType === Node.ELEMENT_NODE && while (parentNode && parentNode.nodeType === Node.ELEMENT_NODE &&
!__gCrWeb.fill.hasTagName(parentNode, 'li')) { !__gCrWeb.fill.hasTagName(parentNode, 'li')) {
parentNode = parentNode.parentNode; parentNode = parentNode.parentNode;
...@@ -1293,7 +1293,7 @@ __gCrWeb.fill.inferLabelFromTableColumn = function(element) { ...@@ -1293,7 +1293,7 @@ __gCrWeb.fill.inferLabelFromTableColumn = function(element) {
return ''; return '';
} }
var parentNode = element.parentNode; let parentNode = element.parentNode;
while (parentNode && parentNode.nodeType === Node.ELEMENT_NODE && while (parentNode && parentNode.nodeType === Node.ELEMENT_NODE &&
!__gCrWeb.fill.hasTagName(parentNode, 'td')) { !__gCrWeb.fill.hasTagName(parentNode, 'td')) {
parentNode = parentNode.parentNode; parentNode = parentNode.parentNode;
...@@ -1305,8 +1305,8 @@ __gCrWeb.fill.inferLabelFromTableColumn = function(element) { ...@@ -1305,8 +1305,8 @@ __gCrWeb.fill.inferLabelFromTableColumn = function(element) {
// Check all previous siblings, skipping non-element nodes, until we find a // Check all previous siblings, skipping non-element nodes, until we find a
// non-empty text block. // non-empty text block.
var inferredLabel = ''; let inferredLabel = '';
var previous = parentNode.previousSibling; let previous = parentNode.previousSibling;
while (inferredLabel.length === 0 && previous) { while (inferredLabel.length === 0 && previous) {
if (__gCrWeb.fill.hasTagName(previous, 'td') || if (__gCrWeb.fill.hasTagName(previous, 'td') ||
__gCrWeb.fill.hasTagName(previous, 'th')) { __gCrWeb.fill.hasTagName(previous, 'th')) {
...@@ -1340,7 +1340,7 @@ __gCrWeb.fill.inferLabelFromTableRow = function(element) { ...@@ -1340,7 +1340,7 @@ __gCrWeb.fill.inferLabelFromTableRow = function(element) {
return ''; return '';
} }
var cell = element.parentNode; let cell = element.parentNode;
while (cell) { while (cell) {
if (cell.nodeType === Node.ELEMENT_NODE && if (cell.nodeType === Node.ELEMENT_NODE &&
__gCrWeb.fill.hasTagName(cell, 'td')) { __gCrWeb.fill.hasTagName(cell, 'td')) {
...@@ -1355,12 +1355,12 @@ __gCrWeb.fill.inferLabelFromTableRow = function(element) { ...@@ -1355,12 +1355,12 @@ __gCrWeb.fill.inferLabelFromTableRow = function(element) {
} }
// Count the cell holding |element|. // Count the cell holding |element|.
var cellCount = cell.colSpan; let cellCount = cell.colSpan;
var cellPosition = 0; let cellPosition = 0;
var cellPositionEnd = cellCount - 1; let cellPositionEnd = cellCount - 1;
// Count cells to the left to figure out |element|'s cell's position. // Count cells to the left to figure out |element|'s cell's position.
var cellIterator = cell.previousSibling; let cellIterator = cell.previousSibling;
while (cellIterator) { while (cellIterator) {
if (cellIterator.nodeType === Node.ELEMENT_NODE && if (cellIterator.nodeType === Node.ELEMENT_NODE &&
__gCrWeb.fill.hasTagName(cellIterator, 'td')) { __gCrWeb.fill.hasTagName(cellIterator, 'td')) {
...@@ -1384,7 +1384,7 @@ __gCrWeb.fill.inferLabelFromTableRow = function(element) { ...@@ -1384,7 +1384,7 @@ __gCrWeb.fill.inferLabelFromTableRow = function(element) {
cellPositionEnd += cellPosition; cellPositionEnd += cellPosition;
// Find the current row. // Find the current row.
var parentNode = element.parentNode; let parentNode = element.parentNode;
while (parentNode && parentNode.nodeType === Node.ELEMENT_NODE && while (parentNode && parentNode.nodeType === Node.ELEMENT_NODE &&
!__gCrWeb.fill.hasTagName(parentNode, 'tr')) { !__gCrWeb.fill.hasTagName(parentNode, 'tr')) {
parentNode = parentNode.parentNode; parentNode = parentNode.parentNode;
...@@ -1395,7 +1395,7 @@ __gCrWeb.fill.inferLabelFromTableRow = function(element) { ...@@ -1395,7 +1395,7 @@ __gCrWeb.fill.inferLabelFromTableRow = function(element) {
} }
// Now find the previous row. // Now find the previous row.
var rowIt = parentNode.previousSibling; let rowIt = parentNode.previousSibling;
while (rowIt) { while (rowIt) {
if (rowIt.nodeType === Node.ELEMENT_NODE && if (rowIt.nodeType === Node.ELEMENT_NODE &&
__gCrWeb.fill.hasTagName(parentNode, 'tr')) { __gCrWeb.fill.hasTagName(parentNode, 'tr')) {
...@@ -1407,15 +1407,15 @@ __gCrWeb.fill.inferLabelFromTableRow = function(element) { ...@@ -1407,15 +1407,15 @@ __gCrWeb.fill.inferLabelFromTableRow = function(element) {
// If there exists a previous row, check its cells and size. If they align // If there exists a previous row, check its cells and size. If they align
// with the current row, infer the label from the cell above. // with the current row, infer the label from the cell above.
if (rowIt) { if (rowIt) {
var matchingCell = null; let matchingCell = null;
var prevRowCount = 0; let prevRowCount = 0;
var prevRowIt = rowIt.firstChild; let prevRowIt = rowIt.firstChild;
while (prevRowIt) { while (prevRowIt) {
if (prevRowIt.nodeType === Node.ELEMENT_NODE) { if (prevRowIt.nodeType === Node.ELEMENT_NODE) {
if (__gCrWeb.fill.hasTagName(prevRowIt, 'td') || if (__gCrWeb.fill.hasTagName(prevRowIt, 'td') ||
__gCrWeb.fill.hasTagName(prevRowIt, 'th')) { __gCrWeb.fill.hasTagName(prevRowIt, 'th')) {
var span = prevRowIt.colSpan; const span = prevRowIt.colSpan;
var prevRowCountEnd = prevRowCount + span - 1; const prevRowCountEnd = prevRowCount + span - 1;
if (prevRowCount === cellPosition && if (prevRowCount === cellPosition &&
prevRowCountEnd === cellPositionEnd) { prevRowCountEnd === cellPositionEnd) {
matchingCell = prevRowIt; matchingCell = prevRowIt;
...@@ -1426,7 +1426,7 @@ __gCrWeb.fill.inferLabelFromTableRow = function(element) { ...@@ -1426,7 +1426,7 @@ __gCrWeb.fill.inferLabelFromTableRow = function(element) {
prevRowIt = prevRowIt.nextSibling; prevRowIt = prevRowIt.nextSibling;
} }
if (cellCount === prevRowCount && matchingCell) { if (cellCount === prevRowCount && matchingCell) {
var inferredLabel = __gCrWeb.fill.findChildText(matchingCell); const inferredLabel = __gCrWeb.fill.findChildText(matchingCell);
if (inferredLabel.length > 0) { if (inferredLabel.length > 0) {
return inferredLabel; return inferredLabel;
} }
...@@ -1436,8 +1436,8 @@ __gCrWeb.fill.inferLabelFromTableRow = function(element) { ...@@ -1436,8 +1436,8 @@ __gCrWeb.fill.inferLabelFromTableRow = function(element) {
// If there is no previous row, or if the previous row and current row do not // If there is no previous row, or if the previous row and current row do not
// align, check all previous siblings, skipping non-element nodes, until we // align, check all previous siblings, skipping non-element nodes, until we
// find a non-empty text block. // find a non-empty text block.
var inferredLabel = ''; let inferredLabel = '';
var previous = parentNode.previousSibling; let previous = parentNode.previousSibling;
while (inferredLabel.length === 0 && previous) { while (inferredLabel.length === 0 && previous) {
if (__gCrWeb.fill.hasTagName(previous, 'tr')) { if (__gCrWeb.fill.hasTagName(previous, 'tr')) {
inferredLabel = __gCrWeb.fill.findChildText(previous); inferredLabel = __gCrWeb.fill.findChildText(previous);
...@@ -1463,7 +1463,7 @@ __gCrWeb.fill.isTraversableContainerElement = function(node) { ...@@ -1463,7 +1463,7 @@ __gCrWeb.fill.isTraversableContainerElement = function(node) {
return false; return false;
} }
var tagName = /** @type {Element} */ (node).tagName; const tagName = /** @type {Element} */ (node).tagName;
return ( return (
tagName === 'DD' || tagName === 'DIV' || tagName === 'FIELDSET' || tagName === 'DD' || tagName === 'DIV' || tagName === 'FIELDSET' ||
tagName === 'LI' || tagName === 'TD' || tagName === 'TABLE'); tagName === 'LI' || tagName === 'TD' || tagName === 'TABLE');
...@@ -1486,7 +1486,7 @@ __gCrWeb.fill.inferLabelFromEnclosingLabel = function(element) { ...@@ -1486,7 +1486,7 @@ __gCrWeb.fill.inferLabelFromEnclosingLabel = function(element) {
if (!element) { if (!element) {
return ''; return '';
} }
var node = element.parentNode; let node = element.parentNode;
while (node && !__gCrWeb.fill.hasTagName(node, 'label')) { while (node && !__gCrWeb.fill.hasTagName(node, 'label')) {
node = node.parentNode; node = node.parentNode;
} }
...@@ -1517,12 +1517,12 @@ __gCrWeb.fill.inferLabelFromDivTable = function(element) { ...@@ -1517,12 +1517,12 @@ __gCrWeb.fill.inferLabelFromDivTable = function(element) {
return ''; return '';
} }
var node = element.parentNode; let node = element.parentNode;
var lookingForParent = true; let lookingForParent = true;
var divsToSkip = []; const divsToSkip = [];
// Search the sibling and parent <div>s until we find a candidate label. // Search the sibling and parent <div>s until we find a candidate label.
var inferredLabel = ''; let inferredLabel = '';
while (inferredLabel.length === 0 && node) { while (inferredLabel.length === 0 && node) {
if (__gCrWeb.fill.hasTagName(node, 'div')) { if (__gCrWeb.fill.hasTagName(node, 'div')) {
if (lookingForParent) { if (lookingForParent) {
...@@ -1533,11 +1533,11 @@ __gCrWeb.fill.inferLabelFromDivTable = function(element) { ...@@ -1533,11 +1533,11 @@ __gCrWeb.fill.inferLabelFromDivTable = function(element) {
} }
// Avoid sibling DIVs that contain autofillable fields. // Avoid sibling DIVs that contain autofillable fields.
if (!lookingForParent && inferredLabel.length > 0) { if (!lookingForParent && inferredLabel.length > 0) {
var resultElement = node.querySelector('input, select, textarea'); const resultElement = node.querySelector('input, select, textarea');
if (resultElement) { if (resultElement) {
inferredLabel = ''; inferredLabel = '';
var addDiv = true; let addDiv = true;
for (var i = 0; i < divsToSkip.length; ++i) { for (let i = 0; i < divsToSkip.length; ++i) {
if (node === divsToSkip[i]) { if (node === divsToSkip[i]) {
addDiv = false; addDiv = false;
break; break;
...@@ -1594,7 +1594,7 @@ __gCrWeb.fill.inferLabelFromDefinitionList = function(element) { ...@@ -1594,7 +1594,7 @@ __gCrWeb.fill.inferLabelFromDefinitionList = function(element) {
return ''; return '';
} }
var parentNode = element.parentNode; let parentNode = element.parentNode;
while (parentNode && parentNode.nodeType === Node.ELEMENT_NODE && while (parentNode && parentNode.nodeType === Node.ELEMENT_NODE &&
!__gCrWeb.fill.hasTagName(parentNode, 'dd')) { !__gCrWeb.fill.hasTagName(parentNode, 'dd')) {
parentNode = parentNode.parentNode; parentNode = parentNode.parentNode;
...@@ -1605,7 +1605,7 @@ __gCrWeb.fill.inferLabelFromDefinitionList = function(element) { ...@@ -1605,7 +1605,7 @@ __gCrWeb.fill.inferLabelFromDefinitionList = function(element) {
} }
// Skip by any intervening text nodes. // Skip by any intervening text nodes.
var previous = parentNode.previousSibling; let previous = parentNode.previousSibling;
while (previous && previous.nodeType === Node.TEXT_NODE) { while (previous && previous.nodeType === Node.TEXT_NODE) {
previous = previous.previousSibling; previous = previous.previousSibling;
} }
...@@ -1628,8 +1628,8 @@ __gCrWeb.fill.inferLabelFromDefinitionList = function(element) { ...@@ -1628,8 +1628,8 @@ __gCrWeb.fill.inferLabelFromDefinitionList = function(element) {
* @return {Array} The element types for all ancestors. * @return {Array} The element types for all ancestors.
*/ */
__gCrWeb.fill.ancestorTagNames = function(element) { __gCrWeb.fill.ancestorTagNames = function(element) {
var tagNames = []; const tagNames = [];
var parentNode = element.parentNode; let parentNode = element.parentNode;
while (parentNode) { while (parentNode) {
if (parentNode.nodeType === Node.ELEMENT_NODE) { if (parentNode.nodeType === Node.ELEMENT_NODE) {
tagNames.push(parentNode.tagName); tagNames.push(parentNode.tagName);
...@@ -1651,7 +1651,7 @@ __gCrWeb.fill.ancestorTagNames = function(element) { ...@@ -1651,7 +1651,7 @@ __gCrWeb.fill.ancestorTagNames = function(element) {
* @return {string} The inferred label of element, or '' if none could be found. * @return {string} The inferred label of element, or '' if none could be found.
*/ */
__gCrWeb.fill.inferLabelForElement = function(element) { __gCrWeb.fill.inferLabelForElement = function(element) {
var inferredLabel; let inferredLabel;
if (__gCrWeb.fill.isCheckableElement(element)) { if (__gCrWeb.fill.isCheckableElement(element)) {
inferredLabel = __gCrWeb.fill.inferLabelFromNext(element); inferredLabel = __gCrWeb.fill.inferLabelFromNext(element);
if (__gCrWeb.fill.IsLabelValid(inferredLabel)) { if (__gCrWeb.fill.IsLabelValid(inferredLabel)) {
...@@ -1678,10 +1678,10 @@ __gCrWeb.fill.inferLabelForElement = function(element) { ...@@ -1678,10 +1678,10 @@ __gCrWeb.fill.inferLabelForElement = function(element) {
// For all other searches that involve traversing up the tree, the search // For all other searches that involve traversing up the tree, the search
// order is based on which tag is the closest ancestor to |element|. // order is based on which tag is the closest ancestor to |element|.
var tagNames = __gCrWeb.fill.ancestorTagNames(element); const tagNames = __gCrWeb.fill.ancestorTagNames(element);
var seenTagNames = {}; const seenTagNames = {};
for (var index = 0; index < tagNames.length; ++index) { for (let index = 0; index < tagNames.length; ++index) {
var tagName = tagNames[index]; const tagName = tagNames[index];
if (tagName in seenTagNames) { if (tagName in seenTagNames) {
continue; continue;
} }
...@@ -1738,9 +1738,9 @@ __gCrWeb.fill.getOptionStringsFromElement = function(selectElement, field) { ...@@ -1738,9 +1738,9 @@ __gCrWeb.fill.getOptionStringsFromElement = function(selectElement, field) {
field['option_values'].toJSON = null; field['option_values'].toJSON = null;
field['option_contents'] = []; field['option_contents'] = [];
field['option_contents'].toJSON = null; field['option_contents'].toJSON = null;
var options = selectElement.options; const options = selectElement.options;
for (var i = 0; i < options.length; ++i) { for (let i = 0; i < options.length; ++i) {
var option = options[i]; const option = options[i];
field['option_values'].push(option['value']); field['option_values'].push(option['value']);
field['option_contents'].push(option['text']); field['option_contents'].push(option['text']);
} }
...@@ -1859,12 +1859,12 @@ __gCrWeb.fill.nodeValue = function(node) { ...@@ -1859,12 +1859,12 @@ __gCrWeb.fill.nodeValue = function(node) {
* @return {string} The value for |element|. * @return {string} The value for |element|.
*/ */
__gCrWeb.fill.value = function(element) { __gCrWeb.fill.value = function(element) {
var value = element.value; let value = element.value;
if (__gCrWeb.fill.isSelectElement(element)) { if (__gCrWeb.fill.isSelectElement(element)) {
if (element.options.length > 0 && element.selectedIndex == 0 && if (element.options.length > 0 && element.selectedIndex == 0 &&
element.options[0].disabled && element.options[0].disabled &&
!element.options[0].hasAttribute('selected')) { !element.options[0].hasAttribute('selected')) {
for (var i = 0; i < element.options.length; i++) { for (let i = 0; i < element.options.length; i++) {
if (!element.options[i].disabled || if (!element.options[i].disabled ||
element.options[i].hasAttribute('selected')) { element.options[i].hasAttribute('selected')) {
value = element.options[i].value; value = element.options[i].value;
...@@ -1911,7 +1911,7 @@ __gCrWeb.fill.webFormControlElementToFormField = function( ...@@ -1911,7 +1911,7 @@ __gCrWeb.fill.webFormControlElementToFormField = function(
field['id_attribute'] = element.getAttribute('id') || ''; field['id_attribute'] = element.getAttribute('id') || '';
field['form_control_type'] = element.type; field['form_control_type'] = element.type;
var autocompleteAttribute = element.getAttribute('autocomplete'); const autocompleteAttribute = element.getAttribute('autocomplete');
if (autocompleteAttribute) { if (autocompleteAttribute) {
field['autocomplete_attribute'] = autocompleteAttribute; field['autocomplete_attribute'] = autocompleteAttribute;
} }
...@@ -1923,7 +1923,7 @@ __gCrWeb.fill.webFormControlElementToFormField = function( ...@@ -1923,7 +1923,7 @@ __gCrWeb.fill.webFormControlElementToFormField = function(
field['autocomplete_attribute'] = 'x-max-data-length-exceeded'; field['autocomplete_attribute'] = 'x-max-data-length-exceeded';
} }
var roleAttribute = element.getAttribute('role'); const roleAttribute = element.getAttribute('role');
if (roleAttribute && roleAttribute.toLowerCase() == 'presentation') { if (roleAttribute && roleAttribute.toLowerCase() == 'presentation') {
field['role'] = __gCrWeb.fill.ROLE_ATTRIBUTE_PRESENTATION; field['role'] = __gCrWeb.fill.ROLE_ATTRIBUTE_PRESENTATION;
} }
...@@ -1963,14 +1963,14 @@ __gCrWeb.fill.webFormControlElementToFormField = function( ...@@ -1963,14 +1963,14 @@ __gCrWeb.fill.webFormControlElementToFormField = function(
return; return;
} }
var value = __gCrWeb.fill.value(element); let value = __gCrWeb.fill.value(element);
if (__gCrWeb.fill.isSelectElement(element) && if (__gCrWeb.fill.isSelectElement(element) &&
(extractMask & __gCrWeb.fill.EXTRACT_MASK_OPTION_TEXT)) { (extractMask & __gCrWeb.fill.EXTRACT_MASK_OPTION_TEXT)) {
// Convert the |select_element| value to text if requested. // Convert the |select_element| value to text if requested.
var options = element.options; const options = element.options;
for (var index = 0; index < options.length; ++index) { for (let index = 0; index < options.length; ++index) {
var optionElement = options[index]; const optionElement = options[index];
if (__gCrWeb.fill.value(optionElement) === value) { if (__gCrWeb.fill.value(optionElement) === value) {
value = optionElement.text; value = optionElement.text;
break; break;
...@@ -2000,8 +2000,8 @@ __gCrWeb.fill.webFormControlElementToFormField = function( ...@@ -2000,8 +2000,8 @@ __gCrWeb.fill.webFormControlElementToFormField = function(
* @return {string} a JSON encoded version of |form| * @return {string} a JSON encoded version of |form|
*/ */
__gCrWeb.fill.autofillSubmissionData = function(form) { __gCrWeb.fill.autofillSubmissionData = function(form) {
var formData = new __gCrWeb['common'].JSONSafeObject; const formData = new __gCrWeb['common'].JSONSafeObject;
var extractMask = const extractMask =
__gCrWeb.fill.EXTRACT_MASK_VALUE | __gCrWeb.fill.EXTRACT_MASK_OPTIONS; __gCrWeb.fill.EXTRACT_MASK_VALUE | __gCrWeb.fill.EXTRACT_MASK_OPTIONS;
__gCrWeb['fill'].webFormElementToFormData( __gCrWeb['fill'].webFormElementToFormData(
window, form, null, extractMask, formData, null); window, form, null, extractMask, formData, null);
...@@ -2033,7 +2033,7 @@ function coalesceTextByIdList(element, attribute) { ...@@ -2033,7 +2033,7 @@ function coalesceTextByIdList(element, attribute) {
return ''; return '';
} }
var ids = element.getAttribute(attribute); const ids = element.getAttribute(attribute);
if (!ids) { if (!ids) {
return ''; return '';
} }
...@@ -2062,7 +2062,7 @@ function coalesceTextByIdList(element, attribute) { ...@@ -2062,7 +2062,7 @@ function coalesceTextByIdList(element, attribute) {
* aria-labelledby text. * aria-labelledby text.
*/ */
__gCrWeb.fill.getAriaLabel = function(element) { __gCrWeb.fill.getAriaLabel = function(element) {
var label = coalesceTextByIdList(element, 'aria-labelledby'); let label = coalesceTextByIdList(element, 'aria-labelledby');
if (!label) { if (!label) {
label = element.getAttribute('aria-label') || ''; label = element.getAttribute('aria-label') || '';
} }
......
...@@ -46,7 +46,7 @@ __gCrWeb.form.wasEditedByUser = null; ...@@ -46,7 +46,7 @@ __gCrWeb.form.wasEditedByUser = null;
* @return {boolean} true if the |element| is a form control element. * @return {boolean} true if the |element| is a form control element.
*/ */
__gCrWeb.form.isFormControlElement = function(element) { __gCrWeb.form.isFormControlElement = function(element) {
var tagName = element.tagName; const tagName = element.tagName;
return ( return (
tagName === 'INPUT' || tagName === 'SELECT' || tagName === 'TEXTAREA'); tagName === 'INPUT' || tagName === 'SELECT' || tagName === 'TEXTAREA');
}; };
...@@ -68,7 +68,7 @@ __gCrWeb.form.getFormControlElements = function(form) { ...@@ -68,7 +68,7 @@ __gCrWeb.form.getFormControlElements = function(form) {
if (!form) { if (!form) {
return []; return [];
} }
var results = []; const results = [];
// Get input and select elements from form.elements. // Get input and select elements from form.elements.
// According to // According to
// http://www.w3.org/TR/2011/WD-html5-20110525/forms.html, form.elements are // http://www.w3.org/TR/2011/WD-html5-20110525/forms.html, form.elements are
...@@ -81,8 +81,8 @@ __gCrWeb.form.getFormControlElements = function(form) { ...@@ -81,8 +81,8 @@ __gCrWeb.form.getFormControlElements = function(form) {
// implementation. Note for Autofill, as input Image Button is not // implementation. Note for Autofill, as input Image Button is not
// considered as autofillable elements, there is no impact on Autofill // considered as autofillable elements, there is no impact on Autofill
// feature. // feature.
var elements = form.elements; const elements = form.elements;
for (var i = 0; i < elements.length; i++) { for (let i = 0; i < elements.length; i++) {
if (__gCrWeb.form.isFormControlElement(elements[i])) { if (__gCrWeb.form.isFormControlElement(elements[i])) {
results.push(/** @type {FormControlElement} */ (elements[i])); results.push(/** @type {FormControlElement} */ (elements[i]));
} }
...@@ -121,7 +121,7 @@ __gCrWeb.form.getFieldIdentifier = function(element) { ...@@ -121,7 +121,7 @@ __gCrWeb.form.getFieldIdentifier = function(element) {
if (!element) { if (!element) {
return ''; return '';
} }
var trimmedIdentifier = element.id; let trimmedIdentifier = element.id;
if (trimmedIdentifier) { if (trimmedIdentifier) {
return __gCrWeb.common.trim(trimmedIdentifier); return __gCrWeb.common.trim(trimmedIdentifier);
} }
...@@ -136,8 +136,8 @@ __gCrWeb.form.getFieldIdentifier = function(element) { ...@@ -136,8 +136,8 @@ __gCrWeb.form.getFieldIdentifier = function(element) {
} }
} }
var elements = __gCrWeb.form.getFormControlElements(element.form); const elements = __gCrWeb.form.getFormControlElements(element.form);
for (var index = 0; index < elements.length; index++) { for (let index = 0; index < elements.length; index++) {
if (elements[index] === element) { if (elements[index] === element) {
return __gCrWeb.form.kNamelessFieldIDPrefix + index; return __gCrWeb.form.kNamelessFieldIDPrefix + index;
} }
...@@ -147,22 +147,22 @@ __gCrWeb.form.getFieldIdentifier = function(element) { ...@@ -147,22 +147,22 @@ __gCrWeb.form.getFieldIdentifier = function(element) {
// As best effort, try to find the closest ancestor with an id, then // As best effort, try to find the closest ancestor with an id, then
// check the index of the element in the descendants of the ancestors with // check the index of the element in the descendants of the ancestors with
// the same type. // the same type.
var ancestor = element.parentNode; let ancestor = element.parentNode;
while (!!ancestor && ancestor.nodeType == Node.ELEMENT_NODE && while (!!ancestor && ancestor.nodeType == Node.ELEMENT_NODE &&
(!ancestor.hasAttribute('id') || (!ancestor.hasAttribute('id') ||
__gCrWeb.common.trim(ancestor.id) == '')) { __gCrWeb.common.trim(ancestor.id) == '')) {
ancestor = ancestor.parentNode; ancestor = ancestor.parentNode;
} }
var query = element.tagName; const query = element.tagName;
var ancestorId = ''; let ancestorId = '';
if (!ancestor || ancestor.nodeType != Node.ELEMENT_NODE) { if (!ancestor || ancestor.nodeType != Node.ELEMENT_NODE) {
ancestor = document.body; ancestor = document.body;
} }
if (ancestor.hasAttribute('id')) { if (ancestor.hasAttribute('id')) {
ancestorId = '#' + __gCrWeb.common.trim(ancestor.id); ancestorId = '#' + __gCrWeb.common.trim(ancestor.id);
} }
var descendants = ancestor.querySelectorAll(element.tagName); const descendants = ancestor.querySelectorAll(element.tagName);
var i = 0; let i = 0;
for (i = 0; i < descendants.length; i++) { for (i = 0; i < descendants.length; i++) {
if (descendants[i] === element) { if (descendants[i] === element) {
return __gCrWeb.form.kNamelessFieldIDPrefix + ancestorId + '~' + return __gCrWeb.form.kNamelessFieldIDPrefix + ancestorId + '~' +
...@@ -192,7 +192,7 @@ __gCrWeb.form.getFieldName = function(element) { ...@@ -192,7 +192,7 @@ __gCrWeb.form.getFieldName = function(element) {
if (!element) { if (!element) {
return ''; return '';
} }
var trimmedName = element.name; let trimmedName = element.name;
if (trimmedName) { if (trimmedName) {
trimmedName = __gCrWeb.common.trim(trimmedName); trimmedName = __gCrWeb.common.trim(trimmedName);
if (trimmedName.length > 0) { if (trimmedName.length > 0) {
...@@ -219,7 +219,7 @@ __gCrWeb.form.getFieldName = function(element) { ...@@ -219,7 +219,7 @@ __gCrWeb.form.getFieldName = function(element) {
*/ */
__gCrWeb.form.getFormIdentifier = function(form) { __gCrWeb.form.getFormIdentifier = function(form) {
if (!form) return ''; if (!form) return '';
var name = form.getAttribute('name'); let name = form.getAttribute('name');
if (name && name.length != 0 && if (name && name.length != 0 &&
form.ownerDocument.forms.namedItem(name) === form) { form.ownerDocument.forms.namedItem(name) === form) {
return name; return name;
...@@ -233,7 +233,7 @@ __gCrWeb.form.getFormIdentifier = function(form) { ...@@ -233,7 +233,7 @@ __gCrWeb.form.getFormIdentifier = function(form) {
// identified from the name. A last resort is to take the index number of // identified from the name. A last resort is to take the index number of
// the form in document.forms. ids are not supposed to begin with digits (by // the form in document.forms. ids are not supposed to begin with digits (by
// HTML 4 spec) so this is unlikely to match a true id. // HTML 4 spec) so this is unlikely to match a true id.
for (var idx = 0; idx != document.forms.length; idx++) { for (let idx = 0; idx != document.forms.length; idx++) {
if (document.forms[idx] == form) { if (document.forms[idx] == form) {
return __gCrWeb.form.kNamelessFormIDPrefix + idx; return __gCrWeb.form.kNamelessFormIDPrefix + idx;
} }
...@@ -252,7 +252,7 @@ __gCrWeb.form.getFormIdentifier = function(form) { ...@@ -252,7 +252,7 @@ __gCrWeb.form.getFormIdentifier = function(form) {
*/ */
__gCrWeb.form.getFormElementFromIdentifier = function(name) { __gCrWeb.form.getFormElementFromIdentifier = function(name) {
// First attempt is from the name / id supplied. // First attempt is from the name / id supplied.
var form = document.forms.namedItem(name); const form = document.forms.namedItem(name);
if (form) { if (form) {
if (form.nodeType !== Node.ELEMENT_NODE) return null; if (form.nodeType !== Node.ELEMENT_NODE) return null;
return (form); return (form);
...@@ -260,7 +260,7 @@ __gCrWeb.form.getFormElementFromIdentifier = function(name) { ...@@ -260,7 +260,7 @@ __gCrWeb.form.getFormElementFromIdentifier = function(name) {
// Second attempt is from the prefixed index position of the form in // Second attempt is from the prefixed index position of the form in
// document.forms. // document.forms.
if (name.indexOf(__gCrWeb.form.kNamelessFormIDPrefix) == 0) { if (name.indexOf(__gCrWeb.form.kNamelessFormIDPrefix) == 0) {
var nameAsInteger = const nameAsInteger =
0 | name.substring(__gCrWeb.form.kNamelessFormIDPrefix.length); 0 | name.substring(__gCrWeb.form.kNamelessFormIDPrefix.length);
if (__gCrWeb.form.kNamelessFormIDPrefix + nameAsInteger == name && if (__gCrWeb.form.kNamelessFormIDPrefix + nameAsInteger == name &&
nameAsInteger < document.forms.length) { nameAsInteger < document.forms.length) {
......
...@@ -25,29 +25,29 @@ __gCrWeb.formHandlers = {}; ...@@ -25,29 +25,29 @@ __gCrWeb.formHandlers = {};
/** /**
* The MutationObserver tracking form related changes. * The MutationObserver tracking form related changes.
*/ */
var formMutationObserver = null; let formMutationObserver = null;
/** /**
* The form mutation message scheduled to be sent to browser. * The form mutation message scheduled to be sent to browser.
*/ */
var formMutationMessageToSend = null; let formMutationMessageToSend = null;
/** /**
* A message scheduled to be sent to host on the next runloop. * A message scheduled to be sent to host on the next runloop.
*/ */
var messageToSend = null; let messageToSend = null;
/** /**
* The last HTML element that had focus. * The last HTML element that had focus.
*/ */
var lastFocusedElement = null; let lastFocusedElement = null;
/** /**
* The original implementation of HTMLFormElement.submit that will be called by * The original implementation of HTMLFormElement.submit that will be called by
* the hook. * the hook.
* @private * @private
*/ */
var formSubmitOriginalFunction = null; let formSubmitOriginalFunction = null;
/** /**
* Schedule |mesg| to be sent on next runloop. * Schedule |mesg| to be sent on next runloop.
...@@ -71,7 +71,7 @@ function sendMessageOnNextLoop_(mesg) { ...@@ -71,7 +71,7 @@ function sendMessageOnNextLoop_(mesg) {
function getFullyQualifiedUrl_(originalURL) { function getFullyQualifiedUrl_(originalURL) {
// A dummy anchor (never added to the document) is used to obtain the // A dummy anchor (never added to the document) is used to obtain the
// fully-qualified URL of |originalURL|. // fully-qualified URL of |originalURL|.
var anchor = document.createElement('a'); const anchor = document.createElement('a');
anchor.href = originalURL; anchor.href = originalURL;
return anchor.href; return anchor.href;
} }
...@@ -93,13 +93,13 @@ function getFullyQualifiedUrl_(originalURL) { ...@@ -93,13 +93,13 @@ function getFullyQualifiedUrl_(originalURL) {
* @private * @private
*/ */
function formActivity_(evt) { function formActivity_(evt) {
var target = evt.target; const target = evt.target;
if (!['FORM', 'INPUT', 'OPTION', 'SELECT', 'TEXTAREA'].includes( if (!['FORM', 'INPUT', 'OPTION', 'SELECT', 'TEXTAREA'].includes(
target.tagName)) { target.tagName)) {
return; return;
} }
var value = target.value || ''; const value = target.value || '';
var fieldType = target.type || ''; const fieldType = target.type || '';
if (evt.type !== 'blur') { if (evt.type !== 'blur') {
lastFocusedElement = document.activeElement; lastFocusedElement = document.activeElement;
} }
...@@ -108,7 +108,7 @@ function formActivity_(evt) { ...@@ -108,7 +108,7 @@ function formActivity_(evt) {
__gCrWeb.form.wasEditedByUser.set(target, evt.isTrusted); __gCrWeb.form.wasEditedByUser.set(target, evt.isTrusted);
} }
if (target != lastFocusedElement) return; if (target != lastFocusedElement) return;
var msg = { const msg = {
'command': 'form.activity', 'command': 'form.activity',
'formName': __gCrWeb.form.getFormIdentifier(evt.target.form), 'formName': __gCrWeb.form.getFormIdentifier(evt.target.form),
'fieldIdentifier': __gCrWeb.form.getFieldIdentifier(target), 'fieldIdentifier': __gCrWeb.form.getFieldIdentifier(target),
...@@ -136,7 +136,7 @@ function submitHandler_(evt) { ...@@ -136,7 +136,7 @@ function submitHandler_(evt) {
// Send the form data to the browser. // Send the form data to the browser.
function formSubmitted_(form) { function formSubmitted_(form) {
// Default action is to re-submit to same page. // Default action is to re-submit to same page.
var action = form.getAttribute('action') || document.location.href; const action = form.getAttribute('action') || document.location.href;
__gCrWeb.message.invokeOnHost({ __gCrWeb.message.invokeOnHost({
'command': 'form.submit', 'command': 'form.submit',
'formName': __gCrWeb.form.getFormIdentifier(form), 'formName': __gCrWeb.form.getFormIdentifier(form),
...@@ -219,24 +219,24 @@ __gCrWeb.formHandlers['trackFormMutations'] = function(delay) { ...@@ -219,24 +219,24 @@ __gCrWeb.formHandlers['trackFormMutations'] = function(delay) {
if (!delay) return; if (!delay) return;
formMutationObserver = new MutationObserver(function(mutations) { formMutationObserver = new MutationObserver(function(mutations) {
for (var i = 0; i < mutations.length; i++) { for (let i = 0; i < mutations.length; i++) {
var mutation = mutations[i]; const mutation = mutations[i];
// Only process mutations to the tree of nodes. // Only process mutations to the tree of nodes.
if (mutation.type != 'childList') continue; if (mutation.type != 'childList') continue;
var addedElements = []; const addedElements = [];
for (var j = 0; j < mutation.addedNodes.length; j++) { for (let j = 0; j < mutation.addedNodes.length; j++) {
var node = mutation.addedNodes[j]; const node = mutation.addedNodes[j];
// Ignore non-element nodes. // Ignore non-element nodes.
if (node.nodeType != Node.ELEMENT_NODE) continue; if (node.nodeType != Node.ELEMENT_NODE) continue;
addedElements.push(node); addedElements.push(node);
[].push.apply( [].push.apply(
addedElements, [].slice.call(node.getElementsByTagName('*'))); addedElements, [].slice.call(node.getElementsByTagName('*')));
} }
var formChanged = addedElements.find(function(element) { const formChanged = addedElements.find(function(element) {
return element.tagName.match(/(FORM|INPUT|SELECT|OPTION|TEXTAREA)/); return element.tagName.match(/(FORM|INPUT|SELECT|OPTION|TEXTAREA)/);
}); });
if (formChanged) { if (formChanged) {
var msg = { const msg = {
'command': 'form.activity', 'command': 'form.activity',
'formName': '', 'formName': '',
'fieldIdentifier': '', 'fieldIdentifier': '',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment