Bug 1243722 - Introduce notUsernameSelector in passwordmgr recipes, r=MattN a=lizzard CLOSED TREE
authorTimothy Guan-tin Chien <timdream@gmail.com>
Tue, 19 Apr 2016 21:53:52 -0700
changeset 317811 f51382b3b967
parent 317810 bbbd40c84bae
child 317812 201c523bcb48
push id5910
push usermozilla@noorenberghe.ca
push dateWed, 20 Apr 2016 05:01:05 +0000
treeherdermozilla-beta@f51382b3b967 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN, lizzard
bugs1243722
milestone46.0
Bug 1243722 - Introduce notUsernameSelector in passwordmgr recipes, r=MattN a=lizzard CLOSED TREE Additionally, add a recipe for Facebook. MozReview-Commit-ID: 7TdT3q652Tk
toolkit/components/passwordmgr/LoginManagerContent.jsm
toolkit/components/passwordmgr/LoginRecipes.jsm
toolkit/components/passwordmgr/content/recipes.json
--- a/toolkit/components/passwordmgr/LoginManagerContent.jsm
+++ b/toolkit/components/passwordmgr/LoginManagerContent.jsm
@@ -658,20 +658,27 @@ var LoginManagerContent = {
 
     if (!usernameField) {
       // Locate the username field in the form by searching backwards
       // from the first password field, assume the first text field is the
       // username. We might not find a username field if the user is
       // already logged in to the site.
       for (var i = pwFields[0].index - 1; i >= 0; i--) {
         var element = form.elements[i];
-        if (LoginHelper.isUsernameFieldType(element)) {
-          usernameField = element;
-          break;
+        if (!LoginHelper.isUsernameFieldType(element)) {
+          continue;
         }
+
+        if (fieldOverrideRecipe && fieldOverrideRecipe.notUsernameSelector &&
+            element.matches(fieldOverrideRecipe.notUsernameSelector)) {
+          continue;
+        }
+
+        usernameField = element;
+        break;
       }
     }
 
     if (!usernameField)
       log("(form -- no username field found)");
     else
       log("Username field ", usernameField, "has name/value:",
           usernameField.name, "/", usernameField.value);
--- a/toolkit/components/passwordmgr/LoginRecipes.jsm
+++ b/toolkit/components/passwordmgr/LoginRecipes.jsm
@@ -3,17 +3,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 this.EXPORTED_SYMBOLS = ["LoginRecipesContent", "LoginRecipesParent"];
 
 const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components;
 const REQUIRED_KEYS = ["hosts"];
-const OPTIONAL_KEYS = ["description", "passwordSelector", "pathRegex", "usernameSelector"];
+const OPTIONAL_KEYS = ["description", "notUsernameSelector", "passwordSelector", "pathRegex", "usernameSelector"];
 const SUPPORTED_KEYS = REQUIRED_KEYS.concat(OPTIONAL_KEYS);
 
 Cu.importGlobalProperties(["URL"]);
 
 Cu.import("resource://gre/modules/NetUtil.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
@@ -222,17 +222,18 @@ var LoginRecipesContent = {
     log.debug("getFieldOverrides: filtered recipes:", recipes);
     if (!recipes.size) {
       return null;
     }
 
     let chosenRecipe = null;
     // Find the first (most-specific recipe that involves field overrides).
     for (let recipe of recipes) {
-      if (!recipe.usernameSelector && !recipe.passwordSelector) {
+      if (!recipe.usernameSelector && !recipe.passwordSelector &&
+          !recipe.notUsernameSelector) {
         continue;
       }
 
       chosenRecipe = recipe;
       break;
     }
 
     return chosenRecipe;
--- a/toolkit/components/passwordmgr/content/recipes.json
+++ b/toolkit/components/passwordmgr/content/recipes.json
@@ -16,11 +16,16 @@
       "usernameSelector": "#login-account"
     },
     {
       "description": "Tibia uses type=password for its username field and puts the email address before the password field during registration",
       "hosts": ["secure.tibia.com"],
       "usernameSelector": "#accountname, input[name='loginname']",
       "passwordSelector": "#password1, input[name='loginpassword']",
       "pathRegex": "^\/account\/"
+    },
+    {
+      "description": "Username field will be incorrectly captured in the change password form (bug 1243722)",
+      "hosts": ["www.facebook.com"],
+      "notUsernameSelector": "#password_strength"
     }
   ]
 }