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; ...@@ -145,14 +145,11 @@ __gCrWeb.fill.ROLE_ATTRIBUTE_PRESENTATION = 0;
__gCrWeb.fill.RENDERER_ID_NOT_SET = '-1'; __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 * @const {symbol}
* chromium/src/components/autofill/ios/browser/autofill_util.h
*
* @const {string}
*/ */
__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. * Returns true if an element can be autocompleted.
...@@ -2310,8 +2307,7 @@ __gCrWeb.fill.extractAutofillableElementsFromSet = function(controlElements) { ...@@ -2310,8 +2307,7 @@ __gCrWeb.fill.extractAutofillableElementsFromSet = function(controlElements) {
* @param {int} nextAvailableID Next available integer. * @param {int} nextAvailableID Next available integer.
*/ */
__gCrWeb.fill['setUpForUniqueIDs'] = function(nextAvailableID) { __gCrWeb.fill['setUpForUniqueIDs'] = function(nextAvailableID) {
const uniqueID = Symbol.for(__gCrWeb.fill.UNIQUE_ID_SYMBOL_NAME); document[__gCrWeb.fill.ID_SYMBOL] = nextAvailableID;
document[uniqueID] = nextAvailableID;
}; };
/** /**
...@@ -2319,7 +2315,7 @@ __gCrWeb.fill['setUpForUniqueIDs'] = function(nextAvailableID) { ...@@ -2319,7 +2315,7 @@ __gCrWeb.fill['setUpForUniqueIDs'] = function(nextAvailableID) {
*/ */
__gCrWeb.fill.setUniqueIDIfNeeded = function(element) { __gCrWeb.fill.setUniqueIDIfNeeded = function(element) {
try { 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 // Do not assign element id value if the base value for the document
// is not set. // is not set.
if (typeof document[uniqueID] !== 'undefined' && if (typeof document[uniqueID] !== 'undefined' &&
...@@ -2336,7 +2332,7 @@ __gCrWeb.fill.setUniqueIDIfNeeded = function(element) { ...@@ -2336,7 +2332,7 @@ __gCrWeb.fill.setUniqueIDIfNeeded = function(element) {
*/ */
__gCrWeb.fill.getUniqueID = function(element) { __gCrWeb.fill.getUniqueID = function(element) {
try { 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])) { if (typeof element[uniqueID] !== 'undefined' && !isNaN(element[uniqueID])) {
return element[uniqueID].toString(); return element[uniqueID].toString();
} else { } else {
......
...@@ -280,8 +280,7 @@ __gCrWeb.form.getFormElementFromUniqueFormId = function(identifier) { ...@@ -280,8 +280,7 @@ __gCrWeb.form.getFormElementFromUniqueFormId = function(identifier) {
const forms = document.forms; const forms = document.forms;
for (let i = 0; i < forms.length; i++) { for (let i = 0; i < forms.length; i++) {
const form = forms[i]; const form = forms[i];
const uniqueID = Symbol.for(__gCrWeb.fill.UNIQUE_ID_SYMBOL_NAME); if (identifier.toString() === __gCrWeb.fill.getUniqueID(form)) {
if (identifier === form[uniqueID]) {
return form; return form;
} }
} }
......
...@@ -128,9 +128,8 @@ const onSubmitButtonTouchEnd = function(evt) { ...@@ -128,9 +128,8 @@ const onSubmitButtonTouchEnd = function(evt) {
* @return {HTMLInputElement} * @return {HTMLInputElement}
*/ */
const findInputByUniqueFieldId = function(inputs, identifier) { const findInputByUniqueFieldId = function(inputs, identifier) {
const uniqueID = Symbol.for(__gCrWeb.fill.UNIQUE_ID_SYMBOL_NAME);
for (let i = 0; i < inputs.length; ++i) { for (let i = 0; i < inputs.length; ++i) {
if (identifier === inputs[i][uniqueID]) { if (identifier.toString() === __gCrWeb.fill.getUniqueID(inputs[i])) {
return 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