OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Installs Autofill management functions on the |__gCrWeb| object. | 5 // Installs Autofill management functions on the |__gCrWeb| object. |
6 // | 6 // |
7 // It scans the DOM, extracting and storing forms and returns a JSON string | 7 // It scans the DOM, extracting and storing forms and returns a JSON string |
8 // representing an array of objects, each of which represents an Autofill form | 8 // representing an array of objects, each of which represents an Autofill form |
9 // with information about a form to be filled and/or submitted and it can be | 9 // with information about a form to be filled and/or submitted and it can be |
10 // translated to struct FormData | 10 // translated to struct FormData |
11 // (chromium/src/components/autofill/common/form_data.h) for further processing. | 11 // (chromium/src/components/autofill/core/common/form_data.h) for further |
12 // processing. | |
12 | 13 |
13 /** | 14 /** |
14 * Namespace for this file. It depends on |__gCrWeb| having already been | 15 * Namespace for this file. It depends on |__gCrWeb| having already been |
15 * injected. | 16 * injected. |
16 */ | 17 */ |
17 __gCrWeb['autofill'] = {}; | 18 __gCrWeb['autofill'] = {}; |
18 | 19 |
19 /** | 20 /** |
20 * The maximum length allowed for form data. | 21 * The maximum length allowed for form data. |
21 * | 22 * |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 * chromium/src/components/autofill/content/renderer/form_autofill_util.h | 92 * chromium/src/components/autofill/content/renderer/form_autofill_util.h |
92 */ | 93 */ |
93 __gCrWeb.autofill.EXTRACT_MASK_OPTIONS = 1 << 2; | 94 __gCrWeb.autofill.EXTRACT_MASK_OPTIONS = 1 << 2; |
94 | 95 |
95 /** | 96 /** |
96 * The last element that was autofilled. | 97 * The last element that was autofilled. |
97 */ | 98 */ |
98 __gCrWeb.autofill.lastAutoFilledElement = null; | 99 __gCrWeb.autofill.lastAutoFilledElement = null; |
99 | 100 |
100 /** | 101 /** |
102 * The last element that was active (used to restore focus if necessary). | |
103 */ | |
104 __gCrWeb.autofill.lastActiveElement = null; | |
105 | |
106 /** | |
101 * Scans DOM and returns a JSON string representation of forms and form | 107 * Scans DOM and returns a JSON string representation of forms and form |
102 * extraction results. | 108 * extraction results. |
103 * @param {int} requiredFields The minimum number of fields forms must have to | 109 * @param {int} requiredFields The minimum number of fields forms must have to |
104 * be extracted. | 110 * be extracted. |
105 * @param {int} requirements The requirements mask for forms, e.g. autocomplete | 111 * @param {int} requirements The requirements mask for forms, e.g. autocomplete |
106 * attribute state. | 112 * attribute state. |
107 * @return {string} A JSON encoded object with object['forms'] containing the | 113 * @return {string} A JSON encoded object with object['forms'] containing the |
108 * forms data and object['has_more_forms'] indicating if there are more | 114 * forms data and object['has_more_forms'] indicating if there are more |
109 * forms to extract. | 115 * forms to extract. |
110 */ | 116 */ |
111 __gCrWeb.autofill['extractForms'] = function(requiredFields, requirements) { | 117 __gCrWeb.autofill['extractForms'] = function(requiredFields, requirements) { |
112 var forms = []; | 118 var forms = []; |
113 // Protect against custom implementation of Array.toJSON in host pages. | 119 // Protect against custom implementation of Array.toJSON in host pages. |
114 forms.toJSON = null; | 120 forms.toJSON = null; |
115 // TODO(chenyu): check if any preparation is needed for information such as | 121 // TODO(chenyu): check if any preparation is needed for information such as |
116 // user_submitted or the one added in core.js is sufficient. | 122 // user_submitted or the one added in core.js is sufficient. |
117 var hasMoreForms = __gCrWeb.autofill.extractFormsAndFormElements( | 123 var hasMoreForms = __gCrWeb.autofill.extractFormsAndFormElements( |
118 window, | 124 window, |
119 requiredFields, | 125 requiredFields, |
120 requirements, | 126 requirements, |
121 forms); | 127 forms); |
122 var results = new __gCrWeb.common.JSONSafeObject; | 128 var results = new __gCrWeb.common.JSONSafeObject; |
123 results['has_more_forms'] = hasMoreForms; | 129 results['has_more_forms'] = hasMoreForms; |
124 results['forms'] = forms; | 130 results['forms'] = forms; |
125 return __gCrWeb.stringify(results); | 131 return __gCrWeb.stringify(results); |
126 }; | 132 }; |
127 | 133 |
128 /** | 134 /** |
129 * Fills data into the active form field. | 135 * Stores the current active element. This is used to make the element active |
136 * again in case the web view loses focus when a dialog is presented over it. | |
137 */ | |
138 __gCrWeb.autofill['storeActiveElement'] = function() { | |
Dan Beam
2015/05/20 23:31:52
why are you missing ['braces'] and .dot notation?
Dan Beam
2015/05/20 23:32:06
s/missing/mixing
Justin Donnelly
2015/05/21 00:36:01
I don't know, I'm pretty new to working with this
dconnelly
2015/05/21 07:27:54
Yeah, it's some Closure compiler thing. The functi
| |
139 __gCrWeb.autofill.lastActiveElement = document.activeElement; | |
140 } | |
141 | |
142 /** | |
143 * Clears the current active element by setting it to null. | |
144 */ | |
145 __gCrWeb.autofill['clearActiveElement'] = function() { | |
146 __gCrWeb.autofill.lastActiveElement = null; | |
147 } | |
148 | |
149 /** | |
150 * Fills data into the active form field. The active form field is either | |
151 * document.activeElement or the value of lastActiveElement if that value is | |
152 * non-null. | |
130 * | 153 * |
131 * @param {Object} data The data to fill in. | 154 * @param {Object} data The data to fill in. |
132 */ | 155 */ |
133 __gCrWeb.autofill['fillActiveFormField'] = function(data) { | 156 __gCrWeb.autofill['fillActiveFormField'] = function(data) { |
134 var activeElement = document.activeElement; | 157 var activeElement = document.activeElement; |
158 if (__gCrWeb.autofill.lastActiveElement) { | |
159 activeElement = __gCrWeb.autofill.lastActiveElement; | |
160 activeElement.focus(); | |
161 __gCrWeb.autofill.lastActiveElement = null; | |
162 } | |
135 if (data['name'] !== __gCrWeb['common'].nameForAutofill(activeElement)) { | 163 if (data['name'] !== __gCrWeb['common'].nameForAutofill(activeElement)) { |
136 return; | 164 return; |
137 } | 165 } |
138 __gCrWeb.autofill.lastAutoFilledElement = activeElement; | 166 __gCrWeb.autofill.lastAutoFilledElement = activeElement; |
139 __gCrWeb.autofill.fillFormField(data, activeElement); | 167 __gCrWeb.autofill.fillFormField(data, activeElement); |
140 }; | 168 }; |
141 | 169 |
142 /** | 170 /** |
143 * Fills a number of fields in the same named form. | 171 * Fills a number of fields in the same named form. |
144 * | 172 * |
(...skipping 1237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1382 continue; | 1410 continue; |
1383 } | 1411 } |
1384 var elementName = __gCrWeb['common'].nameForAutofill(element); | 1412 var elementName = __gCrWeb['common'].nameForAutofill(element); |
1385 var value = formData[elementName]; | 1413 var value = formData[elementName]; |
1386 if (value) { | 1414 if (value) { |
1387 element.placeholder = value; | 1415 element.placeholder = value; |
1388 } | 1416 } |
1389 } | 1417 } |
1390 } | 1418 } |
1391 }; | 1419 }; |
OLD | NEW |