2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Places.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Google Inc.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2005
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Brian Ryner <bryner@brianryner.com> (original author)
|
2009-10-09 03:30:12 -07:00
|
|
|
* Dietrich Ayala <dietrich@mozilla.com>
|
2009-01-13 02:48:27 -08:00
|
|
|
* Drew Willcoxon <adw@mozilla.com>
|
2009-10-09 03:30:12 -07:00
|
|
|
* Marco Bonardo <mak77@bonardo.net>
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsAppDirectoryServiceDefs.h"
|
|
|
|
#include "nsNavBookmarks.h"
|
|
|
|
#include "nsNavHistory.h"
|
|
|
|
#include "mozStorageHelper.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsNetUtil.h"
|
2007-08-02 13:19:44 -07:00
|
|
|
#include "nsIDynamicContainer.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsUnicharUtils.h"
|
|
|
|
#include "nsFaviconService.h"
|
|
|
|
#include "nsAnnotationService.h"
|
2007-04-04 10:21:03 -07:00
|
|
|
#include "nsPrintfCString.h"
|
2007-07-25 20:53:59 -07:00
|
|
|
#include "nsIUUIDGenerator.h"
|
|
|
|
#include "prprf.h"
|
2008-01-25 09:11:14 -08:00
|
|
|
#include "nsILivemarkService.h"
|
2008-08-04 09:59:56 -07:00
|
|
|
#include "nsPlacesTriggers.h"
|
2008-08-04 10:14:17 -07:00
|
|
|
#include "nsPlacesTables.h"
|
2009-05-11 02:05:56 -07:00
|
|
|
#include "nsPlacesIndexes.h"
|
2009-03-25 13:31:36 -07:00
|
|
|
#include "nsPlacesMacros.h"
|
2010-01-16 03:38:02 -08:00
|
|
|
#include "Helpers.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-19 16:22:19 -07:00
|
|
|
#include "mozilla/FunctionTimer.h"
|
|
|
|
|
2010-08-09 08:59:43 -07:00
|
|
|
#define BOOKMARKS_TO_KEYWORDS_INITIAL_CACHE_SIZE 64
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
const PRInt32 nsNavBookmarks::kFindBookmarksIndex_ID = 0;
|
2007-04-04 10:21:03 -07:00
|
|
|
const PRInt32 nsNavBookmarks::kFindBookmarksIndex_Type = 1;
|
2008-11-05 14:02:12 -08:00
|
|
|
const PRInt32 nsNavBookmarks::kFindBookmarksIndex_PlaceID = 2;
|
2007-03-22 10:30:00 -07:00
|
|
|
const PRInt32 nsNavBookmarks::kFindBookmarksIndex_Parent = 3;
|
|
|
|
const PRInt32 nsNavBookmarks::kFindBookmarksIndex_Position = 4;
|
|
|
|
const PRInt32 nsNavBookmarks::kFindBookmarksIndex_Title = 5;
|
|
|
|
|
|
|
|
// These columns sit to the right of the kGetInfoIndex_* columns.
|
2009-10-05 03:12:38 -07:00
|
|
|
const PRInt32 nsNavBookmarks::kGetChildrenIndex_Position = 13;
|
|
|
|
const PRInt32 nsNavBookmarks::kGetChildrenIndex_Type = 14;
|
|
|
|
const PRInt32 nsNavBookmarks::kGetChildrenIndex_PlaceID = 15;
|
|
|
|
const PRInt32 nsNavBookmarks::kGetChildrenIndex_ServiceContractId = 16;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-05-08 18:19:12 -07: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 13:19:44 -07:00
|
|
|
const PRInt32 nsNavBookmarks::kGetItemPropertiesIndex_ServiceContractId = 7;
|
2007-05-18 17:40:55 -07:00
|
|
|
const PRInt32 nsNavBookmarks::kGetItemPropertiesIndex_DateAdded = 8;
|
|
|
|
const PRInt32 nsNavBookmarks::kGetItemPropertiesIndex_LastModified = 9;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-04-27 04:25:05 -07:00
|
|
|
using namespace mozilla::places;
|
2009-06-24 01:59:14 -07:00
|
|
|
|
2009-12-01 05:00:45 -08:00
|
|
|
PLACES_FACTORY_SINGLETON_IMPLEMENTATION(nsNavBookmarks, gBookmarksService)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#define BOOKMARKS_ANNO_PREFIX "bookmarks/"
|
2007-05-31 17:35:49 -07:00
|
|
|
#define BOOKMARKS_TOOLBAR_FOLDER_ANNO NS_LITERAL_CSTRING(BOOKMARKS_ANNO_PREFIX "toolbarFolder")
|
2007-07-25 20:53:59 -07:00
|
|
|
#define GUID_ANNO NS_LITERAL_CSTRING("placesInternal/GUID")
|
2007-08-02 13:19:44 -07:00
|
|
|
#define READ_ONLY_ANNO NS_LITERAL_CSTRING("placesInternal/READ_ONLY")
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-09 08:59:43 -07: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // Anonymous namespace.
|
|
|
|
|
|
|
|
|
2009-10-05 03:12:38 -07:00
|
|
|
nsNavBookmarks::nsNavBookmarks() : mItemCount(0)
|
|
|
|
, mRoot(0)
|
|
|
|
, mBookmarksRoot(0)
|
|
|
|
, mTagRoot(0)
|
|
|
|
, mToolbarFolder(0)
|
|
|
|
, mBatchLevel(0)
|
2010-04-16 05:31:21 -07:00
|
|
|
, mBatchDBTransaction(nsnull)
|
2009-10-05 03:12:38 -07:00
|
|
|
, mCanNotify(false)
|
|
|
|
, mCacheObservers("bookmark-observers")
|
2010-01-16 03:37:57 -08:00
|
|
|
, mShuttingDown(false)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-12-01 05:00:45 -08:00
|
|
|
NS_ASSERTION(!gBookmarksService,
|
|
|
|
"Attempting to create two instances of the service!");
|
|
|
|
gBookmarksService = this;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsNavBookmarks::~nsNavBookmarks()
|
|
|
|
{
|
2009-12-01 05:00:45 -08:00
|
|
|
NS_ASSERTION(gBookmarksService == this,
|
|
|
|
"Deleting a non-singleton instance of the service");
|
|
|
|
if (gBookmarksService == this)
|
|
|
|
gBookmarksService = nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-05-10 01:05:19 -07:00
|
|
|
NS_IMPL_ISUPPORTS3(nsNavBookmarks,
|
|
|
|
nsINavBookmarksService,
|
|
|
|
nsINavHistoryObserver,
|
|
|
|
nsIAnnotationObserver)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
|
|
|
nsNavBookmarks::Init()
|
|
|
|
{
|
2010-05-19 16:22:19 -07:00
|
|
|
NS_TIME_FUNCTION;
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavHistory* history = nsNavHistory::GetHistoryService();
|
2008-10-27 15:52:21 -07:00
|
|
|
NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
mDBConn = history->GetStorageConnection();
|
2010-01-16 03:38:00 -08:00
|
|
|
NS_ENSURE_STATE(mDBConn);
|
2008-10-27 15:52:21 -07:00
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
// TODO: we could consider roots changes as schema changes, and init them
|
|
|
|
// only if the database has been created/updated, history.databaseStatus
|
|
|
|
// can tell us that.
|
|
|
|
nsresult rv = InitRoots();
|
2008-10-27 15:52:21 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-03-25 13:31:36 -07:00
|
|
|
mCanNotify = true;
|
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
// Observe annotations.
|
2008-10-27 15:52:21 -07:00
|
|
|
nsAnnotationService* annosvc = nsAnnotationService::GetAnnotationService();
|
|
|
|
NS_ENSURE_TRUE(annosvc, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
annosvc->AddObserver(this);
|
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
// Allows us to notify on title changes. MUST BE LAST so it is impossible
|
2008-10-27 15:52:21 -07: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 03:37:57 -08:00
|
|
|
|
2010-01-16 03:38:00 -08: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 15:52:21 -07:00
|
|
|
nsresult // static
|
|
|
|
nsNavBookmarks::InitTables(mozIStorageConnection* aDBConn)
|
|
|
|
{
|
|
|
|
PRBool exists;
|
|
|
|
nsresult rv = aDBConn->TableExists(NS_LITERAL_CSTRING("moz_bookmarks"), &exists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (! exists) {
|
|
|
|
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 02:05:56 -07:00
|
|
|
rv = aDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_BOOKMARKS_PLACETYPE);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-10-27 15:52:21 -07:00
|
|
|
|
|
|
|
// The most common operation is to find the children given a parent and position.
|
2009-05-11 02:05:56 -07:00
|
|
|
rv = aDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_BOOKMARKS_PARENTPOSITION);
|
2007-04-04 10:21:03 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-10-27 15:52:21 -07:00
|
|
|
// fast access to lastModified is useful during sync and to get
|
|
|
|
// last modified bookmark title for tags container's children.
|
2009-05-11 02:05:56 -07:00
|
|
|
rv = aDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_BOOKMARKS_PLACELASTMODIFIED);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2008-10-27 15:52:21 -07:00
|
|
|
// moz_bookmarks_roots
|
|
|
|
rv = aDBConn->TableExists(NS_LITERAL_CSTRING("moz_bookmarks_roots"), &exists);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-10-27 15:52:21 -07:00
|
|
|
if (!exists) {
|
|
|
|
rv = aDBConn->ExecuteSimpleSQL(CREATE_MOZ_BOOKMARKS_ROOTS);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// moz_keywords
|
|
|
|
rv = aDBConn->TableExists(NS_LITERAL_CSTRING("moz_keywords"), &exists);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-10-27 15:52:21 -07:00
|
|
|
if (! exists) {
|
|
|
|
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;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-10-27 15:52:21 -07:00
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
mozIStorageStatement*
|
|
|
|
nsNavBookmarks::GetStatement(const nsCOMPtr<mozIStorageStatement>& aStmt)
|
2008-10-27 15:52:21 -07:00
|
|
|
{
|
2010-01-16 03:38:00 -08:00
|
|
|
if (mShuttingDown)
|
|
|
|
return nsnull;
|
|
|
|
|
2009-06-24 01:59:14 -07:00
|
|
|
// Double ordering covers possible lastModified ties, that could happen when
|
|
|
|
// importing, syncing or due to extensions.
|
2010-01-16 03:38:00 -08:00
|
|
|
RETURN_IF_STMT(mDBFindURIBookmarks, NS_LITERAL_CSTRING(
|
|
|
|
"SELECT b.id "
|
|
|
|
"FROM moz_bookmarks b "
|
2010-04-27 04:25:05 -07:00
|
|
|
"WHERE b.type = :item_type AND b.fk = ( "
|
2010-01-16 03:38:00 -08:00
|
|
|
"SELECT id FROM moz_places_temp "
|
2010-04-27 04:25:05 -07:00
|
|
|
"WHERE url = :page_url "
|
2010-01-16 03:38:00 -08:00
|
|
|
"UNION "
|
|
|
|
"SELECT id FROM moz_places "
|
2010-04-27 04:25:05 -07:00
|
|
|
"WHERE url = :page_url "
|
2010-01-16 03:38:00 -08:00
|
|
|
"LIMIT 1 "
|
|
|
|
") "
|
|
|
|
"ORDER BY b.lastModified DESC, b.id DESC "));
|
2007-10-10 23:42:38 -07:00
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
// Select all children of a given folder, sorted by position.
|
2008-04-11 09:22:01 -07:00
|
|
|
// This is a LEFT OUTER JOIN with moz_places since folders does not have
|
|
|
|
// a reference into that table.
|
2010-01-16 03:38:00 -08: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(
|
|
|
|
"SELECT IFNULL(h_t.id, h.id), IFNULL(h_t.url, h.url), "
|
|
|
|
"COALESCE(b.title, h_t.title, h.title), "
|
|
|
|
"IFNULL(h_t.rev_host, h.rev_host), "
|
|
|
|
"IFNULL(h_t.visit_count, h.visit_count), "
|
|
|
|
"IFNULL(h_t.last_visit_date, h.last_visit_date), "
|
|
|
|
"f.url, null, b.id, b.dateAdded, b.lastModified, b.parent, null, "
|
|
|
|
"b.position, b.type, b.fk, b.folder_type "
|
|
|
|
"FROM moz_bookmarks b "
|
|
|
|
"LEFT JOIN moz_places_temp h_t ON b.fk = h_t.id "
|
|
|
|
"LEFT JOIN moz_places h ON b.fk = h.id "
|
|
|
|
"LEFT JOIN moz_favicons f ON h.favicon_id = f.id "
|
2010-04-27 04:25:05 -07:00
|
|
|
"WHERE b.parent = :parent "
|
2010-01-16 03:38:00 -08: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 04:25:05 -07:00
|
|
|
"(SELECT id FROM moz_bookmarks WHERE id = :parent) "
|
|
|
|
"FROM moz_bookmarks WHERE parent = :parent"));
|
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
RETURN_IF_STMT(mDBGetChildAt, NS_LITERAL_CSTRING(
|
|
|
|
"SELECT id, fk, type FROM moz_bookmarks "
|
2010-04-27 04:25:05 -07:00
|
|
|
"WHERE parent = :parent AND position = :item_index"));
|
2010-01-16 03:38:00 -08:00
|
|
|
|
|
|
|
// Get bookmark/folder/separator properties.
|
|
|
|
RETURN_IF_STMT(mDBGetItemProperties, NS_LITERAL_CSTRING(
|
|
|
|
"SELECT b.id, "
|
|
|
|
"IFNULL((SELECT url FROM moz_places_temp WHERE id = b.fk), "
|
|
|
|
"(SELECT url FROM moz_places WHERE id = b.fk)), "
|
|
|
|
"b.title, b.position, b.fk, b.parent, b.type, b.folder_type, "
|
|
|
|
"b.dateAdded, b.lastModified "
|
|
|
|
"FROM moz_bookmarks b "
|
2010-04-27 04:25:05 -07:00
|
|
|
"WHERE b.id = :item_id"));
|
2010-01-16 03:38:00 -08:00
|
|
|
|
|
|
|
RETURN_IF_STMT(mDBGetItemIdForGUID, NS_LITERAL_CSTRING(
|
|
|
|
"SELECT item_id FROM moz_items_annos "
|
2010-04-27 04:25:05 -07:00
|
|
|
"WHERE content = :guid "
|
2010-01-16 03:38:00 -08:00
|
|
|
"LIMIT 1"));
|
2007-07-25 20:53:59 -07:00
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
RETURN_IF_STMT(mDBInsertBookmark, NS_LITERAL_CSTRING(
|
|
|
|
"INSERT INTO moz_bookmarks "
|
|
|
|
"(id, fk, type, parent, position, title, folder_type, "
|
|
|
|
"dateAdded, lastModified) "
|
2010-04-27 04:25:05 -07:00
|
|
|
"VALUES (:item_id, :page_id, :item_type, :parent, :item_index, "
|
|
|
|
":item_title, :folder_type, :date_added, :last_modified)"));
|
2007-11-09 13:21:38 -08: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 03:38:00 -08:00
|
|
|
RETURN_IF_STMT(mDBIsBookmarkedInDatabase, NS_LITERAL_CSTRING(
|
2010-04-27 04:25:05 -07:00
|
|
|
"SELECT 1 FROM moz_bookmarks WHERE fk = :page_id"));
|
2010-03-10 04:40:52 -08:00
|
|
|
|
|
|
|
RETURN_IF_STMT(mDBIsURIBookmarkedInDatabase, NS_LITERAL_CSTRING(
|
|
|
|
"SELECT 1 FROM moz_bookmarks WHERE fk = ("
|
2010-04-27 04:25:05 -07:00
|
|
|
"SELECT id FROM moz_places_temp WHERE url = :page_url "
|
2010-03-10 04:40:52 -08:00
|
|
|
"UNION ALL "
|
2010-04-27 04:25:05 -07:00
|
|
|
"SELECT id FROM moz_places WHERE url = :page_url "
|
2010-03-10 04:40:52 -08:00
|
|
|
"LIMIT 1"
|
|
|
|
")"));
|
2007-11-09 13:21:38 -08:00
|
|
|
|
2010-03-10 04:40:52 -08:00
|
|
|
// Checks to make sure a place id is a bookmark, and isn't a livemark.
|
2010-01-16 03:38:00 -08:00
|
|
|
RETURN_IF_STMT(mDBIsRealBookmark, NS_LITERAL_CSTRING(
|
|
|
|
"SELECT id "
|
|
|
|
"FROM moz_bookmarks "
|
2010-04-27 04:25:05 -07:00
|
|
|
"WHERE fk = :page_id "
|
|
|
|
"AND type = :item_type "
|
2010-01-16 03:38:00 -08: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 04:25:05 -07:00
|
|
|
"WHERE n.name = :anno_name"
|
2010-01-16 03:38:00 -08:00
|
|
|
") "
|
|
|
|
"LIMIT 1"));
|
|
|
|
|
|
|
|
RETURN_IF_STMT(mDBGetLastBookmarkID, NS_LITERAL_CSTRING(
|
|
|
|
"SELECT id "
|
|
|
|
"FROM moz_bookmarks "
|
|
|
|
"ORDER BY ROWID DESC "
|
|
|
|
"LIMIT 1"));
|
2008-08-16 15:28:28 -07:00
|
|
|
|
2009-06-24 01:59:14 -07: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 03:38:00 -08:00
|
|
|
RETURN_IF_STMT(mDBSetItemDateAdded, NS_LITERAL_CSTRING(
|
2010-04-27 04:25:05 -07:00
|
|
|
"UPDATE moz_bookmarks SET dateAdded = :date, lastModified = :date "
|
|
|
|
"WHERE id = :item_id"));
|
2010-01-16 03:38:00 -08:00
|
|
|
|
|
|
|
RETURN_IF_STMT(mDBSetItemLastModified, NS_LITERAL_CSTRING(
|
2010-04-27 04:25:05 -07:00
|
|
|
"UPDATE moz_bookmarks SET lastModified = :date WHERE id = :item_id"));
|
2010-01-16 03:38:00 -08:00
|
|
|
|
|
|
|
RETURN_IF_STMT(mDBSetItemIndex, NS_LITERAL_CSTRING(
|
2010-04-27 04:25:05 -07:00
|
|
|
"UPDATE moz_bookmarks SET position = :item_index WHERE id = :item_id"));
|
2010-01-16 03:38:00 -08:00
|
|
|
|
|
|
|
// Get keyword text for bookmarked URI.
|
|
|
|
RETURN_IF_STMT(mDBGetKeywordForURI, NS_LITERAL_CSTRING(
|
|
|
|
"SELECT k.keyword "
|
|
|
|
"FROM ( "
|
|
|
|
"SELECT id FROM moz_places_temp "
|
2010-04-27 04:25:05 -07:00
|
|
|
"WHERE url = :page_url "
|
2008-10-27 15:52:20 -07:00
|
|
|
"UNION ALL "
|
2010-01-16 03:38:00 -08:00
|
|
|
"SELECT id FROM moz_places "
|
2010-04-27 04:25:05 -07:00
|
|
|
"WHERE url = :page_url "
|
2010-01-16 03:38:00 -08:00
|
|
|
"LIMIT 1 "
|
|
|
|
") AS h "
|
|
|
|
"JOIN moz_bookmarks b ON b.fk = h.id "
|
|
|
|
"JOIN moz_keywords k ON k.id = b.keyword_id"));
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
RETURN_IF_STMT(mDBAdjustPosition, NS_LITERAL_CSTRING(
|
2010-04-27 04:25:05 -07:00
|
|
|
"UPDATE moz_bookmarks SET position = position + :delta "
|
|
|
|
"WHERE parent = :parent "
|
|
|
|
"AND position >= :from_index AND position <= :to_index"));
|
2010-01-16 03:37:57 -08:00
|
|
|
|
|
|
|
RETURN_IF_STMT(mDBRemoveItem, NS_LITERAL_CSTRING(
|
2010-04-27 04:25:05 -07:00
|
|
|
"DELETE FROM moz_bookmarks WHERE id = :item_id"));
|
2010-01-16 03:37:57 -08:00
|
|
|
|
|
|
|
RETURN_IF_STMT(mDBGetLastChildId, NS_LITERAL_CSTRING(
|
2010-04-27 04:25:05 -07:00
|
|
|
"SELECT id FROM moz_bookmarks WHERE parent = :parent "
|
2010-01-16 03:37:57 -08:00
|
|
|
"ORDER BY position DESC LIMIT 1"));
|
|
|
|
|
|
|
|
RETURN_IF_STMT(mDBMoveItem, NS_LITERAL_CSTRING(
|
2010-04-27 04:25:05 -07:00
|
|
|
"UPDATE moz_bookmarks SET parent = :parent, position = :item_index "
|
|
|
|
"WHERE id = :item_id "));
|
2010-01-16 03:37:57 -08:00
|
|
|
|
|
|
|
RETURN_IF_STMT(mDBSetItemTitle, NS_LITERAL_CSTRING(
|
2010-04-27 04:25:05 -07:00
|
|
|
"UPDATE moz_bookmarks SET title = :item_title, lastModified = :date "
|
|
|
|
"WHERE id = :item_id "));
|
2010-01-16 03:37:57 -08:00
|
|
|
|
|
|
|
RETURN_IF_STMT(mDBChangeBookmarkURI, NS_LITERAL_CSTRING(
|
2010-04-27 04:25:05 -07:00
|
|
|
"UPDATE moz_bookmarks SET fk = :page_id, lastModified = :date "
|
|
|
|
"WHERE id = :item_id "));
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2010-03-10 04:40:52 -08: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.
|
|
|
|
//
|
|
|
|
// Moreover this query does not mix-up all possible cases of disk and temp
|
|
|
|
// tables. This is because we expect a redirects chain to be completely on
|
|
|
|
// disk or completely in memory. We never bring back visits from disk to
|
|
|
|
// memory, we sync visits on a timer (the chained visits have narrow times),
|
|
|
|
// or on bookmarks changes. The likely possiblity that we break a chain in
|
|
|
|
// the middle is so much smaller than the perf and readability hit we would
|
|
|
|
// get making complete crossing joins.
|
|
|
|
//
|
|
|
|
// 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(
|
|
|
|
"SELECT IFNULL( "
|
2010-04-27 04:25:03 -07:00
|
|
|
"(SELECT url FROM moz_places_temp WHERE id = :page_id), "
|
|
|
|
"(SELECT url FROM moz_places WHERE id = :page_id) "
|
2010-03-10 04:40:52 -08:00
|
|
|
") "
|
|
|
|
"FROM moz_bookmarks b "
|
2010-04-27 04:25:03 -07:00
|
|
|
"WHERE b.fk = :page_id "
|
2010-03-10 04:40:52 -08:00
|
|
|
"UNION ALL " // Not directly bookmarked.
|
|
|
|
"SELECT IFNULL( "
|
|
|
|
"(SELECT url FROM moz_places_temp WHERE id = " COALESCE_PLACEID "), "
|
|
|
|
"(SELECT url FROM moz_places WHERE id = " COALESCE_PLACEID ") "
|
|
|
|
") "
|
|
|
|
"FROM moz_historyvisits_temp self "
|
|
|
|
"JOIN moz_bookmarks b ON b.fk = " COALESCE_PLACEID
|
|
|
|
"LEFT JOIN moz_historyvisits_temp parent ON parent.id = self.from_visit "
|
|
|
|
"LEFT JOIN moz_historyvisits_temp grandparent ON parent.from_visit = grandparent.id "
|
|
|
|
"AND parent.visit_type IN (") + redirectsFragment + NS_LITERAL_CSTRING(") "
|
|
|
|
"LEFT JOIN moz_historyvisits_temp 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 04:25:03 -07:00
|
|
|
"AND self.place_id = :page_id "
|
2010-03-10 04:40:52 -08:00
|
|
|
"UNION ALL " // Not in the temp table.
|
|
|
|
"SELECT IFNULL( "
|
|
|
|
"(SELECT url FROM moz_places_temp WHERE id = " COALESCE_PLACEID "), "
|
|
|
|
"(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 04:25:03 -07:00
|
|
|
"AND self.place_id = :page_id "
|
2010-03-10 04:40:52 -08:00
|
|
|
"LIMIT 1 " // Stop at the first result.
|
|
|
|
));
|
|
|
|
#undef COALESCE_PLACEID
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-13 22:45:49 -08:00
|
|
|
nsresult
|
|
|
|
nsNavBookmarks::FinalizeStatements() {
|
2010-01-16 03:37:57 -08:00
|
|
|
mShuttingDown = true;
|
|
|
|
|
2008-11-13 22:45:49 -08:00
|
|
|
mozIStorageStatement* stmts[] = {
|
|
|
|
mDBGetChildren,
|
|
|
|
mDBFindURIBookmarks,
|
|
|
|
mDBFolderCount,
|
|
|
|
mDBGetChildAt,
|
|
|
|
mDBGetItemProperties,
|
|
|
|
mDBGetItemIdForGUID,
|
|
|
|
mDBInsertBookmark,
|
|
|
|
mDBIsBookmarkedInDatabase,
|
2009-01-27 18:01:33 -08:00
|
|
|
mDBIsRealBookmark,
|
2008-11-13 22:45:49 -08:00
|
|
|
mDBGetLastBookmarkID,
|
|
|
|
mDBSetItemDateAdded,
|
|
|
|
mDBSetItemLastModified,
|
|
|
|
mDBSetItemIndex,
|
|
|
|
mDBGetKeywordForURI,
|
2010-01-16 03:37:57 -08:00
|
|
|
mDBAdjustPosition,
|
|
|
|
mDBRemoveItem,
|
|
|
|
mDBGetLastChildId,
|
|
|
|
mDBMoveItem,
|
|
|
|
mDBSetItemTitle,
|
|
|
|
mDBChangeBookmarkURI,
|
2010-03-10 04:40:52 -08:00
|
|
|
mDBIsURIBookmarkedInDatabase,
|
|
|
|
mDBFindRedirectedBookmark,
|
2008-11-13 22:45:49 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(stmts); i++) {
|
|
|
|
nsresult rv = nsNavHistory::FinalizeStatement(stmts[i]);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsNavBookmarks::InitRoots
|
|
|
|
//
|
|
|
|
// This locates and creates if necessary the root items in the bookmarks
|
|
|
|
// folder hierarchy. These items are stored in a special roots table that
|
|
|
|
// maps short predefined names to folder IDs.
|
|
|
|
//
|
|
|
|
// Normally, these folders will exist already and we will save their IDs
|
|
|
|
// which are exposed through the bookmark service interface.
|
|
|
|
//
|
|
|
|
// If the root does not exist, a folder is created for it and the ID is
|
|
|
|
// saved in the root table. No user-visible name is given to these folders
|
|
|
|
// and they have no parent or other attributes.
|
|
|
|
//
|
|
|
|
// These attributes are set when the default_places.html file is imported.
|
|
|
|
// It defines the hierarchy, and has special attributes that tell us when
|
|
|
|
// a folder is one of our well-known roots. We then insert the root in the
|
|
|
|
// defined point in the hierarchy and set its attributes from this.
|
|
|
|
//
|
|
|
|
// This should be called as the last part of the init process so that
|
|
|
|
// all of the statements are set up and the service is ready to use.
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsNavBookmarks::InitRoots()
|
|
|
|
{
|
2010-01-16 03:38:00 -08:00
|
|
|
mozStorageTransaction transaction(mDBConn, PR_FALSE);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<mozIStorageStatement> getRootStatement;
|
2008-10-27 15:52:21 -07:00
|
|
|
nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2010-04-27 04:25:05 -07:00
|
|
|
"SELECT folder_id FROM moz_bookmarks_roots WHERE root_name = :root_name"),
|
2008-10-27 15:52:20 -07:00
|
|
|
getter_AddRefs(getRootStatement));
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-11-19 18:01:53 -08:00
|
|
|
PRBool createdPlacesRoot = PR_FALSE;
|
2010-01-16 03:37:57 -08:00
|
|
|
rv = CreateRoot(getRootStatement, NS_LITERAL_CSTRING("places"),
|
|
|
|
&mRoot, 0, &createdPlacesRoot);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
rv = CreateRoot(getRootStatement, NS_LITERAL_CSTRING("menu"),
|
|
|
|
&mBookmarksRoot, mRoot, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-11-19 18:01:53 -08:00
|
|
|
PRBool createdToolbarFolder;
|
2010-01-16 03:37:57 -08:00
|
|
|
rv = CreateRoot(getRootStatement, NS_LITERAL_CSTRING("toolbar"),
|
|
|
|
&mToolbarFolder, mRoot, &createdToolbarFolder);
|
2007-11-19 18:01:53 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Once toolbar was not a root, we may need to move over the items and
|
|
|
|
// delete the custom folder
|
|
|
|
if (!createdPlacesRoot && createdToolbarFolder) {
|
|
|
|
nsAnnotationService* annosvc = nsAnnotationService::GetAnnotationService();
|
|
|
|
NS_ENSURE_TRUE(annosvc, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
nsTArray<PRInt64> folders;
|
2010-01-16 03:37:57 -08:00
|
|
|
rv = annosvc->GetItemsWithAnnotationTArray(BOOKMARKS_TOOLBAR_FOLDER_ANNO,
|
|
|
|
&folders);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-11-19 18:01:53 -08:00
|
|
|
if (folders.Length() > 0) {
|
|
|
|
nsCOMPtr<mozIStorageStatement> moveItems;
|
2008-10-27 15:52:21 -07:00
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2010-04-27 04:25:05 -07:00
|
|
|
"UPDATE moz_bookmarks SET parent = :new_parent "
|
|
|
|
"WHERE parent = :old_parent"
|
|
|
|
), getter_AddRefs(moveItems));
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = moveItems->BindInt64ByName(NS_LITERAL_CSTRING("new_parent"),
|
|
|
|
mToolbarFolder);
|
2007-11-19 18:01:53 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = moveItems->BindInt64ByName(NS_LITERAL_CSTRING("old_parent"),
|
|
|
|
folders[0]);
|
2007-11-19 18:01:53 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = moveItems->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = RemoveFolder(folders[0]);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
rv = CreateRoot(getRootStatement, NS_LITERAL_CSTRING("tags"),
|
|
|
|
&mTagRoot, mRoot, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
rv = CreateRoot(getRootStatement, NS_LITERAL_CSTRING("unfiled"),
|
|
|
|
&mUnfiledRoot, mRoot, nsnull);
|
2007-09-16 18:42:15 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-11-19 18:01:53 -08:00
|
|
|
// Set titles for special folders
|
|
|
|
// We cannot rely on createdPlacesRoot due to Fx3beta->final migration path
|
2008-11-12 12:45:53 -08:00
|
|
|
PRUint16 databaseStatus = nsINavHistoryService::DATABASE_STATUS_OK;
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavHistory* history = nsNavHistory::GetHistoryService();
|
2009-12-01 05:00:45 -08:00
|
|
|
NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
rv = history->GetDatabaseStatus(&databaseStatus);
|
2008-11-12 12:45:53 -08:00
|
|
|
if (NS_FAILED(rv) ||
|
|
|
|
databaseStatus != nsINavHistoryService::DATABASE_STATUS_OK) {
|
2007-04-15 14:15:56 -07:00
|
|
|
rv = InitDefaults();
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2007-05-31 18:33:29 -07:00
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = transaction.Commit();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-04-15 14:15:56 -07:00
|
|
|
// nsNavBookmarks::InitDefaults
|
|
|
|
//
|
|
|
|
// Initializes default bookmarks and containers.
|
|
|
|
// Pulls from places.propertes for l10n.
|
|
|
|
// Replaces the old default_places.html file.
|
|
|
|
nsresult
|
|
|
|
nsNavBookmarks::InitDefaults()
|
|
|
|
{
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavHistory* history = nsNavHistory::GetHistoryService();
|
2009-12-01 05:00:45 -08:00
|
|
|
NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY);
|
2010-01-16 03:37:57 -08:00
|
|
|
nsIStringBundle* bundle = history->GetBundle();
|
2008-10-27 15:52:22 -07:00
|
|
|
NS_ENSURE_TRUE(bundle, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2007-11-19 18:01:53 -08:00
|
|
|
// Bookmarks Menu
|
2007-04-15 14:15:56 -07:00
|
|
|
nsXPIDLString bookmarksTitle;
|
2010-01-16 03:37:57 -08:00
|
|
|
nsresult rv = bundle->GetStringFromName(
|
|
|
|
NS_LITERAL_STRING("BookmarksMenuFolderTitle").get(),
|
|
|
|
getter_Copies(bookmarksTitle));
|
2007-04-15 14:15:56 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-01-08 19:54:37 -08:00
|
|
|
rv = SetItemTitle(mBookmarksRoot, NS_ConvertUTF16toUTF8(bookmarksTitle));
|
2007-04-15 14:15:56 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-11-19 18:01:53 -08:00
|
|
|
// Bookmarks Toolbar
|
2007-04-15 14:15:56 -07:00
|
|
|
nsXPIDLString toolbarTitle;
|
2010-01-16 03:37:57 -08:00
|
|
|
rv = bundle->GetStringFromName(
|
|
|
|
NS_LITERAL_STRING("BookmarksToolbarFolderTitle").get(),
|
|
|
|
getter_Copies(toolbarTitle));
|
2007-04-15 14:15:56 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-01-08 19:54:37 -08:00
|
|
|
rv = SetItemTitle(mToolbarFolder, NS_ConvertUTF16toUTF8(toolbarTitle));
|
2007-04-15 14:15:56 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-03-08 03:45:32 -08:00
|
|
|
// Unsorted Bookmarks
|
2007-11-19 18:01:53 -08:00
|
|
|
nsXPIDLString unfiledTitle;
|
2010-01-16 03:37:57 -08:00
|
|
|
rv = bundle->GetStringFromName(
|
|
|
|
NS_LITERAL_STRING("UnsortedBookmarksFolderTitle").get(),
|
|
|
|
getter_Copies(unfiledTitle));
|
2007-11-19 18:01:53 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-01-08 19:54:37 -08:00
|
|
|
rv = SetItemTitle(mUnfiledRoot, NS_ConvertUTF16toUTF8(unfiledTitle));
|
2007-11-19 18:01:53 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-11-19 18:01:53 -08:00
|
|
|
// Tags
|
|
|
|
nsXPIDLString tagsTitle;
|
2010-01-16 03:37:57 -08:00
|
|
|
rv = bundle->GetStringFromName(
|
|
|
|
NS_LITERAL_STRING("TagsFolderTitle").get(),
|
|
|
|
getter_Copies(tagsTitle));
|
2007-11-19 18:01:53 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-01-08 19:54:37 -08:00
|
|
|
rv = SetItemTitle(mTagRoot, NS_ConvertUTF16toUTF8(tagsTitle));
|
2007-11-19 18:01:53 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-05-31 17:35:49 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsNavBookmarks::CreateRoot
|
|
|
|
//
|
|
|
|
// This gets or creates a root folder of the given type. aWasCreated
|
|
|
|
// (optional) is true if the folder had to be created, false if we just used
|
|
|
|
// an old one. The statement that gets a folder ID from a root name is
|
|
|
|
// passed in so the DB only needs to parse the statement once, and we don't
|
|
|
|
// have to have a global for this. Creation is less optimized because it
|
|
|
|
// happens rarely.
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsNavBookmarks::CreateRoot(mozIStorageStatement* aGetRootStatement,
|
|
|
|
const nsCString& name, PRInt64* aID,
|
2007-05-31 18:33:29 -07:00
|
|
|
PRInt64 aParentID, PRBool* aWasCreated)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-01-16 03:38:00 -08:00
|
|
|
NS_ENSURE_STATE(aGetRootStatement);
|
2010-01-16 03:37:57 -08:00
|
|
|
mozStorageStatementScoper scoper(aGetRootStatement);
|
2007-03-22 10:30:00 -07:00
|
|
|
PRBool hasResult = PR_FALSE;
|
2010-04-27 04:25:05 -07:00
|
|
|
nsresult rv = aGetRootStatement->BindUTF8StringByName(NS_LITERAL_CSTRING("root_name"), name);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = aGetRootStatement->ExecuteStep(&hasResult);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (hasResult) {
|
|
|
|
if (aWasCreated)
|
|
|
|
*aWasCreated = PR_FALSE;
|
|
|
|
rv = aGetRootStatement->GetInt64(0, aID);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ASSERTION(*aID != 0, "Root is 0 for some reason, folders can't have 0 ID");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aWasCreated)
|
|
|
|
*aWasCreated = PR_TRUE;
|
|
|
|
|
|
|
|
// create folder with no name or attributes
|
|
|
|
nsCOMPtr<mozIStorageStatement> insertStatement;
|
2008-01-08 19:54:37 -08:00
|
|
|
rv = CreateFolder(aParentID, EmptyCString(), nsINavBookmarksService::DEFAULT_INDEX, aID);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// save root ID
|
2008-10-27 15:52:21 -07:00
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2010-04-27 04:25:05 -07:00
|
|
|
"INSERT INTO moz_bookmarks_roots (root_name, folder_id) "
|
|
|
|
"VALUES (:root_name, :item_id)"
|
|
|
|
), getter_AddRefs(insertStatement));
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = insertStatement->BindUTF8StringByName(NS_LITERAL_CSTRING("root_name"), name);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = insertStatement->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), *aID);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = insertStatement->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2009-01-27 18:01:33 -08:00
|
|
|
PRBool
|
|
|
|
nsNavBookmarks::IsRealBookmark(PRInt64 aPlaceId)
|
|
|
|
{
|
2010-03-10 04:40:52 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBIsRealBookmark);
|
2010-04-27 04:25:05 -07:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("page_id"), aPlaceId);
|
2010-03-10 04:40:52 -08:00
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Binding failed");
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = stmt->BindInt32ByName(NS_LITERAL_CSTRING("item_type"), TYPE_BOOKMARK);
|
2010-03-10 04:40:52 -08:00
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Binding failed");
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = stmt->BindUTF8StringByName(NS_LITERAL_CSTRING("anno_name"),
|
|
|
|
NS_LITERAL_CSTRING(LMANNO_FEEDURI));
|
2010-03-10 04:40:52 -08: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-27 18:01:33 -08:00
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsNavBookmarks::IsBookmarkedInDatabase
|
|
|
|
//
|
2009-01-27 18:01:33 -08:00
|
|
|
// This checks to see if the specified place_id is actually bookmarked.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsNavBookmarks::IsBookmarkedInDatabase(PRInt64 aPlaceId,
|
2010-01-16 03:37:57 -08:00
|
|
|
PRBool* aIsBookmarked)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-01-16 03:38:02 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBIsBookmarkedInDatabase);
|
2010-04-27 04:25:05 -07:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("page_id"), aPlaceId);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->ExecuteStep(aIsBookmarked);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::AdjustIndices(PRInt64 aFolderId,
|
|
|
|
PRInt32 aStartIndex,
|
|
|
|
PRInt32 aEndIndex,
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt32 aDelta)
|
|
|
|
{
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ASSERTION(aStartIndex >= 0 && aEndIndex <= PR_INT32_MAX &&
|
|
|
|
aStartIndex <= aEndIndex, "Bad indices");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-01-16 03:38:02 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBAdjustPosition);
|
2010-04-27 04:25:05 -07:00
|
|
|
nsresult rv = stmt->BindInt32ByName(NS_LITERAL_CSTRING("delta"), aDelta);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("parent"), aFolderId);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = stmt->BindInt32ByName(NS_LITERAL_CSTRING("from_index"), aStartIndex);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = stmt->BindInt32ByName(NS_LITERAL_CSTRING("to_index"), aEndIndex);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
rv = stmt->Execute();
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::GetPlacesRoot(PRInt64* aRoot)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*aRoot = mRoot;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::GetBookmarksMenuFolder(PRInt64* aRoot)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*aRoot = mBookmarksRoot;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::GetToolbarFolder(PRInt64* aFolderId)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*aFolderId = mToolbarFolder;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::GetTagsFolder(PRInt64* aRoot)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*aRoot = mTagRoot;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-09-16 18:42:15 -07:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::GetUnfiledBookmarksFolder(PRInt64* aRoot)
|
2007-09-16 18:42:15 -07:00
|
|
|
{
|
|
|
|
*aRoot = mUnfiledRoot;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2009-06-24 01:59:14 -07:00
|
|
|
nsresult
|
|
|
|
nsNavBookmarks::InsertBookmarkInDB(PRInt64 aItemId,
|
|
|
|
PRInt64 aPlaceId,
|
|
|
|
enum ItemType aItemType,
|
|
|
|
PRInt64 aParentId,
|
|
|
|
PRInt32 aIndex,
|
2010-01-16 03:37:57 -08:00
|
|
|
const nsACString& aTitle,
|
2009-06-24 01:59:14 -07:00
|
|
|
PRTime aDateAdded,
|
|
|
|
PRTime aLastModified,
|
2010-01-16 03:37:57 -08:00
|
|
|
const nsAString& aServiceContractId,
|
|
|
|
PRInt64* _newItemId)
|
2009-06-24 01:59:14 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(_newItemId, "Null pointer passed to InsertBookmarkInDB!");
|
|
|
|
|
2010-01-16 03:38:02 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBInsertBookmark);
|
2009-06-24 01:59:14 -07:00
|
|
|
nsresult rv;
|
|
|
|
if (aItemId && aItemId != -1)
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2009-06-24 01:59:14 -07:00
|
|
|
else
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = stmt->BindNullByName(NS_LITERAL_CSTRING("item_id"));
|
2009-06-24 01:59:14 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (aPlaceId && aPlaceId != -1)
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("page_id"), aPlaceId);
|
2009-06-24 01:59:14 -07:00
|
|
|
else
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = stmt->BindNullByName(NS_LITERAL_CSTRING("page_id"));
|
2009-06-24 01:59:14 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = stmt->BindInt32ByName(NS_LITERAL_CSTRING("item_type"), aItemType);
|
2009-06-24 01:59:14 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("parent"), aParentId);
|
2009-06-24 01:59:14 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = stmt->BindInt32ByName(NS_LITERAL_CSTRING("item_index"), aIndex);
|
2009-06-24 01:59:14 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Support NULL titles.
|
|
|
|
if (aTitle.IsVoid())
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = stmt->BindNullByName(NS_LITERAL_CSTRING("item_title"));
|
2009-06-24 01:59:14 -07:00
|
|
|
else
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = stmt->BindUTF8StringByName(NS_LITERAL_CSTRING("item_title"), aTitle);
|
2009-06-24 01:59:14 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-04-27 04:25:05 -07: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 01:59:14 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("date_added"), aDateAdded);
|
2009-06-24 01:59:14 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-04-27 04:25:05 -07: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 01:59:14 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->Execute();
|
2009-06-24 01:59:14 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!aItemId || aItemId == -1) {
|
|
|
|
// Get the new inserted item id.
|
2010-01-16 03:38:02 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(lastInsertIdStmt, mDBGetLastBookmarkID);
|
2009-06-24 01:59:14 -07:00
|
|
|
PRBool hasResult;
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = lastInsertIdStmt->ExecuteStep(&hasResult);
|
2009-06-24 01:59:14 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(hasResult, NS_ERROR_UNEXPECTED);
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = lastInsertIdStmt->GetInt64(0, _newItemId);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-06-24 01:59:14 -07:00
|
|
|
}
|
2010-01-16 03:37:57 -08:00
|
|
|
else {
|
2009-06-24 01:59:14 -07:00
|
|
|
*_newItemId = aItemId;
|
2010-01-16 03:37:57 -08:00
|
|
|
}
|
2009-06-24 01:59:14 -07: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 03:38:00 -08:00
|
|
|
rv = SetItemDateInternal(GetStatement(mDBSetItemLastModified),
|
|
|
|
aParentId, aDateAdded);
|
2009-06-24 01:59:14 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2009-06-12 00:34:35 -07:00
|
|
|
nsNavBookmarks::InsertBookmark(PRInt64 aFolder,
|
2010-01-16 03:37:57 -08:00
|
|
|
nsIURI* aURI,
|
2009-06-12 00:34:35 -07:00
|
|
|
PRInt32 aIndex,
|
2008-01-08 19:54:37 -08:00
|
|
|
const nsACString& aTitle,
|
2010-01-16 03:37:57 -08:00
|
|
|
PRInt64* aNewBookmarkId)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-06-12 00:34:35 -07:00
|
|
|
NS_ENSURE_ARG(aURI);
|
|
|
|
NS_ENSURE_ARG_POINTER(aNewBookmarkId);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// You can pass -1 to indicate append, but no other negative number is allowed
|
|
|
|
if (aIndex < nsINavBookmarksService::DEFAULT_INDEX)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2008-10-27 15:52:21 -07:00
|
|
|
mozStorageTransaction transaction(mDBConn, PR_FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavHistory* history = nsNavHistory::GetHistoryService();
|
2009-12-01 05:00:45 -08:00
|
|
|
NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2008-08-16 15:28:28 -07:00
|
|
|
// This is really a place ID
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt64 childID;
|
2009-12-01 05:00:45 -08:00
|
|
|
nsresult rv = history->GetUrlIdFor(aURI, &childID, PR_TRUE);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-11-21 17:46:43 -08:00
|
|
|
PRInt32 index;
|
2009-08-21 02:54:12 -07:00
|
|
|
PRInt32 folderCount;
|
|
|
|
rv = FolderCount(aFolder, &folderCount);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (aIndex == nsINavBookmarksService::DEFAULT_INDEX ||
|
|
|
|
aIndex >= folderCount) {
|
|
|
|
index = folderCount;
|
|
|
|
}
|
|
|
|
else {
|
2007-11-21 17:46:43 -08:00
|
|
|
index = aIndex;
|
|
|
|
rv = AdjustIndices(aFolder, index, PR_INT32_MAX, 1);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-06-24 01:59:14 -07:00
|
|
|
rv = InsertBookmarkInDB(-1, childID, BOOKMARK, aFolder, index,
|
|
|
|
aTitle, PR_Now(), nsnull, EmptyString(),
|
|
|
|
aNewBookmarkId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-01-25 09:11:14 -08: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 00:34:35 -07:00
|
|
|
rv = aURI->GetSpec(url);
|
2008-01-25 09:11:14 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// prevent place: queries from showing up in the URL bar autocomplete results
|
|
|
|
PRBool isBookmark = !IsQueryURI(url);
|
|
|
|
|
|
|
|
if (isBookmark) {
|
|
|
|
// if it is a livemark item (the parent is a livemark),
|
|
|
|
// we pass in false for isBookmark. otherwise, unvisited livemark
|
|
|
|
// items will appear in URL autocomplete before we visit them.
|
|
|
|
PRBool parentIsLivemark;
|
|
|
|
nsCOMPtr<nsILivemarkService> lms =
|
|
|
|
do_GetService(NS_LIVEMARKSERVICE_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = lms->IsLivemark(aFolder, &parentIsLivemark);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
isBookmark = !parentIsLivemark;
|
|
|
|
}
|
|
|
|
|
|
|
|
// when we created the moz_place entry for the new bookmark
|
|
|
|
// (a side effect of calling GetUrlIdFor()) frecency -1;
|
|
|
|
// now we re-calculate the frecency for this moz_place entry.
|
2009-12-01 05:00:45 -08:00
|
|
|
rv = history->UpdateFrecency(childID, isBookmark);
|
2008-01-25 09:11:14 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = transaction.Commit();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 03:38:04 -08:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemAdded(*aNewBookmarkId, aFolder, index, TYPE_BOOKMARK));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-12-20 11:07:58 -08: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 14:02:12 -08:00
|
|
|
PRInt64 grandParentId;
|
|
|
|
rv = GetFolderIdForItem(aFolder, &grandParentId);
|
2007-12-20 11:07:58 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-11-05 14:02:12 -08:00
|
|
|
if (grandParentId == mTagRoot) {
|
2007-12-20 11:07:58 -08:00
|
|
|
// query for all bookmarks for that URI, notify for each
|
|
|
|
nsTArray<PRInt64> bookmarks;
|
2009-10-28 16:52:41 -07:00
|
|
|
rv = GetBookmarkIdsForURITArray(aURI, bookmarks);
|
2007-12-20 11:07:58 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (bookmarks.Length()) {
|
|
|
|
for (PRUint32 i = 0; i < bookmarks.Length(); i++) {
|
2010-01-16 03:38:04 -08:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemChanged(bookmarks[i], NS_LITERAL_CSTRING("tags"),
|
|
|
|
PR_FALSE, EmptyCString(), 0,
|
|
|
|
TYPE_BOOKMARK));
|
2007-12-20 11:07:58 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavBookmarks::RemoveItem(PRInt64 aItemId)
|
|
|
|
{
|
2009-02-11 02:53:35 -08:00
|
|
|
NS_ENSURE_TRUE(aItemId != mRoot, NS_ERROR_INVALID_ARG);
|
|
|
|
|
2008-04-13 11:17:46 -07:00
|
|
|
nsresult rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt32 childIndex;
|
|
|
|
PRInt64 placeId, folderId;
|
2010-01-16 03:37:57 -08:00
|
|
|
PRInt32 itemType;
|
2007-05-10 01:05:19 -07:00
|
|
|
nsCAutoString buffer;
|
2007-12-20 11:07:58 -08:00
|
|
|
nsCAutoString spec;
|
2007-05-10 01:05:19 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
{ // scoping to ensure the statement gets reset
|
2010-01-16 03:38:02 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(getInfoStmt, mDBGetItemProperties);
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = getInfoStmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
PRBool hasResult;
|
|
|
|
rv = getInfoStmt->ExecuteStep(&hasResult);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!hasResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_INVALID_ARG; // invalid bookmark id
|
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = getInfoStmt->GetInt32(kGetItemPropertiesIndex_Position, &childIndex);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = getInfoStmt->GetInt64(kGetItemPropertiesIndex_PlaceID, &placeId);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = getInfoStmt->GetInt64(kGetItemPropertiesIndex_Parent, &folderId);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = getInfoStmt->GetInt32(kGetItemPropertiesIndex_Type, &itemType);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-12-20 11:07:58 -08:00
|
|
|
if (itemType == TYPE_BOOKMARK) {
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = getInfoStmt->GetUTF8String(kGetItemPropertiesIndex_URI, spec);
|
2007-12-20 11:07:58 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-04-13 11:17:46 -07:00
|
|
|
if (itemType == TYPE_FOLDER) {
|
|
|
|
rv = RemoveFolder(aItemId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:38:04 -08:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnBeforeItemRemoved(aItemId, itemType));
|
2009-03-19 12:56:51 -07:00
|
|
|
|
2008-10-27 15:52:21 -07:00
|
|
|
mozStorageTransaction transaction(mDBConn, PR_FALSE);
|
2008-04-13 11:17:46 -07: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 03:37:57 -08:00
|
|
|
{
|
2010-01-16 03:38:02 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBRemoveItem);
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = stmt->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (childIndex != -1) {
|
|
|
|
rv = AdjustIndices(folderId, childIndex + 1, PR_INT32_MAX, -1);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = SetItemDateInternal(GetStatement(mDBSetItemLastModified),
|
|
|
|
folderId, PR_Now());
|
2007-07-11 15:38:13 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = transaction.Commit();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-01-25 09:11:14 -08:00
|
|
|
if (itemType == TYPE_BOOKMARK) {
|
2009-02-16 03:09:19 -08:00
|
|
|
// UpdateFrecency needs to know whether placeId is still bookmarked.
|
|
|
|
// Although we removed aItemId, placeId may still be bookmarked elsewhere;
|
|
|
|
// IsRealBookmark will know.
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavHistory* history = nsNavHistory::GetHistoryService();
|
2009-12-01 05:00:45 -08:00
|
|
|
NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
rv = history->UpdateFrecency(placeId, IsRealBookmark(placeId));
|
2008-01-25 09:11:14 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-08-09 08:59:43 -07:00
|
|
|
|
|
|
|
rv = UpdateKeywordsHashForRemovedBookmark(aItemId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-01-25 09:11:14 -08:00
|
|
|
}
|
|
|
|
|
2010-01-16 03:38:04 -08:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemRemoved(aItemId, folderId, childIndex, itemType));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-12-20 11:07:58 -08:00
|
|
|
if (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.
|
2008-11-05 14:02:12 -08:00
|
|
|
PRInt64 grandParentId;
|
|
|
|
rv = GetFolderIdForItem(folderId, &grandParentId);
|
2007-12-20 11:07:58 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-11-05 14:02:12 -08:00
|
|
|
if (grandParentId == mTagRoot) {
|
2007-12-20 11:07:58 -08:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
rv = NS_NewURI(getter_AddRefs(uri), spec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
nsTArray<PRInt64> bookmarks;
|
|
|
|
|
2009-10-28 16:52:41 -07:00
|
|
|
rv = GetBookmarkIdsForURITArray(uri, bookmarks);
|
2007-12-20 11:07:58 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (bookmarks.Length()) {
|
|
|
|
for (PRUint32 i = 0; i < bookmarks.Length(); i++) {
|
2010-01-16 03:38:04 -08:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemChanged(bookmarks[i],
|
|
|
|
NS_LITERAL_CSTRING("tags"), PR_FALSE,
|
|
|
|
EmptyCString(), 0, TYPE_BOOKMARK));
|
2007-12-20 11:07:58 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::CreateFolder(PRInt64 aParent, const nsACString& aName,
|
|
|
|
PRInt32 aIndex, PRInt64* aNewFolder)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-06-12 00:34:35 -07:00
|
|
|
// NOTE: aParent can be null for root creation, so not checked
|
|
|
|
NS_ENSURE_ARG_POINTER(aNewFolder);
|
|
|
|
|
2007-08-02 13:19:44 -07:00
|
|
|
// CreateContainerWithID returns the index of the new folder, but that's not
|
2007-03-22 10:30:00 -07: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 03:37:57 -08:00
|
|
|
nsresult rv = CreateContainerWithID(-1, aParent, aName, EmptyString(),
|
|
|
|
PR_TRUE, &localIndex, aNewFolder);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::CreateDynamicContainer(PRInt64 aParent,
|
|
|
|
const nsACString& aName,
|
|
|
|
const nsAString& aContractId,
|
2007-08-02 13:19:44 -07:00
|
|
|
PRInt32 aIndex,
|
2010-01-16 03:37:57 -08:00
|
|
|
PRInt64* aNewFolder)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_FALSE(aContractId.IsEmpty(), NS_ERROR_INVALID_ARG);
|
2007-08-02 13:19:44 -07:00
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
nsresult rv = CreateContainerWithID(-1, aParent, aName, aContractId,
|
|
|
|
PR_FALSE, &aIndex, aNewFolder);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
2007-08-02 13:19:44 -07:00
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-08-02 13:19:44 -07:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::GetFolderReadonly(PRInt64 aFolder, PRBool* aResult)
|
2007-08-02 13:19:44 -07:00
|
|
|
{
|
2009-06-12 00:34:35 -07:00
|
|
|
NS_ENSURE_ARG_MIN(aFolder, 1);
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
|
2007-08-02 13:19:44 -07:00
|
|
|
nsAnnotationService* annosvc = nsAnnotationService::GetAnnotationService();
|
|
|
|
NS_ENSURE_TRUE(annosvc, NS_ERROR_OUT_OF_MEMORY);
|
2010-01-16 03:37:57 -08:00
|
|
|
nsresult rv = annosvc->ItemHasAnnotation(aFolder, READ_ONLY_ANNO, aResult);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
2007-08-02 13:19:44 -07:00
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-08-02 13:19:44 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavBookmarks::SetFolderReadonly(PRInt64 aFolder, PRBool aReadOnly)
|
|
|
|
{
|
2009-06-12 00:34:35 -07:00
|
|
|
NS_ENSURE_ARG_MIN(aFolder, 1);
|
|
|
|
|
2007-08-02 13:19:44 -07:00
|
|
|
nsAnnotationService* annosvc = nsAnnotationService::GetAnnotationService();
|
|
|
|
NS_ENSURE_TRUE(annosvc, NS_ERROR_OUT_OF_MEMORY);
|
2010-01-16 03:37:57 -08:00
|
|
|
nsresult rv;
|
2007-08-02 13:19:44 -07:00
|
|
|
if (aReadOnly) {
|
2010-01-16 03:37:57 -08:00
|
|
|
rv = annosvc->SetItemAnnotationInt32(aFolder, READ_ONLY_ANNO, 1, 0,
|
|
|
|
nsAnnotationService::EXPIRE_NEVER);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-08-02 13:19:44 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
PRBool hasAnno;
|
2010-01-16 03:37:57 -08:00
|
|
|
rv = annosvc->ItemHasAnnotation(aFolder, READ_ONLY_ANNO, &hasAnno);
|
2007-08-02 13:19:44 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 03:37:57 -08:00
|
|
|
if (hasAnno) {
|
|
|
|
rv = annosvc->RemoveItemAnnotation(aFolder, READ_ONLY_ANNO);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2007-08-02 13:19:44 -07:00
|
|
|
}
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::CreateContainerWithID(PRInt64 aItemId,
|
|
|
|
PRInt64 aParent,
|
2008-01-08 19:54:37 -08:00
|
|
|
const nsACString& aName,
|
2007-08-02 13:19:44 -07:00
|
|
|
const nsAString& aContractId,
|
|
|
|
PRBool aIsBookmarkFolder,
|
2010-01-16 03:37:57 -08:00
|
|
|
PRInt32* aIndex,
|
|
|
|
PRInt64* aNewFolder)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// You can pass -1 to indicate append, but no other negative number is allowed
|
|
|
|
if (*aIndex < -1)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2008-10-27 15:52:21 -07:00
|
|
|
mozStorageTransaction transaction(mDBConn, PR_FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-11-21 17:46:43 -08:00
|
|
|
PRInt32 index;
|
2009-08-21 02:54:12 -07:00
|
|
|
PRInt32 folderCount;
|
|
|
|
nsresult rv = FolderCount(aParent, &folderCount);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (*aIndex == nsINavBookmarksService::DEFAULT_INDEX ||
|
|
|
|
*aIndex >= folderCount) {
|
|
|
|
index = folderCount;
|
2007-11-21 17:46:43 -08:00
|
|
|
} else {
|
|
|
|
index = *aIndex;
|
|
|
|
rv = AdjustIndices(aParent, index, PR_INT32_MAX, 1);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-06-24 01:59:14 -07:00
|
|
|
ItemType containerType = aIsBookmarkFolder ? FOLDER
|
|
|
|
: DYNAMIC_CONTAINER;
|
|
|
|
rv = InsertBookmarkInDB(aItemId, nsnull, containerType, aParent, index,
|
|
|
|
aName, PR_Now(), nsnull, aContractId, aNewFolder);
|
2007-07-11 15:38:13 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = transaction.Commit();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 03:38:04 -08:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemAdded(*aNewFolder, aParent, index, containerType));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
*aIndex = index;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::InsertSeparator(PRInt64 aParent,
|
|
|
|
PRInt32 aIndex,
|
2007-05-10 11:18:34 -07:00
|
|
|
PRInt64* aNewItemId)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-06-12 00:34:35 -07:00
|
|
|
NS_ENSURE_ARG_MIN(aParent, 1);
|
2009-11-06 07:25:00 -08:00
|
|
|
// -1 means "append", but no other negative value is allowed.
|
|
|
|
NS_ENSURE_ARG_MIN(aIndex, -1);
|
2009-06-12 00:34:35 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aNewItemId);
|
|
|
|
|
2008-10-27 15:52:21 -07:00
|
|
|
mozStorageTransaction transaction(mDBConn, PR_FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-11-21 17:46:43 -08:00
|
|
|
PRInt32 index;
|
2009-08-21 02:54:12 -07: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 07:25:00 -08:00
|
|
|
}
|
|
|
|
else {
|
2007-11-21 17:46:43 -08:00
|
|
|
index = aIndex;
|
|
|
|
rv = AdjustIndices(aParent, index, PR_INT32_MAX, 1);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
// Set a NULL title, not an empty title.
|
2009-06-24 01:59:14 -07:00
|
|
|
nsCString voidString;
|
|
|
|
voidString.SetIsVoid(PR_TRUE);
|
|
|
|
rv = InsertBookmarkInDB(-1, nsnull, SEPARATOR, aParent, index,
|
|
|
|
voidString, PR_Now(), nsnull, EmptyString(),
|
|
|
|
aNewItemId);
|
2007-07-11 15:38:13 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = transaction.Commit();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 03:38:04 -08:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemAdded(*aNewItemId, aParent, index, TYPE_SEPARATOR));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2008-02-06 13:05:23 -08:00
|
|
|
nsresult
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::GetLastChildId(PRInt64 aFolderId, PRInt64* aItemId)
|
2008-02-06 13:05:23 -08:00
|
|
|
{
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ASSERTION(aFolderId > 0, "Invalid folder id");
|
2009-11-06 07:25:00 -08:00
|
|
|
*aItemId = -1;
|
|
|
|
|
2010-01-16 03:38:02 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetLastChildId);
|
2010-04-27 04:25:05 -07:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("parent"), aFolderId);
|
2008-02-06 13:05:23 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-11-06 07:25:00 -08:00
|
|
|
PRBool found;
|
2010-01-16 03:37:57 -08:00
|
|
|
rv = stmt->ExecuteStep(&found);
|
2008-02-06 13:05:23 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 03:37:57 -08:00
|
|
|
if (found) {
|
|
|
|
rv = stmt->GetInt64(0, aItemId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2008-02-06 13:05:23 -08:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2008-02-06 13:05:23 -08:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::GetIdForItemAt(PRInt64 aFolder,
|
|
|
|
PRInt32 aIndex,
|
|
|
|
PRInt64* aItemId)
|
2008-02-06 13:05:23 -08:00
|
|
|
{
|
2009-06-12 00:34:35 -07:00
|
|
|
NS_ENSURE_ARG_MIN(aFolder, 1);
|
|
|
|
NS_ENSURE_ARG_POINTER(aItemId);
|
|
|
|
|
2009-11-06 07:25:00 -08:00
|
|
|
*aItemId = -1;
|
|
|
|
|
2008-02-06 13:05:23 -08:00
|
|
|
nsresult rv;
|
|
|
|
if (aIndex == nsINavBookmarksService::DEFAULT_INDEX) {
|
2009-11-06 07:25:00 -08:00
|
|
|
// Get last item within aFolder.
|
2009-02-09 10:16:02 -08:00
|
|
|
rv = GetLastChildId(aFolder, aItemId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-11-06 07:25:00 -08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Get the item in aFolder with position aIndex.
|
2010-01-16 03:38:02 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetChildAt);
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("parent"), aFolder);
|
2009-11-06 07:25:00 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = stmt->BindInt32ByName(NS_LITERAL_CSTRING("item_index"), aIndex);
|
2009-11-06 07:25:00 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-02-06 13:05:23 -08:00
|
|
|
|
2009-11-06 07:25:00 -08:00
|
|
|
PRBool found;
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->ExecuteStep(&found);
|
2009-11-06 07:25:00 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 03:37:57 -08:00
|
|
|
if (found) {
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->GetInt64(0, aItemId);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2008-02-06 13:05:23 -08:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::GetParentAndIndexOfFolder(PRInt64 aFolderId,
|
|
|
|
PRInt64* _aParent,
|
|
|
|
PRInt32* _aIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-01-16 03:38:02 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemProperties);
|
2010-04-27 04:25:05 -07:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aFolderId);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
PRBool hasResult;
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_TRUE(hasResult, NS_ERROR_INVALID_ARG);
|
2009-11-06 07:25:00 -08:00
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->GetInt64(kGetItemPropertiesIndex_Parent, _aParent);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->GetInt32(kGetItemPropertiesIndex_Position, _aIndex);
|
2009-11-06 07:25:00 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
|
|
|
nsresult
|
2008-04-13 11:17:46 -07:00
|
|
|
nsNavBookmarks::RemoveFolder(PRInt64 aFolderId)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-02-11 02:53:35 -08:00
|
|
|
NS_ENSURE_TRUE(aFolderId != mRoot, NS_ERROR_INVALID_ARG);
|
|
|
|
|
2010-01-16 03:38:04 -08:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnBeforeItemRemoved(aFolderId, TYPE_FOLDER));
|
2009-03-19 12:56:51 -07:00
|
|
|
|
2008-10-27 15:52:21 -07:00
|
|
|
mozStorageTransaction transaction(mDBConn, PR_FALSE);
|
2007-09-28 16:28:14 -07:00
|
|
|
|
2008-04-13 11:17:46 -07:00
|
|
|
nsresult rv;
|
2007-05-08 18:19:12 -07:00
|
|
|
PRInt64 parent;
|
2008-04-13 11:17:46 -07:00
|
|
|
PRInt32 index, type;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCAutoString folderType;
|
2007-05-08 18:19:12 -07:00
|
|
|
{
|
2010-01-16 03:38:02 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(getInfoStmt, mDBGetItemProperties);
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = getInfoStmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aFolderId);
|
2007-05-08 18:19:12 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
PRBool hasResult;
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = getInfoStmt->ExecuteStep(&hasResult);
|
2007-05-08 18:19:12 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 03:37:57 -08:00
|
|
|
if (!hasResult) {
|
2007-05-08 18:19:12 -07:00
|
|
|
return NS_ERROR_INVALID_ARG; // folder is not in the hierarchy
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = getInfoStmt->GetInt32(kGetItemPropertiesIndex_Type, &type);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = getInfoStmt->GetInt64(kGetItemPropertiesIndex_Parent, &parent);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = getInfoStmt->GetInt32(kGetItemPropertiesIndex_Position, &index);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = getInfoStmt->GetUTF8String(kGetItemPropertiesIndex_ServiceContractId,
|
|
|
|
folderType);
|
2007-05-08 18:19:12 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
// Ensure this is really a folder.
|
|
|
|
NS_ENSURE_TRUE(type == TYPE_FOLDER, NS_ERROR_INVALID_ARG);
|
2008-04-13 11:17:46 -07: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-08 18:19:12 -07:00
|
|
|
// If this is a container bookmark, try to notify its service.
|
2007-03-22 10:30:00 -07:00
|
|
|
if (folderType.Length() > 0) {
|
2008-10-13 08:58:36 -07:00
|
|
|
// There is a type associated with this folder.
|
2007-08-02 13:19:44 -07:00
|
|
|
nsCOMPtr<nsIDynamicContainer> bmcServ = do_GetService(folderType.get());
|
2007-03-22 10:30:00 -07:00
|
|
|
if (bmcServ) {
|
2008-04-13 11:17:46 -07:00
|
|
|
rv = bmcServ->OnContainerRemoving(aFolderId);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
|
|
|
|
"Remove folder container notification failed.");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove all of the folder's children
|
2008-11-05 14:02:12 -08:00
|
|
|
rv = RemoveFolderChildren(aFolderId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
{
|
|
|
|
// Remove the folder from its parent.
|
2010-01-16 03:38:02 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBRemoveItem);
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aFolderId);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = stmt->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
rv = AdjustIndices(parent, index + 1, PR_INT32_MAX, -1);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = SetItemDateInternal(GetStatement(mDBSetItemLastModified),
|
|
|
|
parent, PR_Now());
|
2007-07-11 15:38:13 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = transaction.Commit();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-04-13 11:17:46 -07:00
|
|
|
if (aFolderId == mToolbarFolder) {
|
2007-05-16 23:06:48 -07:00
|
|
|
mToolbarFolder = 0;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:38:04 -08:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemRemoved(aFolderId, parent, index, TYPE_FOLDER));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS1(nsNavBookmarks::RemoveFolderTransaction, nsITransaction)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-06-12 00:34:35 -07:00
|
|
|
nsNavBookmarks::GetRemoveFolderTransaction(PRInt64 aFolderId, nsITransaction** aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-06-12 00:34:35 -07:00
|
|
|
NS_ENSURE_ARG_MIN(aFolderId, 1);
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Create and initialize a RemoveFolderTransaction object that can be used to
|
|
|
|
// recreate the folder safely later.
|
|
|
|
|
|
|
|
RemoveFolderTransaction* rft =
|
2009-06-12 00:34:35 -07:00
|
|
|
new RemoveFolderTransaction(aFolderId);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!rft)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
NS_ADDREF(*aResult = rft);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2008-11-05 14:02:12 -08:00
|
|
|
nsresult
|
|
|
|
nsNavBookmarks::GetDescendantChildren(PRInt64 aFolderId,
|
|
|
|
PRInt64 aGrandParentId,
|
|
|
|
nsTArray<folderChildrenInfo>& aFolderChildrenArray) {
|
|
|
|
// New children will be added from this index on.
|
|
|
|
PRUint32 startIndex = aFolderChildrenArray.Length();
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv;
|
|
|
|
{
|
2008-11-05 14:02:12 -08:00
|
|
|
// Collect children informations.
|
2010-01-16 03:38:02 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetChildren);
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("parent"), aFolderId);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRBool hasMore;
|
2010-01-16 03:38:00 -08:00
|
|
|
while (NS_SUCCEEDED(stmt->ExecuteStep(&hasMore)) && hasMore) {
|
2008-11-05 14:02:12 -08:00
|
|
|
folderChildrenInfo child;
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->GetInt64(nsNavHistory::kGetInfoIndex_ItemId, &child.itemId);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-11-05 14:02:12 -08:00
|
|
|
child.parentId = aFolderId;
|
|
|
|
child.grandParentId = aGrandParentId;
|
2010-01-16 03:37:57 -08:00
|
|
|
PRInt32 itemType;
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->GetInt32(kGetChildrenIndex_Type, &itemType);
|
2010-01-16 03:37:57 -08:00
|
|
|
child.itemType = (PRUint16)itemType;
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->GetInt64(kGetChildrenIndex_PlaceID, &child.placeId);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->GetInt32(kGetChildrenIndex_Position, &child.index);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-11-05 14:02:12 -08:00
|
|
|
|
|
|
|
if (child.itemType == TYPE_BOOKMARK) {
|
|
|
|
nsCAutoString URIString;
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->GetUTF8String(nsNavHistory::kGetInfoIndex_URL, URIString);
|
2008-11-05 14:02:12 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
child.url = URIString;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-11-05 14:02:12 -08:00
|
|
|
else if (child.itemType == TYPE_FOLDER) {
|
|
|
|
nsCAutoString folderType;
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->GetUTF8String(kGetChildrenIndex_ServiceContractId,
|
|
|
|
folderType);
|
2008-11-05 14:02:12 -08: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);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-05 14:02:12 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2008-11-05 14:02:12 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavBookmarks::RemoveFolderChildren(PRInt64 aFolderId)
|
|
|
|
{
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_ARG_MIN(aFolderId, 1);
|
|
|
|
|
2008-11-05 14:02:12 -08:00
|
|
|
nsresult rv;
|
2010-01-16 03:37:57 -08:00
|
|
|
PRInt32 itemType;
|
2008-11-05 14:02:12 -08:00
|
|
|
PRInt64 grandParentId;
|
|
|
|
{
|
2010-01-16 03:38:02 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(getInfoStmt, mDBGetItemProperties);
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = getInfoStmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aFolderId);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-11-05 14:02:12 -08:00
|
|
|
|
|
|
|
// Sanity check: ensure that item exists.
|
|
|
|
PRBool folderExists;
|
2010-01-16 03:38:00 -08:00
|
|
|
if (NS_FAILED(getInfoStmt->ExecuteStep(&folderExists)) || !folderExists)
|
2008-11-05 14:02:12 -08:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
// Sanity check: ensure that this is a folder.
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = getInfoStmt->GetInt32(kGetItemPropertiesIndex_Type, &itemType);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-11-05 14:02:12 -08: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 03:38:00 -08:00
|
|
|
rv = getInfoStmt->GetInt64(kGetItemPropertiesIndex_Parent, &grandParentId);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-11-05 14:02:12 -08: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 12:56:51 -07:00
|
|
|
|
|
|
|
// Notify observers that we are about to remove this child.
|
2010-01-16 03:38:04 -08:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnBeforeItemRemoved(child.itemId, child.itemType));
|
2009-03-19 12:56:51 -07:00
|
|
|
|
2008-11-05 14:02:12 -08: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 12:56:51 -07:00
|
|
|
// XXX (bug 484094) this should use a bookmark observer!
|
2008-11-05 14:02:12 -08: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 03:32:52 -08:00
|
|
|
nsCOMPtr<mozIStorageStatement> deleteStatement;
|
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2008-11-05 14:02:12 -08:00
|
|
|
"DELETE FROM moz_bookmarks "
|
2010-04-27 04:25:05 -07:00
|
|
|
"WHERE parent IN (:parent") +
|
2008-11-05 14:02:12 -08:00
|
|
|
foldersToRemove +
|
2009-02-12 03:32:52 -08:00
|
|
|
NS_LITERAL_CSTRING(")"),
|
|
|
|
getter_AddRefs(deleteStatement));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = deleteStatement->BindInt64ByName(NS_LITERAL_CSTRING("parent"), aFolderId);
|
2009-02-12 03:32:52 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = deleteStatement->Execute();
|
2008-11-05 14:02:12 -08: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 03:38:00 -08:00
|
|
|
rv = SetItemDateInternal(GetStatement(mDBSetItemLastModified),
|
|
|
|
aFolderId, PR_Now());
|
2008-11-05 14:02:12 -08: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;
|
|
|
|
|
2009-02-16 03:09:19 -08:00
|
|
|
// UpdateFrecency needs to know whether placeId is still bookmarked.
|
|
|
|
// Although we removed a child of aFolderId that bookmarked it, it may
|
|
|
|
// still be bookmarked elsewhere; IsRealBookmark will know.
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavHistory* history = nsNavHistory::GetHistoryService();
|
2009-12-01 05:00:45 -08:00
|
|
|
NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
rv = history->UpdateFrecency(placeId, IsRealBookmark(placeId));
|
2008-11-05 14:02:12 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-08-09 08:59:43 -07:00
|
|
|
|
|
|
|
rv = UpdateKeywordsHashForRemovedBookmark(child.itemId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-11-05 14:02:12 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = transaction.Commit();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// 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 03:38:04 -08:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemRemoved(child.itemId, child.parentId, child.index,
|
|
|
|
child.itemType));
|
2008-11-05 14:02:12 -08: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.
|
|
|
|
|
|
|
|
if (child.grandParentId == mTagRoot) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
rv = NS_NewURI(getter_AddRefs(uri), child.url);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsTArray<PRInt64> bookmarks;
|
2009-10-28 16:52:41 -07:00
|
|
|
rv = GetBookmarkIdsForURITArray(uri, bookmarks);
|
2008-11-05 14:02:12 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (bookmarks.Length()) {
|
|
|
|
for (PRUint32 i = 0; i < bookmarks.Length(); i++) {
|
2010-01-16 03:38:04 -08:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemChanged(bookmarks[i],
|
|
|
|
NS_LITERAL_CSTRING("tags"), PR_FALSE,
|
|
|
|
EmptyCString(), 0, TYPE_BOOKMARK));
|
2008-11-05 14:02:12 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2007-05-22 15:03:53 -07:00
|
|
|
nsNavBookmarks::MoveItem(PRInt64 aItemId, PRInt64 aNewParent, PRInt32 aIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-02-11 02:53:35 -08:00
|
|
|
NS_ENSURE_TRUE(aItemId != mRoot, NS_ERROR_INVALID_ARG);
|
2010-01-16 03:37:57 -08: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-23 22:50:47 -07:00
|
|
|
// Disallow making an item its own parent.
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_TRUE(aItemId != aNewParent, NS_ERROR_INVALID_ARG);
|
2007-05-08 18:19:12 -07:00
|
|
|
|
2008-10-27 15:52:21 -07:00
|
|
|
mozStorageTransaction transaction(mDBConn, PR_FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-05-08 18:19:12 -07:00
|
|
|
// get item properties
|
|
|
|
nsresult rv;
|
|
|
|
PRInt64 oldParent;
|
2008-11-05 14:02:12 -08:00
|
|
|
PRInt32 oldIndex;
|
2010-01-16 03:37:57 -08:00
|
|
|
PRInt32 itemType;
|
2007-05-22 15:03:53 -07:00
|
|
|
nsCAutoString folderType;
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-01-16 03:38:02 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(getInfoStmt, mDBGetItemProperties);
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = getInfoStmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
PRBool hasResult;
|
|
|
|
rv = getInfoStmt->ExecuteStep(&hasResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 03:38:00 -08:00
|
|
|
if (!hasResult) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_INVALID_ARG; // folder is not in the hierarchy
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = getInfoStmt->GetInt64(kGetItemPropertiesIndex_Parent, &oldParent);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = getInfoStmt->GetInt32(kGetItemPropertiesIndex_Position, &oldIndex);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = getInfoStmt->GetInt32(kGetItemPropertiesIndex_Type, &itemType);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-05-22 15:03:53 -07:00
|
|
|
if (itemType == TYPE_FOLDER) {
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = getInfoStmt->GetUTF8String(kGetItemPropertiesIndex_ServiceContractId,
|
|
|
|
folderType);
|
2007-05-22 15:03:53 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-05-08 18:19:12 -07:00
|
|
|
// if parent and index are the same, nothing to do
|
|
|
|
if (oldParent == aNewParent && oldIndex == aIndex)
|
|
|
|
return NS_OK;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Make sure aNewParent is not aFolder or a subfolder of aFolder
|
2007-05-22 15:03:53 -07:00
|
|
|
if (itemType == TYPE_FOLDER) {
|
2010-01-16 03:37:57 -08:00
|
|
|
PRInt64 ancestorId = aNewParent;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
while (ancestorId) {
|
|
|
|
if (ancestorId == aItemId) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:38:02 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(getInfoStmt, mDBGetItemProperties);
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = getInfoStmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"),
|
|
|
|
ancestorId);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
PRBool hasResult;
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = getInfoStmt->ExecuteStep(&hasResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 03:37:57 -08:00
|
|
|
if (hasResult) {
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = getInfoStmt->GetInt64(kGetItemPropertiesIndex_Parent, &ancestorId);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-08 18:19:12 -07:00
|
|
|
// calculate new index
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt32 newIndex;
|
2009-08-21 02:54:12 -07:00
|
|
|
PRInt32 folderCount;
|
|
|
|
rv = FolderCount(aNewParent, &folderCount);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (aIndex == nsINavBookmarksService::DEFAULT_INDEX ||
|
|
|
|
aIndex >= folderCount) {
|
|
|
|
newIndex = folderCount;
|
2007-03-22 10:30:00 -07: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-08 18:19:12 -07:00
|
|
|
if (oldParent == aNewParent) {
|
2007-03-22 10:30:00 -07:00
|
|
|
--newIndex;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
newIndex = aIndex;
|
|
|
|
|
2007-05-08 18:19:12 -07:00
|
|
|
if (oldParent == aNewParent && newIndex > oldIndex) {
|
2007-03-22 10:30:00 -07: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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-08 18:19:12 -07: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) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Nothing to do!
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-05-08 18:19:12 -07:00
|
|
|
// adjust indices to account for the move
|
2007-05-30 16:25:19 -07: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-08 18:19:12 -07:00
|
|
|
if (oldParent == aNewParent) {
|
2007-03-22 10:30:00 -07: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.
|
|
|
|
if (oldIndex > newIndex) {
|
2007-05-08 18:19:12 -07:00
|
|
|
rv = AdjustIndices(oldParent, newIndex, oldIndex - 1, 1);
|
2010-01-16 03:37:57 -08:00
|
|
|
}
|
|
|
|
else {
|
2007-05-08 18:19:12 -07:00
|
|
|
rv = AdjustIndices(oldParent, oldIndex + 1, newIndex, -1);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
else {
|
2007-03-22 10:30:00 -07:00
|
|
|
// We're moving between containers, so this happens in two steps.
|
2007-05-08 18:19:12 -07:00
|
|
|
// First, fill the hole from the removal from the old parent.
|
|
|
|
rv = AdjustIndices(oldParent, oldIndex + 1, PR_INT32_MAX, -1);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// Now, make room in the new parent for the insertion.
|
2008-04-07 23:32:35 -07:00
|
|
|
rv = AdjustIndices(aNewParent, newIndex, PR_INT32_MAX, 1);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
{
|
|
|
|
// Update parent and position.
|
2010-01-16 03:38:02 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBMoveItem);
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("parent"), aNewParent);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = stmt->BindInt32ByName(NS_LITERAL_CSTRING("item_index"), newIndex);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = stmt->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 06:48:42 -08:00
|
|
|
}
|
2007-05-30 16:25:19 -07:00
|
|
|
|
2007-07-11 15:38:13 -07:00
|
|
|
PRTime now = PR_Now();
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = SetItemDateInternal(GetStatement(mDBSetItemLastModified),
|
|
|
|
oldParent, now);
|
2007-07-11 15:38:13 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = SetItemDateInternal(GetStatement(mDBSetItemLastModified),
|
|
|
|
aNewParent, now);
|
2007-07-11 15:38:13 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = transaction.Commit();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 03:38:04 -08:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemMoved(aItemId, oldParent, oldIndex, aNewParent,
|
|
|
|
newIndex, itemType));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-08-02 13:19:44 -07:00
|
|
|
// notify dynamic container provider if there is one
|
2007-05-22 15:03:53 -07:00
|
|
|
if (!folderType.IsEmpty()) {
|
2007-08-02 13:19:44 -07:00
|
|
|
nsCOMPtr<nsIDynamicContainer> container =
|
2007-05-22 15:03:53 -07:00
|
|
|
do_GetService(folderType.get(), &rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2007-05-22 15:03:53 -07:00
|
|
|
rv = container->OnContainerMoved(aItemId, aNewParent, newIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2008-03-17 16:25:36 -07:00
|
|
|
nsresult
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::SetItemDateInternal(mozIStorageStatement* aStatement,
|
|
|
|
PRInt64 aItemId,
|
|
|
|
PRTime aValue)
|
2007-05-18 17:40:55 -07:00
|
|
|
{
|
2010-01-16 03:38:00 -08:00
|
|
|
NS_ENSURE_STATE(aStatement);
|
|
|
|
mozStorageStatementScoper scoper(aStatement);
|
2010-01-16 03:38:02 -08:00
|
|
|
|
2010-04-27 04:25:05 -07:00
|
|
|
nsresult rv = aStatement->BindInt64ByName(NS_LITERAL_CSTRING("date"), aValue);
|
2007-05-18 17:40:55 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = aStatement->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2007-05-18 17:40:55 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-03-17 16:25:36 -07:00
|
|
|
rv = aStatement->Execute();
|
2007-05-18 17:40:55 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// note, we are not notifying the observers
|
|
|
|
// that the item has changed.
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2008-03-17 16:25:36 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavBookmarks::SetItemDateAdded(PRInt64 aItemId, PRTime aDateAdded)
|
|
|
|
{
|
2009-10-01 09:53:26 -07: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 00:34:35 -07:00
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = SetItemDateInternal(GetStatement(mDBSetItemDateAdded),
|
|
|
|
aItemId, aDateAdded);
|
2008-03-17 16:25:36 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-10-01 09:53:26 -07:00
|
|
|
// Note: mDBSetItemDateAdded also sets lastModified to aDateAdded.
|
2010-01-16 03:38:04 -08:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemChanged(aItemId, NS_LITERAL_CSTRING("dateAdded"),
|
|
|
|
PR_FALSE,
|
|
|
|
nsPrintfCString(16, "%lld", aDateAdded),
|
|
|
|
aDateAdded, itemType));
|
2008-03-17 16:25:36 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-05-18 17:40:55 -07:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::GetItemDateAdded(PRInt64 aItemId, PRTime* _dateAdded)
|
2007-05-18 17:40:55 -07:00
|
|
|
{
|
2009-06-12 00:34:35 -07:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_ARG_POINTER(_dateAdded);
|
2007-05-18 17:40:55 -07:00
|
|
|
|
2010-01-16 03:38:02 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemProperties);
|
2010-04-27 04:25:05 -07:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2007-05-18 17:40:55 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
PRBool hasResult;
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
2007-05-18 17:40:55 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_TRUE(hasResult, NS_ERROR_INVALID_ARG); // Invalid itemId.
|
2007-05-18 17:40:55 -07:00
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->GetInt64(kGetItemPropertiesIndex_DateAdded, _dateAdded);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-05-18 17:40:55 -07:00
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
return NS_OK;
|
2007-05-18 17:40:55 -07:00
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-05-18 17:40:55 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavBookmarks::SetItemLastModified(PRInt64 aItemId, PRTime aLastModified)
|
|
|
|
{
|
2009-10-01 09:53:26 -07: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 00:34:35 -07:00
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = SetItemDateInternal(GetStatement(mDBSetItemLastModified),
|
|
|
|
aItemId, aLastModified);
|
2007-05-18 17:40:55 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 03:38:04 -08:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemChanged(aItemId, NS_LITERAL_CSTRING("lastModified"),
|
|
|
|
PR_FALSE,
|
|
|
|
nsPrintfCString(16, "%lld", aLastModified),
|
|
|
|
aLastModified, itemType));
|
2007-05-18 17:40:55 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-05-18 17:40:55 -07:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::GetItemLastModified(PRInt64 aItemId, PRTime* aLastModified)
|
2007-05-18 17:40:55 -07:00
|
|
|
{
|
2009-06-12 00:34:35 -07:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
2007-05-18 17:40:55 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aLastModified);
|
|
|
|
|
2010-01-16 03:38:02 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemProperties);
|
2010-04-27 04:25:05 -07:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2007-05-18 17:40:55 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
PRBool hasResult;
|
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
2007-05-18 17:40:55 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
if (!hasResult)
|
2007-05-18 17:40:55 -07:00
|
|
|
return NS_ERROR_INVALID_ARG; // invalid item id
|
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->GetInt64(kGetItemPropertiesIndex_LastModified, aLastModified);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
2007-05-18 17:40:55 -07:00
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2008-10-27 15:52:21 -07: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 03:37:57 -08:00
|
|
|
|
2007-07-25 20:53:59 -07:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::GetItemGUID(PRInt64 aItemId, nsAString& aGUID)
|
2007-07-25 20:53:59 -07:00
|
|
|
{
|
2009-06-12 00:34:35 -07:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
|
|
|
|
2007-07-25 20:53:59 -07: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-11 20:30:42 -08:00
|
|
|
aGUID.SetCapacity(NSID_LENGTH - 1 + tmp.Length());
|
2008-10-27 15:52:21 -07:00
|
|
|
nsString GUIDBase;
|
|
|
|
rv = GetGUIDBase(GUIDBase);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
aGUID.Assign(GUIDBase);
|
2008-01-11 20:30:42 -08:00
|
|
|
aGUID.Append(tmp);
|
2007-07-25 20:53:59 -07:00
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
rv = SetItemGUID(aItemId, aGUID);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
2007-07-25 20:53:59 -07:00
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-07-25 20:53:59 -07:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::SetItemGUID(PRInt64 aItemId, const nsAString& aGUID)
|
2007-07-25 20:53:59 -07:00
|
|
|
{
|
2009-06-12 00:34:35 -07:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
|
|
|
|
2007-07-25 20:53:59 -07: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 03:37:57 -08:00
|
|
|
nsresult rv = annosvc->SetItemAnnotationString(aItemId, GUID_ANNO, aGUID, 0,
|
|
|
|
nsIAnnotationService::EXPIRE_NEVER);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
2007-07-25 20:53:59 -07:00
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-07-25 20:53:59 -07:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::GetItemIdForGUID(const nsAString& aGUID, PRInt64* aItemId)
|
2007-07-25 20:53:59 -07:00
|
|
|
{
|
2009-06-12 00:34:35 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aItemId);
|
|
|
|
|
2010-01-16 03:38:02 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemIdForGUID);
|
2010-04-27 04:25:05 -07:00
|
|
|
nsresult rv = stmt->BindStringByName(NS_LITERAL_CSTRING("guid"), aGUID);
|
2007-07-25 20:53:59 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRBool hasMore = PR_FALSE;
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->ExecuteStep(&hasMore);
|
2007-07-25 20:53:59 -07:00
|
|
|
if (NS_FAILED(rv) || ! hasMore) {
|
|
|
|
*aItemId = -1;
|
|
|
|
return NS_OK; // not found: return -1
|
|
|
|
}
|
|
|
|
|
|
|
|
// found, get the itemId
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->GetInt64(0, aItemId);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
2007-07-25 20:53:59 -07:00
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::SetItemTitle(PRInt64 aItemId, const nsACString& aTitle)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-10-01 09:53:26 -07: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 00:34:35 -07:00
|
|
|
|
2010-01-16 03:38:02 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(statement, mDBSetItemTitle);
|
2009-04-30 09:52:40 -07:00
|
|
|
// Support setting a null title, we support this in insertBookmark.
|
|
|
|
if (aTitle.IsVoid())
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = statement->BindNullByName(NS_LITERAL_CSTRING("item_title"));
|
2009-04-30 09:52:40 -07:00
|
|
|
else
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = statement->BindUTF8StringByName(NS_LITERAL_CSTRING("item_title"), aTitle);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-06-24 01:59:14 -07:00
|
|
|
PRTime lastModified = PR_Now();
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = statement->BindInt64ByName(NS_LITERAL_CSTRING("date"), lastModified);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = statement->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-04-13 18:10:20 -07:00
|
|
|
rv = statement->Execute();
|
2007-05-18 17:40:55 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 03:38:04 -08:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemChanged(aItemId, NS_LITERAL_CSTRING("title"), PR_FALSE,
|
|
|
|
aTitle, lastModified, itemType));
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::GetItemTitle(PRInt64 aItemId, nsACString& aTitle)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-06-12 00:34:35 -07:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
|
|
|
|
2010-01-16 03:38:02 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemProperties);
|
2010-04-27 04:25:05 -07:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
PRBool hasResult;
|
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
if (!hasResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_INVALID_ARG; // invalid bookmark id
|
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->GetUTF8String(kGetItemPropertiesIndex_Title, aTitle);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::GetBookmarkURI(PRInt64 aItemId, nsIURI** aURI)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-06-12 00:34:35 -07:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
|
|
|
|
2010-01-16 03:38:02 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemProperties);
|
2010-04-27 04:25:05 -07:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
PRBool hasResult;
|
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
if (!hasResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_INVALID_ARG; // invalid bookmark id
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
PRInt32 type;
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->GetInt32(kGetItemPropertiesIndex_Type, &type);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// Ensure this is a bookmark.
|
|
|
|
NS_ENSURE_TRUE(type == TYPE_BOOKMARK, NS_ERROR_INVALID_ARG);
|
2007-05-08 18:19:12 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCAutoString spec;
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->GetUTF8String(kGetItemPropertiesIndex_URI, spec);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = NS_NewURI(aURI, spec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::GetItemType(PRInt64 aItemId, PRUint16* _type)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-06-12 00:34:35 -07:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_ARG_POINTER(_type);
|
2009-06-12 00:34:35 -07:00
|
|
|
|
2010-01-16 03:38:02 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemProperties);
|
2010-04-27 04:25:05 -07:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
PRBool hasResult;
|
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
if (!hasResult) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_INVALID_ARG; // invalid bookmark id
|
2007-05-08 18:19:12 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
PRInt32 itemType;
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->GetInt32(kGetItemPropertiesIndex_Type, &itemType);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
*_type = itemType;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::GetFolderType(PRInt64 aFolder, nsACString& aType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-01-16 03:38:02 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemProperties);
|
2010-04-27 04:25:05 -07:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aFolder);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
PRBool hasResult;
|
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
if (!hasResult) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
return stmt->GetUTF8String(kGetItemPropertiesIndex_ServiceContractId, aType);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
2007-08-02 13:19:44 -07:00
|
|
|
nsNavBookmarks::ResultNodeForContainer(PRInt64 aID,
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavHistoryQueryOptions* aOptions,
|
|
|
|
nsNavHistoryResultNode** aNode)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-01-16 03:38:02 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemProperties);
|
2010-04-27 04:25:05 -07:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aID);
|
2010-01-16 03:38:00 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
PRBool hasResult;
|
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 03:38:00 -08:00
|
|
|
NS_ENSURE_TRUE(hasResult, NS_ERROR_INVALID_ARG);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCAutoString title;
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->GetUTF8String(kGetItemPropertiesIndex_Title, title);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
PRInt32 itemType;
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->GetInt32(kGetItemPropertiesIndex_Type, &itemType);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-08-02 13:19:44 -07:00
|
|
|
if (itemType == TYPE_DYNAMIC_CONTAINER) {
|
2009-10-05 03:12:38 -07:00
|
|
|
// contract id
|
|
|
|
nsCAutoString contractId;
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->GetUTF8String(kGetItemPropertiesIndex_ServiceContractId,
|
|
|
|
contractId);
|
2009-10-05 03:12:38 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 03:38:00 -08:00
|
|
|
*aNode = new nsNavHistoryContainerResultNode(EmptyCString(), title,
|
|
|
|
EmptyCString(),
|
2007-08-02 13:19:44 -07:00
|
|
|
nsINavHistoryResultNode::RESULT_TYPE_DYNAMIC_CONTAINER,
|
2010-01-16 03:38:00 -08:00
|
|
|
PR_TRUE, contractId, aOptions);
|
2007-08-02 13:19:44 -07:00
|
|
|
(*aNode)->mItemId = aID;
|
2010-01-16 03:37:57 -08:00
|
|
|
}
|
|
|
|
else { // TYPE_FOLDER
|
2009-10-05 03:12:38 -07:00
|
|
|
*aNode = new nsNavHistoryFolderResultNode(title, aOptions, aID, EmptyCString());
|
2007-08-02 13:19:44 -07:00
|
|
|
}
|
2007-05-20 04:39:02 -07:00
|
|
|
if (!*aNode)
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2007-05-20 04:39:02 -07:00
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->GetInt64(kGetItemPropertiesIndex_DateAdded,
|
|
|
|
&(*aNode)->mDateAdded);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->GetInt64(kGetItemPropertiesIndex_LastModified,
|
|
|
|
&(*aNode)->mLastModified);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-05-20 04:39:02 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ADDREF(*aNode);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
2010-04-09 11:30:29 -07:00
|
|
|
nsNavBookmarks::QueryFolderChildren(
|
|
|
|
PRInt64 aFolderId,
|
|
|
|
nsNavHistoryQueryOptions* aOptions,
|
|
|
|
nsCOMArray<nsNavHistoryResultNode>* aChildren)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-04-09 11:30:29 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aOptions);
|
|
|
|
NS_ENSURE_ARG_POINTER(aChildren);
|
|
|
|
|
2010-01-16 03:38:02 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetChildren);
|
2010-04-27 04:25:05 -07:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("parent"), aFolderId);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-04-09 11:30:29 -07:00
|
|
|
nsCOMPtr<mozIStorageValueArray> row = do_QueryInterface(stmt, &rv);
|
2008-10-13 08:58:36 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt32 index = -1;
|
2010-01-16 03:38:00 -08:00
|
|
|
PRBool hasResult;
|
|
|
|
while (NS_SUCCEEDED(stmt->ExecuteStep(&hasResult)) && hasResult) {
|
2010-04-09 11:30:29 -07:00
|
|
|
rv = ProcessFolderNodeRow(row, aOptions, aChildren, index);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-04-09 11:30:29 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-04-09 11:30:29 -07: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 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-02-08 14:00:16 -08:00
|
|
|
|
2010-04-09 11:30:29 -07: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 14:00:16 -08:00
|
|
|
}
|
2010-04-09 11:30:29 -07:00
|
|
|
else {
|
|
|
|
readOnly = PR_FALSE;
|
2007-05-08 18:19:12 -07:00
|
|
|
GetFolderReadonly(id, &readOnly);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-04-09 11:30:29 -07: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);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-04-09 11:30:29 -07: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 14:03:29 -07:00
|
|
|
|
2010-04-09 11:30:29 -07:00
|
|
|
// Store the index of the node within this container. Note that this is not
|
|
|
|
// moz_bookmarks.position.
|
|
|
|
node->mBookmarkIndex = aCurrentIndex;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-04-09 11:30:29 -07:00
|
|
|
NS_ENSURE_TRUE(aChildren->AppendObject(node), NS_ERROR_OUT_OF_MEMORY);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-04-09 11:30:29 -07: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 04:25:05 -07:00
|
|
|
nsresult rv = mDBGetChildren->BindInt64ByName(NS_LITERAL_CSTRING("parent"),
|
|
|
|
aFolderId);
|
2010-04-09 11:30:29 -07: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);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2009-08-21 02:54:12 -07:00
|
|
|
nsresult
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::FolderCount(PRInt64 aFolderId, PRInt32* _folderCount)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-01-16 03:37:57 -08:00
|
|
|
*_folderCount = 0;
|
2010-01-16 03:38:02 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBFolderCount);
|
2010-04-27 04:25:05 -07:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("parent"), aFolderId);
|
2009-08-21 02:54:12 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
PRBool hasResult;
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_TRUE(hasResult, NS_ERROR_UNEXPECTED);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-21 02:54:12 -07:00
|
|
|
// Ensure that the folder we are looking for exists.
|
2010-01-16 03:37:57 -08:00
|
|
|
PRInt64 confirmFolderId;
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->GetInt64(1, &confirmFolderId);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(confirmFolderId == aFolderId, NS_ERROR_INVALID_ARG);
|
2009-08-21 02:54:12 -07:00
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->GetInt32(0, _folderCount);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-08-21 02:54:12 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::IsBookmarked(nsIURI* aURI, PRBool* aBookmarked)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-04-13 11:17:46 -07:00
|
|
|
NS_ENSURE_ARG(aURI);
|
2009-06-12 00:34:35 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aBookmarked);
|
2008-04-13 11:17:46 -07:00
|
|
|
|
2010-03-10 04:40:52 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBIsURIBookmarkedInDatabase);
|
2010-04-27 04:25:05 -07:00
|
|
|
nsresult rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("page_url"), aURI);
|
2010-03-10 04:40:52 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = stmt->ExecuteStep(aBookmarked);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavBookmarks::GetBookmarkedURIFor(nsIURI* aURI, nsIURI** _retval)
|
|
|
|
{
|
2009-06-12 00:34:35 -07:00
|
|
|
NS_ENSURE_ARG(aURI);
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
*_retval = nsnull;
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavHistory* history = nsNavHistory::GetHistoryService();
|
2009-12-01 05:00:45 -08:00
|
|
|
NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY);
|
2010-03-10 04:40:52 -08:00
|
|
|
PRInt64 placeId;
|
2010-08-26 03:19:34 -07:00
|
|
|
nsresult rv = history->GetUrlIdFor(aURI, &placeId, PR_FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-03-10 04:40:52 -08:00
|
|
|
if (!placeId) {
|
|
|
|
// This URI is unknown, just return null.
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-03-10 04:40:52 -08: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 04:25:03 -07:00
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("page_id"), placeId);
|
2010-03-10 04:40:52 -08: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);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2010-03-10 04:40:52 -08:00
|
|
|
|
|
|
|
// If there is no bookmarked origin, we will just return null.
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::ChangeBookmarkURI(PRInt64 aBookmarkId, nsIURI* aNewURI)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-06-12 00:34:35 -07:00
|
|
|
NS_ENSURE_ARG_MIN(aBookmarkId, 1);
|
2007-05-10 01:05:19 -07:00
|
|
|
NS_ENSURE_ARG(aNewURI);
|
|
|
|
|
2008-10-27 15:52:21 -07:00
|
|
|
mozStorageTransaction transaction(mDBConn, PR_FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavHistory* history = nsNavHistory::GetHistoryService();
|
2009-12-01 05:00:45 -08:00
|
|
|
NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt64 placeId;
|
2009-12-01 05:00:45 -08:00
|
|
|
nsresult rv = history->GetUrlIdFor(aNewURI, &placeId, PR_TRUE);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!placeId)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2009-01-13 02:48:27 -08: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 05:00:45 -08:00
|
|
|
rv = history->GetUrlIdFor(oldURI, &oldPlaceId, PR_FALSE);
|
2009-01-13 02:48:27 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 03:38:02 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(statement, mDBChangeBookmarkURI);
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = statement->BindInt64ByName(NS_LITERAL_CSTRING("page_id"), placeId);
|
2009-06-24 01:59:14 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
PRTime lastModified = PR_Now();
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = statement->BindInt64ByName(NS_LITERAL_CSTRING("date"), lastModified);
|
2009-06-24 01:59:14 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = statement->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aBookmarkId);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-06-24 01:59:14 -07:00
|
|
|
rv = statement->Execute();
|
2007-07-11 15:38:13 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = transaction.Commit();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-01-13 02:48:27 -08:00
|
|
|
// Upon changing the URI for a bookmark, update the frecency for the new place.
|
|
|
|
// UpdateFrecency needs to know whether placeId is bookmarked (as opposed
|
|
|
|
// to a livemark item). Bookmarking it is exactly what we did above.
|
2009-12-01 05:00:45 -08:00
|
|
|
rv = history->UpdateFrecency(placeId, PR_TRUE /* isBookmarked */);
|
2008-01-25 09:11:14 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-01-13 02:48:27 -08:00
|
|
|
// Upon changing the URI for a bookmark, update the frecency for the old place.
|
|
|
|
// UpdateFrecency again needs to know whether oldPlaceId is bookmarked. It may
|
|
|
|
// no longer be, so we need to figure out whether it still is. Our strategy
|
|
|
|
// is: find all bookmarks corresponding to oldPlaceId that are not livemark
|
|
|
|
// items, i.e., whose parents are not livemarks. If any such bookmarks exist,
|
|
|
|
// oldPlaceId is still bookmarked.
|
|
|
|
|
2009-12-01 05:00:45 -08:00
|
|
|
rv = history->UpdateFrecency(oldPlaceId, IsRealBookmark(oldPlaceId));
|
2008-01-25 09:11:14 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-05-10 01:05:19 -07:00
|
|
|
nsCAutoString spec;
|
|
|
|
rv = aNewURI->GetSpec(spec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Pass the new URI to OnItemChanged.
|
2010-01-16 03:38:04 -08:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemChanged(aBookmarkId, NS_LITERAL_CSTRING("uri"),
|
|
|
|
PR_FALSE, spec, lastModified, TYPE_BOOKMARK));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::GetFolderIdForItem(PRInt64 aItemId, PRInt64* aFolderId)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-06-12 00:34:35 -07:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aFolderId);
|
|
|
|
|
2010-01-16 03:38:02 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemProperties);
|
2010-04-27 04:25:05 -07:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
PRBool hasResult;
|
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
if (!hasResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_INVALID_ARG; // invalid item id
|
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->GetInt64(kGetItemPropertiesIndex_Parent, aFolderId);
|
2007-10-23 22:50:47 -07: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;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2009-10-28 16:52:41 -07:00
|
|
|
nsresult
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::GetBookmarkIdsForURITArray(nsIURI* aURI,
|
|
|
|
nsTArray<PRInt64>& aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-06-12 00:34:35 -07:00
|
|
|
NS_ENSURE_ARG(aURI);
|
|
|
|
|
2010-01-16 03:38:02 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBFindURIBookmarks);
|
2010-04-27 04:25:05 -07:00
|
|
|
nsresult rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("page_url"), aURI);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = stmt->BindInt32ByName(NS_LITERAL_CSTRING("item_type"), TYPE_BOOKMARK);
|
2009-08-03 01:48:08 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
PRBool more;
|
2010-01-16 03:38:00 -08:00
|
|
|
while (NS_SUCCEEDED((rv = stmt->ExecuteStep(&more))) && more) {
|
2010-01-16 03:37:57 -08:00
|
|
|
PRInt64 bookmarkId;
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->GetInt64(kFindBookmarksIndex_ID, &bookmarkId);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(aResult.AppendElement(bookmarkId), NS_ERROR_OUT_OF_MEMORY);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-01-16 06:48:42 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2008-02-08 14:00:16 -08:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::GetBookmarkIdsForURI(nsIURI* aURI, PRUint32* aCount,
|
|
|
|
PRInt64** aBookmarks)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-06-12 00:34:35 -07:00
|
|
|
NS_ENSURE_ARG(aURI);
|
|
|
|
NS_ENSURE_ARG_POINTER(aCount);
|
|
|
|
NS_ENSURE_ARG_POINTER(aBookmarks);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
*aCount = 0;
|
|
|
|
*aBookmarks = nsnull;
|
|
|
|
nsTArray<PRInt64> bookmarks;
|
|
|
|
|
|
|
|
// Get the information from the DB as a TArray
|
2009-10-28 16:52:41 -07:00
|
|
|
nsresult rv = GetBookmarkIdsForURITArray(aURI, bookmarks);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Copy the results into a new array for output
|
|
|
|
if (bookmarks.Length()) {
|
2010-01-16 03:37:57 -08:00
|
|
|
*aBookmarks =
|
|
|
|
static_cast<PRInt64*>(nsMemory::Alloc(sizeof(PRInt64) * bookmarks.Length()));
|
|
|
|
if (!*aBookmarks)
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
for (PRUint32 i = 0; i < bookmarks.Length(); i ++)
|
|
|
|
(*aBookmarks)[i] = bookmarks[i];
|
|
|
|
}
|
|
|
|
*aCount = bookmarks.Length();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::GetItemIndex(PRInt64 aItemId, PRInt32* _index)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-06-12 00:34:35 -07:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_ARG_POINTER(_index);
|
|
|
|
|
|
|
|
*_index = -1;
|
2009-06-12 00:34:35 -07:00
|
|
|
|
2010-01-16 03:38:07 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemProperties);
|
2010-04-27 04:25:05 -07:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2010-01-16 03:38:00 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 03:37:57 -08:00
|
|
|
PRBool hasResult;
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 03:37:57 -08:00
|
|
|
if (!hasResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2010-01-16 03:38:07 -08:00
|
|
|
rv = stmt->GetInt32(kGetItemPropertiesIndex_Position, _index);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-05-11 12:06:57 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavBookmarks::SetItemIndex(PRInt64 aItemId, PRInt32 aNewIndex)
|
|
|
|
{
|
2009-06-12 00:34:35 -07:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
2009-08-21 02:54:12 -07:00
|
|
|
NS_ENSURE_ARG_MIN(aNewIndex, 0);
|
2009-06-12 00:34:35 -07:00
|
|
|
|
2007-05-11 12:06:57 -07:00
|
|
|
nsresult rv;
|
|
|
|
PRInt32 oldIndex = 0;
|
|
|
|
PRInt64 parent = 0;
|
2010-01-16 03:37:57 -08:00
|
|
|
PRInt32 itemType;
|
2007-05-11 12:06:57 -07:00
|
|
|
|
|
|
|
{
|
2010-01-16 03:38:00 -08:00
|
|
|
mozIStorageStatement* getInfoStmt(mDBGetItemProperties);
|
|
|
|
NS_ENSURE_STATE(getInfoStmt);
|
|
|
|
mozStorageStatementScoper scoper(getInfoStmt);
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = getInfoStmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2007-05-11 12:06:57 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
PRBool hasResult;
|
|
|
|
rv = getInfoStmt->ExecuteStep(&hasResult);
|
2007-05-11 12:06:57 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 03:38:00 -08:00
|
|
|
if (!hasResult)
|
2007-05-11 12:06:57 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = getInfoStmt->GetInt32(kGetItemPropertiesIndex_Position, &oldIndex);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = getInfoStmt->GetInt32(kGetItemPropertiesIndex_Type, &itemType);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = getInfoStmt->GetInt64(kGetItemPropertiesIndex_Parent, &parent);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-05-11 12:06:57 -07:00
|
|
|
}
|
|
|
|
|
2009-08-21 02:54:12 -07: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 03:38:02 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBSetItemIndex);
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2007-05-11 12:06:57 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 04:25:05 -07:00
|
|
|
rv = stmt->BindInt32ByName(NS_LITERAL_CSTRING("item_index"), aNewIndex);
|
2007-05-11 12:06:57 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->Execute();
|
2007-05-11 12:06:57 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 03:38:04 -08:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemMoved(aItemId, parent, oldIndex, parent, aNewIndex,
|
|
|
|
itemType));
|
2007-05-11 12:06:57 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2010-08-09 08:59:43 -07: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::SetKeywordForBookmark(PRInt64 aBookmarkId,
|
2010-08-27 22:44:05 -07:00
|
|
|
const nsAString& aUserCasedKeyword)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-06-12 00:34:35 -07:00
|
|
|
NS_ENSURE_ARG_MIN(aBookmarkId, 1);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-09 08:59:43 -07:00
|
|
|
nsresult rv = EnsureKeywordsHash();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Shortcuts are always lowercased internally.
|
2010-08-27 22:44:05 -07:00
|
|
|
nsAutoString keyword(aUserCasedKeyword);
|
2010-08-09 08:59:43 -07: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 15:52:21 -07:00
|
|
|
mozStorageTransaction transaction(mDBConn, PR_FALSE);
|
2010-08-09 08:59:43 -07: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 15:52:21 -07:00
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2010-08-09 08:59:43 -07:00
|
|
|
"INSERT OR IGNORE INTO moz_keywords (keyword) VALUES (:keyword)"
|
|
|
|
), getter_AddRefs(newKeywordStmt));
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-08-09 08:59:43 -07:00
|
|
|
rv = newKeywordStmt->BindStringByName(NS_LITERAL_CSTRING("keyword"),
|
|
|
|
keyword);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-08-09 08:59:43 -07:00
|
|
|
rv = newKeywordStmt->Execute();
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-08-09 08:59:43 -07: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 04:25:05 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-06-24 01:59:14 -07:00
|
|
|
PRTime lastModified = PR_Now();
|
2010-08-09 08:59:43 -07:00
|
|
|
rv = updateBookmarkStmt->BindInt64ByName(NS_LITERAL_CSTRING("date"),
|
|
|
|
lastModified);
|
2009-06-24 01:59:14 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-08-09 08:59:43 -07:00
|
|
|
rv = updateBookmarkStmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"),
|
|
|
|
aBookmarkId);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-08-09 08:59:43 -07:00
|
|
|
rv = updateBookmarkStmt->Execute();
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-07-11 15:38:13 -07:00
|
|
|
|
2009-06-24 01:59:14 -07:00
|
|
|
rv = transaction.Commit();
|
2007-05-18 17:40:55 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-05-14 14:47:59 -07:00
|
|
|
|
2010-01-16 03:38:04 -08:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemChanged(aBookmarkId, NS_LITERAL_CSTRING("keyword"),
|
2010-08-09 08:59:43 -07:00
|
|
|
PR_FALSE, NS_ConvertUTF16toUTF8(keyword),
|
2010-01-16 03:38:04 -08:00
|
|
|
lastModified, TYPE_BOOKMARK));
|
2007-05-18 17:40:55 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavBookmarks::GetKeywordForURI(nsIURI* aURI, nsAString& aKeyword)
|
|
|
|
{
|
2009-06-12 00:34:35 -07:00
|
|
|
NS_ENSURE_ARG(aURI);
|
2007-03-22 10:30:00 -07:00
|
|
|
aKeyword.Truncate(0);
|
|
|
|
|
2010-01-16 03:38:02 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetKeywordForURI);
|
2010-04-27 04:25:05 -07:00
|
|
|
nsresult rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("page_url"), aURI);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRBool hasMore = PR_FALSE;
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->ExecuteStep(&hasMore);
|
2010-01-16 03:37:57 -08:00
|
|
|
if (NS_FAILED(rv) || !hasMore) {
|
2007-03-22 10:30:00 -07:00
|
|
|
aKeyword.SetIsVoid(PR_TRUE);
|
|
|
|
return NS_OK; // not found: return void keyword string
|
|
|
|
}
|
|
|
|
|
|
|
|
// found, get the keyword
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->GetString(0, aKeyword);
|
2010-01-16 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavBookmarks::GetKeywordForBookmark(PRInt64 aBookmarkId, nsAString& aKeyword)
|
|
|
|
{
|
2009-06-12 00:34:35 -07:00
|
|
|
NS_ENSURE_ARG_MIN(aBookmarkId, 1);
|
2007-03-22 10:30:00 -07:00
|
|
|
aKeyword.Truncate(0);
|
|
|
|
|
2010-08-09 08:59:43 -07:00
|
|
|
nsresult rv = EnsureKeywordsHash();
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-08-09 08:59:43 -07:00
|
|
|
nsAutoString keyword;
|
|
|
|
if (!mBookmarkToKeywordHash.Get(aBookmarkId, &keyword)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
aKeyword.SetIsVoid(PR_TRUE);
|
2010-08-09 08:59:43 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
aKeyword.Assign(keyword);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-01-16 03:38:00 -08:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2010-08-27 22:44:05 -07:00
|
|
|
nsNavBookmarks::GetURIForKeyword(const nsAString& aUserCasedKeyword,
|
|
|
|
nsIURI** aURI)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-06-12 00:34:35 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
2010-08-27 22:44:05 -07:00
|
|
|
NS_ENSURE_TRUE(!aUserCasedKeyword.IsEmpty(), NS_ERROR_INVALID_ARG);
|
2007-03-22 10:30:00 -07:00
|
|
|
*aURI = nsnull;
|
|
|
|
|
|
|
|
// Shortcuts are always lowercased internally.
|
2010-08-27 22:44:05 -07:00
|
|
|
nsAutoString keyword(aUserCasedKeyword);
|
2010-08-09 08:59:43 -07:00
|
|
|
ToLowerCase(keyword);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-09 08:59:43 -07:00
|
|
|
nsresult rv = EnsureKeywordsHash();
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-08-09 08:59:43 -07:00
|
|
|
keywordSearchData searchData;
|
2010-08-27 22:44:05 -07:00
|
|
|
searchData.keyword.Assign(keyword);
|
2010-08-09 08:59:43 -07:00
|
|
|
searchData.itemId = -1;
|
|
|
|
mBookmarkToKeywordHash.EnumerateRead(SearchBookmarkForKeyword, &searchData);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-09 08:59:43 -07:00
|
|
|
if (searchData.itemId == -1) {
|
|
|
|
// Not found.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = GetBookmarkURI(searchData.itemId, aURI);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-08-09 08:59:43 -07: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 03:37:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-08-09 08:59:43 -07: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 03:37:57 -08:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2008-02-21 20:09:08 -08:00
|
|
|
// See RunInBatchMode
|
2007-05-31 17:44:43 -07:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
nsNavBookmarks::BeginUpdateBatch()
|
|
|
|
{
|
|
|
|
if (mBatchLevel++ == 0) {
|
2010-04-16 05:31:21 -07:00
|
|
|
mBatchDBTransaction = new mozStorageTransaction(mDBConn, PR_FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-01-16 03:38:04 -08:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver, OnBeginUpdateBatch());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-05-31 17:44:43 -07:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
nsNavBookmarks::EndUpdateBatch()
|
|
|
|
{
|
|
|
|
if (--mBatchLevel == 0) {
|
2010-04-16 05:31:21 -07:00
|
|
|
if (mBatchDBTransaction) {
|
|
|
|
nsresult rv = mBatchDBTransaction->Commit();
|
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Batch failed to commit transaction");
|
|
|
|
delete mBatchDBTransaction;
|
|
|
|
mBatchDBTransaction = nsnull;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:38:04 -08:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver, OnEndUpdateBatch());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-05-31 17:44:43 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavBookmarks::RunInBatchMode(nsINavHistoryBatchCallback* aCallback,
|
|
|
|
nsISupports* aUserData) {
|
2009-06-12 00:34:35 -07:00
|
|
|
NS_ENSURE_ARG(aCallback);
|
2007-05-31 17:44:43 -07:00
|
|
|
|
|
|
|
BeginUpdateBatch();
|
|
|
|
nsresult rv = aCallback->RunBatched(aUserData);
|
|
|
|
EndUpdateBatch();
|
|
|
|
|
2008-02-21 20:09:08 -08:00
|
|
|
return rv;
|
2007-05-31 17:44:43 -07:00
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::AddObserver(nsINavBookmarkObserver* aObserver,
|
2007-03-22 10:30:00 -07:00
|
|
|
PRBool aOwnsWeak)
|
|
|
|
{
|
2009-06-12 00:34:35 -07:00
|
|
|
NS_ENSURE_ARG(aObserver);
|
2007-03-22 10:30:00 -07:00
|
|
|
return mObservers.AppendWeakElement(aObserver, aOwnsWeak);
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::RemoveObserver(nsINavBookmarkObserver* aObserver)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return mObservers.RemoveWeakElement(aObserver);
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsNavBookmarks::nsINavHistoryObserver
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavBookmarks::OnBeginUpdateBatch()
|
|
|
|
{
|
|
|
|
// These aren't passed through to bookmark observers currently.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavBookmarks::OnEndUpdateBatch()
|
|
|
|
{
|
|
|
|
// These aren't passed through to bookmark observers currently.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::OnVisit(nsIURI* aURI, PRInt64 aVisitID, PRTime aTime,
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt64 aSessionID, PRInt64 aReferringID,
|
2008-02-26 20:48:51 -08:00
|
|
|
PRUint32 aTransitionType, PRUint32* aAdded)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// If the page is bookmarked, we need to notify observers
|
|
|
|
PRBool bookmarked = PR_FALSE;
|
|
|
|
IsBookmarked(aURI, &bookmarked);
|
|
|
|
if (bookmarked) {
|
|
|
|
// query for all bookmarks for that URI, notify for each
|
|
|
|
nsTArray<PRInt64> bookmarks;
|
|
|
|
|
2009-10-28 16:52:41 -07:00
|
|
|
nsresult rv = GetBookmarkIdsForURITArray(aURI, bookmarks);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (bookmarks.Length()) {
|
|
|
|
for (PRUint32 i = 0; i < bookmarks.Length(); i++)
|
2010-01-16 03:38:04 -08:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemVisited(bookmarks[i], aVisitID, aTime));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2009-04-10 10:51:40 -07:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::OnBeforeDeleteURI(nsIURI* aURI)
|
2009-04-10 10:51:40 -07:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::OnDeleteURI(nsIURI* aURI)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// If the page is bookmarked, we need to notify observers
|
|
|
|
PRBool bookmarked = PR_FALSE;
|
|
|
|
IsBookmarked(aURI, &bookmarked);
|
|
|
|
if (bookmarked) {
|
|
|
|
// query for all bookmarks for that URI, notify for each
|
|
|
|
nsTArray<PRInt64> bookmarks;
|
|
|
|
|
2009-10-28 16:52:41 -07:00
|
|
|
nsresult rv = GetBookmarkIdsForURITArray(aURI, bookmarks);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (bookmarks.Length()) {
|
|
|
|
for (PRUint32 i = 0; i < bookmarks.Length(); i ++)
|
2010-01-16 03:38:04 -08:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemChanged(bookmarks[i],
|
|
|
|
NS_LITERAL_CSTRING("cleartime"),
|
|
|
|
PR_FALSE, EmptyCString(), 0,
|
|
|
|
TYPE_BOOKMARK));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavBookmarks::OnClearHistory()
|
|
|
|
{
|
|
|
|
// TODO(bryner): we should notify on visited-time change for all URIs
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2007-07-26 09:23:11 -07:00
|
|
|
nsNavBookmarks::OnTitleChanged(nsIURI* aURI, const nsAString& aPageTitle)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// NOOP. We don't consume page titles from moz_places anymore.
|
|
|
|
// Title-change notifications are sent from SetItemTitle.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2010-01-16 03:37:57 -08:00
|
|
|
nsNavBookmarks::OnPageChanged(nsIURI* aURI, PRUint32 aWhat,
|
|
|
|
const nsAString& aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-05-27 15:08:13 -07:00
|
|
|
nsresult rv;
|
|
|
|
if (aWhat == nsINavHistoryObserver::ATTRIBUTE_FAVICON) {
|
|
|
|
// 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 03:37:57 -08:00
|
|
|
nsNavHistory* history = nsNavHistory::GetHistoryService();
|
2009-12-01 05:00:45 -08:00
|
|
|
NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY);
|
2007-05-27 15:08:13 -07:00
|
|
|
|
|
|
|
nsCOMArray<nsNavHistoryQuery> queries;
|
|
|
|
nsCOMPtr<nsNavHistoryQueryOptions> options;
|
|
|
|
rv = history->QueryStringToQueryArray(spec, &queries, getter_AddRefs(options));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
NS_ENSURE_STATE(queries.Count() == 1);
|
|
|
|
NS_ENSURE_STATE(queries[0]->Folders().Length() == 1);
|
|
|
|
|
2010-01-16 03:38:04 -08:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemChanged(queries[0]->Folders()[0],
|
|
|
|
NS_LITERAL_CSTRING("favicon"),
|
|
|
|
PR_FALSE,
|
|
|
|
NS_ConvertUTF16toUTF8(aValue),
|
|
|
|
0, TYPE_BOOKMARK));
|
2007-05-27 15:08:13 -07:00
|
|
|
}
|
|
|
|
else {
|
2007-03-22 10:30:00 -07:00
|
|
|
// query for all bookmarks for that URI, notify for each
|
|
|
|
nsTArray<PRInt64> bookmarks;
|
2009-10-28 16:52:41 -07:00
|
|
|
rv = GetBookmarkIdsForURITArray(aURI, bookmarks);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (bookmarks.Length()) {
|
|
|
|
for (PRUint32 i = 0; i < bookmarks.Length(); i ++)
|
2010-01-16 03:38:04 -08:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemChanged(bookmarks[i],
|
|
|
|
NS_LITERAL_CSTRING("favicon"),
|
|
|
|
PR_FALSE,
|
|
|
|
NS_ConvertUTF16toUTF8(aValue),
|
|
|
|
0, TYPE_BOOKMARK));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2010-01-15 08:40:17 -08:00
|
|
|
nsNavBookmarks::OnDeleteVisits(nsIURI* aURI, PRTime aVisitTime)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// pages that are bookmarks shouldn't expire, so we don't need to handle it
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-05-10 01:05:19 -07:00
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-05-10 01:05:19 -07:00
|
|
|
// nsIAnnotationObserver
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavBookmarks::OnPageAnnotationSet(nsIURI* aPage, const nsACString& aName)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-05-10 01:05:19 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavBookmarks::OnItemAnnotationSet(PRInt64 aItemId, const nsACString& aName)
|
|
|
|
{
|
2009-10-01 09:53:26 -07:00
|
|
|
// GetItemType also ensures that aItemId points to a valid item.
|
|
|
|
PRUint16 itemType;
|
|
|
|
nsresult rv = GetItemType(aItemId, &itemType);
|
2009-09-26 01:23:17 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-10-01 09:53:26 -07:00
|
|
|
PRTime lastModified = PR_Now();
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = SetItemDateInternal(GetStatement(mDBSetItemLastModified),
|
|
|
|
aItemId, lastModified);
|
2009-10-01 09:53:26 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 03:38:04 -08:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemChanged(aItemId, aName, PR_TRUE, EmptyCString(),
|
|
|
|
lastModified, itemType));
|
2007-05-18 17:40:55 -07:00
|
|
|
|
2007-05-10 01:05:19 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavBookmarks::OnPageAnnotationRemoved(nsIURI* aPage, const nsACString& aName)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-05-10 01:05:19 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavBookmarks::OnItemAnnotationRemoved(PRInt64 aItemId, const nsACString& aName)
|
2009-06-24 01:59:14 -07:00
|
|
|
{
|
2009-10-01 09:53:26 -07:00
|
|
|
// GetItemType also ensures that aItemId points to a valid item.
|
|
|
|
PRUint16 itemType;
|
|
|
|
nsresult rv = GetItemType(aItemId, &itemType);
|
2007-05-18 17:40:55 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-10-01 09:53:26 -07:00
|
|
|
PRTime lastModified = PR_Now();
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = SetItemDateInternal(GetStatement(mDBSetItemLastModified),
|
|
|
|
aItemId, lastModified);
|
2009-10-01 09:53:26 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-16 03:38:04 -08:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavBookmarkObserver,
|
|
|
|
OnItemChanged(aItemId, aName, PR_TRUE, EmptyCString(),
|
|
|
|
lastModified, itemType));
|
2007-05-18 17:40:55 -07:00
|
|
|
|
2007-05-10 01:05:19 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-06-25 18:08:54 -07:00
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
|
2007-06-25 18:08:54 -07:00
|
|
|
PRBool
|
|
|
|
nsNavBookmarks::ItemExists(PRInt64 aItemId) {
|
2010-01-16 03:38:02 -08:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemProperties);
|
2010-04-27 04:25:05 -07:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2007-06-25 18:08:54 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
PRBool hasResult;
|
2010-01-16 03:38:00 -08:00
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
2007-06-25 18:08:54 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
|
|
|
|
2010-01-16 03:37:57 -08:00
|
|
|
return hasResult;
|
2007-06-25 18:08:54 -07:00
|
|
|
}
|