michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: const Ci = Components.interfaces; michael@0: const Cc = Components.classes; michael@0: michael@0: Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: michael@0: const APPLICATION_CID = Components.ID("fe74cf80-aa2d-11db-abbd-0800200c9a66"); michael@0: const APPLICATION_CONTRACTID = "@mozilla.org/fuel/application;1"; michael@0: michael@0: //================================================= michael@0: // Singleton that holds services and utilities michael@0: var Utilities = { michael@0: get bookmarks() { michael@0: let bookmarks = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. michael@0: getService(Ci.nsINavBookmarksService); michael@0: this.__defineGetter__("bookmarks", function() bookmarks); michael@0: return this.bookmarks; michael@0: }, michael@0: michael@0: get bookmarksObserver() { michael@0: let bookmarksObserver = new BookmarksObserver(); michael@0: this.__defineGetter__("bookmarksObserver", function() bookmarksObserver); michael@0: return this.bookmarksObserver; michael@0: }, michael@0: michael@0: get annotations() { michael@0: let annotations = Cc["@mozilla.org/browser/annotation-service;1"]. michael@0: getService(Ci.nsIAnnotationService); michael@0: this.__defineGetter__("annotations", function() annotations); michael@0: return this.annotations; michael@0: }, michael@0: michael@0: get history() { michael@0: let history = Cc["@mozilla.org/browser/nav-history-service;1"]. michael@0: getService(Ci.nsINavHistoryService); michael@0: this.__defineGetter__("history", function() history); michael@0: return this.history; michael@0: }, michael@0: michael@0: get windowMediator() { michael@0: let windowMediator = Cc["@mozilla.org/appshell/window-mediator;1"]. michael@0: getService(Ci.nsIWindowMediator); michael@0: this.__defineGetter__("windowMediator", function() windowMediator); michael@0: return this.windowMediator; michael@0: }, michael@0: michael@0: makeURI: function fuelutil_makeURI(aSpec) { michael@0: if (!aSpec) michael@0: return null; michael@0: var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); michael@0: return ios.newURI(aSpec, null, null); michael@0: }, michael@0: michael@0: free: function fuelutil_free() { michael@0: delete this.bookmarks; michael@0: delete this.bookmarksObserver; michael@0: delete this.annotations; michael@0: delete this.history; michael@0: delete this.windowMediator; michael@0: } michael@0: }; michael@0: michael@0: michael@0: //================================================= michael@0: // Window implementation michael@0: michael@0: var fuelWindowMap = new WeakMap(); michael@0: function getWindow(aWindow) { michael@0: let fuelWindow = fuelWindowMap.get(aWindow); michael@0: if (!fuelWindow) { michael@0: fuelWindow = new Window(aWindow); michael@0: fuelWindowMap.set(aWindow, fuelWindow); michael@0: } michael@0: return fuelWindow; michael@0: } michael@0: michael@0: // Don't call new Window() directly; use getWindow instead. michael@0: function Window(aWindow) { michael@0: this._window = aWindow; michael@0: this._events = new Events(); michael@0: michael@0: this._watch("TabOpen"); michael@0: this._watch("TabMove"); michael@0: this._watch("TabClose"); michael@0: this._watch("TabSelect"); michael@0: } michael@0: michael@0: Window.prototype = { michael@0: get events() { michael@0: return this._events; michael@0: }, michael@0: michael@0: get _tabbrowser() { michael@0: return this._window.getBrowser(); michael@0: }, michael@0: michael@0: /* michael@0: * Helper used to setup event handlers on the XBL element. Note that the events michael@0: * are actually dispatched to tabs, so we capture them. michael@0: */ michael@0: _watch: function win_watch(aType) { michael@0: this._tabbrowser.tabContainer.addEventListener(aType, this, michael@0: /* useCapture = */ true); michael@0: }, michael@0: michael@0: handleEvent: function win_handleEvent(aEvent) { michael@0: this._events.dispatch(aEvent.type, getBrowserTab(this, aEvent.originalTarget.linkedBrowser)); michael@0: }, michael@0: michael@0: get tabs() { michael@0: var tabs = []; michael@0: var browsers = this._tabbrowser.browsers; michael@0: for (var i=0; i getWindow(Utilities.windowMediator.getMostRecentWindow("navigator:browser")), michael@0: enumerable: true, michael@0: configurable: true michael@0: }); michael@0: michael@0: }; michael@0: michael@0: // set the proto, defined in extApplication.js michael@0: ApplicationPrototype.prototype = extApplication.prototype; michael@0: michael@0: Application.prototype = new ApplicationPrototype(); michael@0: michael@0: this.NSGetFactory = XPCOMUtils.generateNSGetFactory([Application]); michael@0: