Bug 1047819 - Remove unused nsIAnnotationService::copyPageAnnotations/copyItemAnnotations. r?mak
MozReview-Commit-ID: nIsuDReLoZ
--- a/toolkit/components/places/nsAnnotationService.cpp
+++ b/toolkit/components/places/nsAnnotationService.cpp
@@ -1564,191 +1564,16 @@ nsAnnotationService::RemoveItemAnnotatio
rv = statement->Execute();
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
-/**
- * @note If we use annotations for some standard items like GeckoFlags, it
- * might be a good idea to blacklist these standard annotations from this
- * copy function.
- */
-NS_IMETHODIMP
-nsAnnotationService::CopyPageAnnotations(nsIURI* aSourceURI,
- nsIURI* aDestURI,
- bool aOverwriteDest)
-{
- NS_ENSURE_ARG(aSourceURI);
- NS_ENSURE_ARG(aDestURI);
-
- mozStorageTransaction transaction(mDB->MainConn(), false);
-
- nsCOMPtr<mozIStorageStatement> sourceStmt = mDB->GetStatement(
- "SELECT h.id, n.id, n.name, a2.id "
- "FROM moz_places h "
- "JOIN moz_annos a ON a.place_id = h.id "
- "JOIN moz_anno_attributes n ON n.id = a.anno_attribute_id "
- "LEFT JOIN moz_annos a2 ON a2.place_id = "
- "(SELECT id FROM moz_places WHERE url_hash = hash(:dest_url) AND url = :dest_url) "
- "AND a2.anno_attribute_id = n.id "
- "WHERE url = :source_url"
- );
- NS_ENSURE_STATE(sourceStmt);
- mozStorageStatementScoper sourceScoper(sourceStmt);
-
- nsresult rv = URIBinder::Bind(sourceStmt, NS_LITERAL_CSTRING("source_url"), aSourceURI);
- NS_ENSURE_SUCCESS(rv, rv);
- rv = URIBinder::Bind(sourceStmt, NS_LITERAL_CSTRING("dest_url"), aDestURI);
- NS_ENSURE_SUCCESS(rv, rv);
-
- nsCOMPtr<mozIStorageStatement> copyStmt = mDB->GetStatement(
- "INSERT INTO moz_annos "
- "(place_id, anno_attribute_id, content, flags, expiration, "
- "type, dateAdded, lastModified) "
- "SELECT (SELECT id FROM moz_places WHERE url_hash = hash(:page_url) AND url = :page_url), "
- "anno_attribute_id, content, flags, expiration, type, "
- ":date, :date "
- "FROM moz_annos "
- "WHERE place_id = :page_id "
- "AND anno_attribute_id = :name_id"
- );
- NS_ENSURE_STATE(copyStmt);
- mozStorageStatementScoper copyScoper(copyStmt);
-
- bool hasResult;
- while (NS_SUCCEEDED(sourceStmt->ExecuteStep(&hasResult)) && hasResult) {
- int64_t sourcePlaceId = sourceStmt->AsInt64(0);
- int64_t annoNameID = sourceStmt->AsInt64(1);
- nsAutoCString annoName;
- rv = sourceStmt->GetUTF8String(2, annoName);
- NS_ENSURE_SUCCESS(rv, rv);
- int64_t annoExistsOnDest = sourceStmt->AsInt64(3);
-
- if (annoExistsOnDest) {
- if (!aOverwriteDest)
- continue;
- rv = RemovePageAnnotation(aDestURI, annoName);
- NS_ENSURE_SUCCESS(rv, rv);
- }
-
- // Copy the annotation.
- mozStorageStatementScoper scoper(copyStmt);
- rv = URIBinder::Bind(copyStmt, NS_LITERAL_CSTRING("page_url"), aDestURI);
- NS_ENSURE_SUCCESS(rv, rv);
- rv = copyStmt->BindInt64ByName(NS_LITERAL_CSTRING("page_id"), sourcePlaceId);
- NS_ENSURE_SUCCESS(rv, rv);
- rv = copyStmt->BindInt64ByName(NS_LITERAL_CSTRING("name_id"), annoNameID);
- NS_ENSURE_SUCCESS(rv, rv);
- rv = copyStmt->BindInt64ByName(NS_LITERAL_CSTRING("date"), PR_Now());
- NS_ENSURE_SUCCESS(rv, rv);
-
- rv = copyStmt->Execute();
- NS_ENSURE_SUCCESS(rv, rv);
-
- NOTIFY_ANNOS_OBSERVERS(OnPageAnnotationSet(aDestURI, annoName));
- }
-
- rv = transaction.Commit();
- NS_ENSURE_SUCCESS(rv, rv);
-
- return NS_OK;
-}
-
-
-NS_IMETHODIMP
-nsAnnotationService::CopyItemAnnotations(int64_t aSourceItemId,
- int64_t aDestItemId,
- bool aOverwriteDest,
- uint16_t aSource)
-{
- NS_ENSURE_ARG_MIN(aSourceItemId, 1);
- NS_ENSURE_ARG_MIN(aDestItemId, 1);
-
- mozStorageTransaction transaction(mDB->MainConn(), false);
-
- nsCOMPtr<mozIStorageStatement> sourceStmt = mDB->GetStatement(
- "SELECT n.id, n.name, a2.id "
- "FROM moz_bookmarks b "
- "JOIN moz_items_annos a ON a.item_id = b.id "
- "JOIN moz_anno_attributes n ON n.id = a.anno_attribute_id "
- "LEFT JOIN moz_items_annos a2 ON a2.item_id = :dest_item_id "
- "AND a2.anno_attribute_id = n.id "
- "WHERE b.id = :source_item_id"
- );
- NS_ENSURE_STATE(sourceStmt);
- mozStorageStatementScoper sourceScoper(sourceStmt);
-
- nsresult rv = sourceStmt->BindInt64ByName(NS_LITERAL_CSTRING("source_item_id"), aSourceItemId);
- NS_ENSURE_SUCCESS(rv, rv);
- rv = sourceStmt->BindInt64ByName(NS_LITERAL_CSTRING("dest_item_id"), aDestItemId);
- NS_ENSURE_SUCCESS(rv, rv);
-
- nsCOMPtr<mozIStorageStatement> copyStmt = mDB->GetStatement(
- "INSERT OR REPLACE INTO moz_items_annos "
- "(item_id, anno_attribute_id, content, flags, expiration, "
- "type, dateAdded, lastModified) "
- "SELECT :dest_item_id, anno_attribute_id, content, flags, expiration, "
- "type, :date, :date "
- "FROM moz_items_annos "
- "WHERE item_id = :source_item_id "
- "AND anno_attribute_id = :name_id"
- );
- NS_ENSURE_STATE(copyStmt);
- mozStorageStatementScoper copyScoper(copyStmt);
-
- bool hasResult;
- while (NS_SUCCEEDED(sourceStmt->ExecuteStep(&hasResult)) && hasResult) {
- int64_t annoNameID = sourceStmt->AsInt64(0);
- nsAutoCString annoName;
- rv = sourceStmt->GetUTF8String(1, annoName);
- NS_ENSURE_SUCCESS(rv, rv);
- int64_t annoExistsOnDest = sourceStmt->AsInt64(2);
-
- if (annoExistsOnDest) {
- if (!aOverwriteDest)
- continue;
- rv = RemoveItemAnnotation(aDestItemId, annoName, aSource);
- NS_ENSURE_SUCCESS(rv, rv);
- }
-
- // Copy the annotation.
- mozStorageStatementScoper scoper(copyStmt);
- rv = copyStmt->BindInt64ByName(NS_LITERAL_CSTRING("dest_item_id"), aDestItemId);
- NS_ENSURE_SUCCESS(rv, rv);
- rv = copyStmt->BindInt64ByName(NS_LITERAL_CSTRING("source_item_id"), aSourceItemId);
- NS_ENSURE_SUCCESS(rv, rv);
- rv = copyStmt->BindInt64ByName(NS_LITERAL_CSTRING("name_id"), annoNameID);
- NS_ENSURE_SUCCESS(rv, rv);
- rv = copyStmt->BindInt64ByName(NS_LITERAL_CSTRING("date"), PR_Now());
- NS_ENSURE_SUCCESS(rv, rv);
-
- rv = copyStmt->Execute();
- NS_ENSURE_SUCCESS(rv, rv);
-
- NOTIFY_ANNOS_OBSERVERS(OnItemAnnotationSet(aDestItemId, annoName, aSource, false));
-
- nsNavBookmarks* bookmarks = nsNavBookmarks::GetBookmarksService();
- if (bookmarks) {
- BookmarkData bookmark;
- if (NS_SUCCEEDED(bookmarks->FetchItemInfo(aDestItemId, bookmark))) {
- NotifyItemChanged(bookmark, annoName, aSource, false);
- }
- }
- }
-
- rv = transaction.Commit();
- NS_ENSURE_SUCCESS(rv, rv);
-
- return NS_OK;
-}
-
-
NS_IMETHODIMP
nsAnnotationService::AddObserver(nsIAnnotationObserver* aObserver)
{
NS_ENSURE_ARG(aObserver);
if (mObservers.IndexOfObject(aObserver) >= 0)
return NS_ERROR_INVALID_ARG; // Already registered.
if (!mObservers.AppendObject(aObserver))
--- a/toolkit/components/places/nsIAnnotationService.idl
+++ b/toolkit/components/places/nsIAnnotationService.idl
@@ -360,33 +360,16 @@ interface nsIAnnotationService : nsISupp
* Unlike the other item methods, `removeItemAnnotations` does *not* notify
* `nsINavBookmarkObserver::onItemChanged` for the affected item.
*/
void removePageAnnotations(in nsIURI aURI);
void removeItemAnnotations(in long long aItemId,
[optional] in unsigned short aSource);
/**
- * Copies all annotations from the source to the destination URI/item. If
- * the destination already has an annotation with the same name as one on
- * the source, it will be overwritten if aOverwriteDest is set. Otherwise,
- * the original annotation will be preferred.
- *
- * All the source annotations will stay as-is. If you don't want them
- * any more, use removePageAnnotations on that URI.
- */
- void copyPageAnnotations(in nsIURI aSourceURI,
- in nsIURI aDestURI,
- in boolean aOverwriteDest);
- void copyItemAnnotations(in long long aSourceItemId,
- in long long aDestItemId,
- in boolean aOverwriteDest,
- [optional] in unsigned short aSource);
-
- /**
* Adds an annotation observer. The annotation service will keep an owning
* reference to the observer object.
*/
void addObserver(in nsIAnnotationObserver aObserver);
/**
* Removes an annotaton observer previously registered by addObserver.
--- a/toolkit/components/places/tests/unit/test_annotations.js
+++ b/toolkit/components/places/tests/unit/test_annotations.js
@@ -154,79 +154,16 @@ add_task(async function test_execute() {
Assert.equal(annoNames.length, 1);
Assert.equal(annoNames[0], "moz-test-places/annotations");
// get annotation names for an item
annoNames = annosvc.getItemAnnotationNames(testItemId);
Assert.equal(annoNames.length, 1);
Assert.equal(annoNames[0], "moz-test-places/annotations");
- // copy annotations to another uri
- var newURI = uri("http://mozilla.org");
- await PlacesTestUtils.addVisits(newURI);
- annosvc.setPageAnnotation(testURI, "oldAnno", "new", 0, 0);
- annosvc.setPageAnnotation(newURI, "oldAnno", "old", 0, 0);
- annoNames = annosvc.getPageAnnotationNames(newURI);
- Assert.equal(annoNames.length, 1);
- Assert.equal(annoNames[0], "oldAnno");
- var oldAnnoNames = annosvc.getPageAnnotationNames(testURI);
- Assert.equal(oldAnnoNames.length, 2);
- var copiedAnno = oldAnnoNames[0];
- annosvc.copyPageAnnotations(testURI, newURI, false);
- var newAnnoNames = annosvc.getPageAnnotationNames(newURI);
- Assert.equal(newAnnoNames.length, 2);
- Assert.ok(annosvc.pageHasAnnotation(newURI, "oldAnno"));
- Assert.ok(annosvc.pageHasAnnotation(newURI, copiedAnno));
- Assert.equal(annosvc.getPageAnnotation(newURI, "oldAnno"), "old");
- annosvc.setPageAnnotation(newURI, "oldAnno", "new", 0, 0);
- annosvc.copyPageAnnotations(testURI, newURI, true);
- newAnnoNames = annosvc.getPageAnnotationNames(newURI);
- Assert.equal(newAnnoNames.length, 2);
- Assert.ok(annosvc.pageHasAnnotation(newURI, "oldAnno"));
- Assert.ok(annosvc.pageHasAnnotation(newURI, copiedAnno));
- Assert.equal(annosvc.getPageAnnotation(newURI, "oldAnno"), "new");
-
-
- // copy annotations to another item
- newURI = uri("http://mozilla.org");
- let newItem = await PlacesUtils.bookmarks.insert({
- parentGuid: PlacesUtils.bookmarks.menuGuid,
- title: "",
- url: newURI,
- });
- let newItemId = await PlacesUtils.promiseItemId(newItem.guid);
- item = await PlacesUtils.bookmarks.insert({
- parentGuid: PlacesUtils.bookmarks.menuGuid,
- title: "",
- url: testURI,
- });
- var itemId = await PlacesUtils.promiseItemId(item.guid);
- annosvc.setItemAnnotation(itemId, "oldAnno", "new", 0, 0);
- annosvc.setItemAnnotation(itemId, "testAnno", "test", 0, 0);
- annosvc.setItemAnnotation(newItemId, "oldAnno", "old", 0, 0);
- annoNames = annosvc.getItemAnnotationNames(newItemId);
- Assert.equal(annoNames.length, 1);
- Assert.equal(annoNames[0], "oldAnno");
- oldAnnoNames = annosvc.getItemAnnotationNames(itemId);
- Assert.equal(oldAnnoNames.length, 2);
- copiedAnno = oldAnnoNames[0];
- annosvc.copyItemAnnotations(itemId, newItemId, false);
- newAnnoNames = annosvc.getItemAnnotationNames(newItemId);
- Assert.equal(newAnnoNames.length, 2);
- Assert.ok(annosvc.itemHasAnnotation(newItemId, "oldAnno"));
- Assert.ok(annosvc.itemHasAnnotation(newItemId, copiedAnno));
- Assert.equal(annosvc.getItemAnnotation(newItemId, "oldAnno"), "old");
- annosvc.setItemAnnotation(newItemId, "oldAnno", "new", 0, 0);
- annosvc.copyItemAnnotations(itemId, newItemId, true);
- newAnnoNames = annosvc.getItemAnnotationNames(newItemId);
- Assert.equal(newAnnoNames.length, 2);
- Assert.ok(annosvc.itemHasAnnotation(newItemId, "oldAnno"));
- Assert.ok(annosvc.itemHasAnnotation(newItemId, copiedAnno));
- Assert.equal(annosvc.getItemAnnotation(newItemId, "oldAnno"), "new");
-
// test int32 anno type
var int32Key = testAnnoName + "/types/Int32";
var int32Val = 23;
annosvc.setPageAnnotation(testURI, int32Key, int32Val, 0, 0);
Assert.ok(annosvc.pageHasAnnotation(testURI, int32Key));
value = {}, flags = {}, exp = {}, storageType = {};
annosvc.getPageAnnotationInfo(testURI, int32Key, flags, exp, storageType);
Assert.equal(flags.value, 0);
@@ -323,17 +260,17 @@ add_task(async function test_execute() {
}
// setting an annotation with EXPIRE_HISTORY for an item should throw
item = await PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.menuGuid,
title: "",
url: testURI,
});
- itemId = await PlacesUtils.promiseItemId(item.guid);
+ let itemId = await PlacesUtils.promiseItemId(item.guid);
try {
annosvc.setItemAnnotation(itemId, "foo", "bar", 0, annosvc.EXPIRE_WITH_HISTORY);
do_throw("setting an item annotation with EXPIRE_HISTORY should throw");
} catch (ex) {
}
annosvc.removeObserver(annoObserver);
});