Bug 1365542 - Use HTML5 FormData object rather than hand-rolling form data for search keyword handling r=Gijs
authorArshad Kazmi <arshadkazmi42@gmail.com>
Tue, 18 Dec 2018 23:44:15 +0000
changeset 511196 7c5b9046b433
parent 511195 556920bb426c
child 511197 6ba198e2a59e
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1365542
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1365542 - Use HTML5 FormData object rather than hand-rolling form data for search keyword handling r=Gijs Differential Revision: https://phabricator.services.mozilla.com/D14877
browser/actors/ContextMenuChild.jsm
--- a/browser/actors/ContextMenuChild.jsm
+++ b/browser/actors/ContextMenuChild.jsm
@@ -120,51 +120,28 @@ const messageListeners = {
     let formBaseURI = Services.io.newURI(node.form.baseURI, charset);
     let formURI = Services.io.newURI(node.form.getAttribute("action"),
                                      charset, formBaseURI);
     let spec = formURI.spec;
     let isURLEncoded =  (node.form.method.toUpperCase() == "POST" &&
                          (node.form.enctype == "application/x-www-form-urlencoded" ||
                           node.form.enctype == ""));
     let title = node.ownerDocument.title;
-    let formData = [];
 
-    function escapeNameValuePair(aName, aValue, aIsFormUrlEncoded) {
-      if (aIsFormUrlEncoded) {
+    function escapeNameValuePair([aName, aValue]) {
+      if (isURLEncoded) {
         return escape(aName + "=" + aValue);
       }
 
       return escape(aName) + "=" + escape(aValue);
     }
-
-    for (let el of node.form.elements) {
-      if (!el.type) // happens with fieldsets
-        continue;
-
-      if (el == node) {
-        formData.push((isURLEncoded) ? escapeNameValuePair(el.name, "%s", true) :
-                                       // Don't escape "%s", just append
-                                       escapeNameValuePair(el.name, "", false) + "%s");
-        continue;
-      }
-
-      let type = el.type.toLowerCase();
-
-      if (((el instanceof this.content.HTMLInputElement && el.mozIsTextField(true)) ||
-          type == "hidden" || type == "textarea") ||
-          ((type == "checkbox" || type == "radio") && el.checked)) {
-        formData.push(escapeNameValuePair(el.name, el.value, isURLEncoded));
-      } else if (el instanceof this.content.HTMLSelectElement && el.selectedIndex >= 0) {
-        for (let j = 0; j < el.options.length; j++) {
-          if (el.options[j].selected)
-            formData.push(escapeNameValuePair(el.name, el.options[j].value,
-                                              isURLEncoded));
-        }
-      }
-    }
+    let formData = new this.content.FormData(node.form);
+    formData.delete(node.name);
+    formData = Array.from(formData).map(escapeNameValuePair);
+    formData.push(escape(node.name) + (isURLEncoded ? escape("=%s") : "=%s"));
 
     let postData;
 
     if (isURLEncoded) {
       postData = formData.join("&");
     } else {
       let separator = spec.includes("?") ? "&" : "?";
       spec += separator + formData.join("&");