Commit 4f31344b authored by Maria Kazinova's avatar Maria Kazinova Committed by Chromium LUCI CQ

[iOS][Passwords] Presave unique renderer id Symbol object on pageload.

This helps in cases when the page is loading scripts that interfere with
Symbols creation and unique ID setting process.

Bug: 1169690
Change-Id: Iae3a9ce3eef72e3d9b3e8021c16ad24da03d3c8c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2644957Reviewed-by: default avatarVadym Doroshenko  <dvadym@chromium.org>
Commit-Queue: Maria Kazinova <kazinova@google.com>
Cr-Commit-Position: refs/heads/master@{#846349}
parent a0c63f29
......@@ -145,14 +145,11 @@ __gCrWeb.fill.ROLE_ATTRIBUTE_PRESENTATION = 0;
__gCrWeb.fill.RENDERER_ID_NOT_SET = '-1';
/**
* The name of the JS Symbol used to set stable unique form and field IDs.
* The JS Symbol object used to set stable unique form and field IDs.
*
* This variable is |kNotSetRendererID| from
* chromium/src/components/autofill/ios/browser/autofill_util.h
*
* @const {string}
* @const {symbol}
*/
__gCrWeb.fill.UNIQUE_ID_SYMBOL_NAME = '__gChrome~uniqueID';
__gCrWeb.fill.ID_SYMBOL = window.Symbol.for('__gChrome~uniqueID');
/**
* Returns true if an element can be autocompleted.
......@@ -2310,8 +2307,7 @@ __gCrWeb.fill.extractAutofillableElementsFromSet = function(controlElements) {
* @param {int} nextAvailableID Next available integer.
*/
__gCrWeb.fill['setUpForUniqueIDs'] = function(nextAvailableID) {
const uniqueID = Symbol.for(__gCrWeb.fill.UNIQUE_ID_SYMBOL_NAME);
document[uniqueID] = nextAvailableID;
document[__gCrWeb.fill.ID_SYMBOL] = nextAvailableID;
};
/**
......@@ -2319,7 +2315,7 @@ __gCrWeb.fill['setUpForUniqueIDs'] = function(nextAvailableID) {
*/
__gCrWeb.fill.setUniqueIDIfNeeded = function(element) {
try {
const uniqueID = Symbol.for(__gCrWeb.fill.UNIQUE_ID_SYMBOL_NAME);
const uniqueID = __gCrWeb.fill.ID_SYMBOL;
// Do not assign element id value if the base value for the document
// is not set.
if (typeof document[uniqueID] !== 'undefined' &&
......@@ -2336,7 +2332,7 @@ __gCrWeb.fill.setUniqueIDIfNeeded = function(element) {
*/
__gCrWeb.fill.getUniqueID = function(element) {
try {
const uniqueID = Symbol.for(__gCrWeb.fill.UNIQUE_ID_SYMBOL_NAME);
const uniqueID = __gCrWeb.fill.ID_SYMBOL;
if (typeof element[uniqueID] !== 'undefined' && !isNaN(element[uniqueID])) {
return element[uniqueID].toString();
} else {
......
......@@ -280,8 +280,7 @@ __gCrWeb.form.getFormElementFromUniqueFormId = function(identifier) {
const forms = document.forms;
for (let i = 0; i < forms.length; i++) {
const form = forms[i];
const uniqueID = Symbol.for(__gCrWeb.fill.UNIQUE_ID_SYMBOL_NAME);
if (identifier === form[uniqueID]) {
if (identifier.toString() === __gCrWeb.fill.getUniqueID(form)) {
return form;
}
}
......
......@@ -128,9 +128,8 @@ const onSubmitButtonTouchEnd = function(evt) {
* @return {HTMLInputElement}
*/
const findInputByUniqueFieldId = function(inputs, identifier) {
const uniqueID = Symbol.for(__gCrWeb.fill.UNIQUE_ID_SYMBOL_NAME);
for (let i = 0; i < inputs.length; ++i) {
if (identifier === inputs[i][uniqueID]) {
if (identifier.toString() === __gCrWeb.fill.getUniqueID(inputs[i])) {
return inputs[i];
}
}
......
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