Bug 1249226 - Use weak reference to keep popup's previous focus to avoid leak. r=neil

MozReview-Commit-ID: 8VUexyKMbJr
This commit is contained in:
Ting-Yu Chou 2016-03-09 10:54:04 +08:00
parent 7b72d7a595
commit 92314af9cb

View File

@ -285,12 +285,13 @@
<handler event="popupshowing"><![CDATA[
// Capture the previous focus before has a chance to get set inside the panel
try {
this._prevFocus = document.commandDispatcher.focusedElement;
if (this._prevFocus)
this._prevFocus = Components.utils
.getWeakReference(document.commandDispatcher.focusedElement);
if (this._prevFocus.get())
return;
} catch (ex) { }
this._prevFocus = document.activeElement;
this._prevFocus = Components.utils.getWeakReference(document.activeElement);
]]></handler>
<handler event="popupshown"><![CDATA[
// Fire event for accessibility APIs
@ -307,7 +308,7 @@
]]></handler>
<handler event="popuphidden"><![CDATA[
var currentFocus = this._currentFocus;
var prevFocus = this._prevFocus;
var prevFocus = this._prevFocus ? this._prevFocus.get() : null;
this._currentFocus = null;
this._prevFocus = null;
if (prevFocus && currentFocus && this.getAttribute("norestorefocus") != "true") {