b=421235, r=gavin, a1.9=dsicore. Add new bookmark roots to FUEL

This commit is contained in:
mark.finkle@gmail.com 2008-03-16 07:46:13 -07:00
parent e818e971a0
commit 4aa97befa7
4 changed files with 152 additions and 45 deletions

View File

@ -72,7 +72,7 @@ var testData = [
new keywordResult(null, null)],
[new bmKeywordData("bmpost-noparam", "http://bmpost-noparam/", "not_a=param", "foo8"),
new keywordResult(null, null)],
// Test escaping (%s = escaped, %S = raw)
// UTF-8 default
[new bmKeywordData("bmget-escaping", "http://bmget/?esc=%s&raw=%S", null, "foé"),
@ -108,7 +108,7 @@ var gAddedEngines = [];
function setupKeywords() {
var searchService = Cc["@mozilla.org/browser/search-service;1"].
getService(Ci.nsIBrowserSearchService);
gBMFolder = Application.bookmarks.addFolder("keyword-test");
gBMFolder = Application.bookmarks.menu.addFolder("keyword-test");
for each (var item in testData) {
var data = item[0];
if (data instanceof bmKeywordData) {
@ -117,7 +117,7 @@ function setupKeywords() {
if (data.postData)
bm.annotations.set("bookmarkProperties/POSTData", data.postData, Ci.nsIAnnotationService.EXPIRE_SESSION);
}
if (data instanceof searchKeywordData) {
searchService.addEngineWithDetails(data.keyword, "", data.keyword, "", data.method, data.uri.spec);
var addedEngine = searchService.getEngineByName(data.keyword);

View File

@ -51,7 +51,7 @@ interface fuelIEventItem : nsISupports
* Cancels the event if it is cancelable.
*/
void preventDefault();
};
};
/**
@ -61,14 +61,14 @@ interface fuelIEventItem : nsISupports
interface fuelIEventListener : nsISupports
{
/**
* This method is called whenever an event occurs of the type for which
* This method is called whenever an event occurs of the type for which
* the fuelIEventListener interface was registered.
*
* @param aEvent
* The fuelIEventItem associated with the event.
*/
void handleEvent(in fuelIEventItem aEvent);
};
};
/**
@ -101,7 +101,7 @@ interface fuelIEvents : nsISupports
* The reference to a listener
*/
void removeListener(in AString aEvent, in fuelIEventListener aListener);
};
};
/**
@ -119,18 +119,18 @@ interface fuelIPreferenceBranch : nsISupports
* The name of the branch root.
*/
readonly attribute AString root;
/**
* Array of fuelIPreference listing all preferences in this branch.
*/
readonly attribute nsIVariant all;
/**
* The events object for the preferences
* supports: "change"
*/
readonly attribute fuelIEvents events;
/**
* Check to see if a preference exists.
* @param aName
@ -138,7 +138,7 @@ interface fuelIPreferenceBranch : nsISupports
* @returns true if the preference exists, false if not
*/
boolean has(in AString aName);
/**
* Gets an object representing a preference
* @param aName
@ -146,7 +146,7 @@ interface fuelIPreferenceBranch : nsISupports
* @returns a preference object, or null if the preference does not exist
*/
fuelIPreference get(in AString aName);
/**
* Gets the value of a preference. Returns a default value if
* the preference does not exist.
@ -185,38 +185,38 @@ interface fuelIPreference : nsISupports
* The name of the preference.
*/
readonly attribute AString name;
/**
* A string representing the type of preference (String, Boolean, or Number).
*/
readonly attribute AString type;
/**
* Get/Set the value of the preference.
*/
attribute nsIVariant value;
/**
* Get the locked state of the preference. Set to a boolean value to (un)lock it.
*/
attribute boolean locked;
/**
* Check if a preference has been modified by the user, or not.
*/
readonly attribute boolean modified;
/**
* The preference branch that contains this preference.
*/
readonly attribute fuelIPreferenceBranch branch;
/**
* The events object for this preference.
* supports: "change"
*/
readonly attribute fuelIEvents events;
/**
* Resets a preference back to its default values.
*/
@ -265,7 +265,7 @@ interface fuelISessionStorage : nsISupports
* exists with the given name.
*/
nsIVariant get(in AString aName, in nsIVariant aDefaultValue);
};
};
/**
@ -283,12 +283,12 @@ interface fuelIExtension : nsISupports
* The name of the extension.
*/
readonly attribute AString name;
/**
* Check if the extension is currently enabled, or not.
*/
readonly attribute boolean enabled;
/**
* The version number of the extension.
*/
@ -315,7 +315,7 @@ interface fuelIExtension : nsISupports
* supports: "uninstall"
*/
readonly attribute fuelIEvents events;
};
};
/**
@ -346,7 +346,7 @@ interface fuelIExtensions : nsISupports
* with the given id.
*/
fuelIExtension get(in AString aId);
};
};
/**
@ -459,7 +459,7 @@ interface fuelIBookmark : nsISupports
* delete a bookmark or separator
*/
void remove();
};
};
/**
@ -540,6 +540,35 @@ interface fuelIBookmarkFolder : nsISupports
};
/**
* Interface representing a container for bookmark roots. Roots
* are the top level parents for the various types of bookmarks in the system.
*/
[scriptable, uuid(c9a80870-eb3c-11dc-95ff-0800200c9a66)]
interface fuelIBookmarkRoots : nsISupports
{
/**
* The folder for the 'bookmarks menu' root.
*/
readonly attribute fuelIBookmarkFolder menu;
/**
* The folder for the 'personal toolbar' root.
*/
readonly attribute fuelIBookmarkFolder toolbar;
/**
* The folder for the 'tags' root.
*/
readonly attribute fuelIBookmarkFolder tags;
/**
* The folder for the 'unfiled bookmarks' root.
*/
readonly attribute fuelIBookmarkFolder unfiled;
};
/**
* Interface representing a browser window.
*/
@ -550,19 +579,19 @@ 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"
@ -580,7 +609,7 @@ interface fuelIBrowserTab : nsISupports
* The current uri of this tab.
*/
readonly attribute nsIURI uri;
/**
* The current index of this tab in the browser window.
*/
@ -590,7 +619,7 @@ interface fuelIBrowserTab : nsISupports
* The browser window that is holding the tab.
*/
readonly attribute fuelIWindow window;
/**
* The content document of the browser tab.
*/
@ -601,7 +630,7 @@ interface fuelIBrowserTab : nsISupports
* supports: "load"
*/
readonly attribute fuelIEvents events;
/**
* Load a new URI into this browser tab.
* @param aURI
@ -613,20 +642,20 @@ interface fuelIBrowserTab : nsISupports
* 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.
*/
@ -649,12 +678,12 @@ interface fuelIApplication : nsISupports
* The name of the application.
*/
readonly attribute AString name;
/**
* The version number of the application.
*/
readonly attribute AString version;
/**
* The console object for the application.
*/
@ -685,16 +714,17 @@ interface fuelIApplication : nsISupports
/**
* The root bookmarks object for the application.
* Contains all the bookmark roots in the system.
*/
readonly attribute fuelIBookmarkFolder bookmarks;
readonly attribute fuelIBookmarkRoots bookmarks;
/**
* An array of browser windows within the application.
*/
readonly attribute nsIVariant windows;
/**
* The currently active browser window.
*/
readonly attribute fuelIWindow activeWindow;
};
};

