// Firefox extension enabling the use of Gmail chat across multiple tabs. // Copyright (C) 2007 Jack Wootton . // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . function Tab(aTabMediator) { var _self = this; this._xulTab = null; this._tabMediator = aTabMediator; this._tabHelper = new TabHelper(this); this._largestWindow = null; this._maxWidth = -1; this._prevHeight = -1; this.getXulTab = function() { return this._xulTab; } this.setXulTab = function(aXulTab) { this._xulTab = aXulTab; } this.getXPosition = function() { return this._tabHelper.getXPosition(); } this.getContentWindow = function() { return this._xulTab.contentWindow; } this.getDocument = function() { return this.getContentWindow().document; } this.getBody = function() { var bodyNodes = this.getDocument().getElementsByTagName(Tags.BODY); if (bodyNodes.item(0) != null) { return bodyNodes.item(0); } else { if (this._largestWindow == null) this.getFrames(this.getContentWindow()); var bodyNodes = this._largestWindow.document. getElementsByTagName(Tags.BODY); if (bodyNodes.item(0) != null) return bodyNodes.item(0); } return null; } this.resetFrameCache = function() { this._maxWidth = -1; this._prevHeight = -1; this._largestWindow = null; } this.initialize = function(aXulTab) { try { this._xulTab = aXulTab; this._tabHelper.initialize(); } catch (exception) { throw Exceptions.INTERNAL_ERROR; } } this.usesXulTab = function(aXulTab) { return this._xulTab === aXulTab; } this.onDOMContentLoaded = function(aEventObj) { var newDocument = aEventObj.originalTarget; _self.resetFrameCache(); if (! _self.isTopLevelDocument(newDocument)) return; _self._tabMediator.reloadRemoteChats(newDocument); } this.isTopLevelDocument = function(aDocument) { var browsers = gBrowser.browsers; for (var i = 0; i < browsers.length; i++) if (aDocument == browsers[i].contentDocument) return true; return false; } this.onResize = function(aEventObj) { _self.resetRemoteChatPositions(); } this.resetRemoteChatPositions = function() { _self._tabHelper.setRequestCount(0); _self._tabMediator.resetRemoteChatPositions(); } this.notifyRemoteChatRemoved = function() { var currentRequests = this._tabHelper.getRequestCount(); this._tabHelper.setRequestCount( currentRequests - 1 ); } this.getFrames = function(aWindow) { var framesArray = aWindow.frames; var frameCount = aWindow.frames.length; for (var i = 0; i < frameCount; i++) { frm = framesArray[i]; getFrames(frm); } if (!frameCount) { if (aWindow.innerWidth > maxWidth) { maxWidth = aWindow.innerWidth; prevHeight = aWindow.innerHeight; largestWindow = aWindow; } else if (aWindow.innerWidth == maxWidth) { if (aWindow.innerHeight > prevHeight) { maxWidth = aWindow.innerWidth; prevHeight = aWindow.innerHeight; largestWindow = aWindow; } } } } this.expunge = function() { this._tabHelper.expunge(); this._xulTab = null; this._tabMediator = null; this._tabHelper = null; this._largestWindow = null; } }