2006-07-18 14:27:16 +00: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 10:30:12 +00:00
|
|
|
* Dietrich Ayala <dietrich@mozilla.com>
|
2009-01-13 10:48:27 +00:00
|
|
|
* Drew Willcoxon <adw@mozilla.com>
|
2009-10-09 10:30:12 +00:00
|
|
|
* Marco Bonardo <mak77@bonardo.net>
|
2006-07-18 14:27:16 +00: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 ***** */
|
|
|
|
|
2006-07-18 14:33:42 +00:00
|
|
|
#include "nsAppDirectoryServiceDefs.h"
|
2006-07-18 14:27:16 +00:00
|
|
|
#include "nsNavBookmarks.h"
|
|
|
|
#include "nsNavHistory.h"
|
|
|
|
#include "mozStorageHelper.h"
|
|
|
|
#include "nsIServiceManager.h"
|
2006-07-18 14:29:04 +00:00
|
|
|
#include "nsNetUtil.h"
|
2007-08-02 20:19:44 +00:00
|
|
|
#include "nsIDynamicContainer.h"
|
2006-07-18 14:45:13 +00:00
|
|
|
#include "nsUnicharUtils.h"
|
2006-07-18 14:48:29 +00:00
|
|
|
#include "nsFaviconService.h"
|
|
|
|
#include "nsAnnotationService.h"
|
2007-04-04 17:21:03 +00:00
|
|
|
#include "nsPrintfCString.h"
|
2007-07-26 03:53:59 +00:00
|
|
|
#include "nsIUUIDGenerator.h"
|
|
|
|
#include "prprf.h"
|
2008-01-25 17:11:14 +00:00
|
|
|
#include "nsILivemarkService.h"
|
2008-08-04 16:59:56 +00:00
|
|
|
#include "nsPlacesTriggers.h"
|
2008-08-04 17:14:17 +00:00
|
|
|
#include "nsPlacesTables.h"
|
2009-05-11 09:05:56 +00:00
|
|
|
#include "nsPlacesIndexes.h"
|
2009-03-25 20:31:36 +00:00
|
|
|
#include "nsPlacesMacros.h"
|
2010-01-16 11:38:02 +00:00
|
|
|
#include "Helpers.h"
|
2006-07-18 14:27:16 +00:00
|
|
|
|
2010-05-19 23:22:19 +00:00
|
|
|
#include "mozilla/FunctionTimer.h"
|
|
|
|
|
2010-08-09 15:59:43 +00:00
|
|
|
#define BOOKMARKS_TO_KEYWORDS_INITIAL_CACHE_SIZE 64
|
|
|
|
|
2007-02-26 00:54:36 +00:00
|
|
|
const PRInt32 nsNavBookmarks::kFindBookmarksIndex_ID = 0;
|
2007-04-04 17:21:03 +00:00
|
|
|
const PRInt32 nsNavBookmarks::kFindBookmarksIndex_Type = 1;
|
2008-11-05 22:02:12 +00:00
|
|
|
const PRInt32 nsNavBookmarks::kFindBookmarksIndex_PlaceID = 2;
|
2007-02-26 00:54:36 +00:00
|
|
|
const PRInt32 nsNavBookmarks::kFindBookmarksIndex_Parent = 3;
|
|
|
|
const PRInt32 nsNavBookmarks::kFindBookmarksIndex_Position = 4;
|
|
|
|
const PRInt32 nsNavBookmarks::kFindBookmarksIndex_Title = 5;
|
2006-07-18 14:27:16 +00:00
|
|
|
|
|
|
|
// These columns sit to the right of the kGetInfoIndex_* columns.
|
2011-04-13 20:15:41 +00:00
|
|
|
const PRInt32 nsNavBookmarks::kGetChildrenIndex_Position = 14;
|
|
|
|
const PRInt32 nsNavBookmarks::kGetChildrenIndex_Type = 15;
|
|
|
|
const PRInt32 nsNavBookmarks::kGetChildrenIndex_PlaceID = 16;
|
|
|
|
const PRInt32 nsNavBookmarks::kGetChildrenIndex_ServiceContractId = 17;
|
2007-02-26 00:54:36 +00:00
|
|
|
|
2007-05-09 01:19:12 +00:00
|
|
|
const PRInt32 nsNavBookmarks::kGetItemPropertiesIndex_ID = 0;
|
|
|
|
const PRInt32 nsNavBookmarks::kGetItemPropertiesIndex_URI = 1;
|
|
|
|
const PRInt32 nsNavBookmarks::kGetItemPropertiesIndex_Title = 2;
|
|
|
|
const PRInt32 nsNavBookmarks::kGetItemPropertiesIndex_Position = 3;
|
|
|
|
const PRInt32 nsNavBookmarks::kGetItemPropertiesIndex_PlaceID = 4;
|
|
|
|
const PRInt32 nsNavBookmarks::kGetItemPropertiesIndex_Parent = 5;
|
|
|
|
const PRInt32 nsNavBookmarks::kGetItemPropertiesIndex_Type = 6;
|
2007-08-02 20:19:44 +00:00
|
|
|
const PRInt32 nsNavBookmarks::kGetItemPropertiesIndex_ServiceContractId = 7;
|
2007-05-19 00:40:55 +00:00
|
|
|
const PRInt32 nsNavBookmarks::kGetItemPropertiesIndex_DateAdded = 8;
|
|
|
|
const PRInt32 nsNavBookmarks::kGetItemPropertiesIndex_LastModified = 9;
|
2006-07-18 14:27:16 +00:00
|
|
|
|
2010-04-27 11:25:05 +00:00
|
|
|
using namespace mozilla::places;
|
2009-06-24 08:59:14 +00:00
|
|
|
|
2009-12-01 13:00:45 +00:00
|
|
|
PLACES_FACTORY_SINGLETON_IMPLEMENTATION(nsNavBookmarks, gBookmarksService)
|
2006-07-18 14:27:16 +00:00
|
|
|
|
2006-07-18 14:36:24 +00:00
|
|
|
#define BOOKMARKS_ANNO_PREFIX "bookmarks/"
|
2007-06-01 00:35:49 +00:00
|
|
|
#define BOOKMARKS_TOOLBAR_FOLDER_ANNO NS_LITERAL_CSTRING(BOOKMARKS_ANNO_PREFIX "toolbarFolder")
|
2007-07-26 03:53:59 +00:00
|
|
|
#define GUID_ANNO NS_LITERAL_CSTRING("placesInternal/GUID")
|
2007-08-02 20:19:44 +00:00
|
|
|
#define READ_ONLY_ANNO NS_LITERAL_CSTRING("placesInternal/READ_ONLY")
|
2006-07-18 14:36:24 +00:00
|
|
|
|
2010-08-09 15:59:43 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct keywordSearchData
|
|
|
|
{
|
|
|
|
PRInt64 itemId;
|
|
|
|
nsString keyword;
|
|
|
|
};
|
|
|
|
|
|
|
|
PLDHashOperator
|
|
|
|
SearchBookmarkForKeyword(nsTrimInt64HashKey::KeyType aKey,
|
|
|
|
const nsString aValue,
|
|
|
|
void* aUserArg)
|
|
|
|
{
|
|
|
|
keywordSearchData* data = reinterpret_cast<keywordSearchData*>(aUserArg);
|
|
|
|
if (data->keyword.Equals(aValue)) {
|
|
|
|
data->itemId = aKey;
|
|
|
|
return PL_DHASH_STOP;
|
|
|
|
}
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2010-12-20 17:21:49 +00:00
|
|
|
template<typename Method, typename DataType>
|
|
|
|
class AsyncGetBookmarksForURI : public AsyncStatementCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AsyncGetBookmarksForURI(nsNavBookmarks* aBookmarksSvc,
|
|
|
|
Method aCallback,
|
2011-02-05 12:22:10 +00:00
|
|
|
const DataType& aData)
|
2010-12-20 17:21:49 +00:00
|
|
|
: mBookmarksSvc(aBookmarksSvc)
|
|
|
|
, mCallback(aCallback)
|
|
|
|
, mData(aData)
|
2011-02-05 12:22:10 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Init()
|
2010-12-20 17:21:49 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<mozIStorageStatement> stmt =
|
2011-02-05 12:22:10 +00:00
|
|
|
mBookmarksSvc->GetStatementById(DB_GET_BOOKMARKS_FOR_URI);
|
2010-12-20 17:21:49 +00:00
|
|
|
if (stmt) {
|
2011-02-05 12:22:10 +00:00
|
|
|
(void)URIBinder::Bind(stmt, NS_LITERAL_CSTRING("page_url"), mData.uri);
|
2010-12-20 17:21:49 +00:00
|
|
|
nsCOMPtr<mozIStoragePendingStatement> pendingStmt;
|
|
|
|
(void)stmt->ExecuteAsync(this, getter_AddRefs(pendingStmt));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD HandleResult(mozIStorageResultSet* aResultSet)
|
|
|
|
{
|
|
|
|
nsCOMPtr<mozIStorageRow> row;
|
|
|
|
while (NS_SUCCEEDED(aResultSet->GetNextRow(getter_AddRefs(row))) && row) {
|
|
|
|
nsresult rv = row->GetInt64(0, &mData.itemId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (mCallback) {
|
|
|
|
((*mBookmarksSvc).*mCallback)(mData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsRefPtr<nsNavBookmarks> mBookmarksSvc;
|
|
|
|
Method mCallback;
|
|
|
|
DataType mData;
|
|
|
|
};
|
|
|
|
|
2010-08-09 15:59:43 +00:00
|
|
|
} // Anonymous namespace.
|
|
|
|
|
|
|
|
|
2009-10-05 10:12:38 +00:00
|
|
|
nsNavBookmarks::nsNavBookmarks() : mItemCount(0)
|
|
|
|
, mRoot(0)
|
2010-10-21 00:51:18 +00:00
|
|
|
, mMenuRoot(0)
|
|
|
|
, mTagsRoot(0)
|
|
|
|
, mUnfiledRoot(0)
|
|
|
|
, mToolbarRoot(0)
|
2009-10-05 10:12:38 +00:00
|
|
|
, mCanNotify(false)
|
|
|
|
, mCacheObservers("bookmark-observers")
|
2010-01-16 11:37:57 +00:00
|
|
|
, mShuttingDown(false)
|
2010-12-03 01:37:53 +00:00
|
|
|
, mBatching(false)
|
2006-07-18 14:27:16 +00:00
|
|
|
{
|
2009-12-01 13:00:45 +00:00
|
|
|
NS_ASSERTION(!gBookmarksService,
|
|
|
|
"Attempting to create two instances of the service!");
|
|
|
|
gBookmarksService = this;
|
2006-07-18 14:27:16 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:27:16 +00:00
|
|
|
nsNavBookmarks::~nsNavBookmarks()
|
|
|
|
{
|
2009-12-01 13:00:45 +00:00
|
|
|
NS_ASSERTION(gBookmarksService == this,
|
|
|
|
"Deleting a non-singleton instance of the service");
|
|
|
|
if (gBookmarksService == this)
|
|
|
|
gBookmarksService = nsnull;
|
2006-07-18 14:27:16 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
NS_IMPL_ISUPPORTS3(nsNavBookmarks,
|
|
|
|
nsINavBookmarksService,
|
|
|
|
nsINavHistoryObserver,
|
|
|
|
nsIAnnotationObserver)
|
2006-07-18 14:27:16 +00:00
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:27:16 +00:00
|
|
|
nsresult
|
|
|
|
nsNavBookmarks::Init()
|
|
|
|
{
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION;
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavHistory* history = nsNavHistory::GetHistoryService();
|
2008-10-27 22:52:21 +00:00
|
|
|
NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
mDBConn = history->GetStorageConnection();
|
2010-01-16 11:38:00 +00:00
|
|
|
NS_ENSURE_STATE(mDBConn);
|
2010-11-29 17:33:26 +00:00
|
|
|
|
|
|
|
// Get our read-only cloned connection.
|
|
|
|
nsresult rv = mDBConn->Clone(PR_TRUE, getter_AddRefs(mDBReadOnlyConn));
|
2010-10-21 00:51:18 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-10-27 22:52:21 +00:00
|
|
|
|
2010-11-29 17:33:26 +00:00
|
|
|
PRUint16 dbStatus;
|
|
|
|
rv = history->GetDatabaseStatus(&dbStatus);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-10-21 00:51:18 +00:00
|
|
|
rv = InitRoots(dbStatus != nsINavHistoryService::DATABASE_STATUS_OK);
|
2008-10-27 22:52:21 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-03-25 20:31:36 +00:00
|
|
|
mCanNotify = true;
|
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
// Observe annotations.
|
2008-10-27 22:52:21 +00:00
|
|
|
nsAnnotationService* annosvc = nsAnnotationService::GetAnnotationService();
|
|
|
|
NS_ENSURE_TRUE(annosvc, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
annosvc->AddObserver(this);
|
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
// Allows us to notify on title changes. MUST BE LAST so it is impossible
|
2008-10-27 22:52:21 +00:00
|
|
|
// to fail after this call, or the history service will have a reference to
|
|
|
|
// us and we won't go away.
|
|
|
|
history->AddObserver(this, PR_FALSE);
|
|
|
|
|
|
|
|
// DO NOT PUT STUFF HERE that can fail. See observer comment above.
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
/**
|
|
|
|
* All commands that initialize the database schema should be here.
|
|
|
|
* This is called from history init after database connection has been
|
|
|
|
* established.
|
|
|
|
*/
|
2008-10-27 22:52:21 +00:00
|
|
|
nsresult // static
|
|
|
|
nsNavBookmarks::InitTables(mozIStorageConnection* aDBConn)
|
|
|
|
{
|
|
|
|
PRBool exists;
|
|
|
|
nsresult rv = aDBConn->TableExists(NS_LITERAL_CSTRING("moz_bookmarks"), &exists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-10-21 00:51:18 +00:00
|
|
|
if (!exists) {
|
2008-10-27 22:52:21 +00:00
|
|
|
rv = aDBConn->ExecuteSimpleSQL(CREATE_MOZ_BOOKMARKS);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// This index will make it faster to determine if a given item is
|
|
|
|
// bookmarked (used by history queries and vacuuming, for example).
|
|
|
|
// Making it compound with "type" speeds up type-differentiation
|
|
|
|
// queries, such as expiration and search.
|
2009-05-11 09:05:56 +00:00
|
|
|
rv = aDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_BOOKMARKS_PLACETYPE);
|
2006-07-18 14:27:16 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-10-27 22:52:21 +00:00
|
|
|
|
|
|
|
// The most common operation is to find the children given a parent and position.
|
2009-05-11 09:05:56 +00:00
|
|
|
rv = aDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_BOOKMARKS_PARENTPOSITION);
|
2007-04-04 17:21:03 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 14:27:16 +00:00
|
|
|
|
2008-10-27 22:52:21 +00:00
|
|
|
// fast access to lastModified is useful during sync and to get
|
|
|
|
// last modified bookmark title for tags container's children.
|
2009-05-11 09:05:56 +00:00
|
|
|
rv = aDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_BOOKMARKS_PLACELASTMODIFIED);
|
2006-07-18 14:27:16 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-12-02 17:40:18 +00:00
|
|
|
|
|
|
|
// Selecting by guid needs to be fast.
|
|
|
|
rv = aDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_BOOKMARKS_GUID);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 14:27:16 +00:00
|
|
|
}
|
|
|
|
|
2008-10-27 22:52:21 +00:00
|
|
|
rv = aDBConn->TableExists(NS_LITERAL_CSTRING("moz_bookmarks_roots"), &exists);
|
2006-07-18 14:30:13 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-10-27 22:52:21 +00:00
|
|
|
if (!exists) {
|
|
|
|
rv = aDBConn->ExecuteSimpleSQL(CREATE_MOZ_BOOKMARKS_ROOTS);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = aDBConn->TableExists(NS_LITERAL_CSTRING("moz_keywords"), &exists);
|
2006-07-18 14:30:13 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-10-21 00:51:18 +00:00
|
|
|
if (!exists) {
|
2008-10-27 22:52:21 +00:00
|
|
|
rv = aDBConn->ExecuteSimpleSQL(CREATE_MOZ_KEYWORDS);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Create trigger to update as well
|
|
|
|
rv = aDBConn->ExecuteSimpleSQL(CREATE_KEYWORD_VALIDITY_TRIGGER);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-07-18 14:30:13 +00:00
|
|
|
|
2008-10-27 22:52:21 +00:00
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
mozIStorageStatement*
|
|
|
|
nsNavBookmarks::GetStatement(const nsCOMPtr<mozIStorageStatement>& aStmt)
|
2008-10-27 22:52:21 +00:00
|
|
|
{
|
2010-01-16 11:38:00 +00:00
|
|
|
if (mShuttingDown)
|
|
|
|
return nsnull;
|
|
|
|
|
2009-06-24 08:59:14 +00:00
|
|
|
// Double ordering covers possible lastModified ties, that could happen when
|
|
|
|
// importing, syncing or due to extensions.
|
2010-08-09 15:59:59 +00:00
|
|
|
// Note: not using a JOIN is cheaper in this case.
|
2010-01-16 11:38:00 +00:00
|
|
|
RETURN_IF_STMT(mDBFindURIBookmarks, NS_LITERAL_CSTRING(
|
|
|
|
"SELECT b.id "
|
|
|
|
"FROM moz_bookmarks b "
|
2010-08-09 15:59:59 +00:00
|
|
|
"WHERE b.fk = (SELECT id FROM moz_places WHERE url = :page_url) "
|
2010-01-16 11:38:00 +00:00
|
|
|
"ORDER BY b.lastModified DESC, b.id DESC "));
|
2007-10-11 06:42:38 +00:00
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
// Select all children of a given folder, sorted by position.
|
2010-10-27 12:53:22 +00:00
|
|
|
// This is a LEFT JOIN because not all bookmarks types have a place.
|
2010-01-16 11:38:00 +00:00
|
|
|
// We construct a result where the first columns exactly match those returned
|
|
|
|
// by mDBGetURLPageInfo, and additionally contains columns for position,
|
|
|
|
// item_child, and folder_child from moz_bookmarks.
|
|
|
|
RETURN_IF_STMT(mDBGetChildren, NS_LITERAL_CSTRING(
|
2010-08-09 15:59:59 +00:00
|
|
|
"SELECT h.id, h.url, IFNULL(b.title, h.title), h.rev_host, h.visit_count, "
|
|
|
|
"h.last_visit_date, f.url, null, b.id, b.dateAdded, b.lastModified, "
|
2011-04-13 20:15:41 +00:00
|
|
|
"b.parent, null, h.frecency, b.position, b.type, b.fk, b.folder_type "
|
2010-01-16 11:38:00 +00:00
|
|
|
"FROM moz_bookmarks b "
|
|
|
|
"LEFT JOIN moz_places h ON b.fk = h.id "
|
|
|
|
"LEFT JOIN moz_favicons f ON h.favicon_id = f.id "
|
2010-04-27 11:25:05 +00:00
|
|
|
"WHERE b.parent = :parent "
|
2010-01-16 11:38:00 +00:00
|
|
|
"ORDER BY b.position ASC"));
|
|
|
|
|
|
|
|
// Count all of the children of a given folder and checks that it exists.
|
|
|
|
RETURN_IF_STMT(mDBFolderCount, NS_LITERAL_CSTRING(
|
|
|
|
"SELECT COUNT(*), "
|
2010-04-27 11:25:05 +00:00
|
|
|
"(SELECT id FROM moz_bookmarks WHERE id = :parent) "
|
|
|
|
"FROM moz_bookmarks WHERE parent = :parent"));
|
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
RETURN_IF_STMT(mDBGetChildAt, NS_LITERAL_CSTRING(
|
|
|
|
"SELECT id, fk, type FROM moz_bookmarks "
|
2010-04-27 11:25:05 +00:00
|
|
|
"WHERE parent = :parent AND position = :item_index"));
|
2010-01-16 11:38:00 +00:00
|
|
|
|
|
|
|
// Get bookmark/folder/separator properties.
|
2010-10-27 12:53:22 +00:00
|
|
|
// This is a LEFT JOIN because not all bookmarks types have a place.
|
2010-01-16 11:38:00 +00:00
|
|
|
RETURN_IF_STMT(mDBGetItemProperties, NS_LITERAL_CSTRING(
|
2010-10-27 12:53:22 +00:00
|
|
|
"SELECT b.id, h.url, b.title, b.position, b.fk, b.parent, b.type, "
|
|
|
|
"b.folder_type, b.dateAdded, b.lastModified "
|
2010-01-16 11:38:00 +00:00
|
|
|
"FROM moz_bookmarks b "
|
2010-10-27 12:53:22 +00:00
|
|
|
"LEFT JOIN moz_places h ON h.id = b.fk "
|
2010-04-27 11:25:05 +00:00
|
|
|
"WHERE b.id = :item_id"));
|
2010-01-16 11:38:00 +00:00
|
|
|
|
|
|
|
RETURN_IF_STMT(mDBGetItemIdForGUID, NS_LITERAL_CSTRING(
|
|
|
|
"SELECT item_id FROM moz_items_annos "
|
2010-04-27 11:25:05 +00:00
|
|
|
"WHERE content = :guid "
|
2010-01-16 11:38:00 +00:00
|
|
|
"LIMIT 1"));
|
2007-07-26 03:53:59 +00:00
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
RETURN_IF_STMT(mDBInsertBookmark, NS_LITERAL_CSTRING(
|
|
|
|
"INSERT INTO moz_bookmarks "
|
|
|
|
"(id, fk, type, parent, position, title, folder_type, "
|
2010-12-02 22:03:07 +00:00
|
|
|
"dateAdded, lastModified, guid) "
|
2010-04-27 11:25:05 +00:00
|
|
|
"VALUES (:item_id, :page_id, :item_type, :parent, :item_index, "
|
2010-12-02 22:03:07 +00:00
|
|
|
":item_title, :folder_type, :date_added, :last_modified, "
|
|
|
|
"GENERATE_GUID())"));
|
2007-11-09 21:21:38 +00:00
|
|
|
|
|
|
|
// Just select position since it's just an int32 and may be faster.
|
|
|
|
// We don't actually care about the data, just whether there is any.
|
2010-01-16 11:38:00 +00:00
|
|
|
RETURN_IF_STMT(mDBIsBookmarkedInDatabase, NS_LITERAL_CSTRING(
|
2010-04-27 11:25:05 +00:00
|
|
|
"SELECT 1 FROM moz_bookmarks WHERE fk = :page_id"));
|
2010-03-10 12:40:52 +00:00
|
|
|
|
|
|
|
RETURN_IF_STMT(mDBIsURIBookmarkedInDatabase, NS_LITERAL_CSTRING(
|
2010-08-09 15:59:59 +00:00
|
|
|
"SELECT 1 FROM moz_bookmarks b "
|
|
|
|
"JOIN moz_places h ON b.fk = h.id "
|
|
|
|
"WHERE h.url = :page_url"));
|
2007-11-09 21:21:38 +00:00
|
|
|
|
2010-03-10 12:40:52 +00:00
|
|
|
// Checks to make sure a place id is a bookmark, and isn't a livemark.
|
2010-01-16 11:38:00 +00:00
|
|
|
RETURN_IF_STMT(mDBIsRealBookmark, NS_LITERAL_CSTRING(
|
|
|
|
"SELECT id "
|
|
|
|
"FROM moz_bookmarks "
|
2010-04-27 11:25:05 +00:00
|
|
|
"WHERE fk = :page_id "
|
|
|
|
"AND type = :item_type "
|
2010-01-16 11:38:00 +00:00
|
|
|
"AND parent NOT IN ("
|
|
|
|
"SELECT a.item_id "
|
|
|
|
"FROM moz_items_annos a "
|
|
|
|
"JOIN moz_anno_attributes n ON a.anno_attribute_id = n.id "
|
2010-04-27 11:25:05 +00:00
|
|
|
"WHERE n.name = :anno_name"
|
2010-10-27 12:53:22 +00:00
|
|
|
") "));
|
2010-01-16 11:38:00 +00:00
|
|
|
|
|
|
|
RETURN_IF_STMT(mDBGetLastBookmarkID, NS_LITERAL_CSTRING(
|
|
|
|
"SELECT id "
|
|
|
|
"FROM moz_bookmarks "
|
|
|
|
"ORDER BY ROWID DESC "
|
|
|
|
"LIMIT 1"));
|
2008-08-16 22:28:28 +00:00
|
|
|
|
2009-06-24 08:59:14 +00:00
|
|
|
// lastModified is set to the same value as dateAdded. We do this for
|
|
|
|
// performance reasons, since it will allow us to use an index to sort items
|
|
|
|
// by date.
|
2010-01-16 11:38:00 +00:00
|
|
|
RETURN_IF_STMT(mDBSetItemDateAdded, NS_LITERAL_CSTRING(
|
2010-04-27 11:25:05 +00:00
|
|
|
"UPDATE moz_bookmarks SET dateAdded = :date, lastModified = :date "
|
|
|
|
"WHERE id = :item_id"));
|
2010-01-16 11:38:00 +00:00
|
|
|
|
|
|
|
RETURN_IF_STMT(mDBSetItemLastModified, NS_LITERAL_CSTRING(
|
2010-04-27 11:25:05 +00:00
|
|
|
"UPDATE moz_bookmarks SET lastModified = :date WHERE id = :item_id"));
|
2010-01-16 11:38:00 +00:00
|
|
|
|
|
|
|
RETURN_IF_STMT(mDBSetItemIndex, NS_LITERAL_CSTRING(
|
2010-04-27 11:25:05 +00:00
|
|
|
"UPDATE moz_bookmarks SET position = :item_index WHERE id = :item_id"));
|
2010-01-16 11:38:00 +00:00
|
|
|
|
|
|
|
RETURN_IF_STMT(mDBGetKeywordForURI, NS_LITERAL_CSTRING(
|
|
|
|
"SELECT k.keyword "
|
2010-08-09 15:59:59 +00:00
|
|
|
"FROM moz_places h "
|
2010-01-16 11:38:00 +00:00
|
|
|
"JOIN moz_bookmarks b ON b.fk = h.id "
|
2010-08-09 15:59:59 +00:00
|
|
|
"JOIN moz_keywords k ON k.id = b.keyword_id "
|
|
|
|
"WHERE h.url = :page_url "));
|
2010-01-16 11:38:00 +00:00
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
RETURN_IF_STMT(mDBAdjustPosition, NS_LITERAL_CSTRING(
|
2010-04-27 11:25:05 +00:00
|
|
|
"UPDATE moz_bookmarks SET position = position + :delta "
|
|
|
|
"WHERE parent = :parent "
|
2010-10-27 12:53:22 +00:00
|
|
|
"AND position BETWEEN :from_index AND :to_index"));
|
2010-01-16 11:37:57 +00:00
|
|
|
|
|
|
|
RETURN_IF_STMT(mDBRemoveItem, NS_LITERAL_CSTRING(
|
2010-04-27 11:25:05 +00:00
|
|
|
"DELETE FROM moz_bookmarks WHERE id = :item_id"));
|
2010-01-16 11:37:57 +00:00
|
|
|
|
|
|
|
RETURN_IF_STMT(mDBGetLastChildId, NS_LITERAL_CSTRING(
|
2010-04-27 11:25:05 +00:00
|
|
|
"SELECT id FROM moz_bookmarks WHERE parent = :parent "
|
2010-01-16 11:37:57 +00:00
|
|
|
"ORDER BY position DESC LIMIT 1"));
|
|
|
|
|
|
|
|
RETURN_IF_STMT(mDBMoveItem, NS_LITERAL_CSTRING(
|
2010-04-27 11:25:05 +00:00
|
|
|
"UPDATE moz_bookmarks SET parent = :parent, position = :item_index "
|
|
|
|
"WHERE id = :item_id "));
|
2010-01-16 11:37:57 +00:00
|
|
|
|
|
|
|
RETURN_IF_STMT(mDBSetItemTitle, NS_LITERAL_CSTRING(
|
2010-04-27 11:25:05 +00:00
|
|
|
"UPDATE moz_bookmarks SET title = :item_title, lastModified = :date "
|
|
|
|
"WHERE id = :item_id "));
|
2010-01-16 11:37:57 +00:00
|
|
|
|
|
|
|
RETURN_IF_STMT(mDBChangeBookmarkURI, NS_LITERAL_CSTRING(
|
2010-04-27 11:25:05 +00:00
|
|
|
"UPDATE moz_bookmarks SET fk = :page_id, lastModified = :date "
|
|
|
|
"WHERE id = :item_id "));
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2010-03-10 12:40:52 +00:00
|
|
|
// The next query finds the bookmarked ancestors in a redirects chain.
|
|
|
|
// It won't go further than 3 levels of redirects (a->b->c->your_place_id).
|
|
|
|
// To make this path 100% correct (up to any level) we would need either:
|
|
|
|
// - A separate hash, build through recursive querying of the database.
|
|
|
|
// This solution was previously implemented, but it had a negative effect
|
|
|
|
// on startup since at each startup we have to recursively query the
|
|
|
|
// database to rebuild a hash that is always the same across sessions.
|
|
|
|
// It must be updated at each visit and bookmarks change too. The code to
|
|
|
|
// manage it is complex and prone to errors, sometimes causing incorrect
|
|
|
|
// data fetches (for example wrong favicon for a redirected bookmark).
|
|
|
|
// - A better way to track redirects for a visit.
|
|
|
|
// We would need a separate table to track redirects, in the table we would
|
|
|
|
// have visit_id, redirect_session. To get all sources for
|
|
|
|
// a visit then we could just join this table and get all visit_id that
|
|
|
|
// are in the same redirect_session as our visit. This has the drawback
|
|
|
|
// that we can't ensure data integrity in the downgrade -> upgrade path,
|
|
|
|
// since an old version would not update the table on new visits.
|
|
|
|
//
|
|
|
|
// For most cases these levels of redirects should be fine though, it's hard
|
|
|
|
// to hit a page that is 4 or 5 levels of redirects below a bookmarked page.
|
|
|
|
//
|
|
|
|
// As a bonus the query also checks first if place_id is already a bookmark,
|
|
|
|
// so you don't have to check that apart.
|
|
|
|
|
|
|
|
#define COALESCE_PLACEID \
|
|
|
|
"COALESCE(greatgrandparent.place_id, grandparent.place_id, parent.place_id) "
|
|
|
|
|
|
|
|
nsCString redirectsFragment =
|
|
|
|
nsPrintfCString(3, "%d,%d",
|
|
|
|
nsINavHistoryService::TRANSITION_REDIRECT_PERMANENT,
|
|
|
|
nsINavHistoryService::TRANSITION_REDIRECT_TEMPORARY);
|
|
|
|
|
|
|
|
RETURN_IF_STMT(mDBFindRedirectedBookmark, NS_LITERAL_CSTRING(
|
2010-08-09 15:59:59 +00:00
|
|
|
"SELECT "
|
2010-04-27 11:25:03 +00:00
|
|
|
"(SELECT url FROM moz_places WHERE id = :page_id) "
|
2010-03-10 12:40:52 +00:00
|
|
|
"FROM moz_bookmarks b "
|
2010-04-27 11:25:03 +00:00
|
|
|
"WHERE b.fk = :page_id "
|
2010-03-10 12:40:52 +00:00
|
|
|
"UNION ALL " // Not directly bookmarked.
|
2010-08-09 15:59:59 +00:00
|
|
|
"SELECT "
|
2010-03-10 12:40:52 +00:00
|
|
|
"(SELECT url FROM moz_places WHERE id = " COALESCE_PLACEID ") "
|
|
|
|
"FROM moz_historyvisits self "
|
|
|
|
"JOIN moz_bookmarks b ON b.fk = " COALESCE_PLACEID
|
|
|
|
"LEFT JOIN moz_historyvisits parent ON parent.id = self.from_visit "
|
|
|
|
"LEFT JOIN moz_historyvisits grandparent ON parent.from_visit = grandparent.id "
|
|
|
|
"AND parent.visit_type IN (") + redirectsFragment + NS_LITERAL_CSTRING(") "
|
|
|
|
"LEFT JOIN moz_historyvisits greatgrandparent ON grandparent.from_visit = greatgrandparent.id "
|
|
|
|
"AND grandparent.visit_type IN (") + redirectsFragment + NS_LITERAL_CSTRING(") "
|
|
|
|
"WHERE self.visit_type IN (") + redirectsFragment + NS_LITERAL_CSTRING(") "
|
2010-04-27 11:25:03 +00:00
|
|
|
"AND self.place_id = :page_id "
|
2010-03-10 12:40:52 +00:00
|
|
|
"LIMIT 1 " // Stop at the first result.
|
|
|
|
));
|
|
|
|
#undef COALESCE_PLACEID
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-14 06:45:49 +00:00
|
|
|
nsresult
|
|
|
|
nsNavBookmarks::FinalizeStatements() {
|
2010-01-16 11:37:57 +00:00
|
|
|
mShuttingDown = true;
|
|
|
|
|
2008-11-14 06:45:49 +00:00
|
|
|
mozIStorageStatement* stmts[] = {
|
|
|
|
mDBGetChildren,
|
|
|
|
mDBFindURIBookmarks,
|
|
|
|
mDBFolderCount,
|
|
|
|
mDBGetChildAt,
|
|
|
|
mDBGetItemProperties,
|
|
|
|
mDBGetItemIdForGUID,
|
|
|
|
mDBInsertBookmark,
|
|
|
|
mDBIsBookmarkedInDatabase,
|
2009-01-28 02:01:33 +00:00
|
|
|
mDBIsRealBookmark,
|
2008-11-14 06:45:49 +00:00
|
|
|
mDBGetLastBookmarkID,
|
|
|
|
mDBSetItemDateAdded,
|
|
|
|
mDBSetItemLastModified,
|
|
|
|
mDBSetItemIndex,
|
|
|
|
mDBGetKeywordForURI,
|
2010-01-16 11:37:57 +00:00
|
|
|
mDBAdjustPosition,
|
|
|
|
mDBRemoveItem,
|
|
|
|
mDBGetLastChildId,
|
|
|
|
mDBMoveItem,
|
|
|
|
mDBSetItemTitle,
|
|
|
|
mDBChangeBookmarkURI,
|
2010-03-10 12:40:52 +00:00
|
|
|
mDBIsURIBookmarkedInDatabase,
|
|
|
|
mDBFindRedirectedBookmark,
|
2008-11-14 06:45:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(stmts); i++) {
|
|
|
|
nsresult rv = nsNavHistory::FinalizeStatement(stmts[i]);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2010-11-29 17:33:26 +00:00
|
|
|
// Since we are shutting down, close the read-only connection.
|
|
|
|
(void)mDBReadOnlyConn->AsyncClose(nsnull);
|
|
|
|
|
2010-12-02 22:03:07 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
// Sanity check that all bookmarks have guids.
|
|
|
|
nsCOMPtr<mozIStorageStatement> stmt;
|
|
|
|
nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
|
|
|
"SELECT * "
|
|
|
|
"FROM moz_bookmarks "
|
|
|
|
"WHERE guid IS NULL "
|
|
|
|
), getter_AddRefs(stmt));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRBool haveNullGuids;
|
|
|
|
rv = stmt->ExecuteStep(&haveNullGuids);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ASSERTION(!haveNullGuids,
|
|
|
|
"Someone added a bookmark without adding a GUID!");
|
|
|
|
#endif
|
|
|
|
|
2008-11-14 06:45:49 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-07-18 14:46:48 +00:00
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:33:42 +00:00
|
|
|
nsresult
|
2010-10-21 00:51:18 +00:00
|
|
|
nsNavBookmarks::InitRoots(bool aForceCreate)
|
2006-07-18 14:33:42 +00:00
|
|
|
{
|
2010-10-21 00:51:18 +00:00
|
|
|
nsCOMPtr<mozIStorageStatement> stmt;
|
2010-11-29 17:33:26 +00:00
|
|
|
nsresult rv = mDBReadOnlyConn->CreateStatement(NS_LITERAL_CSTRING(
|
2010-10-21 00:51:18 +00:00
|
|
|
"SELECT root_name, folder_id FROM moz_bookmarks_roots"
|
|
|
|
), getter_AddRefs(stmt));
|
2006-07-18 14:33:42 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-10-21 00:51:18 +00:00
|
|
|
PRBool hasResult;
|
|
|
|
while (NS_SUCCEEDED(stmt->ExecuteStep(&hasResult)) && hasResult) {
|
|
|
|
nsCAutoString rootName;
|
|
|
|
rv = stmt->GetUTF8String(0, rootName);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-10-21 00:51:18 +00:00
|
|
|
PRInt64 rootId;
|
|
|
|
rv = stmt->GetInt64(1, &rootId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ABORT_IF_FALSE(rootId != 0, "Root id is 0, that is an invalid value.");
|
|
|
|
|
|
|
|
if (rootName.EqualsLiteral("places")) {
|
|
|
|
mRoot = rootId;
|
|
|
|
}
|
|
|
|
else if (rootName.EqualsLiteral("menu")) {
|
|
|
|
mMenuRoot = rootId;
|
|
|
|
}
|
|
|
|
else if (rootName.EqualsLiteral("toolbar")) {
|
|
|
|
mToolbarRoot = rootId;
|
|
|
|
}
|
|
|
|
else if (rootName.EqualsLiteral("tags")) {
|
|
|
|
mTagsRoot = rootId;
|
|
|
|
}
|
|
|
|
else if (rootName.EqualsLiteral("unfiled")) {
|
|
|
|
mUnfiledRoot = rootId;
|
2007-11-20 02:01:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-21 00:51:18 +00:00
|
|
|
if (aForceCreate) {
|
|
|
|
nsNavHistory* history = nsNavHistory::GetHistoryService();
|
|
|
|
NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
nsIStringBundle* bundle = history->GetBundle();
|
|
|
|
NS_ENSURE_TRUE(bundle, NS_ERROR_OUT_OF_MEMORY);
|
2006-07-18 14:48:29 +00:00
|
|
|
|
2010-10-21 00:51:18 +00:00
|
|
|
mozStorageTransaction transaction(mDBConn, PR_FALSE);
|
2007-09-17 01:42:15 +00:00
|
|
|
|
2010-10-21 00:51:18 +00:00
|
|
|
rv = CreateRoot(NS_LITERAL_CSTRING("places"), &mRoot, 0,
|
|
|
|
nsnull, nsnull);
|
2006-07-18 14:33:42 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-10-21 00:51:18 +00:00
|
|
|
rv = CreateRoot(NS_LITERAL_CSTRING("menu"), &mMenuRoot, mRoot, bundle,
|
|
|
|
NS_LITERAL_STRING("BookmarksMenuFolderTitle").get());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2010-10-21 00:51:18 +00:00
|
|
|
rv = CreateRoot(NS_LITERAL_CSTRING("toolbar"), &mToolbarRoot, mRoot, bundle,
|
|
|
|
NS_LITERAL_STRING("BookmarksToolbarFolderTitle").get());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-04-15 21:15:56 +00:00
|
|
|
|
2010-10-21 00:51:18 +00:00
|
|
|
rv = CreateRoot(NS_LITERAL_CSTRING("tags"), &mTagsRoot, mRoot, bundle,
|
|
|
|
NS_LITERAL_STRING("TagsFolderTitle").get());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-04-15 21:15:56 +00:00
|
|
|
|
2010-10-21 00:51:18 +00:00
|
|
|
rv = CreateRoot(NS_LITERAL_CSTRING("unfiled"), &mUnfiledRoot, mRoot, bundle,
|
|
|
|
NS_LITERAL_STRING("UnsortedBookmarksFolderTitle").get());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-03-07 21:22:54 +00:00
|
|
|
|
2010-10-21 00:51:18 +00:00
|
|
|
rv = transaction.Commit();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-12-03 01:37:53 +00:00
|
|
|
|
|
|
|
if (!mBatching) {
|
|
|
|
ForceWALCheckpoint(mDBConn);
|
|
|
|
}
|
2010-10-21 00:51:18 +00:00
|
|
|
}
|
2007-06-01 00:35:49 +00:00
|
|
|
|
2007-03-07 21:22:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-07-18 14:33:42 +00:00
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:33:42 +00:00
|
|
|
nsresult
|
2010-10-21 00:51:18 +00:00
|
|
|
nsNavBookmarks::CreateRoot(const nsCString& name,
|
|
|
|
PRInt64* _itemId,
|
|
|
|
PRInt64 aParentId,
|
|
|
|
nsIStringBundle* aBundle,
|
|
|
|
const PRUnichar* aTitleStringId)
|
2006-07-18 14:33:42 +00:00
|
|
|
{
|
2010-10-21 00:51:18 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
if (*_itemId == 0) {
|
|
|
|
// The root does not exist. Create a new untitled folder for it.
|
|
|
|
rv = CreateFolder(aParentId, EmptyCString(), DEFAULT_INDEX, _itemId);
|
2006-07-18 14:33:42 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-10-21 00:51:18 +00:00
|
|
|
// Create a entry in moz_bookmarks_roots to link the folder to the root.
|
|
|
|
nsCOMPtr<mozIStorageStatement> stmt;
|
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
|
|
|
"INSERT INTO moz_bookmarks_roots (root_name, folder_id) "
|
|
|
|
"VALUES (:root_name, :item_id)"
|
|
|
|
), getter_AddRefs(stmt));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = stmt->BindUTF8StringByName(NS_LITERAL_CSTRING("root_name"), name);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), *_itemId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = stmt->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2006-07-18 14:33:42 +00:00
|
|
|
|
2010-10-21 00:51:18 +00:00
|
|
|
// Now set the title on the root. Notice we do this regardless, to take in
|
|
|
|
// could title changes when schema changes.
|
|
|
|
if (aTitleStringId) {
|
|
|
|
nsXPIDLString title;
|
|
|
|
rv = aBundle->GetStringFromName(aTitleStringId, getter_Copies(title));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = SetItemTitle(*_itemId, NS_ConvertUTF16toUTF8(title));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2006-07-18 14:33:42 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2009-01-28 02:01:33 +00:00
|
|
|
PRBool
|
|
|
|
nsNavBookmarks::IsRealBookmark(PRInt64 aPlaceId)
|
|
|
|
{
|
2010-03-10 12:40:52 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBIsRealBookmark);
|
2010-04-27 11:25:05 +00:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("page_id"), aPlaceId);
|
2010-03-10 12:40:52 +00:00
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Binding failed");
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = stmt->BindInt32ByName(NS_LITERAL_CSTRING("item_type"), TYPE_BOOKMARK);
|
2010-03-10 12:40:52 +00:00
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Binding failed");
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = stmt->BindUTF8StringByName(NS_LITERAL_CSTRING("anno_name"),
|
|
|
|
NS_LITERAL_CSTRING(LMANNO_FEEDURI));
|
2010-03-10 12:40:52 +00:00
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Binding failed");
|
|
|
|
|
|
|
|
// If we get any rows, then there exists at least one bookmark corresponding
|
|
|
|
// to aPlaceId that is not a livemark item.
|
|
|
|
PRBool isBookmark;
|
|
|
|
rv = stmt->ExecuteStep(&isBookmark);
|
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "ExecuteStep failed");
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
return isBookmark;
|
2009-01-28 02:01:33 +00:00
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:46:00 +00:00
|
|
|
// nsNavBookmarks::IsBookmarkedInDatabase
|
|
|
|
//
|
2009-01-28 02:01:33 +00:00
|
|
|
// This checks to see if the specified place_id is actually bookmarked.
|
2006-07-18 14:46:00 +00:00
|
|
|
|
|
|
|
nsresult
|
2007-02-26 00:54:36 +00:00
|
|
|
nsNavBookmarks::IsBookmarkedInDatabase(PRInt64 aPlaceId,
|
2010-01-16 11:37:57 +00:00
|
|
|
PRBool* aIsBookmarked)
|
2006-07-18 14:46:00 +00:00
|
|
|
{
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBIsBookmarkedInDatabase);
|
2010-04-27 11:25:05 +00:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("page_id"), aPlaceId);
|
2006-07-18 14:46:00 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->ExecuteStep(aIsBookmarked);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
2006-07-18 14:46:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-18 14:27:16 +00:00
|
|
|
nsresult
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::AdjustIndices(PRInt64 aFolderId,
|
|
|
|
PRInt32 aStartIndex,
|
|
|
|
PRInt32 aEndIndex,
|
2006-07-18 14:27:16 +00:00
|
|
|
PRInt32 aDelta)
|
|
|
|
{
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ASSERTION(aStartIndex >= 0 && aEndIndex <= PR_INT32_MAX &&
|
|
|
|
aStartIndex <= aEndIndex, "Bad indices");
|
2006-07-18 14:38:44 +00:00
|
|
|
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBAdjustPosition);
|
2010-04-27 11:25:05 +00:00
|
|
|
nsresult rv = stmt->BindInt32ByName(NS_LITERAL_CSTRING("delta"), aDelta);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("parent"), aFolderId);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = stmt->BindInt32ByName(NS_LITERAL_CSTRING("from_index"), aStartIndex);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = stmt->BindInt32ByName(NS_LITERAL_CSTRING("to_index"), aEndIndex);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 14:27:16 +00:00
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
rv = stmt->Execute();
|
2006-07-18 14:29:04 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
2006-07-18 14:27:16 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:27:16 +00:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::GetPlacesRoot(PRInt64* aRoot)
|
2006-07-18 14:27:16 +00:00
|
|
|
{
|
|
|
|
*aRoot = mRoot;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:28:02 +00:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::GetBookmarksMenuFolder(PRInt64* aRoot)
|
2006-07-18 14:28:02 +00:00
|
|
|
{
|
2010-10-21 00:51:18 +00:00
|
|
|
*aRoot = mMenuRoot;
|
2006-07-18 14:28:02 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:28:02 +00:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::GetToolbarFolder(PRInt64* aFolderId)
|
2007-03-07 21:22:54 +00:00
|
|
|
{
|
2010-10-21 00:51:18 +00:00
|
|
|
*aFolderId = mToolbarRoot;
|
2007-03-07 21:22:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2007-03-07 21:22:54 +00:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::GetTagsFolder(PRInt64* aRoot)
|
2006-07-18 14:48:29 +00:00
|
|
|
{
|
2010-10-21 00:51:18 +00:00
|
|
|
*aRoot = mTagsRoot;
|
2006-07-18 14:48:29 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2007-09-17 01:42:15 +00:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::GetUnfiledBookmarksFolder(PRInt64* aRoot)
|
2007-09-17 01:42:15 +00:00
|
|
|
{
|
|
|
|
*aRoot = mUnfiledRoot;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2009-06-24 08:59:14 +00:00
|
|
|
nsresult
|
|
|
|
nsNavBookmarks::InsertBookmarkInDB(PRInt64 aItemId,
|
|
|
|
PRInt64 aPlaceId,
|
|
|
|
enum ItemType aItemType,
|
|
|
|
PRInt64 aParentId,
|
|
|
|
PRInt32 aIndex,
|
2010-01-16 11:37:57 +00:00
|
|
|
const nsACString& aTitle,
|
2009-06-24 08:59:14 +00:00
|
|
|
PRTime aDateAdded,
|
|
|
|
PRTime aLastModified,
|
2010-01-16 11:37:57 +00:00
|
|
|
const nsAString& aServiceContractId,
|
|
|
|
PRInt64* _newItemId)
|
2009-06-24 08:59:14 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(_newItemId, "Null pointer passed to InsertBookmarkInDB!");
|
|
|
|
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBInsertBookmark);
|
2009-06-24 08:59:14 +00:00
|
|
|
nsresult rv;
|
|
|
|
if (aItemId && aItemId != -1)
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2009-06-24 08:59:14 +00:00
|
|
|
else
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = stmt->BindNullByName(NS_LITERAL_CSTRING("item_id"));
|
2009-06-24 08:59:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (aPlaceId && aPlaceId != -1)
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("page_id"), aPlaceId);
|
2009-06-24 08:59:14 +00:00
|
|
|
else
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = stmt->BindNullByName(NS_LITERAL_CSTRING("page_id"));
|
2009-06-24 08:59:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = stmt->BindInt32ByName(NS_LITERAL_CSTRING("item_type"), aItemType);
|
2009-06-24 08:59:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("parent"), aParentId);
|
2009-06-24 08:59:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = stmt->BindInt32ByName(NS_LITERAL_CSTRING("item_index"), aIndex);
|
2009-06-24 08:59:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Support NULL titles.
|
|
|
|
if (aTitle.IsVoid())
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = stmt->BindNullByName(NS_LITERAL_CSTRING("item_title"));
|
2009-06-24 08:59:14 +00:00
|
|
|
else
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = stmt->BindUTF8StringByName(NS_LITERAL_CSTRING("item_title"), aTitle);
|
2009-06-24 08:59:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-04-27 11:25:05 +00:00
|
|
|
if (aServiceContractId.IsEmpty()) {
|
|
|
|
rv = stmt->BindNullByName(NS_LITERAL_CSTRING("folder_type"));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rv = stmt->BindStringByName(NS_LITERAL_CSTRING("folder_type"),
|
|
|
|
aServiceContractId);
|
|
|
|
}
|
2009-06-24 08:59:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("date_added"), aDateAdded);
|
2009-06-24 08:59:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-04-27 11:25:05 +00:00
|
|
|
if (aLastModified) {
|
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("last_modified"),
|
|
|
|
aLastModified);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("last_modified"), aDateAdded);
|
|
|
|
}
|
2009-06-24 08:59:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->Execute();
|
2009-06-24 08:59:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!aItemId || aItemId == -1) {
|
|
|
|
// Get the new inserted item id.
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(lastInsertIdStmt, mDBGetLastBookmarkID);
|
2009-06-24 08:59:14 +00:00
|
|
|
PRBool hasResult;
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = lastInsertIdStmt->ExecuteStep(&hasResult);
|
2009-06-24 08:59:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(hasResult, NS_ERROR_UNEXPECTED);
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = lastInsertIdStmt->GetInt64(0, _newItemId);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-06-24 08:59:14 +00:00
|
|
|
}
|
2010-01-16 11:37:57 +00:00
|
|
|
else {
|
2009-06-24 08:59:14 +00:00
|
|
|
*_newItemId = aItemId;
|
2010-01-16 11:37:57 +00:00
|
|
|
}
|
2009-06-24 08:59:14 +00:00
|
|
|
|
|
|
|
// Update last modified date of the parent folder.
|
|
|
|
// XXX TODO: This should be done recursively for all ancestors, that would
|
|
|
|
// be slow without a nested tree though. See bug 408991.
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = SetItemDateInternal(GetStatement(mDBSetItemLastModified),
|
|
|
|
aParentId, aDateAdded);
|
2009-06-24 08:59:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:27:16 +00:00
|
|
|
NS_IMETHODIMP
|
2009-06-12 07:34:35 +00:00
|
|
|
nsNavBookmarks::InsertBookmark(PRInt64 aFolder,
|
2010-01-16 11:37:57 +00:00
|
|
|
nsIURI* aURI,
|
2009-06-12 07:34:35 +00:00
|
|
|
PRInt32 aIndex,
|
2008-01-09 03:54:37 +00:00
|
|
|
const nsACString& aTitle,
|
2010-01-16 11:37:57 +00:00
|
|
|
PRInt64* aNewBookmarkId)
|
2006-07-18 14:27:16 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
|
|
|
NS_ENSURE_ARG_POINTER(aNewBookmarkId);
|
|
|
|
|
2006-07-18 14:50:04 +00:00
|
|
|
// You can pass -1 to indicate append, but no other negative number is allowed
|
2007-02-26 00:54:36 +00:00
|
|
|
if (aIndex < nsINavBookmarksService::DEFAULT_INDEX)
|
2006-07-18 14:50:04 +00:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2008-10-27 22:52:21 +00:00
|
|
|
mozStorageTransaction transaction(mDBConn, PR_FALSE);
|
2006-07-18 14:27:16 +00:00
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavHistory* history = nsNavHistory::GetHistoryService();
|
2009-12-01 13:00:45 +00:00
|
|
|
NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2008-08-16 22:28:28 +00:00
|
|
|
// This is really a place ID
|
2006-07-18 14:27:16 +00:00
|
|
|
PRInt64 childID;
|
2009-12-01 13:00:45 +00:00
|
|
|
nsresult rv = history->GetUrlIdFor(aURI, &childID, PR_TRUE);
|
2006-07-18 14:27:16 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-11-22 01:46:43 +00:00
|
|
|
PRInt32 index;
|
2009-08-21 09:54:12 +00:00
|
|
|
PRInt32 folderCount;
|
|
|
|
rv = FolderCount(aFolder, &folderCount);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (aIndex == nsINavBookmarksService::DEFAULT_INDEX ||
|
|
|
|
aIndex >= folderCount) {
|
|
|
|
index = folderCount;
|
|
|
|
}
|
|
|
|
else {
|
2007-11-22 01:46:43 +00:00
|
|
|
index = aIndex;
|
|
|
|
rv = AdjustIndices(aFolder, index, PR_INT32_MAX, 1);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2006-07-18 14:27:16 +00:00
|
|
|
|
2009-06-24 08:59:14 +00:00
|
|
|
rv = InsertBookmarkInDB(-1, childID, BOOKMARK, aFolder, index,
|
|
|
|
aTitle, PR_Now(), nsnull, EmptyString(),
|
|
|
|
aNewBookmarkId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-02-26 00:54:36 +00:00
|
|
|
|
2008-01-25 17:11:14 +00:00
|
|
|
// XXX
|
|
|
|
// 0n import / fx 2 migration, is the frecency work going to slow us down?
|
|
|
|
// We might want to skip this stuff, as well as the frecency work
|
|
|
|
// caused by GetUrlIdFor() which calls InternalAddNewPage().
|
|
|
|
// If we do skip this, after import, we will
|
|
|
|
// need to call FixInvalidFrecenciesForExcludedPlaces().
|
|
|
|
// We might need to call it anyways, if items aren't properly annotated
|
|
|
|
// as livemarks feeds yet.
|
|
|
|
|
|
|
|
nsCAutoString url;
|
2009-06-12 07:34:35 +00:00
|
|
|
rv = aURI->GetSpec(url);
|
2008-01-25 17:11:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-10-11 12:53:31 +00:00
|
|
|
// Re-calculate the frecency for this moz_place entry since it was set to -1.
|
|
|
|
rv = history->UpdateFrecency(childID);
|
2008-01-25 17:11:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-07-18 14:27:16 +00:00
|
|
|
rv = transaction.Commit();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-12-03 01:37:53 +00:00
|
|
|
if (!mBatching) {
|
|
|
|
ForceWALCheckpoint(mDBConn);
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:38:04 +00:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
2010-10-26 22:20:53 +00:00
|
|
|
OnItemAdded(*aNewBookmarkId, aFolder, index, TYPE_BOOKMARK,
|
|
|
|
aURI));
|
2006-07-18 14:27:16 +00:00
|
|
|
|
2007-12-20 19:07:58 +00:00
|
|
|
// If the bookmark has been added to a tag container, notify all
|
|
|
|
// bookmark-folder result nodes which contain a bookmark for the new
|
|
|
|
// bookmark's url
|
2008-11-05 22:02:12 +00:00
|
|
|
PRInt64 grandParentId;
|
|
|
|
rv = GetFolderIdForItem(aFolder, &grandParentId);
|
2007-12-20 19:07:58 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-10-21 00:51:18 +00:00
|
|
|
if (grandParentId == mTagsRoot) {
|
2007-12-20 19:07:58 +00:00
|
|
|
// query for all bookmarks for that URI, notify for each
|
|
|
|
nsTArray<PRInt64> bookmarks;
|
2009-10-28 23:52:41 +00:00
|
|
|
rv = GetBookmarkIdsForURITArray(aURI, bookmarks);
|
2007-12-20 19:07:58 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (bookmarks.Length()) {
|
|
|
|
for (PRUint32 i = 0; i < bookmarks.Length(); i++) {
|
2011-01-27 11:18:20 +00:00
|
|
|
// Don't notify to the same tag entry we just added.
|
|
|
|
if (bookmarks[i] == *aNewBookmarkId) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:38:04 +00:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemChanged(bookmarks[i], NS_LITERAL_CSTRING("tags"),
|
|
|
|
PR_FALSE, EmptyCString(), 0,
|
|
|
|
TYPE_BOOKMARK));
|
2007-12-20 19:07:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-07-18 14:27:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:27:16 +00:00
|
|
|
NS_IMETHODIMP
|
2007-02-26 00:54:36 +00:00
|
|
|
nsNavBookmarks::RemoveItem(PRInt64 aItemId)
|
2006-07-18 14:27:16 +00:00
|
|
|
{
|
2009-02-11 10:53:35 +00:00
|
|
|
NS_ENSURE_TRUE(aItemId != mRoot, NS_ERROR_INVALID_ARG);
|
|
|
|
|
2008-04-13 18:17:46 +00:00
|
|
|
nsresult rv;
|
2006-07-18 14:27:16 +00:00
|
|
|
PRInt32 childIndex;
|
2007-02-26 00:54:36 +00:00
|
|
|
PRInt64 placeId, folderId;
|
2010-01-16 11:37:57 +00:00
|
|
|
PRInt32 itemType;
|
2007-05-10 08:05:19 +00:00
|
|
|
nsCAutoString buffer;
|
2007-12-20 19:07:58 +00:00
|
|
|
nsCAutoString spec;
|
2007-05-10 08:05:19 +00:00
|
|
|
|
2007-02-26 00:54:36 +00:00
|
|
|
{ // scoping to ensure the statement gets reset
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(getInfoStmt, mDBGetItemProperties);
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = getInfoStmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2006-07-18 14:27:16 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
PRBool hasResult;
|
|
|
|
rv = getInfoStmt->ExecuteStep(&hasResult);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!hasResult)
|
2007-02-26 00:54:36 +00:00
|
|
|
return NS_ERROR_INVALID_ARG; // invalid bookmark id
|
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = getInfoStmt->GetInt32(kGetItemPropertiesIndex_Position, &childIndex);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = getInfoStmt->GetInt64(kGetItemPropertiesIndex_PlaceID, &placeId);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = getInfoStmt->GetInt64(kGetItemPropertiesIndex_Parent, &folderId);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = getInfoStmt->GetInt32(kGetItemPropertiesIndex_Type, &itemType);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-12-20 19:07:58 +00:00
|
|
|
if (itemType == TYPE_BOOKMARK) {
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = getInfoStmt->GetUTF8String(kGetItemPropertiesIndex_URI, spec);
|
2007-12-20 19:07:58 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2006-07-18 14:27:16 +00:00
|
|
|
}
|
|
|
|
|
2008-04-13 18:17:46 +00:00
|
|
|
if (itemType == TYPE_FOLDER) {
|
|
|
|
rv = RemoveFolder(aItemId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:38:04 +00:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnBeforeItemRemoved(aItemId, itemType));
|
2009-03-19 19:56:51 +00:00
|
|
|
|
2008-10-27 22:52:21 +00:00
|
|
|
mozStorageTransaction transaction(mDBConn, PR_FALSE);
|
2008-04-13 18:17:46 +00:00
|
|
|
|
|
|
|
// First, remove item annotations
|
|
|
|
nsAnnotationService* annosvc = nsAnnotationService::GetAnnotationService();
|
|
|
|
NS_ENSURE_TRUE(annosvc, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
rv = annosvc->RemoveItemAnnotations(aItemId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
{
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBRemoveItem);
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = stmt->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2006-07-18 14:27:16 +00:00
|
|
|
|
|
|
|
if (childIndex != -1) {
|
2007-02-26 00:54:36 +00:00
|
|
|
rv = AdjustIndices(folderId, childIndex + 1, PR_INT32_MAX, -1);
|
2006-07-18 14:27:16 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = SetItemDateInternal(GetStatement(mDBSetItemLastModified),
|
|
|
|
folderId, PR_Now());
|
2007-07-11 22:38:13 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-07-18 14:27:16 +00:00
|
|
|
rv = transaction.Commit();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-12-03 01:37:53 +00:00
|
|
|
if (!mBatching) {
|
|
|
|
ForceWALCheckpoint(mDBConn);
|
|
|
|
}
|
|
|
|
|
2008-01-25 17:11:14 +00:00
|
|
|
if (itemType == TYPE_BOOKMARK) {
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavHistory* history = nsNavHistory::GetHistoryService();
|
2009-12-01 13:00:45 +00:00
|
|
|
NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY);
|
2010-10-11 12:53:31 +00:00
|
|
|
rv = history->UpdateFrecency(placeId);
|
2008-01-25 17:11:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-08-09 15:59:43 +00:00
|
|
|
|
|
|
|
rv = UpdateKeywordsHashForRemovedBookmark(aItemId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-01-25 17:11:14 +00:00
|
|
|
}
|
|
|
|
|
2011-01-27 11:18:20 +00:00
|
|
|
bool isTagEntry = false;
|
2007-12-20 19:07:58 +00:00
|
|
|
if (itemType == TYPE_BOOKMARK) {
|
2011-01-27 11:18:20 +00:00
|
|
|
// Check if the removed bookmark was child of a tag container.
|
|
|
|
// This is done before notifying since during the notification the parent
|
|
|
|
// could be removed as well.
|
2008-11-05 22:02:12 +00:00
|
|
|
PRInt64 grandParentId;
|
|
|
|
rv = GetFolderIdForItem(folderId, &grandParentId);
|
2007-12-20 19:07:58 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-01-27 11:18:20 +00:00
|
|
|
isTagEntry = grandParentId == mTagsRoot;
|
|
|
|
}
|
2007-12-20 19:07:58 +00:00
|
|
|
|
2011-01-27 11:18:20 +00:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemRemoved(aItemId, folderId, childIndex, itemType));
|
2007-12-20 19:07:58 +00:00
|
|
|
|
2011-01-27 11:18:20 +00:00
|
|
|
if (isTagEntry) {
|
|
|
|
// Get all bookmarks pointing to the same uri as this tag entry and
|
|
|
|
// notify them that tags changed.
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
rv = NS_NewURI(getter_AddRefs(uri), spec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
nsTArray<PRInt64> bookmarks;
|
|
|
|
rv = GetBookmarkIdsForURITArray(uri, bookmarks);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < bookmarks.Length(); i++) {
|
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemChanged(bookmarks[i],
|
|
|
|
NS_LITERAL_CSTRING("tags"), PR_FALSE,
|
|
|
|
EmptyCString(), 0, TYPE_BOOKMARK));
|
2007-12-20 19:07:58 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-27 11:18:20 +00:00
|
|
|
|
2006-07-18 14:27:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::CreateFolder(PRInt64 aParent, const nsACString& aName,
|
|
|
|
PRInt32 aIndex, PRInt64* aNewFolder)
|
2006-07-18 14:48:53 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
// NOTE: aParent can be null for root creation, so not checked
|
|
|
|
NS_ENSURE_ARG_POINTER(aNewFolder);
|
|
|
|
|
2007-08-02 20:19:44 +00:00
|
|
|
// CreateContainerWithID returns the index of the new folder, but that's not
|
2006-07-18 14:51:15 +00:00
|
|
|
// used here. To avoid any risk of corrupting data should this function
|
|
|
|
// be changed, we'll use a local variable to hold it. The PR_TRUE argument
|
|
|
|
// will cause notifications to be sent to bookmark observers.
|
|
|
|
PRInt32 localIndex = aIndex;
|
2010-01-16 11:37:57 +00:00
|
|
|
nsresult rv = CreateContainerWithID(-1, aParent, aName, EmptyString(),
|
|
|
|
PR_TRUE, &localIndex, aNewFolder);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
2006-07-18 14:48:53 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:48:53 +00:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::CreateDynamicContainer(PRInt64 aParent,
|
|
|
|
const nsACString& aName,
|
|
|
|
const nsAString& aContractId,
|
2007-08-02 20:19:44 +00:00
|
|
|
PRInt32 aIndex,
|
2010-01-16 11:37:57 +00:00
|
|
|
PRInt64* aNewFolder)
|
2006-07-18 14:48:53 +00:00
|
|
|
{
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_FALSE(aContractId.IsEmpty(), NS_ERROR_INVALID_ARG);
|
2007-08-02 20:19:44 +00:00
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
nsresult rv = CreateContainerWithID(-1, aParent, aName, aContractId,
|
|
|
|
PR_FALSE, &aIndex, aNewFolder);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
2007-08-02 20:19:44 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2007-08-02 20:19:44 +00:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::GetFolderReadonly(PRInt64 aFolder, PRBool* aResult)
|
2007-08-02 20:19:44 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aFolder, 1);
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
|
2007-08-02 20:19:44 +00:00
|
|
|
nsAnnotationService* annosvc = nsAnnotationService::GetAnnotationService();
|
|
|
|
NS_ENSURE_TRUE(annosvc, NS_ERROR_OUT_OF_MEMORY);
|
2010-01-16 11:37:57 +00:00
|
|
|
nsresult rv = annosvc->ItemHasAnnotation(aFolder, READ_ONLY_ANNO, aResult);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
2007-08-02 20:19:44 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2007-08-02 20:19:44 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavBookmarks::SetFolderReadonly(PRInt64 aFolder, PRBool aReadOnly)
|
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aFolder, 1);
|
|
|
|
|
2007-08-02 20:19:44 +00:00
|
|
|
nsAnnotationService* annosvc = nsAnnotationService::GetAnnotationService();
|
|
|
|
NS_ENSURE_TRUE(annosvc, NS_ERROR_OUT_OF_MEMORY);
|
2010-01-16 11:37:57 +00:00
|
|
|
nsresult rv;
|
2007-08-02 20:19:44 +00:00
|
|
|
if (aReadOnly) {
|
2010-01-16 11:37:57 +00:00
|
|
|
rv = annosvc->SetItemAnnotationInt32(aFolder, READ_ONLY_ANNO, 1, 0,
|
|
|
|
nsAnnotationService::EXPIRE_NEVER);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-08-02 20:19:44 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
PRBool hasAnno;
|
2010-01-16 11:37:57 +00:00
|
|
|
rv = annosvc->ItemHasAnnotation(aFolder, READ_ONLY_ANNO, &hasAnno);
|
2007-08-02 20:19:44 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 11:37:57 +00:00
|
|
|
if (hasAnno) {
|
|
|
|
rv = annosvc->RemoveItemAnnotation(aFolder, READ_ONLY_ANNO);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2007-08-02 20:19:44 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
2006-07-18 14:48:53 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:48:53 +00:00
|
|
|
nsresult
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::CreateContainerWithID(PRInt64 aItemId,
|
|
|
|
PRInt64 aParent,
|
2008-01-09 03:54:37 +00:00
|
|
|
const nsACString& aName,
|
2007-08-02 20:19:44 +00:00
|
|
|
const nsAString& aContractId,
|
|
|
|
PRBool aIsBookmarkFolder,
|
2010-01-16 11:37:57 +00:00
|
|
|
PRInt32* aIndex,
|
|
|
|
PRInt64* aNewFolder)
|
2006-07-18 14:27:16 +00:00
|
|
|
{
|
2006-07-18 14:50:04 +00:00
|
|
|
// You can pass -1 to indicate append, but no other negative number is allowed
|
2006-07-18 14:51:15 +00:00
|
|
|
if (*aIndex < -1)
|
2006-07-18 14:50:04 +00:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2008-10-27 22:52:21 +00:00
|
|
|
mozStorageTransaction transaction(mDBConn, PR_FALSE);
|
2006-07-18 14:27:16 +00:00
|
|
|
|
2007-11-22 01:46:43 +00:00
|
|
|
PRInt32 index;
|
2009-08-21 09:54:12 +00:00
|
|
|
PRInt32 folderCount;
|
|
|
|
nsresult rv = FolderCount(aParent, &folderCount);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (*aIndex == nsINavBookmarksService::DEFAULT_INDEX ||
|
|
|
|
*aIndex >= folderCount) {
|
|
|
|
index = folderCount;
|
2007-11-22 01:46:43 +00:00
|
|
|
} else {
|
|
|
|
index = *aIndex;
|
|
|
|
rv = AdjustIndices(aParent, index, PR_INT32_MAX, 1);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2006-07-18 14:27:16 +00:00
|
|
|
|
2009-06-24 08:59:14 +00:00
|
|
|
ItemType containerType = aIsBookmarkFolder ? FOLDER
|
|
|
|
: DYNAMIC_CONTAINER;
|
|
|
|
rv = InsertBookmarkInDB(aItemId, nsnull, containerType, aParent, index,
|
|
|
|
aName, PR_Now(), nsnull, aContractId, aNewFolder);
|
2007-07-11 22:38:13 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-07-18 14:27:16 +00:00
|
|
|
rv = transaction.Commit();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-12-03 01:37:53 +00:00
|
|
|
if (!mBatching) {
|
|
|
|
ForceWALCheckpoint(mDBConn);
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:38:04 +00:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
2010-10-26 22:20:53 +00:00
|
|
|
OnItemAdded(*aNewFolder, aParent, index, containerType,
|
|
|
|
nsnull));
|
2006-07-18 14:27:16 +00:00
|
|
|
|
2006-07-18 14:51:15 +00:00
|
|
|
*aIndex = index;
|
2006-07-18 14:27:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:43:47 +00:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::InsertSeparator(PRInt64 aParent,
|
|
|
|
PRInt32 aIndex,
|
2007-05-10 18:18:34 +00:00
|
|
|
PRInt64* aNewItemId)
|
2006-07-18 14:43:47 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aParent, 1);
|
2009-11-06 15:25:00 +00:00
|
|
|
// -1 means "append", but no other negative value is allowed.
|
|
|
|
NS_ENSURE_ARG_MIN(aIndex, -1);
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aNewItemId);
|
|
|
|
|
2008-10-27 22:52:21 +00:00
|
|
|
mozStorageTransaction transaction(mDBConn, PR_FALSE);
|
2006-07-18 14:43:47 +00:00
|
|
|
|
2007-11-22 01:46:43 +00:00
|
|
|
PRInt32 index;
|
2009-08-21 09:54:12 +00:00
|
|
|
PRInt32 folderCount;
|
|
|
|
nsresult rv = FolderCount(aParent, &folderCount);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (aIndex == nsINavBookmarksService::DEFAULT_INDEX ||
|
|
|
|
aIndex >= folderCount) {
|
|
|
|
index = folderCount;
|
2009-11-06 15:25:00 +00:00
|
|
|
}
|
|
|
|
else {
|
2007-11-22 01:46:43 +00:00
|
|
|
index = aIndex;
|
|
|
|
rv = AdjustIndices(aParent, index, PR_INT32_MAX, 1);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2006-07-18 14:43:47 +00:00
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
// Set a NULL title, not an empty title.
|
2009-06-24 08:59:14 +00:00
|
|
|
nsCString voidString;
|
|
|
|
voidString.SetIsVoid(PR_TRUE);
|
|
|
|
rv = InsertBookmarkInDB(-1, nsnull, SEPARATOR, aParent, index,
|
|
|
|
voidString, PR_Now(), nsnull, EmptyString(),
|
|
|
|
aNewItemId);
|
2007-07-11 22:38:13 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-07-18 14:43:47 +00:00
|
|
|
rv = transaction.Commit();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 11:38:04 +00:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
2010-10-26 22:20:53 +00:00
|
|
|
OnItemAdded(*aNewItemId, aParent, index, TYPE_SEPARATOR,
|
|
|
|
nsnull));
|
2006-07-18 14:43:47 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2008-02-06 21:05:23 +00:00
|
|
|
nsresult
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::GetLastChildId(PRInt64 aFolderId, PRInt64* aItemId)
|
2008-02-06 21:05:23 +00:00
|
|
|
{
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ASSERTION(aFolderId > 0, "Invalid folder id");
|
2009-11-06 15:25:00 +00:00
|
|
|
*aItemId = -1;
|
|
|
|
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetLastChildId);
|
2010-04-27 11:25:05 +00:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("parent"), aFolderId);
|
2008-02-06 21:05:23 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-11-06 15:25:00 +00:00
|
|
|
PRBool found;
|
2010-01-16 11:37:57 +00:00
|
|
|
rv = stmt->ExecuteStep(&found);
|
2008-02-06 21:05:23 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 11:37:57 +00:00
|
|
|
if (found) {
|
|
|
|
rv = stmt->GetInt64(0, aItemId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2008-02-06 21:05:23 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2008-02-06 21:05:23 +00:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::GetIdForItemAt(PRInt64 aFolder,
|
|
|
|
PRInt32 aIndex,
|
|
|
|
PRInt64* aItemId)
|
2008-02-06 21:05:23 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aFolder, 1);
|
|
|
|
NS_ENSURE_ARG_POINTER(aItemId);
|
|
|
|
|
2009-11-06 15:25:00 +00:00
|
|
|
*aItemId = -1;
|
|
|
|
|
2008-02-06 21:05:23 +00:00
|
|
|
nsresult rv;
|
|
|
|
if (aIndex == nsINavBookmarksService::DEFAULT_INDEX) {
|
2009-11-06 15:25:00 +00:00
|
|
|
// Get last item within aFolder.
|
2009-02-09 18:16:02 +00:00
|
|
|
rv = GetLastChildId(aFolder, aItemId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-11-06 15:25:00 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Get the item in aFolder with position aIndex.
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetChildAt);
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("parent"), aFolder);
|
2009-11-06 15:25:00 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = stmt->BindInt32ByName(NS_LITERAL_CSTRING("item_index"), aIndex);
|
2009-11-06 15:25:00 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-02-06 21:05:23 +00:00
|
|
|
|
2009-11-06 15:25:00 +00:00
|
|
|
PRBool found;
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->ExecuteStep(&found);
|
2009-11-06 15:25:00 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 11:37:57 +00:00
|
|
|
if (found) {
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->GetInt64(0, aItemId);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2008-02-06 21:05:23 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:48:53 +00:00
|
|
|
nsresult
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::GetParentAndIndexOfFolder(PRInt64 aFolderId,
|
|
|
|
PRInt64* _aParent,
|
|
|
|
PRInt32* _aIndex)
|
2006-07-18 14:48:53 +00:00
|
|
|
{
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemProperties);
|
2010-04-27 11:25:05 +00:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aFolderId);
|
2006-07-18 14:48:53 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
PRBool hasResult;
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
2006-07-18 14:48:53 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_TRUE(hasResult, NS_ERROR_INVALID_ARG);
|
2009-11-06 15:25:00 +00:00
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->GetInt64(kGetItemPropertiesIndex_Parent, _aParent);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->GetInt32(kGetItemPropertiesIndex_Position, _aIndex);
|
2009-11-06 15:25:00 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-07-18 14:48:53 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
|
|
|
nsresult
|
2008-04-13 18:17:46 +00:00
|
|
|
nsNavBookmarks::RemoveFolder(PRInt64 aFolderId)
|
2006-07-18 14:27:16 +00:00
|
|
|
{
|
2009-02-11 10:53:35 +00:00
|
|
|
NS_ENSURE_TRUE(aFolderId != mRoot, NS_ERROR_INVALID_ARG);
|
|
|
|
|
2010-01-16 11:38:04 +00:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnBeforeItemRemoved(aFolderId, TYPE_FOLDER));
|
2009-03-19 19:56:51 +00:00
|
|
|
|
2008-10-27 22:52:21 +00:00
|
|
|
mozStorageTransaction transaction(mDBConn, PR_FALSE);
|
2007-09-28 23:28:14 +00:00
|
|
|
|
2008-04-13 18:17:46 +00:00
|
|
|
nsresult rv;
|
2007-05-09 01:19:12 +00:00
|
|
|
PRInt64 parent;
|
2008-04-13 18:17:46 +00:00
|
|
|
PRInt32 index, type;
|
2006-07-18 14:42:14 +00:00
|
|
|
nsCAutoString folderType;
|
2007-05-09 01:19:12 +00:00
|
|
|
{
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(getInfoStmt, mDBGetItemProperties);
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = getInfoStmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aFolderId);
|
2007-05-09 01:19:12 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
PRBool hasResult;
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = getInfoStmt->ExecuteStep(&hasResult);
|
2007-05-09 01:19:12 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 11:37:57 +00:00
|
|
|
if (!hasResult) {
|
2007-05-09 01:19:12 +00:00
|
|
|
return NS_ERROR_INVALID_ARG; // folder is not in the hierarchy
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = getInfoStmt->GetInt32(kGetItemPropertiesIndex_Type, &type);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = getInfoStmt->GetInt64(kGetItemPropertiesIndex_Parent, &parent);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = getInfoStmt->GetInt32(kGetItemPropertiesIndex_Position, &index);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = getInfoStmt->GetUTF8String(kGetItemPropertiesIndex_ServiceContractId,
|
|
|
|
folderType);
|
2007-05-09 01:19:12 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
// Ensure this is really a folder.
|
|
|
|
NS_ENSURE_TRUE(type == TYPE_FOLDER, NS_ERROR_INVALID_ARG);
|
2008-04-13 18:17:46 +00:00
|
|
|
|
|
|
|
// First, remove item annotations
|
|
|
|
nsAnnotationService* annosvc = nsAnnotationService::GetAnnotationService();
|
|
|
|
NS_ENSURE_TRUE(annosvc, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
rv = annosvc->RemoveItemAnnotations(aFolderId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-05-09 01:19:12 +00:00
|
|
|
// If this is a container bookmark, try to notify its service.
|
2006-07-18 14:37:57 +00:00
|
|
|
if (folderType.Length() > 0) {
|
2008-10-13 15:58:36 +00:00
|
|
|
// There is a type associated with this folder.
|
2007-08-02 20:19:44 +00:00
|
|
|
nsCOMPtr<nsIDynamicContainer> bmcServ = do_GetService(folderType.get());
|
2006-07-18 14:37:57 +00:00
|
|
|
if (bmcServ) {
|
2008-04-13 18:17:46 +00:00
|
|
|
rv = bmcServ->OnContainerRemoving(aFolderId);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
|
|
|
|
"Remove folder container notification failed.");
|
2006-07-18 14:37:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove all of the folder's children
|
2008-11-05 22:02:12 +00:00
|
|
|
rv = RemoveFolderChildren(aFolderId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 14:37:57 +00:00
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
{
|
|
|
|
// Remove the folder from its parent.
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBRemoveItem);
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aFolderId);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = stmt->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2006-07-18 14:37:57 +00:00
|
|
|
|
|
|
|
rv = AdjustIndices(parent, index + 1, PR_INT32_MAX, -1);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = SetItemDateInternal(GetStatement(mDBSetItemLastModified),
|
|
|
|
parent, PR_Now());
|
2007-07-11 22:38:13 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-07-18 14:37:57 +00:00
|
|
|
rv = transaction.Commit();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-12-03 01:37:53 +00:00
|
|
|
if (!mBatching) {
|
|
|
|
ForceWALCheckpoint(mDBConn);
|
|
|
|
}
|
|
|
|
|
2010-10-21 00:51:18 +00:00
|
|
|
if (aFolderId == mToolbarRoot) {
|
|
|
|
mToolbarRoot = 0;
|
2007-05-17 06:06:48 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 11:38:04 +00:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemRemoved(aFolderId, parent, index, TYPE_FOLDER));
|
2006-07-18 14:37:57 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:48:53 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(nsNavBookmarks::RemoveFolderTransaction, nsITransaction)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-06-12 07:34:35 +00:00
|
|
|
nsNavBookmarks::GetRemoveFolderTransaction(PRInt64 aFolderId, nsITransaction** aResult)
|
2006-07-18 14:48:53 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aFolderId, 1);
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
|
2006-07-18 14:48:53 +00:00
|
|
|
// Create and initialize a RemoveFolderTransaction object that can be used to
|
|
|
|
// recreate the folder safely later.
|
|
|
|
|
|
|
|
RemoveFolderTransaction* rft =
|
2009-06-12 07:34:35 +00:00
|
|
|
new RemoveFolderTransaction(aFolderId);
|
2006-07-18 14:48:53 +00:00
|
|
|
if (!rft)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
NS_ADDREF(*aResult = rft);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2008-11-05 22:02:12 +00:00
|
|
|
nsresult
|
|
|
|
nsNavBookmarks::GetDescendantChildren(PRInt64 aFolderId,
|
|
|
|
PRInt64 aGrandParentId,
|
|
|
|
nsTArray<folderChildrenInfo>& aFolderChildrenArray) {
|
|
|
|
// New children will be added from this index on.
|
|
|
|
PRUint32 startIndex = aFolderChildrenArray.Length();
|
2006-07-18 14:42:37 +00:00
|
|
|
nsresult rv;
|
2006-07-18 14:32:56 +00:00
|
|
|
{
|
2008-11-05 22:02:12 +00:00
|
|
|
// Collect children informations.
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetChildren);
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("parent"), aFolderId);
|
2006-07-18 14:32:56 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-07-18 14:42:37 +00:00
|
|
|
PRBool hasMore;
|
2010-01-16 11:38:00 +00:00
|
|
|
while (NS_SUCCEEDED(stmt->ExecuteStep(&hasMore)) && hasMore) {
|
2008-11-05 22:02:12 +00:00
|
|
|
folderChildrenInfo child;
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->GetInt64(nsNavHistory::kGetInfoIndex_ItemId, &child.itemId);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-11-05 22:02:12 +00:00
|
|
|
child.parentId = aFolderId;
|
|
|
|
child.grandParentId = aGrandParentId;
|
2010-01-16 11:37:57 +00:00
|
|
|
PRInt32 itemType;
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->GetInt32(kGetChildrenIndex_Type, &itemType);
|
2010-01-16 11:37:57 +00:00
|
|
|
child.itemType = (PRUint16)itemType;
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->GetInt64(kGetChildrenIndex_PlaceID, &child.placeId);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->GetInt32(kGetChildrenIndex_Position, &child.index);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-11-05 22:02:12 +00:00
|
|
|
|
|
|
|
if (child.itemType == TYPE_BOOKMARK) {
|
|
|
|
nsCAutoString URIString;
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->GetUTF8String(nsNavHistory::kGetInfoIndex_URL, URIString);
|
2008-11-05 22:02:12 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
child.url = URIString;
|
2006-07-18 14:42:37 +00:00
|
|
|
}
|
2008-11-05 22:02:12 +00:00
|
|
|
else if (child.itemType == TYPE_FOLDER) {
|
|
|
|
nsCAutoString folderType;
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->GetUTF8String(kGetChildrenIndex_ServiceContractId,
|
|
|
|
folderType);
|
2008-11-05 22:02:12 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
child.folderType = folderType;
|
|
|
|
}
|
|
|
|
// Append item to children's array.
|
|
|
|
aFolderChildrenArray.AppendElement(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Recursively call GetDescendantChildren for added folders.
|
|
|
|
// We start at startIndex since previous folders are checked
|
|
|
|
// by previous calls to this method.
|
|
|
|
PRUint32 childCount = aFolderChildrenArray.Length();
|
|
|
|
for (PRUint32 i = startIndex; i < childCount; i++) {
|
|
|
|
if (aFolderChildrenArray[i].itemType == TYPE_FOLDER) {
|
|
|
|
GetDescendantChildren(aFolderChildrenArray[i].itemId,
|
|
|
|
aFolderId,
|
|
|
|
aFolderChildrenArray);
|
2006-07-18 14:32:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-05 22:02:12 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-07-18 14:43:47 +00:00
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2008-11-05 22:02:12 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavBookmarks::RemoveFolderChildren(PRInt64 aFolderId)
|
|
|
|
{
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aFolderId, 1);
|
|
|
|
|
2008-11-05 22:02:12 +00:00
|
|
|
nsresult rv;
|
2010-01-16 11:37:57 +00:00
|
|
|
PRInt32 itemType;
|
2008-11-05 22:02:12 +00:00
|
|
|
PRInt64 grandParentId;
|
|
|
|
{
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(getInfoStmt, mDBGetItemProperties);
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = getInfoStmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aFolderId);
|
2006-07-18 14:42:37 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-11-05 22:02:12 +00:00
|
|
|
|
|
|
|
// Sanity check: ensure that item exists.
|
|
|
|
PRBool folderExists;
|
2010-01-16 11:38:00 +00:00
|
|
|
if (NS_FAILED(getInfoStmt->ExecuteStep(&folderExists)) || !folderExists)
|
2008-11-05 22:02:12 +00:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
// Sanity check: ensure that this is a folder.
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = getInfoStmt->GetInt32(kGetItemPropertiesIndex_Type, &itemType);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-11-05 22:02:12 +00:00
|
|
|
if (itemType != TYPE_FOLDER)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
// Get the grandParent.
|
|
|
|
// We have to do this only once since recursion will give us other
|
|
|
|
// grandParents without the need of additional queries.
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = getInfoStmt->GetInt64(kGetItemPropertiesIndex_Parent, &grandParentId);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 14:32:56 +00:00
|
|
|
}
|
|
|
|
|
2008-11-05 22:02:12 +00:00
|
|
|
// Fill folder children array recursively.
|
|
|
|
nsTArray<folderChildrenInfo> folderChildrenArray;
|
|
|
|
rv = GetDescendantChildren(aFolderId, grandParentId, folderChildrenArray);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Build a string of folders whose children will be removed.
|
|
|
|
nsCString foldersToRemove;
|
|
|
|
for (PRUint32 i = 0; i < folderChildrenArray.Length(); i++) {
|
|
|
|
folderChildrenInfo child = folderChildrenArray[i];
|
2009-03-19 19:56:51 +00:00
|
|
|
|
|
|
|
// Notify observers that we are about to remove this child.
|
2010-01-16 11:38:04 +00:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnBeforeItemRemoved(child.itemId, child.itemType));
|
2009-03-19 19:56:51 +00:00
|
|
|
|
2008-11-05 22:02:12 +00:00
|
|
|
if (child.itemType == TYPE_FOLDER) {
|
|
|
|
foldersToRemove.AppendLiteral(",");
|
|
|
|
foldersToRemove.AppendInt(child.itemId);
|
|
|
|
|
|
|
|
// If this is a dynamic container, try to notify its service that we
|
|
|
|
// are going to remove it.
|
2009-03-19 19:56:51 +00:00
|
|
|
// XXX (bug 484094) this should use a bookmark observer!
|
2008-11-05 22:02:12 +00:00
|
|
|
if (child.folderType.Length() > 0) {
|
|
|
|
nsCOMPtr<nsIDynamicContainer> bmcServ =
|
|
|
|
do_GetService(child.folderType.get());
|
|
|
|
if (bmcServ) {
|
|
|
|
rv = bmcServ->OnContainerRemoving(child.itemId);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
NS_WARNING("Remove folder container notification failed.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete items from the database now.
|
|
|
|
mozStorageTransaction transaction(mDBConn, PR_FALSE);
|
|
|
|
|
2009-02-12 11:32:52 +00:00
|
|
|
nsCOMPtr<mozIStorageStatement> deleteStatement;
|
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2008-11-05 22:02:12 +00:00
|
|
|
"DELETE FROM moz_bookmarks "
|
2010-04-27 11:25:05 +00:00
|
|
|
"WHERE parent IN (:parent") +
|
2008-11-05 22:02:12 +00:00
|
|
|
foldersToRemove +
|
2009-02-12 11:32:52 +00:00
|
|
|
NS_LITERAL_CSTRING(")"),
|
|
|
|
getter_AddRefs(deleteStatement));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = deleteStatement->BindInt64ByName(NS_LITERAL_CSTRING("parent"), aFolderId);
|
2009-02-12 11:32:52 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = deleteStatement->Execute();
|
2008-11-05 22:02:12 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Clean up orphan items annotations.
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(
|
|
|
|
NS_LITERAL_CSTRING(
|
|
|
|
"DELETE FROM moz_items_annos "
|
|
|
|
"WHERE id IN ("
|
|
|
|
"SELECT a.id from moz_items_annos a "
|
|
|
|
"LEFT JOIN moz_bookmarks b ON a.item_id = b.id "
|
|
|
|
"WHERE b.id ISNULL)"));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Set the lastModified date.
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = SetItemDateInternal(GetStatement(mDBSetItemLastModified),
|
|
|
|
aFolderId, PR_Now());
|
2008-11-05 22:02:12 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < folderChildrenArray.Length(); i++) {
|
|
|
|
folderChildrenInfo child = folderChildrenArray[i];
|
|
|
|
if (child.itemType == TYPE_BOOKMARK) {
|
|
|
|
PRInt64 placeId = child.placeId;
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavHistory* history = nsNavHistory::GetHistoryService();
|
2009-12-01 13:00:45 +00:00
|
|
|
NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY);
|
2010-10-11 12:53:31 +00:00
|
|
|
rv = history->UpdateFrecency(placeId);
|
2008-11-05 22:02:12 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-08-09 15:59:43 +00:00
|
|
|
|
|
|
|
rv = UpdateKeywordsHashForRemovedBookmark(child.itemId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-11-05 22:02:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = transaction.Commit();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-12-03 01:37:53 +00:00
|
|
|
if (!mBatching) {
|
|
|
|
ForceWALCheckpoint(mDBConn);
|
|
|
|
}
|
|
|
|
|
2008-11-05 22:02:12 +00:00
|
|
|
// Call observers in reverse order to serve children before their parent.
|
|
|
|
for (PRInt32 i = folderChildrenArray.Length() - 1; i >= 0 ; i--) {
|
|
|
|
folderChildrenInfo child = folderChildrenArray[i];
|
|
|
|
|
2010-01-16 11:38:04 +00:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemRemoved(child.itemId, child.parentId, child.index,
|
|
|
|
child.itemType));
|
2008-11-05 22:02:12 +00:00
|
|
|
|
|
|
|
if (child.itemType == TYPE_BOOKMARK) {
|
|
|
|
// If the removed bookmark was a child of a tag container, notify all
|
|
|
|
// bookmark-folder result nodes which contain a bookmark for the removed
|
|
|
|
// bookmark's url.
|
|
|
|
|
2010-10-21 00:51:18 +00:00
|
|
|
if (child.grandParentId == mTagsRoot) {
|
2008-11-05 22:02:12 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
rv = NS_NewURI(getter_AddRefs(uri), child.url);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsTArray<PRInt64> bookmarks;
|
2009-10-28 23:52:41 +00:00
|
|
|
rv = GetBookmarkIdsForURITArray(uri, bookmarks);
|
2008-11-05 22:02:12 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (bookmarks.Length()) {
|
|
|
|
for (PRUint32 i = 0; i < bookmarks.Length(); i++) {
|
2010-01-16 11:38:04 +00:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemChanged(bookmarks[i],
|
|
|
|
NS_LITERAL_CSTRING("tags"), PR_FALSE,
|
|
|
|
EmptyCString(), 0, TYPE_BOOKMARK));
|
2008-11-05 22:02:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-07-18 14:42:37 +00:00
|
|
|
}
|
|
|
|
|
2006-07-18 14:39:08 +00:00
|
|
|
return NS_OK;
|
2006-07-18 14:27:16 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:27:16 +00:00
|
|
|
NS_IMETHODIMP
|
2007-05-22 22:03:53 +00:00
|
|
|
nsNavBookmarks::MoveItem(PRInt64 aItemId, PRInt64 aNewParent, PRInt32 aIndex)
|
2006-07-18 14:27:16 +00:00
|
|
|
{
|
2009-02-11 10:53:35 +00:00
|
|
|
NS_ENSURE_TRUE(aItemId != mRoot, NS_ERROR_INVALID_ARG);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
|
|
|
NS_ENSURE_ARG_MIN(aNewParent, 1);
|
|
|
|
// -1 is append, but no other negative number is allowed.
|
|
|
|
NS_ENSURE_ARG_MIN(aIndex, -1);
|
2007-10-24 05:50:47 +00:00
|
|
|
// Disallow making an item its own parent.
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_TRUE(aItemId != aNewParent, NS_ERROR_INVALID_ARG);
|
2007-05-09 01:19:12 +00:00
|
|
|
|
2008-10-27 22:52:21 +00:00
|
|
|
mozStorageTransaction transaction(mDBConn, PR_FALSE);
|
2006-07-18 14:27:16 +00:00
|
|
|
|
2007-05-09 01:19:12 +00:00
|
|
|
// get item properties
|
|
|
|
nsresult rv;
|
|
|
|
PRInt64 oldParent;
|
2008-11-05 22:02:12 +00:00
|
|
|
PRInt32 oldIndex;
|
2010-01-16 11:37:57 +00:00
|
|
|
PRInt32 itemType;
|
2007-05-22 22:03:53 +00:00
|
|
|
nsCAutoString folderType;
|
2006-07-18 14:27:16 +00:00
|
|
|
{
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(getInfoStmt, mDBGetItemProperties);
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = getInfoStmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2006-07-18 14:27:16 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
PRBool hasResult;
|
|
|
|
rv = getInfoStmt->ExecuteStep(&hasResult);
|
2006-07-18 14:27:16 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 11:38:00 +00:00
|
|
|
if (!hasResult) {
|
2006-07-18 14:27:16 +00:00
|
|
|
return NS_ERROR_INVALID_ARG; // folder is not in the hierarchy
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = getInfoStmt->GetInt64(kGetItemPropertiesIndex_Parent, &oldParent);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = getInfoStmt->GetInt32(kGetItemPropertiesIndex_Position, &oldIndex);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = getInfoStmt->GetInt32(kGetItemPropertiesIndex_Type, &itemType);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-05-22 22:03:53 +00:00
|
|
|
if (itemType == TYPE_FOLDER) {
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = getInfoStmt->GetUTF8String(kGetItemPropertiesIndex_ServiceContractId,
|
|
|
|
folderType);
|
2007-05-22 22:03:53 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2006-07-18 14:31:23 +00:00
|
|
|
}
|
|
|
|
|
2007-05-09 01:19:12 +00:00
|
|
|
// if parent and index are the same, nothing to do
|
|
|
|
if (oldParent == aNewParent && oldIndex == aIndex)
|
|
|
|
return NS_OK;
|
|
|
|
|
2006-07-18 14:39:31 +00:00
|
|
|
// Make sure aNewParent is not aFolder or a subfolder of aFolder
|
2007-05-22 22:03:53 +00:00
|
|
|
if (itemType == TYPE_FOLDER) {
|
2010-01-16 11:37:57 +00:00
|
|
|
PRInt64 ancestorId = aNewParent;
|
2006-07-18 14:39:31 +00:00
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
while (ancestorId) {
|
|
|
|
if (ancestorId == aItemId) {
|
2006-07-18 14:39:31 +00:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(getInfoStmt, mDBGetItemProperties);
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = getInfoStmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"),
|
|
|
|
ancestorId);
|
2006-07-18 14:39:31 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
PRBool hasResult;
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = getInfoStmt->ExecuteStep(&hasResult);
|
2006-07-18 14:39:31 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 11:37:57 +00:00
|
|
|
if (hasResult) {
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = getInfoStmt->GetInt64(kGetItemPropertiesIndex_Parent, &ancestorId);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
break;
|
|
|
|
}
|
2006-07-18 14:39:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-09 01:19:12 +00:00
|
|
|
// calculate new index
|
2006-07-18 14:31:23 +00:00
|
|
|
PRInt32 newIndex;
|
2009-08-21 09:54:12 +00:00
|
|
|
PRInt32 folderCount;
|
|
|
|
rv = FolderCount(aNewParent, &folderCount);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (aIndex == nsINavBookmarksService::DEFAULT_INDEX ||
|
|
|
|
aIndex >= folderCount) {
|
|
|
|
newIndex = folderCount;
|
2006-07-18 14:31:23 +00:00
|
|
|
// If the parent remains the same, then the folder is really being moved
|
|
|
|
// to count - 1 (since it's being removed from the old position)
|
2007-05-09 01:19:12 +00:00
|
|
|
if (oldParent == aNewParent) {
|
2006-07-18 14:31:23 +00:00
|
|
|
--newIndex;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
newIndex = aIndex;
|
2006-07-18 14:33:42 +00:00
|
|
|
|
2007-05-09 01:19:12 +00:00
|
|
|
if (oldParent == aNewParent && newIndex > oldIndex) {
|
2006-07-18 14:33:42 +00:00
|
|
|
// when an item is being moved lower in the same folder, the new index
|
|
|
|
// refers to the index before it was removed. Removal causes everything
|
|
|
|
// to shift up.
|
|
|
|
--newIndex;
|
|
|
|
}
|
2006-07-18 14:27:16 +00:00
|
|
|
}
|
|
|
|
|
2007-05-09 01:19:12 +00:00
|
|
|
// this is like the previous check, except this covers if
|
|
|
|
// the specified index was -1 (append), and the calculated
|
|
|
|
// new index is the same as the existing index
|
|
|
|
if (aNewParent == oldParent && newIndex == oldIndex) {
|
2006-07-18 14:27:16 +00:00
|
|
|
// Nothing to do!
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-05-09 01:19:12 +00:00
|
|
|
// adjust indices to account for the move
|
2007-05-30 23:25:19 +00:00
|
|
|
// do this before we update the parent/index fields
|
|
|
|
// or we'll re-adjust the index for the item we are moving
|
2007-05-09 01:19:12 +00:00
|
|
|
if (oldParent == aNewParent) {
|
2006-07-18 14:38:44 +00:00
|
|
|
// We can optimize the updates if moving within the same container.
|
|
|
|
// We only shift the items between the old and new positions, since the
|
|
|
|
// insertion will offset the deletion.
|
2006-07-18 14:31:23 +00:00
|
|
|
if (oldIndex > newIndex) {
|
2007-05-09 01:19:12 +00:00
|
|
|
rv = AdjustIndices(oldParent, newIndex, oldIndex - 1, 1);
|
2010-01-16 11:37:57 +00:00
|
|
|
}
|
|
|
|
else {
|
2007-05-09 01:19:12 +00:00
|
|
|
rv = AdjustIndices(oldParent, oldIndex + 1, newIndex, -1);
|
2006-07-18 14:27:16 +00:00
|
|
|
}
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
else {
|
2006-07-18 14:38:44 +00:00
|
|
|
// We're moving between containers, so this happens in two steps.
|
2007-05-09 01:19:12 +00:00
|
|
|
// First, fill the hole from the removal from the old parent.
|
|
|
|
rv = AdjustIndices(oldParent, oldIndex + 1, PR_INT32_MAX, -1);
|
2006-07-18 14:27:16 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 14:38:44 +00:00
|
|
|
// Now, make room in the new parent for the insertion.
|
2008-04-08 06:32:35 +00:00
|
|
|
rv = AdjustIndices(aNewParent, newIndex, PR_INT32_MAX, 1);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 14:27:16 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
{
|
|
|
|
// Update parent and position.
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBMoveItem);
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("parent"), aNewParent);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = stmt->BindInt32ByName(NS_LITERAL_CSTRING("item_index"), newIndex);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = stmt->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 14:48:42 +00:00
|
|
|
}
|
2007-05-30 23:25:19 +00:00
|
|
|
|
2007-07-11 22:38:13 +00:00
|
|
|
PRTime now = PR_Now();
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = SetItemDateInternal(GetStatement(mDBSetItemLastModified),
|
|
|
|
oldParent, now);
|
2007-07-11 22:38:13 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = SetItemDateInternal(GetStatement(mDBSetItemLastModified),
|
|
|
|
aNewParent, now);
|
2007-07-11 22:38:13 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-07-18 14:27:16 +00:00
|
|
|
rv = transaction.Commit();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 11:38:04 +00:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemMoved(aItemId, oldParent, oldIndex, aNewParent,
|
|
|
|
newIndex, itemType));
|
2006-07-18 14:27:16 +00:00
|
|
|
|
2007-08-02 20:19:44 +00:00
|
|
|
// notify dynamic container provider if there is one
|
2007-05-22 22:03:53 +00:00
|
|
|
if (!folderType.IsEmpty()) {
|
2007-08-02 20:19:44 +00:00
|
|
|
nsCOMPtr<nsIDynamicContainer> container =
|
2007-05-22 22:03:53 +00:00
|
|
|
do_GetService(folderType.get(), &rv);
|
2006-07-18 14:42:14 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2007-05-22 22:03:53 +00:00
|
|
|
rv = container->OnContainerMoved(aItemId, aNewParent, newIndex);
|
2006-07-18 14:42:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
}
|
2006-07-18 14:27:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2008-03-17 23:25:36 +00:00
|
|
|
nsresult
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::SetItemDateInternal(mozIStorageStatement* aStatement,
|
|
|
|
PRInt64 aItemId,
|
|
|
|
PRTime aValue)
|
2007-05-19 00:40:55 +00:00
|
|
|
{
|
2010-01-16 11:38:00 +00:00
|
|
|
NS_ENSURE_STATE(aStatement);
|
|
|
|
mozStorageStatementScoper scoper(aStatement);
|
2010-01-16 11:38:02 +00:00
|
|
|
|
2010-04-27 11:25:05 +00:00
|
|
|
nsresult rv = aStatement->BindInt64ByName(NS_LITERAL_CSTRING("date"), aValue);
|
2007-05-19 00:40:55 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = aStatement->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2007-05-19 00:40:55 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-03-17 23:25:36 +00:00
|
|
|
rv = aStatement->Execute();
|
2007-05-19 00:40:55 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// note, we are not notifying the observers
|
|
|
|
// that the item has changed.
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2008-03-17 23:25:36 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavBookmarks::SetItemDateAdded(PRInt64 aItemId, PRTime aDateAdded)
|
|
|
|
{
|
2009-10-01 16:53:26 +00:00
|
|
|
// GetItemType also ensures that aItemId points to a valid item.
|
|
|
|
PRUint16 itemType;
|
|
|
|
nsresult rv = GetItemType(aItemId, &itemType);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-06-12 07:34:35 +00:00
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = SetItemDateInternal(GetStatement(mDBSetItemDateAdded),
|
|
|
|
aItemId, aDateAdded);
|
2008-03-17 23:25:36 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-10-01 16:53:26 +00:00
|
|
|
// Note: mDBSetItemDateAdded also sets lastModified to aDateAdded.
|
2010-01-16 11:38:04 +00:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemChanged(aItemId, NS_LITERAL_CSTRING("dateAdded"),
|
|
|
|
PR_FALSE,
|
|
|
|
nsPrintfCString(16, "%lld", aDateAdded),
|
|
|
|
aDateAdded, itemType));
|
2008-03-17 23:25:36 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2007-05-19 00:40:55 +00:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::GetItemDateAdded(PRInt64 aItemId, PRTime* _dateAdded)
|
2007-05-19 00:40:55 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(_dateAdded);
|
2007-05-19 00:40:55 +00:00
|
|
|
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemProperties);
|
2010-04-27 11:25:05 +00:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2007-05-19 00:40:55 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
PRBool hasResult;
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
2007-05-19 00:40:55 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_TRUE(hasResult, NS_ERROR_INVALID_ARG); // Invalid itemId.
|
2007-05-19 00:40:55 +00:00
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->GetInt64(kGetItemPropertiesIndex_DateAdded, _dateAdded);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-05-19 00:40:55 +00:00
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
return NS_OK;
|
2007-05-19 00:40:55 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2007-05-19 00:40:55 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavBookmarks::SetItemLastModified(PRInt64 aItemId, PRTime aLastModified)
|
|
|
|
{
|
2009-10-01 16:53:26 +00:00
|
|
|
// GetItemType also ensures that aItemId points to a valid item.
|
|
|
|
PRUint16 itemType;
|
|
|
|
nsresult rv = GetItemType(aItemId, &itemType);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-06-12 07:34:35 +00:00
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = SetItemDateInternal(GetStatement(mDBSetItemLastModified),
|
|
|
|
aItemId, aLastModified);
|
2007-05-19 00:40:55 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 11:38:04 +00:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemChanged(aItemId, NS_LITERAL_CSTRING("lastModified"),
|
|
|
|
PR_FALSE,
|
|
|
|
nsPrintfCString(16, "%lld", aLastModified),
|
|
|
|
aLastModified, itemType));
|
2007-05-19 00:40:55 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2007-05-19 00:40:55 +00:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::GetItemLastModified(PRInt64 aItemId, PRTime* aLastModified)
|
2007-05-19 00:40:55 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
2007-05-19 00:40:55 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aLastModified);
|
|
|
|
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemProperties);
|
2010-04-27 11:25:05 +00:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2007-05-19 00:40:55 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
PRBool hasResult;
|
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
2007-05-19 00:40:55 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
if (!hasResult)
|
2007-05-19 00:40:55 +00:00
|
|
|
return NS_ERROR_INVALID_ARG; // invalid item id
|
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->GetInt64(kGetItemPropertiesIndex_LastModified, aLastModified);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
2007-05-19 00:40:55 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2008-10-27 22:52:21 +00:00
|
|
|
nsresult
|
|
|
|
nsNavBookmarks::GetGUIDBase(nsAString &aGUIDBase)
|
|
|
|
{
|
|
|
|
if (!mGUIDBase.IsEmpty()) {
|
|
|
|
aGUIDBase = mGUIDBase;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// generate a new GUID base for this session
|
|
|
|
nsCOMPtr<nsIUUIDGenerator> uuidgen =
|
|
|
|
do_GetService("@mozilla.org/uuid-generator;1");
|
|
|
|
NS_ENSURE_TRUE(uuidgen, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
nsID GUID;
|
|
|
|
nsresult rv = uuidgen->GenerateUUIDInPlace(&GUID);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
char GUIDChars[NSID_LENGTH];
|
|
|
|
GUID.ToProvidedString(GUIDChars);
|
|
|
|
CopyASCIItoUTF16(GUIDChars, mGUIDBase);
|
|
|
|
aGUIDBase = mGUIDBase;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2007-07-26 03:53:59 +00:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::GetItemGUID(PRInt64 aItemId, nsAString& aGUID)
|
2007-07-26 03:53:59 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
|
|
|
|
2007-07-26 03:53:59 +00:00
|
|
|
nsAnnotationService* annosvc = nsAnnotationService::GetAnnotationService();
|
|
|
|
NS_ENSURE_TRUE(annosvc, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
nsresult rv = annosvc->GetItemAnnotationString(aItemId, GUID_ANNO, aGUID);
|
|
|
|
if (NS_SUCCEEDED(rv) || rv != NS_ERROR_NOT_AVAILABLE)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
nsAutoString tmp;
|
|
|
|
tmp.AppendInt(mItemCount++);
|
2008-01-12 04:30:42 +00:00
|
|
|
aGUID.SetCapacity(NSID_LENGTH - 1 + tmp.Length());
|
2008-10-27 22:52:21 +00:00
|
|
|
nsString GUIDBase;
|
|
|
|
rv = GetGUIDBase(GUIDBase);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
aGUID.Assign(GUIDBase);
|
2008-01-12 04:30:42 +00:00
|
|
|
aGUID.Append(tmp);
|
2007-07-26 03:53:59 +00:00
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
rv = SetItemGUID(aItemId, aGUID);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
2007-07-26 03:53:59 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2007-07-26 03:53:59 +00:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::SetItemGUID(PRInt64 aItemId, const nsAString& aGUID)
|
2007-07-26 03:53:59 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
|
|
|
|
2007-07-26 03:53:59 +00:00
|
|
|
PRInt64 checkId;
|
|
|
|
GetItemIdForGUID(aGUID, &checkId);
|
|
|
|
if (checkId != -1)
|
|
|
|
return NS_ERROR_INVALID_ARG; // invalid GUID, already exists
|
|
|
|
|
|
|
|
nsAnnotationService* annosvc = nsAnnotationService::GetAnnotationService();
|
|
|
|
NS_ENSURE_TRUE(annosvc, NS_ERROR_OUT_OF_MEMORY);
|
2010-01-16 11:37:57 +00:00
|
|
|
nsresult rv = annosvc->SetItemAnnotationString(aItemId, GUID_ANNO, aGUID, 0,
|
|
|
|
nsIAnnotationService::EXPIRE_NEVER);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
2007-07-26 03:53:59 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2007-07-26 03:53:59 +00:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::GetItemIdForGUID(const nsAString& aGUID, PRInt64* aItemId)
|
2007-07-26 03:53:59 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aItemId);
|
|
|
|
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemIdForGUID);
|
2010-04-27 11:25:05 +00:00
|
|
|
nsresult rv = stmt->BindStringByName(NS_LITERAL_CSTRING("guid"), aGUID);
|
2007-07-26 03:53:59 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRBool hasMore = PR_FALSE;
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->ExecuteStep(&hasMore);
|
2007-07-26 03:53:59 +00:00
|
|
|
if (NS_FAILED(rv) || ! hasMore) {
|
|
|
|
*aItemId = -1;
|
|
|
|
return NS_OK; // not found: return -1
|
|
|
|
}
|
|
|
|
|
|
|
|
// found, get the itemId
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->GetInt64(0, aItemId);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
2007-07-26 03:53:59 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:27:16 +00:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::SetItemTitle(PRInt64 aItemId, const nsACString& aTitle)
|
2006-07-18 14:27:16 +00:00
|
|
|
{
|
2009-10-01 16:53:26 +00:00
|
|
|
// GetItemType also ensures that aItemId points to a valid item.
|
|
|
|
PRUint16 itemType;
|
|
|
|
nsresult rv = GetItemType(aItemId, &itemType);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-06-12 07:34:35 +00:00
|
|
|
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(statement, mDBSetItemTitle);
|
2009-04-30 16:52:40 +00:00
|
|
|
// Support setting a null title, we support this in insertBookmark.
|
|
|
|
if (aTitle.IsVoid())
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = statement->BindNullByName(NS_LITERAL_CSTRING("item_title"));
|
2009-04-30 16:52:40 +00:00
|
|
|
else
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = statement->BindUTF8StringByName(NS_LITERAL_CSTRING("item_title"), aTitle);
|
2007-02-26 00:54:36 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-06-24 08:59:14 +00:00
|
|
|
PRTime lastModified = PR_Now();
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = statement->BindInt64ByName(NS_LITERAL_CSTRING("date"), lastModified);
|
2007-02-26 00:54:36 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = statement->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2007-02-26 00:54:36 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-04-14 01:10:20 +00:00
|
|
|
rv = statement->Execute();
|
2007-05-19 00:40:55 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 11:38:04 +00:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemChanged(aItemId, NS_LITERAL_CSTRING("title"), PR_FALSE,
|
|
|
|
aTitle, lastModified, itemType));
|
2007-02-26 00:54:36 +00:00
|
|
|
return NS_OK;
|
2006-07-18 14:27:16 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2007-02-26 00:54:36 +00:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::GetItemTitle(PRInt64 aItemId, nsACString& aTitle)
|
2007-02-26 00:54:36 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
|
|
|
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemProperties);
|
2010-04-27 11:25:05 +00:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2007-02-26 00:54:36 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
PRBool hasResult;
|
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
2007-02-26 00:54:36 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
if (!hasResult)
|
2007-02-26 00:54:36 +00:00
|
|
|
return NS_ERROR_INVALID_ARG; // invalid bookmark id
|
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->GetUTF8String(kGetItemPropertiesIndex_Title, aTitle);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
2007-02-26 00:54:36 +00:00
|
|
|
}
|
2006-07-18 14:27:16 +00:00
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2007-02-26 00:54:36 +00:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::GetBookmarkURI(PRInt64 aItemId, nsIURI** aURI)
|
2007-02-26 00:54:36 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
2007-02-26 00:54:36 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
|
|
|
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemProperties);
|
2010-04-27 11:25:05 +00:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2007-02-26 00:54:36 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
PRBool hasResult;
|
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
2006-07-18 14:27:16 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
if (!hasResult)
|
2007-02-26 00:54:36 +00:00
|
|
|
return NS_ERROR_INVALID_ARG; // invalid bookmark id
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
PRInt32 type;
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->GetInt32(kGetItemPropertiesIndex_Type, &type);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// Ensure this is a bookmark.
|
|
|
|
NS_ENSURE_TRUE(type == TYPE_BOOKMARK, NS_ERROR_INVALID_ARG);
|
2007-05-09 01:19:12 +00:00
|
|
|
|
2007-02-26 00:54:36 +00:00
|
|
|
nsCAutoString spec;
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->GetUTF8String(kGetItemPropertiesIndex_URI, spec);
|
2007-02-26 00:54:36 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = NS_NewURI(aURI, spec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2007-02-26 00:54:36 +00:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::GetItemType(PRInt64 aItemId, PRUint16* _type)
|
2007-02-26 00:54:36 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(_type);
|
2009-06-12 07:34:35 +00:00
|
|
|
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemProperties);
|
2010-04-27 11:25:05 +00:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2007-02-26 00:54:36 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 14:27:16 +00:00
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
PRBool hasResult;
|
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
2006-07-18 14:27:16 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
if (!hasResult) {
|
2007-02-26 00:54:36 +00:00
|
|
|
return NS_ERROR_INVALID_ARG; // invalid bookmark id
|
2007-05-09 01:19:12 +00:00
|
|
|
}
|
2006-07-18 14:27:16 +00:00
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
PRInt32 itemType;
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->GetInt32(kGetItemPropertiesIndex_Type, &itemType);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
*_type = itemType;
|
|
|
|
|
2006-07-18 14:27:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:37:57 +00:00
|
|
|
nsresult
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::GetFolderType(PRInt64 aFolder, nsACString& aType)
|
2006-07-18 14:37:57 +00:00
|
|
|
{
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemProperties);
|
2010-04-27 11:25:05 +00:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aFolder);
|
2006-07-18 14:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
PRBool hasResult;
|
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
2006-07-18 14:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
if (!hasResult) {
|
2006-07-18 14:37:57 +00:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
return stmt->GetUTF8String(kGetItemPropertiesIndex_ServiceContractId, aType);
|
2006-07-18 14:37:57 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:41:27 +00:00
|
|
|
nsresult
|
2007-08-02 20:19:44 +00:00
|
|
|
nsNavBookmarks::ResultNodeForContainer(PRInt64 aID,
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavHistoryQueryOptions* aOptions,
|
|
|
|
nsNavHistoryResultNode** aNode)
|
2006-07-18 14:37:57 +00:00
|
|
|
{
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemProperties);
|
2010-04-27 11:25:05 +00:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aID);
|
2010-01-16 11:38:00 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 14:37:57 +00:00
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
PRBool hasResult;
|
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
2006-07-18 14:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 11:38:00 +00:00
|
|
|
NS_ENSURE_TRUE(hasResult, NS_ERROR_INVALID_ARG);
|
2006-07-18 14:37:57 +00:00
|
|
|
|
2006-07-18 14:41:27 +00:00
|
|
|
nsCAutoString title;
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->GetUTF8String(kGetItemPropertiesIndex_Title, title);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 14:41:27 +00:00
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
PRInt32 itemType;
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->GetInt32(kGetItemPropertiesIndex_Type, &itemType);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-08-02 20:19:44 +00:00
|
|
|
if (itemType == TYPE_DYNAMIC_CONTAINER) {
|
2009-10-05 10:12:38 +00:00
|
|
|
// contract id
|
|
|
|
nsCAutoString contractId;
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->GetUTF8String(kGetItemPropertiesIndex_ServiceContractId,
|
|
|
|
contractId);
|
2009-10-05 10:12:38 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 11:38:00 +00:00
|
|
|
*aNode = new nsNavHistoryContainerResultNode(EmptyCString(), title,
|
|
|
|
EmptyCString(),
|
2007-08-02 20:19:44 +00:00
|
|
|
nsINavHistoryResultNode::RESULT_TYPE_DYNAMIC_CONTAINER,
|
2010-01-16 11:38:00 +00:00
|
|
|
PR_TRUE, contractId, aOptions);
|
2007-08-02 20:19:44 +00:00
|
|
|
(*aNode)->mItemId = aID;
|
2010-01-16 11:37:57 +00:00
|
|
|
}
|
|
|
|
else { // TYPE_FOLDER
|
2009-10-05 10:12:38 +00:00
|
|
|
*aNode = new nsNavHistoryFolderResultNode(title, aOptions, aID, EmptyCString());
|
2007-08-02 20:19:44 +00:00
|
|
|
}
|
2007-05-20 11:39:02 +00:00
|
|
|
if (!*aNode)
|
2006-07-18 14:42:14 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2007-05-20 11:39:02 +00:00
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->GetInt64(kGetItemPropertiesIndex_DateAdded,
|
|
|
|
&(*aNode)->mDateAdded);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->GetInt64(kGetItemPropertiesIndex_LastModified,
|
|
|
|
&(*aNode)->mLastModified);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-05-20 11:39:02 +00:00
|
|
|
|
2006-07-18 14:42:14 +00:00
|
|
|
NS_ADDREF(*aNode);
|
2006-07-18 14:37:57 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:27:16 +00:00
|
|
|
nsresult
|
2010-04-09 18:30:29 +00:00
|
|
|
nsNavBookmarks::QueryFolderChildren(
|
|
|
|
PRInt64 aFolderId,
|
|
|
|
nsNavHistoryQueryOptions* aOptions,
|
|
|
|
nsCOMArray<nsNavHistoryResultNode>* aChildren)
|
2006-07-18 14:28:02 +00:00
|
|
|
{
|
2010-04-09 18:30:29 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aOptions);
|
|
|
|
NS_ENSURE_ARG_POINTER(aChildren);
|
|
|
|
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetChildren);
|
2010-04-27 11:25:05 +00:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("parent"), aFolderId);
|
2006-07-18 14:41:27 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 14:28:02 +00:00
|
|
|
|
2010-04-09 18:30:29 +00:00
|
|
|
nsCOMPtr<mozIStorageValueArray> row = do_QueryInterface(stmt, &rv);
|
2008-10-13 15:58:36 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-07-18 14:51:39 +00:00
|
|
|
PRInt32 index = -1;
|
2010-01-16 11:38:00 +00:00
|
|
|
PRBool hasResult;
|
|
|
|
while (NS_SUCCEEDED(stmt->ExecuteStep(&hasResult)) && hasResult) {
|
2010-04-09 18:30:29 +00:00
|
|
|
rv = ProcessFolderNodeRow(row, aOptions, aChildren, index);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2006-07-18 14:51:39 +00:00
|
|
|
|
2010-04-09 18:30:29 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-07-18 14:51:39 +00:00
|
|
|
|
2010-04-09 18:30:29 +00:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsNavBookmarks::ProcessFolderNodeRow(
|
|
|
|
mozIStorageValueArray* aRow,
|
|
|
|
nsNavHistoryQueryOptions* aOptions,
|
|
|
|
nsCOMArray<nsNavHistoryResultNode>* aChildren,
|
|
|
|
PRInt32& aCurrentIndex)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aRow);
|
|
|
|
NS_ENSURE_ARG_POINTER(aOptions);
|
|
|
|
NS_ENSURE_ARG_POINTER(aChildren);
|
|
|
|
|
|
|
|
// The results will be in order of aCurrentIndex. Even if we don't add a node
|
|
|
|
// because it was excluded, we need to count its index, so do that before
|
|
|
|
// doing anything else.
|
|
|
|
aCurrentIndex++;
|
|
|
|
|
|
|
|
PRInt32 itemType;
|
|
|
|
nsresult rv = aRow->GetInt32(kGetChildrenIndex_Type, &itemType);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
PRInt64 id;
|
|
|
|
rv = aRow->GetInt64(nsNavHistory::kGetInfoIndex_ItemId, &id);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
nsRefPtr<nsNavHistoryResultNode> node;
|
|
|
|
if (itemType == TYPE_BOOKMARK) {
|
|
|
|
nsNavHistory* history = nsNavHistory::GetHistoryService();
|
|
|
|
NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
rv = history->RowToResult(aRow, aOptions, getter_AddRefs(node));
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-02-08 22:00:16 +00:00
|
|
|
|
2010-04-09 18:30:29 +00:00
|
|
|
PRUint32 nodeType;
|
|
|
|
node->GetType(&nodeType);
|
|
|
|
if ((nodeType == nsINavHistoryResultNode::RESULT_TYPE_QUERY &&
|
|
|
|
aOptions->ExcludeQueries()) ||
|
|
|
|
(nodeType != nsINavHistoryResultNode::RESULT_TYPE_QUERY &&
|
|
|
|
nodeType != nsINavHistoryResultNode::RESULT_TYPE_FOLDER_SHORTCUT &&
|
|
|
|
aOptions->ExcludeItems())) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (itemType == TYPE_FOLDER || itemType == TYPE_DYNAMIC_CONTAINER) {
|
|
|
|
if (aOptions->ExcludeReadOnlyFolders()) {
|
|
|
|
// If the folder is read-only, skip it.
|
|
|
|
PRBool readOnly;
|
|
|
|
if (itemType == TYPE_DYNAMIC_CONTAINER) {
|
|
|
|
readOnly = PR_TRUE;
|
2008-02-08 22:00:16 +00:00
|
|
|
}
|
2010-04-09 18:30:29 +00:00
|
|
|
else {
|
|
|
|
readOnly = PR_FALSE;
|
2007-05-09 01:19:12 +00:00
|
|
|
GetFolderReadonly(id, &readOnly);
|
2006-07-18 14:47:35 +00:00
|
|
|
}
|
2010-04-09 18:30:29 +00:00
|
|
|
if (readOnly)
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
rv = ResultNodeForContainer(id, aOptions, getter_AddRefs(node));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// This is a separator.
|
|
|
|
if (aOptions->ExcludeItems()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
node = new nsNavHistorySeparatorResultNode();
|
|
|
|
NS_ENSURE_TRUE(node, NS_ERROR_OUT_OF_MEMORY);
|
2006-07-18 14:47:35 +00:00
|
|
|
|
2010-04-09 18:30:29 +00:00
|
|
|
rv = aRow->GetInt64(nsNavHistory::kGetInfoIndex_ItemId, &node->mItemId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = aRow->GetInt64(nsNavHistory::kGetInfoIndex_ItemDateAdded,
|
|
|
|
&node->mDateAdded);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = aRow->GetInt64(nsNavHistory::kGetInfoIndex_ItemLastModified,
|
|
|
|
&node->mLastModified);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2007-04-25 21:03:29 +00:00
|
|
|
|
2010-04-09 18:30:29 +00:00
|
|
|
// Store the index of the node within this container. Note that this is not
|
|
|
|
// moz_bookmarks.position.
|
|
|
|
node->mBookmarkIndex = aCurrentIndex;
|
2006-07-18 14:28:02 +00:00
|
|
|
|
2010-04-09 18:30:29 +00:00
|
|
|
NS_ENSURE_TRUE(aChildren->AppendObject(node), NS_ERROR_OUT_OF_MEMORY);
|
2006-07-18 14:51:39 +00:00
|
|
|
|
2010-04-09 18:30:29 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsNavBookmarks::QueryFolderChildrenAsync(
|
|
|
|
nsNavHistoryFolderResultNode* aNode,
|
|
|
|
PRInt64 aFolderId,
|
|
|
|
mozIStoragePendingStatement** _pendingStmt)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aNode);
|
|
|
|
NS_ENSURE_ARG_POINTER(_pendingStmt);
|
|
|
|
|
|
|
|
mozStorageStatementScoper scope(mDBGetChildren);
|
|
|
|
|
2010-04-27 11:25:05 +00:00
|
|
|
nsresult rv = mDBGetChildren->BindInt64ByName(NS_LITERAL_CSTRING("parent"),
|
|
|
|
aFolderId);
|
2010-04-09 18:30:29 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<mozIStoragePendingStatement> pendingStmt;
|
|
|
|
rv = mDBGetChildren->ExecuteAsync(aNode, getter_AddRefs(pendingStmt));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
NS_IF_ADDREF(*_pendingStmt = pendingStmt);
|
2006-07-18 14:45:36 +00:00
|
|
|
return NS_OK;
|
2006-07-18 14:27:16 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2009-08-21 09:54:12 +00:00
|
|
|
nsresult
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::FolderCount(PRInt64 aFolderId, PRInt32* _folderCount)
|
2006-07-18 14:27:16 +00:00
|
|
|
{
|
2010-01-16 11:37:57 +00:00
|
|
|
*_folderCount = 0;
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBFolderCount);
|
2010-04-27 11:25:05 +00:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("parent"), aFolderId);
|
2009-08-21 09:54:12 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 14:27:16 +00:00
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
PRBool hasResult;
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
2006-07-18 14:27:16 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_TRUE(hasResult, NS_ERROR_UNEXPECTED);
|
2006-07-18 14:27:16 +00:00
|
|
|
|
2009-08-21 09:54:12 +00:00
|
|
|
// Ensure that the folder we are looking for exists.
|
2010-01-16 11:37:57 +00:00
|
|
|
PRInt64 confirmFolderId;
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->GetInt64(1, &confirmFolderId);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(confirmFolderId == aFolderId, NS_ERROR_INVALID_ARG);
|
2009-08-21 09:54:12 +00:00
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->GetInt32(0, _folderCount);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-08-21 09:54:12 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
2006-07-18 14:27:16 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:27:16 +00:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::IsBookmarked(nsIURI* aURI, PRBool* aBookmarked)
|
2006-07-18 14:27:16 +00:00
|
|
|
{
|
2008-04-13 18:17:46 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aBookmarked);
|
2008-04-13 18:17:46 +00:00
|
|
|
|
2010-03-10 12:40:52 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBIsURIBookmarkedInDatabase);
|
2010-04-27 11:25:05 +00:00
|
|
|
nsresult rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("page_url"), aURI);
|
2010-03-10 12:40:52 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = stmt->ExecuteStep(aBookmarked);
|
2006-07-18 14:27:16 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 14:46:00 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:46:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavBookmarks::GetBookmarkedURIFor(nsIURI* aURI, nsIURI** _retval)
|
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
|
2006-07-18 14:46:00 +00:00
|
|
|
*_retval = nsnull;
|
2006-07-18 14:27:16 +00:00
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavHistory* history = nsNavHistory::GetHistoryService();
|
2009-12-01 13:00:45 +00:00
|
|
|
NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY);
|
2010-03-10 12:40:52 +00:00
|
|
|
PRInt64 placeId;
|
2010-08-26 10:19:34 +00:00
|
|
|
nsresult rv = history->GetUrlIdFor(aURI, &placeId, PR_FALSE);
|
2006-07-18 14:27:16 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-03-10 12:40:52 +00:00
|
|
|
if (!placeId) {
|
|
|
|
// This URI is unknown, just return null.
|
2006-07-18 14:46:00 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-07-18 14:27:16 +00:00
|
|
|
|
2010-03-10 12:40:52 +00:00
|
|
|
// Check if a bookmark exists in the redirects chain for this URI.
|
|
|
|
// The query will also check if the page is directly bookmarked, and return
|
|
|
|
// the first found bookmark in case. The check is directly on moz_bookmarks
|
|
|
|
// without special filtering.
|
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBFindRedirectedBookmark);
|
2010-04-27 11:25:03 +00:00
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("page_id"), placeId);
|
2010-03-10 12:40:52 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
PRBool hasBookmarkedOrigin;
|
|
|
|
if (NS_SUCCEEDED(stmt->ExecuteStep(&hasBookmarkedOrigin)) &&
|
|
|
|
hasBookmarkedOrigin) {
|
|
|
|
nsCAutoString spec;
|
|
|
|
rv = stmt->GetUTF8String(0, spec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = NS_NewURI(_retval, spec);
|
2006-07-18 14:46:00 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2010-03-10 12:40:52 +00:00
|
|
|
|
|
|
|
// If there is no bookmarked origin, we will just return null.
|
2006-07-18 14:27:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:27:16 +00:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::ChangeBookmarkURI(PRInt64 aBookmarkId, nsIURI* aNewURI)
|
2006-07-18 14:27:16 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aBookmarkId, 1);
|
2007-05-10 08:05:19 +00:00
|
|
|
NS_ENSURE_ARG(aNewURI);
|
|
|
|
|
2008-10-27 22:52:21 +00:00
|
|
|
mozStorageTransaction transaction(mDBConn, PR_FALSE);
|
2006-07-18 14:48:29 +00:00
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavHistory* history = nsNavHistory::GetHistoryService();
|
2009-12-01 13:00:45 +00:00
|
|
|
NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2007-02-26 00:54:36 +00:00
|
|
|
PRInt64 placeId;
|
2009-12-01 13:00:45 +00:00
|
|
|
nsresult rv = history->GetUrlIdFor(aNewURI, &placeId, PR_TRUE);
|
2006-07-18 14:48:29 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-02-26 00:54:36 +00:00
|
|
|
if (!placeId)
|
2006-07-18 14:48:29 +00:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2009-01-13 10:48:27 +00:00
|
|
|
// We need the bookmark's current corresponding places ID below, so get it now
|
|
|
|
// before we change it. GetBookmarkURI will fail if aBookmarkId is bad.
|
|
|
|
nsCOMPtr<nsIURI> oldURI;
|
|
|
|
PRInt64 oldPlaceId;
|
|
|
|
rv = GetBookmarkURI(aBookmarkId, getter_AddRefs(oldURI));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-12-01 13:00:45 +00:00
|
|
|
rv = history->GetUrlIdFor(oldURI, &oldPlaceId, PR_FALSE);
|
2009-01-13 10:48:27 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(statement, mDBChangeBookmarkURI);
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = statement->BindInt64ByName(NS_LITERAL_CSTRING("page_id"), placeId);
|
2009-06-24 08:59:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
PRTime lastModified = PR_Now();
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = statement->BindInt64ByName(NS_LITERAL_CSTRING("date"), lastModified);
|
2009-06-24 08:59:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = statement->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aBookmarkId);
|
2007-02-26 00:54:36 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-06-24 08:59:14 +00:00
|
|
|
rv = statement->Execute();
|
2007-07-11 22:38:13 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-02-26 00:54:36 +00:00
|
|
|
rv = transaction.Commit();
|
2006-07-18 14:48:29 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-10-11 12:53:31 +00:00
|
|
|
rv = history->UpdateFrecency(placeId);
|
2008-01-25 17:11:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-10-11 12:53:31 +00:00
|
|
|
// Upon changing the URI for a bookmark, update the frecency for the old
|
|
|
|
// place as well.
|
|
|
|
rv = history->UpdateFrecency(oldPlaceId);
|
2008-01-25 17:11:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
nsCAutoString spec;
|
|
|
|
rv = aNewURI->GetSpec(spec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-02-26 00:54:36 +00:00
|
|
|
// Pass the new URI to OnItemChanged.
|
2010-01-16 11:38:04 +00:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemChanged(aBookmarkId, NS_LITERAL_CSTRING("uri"),
|
|
|
|
PR_FALSE, spec, lastModified, TYPE_BOOKMARK));
|
2006-07-18 14:48:29 +00:00
|
|
|
|
2007-02-26 00:54:36 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-07-18 14:48:29 +00:00
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2007-02-26 00:54:36 +00:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::GetFolderIdForItem(PRInt64 aItemId, PRInt64* aFolderId)
|
2007-02-26 00:54:36 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
2007-02-26 00:54:36 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aFolderId);
|
|
|
|
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemProperties);
|
2010-04-27 11:25:05 +00:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2006-07-18 14:48:29 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
PRBool hasResult;
|
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
2006-07-18 14:48:29 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
if (!hasResult)
|
2007-02-26 00:54:36 +00:00
|
|
|
return NS_ERROR_INVALID_ARG; // invalid item id
|
2006-07-18 14:48:29 +00:00
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->GetInt64(kGetItemPropertiesIndex_Parent, aFolderId);
|
2007-10-24 05:50:47 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// this should not happen, but see bug #400448 for details
|
|
|
|
NS_ENSURE_TRUE(aItemId != *aFolderId, NS_ERROR_UNEXPECTED);
|
|
|
|
return NS_OK;
|
2006-07-18 14:48:29 +00:00
|
|
|
}
|
2006-07-18 14:27:16 +00:00
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2009-10-28 23:52:41 +00:00
|
|
|
nsresult
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::GetBookmarkIdsForURITArray(nsIURI* aURI,
|
|
|
|
nsTArray<PRInt64>& aResult)
|
2006-07-18 14:48:29 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
|
|
|
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBFindURIBookmarks);
|
2010-04-27 11:25:05 +00:00
|
|
|
nsresult rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("page_url"), aURI);
|
2006-07-18 14:27:16 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRBool more;
|
2010-01-16 11:38:00 +00:00
|
|
|
while (NS_SUCCEEDED((rv = stmt->ExecuteStep(&more))) && more) {
|
2010-01-16 11:37:57 +00:00
|
|
|
PRInt64 bookmarkId;
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->GetInt64(kFindBookmarksIndex_ID, &bookmarkId);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(aResult.AppendElement(bookmarkId), NS_ERROR_OUT_OF_MEMORY);
|
2006-07-18 14:27:16 +00:00
|
|
|
}
|
2010-01-16 14:48:42 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2008-02-08 22:00:16 +00:00
|
|
|
return NS_OK;
|
2006-07-18 14:48:29 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:48:29 +00:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::GetBookmarkIdsForURI(nsIURI* aURI, PRUint32* aCount,
|
|
|
|
PRInt64** aBookmarks)
|
2006-07-18 14:48:29 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
|
|
|
NS_ENSURE_ARG_POINTER(aCount);
|
|
|
|
NS_ENSURE_ARG_POINTER(aBookmarks);
|
|
|
|
|
2006-07-18 14:48:29 +00:00
|
|
|
*aCount = 0;
|
2007-02-26 00:54:36 +00:00
|
|
|
*aBookmarks = nsnull;
|
|
|
|
nsTArray<PRInt64> bookmarks;
|
2006-07-18 14:48:29 +00:00
|
|
|
|
|
|
|
// Get the information from the DB as a TArray
|
2009-10-28 23:52:41 +00:00
|
|
|
nsresult rv = GetBookmarkIdsForURITArray(aURI, bookmarks);
|
2006-07-18 14:48:29 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Copy the results into a new array for output
|
2007-02-26 00:54:36 +00:00
|
|
|
if (bookmarks.Length()) {
|
2010-01-16 11:37:57 +00:00
|
|
|
*aBookmarks =
|
|
|
|
static_cast<PRInt64*>(nsMemory::Alloc(sizeof(PRInt64) * bookmarks.Length()));
|
|
|
|
if (!*aBookmarks)
|
2006-07-18 14:41:27 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2007-02-26 00:54:36 +00:00
|
|
|
for (PRUint32 i = 0; i < bookmarks.Length(); i ++)
|
|
|
|
(*aBookmarks)[i] = bookmarks[i];
|
2006-07-18 14:41:27 +00:00
|
|
|
}
|
2007-02-26 00:54:36 +00:00
|
|
|
*aCount = bookmarks.Length();
|
2006-07-18 14:48:29 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
2006-07-18 14:27:16 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:34:52 +00:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::GetItemIndex(PRInt64 aItemId, PRInt32* _index)
|
2006-07-18 14:34:52 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(_index);
|
|
|
|
|
|
|
|
*_index = -1;
|
2009-06-12 07:34:35 +00:00
|
|
|
|
2010-01-16 11:38:07 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemProperties);
|
2010-04-27 11:25:05 +00:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2010-01-16 11:38:00 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 11:37:57 +00:00
|
|
|
PRBool hasResult;
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
2006-07-18 14:34:52 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 11:37:57 +00:00
|
|
|
if (!hasResult)
|
2006-07-18 14:34:52 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
2010-01-16 11:38:07 +00:00
|
|
|
rv = stmt->GetInt32(kGetItemPropertiesIndex_Position, _index);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-07-18 14:34:52 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2007-05-11 19:06:57 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavBookmarks::SetItemIndex(PRInt64 aItemId, PRInt32 aNewIndex)
|
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
2009-08-21 09:54:12 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aNewIndex, 0);
|
2009-06-12 07:34:35 +00:00
|
|
|
|
2007-05-11 19:06:57 +00:00
|
|
|
nsresult rv;
|
|
|
|
PRInt32 oldIndex = 0;
|
|
|
|
PRInt64 parent = 0;
|
2010-01-16 11:37:57 +00:00
|
|
|
PRInt32 itemType;
|
2007-05-11 19:06:57 +00:00
|
|
|
|
|
|
|
{
|
2010-01-16 11:38:00 +00:00
|
|
|
mozIStorageStatement* getInfoStmt(mDBGetItemProperties);
|
|
|
|
NS_ENSURE_STATE(getInfoStmt);
|
|
|
|
mozStorageStatementScoper scoper(getInfoStmt);
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = getInfoStmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2007-05-11 19:06:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
PRBool hasResult;
|
|
|
|
rv = getInfoStmt->ExecuteStep(&hasResult);
|
2007-05-11 19:06:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 11:38:00 +00:00
|
|
|
if (!hasResult)
|
2007-05-11 19:06:57 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = getInfoStmt->GetInt32(kGetItemPropertiesIndex_Position, &oldIndex);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = getInfoStmt->GetInt32(kGetItemPropertiesIndex_Type, &itemType);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = getInfoStmt->GetInt64(kGetItemPropertiesIndex_Parent, &parent);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-05-11 19:06:57 +00:00
|
|
|
}
|
|
|
|
|
2009-08-21 09:54:12 +00:00
|
|
|
// Ensure we are not going out of range.
|
|
|
|
PRInt32 folderCount;
|
|
|
|
rv = FolderCount(parent, &folderCount);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(aNewIndex < folderCount, NS_ERROR_INVALID_ARG);
|
|
|
|
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBSetItemIndex);
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2007-05-11 19:06:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:05 +00:00
|
|
|
rv = stmt->BindInt32ByName(NS_LITERAL_CSTRING("item_index"), aNewIndex);
|
2007-05-11 19:06:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->Execute();
|
2007-05-11 19:06:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 11:38:04 +00:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemMoved(aItemId, parent, oldIndex, parent, aNewIndex,
|
|
|
|
itemType));
|
2007-05-11 19:06:57 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2010-08-09 15:59:43 +00:00
|
|
|
nsresult
|
|
|
|
nsNavBookmarks::UpdateKeywordsHashForRemovedBookmark(PRInt64 aItemId)
|
|
|
|
{
|
|
|
|
nsAutoString kw;
|
|
|
|
if (NS_SUCCEEDED(GetKeywordForBookmark(aItemId, kw)) && !kw.IsEmpty()) {
|
|
|
|
nsresult rv = EnsureKeywordsHash();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
mBookmarkToKeywordHash.Remove(aItemId);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-18 14:45:13 +00:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::SetKeywordForBookmark(PRInt64 aBookmarkId,
|
2010-08-28 05:44:05 +00:00
|
|
|
const nsAString& aUserCasedKeyword)
|
2006-07-18 14:45:13 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aBookmarkId, 1);
|
2006-07-18 14:45:13 +00:00
|
|
|
|
2010-08-09 15:59:43 +00:00
|
|
|
nsresult rv = EnsureKeywordsHash();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Shortcuts are always lowercased internally.
|
2010-08-28 05:44:05 +00:00
|
|
|
nsAutoString keyword(aUserCasedKeyword);
|
2010-08-09 15:59:43 +00:00
|
|
|
ToLowerCase(keyword);
|
|
|
|
|
|
|
|
// Check if bookmark was already associated to a keyword.
|
|
|
|
nsAutoString oldKeyword;
|
|
|
|
rv = GetKeywordForBookmark(aBookmarkId, oldKeyword);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Trying to set the same value or to remove a nonexistent keyword is a no-op.
|
|
|
|
if (keyword.Equals(oldKeyword) || (keyword.IsEmpty() && oldKeyword.IsEmpty()))
|
|
|
|
return NS_OK;
|
|
|
|
|
2008-10-27 22:52:21 +00:00
|
|
|
mozStorageTransaction transaction(mDBConn, PR_FALSE);
|
2010-08-09 15:59:43 +00:00
|
|
|
|
|
|
|
nsCOMPtr<mozIStorageStatement> updateBookmarkStmt;
|
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
|
|
|
"UPDATE moz_bookmarks "
|
|
|
|
"SET keyword_id = (SELECT id FROM moz_keywords WHERE keyword = :keyword), "
|
|
|
|
"lastModified = :date "
|
|
|
|
"WHERE id = :item_id "
|
|
|
|
), getter_AddRefs(updateBookmarkStmt));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (keyword.IsEmpty()) {
|
|
|
|
// Remove keyword association from the hash.
|
|
|
|
mBookmarkToKeywordHash.Remove(aBookmarkId);
|
|
|
|
rv = updateBookmarkStmt->BindNullByName(NS_LITERAL_CSTRING("keyword"));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// We are associating bookmark to a new keyword. Create a new keyword
|
|
|
|
// record if needed.
|
|
|
|
nsCOMPtr<mozIStorageStatement> newKeywordStmt;
|
2008-10-27 22:52:21 +00:00
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2010-08-09 15:59:43 +00:00
|
|
|
"INSERT OR IGNORE INTO moz_keywords (keyword) VALUES (:keyword)"
|
|
|
|
), getter_AddRefs(newKeywordStmt));
|
2006-07-18 14:45:13 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-08-09 15:59:43 +00:00
|
|
|
rv = newKeywordStmt->BindStringByName(NS_LITERAL_CSTRING("keyword"),
|
|
|
|
keyword);
|
2006-07-18 14:45:13 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-08-09 15:59:43 +00:00
|
|
|
rv = newKeywordStmt->Execute();
|
2006-07-18 14:45:13 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-08-09 15:59:43 +00:00
|
|
|
// Add new keyword association to the hash, removing the old one if needed.
|
|
|
|
if (!oldKeyword.IsEmpty())
|
|
|
|
mBookmarkToKeywordHash.Remove(aBookmarkId);
|
|
|
|
mBookmarkToKeywordHash.Put(aBookmarkId, keyword);
|
|
|
|
rv = updateBookmarkStmt->BindStringByName(NS_LITERAL_CSTRING("keyword"), keyword);
|
2010-04-27 11:25:05 +00:00
|
|
|
}
|
2006-07-18 14:45:13 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-06-24 08:59:14 +00:00
|
|
|
PRTime lastModified = PR_Now();
|
2010-08-09 15:59:43 +00:00
|
|
|
rv = updateBookmarkStmt->BindInt64ByName(NS_LITERAL_CSTRING("date"),
|
|
|
|
lastModified);
|
2009-06-24 08:59:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-08-09 15:59:43 +00:00
|
|
|
rv = updateBookmarkStmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"),
|
|
|
|
aBookmarkId);
|
2006-07-18 14:45:13 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-08-09 15:59:43 +00:00
|
|
|
rv = updateBookmarkStmt->Execute();
|
2006-07-18 14:45:13 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-07-11 22:38:13 +00:00
|
|
|
|
2009-06-24 08:59:14 +00:00
|
|
|
rv = transaction.Commit();
|
2007-05-19 00:40:55 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-05-14 21:47:59 +00:00
|
|
|
|
2010-01-16 11:38:04 +00:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemChanged(aBookmarkId, NS_LITERAL_CSTRING("keyword"),
|
2010-08-09 15:59:43 +00:00
|
|
|
PR_FALSE, NS_ConvertUTF16toUTF8(keyword),
|
2010-01-16 11:38:04 +00:00
|
|
|
lastModified, TYPE_BOOKMARK));
|
2007-05-19 00:40:55 +00:00
|
|
|
|
2007-02-26 00:54:36 +00:00
|
|
|
return NS_OK;
|
2006-07-18 14:45:13 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:45:13 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavBookmarks::GetKeywordForURI(nsIURI* aURI, nsAString& aKeyword)
|
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
2006-07-18 14:45:13 +00:00
|
|
|
aKeyword.Truncate(0);
|
|
|
|
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetKeywordForURI);
|
2010-04-27 11:25:05 +00:00
|
|
|
nsresult rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("page_url"), aURI);
|
2006-07-18 14:45:13 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRBool hasMore = PR_FALSE;
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->ExecuteStep(&hasMore);
|
2010-01-16 11:37:57 +00:00
|
|
|
if (NS_FAILED(rv) || !hasMore) {
|
2006-07-18 14:49:41 +00:00
|
|
|
aKeyword.SetIsVoid(PR_TRUE);
|
|
|
|
return NS_OK; // not found: return void keyword string
|
|
|
|
}
|
2006-07-18 14:45:13 +00:00
|
|
|
|
|
|
|
// found, get the keyword
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->GetString(0, aKeyword);
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
2006-07-18 14:45:13 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2007-02-26 00:54:36 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavBookmarks::GetKeywordForBookmark(PRInt64 aBookmarkId, nsAString& aKeyword)
|
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aBookmarkId, 1);
|
2007-02-26 00:54:36 +00:00
|
|
|
aKeyword.Truncate(0);
|
|
|
|
|
2010-08-09 15:59:43 +00:00
|
|
|
nsresult rv = EnsureKeywordsHash();
|
2007-02-26 00:54:36 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-08-09 15:59:43 +00:00
|
|
|
nsAutoString keyword;
|
|
|
|
if (!mBookmarkToKeywordHash.Get(aBookmarkId, &keyword)) {
|
2007-02-26 00:54:36 +00:00
|
|
|
aKeyword.SetIsVoid(PR_TRUE);
|
2010-08-09 15:59:43 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
aKeyword.Assign(keyword);
|
2007-02-26 00:54:36 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 11:38:00 +00:00
|
|
|
return NS_OK;
|
2007-02-26 00:54:36 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:45:13 +00:00
|
|
|
NS_IMETHODIMP
|
2010-08-28 05:44:05 +00:00
|
|
|
nsNavBookmarks::GetURIForKeyword(const nsAString& aUserCasedKeyword,
|
|
|
|
nsIURI** aURI)
|
2006-07-18 14:45:13 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
2010-08-28 05:44:05 +00:00
|
|
|
NS_ENSURE_TRUE(!aUserCasedKeyword.IsEmpty(), NS_ERROR_INVALID_ARG);
|
2006-07-18 14:45:13 +00:00
|
|
|
*aURI = nsnull;
|
|
|
|
|
|
|
|
// Shortcuts are always lowercased internally.
|
2010-08-28 05:44:05 +00:00
|
|
|
nsAutoString keyword(aUserCasedKeyword);
|
2010-08-09 15:59:43 +00:00
|
|
|
ToLowerCase(keyword);
|
2006-07-18 14:45:13 +00:00
|
|
|
|
2010-08-09 15:59:43 +00:00
|
|
|
nsresult rv = EnsureKeywordsHash();
|
2006-07-18 14:45:13 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-08-09 15:59:43 +00:00
|
|
|
keywordSearchData searchData;
|
2010-08-28 05:44:05 +00:00
|
|
|
searchData.keyword.Assign(keyword);
|
2010-08-09 15:59:43 +00:00
|
|
|
searchData.itemId = -1;
|
|
|
|
mBookmarkToKeywordHash.EnumerateRead(SearchBookmarkForKeyword, &searchData);
|
2006-07-18 14:45:13 +00:00
|
|
|
|
2010-08-09 15:59:43 +00:00
|
|
|
if (searchData.itemId == -1) {
|
|
|
|
// Not found.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = GetBookmarkURI(searchData.itemId, aURI);
|
2006-07-18 14:45:13 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-08-09 15:59:43 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsNavBookmarks::EnsureKeywordsHash() {
|
|
|
|
if (mBookmarkToKeywordHash.IsInitialized())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
mBookmarkToKeywordHash.Init(BOOKMARKS_TO_KEYWORDS_INITIAL_CACHE_SIZE);
|
|
|
|
|
|
|
|
nsCOMPtr<mozIStorageStatement> stmt;
|
|
|
|
nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
|
|
|
"SELECT b.id, k.keyword "
|
|
|
|
"FROM moz_bookmarks b "
|
|
|
|
"JOIN moz_keywords k ON k.id = b.keyword_id "
|
|
|
|
), getter_AddRefs(stmt));
|
2010-01-16 11:37:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-08-09 15:59:43 +00:00
|
|
|
|
|
|
|
PRBool hasMore;
|
|
|
|
while (NS_SUCCEEDED(stmt->ExecuteStep(&hasMore)) && hasMore) {
|
|
|
|
PRInt64 itemId;
|
|
|
|
rv = stmt->GetInt64(0, &itemId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
nsAutoString keyword;
|
|
|
|
rv = stmt->GetString(1, keyword);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = mBookmarkToKeywordHash.Put(itemId, keyword);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
return NS_OK;
|
2006-07-18 14:45:13 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2007-06-01 00:44:43 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavBookmarks::RunInBatchMode(nsINavHistoryBatchCallback* aCallback,
|
|
|
|
nsISupports* aUserData) {
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG(aCallback);
|
2007-06-01 00:44:43 +00:00
|
|
|
|
2010-12-03 01:37:53 +00:00
|
|
|
mBatching = true;
|
|
|
|
|
2010-11-12 21:20:04 +00:00
|
|
|
// Just forward the request to history. History service must exist for
|
|
|
|
// bookmarks to work and we are observing it, thus batch notifications will be
|
|
|
|
// forwarded to bookmarks observers.
|
|
|
|
nsNavHistory* history = nsNavHistory::GetHistoryService();
|
|
|
|
NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
nsresult rv = history->RunInBatchMode(aCallback, aUserData);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-06-01 00:44:43 +00:00
|
|
|
|
2010-11-12 21:20:04 +00:00
|
|
|
return NS_OK;
|
2007-06-01 00:44:43 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:27:16 +00:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::AddObserver(nsINavBookmarkObserver* aObserver,
|
2006-07-18 14:34:28 +00:00
|
|
|
PRBool aOwnsWeak)
|
2006-07-18 14:27:16 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG(aObserver);
|
2006-07-18 14:34:28 +00:00
|
|
|
return mObservers.AppendWeakElement(aObserver, aOwnsWeak);
|
2006-07-18 14:27:16 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:27:16 +00:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::RemoveObserver(nsINavBookmarkObserver* aObserver)
|
2006-07-18 14:27:16 +00:00
|
|
|
{
|
2006-07-18 14:34:28 +00:00
|
|
|
return mObservers.RemoveWeakElement(aObserver);
|
2006-07-18 14:27:16 +00:00
|
|
|
}
|
|
|
|
|
2010-12-20 17:21:49 +00:00
|
|
|
void
|
2011-02-05 12:22:10 +00:00
|
|
|
nsNavBookmarks::NotifyItemVisited(const ItemVisitData& aData)
|
2010-12-20 17:21:49 +00:00
|
|
|
{
|
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers, nsINavBookmarkObserver,
|
|
|
|
OnItemVisited(aData.itemId, aData.visitId, aData.time));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-02-05 12:22:10 +00:00
|
|
|
nsNavBookmarks::NotifyItemChanged(const ItemChangeData& aData)
|
2010-12-20 17:21:49 +00:00
|
|
|
{
|
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers, nsINavBookmarkObserver,
|
|
|
|
OnItemChanged(aData.itemId, aData.property,
|
|
|
|
aData.isAnnotation, aData.newValue,
|
|
|
|
aData.lastModified, aData.itemType));
|
|
|
|
}
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2010-12-20 17:21:49 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// nsNavBookmarks::nsINavHistoryObserver
|
2006-07-18 14:27:16 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavBookmarks::OnBeginUpdateBatch()
|
|
|
|
{
|
2010-11-12 21:20:04 +00:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver, OnBeginUpdateBatch());
|
2006-07-18 14:27:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:27:16 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavBookmarks::OnEndUpdateBatch()
|
|
|
|
{
|
2010-12-03 01:37:53 +00:00
|
|
|
if (mBatching) {
|
|
|
|
mBatching = false;
|
|
|
|
ForceWALCheckpoint(mDBConn);
|
|
|
|
}
|
|
|
|
|
2010-11-12 21:20:04 +00:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver, OnEndUpdateBatch());
|
2006-07-18 14:27:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:27:16 +00:00
|
|
|
NS_IMETHODIMP
|
2010-12-20 17:21:49 +00:00
|
|
|
nsNavBookmarks::OnVisit(nsIURI* aURI, PRInt64 aVisitId, PRTime aTime,
|
2006-07-18 14:39:08 +00:00
|
|
|
PRInt64 aSessionID, PRInt64 aReferringID,
|
2008-02-27 04:48:51 +00:00
|
|
|
PRUint32 aTransitionType, PRUint32* aAdded)
|
2006-07-18 14:27:16 +00:00
|
|
|
{
|
2010-12-20 17:21:49 +00:00
|
|
|
// If the page is bookmarked, notify observers for each associated bookmark.
|
|
|
|
ItemVisitData visitData;
|
|
|
|
visitData.uri = aURI;
|
|
|
|
visitData.visitId = aVisitId;
|
|
|
|
visitData.time = aTime;
|
2007-02-26 00:54:36 +00:00
|
|
|
|
2010-12-20 17:21:49 +00:00
|
|
|
nsRefPtr< AsyncGetBookmarksForURI<ItemVisitMethod, ItemVisitData> > notifier =
|
|
|
|
new AsyncGetBookmarksForURI<ItemVisitMethod, ItemVisitData>(this, &nsNavBookmarks::NotifyItemVisited, visitData);
|
2011-02-05 12:22:10 +00:00
|
|
|
notifier->Init();
|
2006-07-18 14:27:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2009-04-10 17:51:40 +00:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::OnBeforeDeleteURI(nsIURI* aURI)
|
2009-04-10 17:51:40 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:27:16 +00:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::OnDeleteURI(nsIURI* aURI)
|
2006-07-18 14:27:16 +00:00
|
|
|
{
|
2011-04-29 16:12:20 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsNavHistory* history = nsNavHistory::GetHistoryService();
|
|
|
|
PRInt64 placeId;
|
|
|
|
NS_ABORT_IF_FALSE(
|
|
|
|
history && NS_SUCCEEDED(history->GetUrlIdFor(aURI, &placeId, PR_FALSE)) && !placeId,
|
|
|
|
"OnDeleteURI was notified for a page that still exists?"
|
|
|
|
);
|
|
|
|
#endif
|
2006-07-18 14:27:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:27:16 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavBookmarks::OnClearHistory()
|
|
|
|
{
|
2006-07-18 14:34:52 +00:00
|
|
|
// TODO(bryner): we should notify on visited-time change for all URIs
|
2006-07-18 14:27:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:39:08 +00:00
|
|
|
NS_IMETHODIMP
|
2007-07-26 16:23:11 +00:00
|
|
|
nsNavBookmarks::OnTitleChanged(nsIURI* aURI, const nsAString& aPageTitle)
|
2006-07-18 14:39:08 +00:00
|
|
|
{
|
2007-02-26 00:54:36 +00:00
|
|
|
// NOOP. We don't consume page titles from moz_places anymore.
|
|
|
|
// Title-change notifications are sent from SetItemTitle.
|
2006-07-18 14:39:08 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:27:16 +00:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavBookmarks::OnPageChanged(nsIURI* aURI, PRUint32 aWhat,
|
|
|
|
const nsAString& aValue)
|
2006-07-18 14:27:16 +00:00
|
|
|
{
|
2007-05-27 22:08:13 +00:00
|
|
|
nsresult rv;
|
|
|
|
if (aWhat == nsINavHistoryObserver::ATTRIBUTE_FAVICON) {
|
2010-12-20 17:21:49 +00:00
|
|
|
ItemChangeData changeData;
|
|
|
|
changeData.uri = aURI;
|
|
|
|
changeData.property = NS_LITERAL_CSTRING("favicon");
|
|
|
|
changeData.isAnnotation = PR_FALSE;
|
|
|
|
changeData.newValue = NS_ConvertUTF16toUTF8(aValue);
|
|
|
|
changeData.lastModified = 0;
|
|
|
|
changeData.itemType = TYPE_BOOKMARK;
|
|
|
|
|
2007-05-27 22:08:13 +00:00
|
|
|
// Favicons may be set to either pure URIs or to folder URIs
|
|
|
|
PRBool isPlaceURI;
|
|
|
|
rv = aURI->SchemeIs("place", &isPlaceURI);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (isPlaceURI) {
|
|
|
|
nsCAutoString spec;
|
|
|
|
rv = aURI->GetSpec(spec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
nsNavHistory* history = nsNavHistory::GetHistoryService();
|
2009-12-01 13:00:45 +00:00
|
|
|
NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY);
|
2007-05-27 22:08:13 +00:00
|
|
|
|
|
|
|
nsCOMArray<nsNavHistoryQuery> queries;
|
|
|
|
nsCOMPtr<nsNavHistoryQueryOptions> options;
|
|
|
|
rv = history->QueryStringToQueryArray(spec, &queries, getter_AddRefs(options));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-12-20 17:21:49 +00:00
|
|
|
if (queries.Count() == 1 && queries[0]->Folders().Length() == 1) {
|
|
|
|
changeData.itemId = queries[0]->Folders()[0];
|
|
|
|
NotifyItemChanged(changeData);
|
|
|
|
}
|
2007-05-27 22:08:13 +00:00
|
|
|
}
|
|
|
|
else {
|
2010-12-20 17:21:49 +00:00
|
|
|
nsRefPtr< AsyncGetBookmarksForURI<ItemChangeMethod, ItemChangeData> > notifier =
|
|
|
|
new AsyncGetBookmarksForURI<ItemChangeMethod, ItemChangeData>(this, &nsNavBookmarks::NotifyItemChanged, changeData);
|
2011-02-05 12:22:10 +00:00
|
|
|
notifier->Init();
|
2006-07-18 14:39:08 +00:00
|
|
|
}
|
2006-07-18 14:27:16 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-07-18 14:50:28 +00:00
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2006-07-18 14:50:28 +00:00
|
|
|
NS_IMETHODIMP
|
2010-01-15 16:40:17 +00:00
|
|
|
nsNavBookmarks::OnDeleteVisits(nsIURI* aURI, PRTime aVisitTime)
|
2006-07-18 14:50:28 +00:00
|
|
|
{
|
2011-04-29 16:12:20 +00:00
|
|
|
// Notify "cleartime" only if all visits to the page have been removed.
|
|
|
|
if (!aVisitTime) {
|
|
|
|
// If the page is bookmarked, notify observers for each associated bookmark.
|
|
|
|
ItemChangeData changeData;
|
|
|
|
changeData.uri = aURI;
|
|
|
|
changeData.property = NS_LITERAL_CSTRING("cleartime");
|
|
|
|
changeData.isAnnotation = PR_FALSE;
|
|
|
|
changeData.lastModified = 0;
|
|
|
|
changeData.itemType = TYPE_BOOKMARK;
|
|
|
|
|
|
|
|
nsRefPtr< AsyncGetBookmarksForURI<ItemChangeMethod, ItemChangeData> > notifier =
|
|
|
|
new AsyncGetBookmarksForURI<ItemChangeMethod, ItemChangeData>(this, &nsNavBookmarks::NotifyItemChanged, changeData);
|
|
|
|
notifier->Init();
|
|
|
|
}
|
2006-07-18 14:50:28 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-05-10 08:05:19 +00:00
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
// nsIAnnotationObserver
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavBookmarks::OnPageAnnotationSet(nsIURI* aPage, const nsACString& aName)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavBookmarks::OnItemAnnotationSet(PRInt64 aItemId, const nsACString& aName)
|
|
|
|
{
|
2009-10-01 16:53:26 +00:00
|
|
|
// GetItemType also ensures that aItemId points to a valid item.
|
|
|
|
PRUint16 itemType;
|
|
|
|
nsresult rv = GetItemType(aItemId, &itemType);
|
2009-09-26 08:23:17 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-10-01 16:53:26 +00:00
|
|
|
PRTime lastModified = PR_Now();
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = SetItemDateInternal(GetStatement(mDBSetItemLastModified),
|
|
|
|
aItemId, lastModified);
|
2009-10-01 16:53:26 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 11:38:04 +00:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemChanged(aItemId, aName, PR_TRUE, EmptyCString(),
|
|
|
|
lastModified, itemType));
|
2007-05-19 00:40:55 +00:00
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavBookmarks::OnPageAnnotationRemoved(nsIURI* aPage, const nsACString& aName)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavBookmarks::OnItemAnnotationRemoved(PRInt64 aItemId, const nsACString& aName)
|
2009-06-24 08:59:14 +00:00
|
|
|
{
|
2009-10-01 16:53:26 +00:00
|
|
|
// GetItemType also ensures that aItemId points to a valid item.
|
|
|
|
PRUint16 itemType;
|
|
|
|
nsresult rv = GetItemType(aItemId, &itemType);
|
2007-05-19 00:40:55 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-10-01 16:53:26 +00:00
|
|
|
PRTime lastModified = PR_Now();
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = SetItemDateInternal(GetStatement(mDBSetItemLastModified),
|
|
|
|
aItemId, lastModified);
|
2009-10-01 16:53:26 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 11:38:04 +00:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemChanged(aItemId, aName, PR_TRUE, EmptyCString(),
|
|
|
|
lastModified, itemType));
|
2007-05-19 00:40:55 +00:00
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-06-26 01:08:54 +00:00
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
|
2007-06-26 01:08:54 +00:00
|
|
|
PRBool
|
|
|
|
nsNavBookmarks::ItemExists(PRInt64 aItemId) {
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemProperties);
|
2010-04-27 11:25:05 +00:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2007-06-26 01:08:54 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
PRBool hasResult;
|
2010-01-16 11:38:00 +00:00
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
2007-06-26 01:08:54 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
|
|
|
|
2010-01-16 11:37:57 +00:00
|
|
|
return hasResult;
|
2007-06-26 01:08:54 +00:00
|
|
|
}
|