Bug 1370429 - Part 3: Import the telephone grammar list from Chromium. r=MattN draft
authorSean Lee <selee@mozilla.com>
Wed, 19 Jul 2017 10:16:57 +0800
changeset 613052 6eeda223a01a1d903143bdb2c3ea643d8eadff2d
parent 613051 ea87939163d8311371d5d2aafdd5c6f1d3924abe
child 613053 61506eccd5ef42cdbf9eefcc7e94c24f4d92f4e1
push id69715
push userbmo:selee@mozilla.com
push dateFri, 21 Jul 2017 14:12:03 +0000
reviewersMattN
bugs1370429
milestone56.0a1
Bug 1370429 - Part 3: Import the telephone grammar list from Chromium. r=MattN MozReview-Commit-ID: kwPfrzi6Q3
browser/extensions/formautofill/FormAutofillHeuristics.jsm
toolkit/content/license.html
--- a/browser/extensions/formautofill/FormAutofillHeuristics.jsm
+++ b/browser/extensions/formautofill/FormAutofillHeuristics.jsm
@@ -337,16 +337,134 @@ this.FormAutofillHeuristics = {
         if (fieldNameResult) {
           return fieldNameResult;
         }
       }
     }
 
     return null;
   },
+
+/**
+ * Phone field grammars - first matched grammar will be parsed. Grammars are
+ * separated by { REGEX_SEPARATOR, FIELD_NONE, 0 }. Suffix and extension are
+ * parsed separately unless they are necessary parts of the match.
+ * The following notation is used to describe the patterns:
+ * <cc> - country code field.
+ * <ac> - area code field.
+ * <phone> - phone or prefix.
+ * <suffix> - suffix.
+ * <ext> - extension.
+ * :N means field is limited to N characters, otherwise it is unlimited.
+ * (pattern <field>)? means pattern is optional and matched separately.
+ *
+ * This grammar list from Chromium will be enabled partially once we need to
+ * support more cases of Telephone fields.
+ */
+  PHONE_FIELD_GRAMMARS: [
+    // Country code: <cc> Area Code: <ac> Phone: <phone> (- <suffix>
+
+    // (Ext: <ext>)?)?
+      // {REGEX_COUNTRY, FIELD_COUNTRY_CODE, 0},
+      // {REGEX_AREA, FIELD_AREA_CODE, 0},
+      // {REGEX_PHONE, FIELD_PHONE, 0},
+      // {REGEX_SEPARATOR, FIELD_NONE, 0},
+
+    // \( <ac> \) <phone>:3 <suffix>:4 (Ext: <ext>)?
+      // {REGEX_AREA_NOTEXT, FIELD_AREA_CODE, 3},
+      // {REGEX_PREFIX_SEPARATOR, FIELD_PHONE, 3},
+      // {REGEX_PHONE, FIELD_SUFFIX, 4},
+      // {REGEX_SEPARATOR, FIELD_NONE, 0},
+
+    // Phone: <cc> <ac>:3 - <phone>:3 - <suffix>:4 (Ext: <ext>)?
+      // {REGEX_PHONE, FIELD_COUNTRY_CODE, 0},
+      // {REGEX_PHONE, FIELD_AREA_CODE, 3},
+      // {REGEX_PREFIX_SEPARATOR, FIELD_PHONE, 3},
+      // {REGEX_SUFFIX_SEPARATOR, FIELD_SUFFIX, 4},
+      // {REGEX_SEPARATOR, FIELD_NONE, 0},
+
+    // Phone: <cc>:3 <ac>:3 <phone>:3 <suffix>:4 (Ext: <ext>)?
+      // {REGEX_PHONE, FIELD_COUNTRY_CODE, 3},
+      // {REGEX_PHONE, FIELD_AREA_CODE, 3},
+      // {REGEX_PHONE, FIELD_PHONE, 3},
+      // {REGEX_PHONE, FIELD_SUFFIX, 4},
+      // {REGEX_SEPARATOR, FIELD_NONE, 0},
+
+    // Area Code: <ac> Phone: <phone> (- <suffix> (Ext: <ext>)?)?
+      // {REGEX_AREA, FIELD_AREA_CODE, 0},
+      // {REGEX_PHONE, FIELD_PHONE, 0},
+      // {REGEX_SEPARATOR, FIELD_NONE, 0},
+
+    // Phone: <ac> <phone>:3 <suffix>:4 (Ext: <ext>)?
+      // {REGEX_PHONE, FIELD_AREA_CODE, 0},
+      // {REGEX_PHONE, FIELD_PHONE, 3},
+      // {REGEX_PHONE, FIELD_SUFFIX, 4},
+      // {REGEX_SEPARATOR, FIELD_NONE, 0},
+
+    // Phone: <cc> \( <ac> \) <phone> (- <suffix> (Ext: <ext>)?)?
+      // {REGEX_PHONE, FIELD_COUNTRY_CODE, 0},
+      // {REGEX_AREA_NOTEXT, FIELD_AREA_CODE, 0},
+      // {REGEX_PREFIX_SEPARATOR, FIELD_PHONE, 0},
+      // {REGEX_SEPARATOR, FIELD_NONE, 0},
+
+    // Phone: \( <ac> \) <phone> (- <suffix> (Ext: <ext>)?)?
+      // {REGEX_PHONE, FIELD_COUNTRY_CODE, 0},
+      // {REGEX_AREA_NOTEXT, FIELD_AREA_CODE, 0},
+      // {REGEX_PREFIX_SEPARATOR, FIELD_PHONE, 0},
+      // {REGEX_SEPARATOR, FIELD_NONE, 0},
+
+    // Phone: <cc> - <ac> - <phone> - <suffix> (Ext: <ext>)?
+      // {REGEX_PHONE, FIELD_COUNTRY_CODE, 0},
+      // {REGEX_PREFIX_SEPARATOR, FIELD_AREA_CODE, 0},
+      // {REGEX_PREFIX_SEPARATOR, FIELD_PHONE, 0},
+      // {REGEX_SUFFIX_SEPARATOR, FIELD_SUFFIX, 0},
+      // {REGEX_SEPARATOR, FIELD_NONE, 0},
+
+    // Area code: <ac>:3 Prefix: <prefix>:3 Suffix: <suffix>:4 (Ext: <ext>)?
+      // {REGEX_AREA, FIELD_AREA_CODE, 3},
+      // {REGEX_PREFIX, FIELD_PHONE, 3},
+      // {REGEX_SUFFIX, FIELD_SUFFIX, 4},
+      // {REGEX_SEPARATOR, FIELD_NONE, 0},
+
+    // Phone: <ac> Prefix: <phone> Suffix: <suffix> (Ext: <ext>)?
+      // {REGEX_PHONE, FIELD_AREA_CODE, 0},
+      // {REGEX_PREFIX, FIELD_PHONE, 0},
+      // {REGEX_SUFFIX, FIELD_SUFFIX, 0},
+      // {REGEX_SEPARATOR, FIELD_NONE, 0},
+
+    // Phone: <ac> - <phone>:3 - <suffix>:4 (Ext: <ext>)?
+      // {REGEX_PHONE, FIELD_AREA_CODE, 0},
+      // {REGEX_PREFIX_SEPARATOR, FIELD_PHONE, 3},
+      // {REGEX_SUFFIX_SEPARATOR, FIELD_SUFFIX, 4},
+      // {REGEX_SEPARATOR, FIELD_NONE, 0},
+
+    // Phone: <cc> - <ac> - <phone> (Ext: <ext>)?
+      // {REGEX_PHONE, FIELD_COUNTRY_CODE, 0},
+      // {REGEX_PREFIX_SEPARATOR, FIELD_AREA_CODE, 0},
+      // {REGEX_SUFFIX_SEPARATOR, FIELD_PHONE, 0},
+      // {REGEX_SEPARATOR, FIELD_NONE, 0},
+
+    // Phone: <ac> - <phone> (Ext: <ext>)?
+      // {REGEX_AREA, FIELD_AREA_CODE, 0},
+      // {REGEX_PHONE, FIELD_PHONE, 0},
+      // {REGEX_SEPARATOR, FIELD_NONE, 0},
+
+    // Phone: <cc>:3 - <phone>:10 (Ext: <ext>)?
+      // {REGEX_PHONE, FIELD_COUNTRY_CODE, 3},
+      // {REGEX_PHONE, FIELD_PHONE, 10},
+      // {REGEX_SEPARATOR, FIELD_NONE, 0},
+
+    // Ext: <ext>
+      // {REGEX_EXTENSION, FIELD_EXTENSION, 0},
+      // {REGEX_SEPARATOR, FIELD_NONE, 0},
+
+    // Phone: <phone> (Ext: <ext>)?
+      // {REGEX_PHONE, FIELD_PHONE, 0},
+      // {REGEX_SEPARATOR, FIELD_NONE, 0},
+  ],
 };
 
 XPCOMUtils.defineLazyGetter(this.FormAutofillHeuristics, "RULES", () => {
   let sandbox = {};
   let scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"]
                        .getService(Ci.mozIJSSubScriptLoader);
   const HEURISTICS_REGEXP = "chrome://formautofill/content/heuristicsRegexp.js";
   scriptLoader.loadSubScript(HEURISTICS_REGEXP, sandbox, "utf-8");
--- a/toolkit/content/license.html
+++ b/toolkit/content/license.html
@@ -2737,16 +2737,17 @@ WITH THE USE OR PERFORMANCE OF THIS SOFT
 
     <h1><a id="chromium"></a>Chromium License</h1>
 
     <p>This license applies to parts of the code in:</p>
     <ul>
 #ifndef RELEASE_OR_BETA
         <li><code>browser/extensions/formautofill/content/heuristicsRegexp.js</code></li>
         <li><code>browser/extensions/formautofill/content/nameReferences.js</code></li>
+        <li><code>browser/extensions/formautofill/FormAutofillHeuristics.jsm</code></li>
         <li><code>browser/extensions/formautofill/FormAutofillNameUtils.jsm</code></li>
 #endif
         <li><code>browser/extensions/mortar/host/common/opengles2-utils.jsm</code></li>
         <li><code>editor/libeditor/EditorEventListener.cpp</code></li>
         <li><code>security/sandbox/</code></li>
         <li><code>widget/cocoa/GfxInfo.mm</code></li>
     </ul>
     <p>and also some files in these directories:</p>