2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Places.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Google Inc.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2005
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Brian Ryner <bryner@brianryner.com> (original author)
|
2009-10-09 03:30:12 -07:00
|
|
|
* Dietrich Ayala <dietrich@mozilla.com>
|
|
|
|
* Marco Bonardo <mak77@bonardo.net>
|
2010-04-09 11:30:29 -07:00
|
|
|
* Drew Willcoxon <adw@mozilla.com>
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#ifndef nsNavBookmarks_h_
|
|
|
|
#define nsNavBookmarks_h_
|
|
|
|
|
|
|
|
#include "nsINavBookmarksService.h"
|
2007-05-10 01:05:19 -07:00
|
|
|
#include "nsIAnnotationService.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsITransaction.h"
|
|
|
|
#include "nsNavHistory.h"
|
|
|
|
#include "nsToolkitCompsCID.h"
|
2009-03-25 13:31:36 -07:00
|
|
|
#include "nsCategoryCache.h"
|
2011-05-16 15:11:35 -07:00
|
|
|
#include "nsTHashtable.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-25 04:34:33 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace places {
|
|
|
|
|
|
|
|
enum BookmarkStatementId {
|
|
|
|
DB_FIND_REDIRECTED_BOOKMARK = 0
|
2010-12-20 09:21:49 -08:00
|
|
|
, DB_GET_BOOKMARKS_FOR_URI
|
2010-03-25 04:34:33 -07:00
|
|
|
};
|
|
|
|
|
2011-05-13 12:24:22 -07:00
|
|
|
struct BookmarkData {
|
|
|
|
PRInt64 id;
|
|
|
|
nsCString url;
|
|
|
|
nsCString title;
|
|
|
|
PRInt32 position;
|
|
|
|
PRInt64 placeId;
|
|
|
|
PRInt64 parentId;
|
|
|
|
PRInt64 grandParentId;
|
|
|
|
PRInt32 type;
|
|
|
|
nsCString serviceCID;
|
|
|
|
PRTime dateAdded;
|
|
|
|
PRTime lastModified;
|
|
|
|
nsCString guid;
|
|
|
|
nsCString parentGuid;
|
|
|
|
};
|
|
|
|
|
2010-12-20 09:21:49 -08:00
|
|
|
struct ItemVisitData {
|
2011-05-13 12:24:22 -07:00
|
|
|
BookmarkData bookmark;
|
2010-12-20 09:21:49 -08:00
|
|
|
PRInt64 visitId;
|
2011-05-13 12:24:22 -07:00
|
|
|
PRUint32 transitionType;
|
2010-12-20 09:21:49 -08:00
|
|
|
PRTime time;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ItemChangeData {
|
2011-05-13 12:24:22 -07:00
|
|
|
BookmarkData bookmark;
|
2010-12-20 09:21:49 -08:00
|
|
|
nsCString property;
|
|
|
|
PRBool isAnnotation;
|
|
|
|
nsCString newValue;
|
|
|
|
};
|
|
|
|
|
2011-02-05 04:22:10 -08:00
|
|
|
typedef void (nsNavBookmarks::*ItemVisitMethod)(const ItemVisitData&);
|
|
|
|
typedef void (nsNavBookmarks::*ItemChangeMethod)(const ItemChangeData&);
|
2010-12-20 09:21:49 -08:00
|
|
|
|
2011-05-16 15:11:35 -07:00
|
|
|
class BookmarkKeyClass : public nsTrimInt64HashKey
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BookmarkKeyClass(const PRInt64* aItemId)
|
|
|
|
: nsTrimInt64HashKey(aItemId)
|
|
|
|
, creationTime(PR_Now())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
BookmarkKeyClass(const BookmarkKeyClass& aOther)
|
|
|
|
: nsTrimInt64HashKey(aOther)
|
|
|
|
, creationTime(PR_Now())
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("Do not call me!");
|
|
|
|
}
|
|
|
|
BookmarkData bookmark;
|
|
|
|
PRTime creationTime;
|
|
|
|
};
|
|
|
|
|
2010-03-25 04:34:33 -07:00
|
|
|
} // namespace places
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsIOutputStream;
|
|
|
|
|
|
|
|
class nsNavBookmarks : public nsINavBookmarksService,
|
2007-05-10 01:05:19 -07:00
|
|
|
public nsINavHistoryObserver,
|
2011-05-16 15:11:35 -07:00
|
|
|
public nsIAnnotationObserver,
|
|
|
|
public nsIObserver
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSINAVBOOKMARKSSERVICE
|
|
|
|
NS_DECL_NSINAVHISTORYOBSERVER
|
2007-05-10 01:05:19 -07:00
|
|
|
NS_DECL_NSIANNOTATIONOBSERVER
|
2011-05-16 15:11:35 -07:00
|
|
|
NS_DECL_NSIOBSERVER
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsNavBookmarks();
|
2009-12-01 05:00:45 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtains the service's object.
|
|
|
|
*/
|
2010-01-16 03:37:57 -08:00
|
|
|
static nsNavBookmarks* GetSingleton();
|
2009-12-01 05:00:45 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the service's object. This should only be called once.
|
|
|
|
*/
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult Init();
|
|
|
|
|
|
|
|
// called by nsNavHistory::Init
|
|
|
|
static nsresult InitTables(mozIStorageConnection* aDBConn);
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
static nsNavBookmarks* GetBookmarksService() {
|
2009-12-01 05:00:45 -08:00
|
|
|
if (!gBookmarksService) {
|
|
|
|
nsCOMPtr<nsINavBookmarksService> serv =
|
|
|
|
do_GetService(NS_NAVBOOKMARKSSERVICE_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE(serv, nsnull);
|
|
|
|
NS_ASSERTION(gBookmarksService,
|
|
|
|
"Should have static instance pointer now");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-12-01 05:00:45 -08:00
|
|
|
return gBookmarksService;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-05-16 15:11:35 -07:00
|
|
|
typedef mozilla::places::BookmarkData BookmarkData;
|
|
|
|
typedef mozilla::places::BookmarkKeyClass BookmarkKeyClass;
|
|
|
|
typedef mozilla::places::ItemVisitData ItemVisitData;
|
|
|
|
typedef mozilla::places::ItemChangeData ItemChangeData;
|
|
|
|
typedef mozilla::places::BookmarkStatementId BookmarkStatementId;
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
nsresult ResultNodeForContainer(PRInt64 aID,
|
|
|
|
nsNavHistoryQueryOptions* aOptions,
|
|
|
|
nsNavHistoryResultNode** aNode);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Find all the children of a folder, using the given query and options.
|
|
|
|
// For each child, a ResultNode is created and added to |children|.
|
|
|
|
// The results are ordered by folder position.
|
|
|
|
nsresult QueryFolderChildren(PRInt64 aFolderId,
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavHistoryQueryOptions* aOptions,
|
|
|
|
nsCOMArray<nsNavHistoryResultNode>* children);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-04-09 11:30:29 -07:00
|
|
|
/**
|
|
|
|
* Turns aRow into a node and appends it to aChildren if it is appropriate to
|
|
|
|
* do so.
|
|
|
|
*
|
|
|
|
* @param aRow
|
|
|
|
* A Storage statement (in the case of synchronous execution) or row of
|
|
|
|
* a result set (in the case of asynchronous execution).
|
|
|
|
* @param aOptions
|
|
|
|
* The options of the parent folder node.
|
|
|
|
* @param aChildren
|
|
|
|
* The children of the parent folder node.
|
|
|
|
* @param aCurrentIndex
|
|
|
|
* The index of aRow within the results. When called on the first row,
|
|
|
|
* this should be set to -1.
|
|
|
|
*/
|
|
|
|
nsresult ProcessFolderNodeRow(mozIStorageValueArray* aRow,
|
|
|
|
nsNavHistoryQueryOptions* aOptions,
|
|
|
|
nsCOMArray<nsNavHistoryResultNode>* aChildren,
|
|
|
|
PRInt32& aCurrentIndex);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The async version of QueryFolderChildren.
|
|
|
|
*
|
|
|
|
* @param aNode
|
|
|
|
* The folder node that will receive the children.
|
|
|
|
* @param _pendingStmt
|
|
|
|
* The Storage pending statement that will be used to control async
|
|
|
|
* execution.
|
|
|
|
*/
|
|
|
|
nsresult QueryFolderChildrenAsync(nsNavHistoryFolderResultNode* aNode,
|
|
|
|
PRInt64 aFolderId,
|
|
|
|
mozIStoragePendingStatement** _pendingStmt);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// If aFolder is -1, uses the autoincrement id for folder index. Returns
|
|
|
|
// the index of the new folder in aIndex, whether it was passed in or
|
2007-08-02 13:19:44 -07:00
|
|
|
// generated by autoincrement.
|
|
|
|
nsresult CreateContainerWithID(PRInt64 aId, PRInt64 aParent,
|
2011-05-13 12:24:22 -07:00
|
|
|
const nsACString& aTitle,
|
2007-08-02 13:19:44 -07:00
|
|
|
const nsAString& aContractId,
|
|
|
|
PRBool aIsBookmarkFolder,
|
|
|
|
PRInt32* aIndex,
|
|
|
|
PRInt64* aNewFolder);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-01-27 18:01:33 -08:00
|
|
|
/**
|
|
|
|
* Determines if we have a real bookmark or not (not a livemark).
|
|
|
|
*
|
|
|
|
* @param aPlaceId
|
|
|
|
* The place_id of the location to check against.
|
2009-06-24 01:59:14 -07:00
|
|
|
* @return true if it's a real bookmark, false otherwise.
|
2009-01-27 18:01:33 -08:00
|
|
|
*/
|
|
|
|
PRBool IsRealBookmark(PRInt64 aPlaceId);
|
|
|
|
|
2011-05-13 12:24:22 -07:00
|
|
|
/**
|
|
|
|
* Fetches information about the specified id from the database.
|
|
|
|
*
|
|
|
|
* @param aItemId
|
|
|
|
* Id of the item to fetch information for.
|
|
|
|
* @param aBookmark
|
|
|
|
* BookmarkData to store the information.
|
2011-05-16 15:11:35 -07:00
|
|
|
* @param aInvalidateCache
|
|
|
|
* True if the cache should discard its entry after the fetching.
|
2011-05-13 12:24:22 -07:00
|
|
|
*/
|
|
|
|
nsresult FetchItemInfo(PRInt64 aItemId,
|
2011-05-16 15:11:35 -07:00
|
|
|
BookmarkData& _bookmark,
|
|
|
|
bool aInvalidateCache);
|
2007-06-25 18:08:54 -07:00
|
|
|
|
2008-11-13 22:45:49 -08:00
|
|
|
/**
|
|
|
|
* Finalize all internal statements.
|
|
|
|
*/
|
|
|
|
nsresult FinalizeStatements();
|
|
|
|
|
2011-05-16 15:11:35 -07:00
|
|
|
mozIStorageStatement* GetStatementById(BookmarkStatementId aStatementId)
|
2010-03-25 04:34:33 -07:00
|
|
|
{
|
|
|
|
using namespace mozilla::places;
|
|
|
|
switch(aStatementId) {
|
|
|
|
case DB_FIND_REDIRECTED_BOOKMARK:
|
|
|
|
return GetStatement(mDBFindRedirectedBookmark);
|
2010-12-20 09:21:49 -08:00
|
|
|
case DB_GET_BOOKMARKS_FOR_URI:
|
|
|
|
return GetStatement(mDBFindURIBookmarks);
|
2010-03-25 04:34:33 -07:00
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2010-12-20 09:21:49 -08:00
|
|
|
/**
|
|
|
|
* Notifies that a bookmark has been visited.
|
|
|
|
*
|
|
|
|
* @param aItemId
|
|
|
|
* The visited item id.
|
|
|
|
* @param aData
|
|
|
|
* Details about the new visit.
|
|
|
|
*/
|
2011-05-16 15:11:35 -07:00
|
|
|
void NotifyItemVisited(const ItemVisitData& aData);
|
2010-12-20 09:21:49 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Notifies that a bookmark has changed.
|
|
|
|
*
|
|
|
|
* @param aItemId
|
|
|
|
* The changed item id.
|
|
|
|
* @param aData
|
|
|
|
* Details about the change.
|
|
|
|
*/
|
2011-05-16 15:11:35 -07:00
|
|
|
void NotifyItemChanged(const ItemChangeData& aData);
|
2010-12-20 09:21:49 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
2010-01-16 03:37:57 -08:00
|
|
|
static nsNavBookmarks* gBookmarksService;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
~nsNavBookmarks();
|
|
|
|
|
2010-10-20 17:51:18 -07:00
|
|
|
/**
|
|
|
|
* Locates the root items in the bookmarks folder hierarchy assigning folder
|
|
|
|
* ids to the root properties that are exposed through the service interface.
|
|
|
|
*
|
|
|
|
* @param aForceCreate
|
|
|
|
* Whether the method should try creating the roots. It should be set
|
|
|
|
* to true if the database has just been created or upgraded.
|
|
|
|
*
|
|
|
|
* @note The creation of roots skips already existing entries.
|
|
|
|
*/
|
|
|
|
nsresult InitRoots(bool aForceCreate);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tries to create a root folder with the given name.
|
|
|
|
*
|
|
|
|
* @param name
|
|
|
|
* Name associated to the root.
|
|
|
|
* @param _itemId
|
|
|
|
* if set CreateRoot will skip creation, otherwise will return the
|
|
|
|
* newly created folder id.
|
|
|
|
* @param aParentId
|
|
|
|
* Id of the parent that should cotain this root.
|
|
|
|
* @param aBundle
|
|
|
|
* Stringbundle used to get the visible title of the root.
|
|
|
|
* @param aTitleStringId
|
|
|
|
* Id of the title string in the stringbundle.
|
|
|
|
*/
|
|
|
|
nsresult CreateRoot(const nsCString& name,
|
|
|
|
PRInt64* _itemId,
|
|
|
|
PRInt64 aParentId,
|
|
|
|
nsIStringBundle* aBundle,
|
|
|
|
const PRUnichar* aTitleStringId);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult AdjustIndices(PRInt64 aFolder,
|
2010-01-16 03:37:57 -08:00
|
|
|
PRInt32 aStartIndex,
|
|
|
|
PRInt32 aEndIndex,
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt32 aDelta);
|
2009-08-21 02:54:12 -07:00
|
|
|
|
|
|
|
/**
|
2011-05-13 12:24:22 -07:00
|
|
|
* Fetches properties of a folder.
|
2009-08-21 02:54:12 -07:00
|
|
|
*
|
2011-05-13 12:24:22 -07:00
|
|
|
* @param aFolderId
|
|
|
|
* Folder to count children for.
|
|
|
|
* @param _folderCount
|
|
|
|
* Number of children in the folder.
|
|
|
|
* @param _guid
|
|
|
|
* Unique id of the folder.
|
|
|
|
* @param _parentId
|
|
|
|
* Id of the parent of the folder.
|
2009-08-21 02:54:12 -07:00
|
|
|
*
|
|
|
|
* @throws If folder does not exist.
|
|
|
|
*/
|
2011-05-13 12:24:22 -07:00
|
|
|
nsresult FetchFolderInfo(PRInt64 aFolderId,
|
|
|
|
PRInt32* _folderCount,
|
|
|
|
nsACString& _guid,
|
|
|
|
PRInt64* _parentId);
|
2009-08-21 02:54:12 -07:00
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
nsresult GetFolderType(PRInt64 aFolder, nsACString& aType);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-02-06 13:05:23 -08:00
|
|
|
nsresult GetLastChildId(PRInt64 aFolder, PRInt64* aItemId);
|
|
|
|
|
2010-11-29 09:33:26 -08:00
|
|
|
/**
|
|
|
|
* This is the basic Places read-write connection, obtained from history.
|
|
|
|
*/
|
2008-10-27 15:52:21 -07:00
|
|
|
nsCOMPtr<mozIStorageConnection> mDBConn;
|
2010-11-29 09:33:26 -08:00
|
|
|
/**
|
|
|
|
* Cloned read-only connection. Can be used to read from the database
|
|
|
|
* without being locked out by writers.
|
|
|
|
*/
|
|
|
|
nsCOMPtr<mozIStorageConnection> mDBReadOnlyConn;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-25 20:53:59 -07:00
|
|
|
nsString mGUIDBase;
|
2008-10-27 15:52:21 -07:00
|
|
|
nsresult GetGUIDBase(nsAString& aGUIDBase);
|
|
|
|
|
2007-07-25 20:53:59 -07:00
|
|
|
PRInt32 mItemCount;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMaybeWeakPtrArray<nsINavBookmarkObserver> mObservers;
|
2010-10-20 17:51:18 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt64 mRoot;
|
2010-10-20 17:51:18 -07:00
|
|
|
PRInt64 mMenuRoot;
|
|
|
|
PRInt64 mTagsRoot;
|
2007-09-16 18:42:15 -07:00
|
|
|
PRInt64 mUnfiledRoot;
|
2010-10-20 17:51:18 -07:00
|
|
|
PRInt64 mToolbarRoot;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult IsBookmarkedInDatabase(PRInt64 aBookmarkID, PRBool* aIsBookmarked);
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
nsresult SetItemDateInternal(mozIStorageStatement* aStatement,
|
|
|
|
PRInt64 aItemId,
|
|
|
|
PRTime aValue);
|
2008-03-17 16:25:36 -07:00
|
|
|
|
2008-11-05 14:02:12 -08:00
|
|
|
// Recursive method to build an array of folder's children
|
|
|
|
nsresult GetDescendantChildren(PRInt64 aFolderId,
|
2011-05-13 12:24:22 -07:00
|
|
|
const nsACString& aFolderGuid,
|
2008-11-05 14:02:12 -08:00
|
|
|
PRInt64 aGrandParentId,
|
2011-05-16 15:11:35 -07:00
|
|
|
nsTArray<BookmarkData>& aFolderChildrenArray);
|
2008-11-05 14:02:12 -08:00
|
|
|
|
2009-06-24 01:59:14 -07:00
|
|
|
enum ItemType {
|
|
|
|
BOOKMARK = TYPE_BOOKMARK,
|
|
|
|
FOLDER = TYPE_FOLDER,
|
|
|
|
SEPARATOR = TYPE_SEPARATOR,
|
|
|
|
DYNAMIC_CONTAINER = TYPE_DYNAMIC_CONTAINER
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper to insert a bookmark in the database.
|
|
|
|
*
|
|
|
|
* @param aItemId
|
|
|
|
* The itemId to insert, pass -1 to generate a new one.
|
|
|
|
* @param aPlaceId
|
|
|
|
* The placeId to which this bookmark refers to, pass nsnull for
|
|
|
|
* items that don't refer to an URI (eg. folders, separators, ...).
|
|
|
|
* @param aItemType
|
|
|
|
* The type of the new bookmark, see TYPE_* constants.
|
|
|
|
* @param aParentId
|
|
|
|
* The itemId of the parent folder.
|
|
|
|
* @param aIndex
|
|
|
|
* The position inside the parent folder.
|
|
|
|
* @param aTitle
|
|
|
|
* The title for the new bookmark.
|
|
|
|
* Pass a void string to set a NULL title.
|
|
|
|
* @param aDateAdded
|
|
|
|
* The date for the insertion.
|
|
|
|
* @param [optional] aLastModified
|
|
|
|
* The last modified date for the insertion.
|
|
|
|
* It defaults to aDateAdded.
|
|
|
|
* @param [optional] aServiceContractId
|
|
|
|
* The contract id for a dynamic container.
|
|
|
|
* Pass EmptyCString() for other type of containers.
|
|
|
|
*
|
|
|
|
* @return The new item id that has been inserted.
|
|
|
|
*
|
|
|
|
* @note This will also update last modified date of the parent folder.
|
|
|
|
*/
|
2011-05-13 12:24:22 -07:00
|
|
|
nsresult InsertBookmarkInDB(PRInt64 aPlaceId,
|
2009-06-24 01:59:14 -07:00
|
|
|
enum ItemType aItemType,
|
|
|
|
PRInt64 aParentId,
|
|
|
|
PRInt32 aIndex,
|
2010-01-16 03:37:57 -08:00
|
|
|
const nsACString& aTitle,
|
2009-06-24 01:59:14 -07:00
|
|
|
PRTime aDateAdded,
|
|
|
|
PRTime aLastModified,
|
2010-01-16 03:37:57 -08:00
|
|
|
const nsAString& aServiceContractId,
|
2011-05-13 12:24:22 -07:00
|
|
|
PRInt64* _itemId,
|
|
|
|
nsACString& _guid);
|
2009-06-24 01:59:14 -07:00
|
|
|
|
2009-10-28 16:52:41 -07:00
|
|
|
/**
|
|
|
|
* TArray version of getBookmarksIdForURI for ease of use in C++ code.
|
|
|
|
* Pass in a reference to a TArray; it will get filled with the
|
|
|
|
* resulting list of bookmark IDs.
|
2011-05-05 04:14:21 -07:00
|
|
|
*
|
|
|
|
* @param aURI
|
|
|
|
* URI to get bookmarks for.
|
|
|
|
* @param aResult
|
|
|
|
* Array of bookmark ids.
|
|
|
|
* @param aSkipTags
|
|
|
|
* If true ids of tags-as-bookmarks entries will be excluded.
|
2009-10-28 16:52:41 -07:00
|
|
|
*/
|
2010-01-16 03:37:57 -08:00
|
|
|
nsresult GetBookmarkIdsForURITArray(nsIURI* aURI,
|
2011-05-05 04:14:21 -07:00
|
|
|
nsTArray<PRInt64>& aResult,
|
|
|
|
bool aSkipTags);
|
2009-10-28 16:52:41 -07:00
|
|
|
|
2011-05-13 12:24:22 -07:00
|
|
|
nsresult GetBookmarksForURI(nsIURI* aURI,
|
2011-05-16 15:11:35 -07:00
|
|
|
nsTArray<BookmarkData>& _bookmarks);
|
2011-05-13 12:24:22 -07:00
|
|
|
|
2010-03-10 04:40:52 -08:00
|
|
|
PRInt64 RecursiveFindRedirectedBookmark(PRInt64 aPlaceId);
|
2010-01-16 03:38:00 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* You should always use this getter and never use directly the nsCOMPtr.
|
|
|
|
*/
|
|
|
|
mozIStorageStatement* GetStatement(const nsCOMPtr<mozIStorageStatement>& aStmt);
|
|
|
|
|
2007-11-19 18:01:53 -08:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBGetChildren;
|
2011-05-13 12:24:22 -07:00
|
|
|
// These columns sit to the right of the kGetInfoIndex_* columns.
|
2007-03-22 10:30:00 -07:00
|
|
|
static const PRInt32 kGetChildrenIndex_Position;
|
2007-04-04 10:21:03 -07:00
|
|
|
static const PRInt32 kGetChildrenIndex_Type;
|
2008-11-05 14:02:12 -08:00
|
|
|
static const PRInt32 kGetChildrenIndex_PlaceID;
|
2007-03-22 10:30:00 -07:00
|
|
|
static const PRInt32 kGetChildrenIndex_FolderTitle;
|
2008-11-05 14:02:12 -08:00
|
|
|
static const PRInt32 kGetChildrenIndex_ServiceContractId;
|
2011-05-13 12:24:22 -07:00
|
|
|
static const PRInt32 kGetChildrenIndex_Guid;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBFindURIBookmarks;
|
2011-05-13 12:24:22 -07:00
|
|
|
static const PRInt32 kFindURIBookmarksIndex_Id;
|
|
|
|
static const PRInt32 kFindURIBookmarksIndex_Guid;
|
|
|
|
static const PRInt32 kFindURIBookmarksIndex_ParentId;
|
|
|
|
static const PRInt32 kFindURIBookmarksIndex_LastModified;
|
|
|
|
static const PRInt32 kFindURIBookmarksIndex_ParentGuid;
|
|
|
|
static const PRInt32 kFindURIBookmarksIndex_GrandParentId;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBGetItemProperties;
|
2011-05-13 12:24:22 -07:00
|
|
|
static const PRInt32 kGetItemPropertiesIndex_Id;
|
|
|
|
static const PRInt32 kGetItemPropertiesIndex_Url;
|
2007-05-08 18:19:12 -07:00
|
|
|
static const PRInt32 kGetItemPropertiesIndex_Title;
|
|
|
|
static const PRInt32 kGetItemPropertiesIndex_Position;
|
2011-05-13 12:24:22 -07:00
|
|
|
static const PRInt32 kGetItemPropertiesIndex_PlaceId;
|
|
|
|
static const PRInt32 kGetItemPropertiesIndex_ParentId;
|
2007-05-08 18:19:12 -07:00
|
|
|
static const PRInt32 kGetItemPropertiesIndex_Type;
|
2007-08-02 13:19:44 -07:00
|
|
|
static const PRInt32 kGetItemPropertiesIndex_ServiceContractId;
|
2007-05-18 17:40:55 -07:00
|
|
|
static const PRInt32 kGetItemPropertiesIndex_DateAdded;
|
|
|
|
static const PRInt32 kGetItemPropertiesIndex_LastModified;
|
2011-05-13 12:24:22 -07:00
|
|
|
static const PRInt32 kGetItemPropertiesIndex_Guid;
|
|
|
|
static const PRInt32 kGetItemPropertiesIndex_ParentGuid;
|
|
|
|
static const PRInt32 kGetItemPropertiesIndex_GrandParentId;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-11-09 13:21:38 -08:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBInsertBookmark;
|
2009-06-24 01:59:14 -07:00
|
|
|
static const PRInt32 kInsertBookmarkIndex_Id;
|
|
|
|
static const PRInt32 kInsertBookmarkIndex_PlaceId;
|
|
|
|
static const PRInt32 kInsertBookmarkIndex_Type;
|
|
|
|
static const PRInt32 kInsertBookmarkIndex_Parent;
|
|
|
|
static const PRInt32 kInsertBookmarkIndex_Position;
|
|
|
|
static const PRInt32 kInsertBookmarkIndex_Title;
|
|
|
|
static const PRInt32 kInsertBookmarkIndex_ServiceContractId;
|
|
|
|
static const PRInt32 kInsertBookmarkIndex_DateAdded;
|
|
|
|
static const PRInt32 kInsertBookmarkIndex_LastModified;
|
|
|
|
|
2011-05-13 12:24:22 -07:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBFolderInfo;
|
2010-01-16 03:38:00 -08:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBGetItemIndex;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mDBGetChildAt;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mDBGetItemIdForGUID;
|
2007-11-09 13:21:38 -08:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBIsBookmarkedInDatabase;
|
2010-03-10 04:40:52 -08:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBIsURIBookmarkedInDatabase;
|
2009-01-27 18:01:33 -08:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBIsRealBookmark;
|
2008-08-16 15:28:28 -07:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBGetLastBookmarkID;
|
2007-11-09 13:21:38 -08:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBSetItemDateAdded;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mDBSetItemLastModified;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mDBSetItemIndex;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBGetKeywordForURI;
|
2010-08-09 08:59:43 -07:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBGetBookmarksToKeywords;
|
2010-01-16 03:37:57 -08:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBAdjustPosition;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mDBRemoveItem;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mDBGetLastChildId;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mDBMoveItem;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mDBSetItemTitle;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mDBChangeBookmarkURI;
|
2010-03-10 04:40:52 -08:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBFindRedirectedBookmark;
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
class RemoveFolderTransaction : public nsITransaction {
|
|
|
|
public:
|
2008-09-11 07:16:54 -07:00
|
|
|
RemoveFolderTransaction(PRInt64 aID) : mID(aID) {}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
NS_IMETHOD DoTransaction() {
|
|
|
|
nsNavBookmarks* bookmarks = nsNavBookmarks::GetBookmarksService();
|
2009-12-01 05:00:45 -08:00
|
|
|
NS_ENSURE_TRUE(bookmarks, NS_ERROR_OUT_OF_MEMORY);
|
2011-05-16 15:11:35 -07:00
|
|
|
BookmarkData folder;
|
|
|
|
nsresult rv = bookmarks->FetchItemInfo(mID, folder, true);
|
2011-05-13 12:24:22 -07:00
|
|
|
// TODO (Bug 656935): store the BookmarkData struct instead.
|
|
|
|
mParent = folder.parentId;
|
|
|
|
mIndex = folder.position;
|
2008-09-11 07:16:54 -07:00
|
|
|
|
|
|
|
rv = bookmarks->GetItemTitle(mID, mTitle);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCAutoString type;
|
|
|
|
rv = bookmarks->GetFolderType(mID, type);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-02-06 16:18:16 -08:00
|
|
|
CopyUTF8toUTF16(type, mType);
|
2008-09-11 07:16:54 -07:00
|
|
|
|
2011-05-13 12:24:22 -07:00
|
|
|
return bookmarks->RemoveItem(mID);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD UndoTransaction() {
|
|
|
|
nsNavBookmarks* bookmarks = nsNavBookmarks::GetBookmarksService();
|
2009-12-01 05:00:45 -08:00
|
|
|
NS_ENSURE_TRUE(bookmarks, NS_ERROR_OUT_OF_MEMORY);
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt64 newFolder;
|
2007-08-02 13:19:44 -07:00
|
|
|
return bookmarks->CreateContainerWithID(mID, mParent, mTitle, mType, PR_TRUE,
|
|
|
|
&mIndex, &newFolder);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD RedoTransaction() {
|
|
|
|
return DoTransaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD GetIsTransient(PRBool* aResult) {
|
|
|
|
*aResult = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Merge(nsITransaction* aTransaction, PRBool* aResult) {
|
|
|
|
*aResult = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
PRInt64 mID;
|
|
|
|
PRInt64 mParent;
|
2008-01-08 19:54:37 -08:00
|
|
|
nsCString mTitle;
|
2007-08-02 13:19:44 -07:00
|
|
|
nsString mType;
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt32 mIndex;
|
|
|
|
};
|
2009-03-25 13:31:36 -07:00
|
|
|
|
|
|
|
// Used to enable and disable the observer notifications.
|
|
|
|
bool mCanNotify;
|
|
|
|
nsCategoryCache<nsINavBookmarkObserver> mCacheObservers;
|
2010-01-16 03:37:57 -08:00
|
|
|
|
|
|
|
bool mShuttingDown;
|
2010-08-09 08:59:43 -07:00
|
|
|
|
2010-12-02 17:37:53 -08:00
|
|
|
// Tracks whether we are in batch mode.
|
|
|
|
// Note: this is only tracking bookmarks batches, not history ones.
|
|
|
|
bool mBatching;
|
|
|
|
|
2010-08-09 08:59:43 -07:00
|
|
|
/**
|
|
|
|
* Always call EnsureKeywordsHash() and check it for errors before actually
|
|
|
|
* using the hash. Internal keyword methods are already doing that.
|
|
|
|
*/
|
|
|
|
nsresult EnsureKeywordsHash();
|
|
|
|
nsDataHashtable<nsTrimInt64HashKey, nsString> mBookmarkToKeywordHash;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function must be called every time a bookmark is removed.
|
|
|
|
*
|
|
|
|
* @param aURI
|
|
|
|
* Uri to test.
|
|
|
|
*/
|
|
|
|
nsresult UpdateKeywordsHashForRemovedBookmark(PRInt64 aItemId);
|
2011-05-16 15:11:35 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Cache for the last fetched BookmarkData entries.
|
|
|
|
* This is used to speed up repeated requests to the same item id.
|
|
|
|
*/
|
|
|
|
nsTHashtable<BookmarkKeyClass> mRecentBookmarksCache;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsNavBookmarks_h_
|