Bug 607309 - Modify nsINavBookmarkObserver::onItemAdded to include the URI

r=mak
sr=mconnor
a=blocking
This commit is contained in:
Shawn Wilsher 2010-10-26 17:20:53 -05:00
parent af8a57e9c6
commit 4e205a3fb7
19 changed files with 66 additions and 39 deletions

View File

@ -972,8 +972,9 @@ var PlacesStarButton = {
this.updateState();
this._batching = false;
},
onItemAdded: function PSB_onItemAdded(aItemId, aFolder, aIndex, aItemType) {
onItemAdded: function PSB_onItemAdded(aItemId, aFolder, aIndex, aItemType,
aURI) {
if (!this._batching && !this._starred)
this.updateState();
},

View File

@ -1161,7 +1161,8 @@ var gEditItemOverlay = {
this._folderMenuList.selectedItem = folderItem;
},
onItemAdded: function EIO_onItemAdded(aItemId, aFolder, aIndex, aItemType) {
onItemAdded: function EIO_onItemAdded(aItemId, aFolder, aIndex, aItemType,
aURI) {
this._lastNewItem = aItemId;
},

View File

@ -204,7 +204,7 @@ var bookmarksObserver = {
},
// nsINavBookmarkObserver
onItemAdded: function PSB_onItemAdded(aItemId, aFolderId, aIndex) {
onItemAdded: function PSB_onItemAdded(aItemId, aFolderId, aIndex, aURI) {
var node = null;
var index = null;
[node, index] = getNodeForTreeItem(aItemId, gLibrary.PlacesOrganizer._places);

View File

@ -223,7 +223,7 @@ var bookmarksObserver = {
// nsINavBookmarkObserver
onItemAdded: function PSB_onItemAdded(aItemId, aFolderId, aIndex,
aItemType) {
aItemType, aURI) {
var views = getViewsForFolder(aFolderId);
ok(views.length > 0, "Found affected views (" + views.length + "): " + views);

View File

@ -53,7 +53,7 @@ var observer = {
onEndUpdateBatch: function() {
this._endUpdateBatch = true;
},
onItemAdded: function(id, folder, index, itemType) {
onItemAdded: function(id, folder, index, itemType, uri) {
this._itemAddedId = id;
this._itemAddedParent = folder;
this._itemAddedIndex = index;

View File

@ -394,7 +394,7 @@ Bookmark.prototype = {
onEndUpdateBatch : function bm_oeub() {
},
onItemAdded : function bm_oia(aId, aFolder, aIndex) {
onItemAdded : function bm_oia(aId, aFolder, aIndex, aItemType, aURI) {
// bookmark object doesn't exist at this point
},
@ -547,7 +547,7 @@ BookmarkFolder.prototype = {
onEndUpdateBatch : function bmf_oeub() {
},
onItemAdded : function bmf_oia(aId, aFolder, aIndex) {
onItemAdded : function bmf_oia(aId, aFolder, aIndex, aItemType, aURI) {
// handle root folder events
if (!this._parent)
this._events.dispatch("add", aId);

View File

@ -49,8 +49,7 @@ interface nsINavHistoryBatchCallback;
/**
* Observer for bookmark changes.
*/
[scriptable, uuid(1f7e9032-b2c0-4561-b35b-94ba3f8344e2)]
[scriptable, uuid(76f892d9-31ea-4061-b38c-6b40fad57e9d)]
interface nsINavBookmarkObserver : nsISupports
{
/**
@ -80,9 +79,13 @@ interface nsINavBookmarkObserver : nsISupports
* @param aItemType
* The type of the item that was added (one of the TYPE_* constants
* defined above).
* @param aURI
* The URI of the item that was added when aItemType is TYPE_BOOKMARK,
* null otherwise.
*/
void onItemAdded(in long long aItemId, in long long aParentId,
in long aIndex, in unsigned short aItemType);
in long aIndex, in unsigned short aItemType,
in nsIURI aURI);
/**
* Notify this observer that an item is about to be removed. Called before

View File

@ -1015,7 +1015,8 @@ nsNavBookmarks::InsertBookmark(PRInt64 aFolder,
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
nsINavBookmarkObserver,
OnItemAdded(*aNewBookmarkId, aFolder, index, TYPE_BOOKMARK));
OnItemAdded(*aNewBookmarkId, aFolder, index, TYPE_BOOKMARK,
aURI));
// If the bookmark has been added to a tag container, notify all
// bookmark-folder result nodes which contain a bookmark for the new
@ -1280,7 +1281,8 @@ nsNavBookmarks::CreateContainerWithID(PRInt64 aItemId,
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
nsINavBookmarkObserver,
OnItemAdded(*aNewFolder, aParent, index, containerType));
OnItemAdded(*aNewFolder, aParent, index, containerType,
nsnull));
*aIndex = index;
return NS_OK;
@ -1326,7 +1328,8 @@ nsNavBookmarks::InsertSeparator(PRInt64 aParent,
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
nsINavBookmarkObserver,
OnItemAdded(*aNewItemId, aParent, index, TYPE_SEPARATOR));
OnItemAdded(*aNewItemId, aParent, index, TYPE_SEPARATOR,
nsnull));
return NS_OK;
}

View File

@ -3106,7 +3106,8 @@ NS_IMETHODIMP
nsNavHistoryQueryResultNode::OnItemAdded(PRInt64 aItemId,
PRInt64 aFolder,
PRInt32 aIndex,
PRUint16 aItemType)
PRUint16 aItemType,
nsIURI* aURI)
{
if (aItemType == nsINavBookmarksService::TYPE_BOOKMARK &&
mLiveUpdate == QUERYUPDATE_COMPLEX_WITH_BOOKMARKS)
@ -3804,7 +3805,8 @@ NS_IMETHODIMP
nsNavHistoryFolderResultNode::OnItemAdded(PRInt64 aItemId,
PRInt64 aParentFolder,
PRInt32 aIndex,
PRUint16 aItemType)
PRUint16 aItemType,
nsIURI* aURI)
{
NS_ASSERTION(aParentFolder == mItemId, "Got wrong bookmark update");
@ -3837,11 +3839,9 @@ nsNavHistoryFolderResultNode::OnItemAdded(PRInt64 aItemId,
// in results and views.
PRBool isQuery = PR_FALSE;
if (aItemType == nsINavBookmarksService::TYPE_BOOKMARK) {
nsCOMPtr<nsIURI> itemURI;
rv = bookmarks->GetBookmarkURI(aItemId, getter_AddRefs(itemURI));
NS_ENSURE_SUCCESS(rv, rv);
NS_ASSERTION(aURI, "Got a null URI when we are a bookmark?!");
nsCAutoString itemURISpec;
rv = itemURI->GetSpec(itemURISpec);
rv = aURI->GetSpec(itemURISpec);
NS_ENSURE_SUCCESS(rv, rv);
isQuery = IsQueryURI(itemURISpec);
}
@ -3851,7 +3851,7 @@ nsNavHistoryFolderResultNode::OnItemAdded(PRInt64 aItemId,
// don't update items when we aren't displaying them, but we still need
// to adjust bookmark indices to account for the insertion
ReindexRange(aIndex, PR_INT32_MAX, 1);
return NS_OK;
return NS_OK;
}
if (!StartIncrementalUpdate())
@ -4157,8 +4157,18 @@ nsNavHistoryFolderResultNode::OnItemMoved(PRInt64 aItemId, PRInt64 aOldParent,
// moving between two different folders, just do a remove and an add
if (aOldParent == mItemId)
OnItemRemoved(aItemId, aOldParent, aOldIndex, aItemType);
if (aNewParent == mItemId)
OnItemAdded(aItemId, aNewParent, aNewIndex, aItemType);
if (aNewParent == mItemId) {
nsCOMPtr<nsIURI> itemURI;
if (aItemType == nsINavBookmarksService::TYPE_BOOKMARK) {
nsNavBookmarks* bookmarks = nsNavBookmarks::GetBookmarksService();
NS_ENSURE_TRUE(bookmarks, NS_ERROR_OUT_OF_MEMORY);
nsresult rv =
bookmarks->GetBookmarkURI(aItemId, getter_AddRefs(itemURI));
NS_ENSURE_SUCCESS(rv, rv);
}
OnItemAdded(aItemId, aNewParent, aNewIndex, aItemType, itemURI);
}
}
return NS_OK;
}
@ -4616,13 +4626,18 @@ NS_IMETHODIMP
nsNavHistoryResult::OnItemAdded(PRInt64 aItemId,
PRInt64 aParentId,
PRInt32 aIndex,
PRUint16 aItemType)
PRUint16 aItemType,
nsIURI* aURI)
{
ENUMERATE_BOOKMARK_FOLDER_OBSERVERS(aParentId,
OnItemAdded(aItemId, aParentId, aIndex, aItemType));
ENUMERATE_HISTORY_OBSERVERS(OnItemAdded(aItemId, aParentId, aIndex, aItemType));
ENUMERATE_ALL_BOOKMARKS_OBSERVERS(OnItemAdded(aItemId, aParentId, aIndex,
aItemType));
OnItemAdded(aItemId, aParentId, aIndex, aItemType, aURI)
);
ENUMERATE_HISTORY_OBSERVERS(
OnItemAdded(aItemId, aParentId, aIndex, aItemType, aURI)
);
ENUMERATE_ALL_BOOKMARKS_OBSERVERS(
OnItemAdded(aItemId, aParentId, aIndex, aItemType, aURI)
);
return NS_OK;
}

View File

@ -173,7 +173,7 @@ nsPlacesDBFlush.prototype = {
this._flushWithQueries([kQuerySyncPlacesId, kQuerySyncHistoryVisitsId]);
},
onItemAdded: function(aItemId, aParentId, aIndex, aItemType)
onItemAdded: function(aItemId, aParentId, aIndex, aItemType, aURI)
{
// Sync only if we added a TYPE_BOOKMARK item. Note, we want to run the
// least amount of queries as possible here for performance reasons.

View File

@ -400,7 +400,7 @@ TaggingService.prototype = {
this._inBatch = false;
},
onItemAdded: function(aItemId, aFolderId, aIndex, aItemType) {
onItemAdded: function(aItemId, aFolderId, aIndex, aItemType, aURI) {
// Nothing to do if this is not a tag.
if (aFolderId != PlacesUtils.tagsFolderId ||
aItemType != PlacesUtils.bookmarks.TYPE_FOLDER)

View File

@ -47,7 +47,7 @@ try {
var observer = {
onBeginUpdateBatch: function() {},
onEndUpdateBatch: function() {},
onItemAdded: function(id, folder, index, itemType) {
onItemAdded: function(id, folder, index, itemType, uri) {
this._itemAddedId = id;
this._itemAddedParent = folder;
this._itemAddedIndex = index;

View File

@ -50,10 +50,11 @@ let bookmarksObserver = {
onEndUpdateBatch: function() {
this._endUpdateBatch = true;
},
onItemAdded: function(id, folder, index, itemType) {
onItemAdded: function(id, folder, index, itemType, uri) {
this._itemAddedId = id;
this._itemAddedParent = folder;
this._itemAddedIndex = index;
this._itemAddedURI = uri;
},
onBeforeItemRemoved: function(){},
onItemRemoved: function(id, folder, index, itemType) {
@ -128,6 +129,7 @@ function run_test() {
do_check_eq(bookmarksObserver._itemAddedId, testRoot);
do_check_eq(bookmarksObserver._itemAddedParent, root);
do_check_eq(bookmarksObserver._itemAddedIndex, bmStartIndex);
do_check_eq(bookmarksObserver._itemAddedURI, null);
let testStartIndex = 0;
// test getItemIndex for folders
@ -136,7 +138,7 @@ function run_test() {
// test getItemType for folders
do_check_eq(bs.getItemType(testRoot), bs.TYPE_FOLDER);
// insert a bookmark
// insert a bookmark.
// the time before we insert, in microseconds
let beforeInsert = Date.now() * 1000;
do_check_true(beforeInsert > 0);
@ -146,6 +148,7 @@ function run_test() {
do_check_eq(bookmarksObserver._itemAddedId, newId);
do_check_eq(bookmarksObserver._itemAddedParent, testRoot);
do_check_eq(bookmarksObserver._itemAddedIndex, testStartIndex);
do_check_true(bookmarksObserver._itemAddedURI.equals(uri("http://google.com/")));
do_check_eq(bs.getBookmarkURI(newId).spec, "http://google.com/");
let dateAdded = bs.getItemDateAdded(newId);
@ -210,6 +213,7 @@ function run_test() {
do_check_eq(bookmarksObserver._itemAddedId, workFolder);
do_check_eq(bookmarksObserver._itemAddedParent, testRoot);
do_check_eq(bookmarksObserver._itemAddedIndex, 0);
do_check_eq(bookmarksObserver._itemAddedURI, null);
do_check_eq(bs.getItemTitle(workFolder), "Work");
bs.setItemTitle(workFolder, "Work #");

View File

@ -63,7 +63,7 @@ Observer.prototype =
},
onEndUpdateBatch: function() {
},
onItemAdded: function(id, folder, index) {
onItemAdded: function(id, folder, index, itemType, uri) {
},
onBeforeItemRemoved: function(id) {
this.removedId = id;

View File

@ -69,7 +69,7 @@ var observer =
// nsINavBookmarkObserver
onBeginUpdateBatch: function(){},
onEndUpdateBatch: function(){},
onItemAdded: function(bookmarkId, folderId, index, itemType) {
onItemAdded: function(bookmarkId, folderId, index, itemType, uri) {
if ( status == 0 ) {
runTest1( folderId );
} else {

View File

@ -51,7 +51,7 @@ var observer =
onBeginUpdateBatch: function(){},
onEndUpdateBatch: function(){
},
onItemAdded: function(itemId, folder, index, itemType) {
onItemAdded: function(itemId, folder, index, itemType, uri) {
var title = bmsvc.getItemTitle(itemId);
if (title == "The First Title") {
ok(true, "Item with title loaded");

View File

@ -65,7 +65,7 @@ DummyObserver.prototype = {
// bookmark observer
//onBeginUpdateBatch: function() {},
//onEndUpdateBatch: function() {},
onItemAdded: function(aItemId, aParentId, aIndex, aItemType) {
onItemAdded: function(aItemId, aParentId, aIndex, aItemType, aURI) {
let os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
os.notifyObservers(null, "dummy-observer-item-added", null);

View File

@ -59,7 +59,7 @@ function run_test()
// Now check to make sure it gets added with the right id
bs.addObserver({
onItemAdded: function(aItemId, aFolder, aIndex)
onItemAdded: function(aItemId, aFolder, aIndex, aItemType, aURI)
{
do_check_eq(aItemId, id);
do_check_eq(bs.getItemTitle(aItemId), TITLE);

View File

@ -51,7 +51,7 @@
var observer = {
onBeginUpdateBatch: function() {},
onEndUpdateBatch: function() {},
onItemAdded: function(id, folder, index, itemType) {
onItemAdded: function(id, folder, index, itemType, uri) {
do_check_true(id > 0);
},
onBeforeItemRemoved: function() {},