diff --git a/browser/fuel/public/fuelIApplication.idl b/browser/fuel/public/fuelIApplication.idl index 089fbf39e35..a53c5e95a2e 100644 --- a/browser/fuel/public/fuelIApplication.idl +++ b/browser/fuel/public/fuelIApplication.idl @@ -1,7 +1,12 @@ #include "nsISupports.idl" -#include "nsIVariant.idl" + +interface nsIVariant; +interface nsIURI; +interface nsIDOMHTMLDocument; interface fuelIPreference; +interface fuelIBookmarkFolder; +interface fuelIBrowserTab; /** * Interface that gives simplified access to the console @@ -263,9 +268,9 @@ interface fuelISessionStorage : nsISupports }; - /** - * Interface representing an extension - */ +/** + * Interface representing an extension + */ [scriptable, uuid(ea563b60-aa5a-11db-abbd-0800200c9a66)] interface fuelIExtension : nsISupports { @@ -339,6 +344,291 @@ interface fuelIExtensions : nsISupports }; +/** + * Interface representing a collection of annotations associated + * with a bookmark or bookmark folder. + */ +[scriptable, uuid(335c9292-91a1-4ca0-ad0b-07d5f63ed6cd)] +interface fuelIAnnotations : nsISupports +{ + /** + * Array of the annotation names associated with the owning item + */ + readonly attribute nsIVariant names; + + /** + * Determines if an annotation exists with the given name. + * @param aName + * The name of the annotation + * @returns true if an annotation exists with the given name, + * false otherwise. + */ + boolean has(in AString aName); + + /** + * Gets the value of an annotation with the given name. + * @param aName + * The name of the annotation + * @returns A variant containing the value of the annotation. Supports + * string, boolean and number. + */ + nsIVariant get(in AString aName); + + /** + * Sets the value of an annotation with the given name. + * @param aName + * The name of the annotation + * @param aValue + * The new value of the annotation. Supports string, boolean + * and number + * @param aExpiration + * The expiration policy for the annotation. + * See nsIAnnotationService. + */ + void set(in AString aName, in nsIVariant aValue, in PRInt32 aExpiration); + + /** + * Removes the named annotation from the owner item. + * @param aName + * The name of annotation. + */ + void remove(in AString aName); +}; + + +/** + * Interface representing a bookmark item. + */ +[scriptable, uuid(808585b6-7568-4b26-8c62-545221bf2b8c)] +interface fuelIBookmark : nsISupports +{ + /** + * The id of the bookmark. + */ + readonly attribute long long id; + + /** + * The title of the bookmark. + */ + attribute AString title; + + /** + * The uri of the bookmark. + */ + attribute nsIURI uri; + + /** + * The description of the bookmark. + */ + attribute AString description; + + /** + * The keyword associated with the bookmark. + */ + attribute AString keyword; + + /** + * The type of the bookmark. + * values: "bookmark", "separator" + */ + readonly attribute AString type; + + /** + * The parent folder of the bookmark. + */ + attribute fuelIBookmarkFolder parent; + + /** + * The annotations object for the bookmark. + */ + readonly attribute fuelIAnnotations annotations; + + /** + * The events object for the bookmark. + * supports: "remove", "change", "visit", "move" + */ + readonly attribute fuelIEvents events; + + /** + * Removes the item from the parent folder. Used to + * delete a bookmark or separator + */ + void remove(); +}; + + +/** + * Interface representing a bookmark folder. Folders + * can hold bookmarks, separators and other folders. + */ +[scriptable, uuid(9f42fe20-52de-4a55-8632-a459c7716aa0)] +interface fuelIBookmarkFolder : nsISupports +{ + /** + * The id of the folder. + */ + readonly attribute long long id; + + /** + * The title of the folder. + */ + attribute AString title; + + /** + * The description of the folder. + */ + attribute AString description; + + /** + * The type of the folder. + * values: "folder" + */ + readonly attribute AString type; + + /** + * The parent folder of the folder. + */ + attribute fuelIBookmarkFolder parent; + + /** + * The annotations object for the folder. + */ + readonly attribute fuelIAnnotations annotations; + + /** + * The events object for the folder. + * supports: "add", "addchild", "remove", "removechild", "change", "move" + */ + readonly attribute fuelIEvents events; + + /** + * Array of all bookmarks, separators and folders contained + * in this folder. + */ + readonly attribute nsIVariant children; + + /** + * Adds a new child bookmark to this folder. + * @param aTitle + * The title of bookmark. + * @param aURI + * The uri of bookmark. + */ + fuelIBookmark addBookmark(in AString aTitle, in nsIURI aURI); + + /** + * Adds a new child separator to this folder. + */ + fuelIBookmark addSeparator(); + + /** + * Adds a new child folder to this folder. + * @param aTitle + * The title of folder. + */ + fuelIBookmarkFolder addFolder(in AString aTitle); + + /** + * Removes the folder from the parent folder. + */ + void remove(); +}; + + +/** + * Interface representing a browser window. + */ +[scriptable, uuid(207edb28-eb5e-424e-a862-b0e97C8de866)] +interface fuelIWindow : nsISupports +{ + /** + * A collection of browser tabs within the browser window. + */ + readonly attribute nsIVariant tabs; + + /** + * The currently-active tab within the browser window. + */ + readonly attribute fuelIBrowserTab activeTab; + + /** + * Open a new browser tab, pointing to the specified URI. + * @param aURI + * The uri to open the browser tab to + */ + fuelIBrowserTab open(in nsIURI aURI); + + /** + * The events object for the browser window. + * supports: "TabOpen", "TabClose", "TabMove", "TabSelect" + */ + readonly attribute fuelIEvents events; +}; + +/** + * Interface representing a browser tab. + */ +[scriptable, uuid(3073ceff-777c-41ce-9ace-ab37268147c1)] +interface fuelIBrowserTab : nsISupports +{ + /** + * The current uri of this tab. + */ + readonly attribute nsIURI uri; + + /** + * The current index of this tab in the browser window. + */ + readonly attribute PRInt32 index; + + /** + * The browser window that is holding the tab. + */ + readonly attribute fuelIWindow window; + + /** + * The content document of the browser tab. + */ + readonly attribute nsIDOMHTMLDocument document; + + /** + * The events object for the browser tab. + * supports: "load" + */ + readonly attribute fuelIEvents events; + + /** + * Load a new URI into this browser tab. + * @param aURI + * The uri to load into the browser tab + */ + void load(in nsIURI aURI); + + /** + * Give focus to this browser tab, and bring it to the front. + */ + void focus(); + + /** + * Close the browser tab. This may not actually close the tab + * as script may abort the close operation. + */ + void close(); + + /** + * Moves this browser tab before another browser tab within the window. + * @param aBefore + * The tab before which the target tab will be moved + */ + void moveBefore(in fuelIBrowserTab aBefore); + + /** + * Move this browser tab to the last tab within the window. + */ + void moveToEnd(); +}; + + /** * Interface for managing and accessing the applications systems */ @@ -387,4 +677,19 @@ interface fuelIApplication : nsISupports * supports: "load", "ready", "quit", "unload" */ readonly attribute fuelIEvents events; + + /** + * The root bookmarks object for the application. + */ + readonly attribute fuelIBookmarkFolder bookmarks; + + /** + * An array of browser windows within the application. + */ + readonly attribute nsIVariant windows; + + /** + * The currently active browser window. + */ + readonly attribute fuelIWindow activeWindow; }; diff --git a/browser/fuel/src/fuelApplication.js b/browser/fuel/src/fuelApplication.js index dbf988a2045..7ae7415c3e0 100644 --- a/browser/fuel/src/fuelApplication.js +++ b/browser/fuel/src/fuelApplication.js @@ -34,12 +34,9 @@ * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ - -const nsISupports = Components.interfaces.nsISupports; -const nsIClassInfo = Components.interfaces.nsIClassInfo; -const nsIObserver = Components.interfaces.nsIObserver; -const fuelIApplication = Components.interfaces.fuelIApplication; +const Ci = Components.interfaces; +const Cc = Components.classes; //================================================= // Shutdown - used to store cleanup functions which will @@ -50,7 +47,7 @@ var gShutdown = []; // Console constructor function Console() { this._console = Components.classes["@mozilla.org/consoleservice;1"] - .getService(Components.interfaces.nsIConsoleService); + .getService(Ci.nsIConsoleService); } //================================================= @@ -62,11 +59,11 @@ Console.prototype = { open : function cs_open() { var wMediator = Components.classes["@mozilla.org/appshell/window-mediator;1"] - .getService(Components.interfaces.nsIWindowMediator); + .getService(Ci.nsIWindowMediator); var console = wMediator.getMostRecentWindow("global:console"); if (!console) { var wWatch = Components.classes["@mozilla.org/embedcomp/window-watcher;1"] - .getService(Components.interfaces.nsIWindowWatcher); + .getService(Ci.nsIWindowWatcher); wWatch.openWindow(null, "chrome://global/content/console.xul", "_blank", "chrome,dialog=no,all", cmdLine); } else { @@ -148,13 +145,6 @@ Events.prototype = { }; -//================================================= -// Preferences constants -const nsIPrefService = Components.interfaces.nsIPrefService; -const nsIPrefBranch = Components.interfaces.nsIPrefBranch; -const nsIPrefBranch2 = Components.interfaces.nsIPrefBranch2; -const nsISupportsString = Components.interfaces.nsISupportsString; - //================================================= // PreferenceBranch constructor function PreferenceBranch(aBranch) { @@ -163,13 +153,13 @@ function PreferenceBranch(aBranch) { this._root = aBranch; this._prefs = Components.classes["@mozilla.org/preferences-service;1"] - .getService(nsIPrefService); + .getService(Ci.nsIPrefService); if (aBranch) this._prefs = this._prefs.getBranch(aBranch); - this._prefs.QueryInterface(nsIPrefBranch); - this._prefs.QueryInterface(nsIPrefBranch2); + this._prefs.QueryInterface(Ci.nsIPrefBranch); + this._prefs.QueryInterface(Ci.nsIPrefBranch2); this._prefs.addObserver(this._root, this, false); this._events = new Events(); @@ -225,7 +215,7 @@ PreferenceBranch.prototype = { }, has : function prefs_has(aName) { - return (this._prefs.getPrefType(aName) != nsIPrefBranch.PREF_INVALID); + return (this._prefs.getPrefType(aName) != Ci.nsIPrefBranch.PREF_INVALID); }, get : function prefs_get(aName) { @@ -236,13 +226,13 @@ PreferenceBranch.prototype = { var type = this._prefs.getPrefType(aName); switch (type) { - case nsIPrefBranch2.PREF_STRING: - aValue = this._prefs.getComplexValue(aName, nsISupportsString).data; + case Ci.nsIPrefBranch2.PREF_STRING: + aValue = this._prefs.getComplexValue(aName, Ci.nsISupportsString).data; break; - case nsIPrefBranch2.PREF_BOOL: + case Ci.nsIPrefBranch2.PREF_BOOL: aValue = this._prefs.getBoolPref(aName); break; - case nsIPrefBranch2.PREF_INT: + case Ci.nsIPrefBranch2.PREF_INT: aValue = this._prefs.getIntPref(aName); break; } @@ -256,9 +246,9 @@ PreferenceBranch.prototype = { switch (type) { case "String": var str = Components.classes["@mozilla.org/supports-string;1"] - .createInstance(nsISupportsString); + .createInstance(Ci.nsISupportsString); str.data = aValue; - this._prefs.setComplexValue(aName, nsISupportsString, str); + this._prefs.setComplexValue(aName, Ci.nsISupportsString, str); break; case "Boolean": this._prefs.setBoolPref(aName, aValue); @@ -304,13 +294,13 @@ Preference.prototype = { var type = this._prefs.getPrefType(name); switch (type) { - case nsIPrefBranch2.PREF_STRING: + case Ci.nsIPrefBranch2.PREF_STRING: value = "String"; break; - case nsIPrefBranch2.PREF_BOOL: + case Ci.nsIPrefBranch2.PREF_BOOL: value = "Boolean"; break; - case nsIPrefBranch2.PREF_INT: + case Ci.nsIPrefBranch2.PREF_INT: value = "Number"; break; } @@ -381,10 +371,6 @@ SessionStorage.prototype = { }; -//================================================= -// Extension constants -const nsIUpdateItem = Components.interfaces.nsIUpdateItem; - //================================================= // Extension constructor function Extension(aItem) { @@ -401,7 +387,7 @@ function Extension(aItem) { } var os = Components.classes["@mozilla.org/observer-service;1"] - .getService(Components.interfaces.nsIObserverService); + .getService(Ci.nsIObserverService); os.addObserver(this, "em-action-requested", false); var self = this; @@ -409,12 +395,12 @@ function Extension(aItem) { } //================================================= -// Extensions implementation +// Extension implementation Extension.prototype = { // cleanup observer so we don't leak _shutdown: function ext_shutdown() { var os = Components.classes["@mozilla.org/observer-service;1"] - .getService(Components.interfaces.nsIObserverService); + .getService(Ci.nsIObserverService); os.removeObserver(this, "em-action-requested"); this._prefs = null; @@ -426,7 +412,7 @@ Extension.prototype = { observe: function ext_observe(aSubject, aTopic, aData) { if ((aData == "item-uninstalled") && - (aSubject instanceof nsIUpdateItem) && + (aSubject instanceof Ci.nsIUpdateItem) && (aSubject.id == this._item.id)) { this._events.dispatch("uninstall", this._item.id); @@ -467,7 +453,7 @@ Extension.prototype = { // Extensions constructor function Extensions() { this._extmgr = Components.classes["@mozilla.org/extensions/manager;1"] - .getService(Components.interfaces.nsIExtensionManager); + .getService(Ci.nsIExtensionManager); var self = this; gShutdown.push(function() { self._shutdown(); }); @@ -492,7 +478,7 @@ Extensions.prototype = { // maxVersion: "2.0" find : function exts_find(aOptions) { var retVal = []; - var items = this._extmgr.getItemList(nsIUpdateItem.TYPE_EXTENSION, {}); + var items = this._extmgr.getItemList(Ci.nsIUpdateItem.TYPE_EXTENSION, {}); for (var i = 0; i < items.length; i++) { retVal.push(new Extension(items[i])); @@ -513,6 +499,606 @@ Extensions.prototype = { } }; +//================================================= +// Singleton that holds services and utilities +var Utilities = { + _bookmarks : null, + get bookmarks() { + if (!this._bookmarks) { + this._bookmarks = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. + getService(Ci.nsINavBookmarksService); + } + return this._bookmarks; + }, + + _livemarks : null, + get livemarks() { + if (!this._livemarks) { + this._livemarks = Cc["@mozilla.org/browser/livemark-service;2"]. + getService(Ci.nsILivemarkService); + } + return this._livemarks; + }, + + _annotations : null, + get annotations() { + if (!this._annotations) { + this._annotations = Cc["@mozilla.org/browser/annotation-service;1"]. + getService(Ci.nsIAnnotationService); + } + return this._annotations; + }, + + _history : null, + get history() { + if (!this._history) { + this._history = Cc["@mozilla.org/browser/nav-history-service;1"]. + getService(Ci.nsINavHistoryService); + } + return this._history; + }, + + _windowMediator : null, + get windowMediator() { + if (!this._windowMediator) { + this._windowMediator = Cc["@mozilla.org/appshell/window-mediator;1"]. + getService(Ci.nsIWindowMediator); + } + 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() { + this._bookmarks = null; + this._livemarks = null; + this._annotations = null; + this._history = null; + this._windowMediator = null; + } +}; + + +//================================================= +// 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(aType) { + var self = this; + this._tabbrowser.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(aEvent) { + this._events.dispatch(aEvent.type, ""); + }, + + get tabs() { + var tabs = []; + var browsers = this._tabbrowser.browsers; + + for (var i=0; i + + + + + + + + + + + + + diff --git a/browser/fuel/test/test_ApplicationPrefs.xul b/browser/fuel/test/test_ApplicationPrefs.xul new file mode 100644 index 00000000000..3892fb0b847 --- /dev/null +++ b/browser/fuel/test/test_ApplicationPrefs.xul @@ -0,0 +1,181 @@ + + + + + + + + + + + + + + diff --git a/browser/fuel/test/test_ApplicationStorage.xul b/browser/fuel/test/test_ApplicationStorage.xul new file mode 100644 index 00000000000..86607a8a458 --- /dev/null +++ b/browser/fuel/test/test_ApplicationStorage.xul @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + diff --git a/browser/fuel/test/test_Bookmarks.xul b/browser/fuel/test/test_Bookmarks.xul new file mode 100644 index 00000000000..9a6ba4b99eb --- /dev/null +++ b/browser/fuel/test/test_Bookmarks.xul @@ -0,0 +1,212 @@ + + + + + + + + + + + + + + diff --git a/browser/fuel/test/test_Browser.xul b/browser/fuel/test/test_Browser.xul new file mode 100644 index 00000000000..1fe46f212d3 --- /dev/null +++ b/browser/fuel/test/test_Browser.xul @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + diff --git a/browser/fuel/test/test_ContentA.html b/browser/fuel/test/test_ContentA.html new file mode 100644 index 00000000000..e69de29bb2d diff --git a/browser/fuel/test/test_ContentB.html b/browser/fuel/test/test_ContentB.html new file mode 100644 index 00000000000..e69de29bb2d diff --git a/browser/fuel/test/test_Extensions.xul b/browser/fuel/test/test_Extensions.xul new file mode 100644 index 00000000000..d83d2257ee8 --- /dev/null +++ b/browser/fuel/test/test_Extensions.xul @@ -0,0 +1,54 @@ + + + + + + + + + + + + + +