Bug 1217129: Part 1 - Add onBeforeDestroyed and onDestroyed callbacks to CustomizableUI widgets. r?gijs draft
authorKris Maglione <maglione.k@gmail.com>
Sat, 09 Jan 2016 20:52:47 -0800
changeset 320564 72e33854df036ae07c7e77549688b21c57d7b95c
parent 320279 77c75e5b4df1888b2ccbff01944ecec4bfad0032
child 320565 b577254c0f21aba616fda43a729b70e7ad65e797
push id9233
push usermaglione.k@gmail.com
push dateMon, 11 Jan 2016 20:43:12 +0000
reviewersgijs
bugs1217129
milestone46.0a1
Bug 1217129: Part 1 - Add onBeforeDestroyed and onDestroyed callbacks to CustomizableUI widgets. r?gijs
browser/components/customizableui/CustomizableUI.jsm
--- 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.