/* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is FUEL. * * The Initial Developer of the Original Code is Mozilla Foundation. * Portions created by the Initial Developer are Copyright (C) 2006 * the Initial Developer. All Rights Reserved. * * Contributor(s): * Mark Finkle (Original Author) * John Resig (Original Author) * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), * in which case the provisions of the GPL or the LGPL are applicable instead * of those above. If you wish to allow use of your version of this file only * under the terms of either the GPL or the LGPL, and not to allow others to * use your version of this file under the terms of the MPL, indicate your * decision by deleting the provisions above and replace them with the notice * and other provisions required by the GPL or the LGPL. If you do not delete * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ const Ci = Components.interfaces; const Cc = Components.classes; Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); const APPLICATION_CID = Components.ID("fe74cf80-aa2d-11db-abbd-0800200c9a66"); const APPLICATION_CONTRACTID = "@mozilla.org/fuel/application;1"; //================================================= // Singleton that holds services and utilities var Utilities = { get bookmarks() { let bookmarks = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. getService(Ci.nsINavBookmarksService); this.__defineGetter__("bookmarks", function() bookmarks); return this.bookmarks; }, get livemarks() { let livemarks = Cc["@mozilla.org/browser/livemark-service;2"]. getService(Ci.nsILivemarkService); this.__defineGetter__("livemarks", function() livemarks); return this.livemarks; }, get annotations() { let annotations = Cc["@mozilla.org/browser/annotation-service;1"]. getService(Ci.nsIAnnotationService); this.__defineGetter__("annotations", function() annotations); return this.annotations; }, get history() { let history = Cc["@mozilla.org/browser/nav-history-service;1"]. getService(Ci.nsINavHistoryService); this.__defineGetter__("history", function() history); return this.history; }, get windowMediator() { let windowMediator = Cc["@mozilla.org/appshell/window-mediator;1"]. getService(Ci.nsIWindowMediator); this.__defineGetter__("windowMediator", function() windowMediator); return this.windowMediator; }, makeURI : function(aSpec) { if (!aSpec) return null; var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); return ios.newURI(aSpec, null, null); }, free : function() { delete this.bookmarks; delete this.livemarks delete this.annotations; delete this.history; delete this.windowMediator; } }; //================================================= // Window implementation function Window(aWindow) { this._window = aWindow; this._tabbrowser = aWindow.getBrowser(); this._events = new Events(); this._cleanup = {}; this._watch("TabOpen"); this._watch("TabMove"); this._watch("TabClose"); this._watch("TabSelect"); var self = this; gShutdown.push(function() { self._shutdown(); }); } Window.prototype = { get events() { return this._events; }, /* * Helper used to setup event handlers on the XBL element. Note that the events * are actually dispatched to tabs, so we capture them. */ _watch : function win_watch(aType) { var self = this; this._tabbrowser.tabContainer.addEventListener(aType, this._cleanup[aType] = function(e){ self._event(e); }, true); }, /* * Helper event callback used to redirect events made on the XBL element */ _event : function win_event(aEvent) { this._events.dispatch(aEvent.type, new BrowserTab(this, aEvent.originalTarget.linkedBrowser)); }, get tabs() { var tabs = []; var browsers = this._tabbrowser.browsers; for (var i=0; i