Bug 1453421 - stop findbar from looping over every single property, r?mikedeboer draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Wed, 18 Apr 2018 12:02:35 +0100
changeset 784342 9634a000f2ce01a86e785fc539cefd7254da8222
parent 783966 789e30ff2e3d6e1fcfce1a373c1e5635488d24da
push id106896
push usergijskruitbosch@gmail.com
push dateWed, 18 Apr 2018 12:16:45 +0000
reviewersmikedeboer
bugs1453421
milestone61.0a1
Bug 1453421 - stop findbar from looping over every single property, r?mikedeboer MozReview-Commit-ID: KsrzhUZ167g
toolkit/content/browser-content.js
toolkit/content/widgets/findbar.xml
--- a/toolkit/content/browser-content.js
+++ b/toolkit/content/browser-content.js
@@ -1066,22 +1066,26 @@ var FindBar = {
         this._findMode = mode;
         this._passKeyToParent(event);
       }
     }
   },
 
   _passKeyToParent(event) {
     event.preventDefault();
+    // These are the properties required to dispatch another 'real' event
+    // to the findbar in the parent in _dispatchKeypressEvent in findbar.xml .
+    // If you make changes here, verify that that method can still do its job.
+    const kRequiredProps = [
+      "type", "bubbles", "cancelable", "ctrlKey", "altKey", "shiftKey",
+      "metaKey", "keyCode", "charCode",
+    ];
     let fakeEvent = {};
-    for (let k in event) {
-      if (typeof event[k] != "object" && typeof event[k] != "function" &&
-          !(k in content.KeyboardEvent)) {
-        fakeEvent[k] = event[k];
-      }
+    for (let prop of kRequiredProps) {
+      fakeEvent[prop] = event[prop];
     }
     sendAsyncMessage("Findbar:Keypress", fakeEvent);
   },
 
   _onMouseup(event) {
     if (this._findMode != this.FIND_NORMAL)
       sendAsyncMessage("Findbar:Mouseup");
   },
--- a/toolkit/content/widgets/findbar.xml
+++ b/toolkit/content/widgets/findbar.xml
@@ -763,26 +763,25 @@
           this.toggleHighlight(false);
           this._updateStatusUI();
           this._enableFindButtons(false);
         ]]></body>
       </method>
 
       <method name="_dispatchKeypressEvent">
         <parameter name="aTarget"/>
-        <parameter name="aEvent"/>
+        <parameter name="fakeEvent"/>
         <body><![CDATA[
           if (!aTarget)
             return;
 
-          let event = document.createEvent("KeyboardEvent");
-          event.initKeyEvent(aEvent.type, aEvent.bubbles, aEvent.cancelable,
-                             aEvent.view, aEvent.ctrlKey, aEvent.altKey,
-                             aEvent.shiftKey, aEvent.metaKey, aEvent.keyCode,
-                             aEvent.charCode);
+          // The event information comes from the child process. If we need more
+          // properties/information here, change the list of sent properties in
+          // browser-content.js
+          let event = new aTarget.ownerGlobal.KeyboardEvent(fakeEvent.type, fakeEvent);
           aTarget.dispatchEvent(event);
         ]]></body>
       </method>
 
       <field name="_xulBrowserWindow">null</field>
       <method name="_updateStatusUIBar">
         <parameter name="aFoundURL"/>
         <body><![CDATA[