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/common/form_data.h) for further processing. |
12 | 12 |
13 /** | 13 /** |
14 * Namespace for this file. It depends on |__gCrWeb| having already been | 14 * Namespace for this file. It depends on |__gCrWeb| having already been |
15 * injected. | 15 * injected. |
16 */ | 16 */ |
17 __gCrWeb['autofill'] = {}; | 17 __gCrWeb['autofill'] = {}; |
18 | 18 |
19 /** | 19 /** |
20 * The maximum length allowed for form data. | 20 * The maximum length allowed for form data. |
21 * | 21 * |
22 * This variable is from | 22 * This variable is from |
23 * chromium/src/components/autofill/renderer/form_autofill_util.cc | 23 * chromium/src/components/autofill/content/renderer/form_autofill_util.cc |
24 */ | 24 */ |
25 __gCrWeb.autofill.MAX_DATA_LENGTH = 1024; | 25 __gCrWeb.autofill.MAX_DATA_LENGTH = 1024; |
26 | 26 |
27 /** | 27 /** |
28 * The maximum number of form fields we are willing to parse, due to | 28 * The maximum number of form fields we are willing to parse, due to |
29 * computational costs. Several examples of forms with lots of fields that are | 29 * computational costs. Several examples of forms with lots of fields that are |
30 * not relevant to Autofill: (1) the Netflix queue; (2) the Amazon wishlist; | 30 * not relevant to Autofill: (1) the Netflix queue; (2) the Amazon wishlist; |
31 * (3) router configuration pages; and (4) other configuration pages, e.g. for | 31 * (3) router configuration pages; and (4) other configuration pages, e.g. for |
32 * Google code project settings. | 32 * Google code project settings. |
33 * | 33 * |
34 * This variable is from | 34 * This variable is from |
35 * chromium/src/components/autofill/renderer/form_autofill_util.h | 35 * chromium/src/components/autofill/content/renderer/form_autofill_util.h |
36 */ | 36 */ |
37 __gCrWeb.autofill.MAX_PARSEABE_FIELDS = 100; | 37 __gCrWeb.autofill.MAX_PARSEABLE_FIELDS = 100; |
38 | 38 |
39 /** | 39 /** |
40 * A bit field mask for form or form element requirements for requirement | 40 * A bit field mask for form or form element requirements for requirement |
41 * none. | 41 * none. |
42 * | 42 * |
43 * This variable is from enum RequirementsMask in | 43 * This variable is from enum RequirementsMask in |
44 * chromium/src/components/autofill/renderer/form_autofill_util.h | 44 * chromium/src/components/autofill/content/renderer/form_autofill_util.h |
45 */ | 45 */ |
46 __gCrWeb.autofill.REQUIREMENTS_MASK_NONE = 0; | 46 __gCrWeb.autofill.REQUIREMENTS_MASK_NONE = 0; |
47 | 47 |
48 /** | 48 /** |
49 * A bit field mask for form or form element requirements for requirement | 49 * A bit field mask for form or form element requirements for requirement |
50 * autocomplete != off. | 50 * autocomplete != off. |
51 * | 51 * |
52 * This variable is from enum RequirementsMask in | 52 * This variable is from enum RequirementsMask in |
53 * chromium/src/components/autofill/renderer/form_autofill_util.h | 53 * chromium/src/components/autofill/content/renderer/form_autofill_util.h |
54 */ | 54 */ |
55 __gCrWeb.autofill.REQUIREMENTS_MASK_REQUIRE_AUTOCOMPLETE = 1; | 55 __gCrWeb.autofill.REQUIREMENTS_MASK_REQUIRE_AUTOCOMPLETE = 1; |
56 | 56 |
57 /** | 57 /** |
58 * A bit field mask to extract data from WebFormControlElement for | 58 * A bit field mask to extract data from WebFormControlElement for |
59 * extracting none value. | 59 * extracting none value. |
60 * | 60 * |
61 * This variable is from enum ExtractMask in | 61 * This variable is from enum ExtractMask in |
62 * chromium/src/components/autofill/renderer/form_autofill_util.h | 62 * chromium/src/components/autofill/content/renderer/form_autofill_util.h |
63 */ | 63 */ |
64 __gCrWeb.autofill.EXTRACT_MASK_NONE = 0; | 64 __gCrWeb.autofill.EXTRACT_MASK_NONE = 0; |
65 | 65 |
66 /** | 66 /** |
67 * A bit field mask to extract data from WebFormControlElement for | 67 * A bit field mask to extract data from WebFormControlElement for |
68 * extracting value from WebFormControlElement. | 68 * extracting value from WebFormControlElement. |
69 * | 69 * |
70 * This variable is from enum ExtractMask in | 70 * This variable is from enum ExtractMask in |
71 * chromium/src/components/autofill/renderer/form_autofill_util.h | 71 * chromium/src/components/autofill/content/renderer/form_autofill_util.h |
72 */ | 72 */ |
73 __gCrWeb.autofill.EXTRACT_MASK_VALUE = 1 << 0; | 73 __gCrWeb.autofill.EXTRACT_MASK_VALUE = 1 << 0; |
74 | 74 |
75 /** | 75 /** |
76 * A bit field mask to extract data from WebFormControlElement for | 76 * A bit field mask to extract data from WebFormControlElement for |
77 * extracting option text from WebFormSelectElement. Only valid when | 77 * extracting option text from WebFormSelectElement. Only valid when |
78 * EXTRACT_MASK_VALUE is set. This is used for form submission where human | 78 * EXTRACT_MASK_VALUE is set. This is used for form submission where human |
79 * readable value is captured. | 79 * readable value is captured. |
80 * | 80 * |
81 * This variable is from enum ExtractMask in | 81 * This variable is from enum ExtractMask in |
82 * chromium/src/components/autofill/renderer/form_autofill_util.h | 82 * chromium/src/components/autofill/content/renderer/form_autofill_util.h |
83 */ | 83 */ |
84 __gCrWeb.autofill.EXTRACT_MASK_OPTION_TEXT = 1 << 1; | 84 __gCrWeb.autofill.EXTRACT_MASK_OPTION_TEXT = 1 << 1; |
85 | 85 |
86 /** | 86 /** |
87 * A bit field mask to extract data from WebFormControlElement for | 87 * A bit field mask to extract data from WebFormControlElement for |
88 * extracting options from WebFormControlElement. | 88 * extracting options from WebFormControlElement. |
89 * | 89 * |
90 * This variable is from enum ExtractMask in | 90 * This variable is from enum ExtractMask in |
91 * chromium/src/components/autofill/renderer/form_autofill_util.h | 91 * chromium/src/components/autofill/content/renderer/form_autofill_util.h |
92 */ | 92 */ |
93 __gCrWeb.autofill.EXTRACT_MASK_OPTIONS = 1 << 2; | 93 __gCrWeb.autofill.EXTRACT_MASK_OPTIONS = 1 << 2; |
94 | 94 |
95 /** | 95 /** |
96 * The last element that was autofilled. | 96 * The last element that was autofilled. |
97 */ | 97 */ |
98 __gCrWeb.autofill.lastAutoFilledElement = null; | 98 __gCrWeb.autofill.lastAutoFilledElement = null; |
99 | 99 |
100 /** | 100 /** |
101 * Scans DOM and returns a JSON string representation of forms and form | 101 * Scans DOM and returns a JSON string representation of forms and form |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 * |minimumRequiredFields| limit, else false. | 204 * |minimumRequiredFields| limit, else false. |
205 * | 205 * |
206 * This method is based on the logic in method | 206 * This method is based on the logic in method |
207 * | 207 * |
208 * bool FormCache::ExtractFormsAndFormElements( | 208 * bool FormCache::ExtractFormsAndFormElements( |
209 * const WebFrame& frame, | 209 * const WebFrame& frame, |
210 * size_t minimum_required_fields, | 210 * size_t minimum_required_fields, |
211 * std::vector<FormData>* forms, | 211 * std::vector<FormData>* forms, |
212 * std::vector<WebFormElement>* web_form_elements) | 212 * std::vector<WebFormElement>* web_form_elements) |
213 * | 213 * |
214 * in chromium/src/components/autofill/renderer/form_cache.cc. | 214 * in chromium/src/components/autofill/content/renderer/form_cache.cc. |
215 * | 215 * |
216 * The difference is in this implementation, no form elements are returned in | 216 * The difference is in this implementation, no form elements are returned in |
217 * |web_form_elements|, and cache is not considered. Initial values of select | 217 * |web_form_elements|, and cache is not considered. Initial values of select |
218 * and checkable elements are not recorded at the momemt. | 218 * and checkable elements are not recorded at the momemt. |
219 * | 219 * |
220 * @param {Object} frame A window or a frame containing forms from which the | 220 * @param {Object} frame A window or a frame containing forms from which the |
221 * data will be extracted. | 221 * data will be extracted. |
222 * @param {int} minimumRequiredFields The minimum number of fields a form should | 222 * @param {int} minimumRequiredFields The minimum number of fields a form should |
223 * contain for autofill. | 223 * contain for autofill. |
224 * @param {int} requirements The requirements mask for forms, e.g. autocomplete | 224 * @param {int} requirements The requirements mask for forms, e.g. autocomplete |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 } | 264 } |
265 | 265 |
266 var extractMask = __gCrWeb.autofill.EXTRACT_MASK_VALUE | | 266 var extractMask = __gCrWeb.autofill.EXTRACT_MASK_VALUE | |
267 __gCrWeb.autofill.EXTRACT_MASK_OPTIONS; | 267 __gCrWeb.autofill.EXTRACT_MASK_OPTIONS; |
268 var form = new __gCrWeb['common'].JSONSafeObject; | 268 var form = new __gCrWeb['common'].JSONSafeObject; |
269 if (!__gCrWeb.autofill.webFormElementToFormData( | 269 if (!__gCrWeb.autofill.webFormElementToFormData( |
270 frame, formElement, null, requirements, extractMask, form)) { | 270 frame, formElement, null, requirements, extractMask, form)) { |
271 continue; | 271 continue; |
272 } | 272 } |
273 numFieldsSeen += form['fields'].length; | 273 numFieldsSeen += form['fields'].length; |
274 if (numFieldsSeen > __gCrWeb.autofill.MAX_PARSEABE_FIELDS) { | 274 if (numFieldsSeen > __gCrWeb.autofill.MAX_PARSEABLE_FIELDS) { |
275 break; | 275 break; |
276 } | 276 } |
277 | 277 |
278 if (form.fields.length >= minimumRequiredFields) { | 278 if (form.fields.length >= minimumRequiredFields) { |
279 forms.push(form); | 279 forms.push(form); |
280 } else { | 280 } else { |
281 hasSkippedForms = true; | 281 hasSkippedForms = true; |
282 } | 282 } |
283 } | 283 } |
284 | 284 |
(...skipping 17 matching lines...) Expand all Loading... |
302 * too many fields in the |form|. | 302 * too many fields in the |form|. |
303 * | 303 * |
304 * It is based on the logic in | 304 * It is based on the logic in |
305 * bool WebFormElementToFormData( | 305 * bool WebFormElementToFormData( |
306 * const blink::WebFormElement& form_element, | 306 * const blink::WebFormElement& form_element, |
307 * const blink::WebFormControlElement& form_control_element, | 307 * const blink::WebFormControlElement& form_control_element, |
308 * RequirementsMask requirements, | 308 * RequirementsMask requirements, |
309 * ExtractMask extract_mask, | 309 * ExtractMask extract_mask, |
310 * FormData* form, | 310 * FormData* form, |
311 * FormFieldData* field) | 311 * FormFieldData* field) |
312 * in chromium/src/components/autofill/renderer/form_autofill_util.cc | 312 * in chromium/src/components/autofill/content/renderer/form_autofill_util.cc |
313 * | 313 * |
314 * @param {Element} frame The frame where the formElement is in. | 314 * @param {Element} frame The frame where the formElement is in. |
315 * @param {Element} formElement The form element that will be processed. | 315 * @param {Element} formElement The form element that will be processed. |
316 * @param {Element} formControlElement A control element in formElment, the | 316 * @param {Element} formControlElement A control element in formElment, the |
317 * FormField of which will be returned in field. | 317 * FormField of which will be returned in field. |
318 * @param {int} requirements The requirement on formElement autocompletion. | 318 * @param {int} requirements The requirement on formElement autocompletion. |
319 * @param {int} extractMask Mask controls what data is extracted from | 319 * @param {int} extractMask Mask controls what data is extracted from |
320 * formElement. | 320 * formElement. |
321 * @param {Object} form Form to fill in the FormData information of formElement. | 321 * @param {Object} form Form to fill in the FormData information of formElement. |
322 * @param {Object} field Field to fill in the form field information of | 322 * @param {Object} field Field to fill in the form field information of |
(...skipping 17 matching lines...) Expand all Loading... |
340 form['name'] = __gCrWeb.common.getFormIdentifier(formElement); | 340 form['name'] = __gCrWeb.common.getFormIdentifier(formElement); |
341 var method = formElement.getAttribute('method'); | 341 var method = formElement.getAttribute('method'); |
342 if (method) { | 342 if (method) { |
343 form['method'] = method; | 343 form['method'] = method; |
344 } | 344 } |
345 form['origin'] = __gCrWeb.common.removeQueryAndReferenceFromURL( | 345 form['origin'] = __gCrWeb.common.removeQueryAndReferenceFromURL( |
346 frame.location.href); | 346 frame.location.href); |
347 form['action'] = __gCrWeb.common.absoluteURL( | 347 form['action'] = __gCrWeb.common.absoluteURL( |
348 frame.document, | 348 frame.document, |
349 formElement.getAttribute('action')); | 349 formElement.getAttribute('action')); |
350 // TODO(chenyu): fill form['userSubmitted'] (Issue 231264). | 350 // form['userSubmitted'] is filled by native code. See http://crbug.com/231264 |
351 | 351 |
352 // Note different from form_autofill_utill.cc version of this method, which | 352 // Note different from form_autofill_util.cc version of this method, which |
353 // computes |form.action| using document.completeURL(form_element.action()) | 353 // computes |form.action| using document.completeURL(form_element.action()) |
354 // and falls back to formElement.action() if the computed action is invalid, | 354 // and falls back to formElement.action() if the computed action is invalid, |
355 // here the action returned by |__gCrWeb.common.absoluteURL| is always | 355 // here the action returned by |__gCrWeb.common.absoluteURL| is always |
356 // valid, which is computed by creating a <a> element, and we don't check if | 356 // valid, which is computed by creating a <a> element, and we don't check if |
357 // the action is valid. | 357 // the action is valid. |
358 | 358 |
359 // A map from a FormFieldData's name to the FormFieldData itself. | 359 // A map from a FormFieldData's name to the FormFieldData itself. |
360 var nameMap = {}; | 360 var nameMap = {}; |
361 | 361 |
362 // The extracted FormFields. | 362 // The extracted FormFields. |
(...skipping 24 matching lines...) Expand all Loading... |
387 // Create a new FormFieldData, fill it out and map it to the field's name. | 387 // Create a new FormFieldData, fill it out and map it to the field's name. |
388 var formField = new __gCrWeb['common'].JSONSafeObject; | 388 var formField = new __gCrWeb['common'].JSONSafeObject; |
389 __gCrWeb.autofill.webFormControlElementToFormField( | 389 __gCrWeb.autofill.webFormControlElementToFormField( |
390 controlElement, extractMask, formField); | 390 controlElement, extractMask, formField); |
391 formFields.push(formField); | 391 formFields.push(formField); |
392 nameMap[formField['name']] = formField; | 392 nameMap[formField['name']] = formField; |
393 fieldsExtracted[i] = true; | 393 fieldsExtracted[i] = true; |
394 | 394 |
395 // To avoid overly expensive computation, we impose a maximum number of | 395 // To avoid overly expensive computation, we impose a maximum number of |
396 // allowable fields. | 396 // allowable fields. |
397 if (formFields.length > __gCrWeb.autofill.MAX_PARSEABE_FIELDS) { | 397 if (formFields.length > __gCrWeb.autofill.MAX_PARSEABLE_FIELDS) { |
398 return false; | 398 return false; |
399 } | 399 } |
400 } | 400 } |
401 | 401 |
402 // If we failed to extract any fields, give up. | 402 // If we failed to extract any fields, give up. |
403 if (formFields.length === 0) { | 403 if (formFields.length === 0) { |
404 return false; | 404 return false; |
405 } | 405 } |
406 | 406 |
407 // Loop through the label elements inside the form element. For each label | 407 // Loop through the label elements inside the form element. For each label |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 // Protect against custom implementation of Array.toJSON in host pages. | 469 // Protect against custom implementation of Array.toJSON in host pages. |
470 form['fields'].toJSON = null; | 470 form['fields'].toJSON = null; |
471 return true; | 471 return true; |
472 }; | 472 }; |
473 | 473 |
474 /** | 474 /** |
475 * Returns is the tag of an |element| is tag. | 475 * Returns is the tag of an |element| is tag. |
476 * | 476 * |
477 * It is based on the logic in | 477 * It is based on the logic in |
478 * bool HasTagName(const WebNode& node, const blink::WebString& tag) | 478 * bool HasTagName(const WebNode& node, const blink::WebString& tag) |
479 * in chromium/src/components/autofill/renderer/form_autofill_util.cc. | 479 * in chromium/src/components/autofill/content/renderer/form_autofill_util.cc. |
480 * | 480 * |
481 * @param {Element} node Node to examine. | 481 * @param {Element} node Node to examine. |
482 * @param {string} tag Tag name. | 482 * @param {string} tag Tag name. |
483 * @return {boolean} Whether the tag of node is tag. | 483 * @return {boolean} Whether the tag of node is tag. |
484 */ | 484 */ |
485 __gCrWeb.autofill.hasTagName = function(node, tag) { | 485 __gCrWeb.autofill.hasTagName = function(node, tag) { |
486 return node.nodeType === document.ELEMENT_NODE && | 486 return node.nodeType === document.ELEMENT_NODE && |
487 node.tagName === tag.toUpperCase(); | 487 node.tagName === tag.toUpperCase(); |
488 }; | 488 }; |
489 | 489 |
490 /** | 490 /** |
491 * Checks if an element is autofillable. | 491 * Checks if an element is autofillable. |
492 * | 492 * |
493 * It is based on the logic in | 493 * It is based on the logic in |
494 * bool IsAutofillableElement(const WebFormControlElement& element) | 494 * bool IsAutofillableElement(const WebFormControlElement& element) |
495 * in chromium/src/components/autofill/renderer/form_autofill_util.cc. | 495 * in chromium/src/components/autofill/content/renderer/form_autofill_util.cc. |
496 * | 496 * |
497 * @param {Element} element An element to examine. | 497 * @param {Element} element An element to examine. |
498 * @return {boolean} Whether element is one of the element types that can be | 498 * @return {boolean} Whether element is one of the element types that can be |
499 * autofilled. | 499 * autofilled. |
500 */ | 500 */ |
501 __gCrWeb.autofill.isAutofillableElement = function(element) { | 501 __gCrWeb.autofill.isAutofillableElement = function(element) { |
502 return __gCrWeb.autofill.isAutofillableInputElement(element) || | 502 return __gCrWeb.autofill.isAutofillableInputElement(element) || |
503 __gCrWeb.autofill.isSelectElement(element) || | 503 __gCrWeb.autofill.isSelectElement(element) || |
504 __gCrWeb.autofill.isTextAreaElement(element); | 504 __gCrWeb.autofill.isTextAreaElement(element); |
505 }; | 505 }; |
506 | 506 |
507 /** | 507 /** |
508 * Check whether the given field satisfies the | 508 * Check whether the given field satisfies the |
509 * __gCrWeb.autofill.REQUIREMENTS_MASK_REQUIRE_AUTOCOMPLETE requirement. When | 509 * __gCrWeb.autofill.REQUIREMENTS_MASK_REQUIRE_AUTOCOMPLETE requirement. When |
510 * Autocheckout is enabled, all fields are considered to satisfy this | 510 * Autocheckout is enabled, all fields are considered to satisfy this |
511 * requirement. | 511 * requirement. |
512 * | 512 * |
513 * It is based on the logic in | 513 * It is based on the logic in |
514 * bool SatisfiesRequireAutocomplete(const WebInputElement& input_element) | 514 * bool SatisfiesRequireAutocomplete(const WebInputElement& input_element) |
515 * in chromium/src/components/autofill/renderer/form_autofill_util.cc. | 515 * in chromium/src/components/autofill/content/renderer/form_autofill_util.cc. |
516 * | 516 * |
517 * @param {Element} element The element to be examined. | 517 * @param {Element} element The element to be examined. |
518 * @param {boolean} isExperimentalFormFillingEnabled Boolean from | 518 * @param {boolean} isExperimentalFormFillingEnabled Boolean from |
519 * switches::kEnableExperimentalFormFilling. | 519 * switches::kEnableExperimentalFormFilling. |
520 * @return {boolean} Whether the inputElement satisfies the requirement. | 520 * @return {boolean} Whether the inputElement satisfies the requirement. |
521 */ | 521 */ |
522 __gCrWeb.autofill.satisfiesRequireAutocomplete = function( | 522 __gCrWeb.autofill.satisfiesRequireAutocomplete = function( |
523 element, isExperimentalFormFillingEnabled) { | 523 element, isExperimentalFormFillingEnabled) { |
524 return __gCrWeb.common.autoComplete(element) || | 524 return __gCrWeb.common.autoComplete(element) || |
525 isExperimentalFormFillingEnabled; | 525 isExperimentalFormFillingEnabled; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 | 649 |
650 return nodeText; | 650 return nodeText; |
651 }; | 651 }; |
652 | 652 |
653 /** | 653 /** |
654 * Returns the aggregated values of the descendants of |element| that are | 654 * Returns the aggregated values of the descendants of |element| that are |
655 * non-empty text nodes. | 655 * non-empty text nodes. |
656 * | 656 * |
657 * It is based on the logic in | 657 * It is based on the logic in |
658 * string16 FindChildText(const WebNode& node) | 658 * string16 FindChildText(const WebNode& node) |
659 * chromium/src/components/autofill/renderer/form_autofill_util.cc, which is a | 659 * chromium/src/components/autofill/content/renderer/form_autofill_util.cc, |
660 * faster alternative to |innerText()| for performance critical operations. | 660 * which is a faster alternative to |innerText()| for performance critical |
| 661 * operations. |
661 * | 662 * |
662 * @param {Element} node A node of which the child text will be return. | 663 * @param {Element} node A node of which the child text will be return. |
663 * @return {string} The child text. | 664 * @return {string} The child text. |
664 */ | 665 */ |
665 __gCrWeb.autofill.findChildText = function(node) { | 666 __gCrWeb.autofill.findChildText = function(node) { |
666 if (node.nodeType === document.TEXT_NODE) | 667 if (node.nodeType === document.TEXT_NODE) |
667 return __gCrWeb.autofill.nodeValue(node); | 668 return __gCrWeb.autofill.nodeValue(node); |
668 var child = node.firstChild; | 669 var child = node.firstChild; |
669 | 670 |
670 var kChildSearchDepth = 10; | 671 var kChildSearchDepth = 10; |
671 var nodeText = __gCrWeb.autofill.findChildTextInner(child, kChildSearchDepth); | 672 var nodeText = __gCrWeb.autofill.findChildTextInner(child, kChildSearchDepth); |
672 nodeText = nodeText.trim(); | 673 nodeText = nodeText.trim(); |
673 return nodeText; | 674 return nodeText; |
674 }; | 675 }; |
675 | 676 |
676 /** | 677 /** |
677 * Helper for |InferLabelForElement()| that infers a label, if possible, from | 678 * Helper for |InferLabelForElement()| that infers a label, if possible, from |
678 * a previous sibling of |element|, | 679 * a previous sibling of |element|, |
679 * e.g. Some Text <input ...> | 680 * e.g. Some Text <input ...> |
680 * or Some <span>Text</span> <input ...> | 681 * or Some <span>Text</span> <input ...> |
681 * or <p>Some Text</p><input ...> | 682 * or <p>Some Text</p><input ...> |
682 * or <label>Some Text</label> <input ...> | 683 * or <label>Some Text</label> <input ...> |
683 * or Some Text <img><input ...> | 684 * or Some Text <img><input ...> |
684 * or <b>Some Text</b><br/> <input ...>. | 685 * or <b>Some Text</b><br/> <input ...>. |
685 * | 686 * |
686 * It is based on the logic in | 687 * It is based on the logic in |
687 * string16 InferLabelFromPrevious(const WebFormControlElement& element) | 688 * string16 InferLabelFromPrevious(const WebFormControlElement& element) |
688 * in chromium/src/components/autofill/renderer/form_autofill_util.cc. | 689 * in chromium/src/components/autofill/content/renderer/form_autofill_util.cc. |
689 * | 690 * |
690 * @param {Element} element An element to examine. | 691 * @param {Element} element An element to examine. |
691 * @return {string} The label of element. | 692 * @return {string} The label of element. |
692 */ | 693 */ |
693 __gCrWeb.autofill.inferLabelFromPrevious = function(element) { | 694 __gCrWeb.autofill.inferLabelFromPrevious = function(element) { |
694 var inferredLabel = ''; | 695 var inferredLabel = ''; |
695 var previous = element; | 696 var previous = element; |
696 if (!previous) { | 697 if (!previous) { |
697 return ''; | 698 return ''; |
698 } | 699 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 } | 758 } |
758 return inferredLabel.trim(); | 759 return inferredLabel.trim(); |
759 }; | 760 }; |
760 | 761 |
761 /** | 762 /** |
762 * Helper for |InferLabelForElement()| that infers a label, if possible, from | 763 * Helper for |InferLabelForElement()| that infers a label, if possible, from |
763 * the placeholder attribute. | 764 * the placeholder attribute. |
764 * | 765 * |
765 * It is based on the logic in | 766 * It is based on the logic in |
766 * string16 InferLabelFromPlaceholder(const WebFormControlElement& element) | 767 * string16 InferLabelFromPlaceholder(const WebFormControlElement& element) |
767 * in chromium/src/components/autofill/renderer/form_autofill_util.cc. | 768 * in chromium/src/components/autofill/content/renderer/form_autofill_util.cc. |
768 * | 769 * |
769 * @param {Element} element An element to examine. | 770 * @param {Element} element An element to examine. |
770 * @return {string} The label of element. | 771 * @return {string} The label of element. |
771 */ | 772 */ |
772 __gCrWeb.autofill.inferLabelFromPlaceholder = function(element) { | 773 __gCrWeb.autofill.inferLabelFromPlaceholder = function(element) { |
773 if (!element || !element.placeholder) { | 774 if (!element || !element.placeholder) { |
774 return ''; | 775 return ''; |
775 } | 776 } |
776 | 777 |
777 return element.placeholder; | 778 return element.placeholder; |
778 }; | 779 }; |
779 | 780 |
780 /** | 781 /** |
781 * Helper for |InferLabelForElement()| that infers a label, if possible, from | 782 * Helper for |InferLabelForElement()| that infers a label, if possible, from |
782 * enclosing list item, e.g. | 783 * enclosing list item, e.g. |
783 * <li>Some Text<input ...><input ...><input ...></li> | 784 * <li>Some Text<input ...><input ...><input ...></li> |
784 * | 785 * |
785 * It is based on the logic in | 786 * It is based on the logic in |
786 * string16 InferLabelFromListItem(const WebFormControlElement& element) | 787 * string16 InferLabelFromListItem(const WebFormControlElement& element) |
787 * in chromium/src/components/autofill/renderer/form_autofill_util.cc. | 788 * in chromium/src/components/autofill/content/renderer/form_autofill_util.cc. |
788 * | 789 * |
789 * @param {Element} element An element to examine. | 790 * @param {Element} element An element to examine. |
790 * @return {string} The label of element. | 791 * @return {string} The label of element. |
791 */ | 792 */ |
792 __gCrWeb.autofill.inferLabelFromListItem = function(element) { | 793 __gCrWeb.autofill.inferLabelFromListItem = function(element) { |
793 if (!element) { | 794 if (!element) { |
794 return ''; | 795 return ''; |
795 } | 796 } |
796 | 797 |
797 var parent = element.parentNode; | 798 var parentNode = element.parentNode; |
798 while (parent && | 799 while (parentNode && |
799 parent.nodeType === document.ELEMENT_NODE && | 800 parentNode.nodeType === document.ELEMENT_NODE && |
800 !__gCrWeb.autofill.hasTagName(parent, 'li')) { | 801 !__gCrWeb.autofill.hasTagName(parentNode, 'li')) { |
801 parent = parent.parentNode; | 802 parentNode = parentNode.parentNode; |
802 } | 803 } |
803 | 804 |
804 if (parent && __gCrWeb.autofill.hasTagName(parent, 'li')) | 805 if (parentNode && __gCrWeb.autofill.hasTagName(parentNode, 'li')) |
805 return __gCrWeb.autofill.findChildText(parent); | 806 return __gCrWeb.autofill.findChildText(parentNode); |
806 | 807 |
807 return ''; | 808 return ''; |
808 }; | 809 }; |
809 | 810 |
810 /** | 811 /** |
811 * Helper for |InferLabelForElement()| that infers a label, if possible, from | 812 * Helper for |InferLabelForElement()| that infers a label, if possible, from |
812 * surrounding table structure, | 813 * surrounding table structure, |
813 * e.g. <tr><td>Some Text</td><td><input ...></td></tr> | 814 * e.g. <tr><td>Some Text</td><td><input ...></td></tr> |
814 * or <tr><th>Some Text</th><td><input ...></td></tr> | 815 * or <tr><th>Some Text</th><td><input ...></td></tr> |
815 * or <tr><td><b>Some Text</b></td><td><b><input ...></b></td></tr> | 816 * or <tr><td><b>Some Text</b></td><td><b><input ...></b></td></tr> |
816 * or <tr><th><b>Some Text</b></th><td><b><input ...></b></td></tr> | 817 * or <tr><th><b>Some Text</b></th><td><b><input ...></b></td></tr> |
817 * | 818 * |
818 * It is based on the logic in | 819 * It is based on the logic in |
819 * string16 InferLabelFromTableColumn(const WebFormControlElement& element) | 820 * string16 InferLabelFromTableColumn(const WebFormControlElement& element) |
820 * in chromium/src/components/autofill/renderer/form_autofill_util.cc. | 821 * in chromium/src/components/autofill/content/renderer/form_autofill_util.cc. |
821 * | 822 * |
822 * @param {Element} element An element to examine. | 823 * @param {Element} element An element to examine. |
823 * @return {string} The label of element. | 824 * @return {string} The label of element. |
824 */ | 825 */ |
825 __gCrWeb.autofill.inferLabelFromTableColumn = function(element) { | 826 __gCrWeb.autofill.inferLabelFromTableColumn = function(element) { |
826 if (!element) { | 827 if (!element) { |
827 return ''; | 828 return ''; |
828 } | 829 } |
829 | 830 |
830 var parent = element.parentNode; | 831 var parentNode = element.parentNode; |
831 while (parent && | 832 while (parentNode && |
832 parent.nodeType === document.ELEMENT_NODE && | 833 parentNode.nodeType === document.ELEMENT_NODE && |
833 !__gCrWeb.autofill.hasTagName(parent, 'td')) { | 834 !__gCrWeb.autofill.hasTagName(parentNode, 'td')) { |
834 parent = parent.parentNode; | 835 parentNode = parentNode.parentNode; |
835 } | 836 } |
836 | 837 |
837 if (!parent) { | 838 if (!parentNode) { |
838 return ''; | 839 return ''; |
839 } | 840 } |
840 | 841 |
841 // Check all previous siblings, skipping non-element nodes, until we find a | 842 // Check all previous siblings, skipping non-element nodes, until we find a |
842 // non-empty text block. | 843 // non-empty text block. |
843 var inferredLabel = ''; | 844 var inferredLabel = ''; |
844 var previous = parent.previousSibling; | 845 var previous = parentNode.previousSibling; |
845 while (inferredLabel.length === 0 && previous) { | 846 while (inferredLabel.length === 0 && previous) { |
846 if (__gCrWeb.autofill.hasTagName(previous, 'td') || | 847 if (__gCrWeb.autofill.hasTagName(previous, 'td') || |
847 __gCrWeb.autofill.hasTagName(previous, 'th')) { | 848 __gCrWeb.autofill.hasTagName(previous, 'th')) { |
848 inferredLabel = __gCrWeb.autofill.findChildText(previous); | 849 inferredLabel = __gCrWeb.autofill.findChildText(previous); |
849 } | 850 } |
850 previous = previous.previousSibling; | 851 previous = previous.previousSibling; |
851 } | 852 } |
852 | 853 |
853 return inferredLabel; | 854 return inferredLabel; |
854 }; | 855 }; |
855 | 856 |
856 /** | 857 /** |
857 * Helper for |InferLabelForElement()| that infers a label, if possible, from | 858 * Helper for |InferLabelForElement()| that infers a label, if possible, from |
858 * surrounding table structure, | 859 * surrounding table structure, |
859 * e.g. <tr><td>Some Text</td></tr><tr><td><input ...></td></tr> | 860 * e.g. <tr><td>Some Text</td></tr><tr><td><input ...></td></tr> |
860 * | 861 * |
861 * It is based on the logic in | 862 * It is based on the logic in |
862 * string16 InferLabelFromTableRow(const WebFormControlElement& element) | 863 * string16 InferLabelFromTableRow(const WebFormControlElement& element) |
863 * in chromium/src/components/autofill/renderer/form_autofill_util.cc. | 864 * in chromium/src/components/autofill/content/renderer/form_autofill_util.cc. |
864 * | 865 * |
865 * @param {Element} element An element to examine. | 866 * @param {Element} element An element to examine. |
866 * @return {string} The label of element. | 867 * @return {string} The label of element. |
867 */ | 868 */ |
868 __gCrWeb.autofill.inferLabelFromTableRow = function(element) { | 869 __gCrWeb.autofill.inferLabelFromTableRow = function(element) { |
869 if (!element) { | 870 if (!element) { |
870 return ''; | 871 return ''; |
871 } | 872 } |
872 | 873 |
873 var parent = element.parentNode; | 874 var parentNode = element.parentNode; |
874 while (parent && | 875 while (parentNode && |
875 parent.nodeType === document.ELEMENT_NODE && | 876 parentNode.nodeType === document.ELEMENT_NODE && |
876 !__gCrWeb.autofill.hasTagName(parent, 'tr')) { | 877 !__gCrWeb.autofill.hasTagName(parentNode, 'tr')) { |
877 parent = parent.parentNode; | 878 parentNode = parentNode.parentNode; |
878 } | 879 } |
879 | 880 |
880 if (!parent) { | 881 if (!parentNode) { |
881 return ''; | 882 return ''; |
882 } | 883 } |
883 | 884 |
884 var inferredLabel = ''; | 885 var inferredLabel = ''; |
885 // Check all previous siblings, skipping non-element nodes, until we find a | 886 // Check all previous siblings, skipping non-element nodes, until we find a |
886 // non-empty text block. | 887 // non-empty text block. |
887 var previous = parent.previousSibling; | 888 var previous = parentNode.previousSibling; |
888 while (inferredLabel.length === 0 && previous) { | 889 while (inferredLabel.length === 0 && previous) { |
889 if (__gCrWeb.autofill.hasTagName(previous, 'tr')) { | 890 if (__gCrWeb.autofill.hasTagName(previous, 'tr')) { |
890 inferredLabel = __gCrWeb.autofill.findChildText(previous); | 891 inferredLabel = __gCrWeb.autofill.findChildText(previous); |
891 } | 892 } |
892 previous = previous.previousSibling; | 893 previous = previous.previousSibling; |
893 } | 894 } |
894 return inferredLabel; | 895 return inferredLabel; |
895 }; | 896 }; |
896 | 897 |
897 /** | 898 /** |
898 * Helper for |InferLabelForElement()| that infers a label, if possible, from | 899 * Helper for |InferLabelForElement()| that infers a label, if possible, from |
899 * a surrounding div table, | 900 * a surrounding div table, |
900 * e.g. <div>Some Text<span><input ...></span></div> | 901 * e.g. <div>Some Text<span><input ...></span></div> |
901 * e.g. <div>Some Text</div><div><input ...></div> | 902 * e.g. <div>Some Text</div><div><input ...></div> |
902 * | 903 * |
903 * It is based on the logic in | 904 * It is based on the logic in |
904 * string16 InferLabelFromDivTable(const WebFormControlElement& element) | 905 * string16 InferLabelFromDivTable(const WebFormControlElement& element) |
905 * in chromium/src/components/autofill/renderer/form_autofill_util.cc. | 906 * in chromium/src/components/autofill/content/renderer/form_autofill_util.cc. |
906 * | 907 * |
907 * @param {Element} element An element to examine. | 908 * @param {Element} element An element to examine. |
908 * @return {string} The label of element. | 909 * @return {string} The label of element. |
909 */ | 910 */ |
910 __gCrWeb.autofill.inferLabelFromDivTable = function(element) { | 911 __gCrWeb.autofill.inferLabelFromDivTable = function(element) { |
911 if (!element) { | 912 if (!element) { |
912 return ''; | 913 return ''; |
913 } | 914 } |
914 | 915 |
915 var node = element.parentNode; | 916 var node = element.parentNode; |
(...skipping 29 matching lines...) Expand all Loading... |
945 | 946 |
946 /** | 947 /** |
947 * Helper for |InferLabelForElement()| that infers a label, if possible, from | 948 * Helper for |InferLabelForElement()| that infers a label, if possible, from |
948 * a surrounding definition list, | 949 * a surrounding definition list, |
949 * e.g. <dl><dt>Some Text</dt><dd><input ...></dd></dl> | 950 * e.g. <dl><dt>Some Text</dt><dd><input ...></dd></dl> |
950 * e.g. <dl><dt><b>Some Text</b></dt><dd><b><input ...></b></dd></dl> | 951 * e.g. <dl><dt><b>Some Text</b></dt><dd><b><input ...></b></dd></dl> |
951 * | 952 * |
952 * It is based on the logic in | 953 * It is based on the logic in |
953 * string16 InferLabelFromDefinitionList( | 954 * string16 InferLabelFromDefinitionList( |
954 * const WebFormControlElement& element) | 955 * const WebFormControlElement& element) |
955 * in chromium/src/components/autofill/renderer/form_autofill_util.cc. | 956 * in chromium/src/components/autofill/content/renderer/form_autofill_util.cc. |
956 * | 957 * |
957 * @param {Element} element An element to examine. | 958 * @param {Element} element An element to examine. |
958 * @return {string} The label of element. | 959 * @return {string} The label of element. |
959 */ | 960 */ |
960 __gCrWeb.autofill.inferLabelFromDefinitionList = function(element) { | 961 __gCrWeb.autofill.inferLabelFromDefinitionList = function(element) { |
961 if (!element) { | 962 if (!element) { |
962 return ''; | 963 return ''; |
963 } | 964 } |
964 | 965 |
965 var parent = element.parentNode; | 966 var parentNode = element.parentNode; |
966 while (parent && | 967 while (parentNode && |
967 parent.nodeType === document.ELEMENT_NODE && | 968 parentNode.nodeType === document.ELEMENT_NODE && |
968 !__gCrWeb.autofill.hasTagName(parent, 'dd')) { | 969 !__gCrWeb.autofill.hasTagName(parentNode, 'dd')) { |
969 parent = parent.parentNode; | 970 parentNode = parentNode.parentNode; |
970 } | 971 } |
971 | 972 |
972 if (!parent || !__gCrWeb.autofill.hasTagName(parent, 'dd')) { | 973 if (!parentNode || !__gCrWeb.autofill.hasTagName(parentNode, 'dd')) { |
973 return ''; | 974 return ''; |
974 } | 975 } |
975 | 976 |
976 // Skip by any intervening text nodes. | 977 // Skip by any intervening text nodes. |
977 var previous = parent.previousSibling; | 978 var previous = parentNode.previousSibling; |
978 while (previous && | 979 while (previous && |
979 previous.nodeType === document.TEXT_NODE) { | 980 previous.nodeType === document.TEXT_NODE) { |
980 previous = previous.previousSibling; | 981 previous = previous.previousSibling; |
981 } | 982 } |
982 | 983 |
983 if (!previous || !__gCrWeb.autofill.hasTagName(previous, 'dt')) | 984 if (!previous || !__gCrWeb.autofill.hasTagName(previous, 'dt')) |
984 return ''; | 985 return ''; |
985 | 986 |
986 return __gCrWeb.autofill.findChildText(previous); | 987 return __gCrWeb.autofill.findChildText(previous); |
987 }; | 988 }; |
988 | 989 |
989 /** | 990 /** |
990 * Infers corresponding label for |element| from surrounding context in the DOM, | 991 * Infers corresponding label for |element| from surrounding context in the DOM, |
991 * e.g. the contents of the preceding <p> tag or text element. | 992 * e.g. the contents of the preceding <p> tag or text element. |
992 * | 993 * |
993 * It is based on the logic in | 994 * It is based on the logic in |
994 * string16 InferLabelForElement(const WebFormControlElement& element) | 995 * string16 InferLabelForElement(const WebFormControlElement& element) |
995 * in chromium/src/components/autofill/renderer/form_autofill_util.cc. | 996 * in chromium/src/components/autofill/content/renderer/form_autofill_util.cc. |
996 * | 997 * |
997 * @param {Element} element An element to examine. | 998 * @param {Element} element An element to examine. |
998 * @return {string} The label of element. | 999 * @return {string} The label of element. |
999 */ | 1000 */ |
1000 __gCrWeb.autofill.inferLabelForElement = function(element) { | 1001 __gCrWeb.autofill.inferLabelForElement = function(element) { |
1001 var inferredLabel = __gCrWeb.autofill.inferLabelFromPrevious(element); | 1002 var inferredLabel = __gCrWeb.autofill.inferLabelFromPrevious(element); |
1002 if (inferredLabel.length > 0) { | 1003 if (inferredLabel.length > 0) { |
1003 return inferredLabel; | 1004 return inferredLabel; |
1004 } | 1005 } |
1005 | 1006 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1038 }; | 1039 }; |
1039 | 1040 |
1040 /** | 1041 /** |
1041 * Fills |field| data with the values of the <option> elements present in | 1042 * Fills |field| data with the values of the <option> elements present in |
1042 * |selectElement|. | 1043 * |selectElement|. |
1043 * | 1044 * |
1044 * It is based on the logic in | 1045 * It is based on the logic in |
1045 * void GetOptionStringsFromElement(const WebSelectElement& select_element, | 1046 * void GetOptionStringsFromElement(const WebSelectElement& select_element, |
1046 * std::vector<string16>* option_values, | 1047 * std::vector<string16>* option_values, |
1047 * std::vector<string16>* option_contents) | 1048 * std::vector<string16>* option_contents) |
1048 * in chromium/src/components/autofill/renderer/form_autofill_util.cc. | 1049 * in chromium/src/components/autofill/content/renderer/form_autofill_util.cc. |
1049 * | 1050 * |
1050 * @param {Element} selectElement A select element from which option data are | 1051 * @param {Element} selectElement A select element from which option data are |
1051 * extracted. | 1052 * extracted. |
1052 * @param {Object} field A field that will contain the extracted option | 1053 * @param {Object} field A field that will contain the extracted option |
1053 * information. | 1054 * information. |
1054 */ | 1055 */ |
1055 __gCrWeb.autofill.getOptionStringsFromElement = function( | 1056 __gCrWeb.autofill.getOptionStringsFromElement = function( |
1056 selectElement, field) { | 1057 selectElement, field) { |
1057 field['option_values'] = []; | 1058 field['option_values'] = []; |
1058 // Protect against custom implementation of Array.toJSON in host pages. | 1059 // Protect against custom implementation of Array.toJSON in host pages. |
1059 field['option_values'].toJSON = null; | 1060 field['option_values'].toJSON = null; |
1060 field['option_contents'] = []; | 1061 field['option_contents'] = []; |
1061 field['option_contents'].toJSON = null; | 1062 field['option_contents'].toJSON = null; |
1062 var options = selectElement.options; | 1063 var options = selectElement.options; |
1063 for (var i = 0; i < options.length; ++i) { | 1064 for (var i = 0; i < options.length; ++i) { |
1064 var option = options[i]; | 1065 var option = options[i]; |
1065 field['option_values'].push(option['value']); | 1066 field['option_values'].push(option['value']); |
1066 field['option_contents'].push(option['text']); | 1067 field['option_contents'].push(option['text']); |
1067 } | 1068 } |
1068 }; | 1069 }; |
1069 | 1070 |
1070 /** | 1071 /** |
1071 * Sets the |field|'s value to the value in |data|. | 1072 * Sets the |field|'s value to the value in |data|. |
1072 * Also sets the "autofilled" attribute. | 1073 * Also sets the "autofilled" attribute. |
1073 * | 1074 * |
1074 * It is based on the logic in | 1075 * It is based on the logic in |
1075 * void FillFormField(const FormFieldData& data, | 1076 * void FillFormField(const FormFieldData& data, |
1076 * bool is_initiating_node, | 1077 * bool is_initiating_node, |
1077 * blink::WebFormControlElement* field) | 1078 * blink::WebFormControlElement* field) |
1078 * in chromium/src/components/autofill/renderer/form_autofill_util.cc. | 1079 * in chromium/src/components/autofill/content/renderer/form_autofill_util.cc. |
1079 * | 1080 * |
1080 * Different from FillFormField(), is_initiating_node is not considered in | 1081 * Different from FillFormField(), is_initiating_node is not considered in |
1081 * this implementation. | 1082 * this implementation. |
1082 * | 1083 * |
1083 * @param {Object} data Data that will be filled into field. | 1084 * @param {Object} data Data that will be filled into field. |
1084 * @param {Element} field The element to which data will be filled. | 1085 * @param {Element} field The element to which data will be filled. |
1085 */ | 1086 */ |
1086 __gCrWeb.autofill.fillFormField = function(data, field) { | 1087 __gCrWeb.autofill.fillFormField = function(data, field) { |
1087 // Nothing to fill. | 1088 // Nothing to fill. |
1088 if (!data['value'] || data['value'].length === 0) { | 1089 if (!data['value'] || data['value'].length === 0) { |
(...skipping 26 matching lines...) Expand all Loading... |
1115 __gCrWeb.common.setInputElementChecked(data['is_checked'], field, true); | 1116 __gCrWeb.common.setInputElementChecked(data['is_checked'], field, true); |
1116 } | 1117 } |
1117 } | 1118 } |
1118 }; | 1119 }; |
1119 | 1120 |
1120 /** | 1121 /** |
1121 * Returns true if |element| is a text input element. | 1122 * Returns true if |element| is a text input element. |
1122 * | 1123 * |
1123 * It is based on the logic in | 1124 * It is based on the logic in |
1124 * bool IsTextInput(const blink::WebInputElement* element) | 1125 * bool IsTextInput(const blink::WebInputElement* element) |
1125 * in chromium/src/components/autofill/renderer/form_autofill_util.h. | 1126 * in chromium/src/components/autofill/content/renderer/form_autofill_util.h. |
1126 * | 1127 * |
1127 * @param {Element} element An element to examine. | 1128 * @param {Element} element An element to examine. |
1128 * @return {boolean} Whether element is a text input field. | 1129 * @return {boolean} Whether element is a text input field. |
1129 */ | 1130 */ |
1130 __gCrWeb.autofill.isTextInput = function(element) { | 1131 __gCrWeb.autofill.isTextInput = function(element) { |
1131 if (!element) { | 1132 if (!element) { |
1132 return false; | 1133 return false; |
1133 } | 1134 } |
1134 return __gCrWeb.common.isTextField(element); | 1135 return __gCrWeb.common.isTextField(element); |
1135 }; | 1136 }; |
1136 | 1137 |
1137 /** | 1138 /** |
1138 * Returns true if |element| is a 'select' element. | 1139 * Returns true if |element| is a 'select' element. |
1139 * | 1140 * |
1140 * It is based on the logic in | 1141 * It is based on the logic in |
1141 * bool IsSelectElement(const blink::WebFormControlElement& element) | 1142 * bool IsSelectElement(const blink::WebFormControlElement& element) |
1142 * in chromium/src/components/autofill/renderer/form_autofill_util.h. | 1143 * in chromium/src/components/autofill/content/renderer/form_autofill_util.h. |
1143 * | 1144 * |
1144 * @param {Element} element An element to examine. | 1145 * @param {Element} element An element to examine. |
1145 * @return {boolean} Whether element is a 'select' element. | 1146 * @return {boolean} Whether element is a 'select' element. |
1146 */ | 1147 */ |
1147 __gCrWeb.autofill.isSelectElement = function(element) { | 1148 __gCrWeb.autofill.isSelectElement = function(element) { |
1148 if (!element) { | 1149 if (!element) { |
1149 return false; | 1150 return false; |
1150 } | 1151 } |
1151 return element.type === 'select-one'; | 1152 return element.type === 'select-one'; |
1152 }; | 1153 }; |
1153 | 1154 |
1154 /** | 1155 /** |
1155 * Returns true if |element| is a 'textarea' element. | 1156 * Returns true if |element| is a 'textarea' element. |
1156 * | 1157 * |
1157 * It is based on the logic in | 1158 * It is based on the logic in |
1158 * bool IsTextAreaElement(const blink::WebFormControlElement& element) | 1159 * bool IsTextAreaElement(const blink::WebFormControlElement& element) |
1159 * in chromium/src/components/autofill/renderer/form_autofill_util.h. | 1160 * in chromium/src/components/autofill/content/renderer/form_autofill_util.h. |
1160 * | 1161 * |
1161 * @param {Element} element An element to examine. | 1162 * @param {Element} element An element to examine. |
1162 * @return {boolean} Whether element is a 'textarea' element. | 1163 * @return {boolean} Whether element is a 'textarea' element. |
1163 */ | 1164 */ |
1164 __gCrWeb.autofill.isTextAreaElement = function(element) { | 1165 __gCrWeb.autofill.isTextAreaElement = function(element) { |
1165 if (!element) { | 1166 if (!element) { |
1166 return false; | 1167 return false; |
1167 } | 1168 } |
1168 return element.type === 'textarea'; | 1169 return element.type === 'textarea'; |
1169 }; | 1170 }; |
1170 | 1171 |
1171 /** | 1172 /** |
1172 * Returns true if |element| is a checkbox or a radio button element. | 1173 * Returns true if |element| is a checkbox or a radio button element. |
1173 * | 1174 * |
1174 * It is based on the logic in | 1175 * It is based on the logic in |
1175 * bool IsCheckableElement(const blink::WebInputElement* element) | 1176 * bool IsCheckableElement(const blink::WebInputElement* element) |
1176 * in chromium/src/components/autofill/renderer/form_autofill_util.h. | 1177 * in chromium/src/components/autofill/content/renderer/form_autofill_util.h. |
1177 * | 1178 * |
1178 * @param {Element} element An element to examine. | 1179 * @param {Element} element An element to examine. |
1179 * @return {boolean} Whether element is a checkbox or a radio button. | 1180 * @return {boolean} Whether element is a checkbox or a radio button. |
1180 */ | 1181 */ |
1181 __gCrWeb.autofill.isCheckableElement = function(element) { | 1182 __gCrWeb.autofill.isCheckableElement = function(element) { |
1182 if (!element) { | 1183 if (!element) { |
1183 return false; | 1184 return false; |
1184 } | 1185 } |
1185 return element.type === 'checkbox' || element.type === 'radio'; | 1186 return element.type === 'checkbox' || element.type === 'radio'; |
1186 }; | 1187 }; |
1187 | 1188 |
1188 /** | 1189 /** |
1189 * Returns true if |element| is one of the input element types that can be | 1190 * Returns true if |element| is one of the input element types that can be |
1190 * autofilled. {Text, Radiobutton, Checkbox}. | 1191 * autofilled. {Text, Radiobutton, Checkbox}. |
1191 * | 1192 * |
1192 * It is based on the logic in | 1193 * It is based on the logic in |
1193 * bool IsAutofillableInputElement(const blink::WebInputElement* element) | 1194 * bool IsAutofillableInputElement(const blink::WebInputElement* element) |
1194 * in chromium/src/components/autofill/renderer/form_autofill_util.h. | 1195 * in chromium/src/components/autofill/content/renderer/form_autofill_util.h. |
1195 * | 1196 * |
1196 * @param {Element} element An element to examine. | 1197 * @param {Element} element An element to examine. |
1197 * @return {boolean} Whether element is one of the input element types that | 1198 * @return {boolean} Whether element is one of the input element types that |
1198 * can be autofilled. | 1199 * can be autofilled. |
1199 */ | 1200 */ |
1200 __gCrWeb.autofill.isAutofillableInputElement = function(element) { | 1201 __gCrWeb.autofill.isAutofillableInputElement = function(element) { |
1201 return __gCrWeb.autofill.isTextInput(element) || | 1202 return __gCrWeb.autofill.isTextInput(element) || |
1202 __gCrWeb.autofill.isCheckableElement(element); | 1203 __gCrWeb.autofill.isCheckableElement(element); |
1203 }; | 1204 }; |
1204 | 1205 |
1205 /** | 1206 /** |
1206 * Returns the nodeValue in a way similar to the C++ version of node.nodeValue, | 1207 * Returns the nodeValue in a way similar to the C++ version of node.nodeValue, |
1207 * used in src/components/autofill/renderer/form_autofill_util.h. Newlines and | 1208 * used in src/components/autofill/content/renderer/form_autofill_util.h. |
1208 * tabs are stripped. | 1209 * Newlines and tabs are stripped. |
1209 * | 1210 * |
1210 * @param {Element} element An element to examine. | 1211 * @param {Element} element An element to examine. |
1211 * @return {string} The text contained in |element|. | 1212 * @return {string} The text contained in |element|. |
1212 */ | 1213 */ |
1213 __gCrWeb.autofill.nodeValue = function(element) { | 1214 __gCrWeb.autofill.nodeValue = function(element) { |
1214 return (element.nodeValue || '').replace(/[\n\t]/gm, ''); | 1215 return (element.nodeValue || '').replace(/[\n\t]/gm, ''); |
1215 }; | 1216 }; |
1216 | 1217 |
1217 /** | 1218 /** |
1218 * Returns the value in a way similar to the C++ version of node.value, | 1219 * Returns the value in a way similar to the C++ version of node.value, |
1219 * used in src/components/autofill/renderer/form_autofill_util.h. Newlines and | 1220 * used in src/components/autofill/content/renderer/form_autofill_util.h. |
1220 * tabs are stripped. | 1221 * Newlines and tabs are stripped. |
1221 * | 1222 * |
1222 * @param {Element} element An element to examine. | 1223 * @param {Element} element An element to examine. |
1223 * @return {string} The value for |element|. | 1224 * @return {string} The value for |element|. |
1224 */ | 1225 */ |
1225 __gCrWeb.autofill.value = function(element) { | 1226 __gCrWeb.autofill.value = function(element) { |
1226 return (element.value || '').replace(/[\n\t]/gm, ''); | 1227 return (element.value || '').replace(/[\n\t]/gm, ''); |
1227 }; | 1228 }; |
1228 | 1229 |
1229 /** | 1230 /** |
1230 * Returns the auto-fillable form control elements in |formElement|. | 1231 * Returns the auto-fillable form control elements in |formElement|. |
1231 * | 1232 * |
1232 * It is based on the logic in | 1233 * It is based on the logic in |
1233 * void ExtractAutofillableElements( | 1234 * void ExtractAutofillableElements( |
1234 * const blink::WebFormElement& form_element, | 1235 * const blink::WebFormElement& form_element, |
1235 * RequirementsMask requirements, | 1236 * RequirementsMask requirements, |
1236 * std::vector<blink::WebFormControlElement>* autofillable_elements); | 1237 * std::vector<blink::WebFormControlElement>* autofillable_elements); |
1237 * in chromium/src/components/autofill/renderer/form_autofill_util.h. | 1238 * in chromium/src/components/autofill/content/renderer/form_autofill_util.h. |
1238 * | 1239 * |
1239 * @param {Element} formElement A form element to be processed. | 1240 * @param {Element} formElement A form element to be processed. |
1240 * @param {int} requirementsMask A mask on the requirement. | 1241 * @param {int} requirementsMask A mask on the requirement. |
1241 * @param {Array.<Element>} autofillableElements The array of autofillable | 1242 * @param {Array.<Element>} autofillableElements The array of autofillable |
1242 * elements. | 1243 * elements. |
1243 */ | 1244 */ |
1244 __gCrWeb.autofill.extractAutofillableElements = function( | 1245 __gCrWeb.autofill.extractAutofillableElements = function( |
1245 formElement, requirementsMask, autofillableElements) { | 1246 formElement, requirementsMask, autofillableElements) { |
1246 var controlElements = __gCrWeb.common.getFormControlElements(formElement); | 1247 var controlElements = __gCrWeb.common.getFormControlElements(formElement); |
1247 | 1248 |
1248 for (var i = 0; i < controlElements.length; ++i) { | 1249 for (var i = 0; i < controlElements.length; ++i) { |
1249 var element = controlElements[i]; | 1250 var element = controlElements[i]; |
1250 if (!__gCrWeb.autofill.isAutofillableElement(element)) { | 1251 if (!__gCrWeb.autofill.isAutofillableElement(element)) { |
1251 continue; | 1252 continue; |
1252 } | 1253 } |
1253 if (requirementsMask & | 1254 if (requirementsMask & |
1254 __gCrWeb.autofill.REQUIREMENTS_MASK_REQUIRE_AUTOCOMPLETE) { | 1255 __gCrWeb.autofill.REQUIREMENTS_MASK_REQUIRE_AUTOCOMPLETE) { |
1255 // Different from method void ExtractAutofillableElements() in | 1256 // Different from method void ExtractAutofillableElements() in |
1256 // chromium/src/components/autofill/renderer/form_autofill_util.h, where | 1257 // chromium/src/components/autofill/content/renderer/form_autofill_util.h, |
1257 // satisfiesRequireAutocomplete() check is only applied on input controls, | 1258 // where satisfiesRequireAutocomplete() check is only applied on input |
1258 // here satisfiesRequireAutocomplete() check is also applied on select | 1259 // controls, here satisfiesRequireAutocomplete() check is also applied on |
1259 // control element. This is based on the TODO in that file saying "WebKit | 1260 // select control element. This is based on the TODO in that file saying |
1260 // currently doesn't handle the autocomplete attribute for select control | 1261 // "WebKit currently doesn't handle the autocomplete attribute for select |
1261 // elements, but it probably should." | 1262 // control elements, but it probably should." |
1262 if (!__gCrWeb.autofill.satisfiesRequireAutocomplete(element, false)) { | 1263 if (!__gCrWeb.autofill.satisfiesRequireAutocomplete(element, false)) { |
1263 continue; | 1264 continue; |
1264 } | 1265 } |
1265 } | 1266 } |
1266 autofillableElements.push(element); | 1267 autofillableElements.push(element); |
1267 } | 1268 } |
1268 }; | 1269 }; |
1269 | 1270 |
1270 /** | 1271 /** |
1271 * Fills out a FormField object from a given form control element. | 1272 * Fills out a FormField object from a given form control element. |
1272 * | 1273 * |
1273 * It is based on the logic in | 1274 * It is based on the logic in |
1274 * void WebFormControlElementToFormField( | 1275 * void WebFormControlElementToFormField( |
1275 * const blink::WebFormControlElement& element, | 1276 * const blink::WebFormControlElement& element, |
1276 * ExtractMask extract_mask, | 1277 * ExtractMask extract_mask, |
1277 * FormFieldData* field); | 1278 * FormFieldData* field); |
1278 * in chromium/src/components/autofill/renderer/form_autofill_util.h. | 1279 * in chromium/src/components/autofill/content/renderer/form_autofill_util.h. |
1279 * | 1280 * |
1280 * @param {Element} element The element to be processed. | 1281 * @param {Element} element The element to be processed. |
1281 * @param {int} extractMask A bit field mask to extract data from |element|. | 1282 * @param {int} extractMask A bit field mask to extract data from |element|. |
1282 * See the document on variable __gCrWeb.autofill.EXTRACT_MASK_NONE, | 1283 * See the document on variable __gCrWeb.autofill.EXTRACT_MASK_NONE, |
1283 * __gCrWeb.autofill.EXTRACT_MASK_VALUE, | 1284 * __gCrWeb.autofill.EXTRACT_MASK_VALUE, |
1284 * __gCrWeb.autofill.EXTRACT_MASK_OPTION_TEXT and | 1285 * __gCrWeb.autofill.EXTRACT_MASK_OPTION_TEXT and |
1285 * __gCrWeb.autofill.EXTRACT_MASK_OPTIONS. | 1286 * __gCrWeb.autofill.EXTRACT_MASK_OPTIONS. |
1286 * @param {Object} field Field to fill in the element information. | 1287 * @param {Object} field Field to fill in the element information. |
1287 */ | 1288 */ |
1288 __gCrWeb.autofill.webFormControlElementToFormField = function( | 1289 __gCrWeb.autofill.webFormControlElementToFormField = function( |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1381 continue; | 1382 continue; |
1382 } | 1383 } |
1383 var elementName = __gCrWeb['common'].nameForAutofill(element); | 1384 var elementName = __gCrWeb['common'].nameForAutofill(element); |
1384 var value = formData[elementName]; | 1385 var value = formData[elementName]; |
1385 if (value) { | 1386 if (value) { |
1386 element.placeholder = value; | 1387 element.placeholder = value; |
1387 } | 1388 } |
1388 } | 1389 } |
1389 } | 1390 } |
1390 }; | 1391 }; |
OLD | NEW |