Bug 1217129: Part 1 - Add onBeforeDestroyed and onDestroyed callbacks to CustomizableUI widgets. r?gijs
--- a/browser/components/customizableui/CustomizableUI.jsm
+++ b/browser/components/customizableui/CustomizableUI.jsm
@@ -2331,16 +2331,17 @@ var CustomizableUIInternal = {
if (aSource == CustomizableUI.SOURCE_BUILTIN) {
widget._introducedInVersion = aData.introducedInVersion || 0;
}
this.wrapWidgetEventHandler("onBeforeCreated", widget);
this.wrapWidgetEventHandler("onClick", widget);
this.wrapWidgetEventHandler("onCreated", widget);
+ this.wrapWidgetEventHandler("onDestroyed", widget);
if (widget.type == "button") {
widget.onCommand = typeof aData.onCommand == "function" ?
aData.onCommand :
null;
} else if (widget.type == "view") {
if (typeof aData.viewId != "string") {
ERROR("Expected a string for widget " + widget.id + " viewId, but got "
@@ -2434,16 +2435,19 @@ var CustomizableUIInternal = {
for (let eventName of kSubviewEvents) {
let handler = "on" + eventName;
if (typeof widget[handler] == "function") {
viewNode.removeEventListener(eventName, widget[handler], false);
}
}
}
}
+ if (widgetNode && widget.onDestroyed) {
+ widget.onDestroyed(window.document);
+ }
}
gPalette.delete(aWidgetId);
gGroupWrapperCache.delete(aWidgetId);
this.notifyListeners("onWidgetDestroyed", aWidgetId);
},
@@ -3167,16 +3171,21 @@ this.CustomizableUI = {
* that will be invoked before the widget gets a DOM node
* constructed, passing the document in which that will happen.
* This is useful especially for 'view' type widgets that need
* to construct their views on the fly (e.g. from bootstrapped
* add-ons)
* - onCreated(aNode): Attached to all widgets; a function that will be invoked
* whenever the widget has a DOM node constructed, passing the
* constructed node as an argument.
+ * - onDestroyed(aDoc): Attached to all non-custom widgets; a function that
+ * will be invoked after the widget has a DOM node destroyed,
+ * passing the document from which it was removed. This is
+ * useful especially for 'view' type widgets that need to
+ * cleanup after views that were constructed on the fly.
* - onCommand(aEvt): Only useful for button widgets; a function that will be
* invoked when the user activates the button.
* - onClick(aEvt): Attached to all widgets; a function that will be invoked
* when the user clicks the widget.
* - onViewShowing(aEvt): Only useful for views; a function that will be
* invoked when a user shows your view.
* - onViewHiding(aEvt): Only useful for views; a function that will be
* invoked when a user hides your view.