View File

@ -959,9 +959,6 @@ Bookmark.prototype = {
// BookmarkFolder implementation
function BookmarkFolder(aId, aParent) {
this._id = aId;
if (this._id == null)
this._id = Utilities.bookmarks.bookmarksMenuFolder;
this._parent = aParent;
this._annotations = new Annotations(this._id);
@ -1121,6 +1118,53 @@ BookmarkFolder.prototype = {
QueryInterface : XPCOMUtils.generateQI([Ci.fuelIBookmarkFolder, Ci.nsINavBookmarkObserver])
};
//=================================================
// BookmarkRoots implementation
function BookmarkRoots() {
var self = this;
gShutdown.push(function() { self._shutdown(); });
}
BookmarkRoots.prototype = {
_shutdown : function bmr_shutdown() {
this._menu = null;
this._toolbar = null;
this._tags = null;
this._unfiled = null;
},
get menu() {
if (!this._menu)
this._menu = new BookmarkFolder(Utilities.bookmarks.bookmarksMenuFolder, null);
return this._menu;
},
get toolbar() {
if (!this._toolbar)
this._toolbar = new BookmarkFolder(Utilities.bookmarks.toolbarFolder, null);
return this._toolbar;
},
get tags() {
if (!this._tags)
this._tags = new BookmarkFolder(Utilities.bookmarks.tagsFolder, null);
return this._tags;
},
get unfiled() {
if (!this._unfiled)
this._unfiled = new BookmarkFolder(Utilities.bookmarks.unfiledBookmarksFolder, null);
return this._unfiled;
},
QueryInterface : XPCOMUtils.generateQI([Ci.fuelIBookmarkRoots])
};
//=================================================
// Factory - Treat Application as a singleton
// XXX This is required, because we're registered for the 'JavaScript global
@ -1285,7 +1329,7 @@ Application.prototype = {
get bookmarks() {
if (this._bookmarks == null)
this._bookmarks = new BookmarkFolder(null, null);
this._bookmarks = new BookmarkRoots();
return this._bookmarks;
},

View File

@ -10,7 +10,40 @@ function url(spec) {
}
function test() {
var root = Application.bookmarks;
// Some very basic tests on the tags root
var tags = Application.bookmarks.tags;
ok(tags, "Check access to bookmark tags root");
ok(!tags.parent, "Check tags parent (should be null)");
//----------------------------------------------
// Some very basic tests on the unfiled root
var unfiled = Application.bookmarks.unfiled;
ok(unfiled, "Check access to bookmark unfiled root");
ok(!unfiled.parent, "Check unfiled parent (should be null)");
//----------------------------------------------
// Some basic tests on the toolbar root
var toolbar = Application.bookmarks.toolbar;
ok(toolbar, "Check access to bookmark toolbar root");
ok(!toolbar.parent, "Check toolbar parent (should be null)");
var toolbarKidCount = toolbar.children.length;
// test adding folders
var testFolderToolbar = toolbar.addFolder("FUEL in Toolbar");
ok(testFolderToolbar, "Check folder creation");
is(testFolderToolbar.type, "folder", "Check 'folder.type' after creation");
ok(testFolderToolbar.parent, "Check parent after folder creation");
toolbarKidCount++;
is(toolbar.children.length, toolbarKidCount, "Check toolbar folder child count after adding a child folder");
//----------------------------------------------
// Main testing is done on the bookmarks menu root
var root = Application.bookmarks.menu;
ok(root, "Check access to bookmark root");
ok(!root.parent, "Check root parent (should be null)");