Bug 737032 - add isValidXULTab() method to ease tab checking r=ttaubert
authorBellindira Castillo [:bellindira] <bellindira@appcoast.com>
Tue, 10 Apr 2012 12:13:36 -0600
changeset 94832 6edf254d7e5b56ca7641a1d5b6a7e44192261816
parent 94628 e636439e342fa7e561d2f86e0730251566dc5732
child 94833 51fe735d19a90aef55fe0cf8661f159b650e4cb1
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersttaubert
bugs737032
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 737032 - add isValidXULTab() method to ease tab checking r=ttaubert
browser/components/tabview/groupitems.js
browser/components/tabview/modules/utils.jsm
browser/components/tabview/tabitems.js
browser/components/tabview/tabview.js
browser/components/tabview/ui.js
--- a/browser/components/tabview/groupitems.js
+++ b/browser/components/tabview/groupitems.js
@@ -1187,17 +1187,17 @@ GroupItem.prototype = Utils.extend(new I
   //   options - change how the app tab is added.
   //
   // Options:
   //   position - the position of the app tab should be added to.
   //   dontAdjustTray - (boolean) if true, do not adjust the tray.
   addAppTab: function GroupItem_addAppTab(xulTab, options) {
     GroupItems.getAppTabFavIconUrl(xulTab, function(iconUrl) {
       // The tab might have been removed or unpinned while waiting.
-      if (xulTab.closing || !xulTab.parentNode || !xulTab.pinned)
+      if (!Utils.isValidXULTab(xulTab) || !xulTab.pinned)
         return;
 
       let self = this;
       let $appTab = iQ("<img>")
         .addClass("appTabIcon")
         .attr("src", iconUrl)
         .data("xulTab", xulTab)
         .mousedown(function GroupItem_addAppTab_onAppTabMousedown(event) {
--- a/browser/components/tabview/modules/utils.jsm
+++ b/browser/components/tabview/modules/utils.jsm
@@ -632,16 +632,25 @@ let Utils = {
   // ----------
   // Function: isDOMElement
   // Returns true if the given object is a DOM element.
   isDOMElement: function Utils_isDOMElement(object) {
     return object instanceof Ci.nsIDOMElement;
   },
 
   // ----------
+  // Function: isValidXULTab
+  // A xulTab is valid if it has not been closed,
+  // and it has not been removed from the DOM
+  // Returns true if the tab is valid.
+  isValidXULTab: function Utils_isValidXULTab(xulTab) {
+    return !xulTab.closing && xulTab.parentNode;
+  },
+
+  // ----------
   // Function: isNumber
   // Returns true if the argument is a valid number.
   isNumber: function Utils_isNumber(n) {
     return typeof n == 'number' && !isNaN(n);
   },
 
   // ----------
   // Function: isRect
--- a/browser/components/tabview/tabitems.js
+++ b/browser/components/tabview/tabitems.js
@@ -234,17 +234,17 @@ TabItem.prototype = Utils.extend(new Ite
     return data;
   },
 
   // ----------
   // Function: save
   // Store persistent for this object.
   save: function TabItem_save() {
     try {
-      if (!this.tab || this.tab.parentNode == null || !this._reconnected) // too soon/late to save
+      if (!this.tab || !Utils.isValidXULTab(this.tab) || !this._reconnected) // too soon/late to save
         return;
 
       let data = this.getStorageData();
       if (TabItems.storageSanity(data))
         Storage.saveTab(this.tab, data);
     } catch(e) {
       Utils.log("Error in saving tab value: "+e);
     }
@@ -566,17 +566,17 @@ TabItem.prototype = Utils.extend(new Ite
     this._hasBeenDrawn = true;
 
     UI.clearShouldResizeItems();
 
     rect = this.getBounds(); // ensure that it's a <Rect>
 
     Utils.assert(Utils.isRect(this.bounds), 'TabItem.setBounds: this.bounds is not a real rectangle!');
 
-    if (!this.parent && this.tab.parentNode != null)
+    if (!this.parent && Utils.isValidXULTab(this.tab))
       this.setTrenches(rect);
 
     this.save();
   },
 
   // ----------
   // Function: setZ
   // Sets the z-index for this item.
--- a/browser/components/tabview/tabview.js
+++ b/browser/components/tabview/tabview.js
@@ -55,17 +55,17 @@ let AllTabs = {
     move:         "TabMove",
     open:         "TabOpen",
     select:       "TabSelect",
     pinned:       "TabPinned",
     unpinned:     "TabUnpinned"
   },
 
   get tabs() {
-    return Array.filter(gBrowser.tabs, function (tab) !tab.closing);
+    return Array.filter(gBrowser.tabs, function (tab) Utils.isValidXULTab(tab));
   },
 
   register: function AllTabs_register(eventName, callback) {
     gBrowser.tabContainer.addEventListener(this._events[eventName], callback, false);
   },
 
   unregister: function AllTabs_unregister(eventName, callback) {
     gBrowser.tabContainer.removeEventListener(this._events[eventName], callback, false);
--- a/browser/components/tabview/ui.js
+++ b/browser/components/tabview/ui.js
@@ -786,17 +786,17 @@ let UI = {
         // we don't want to go to the Tab View UI. 
         if (self._storageBusy)
           return;
 
         // if not closing the last tab
         if (gBrowser.tabs.length > 1) {
           // Don't return to TabView if there are any app tabs
           for (let a = 0; a < gBrowser._numPinnedTabs; a++) {
-            if (!gBrowser.tabs[a].closing)
+            if (Utils.isValidXULTab(gBrowser.tabs[a]))
               return;
           }
 
           let groupItem = GroupItems.getActiveGroupItem();
 
           // 1) Only go back to the TabView tab when there you close the last
           // tab of a groupItem.
           let closingLastOfGroup = (groupItem &&