Removed PanelRegistry from panel.js.
authorAtul Varma <varmaa@gmail.com>
Mon, 29 Nov 2010 15:13:20 -0500
changeset 1141 25024ae348a8b4cf8031d895fa741ba818fa725b
parent 1140 7fe5dd06adececaadc9d30ef237f437304215c11
child 1142 74ea9ac4570d7a4196991711ebfca08126767759
push id471
push userbwarner@mozilla.com
push dateTue, 30 Nov 2010 22:30:12 +0000
Removed PanelRegistry from panel.js.
packages/addon-kit/lib/panel.js
--- a/packages/addon-kit/lib/panel.js
+++ b/packages/addon-kit/lib/panel.js
@@ -43,17 +43,16 @@ if (!require("xul-app").is("Firefox")) {
     "for more information."
   ].join(""));
 }
 
 const { Ci } = require("chrome");
 const { validateOptions: valid } = require("api-utils");
 const { Symbiont } = require("content");
 const { EventEmitter } = require('events');
-const { Registry } = require('utils/registry');
 
 require("xpcom").utils.defineLazyServiceGetter(
   this,
   "windowMediator",
   "@mozilla.org/appshell/window-mediator;1",
   "nsIWindowMediator"
 );
 
@@ -96,37 +95,33 @@ const Panel = Symbiont.resolve({
       .swapFrameLoaders(this._viewFrame);
     this.__frameLoadersSwapped = value;
   },
   __frameLoadersSwapped: false,
 
   constructor: function Panel(options) {
     this._onShow = this._onShow.bind(this);
     this._onHide = this._onHide.bind(this);
-    PanelRegistry.on('add', this._onAdd.bind(this));
-    PanelRegistry.on('remove', this._onRemove.bind(this));
     this.on('inited', this._onSymbiontInit.bind(this));
 
     options = options || {};
     if ('onShow' in options)
       this.on('show', options.onShow);
     if ('onHide' in options)
       this.on('hide', options.onHide);
     if ('width' in options)
       this.width = options.width;
     if ('height' in options)
       this.height = options.height;
     if ('contentURL' in options)
       this.contentURL = options.contentURL;
 
     this._init(options);
-    PanelRegistry.add(this._public);
   },
   _destructor: function _destructor() {
-    PanelRegistry.remove(this._public);
     this._removeAllListeners('show');
     // defer cleanup to be performed after panel gets hidden
     this._xulPanel = null;
     this._symbiontDestructor(this);
     this._removeAllListeners(this, 'hide');
   },
   destroy: function destroy() {
     this._destructor();
@@ -139,19 +134,16 @@ const Panel = Symbiont.resolve({
   /* Public API: Panel.height */
   get height() this._height,
   set height(value)
     this._height =  valid({ $: value }, { $: validNumber }).$ || this._height,
   _height: 240,
   /* Public API: Panel.show */
   show: function show(anchor) {
     // do nothing if already open
-    if (!PanelRegistry.has(this))
-      throw new Error(ERR_ADD);
-
     anchor = anchor || null;
     let document = getWindow(anchor).document;
     let xulPanel = this._xulPanel;
     if (!xulPanel) {
       xulPanel = this._xulPanel = document.createElementNS(XUL_NS, 'panel');
       let frame = document.createElementNS(XUL_NS, 'iframe');
       frame.setAttribute('type', 'content');
       frame.setAttribute('flex', '1');
@@ -170,19 +162,16 @@ const Panel = Symbiont.resolve({
       when = null;
     }
     xulPanel.sizeTo(width, height);
     xulPanel.openPopup(anchor, when, x, y);
     return this._public;
   },
   /* Public API: Panel.hide */
   hide: function hide() {
-    if (!PanelRegistry.has(this))
-      throw new Error(ERR_ADD);
-
     // The popuphiding handler takes care of swapping back the frame loaders
     // and removing the XUL panel from the application window, we just have to
     // trigger it by hiding the popup.
     // XXX Sometimes I get "TypeError: xulPanel.hidePopup is not a function"
     // when quitting the host application while a panel is visible.  To suppress
     // them, this now checks for "hidePopup" in xulPanel before calling it.
     // It's not clear if there's an actual issue or the error is just normal.
     let xulPanel = this._xulPanel;
@@ -242,48 +231,30 @@ const Panel = Symbiont.resolve({
         return this.on('inited', this._onShow.bind(this));
       this._frameLoadersSwapped = true;
       this._emit('show', this._public);
     } catch(e) {
       this._emit('error', e);
     }
   },
   /**
-   * Notification that panel was added.
-   */
-  _onAdd: function _onAdd(self) {
-    if (self == this._public && this._inited)
-      this._onInit();
-  },
-  /**
-   * Notification that panel was removed.
-   */
-  _onRemove: function _onRemove(self) {
-    if (self == this._public)
-        this.hide();
-  },
-  /**
    * Notification that panel was fully initialized.
    * This will be called another time when panel was added if it
    * was initialized before.
    */
   _onInit: function _onInit() {
     this._inited = true;
-    if (PanelRegistry.has(this)) {
-      // perform all deferred tasks like initSymbiont, show, hide ...
-      this._emit('inited');
-      this._removeAllListeners('inited');
-    }
+    // perform all deferred tasks like initSymbiont, show, hide ...
+    this._emit('inited');
+    this._removeAllListeners('inited');
   }
 });
 exports.Panel = function(options) Panel(options)
 exports.Panel.prototype = Panel.prototype;
 
-const PanelRegistry = Registry(Panel);
-
 function getWindow(anchor) {
   let window;
 
   if (anchor) {
     let anchorWindow = anchor.ownerDocument.defaultView.top;
     let anchorDocument = anchorWindow.document;
 
     let enumerator = windowMediator.getEnumerator("navigator:browser");