/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ const Ci = Components.interfaces; const Cc = Components.classes; Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "Deprecated", "resource://gre/modules/Deprecated.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 bookmarksObserver() { let bookmarksObserver = new BookmarksObserver(); this.__defineGetter__("bookmarksObserver", function() bookmarksObserver); return this.bookmarksObserver; }, 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 fuelutil_makeURI(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 fuelutil_free() { delete this.bookmarks; delete this.bookmarksObserver; delete this.annotations; delete this.history; delete this.windowMediator; } }; //================================================= // Window implementation var fuelWindowMap = new WeakMap(); function getWindow(aWindow) { let fuelWindow = fuelWindowMap.get(aWindow); if (!fuelWindow) { fuelWindow = new Window(aWindow); fuelWindowMap.set(aWindow, fuelWindow); } return fuelWindow; } // Don't call new Window() directly; use getWindow instead. function Window(aWindow) { this._window = aWindow; this._events = new Events(); this._watch("TabOpen"); this._watch("TabMove"); this._watch("TabClose"); this._watch("TabSelect"); } Window.prototype = { get events() { return this._events; }, get _tabbrowser() { return this._window.getBrowser(); }, /* * 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) { this._tabbrowser.tabContainer.addEventListener(aType, this, /* useCapture = */ true); }, handleEvent: function win_handleEvent(aEvent) { this._events.dispatch(aEvent.type, getBrowserTab(this, aEvent.originalTarget.linkedBrowser)); }, get tabs() { var tabs = []; var browsers = this._tabbrowser.browsers; for (var i=0; i getWindow(Utilities.windowMediator.getMostRecentWindow("navigator:browser")), enumerable: true, configurable: true }); }; // set the proto, defined in extApplication.js ApplicationPrototype.prototype = extApplication.prototype; Application.prototype = new ApplicationPrototype(); this.NSGetFactory = XPCOMUtils.generateNSGetFactory([Application]);