Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 // This file adheres to closure-compiler conventions in order to enable | 5 // This file adheres to closure-compiler conventions in order to enable |
| 6 // compilation with ADVANCED_OPTIMIZATIONS. See http://goo.gl/FwOgy | 6 // compilation with ADVANCED_OPTIMIZATIONS. See http://goo.gl/FwOgy |
| 7 // | 7 // |
| 8 // Installs password management functions on the |__gCrWeb| object. | 8 // Installs password management functions on the |__gCrWeb| object. |
| 9 // | 9 // |
| 10 // Finds all password forms in the current document and extracts | 10 // Finds all password forms in the current document and extracts |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 // Only install the password management functions once. | 21 // Only install the password management functions once. |
| 22 if (__gCrWeb && !__gCrWeb['fillPasswordForm']) { | 22 if (__gCrWeb && !__gCrWeb['fillPasswordForm']) { |
| 23 | 23 |
| 24 /** | 24 /** |
| 25 * Finds all password forms in the window and returns form data as a JSON | 25 * Finds all password forms in the window and returns form data as a JSON |
| 26 * string. | 26 * string. |
| 27 * @return {string} Form data as a JSON string. | 27 * @return {string} Form data as a JSON string. |
| 28 */ | 28 */ |
| 29 __gCrWeb['findPasswordForms'] = function() { | 29 __gCrWeb['findPasswordForms'] = function() { |
| 30 var formDataList = []; | 30 var formDataList = []; |
| 31 if (__gCrWeb.hasPasswordField()) { | 31 if (hasPasswordField_(window)) { |
| 32 __gCrWeb.getPasswordFormDataList(formDataList, window); | 32 __gCrWeb.getPasswordFormDataList(formDataList, window); |
| 33 } | 33 } |
| 34 return __gCrWeb.stringify(formDataList); | 34 return __gCrWeb.stringify(formDataList); |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 /** | 37 /** |
| 38 * Returns true if the top window or any frames inside contain an input field | |
| 39 * of type 'password'. This method is only used for unit tests and are only | |
| 40 * kept for legacy reasons. Prefer to use the private | |
| 41 * {@code hasPasswordField_} within this file. | |
| 42 * @return {boolean} Whether a password field exists. | |
| 43 * | |
| 44 * TODO(danyao): investigate if this method can be completely removed from the | |
|
Eugene But (OOO till 7-30)
2017/04/11 16:19:40
Per Google's Unit Testing Best Practices: "Test co
Eugene But (OOO till 7-30)
2017/04/11 16:19:40
In Chrome for iOS we use |TODO(crbug.com/<bug numb
danyao
2017/04/11 18:05:06
Done. This seems too small to warrant its own bug.
danyao
2017/04/11 18:05:06
Done.
| |
| 45 * gCrWeb public interface. | |
| 46 */ | |
| 47 __gCrWeb['hasPasswordFieldTestOnly'] = function() { | |
| 48 return hasPasswordField_(window); | |
| 49 }; | |
| 50 | |
| 51 /** Returns true if the supplied window or any frames inside contain an input | |
| 52 * field of type 'password'. | |
| 53 * @private | |
| 54 */ | |
| 55 var hasPasswordField_ = function(win) { | |
| 56 var doc = win.document; | |
| 57 | |
| 58 // We may will not be allowed to read the 'document' property from a frame | |
| 59 // that is in a different domain. | |
| 60 if (!doc) { | |
| 61 return false; | |
| 62 } | |
| 63 | |
| 64 if (doc.querySelector('input[type=password]')) { | |
| 65 return true; | |
| 66 } | |
| 67 | |
| 68 var frames = win.frames; | |
| 69 for (var i = 0; i < frames.length; i++) { | |
| 70 if (hasPasswordField_(frames[i])) { | |
| 71 return true; | |
| 72 } | |
| 73 } | |
| 74 | |
| 75 return false; | |
| 76 }; | |
| 77 | |
| 78 | |
| 79 /** | |
| 38 * Returns the password form with the given |name| as a JSON string. | 80 * Returns the password form with the given |name| as a JSON string. |
| 39 * @param {string} name The name of the form to extract. | 81 * @param {string} name The name of the form to extract. |
| 40 * @return {string} The password form. | 82 * @return {string} The password form. |
| 41 */ | 83 */ |
| 42 __gCrWeb['getPasswordForm'] = function(name) { | 84 __gCrWeb['getPasswordForm'] = function(name) { |
| 43 var el = __gCrWeb.common.getFormElementFromIdentifier(name); | 85 var el = __gCrWeb.common.getFormElementFromIdentifier(name); |
| 44 if (!el) | 86 if (!el) |
| 45 return 'noPasswordsFound'; | 87 return 'noPasswordsFound'; |
| 46 var formData = __gCrWeb.getPasswordFormData(el); | 88 var formData = __gCrWeb.getPasswordFormData(el); |
| 47 if (!formData) | 89 if (!formData) |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 426 'method': formElement.getAttribute('method'), | 468 'method': formElement.getAttribute('method'), |
| 427 'name': __gCrWeb.common.getFormIdentifier(formElement), | 469 'name': __gCrWeb.common.getFormIdentifier(formElement), |
| 428 'origin': origin, | 470 'origin': origin, |
| 429 'fields': fields, | 471 'fields': fields, |
| 430 'usernameElement': usernameElement, | 472 'usernameElement': usernameElement, |
| 431 'usernameValue': usernameValue, | 473 'usernameValue': usernameValue, |
| 432 'passwords': passwords | 474 'passwords': passwords |
| 433 }; | 475 }; |
| 434 }; | 476 }; |
| 435 } | 477 } |
| OLD | NEW |