Bug 1453421 - stop findbar from looping over every single property, r?mikedeboer
MozReview-Commit-ID: KsrzhUZ167g
--- 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[