Chromium Code Reviews| Index: ios/chrome/browser/passwords/resources/password_controller.js |
| diff --git a/ios/chrome/browser/passwords/resources/password_controller.js b/ios/chrome/browser/passwords/resources/password_controller.js |
| index f3bb4213d9097e437d8dd52d3c0753e3b917288e..b8b9fb5b74df005ec20a11861ed8e51b68d5c1ba 100644 |
| --- a/ios/chrome/browser/passwords/resources/password_controller.js |
| +++ b/ios/chrome/browser/passwords/resources/password_controller.js |
| @@ -28,13 +28,55 @@ if (__gCrWeb && !__gCrWeb['fillPasswordForm']) { |
| */ |
| __gCrWeb['findPasswordForms'] = function() { |
| var formDataList = []; |
| - if (__gCrWeb.hasPasswordField()) { |
| + if (hasPasswordField_(window)) { |
| __gCrWeb.getPasswordFormDataList(formDataList, window); |
| } |
| return __gCrWeb.stringify(formDataList); |
| }; |
| /** |
| + * Returns true if the top window or any frames inside contain an input field |
| + * of type 'password'. This method is only used for unit tests and are only |
| + * kept for legacy reasons. Prefer to use the private |
| + * {@code hasPasswordField_} within this file. |
| + * @return {boolean} Whether a password field exists. |
| + * |
| + * 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.
|
| + * gCrWeb public interface. |
| + */ |
| + __gCrWeb['hasPasswordFieldTestOnly'] = function() { |
| + return hasPasswordField_(window); |
| + }; |
| + |
| + /** Returns true if the supplied window or any frames inside contain an input |
| + * field of type 'password'. |
| + * @private |
| + */ |
| + var hasPasswordField_ = function(win) { |
| + var doc = win.document; |
| + |
| + // We may will not be allowed to read the 'document' property from a frame |
| + // that is in a different domain. |
| + if (!doc) { |
| + return false; |
| + } |
| + |
| + if (doc.querySelector('input[type=password]')) { |
| + return true; |
| + } |
| + |
| + var frames = win.frames; |
| + for (var i = 0; i < frames.length; i++) { |
| + if (hasPasswordField_(frames[i])) { |
| + return true; |
| + } |
| + } |
| + |
| + return false; |
| + }; |
| + |
| + |
| + /** |
| * Returns the password form with the given |name| as a JSON string. |
| * @param {string} name The name of the form to extract. |
| * @return {string} The password form. |