Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(229)

Unified Diff: ios/chrome/browser/passwords/resources/password_controller.js

Issue 2814773002: Move password-related methods from core.js to password_controller.js. (Closed)
Patch Set: Address reviewer comment (fix verb tense in test comment) Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/chrome/browser/passwords/password_controller_unittest.mm ('k') | ios/web/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..c04af67cdf8314a4b9c6a35861f8be75a50409cd 100644
--- a/ios/chrome/browser/passwords/resources/password_controller.js
+++ b/ios/chrome/browser/passwords/resources/password_controller.js
@@ -28,13 +28,54 @@ 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(crbug.com/614092): investigate if this method can be completely
+ * removed from the gCrWeb public interface.
+ */
+ __gCrWeb['hasPasswordField'] = 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.
« no previous file with comments | « ios/chrome/browser/passwords/password_controller_unittest.mm ('k') | ios/web/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698