2009-12-18 10:30:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
2006-07-18 16:48:10 +00:00
|
|
|
* 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 Mozilla Annotation Service
|
|
|
|
*
|
|
|
|
* 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):
|
|
|
|
* Brett Wilson <brettw@gmail.com> (original author)
|
2007-05-10 08:05:19 +00:00
|
|
|
* Asaf Romano <mano@mozilla.com>
|
2008-10-19 21:14:59 +00:00
|
|
|
* Ehsan Akhgari <ehsan.akhgari@gmail.com>
|
2009-12-18 10:30:37 +00:00
|
|
|
* Marco Bonardo <mak77@bonardo.net>
|
2006-07-18 16:48:10 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsAnnotationService.h"
|
|
|
|
#include "nsNavHistory.h"
|
2009-12-18 10:30:37 +00:00
|
|
|
|
2006-07-18 16:48:56 +00:00
|
|
|
#include "nsNetUtil.h"
|
2006-07-18 16:48:33 +00:00
|
|
|
#include "nsIVariant.h"
|
2006-07-18 16:48:10 +00:00
|
|
|
#include "nsString.h"
|
2006-07-18 16:51:28 +00:00
|
|
|
#include "nsVariant.h"
|
2009-12-18 10:30:37 +00:00
|
|
|
|
2008-08-04 17:14:17 +00:00
|
|
|
#include "nsPlacesTables.h"
|
2009-05-11 09:05:56 +00:00
|
|
|
#include "nsPlacesIndexes.h"
|
2009-12-01 13:00:45 +00:00
|
|
|
#include "nsPlacesMacros.h"
|
2010-01-16 11:38:02 +00:00
|
|
|
#include "Helpers.h"
|
2006-07-18 16:48:10 +00:00
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
#include "mozilla/storage.h"
|
|
|
|
|
|
|
|
#define ENSURE_ANNO_TYPE(_type, _statement) \
|
|
|
|
PR_BEGIN_MACRO \
|
|
|
|
PRInt32 type = _statement->AsInt32(kAnnoIndex_Type); \
|
|
|
|
NS_ENSURE_TRUE(type == nsIAnnotationService::_type, NS_ERROR_INVALID_ARG); \
|
|
|
|
PR_END_MACRO
|
|
|
|
|
|
|
|
#define NOTIFY_ANNOS_OBSERVERS(_notification) \
|
|
|
|
PR_BEGIN_MACRO \
|
|
|
|
for (PRInt32 i = 0; i < mObservers.Count(); i++) \
|
|
|
|
mObservers[i]->_notification; \
|
|
|
|
PR_END_MACRO
|
|
|
|
|
2006-07-18 16:48:33 +00:00
|
|
|
const PRInt32 nsAnnotationService::kAnnoIndex_ID = 0;
|
2007-05-10 08:05:19 +00:00
|
|
|
const PRInt32 nsAnnotationService::kAnnoIndex_PageOrItem = 1;
|
2009-12-18 10:30:37 +00:00
|
|
|
const PRInt32 nsAnnotationService::kAnnoIndex_NameID = 2;
|
2006-07-18 16:48:33 +00:00
|
|
|
const PRInt32 nsAnnotationService::kAnnoIndex_MimeType = 3;
|
|
|
|
const PRInt32 nsAnnotationService::kAnnoIndex_Content = 4;
|
|
|
|
const PRInt32 nsAnnotationService::kAnnoIndex_Flags = 5;
|
|
|
|
const PRInt32 nsAnnotationService::kAnnoIndex_Expiration = 6;
|
2007-04-22 21:48:52 +00:00
|
|
|
const PRInt32 nsAnnotationService::kAnnoIndex_Type = 7;
|
2007-07-26 16:23:11 +00:00
|
|
|
const PRInt32 nsAnnotationService::kAnnoIndex_DateAdded = 8;
|
|
|
|
const PRInt32 nsAnnotationService::kAnnoIndex_LastModified = 9;
|
2006-07-18 16:48:10 +00:00
|
|
|
|
2010-04-27 11:24:58 +00:00
|
|
|
using namespace mozilla::places;
|
|
|
|
|
2009-12-01 13:00:45 +00:00
|
|
|
PLACES_FACTORY_SINGLETON_IMPLEMENTATION(nsAnnotationService, gAnnotationService)
|
2006-07-18 16:52:14 +00:00
|
|
|
|
2006-07-18 16:48:10 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(nsAnnotationService,
|
2006-07-18 16:49:42 +00:00
|
|
|
nsIAnnotationService)
|
2006-07-18 16:48:10 +00:00
|
|
|
|
|
|
|
|
2009-12-18 10:30:40 +00:00
|
|
|
nsAnnotationService::nsAnnotationService() : mShuttingDown(false)
|
2006-07-18 16:48:10 +00:00
|
|
|
{
|
2006-07-18 16:52:14 +00:00
|
|
|
NS_ASSERTION(!gAnnotationService,
|
2009-12-01 13:00:45 +00:00
|
|
|
"Attempting to create two instances of the service!");
|
2006-07-18 16:52:14 +00:00
|
|
|
gAnnotationService = this;
|
2006-07-18 16:48:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsAnnotationService::~nsAnnotationService()
|
|
|
|
{
|
2006-07-18 16:52:37 +00:00
|
|
|
NS_ASSERTION(gAnnotationService == this,
|
2009-12-01 13:00:45 +00:00
|
|
|
"Deleting a non-singleton instance of the service");
|
2006-07-18 16:52:14 +00:00
|
|
|
if (gAnnotationService == this)
|
|
|
|
gAnnotationService = nsnull;
|
2006-07-18 16:48:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsAnnotationService::Init()
|
|
|
|
{
|
2006-07-18 16:51:51 +00:00
|
|
|
// The history service will normally already be created and will call our
|
|
|
|
// static InitTables function. It will get autocreated here if it hasn't
|
|
|
|
// already been created.
|
2009-12-18 10:30:37 +00:00
|
|
|
nsNavHistory* history = nsNavHistory::GetHistoryService();
|
2009-12-01 13:00:45 +00:00
|
|
|
NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY);
|
2006-07-18 16:48:10 +00:00
|
|
|
mDBConn = history->GetStorageConnection();
|
|
|
|
|
2009-12-18 10:30:40 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-12-18 10:30:37 +00:00
|
|
|
|
2006-07-18 16:52:37 +00:00
|
|
|
|
2009-12-18 10:30:40 +00:00
|
|
|
mozIStorageStatement*
|
|
|
|
nsAnnotationService::GetStatement(const nsCOMPtr<mozIStorageStatement>& aStmt)
|
|
|
|
{
|
|
|
|
if (mShuttingDown)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
RETURN_IF_STMT(mDBGetAnnotationsForItem, NS_LITERAL_CSTRING(
|
|
|
|
"SELECT n.name "
|
|
|
|
"FROM moz_anno_attributes n "
|
|
|
|
"JOIN moz_items_annos a ON a.anno_attribute_id = n.id "
|
2010-04-27 11:24:58 +00:00
|
|
|
"WHERE a.item_id = :item_id"));
|
2009-12-18 10:30:40 +00:00
|
|
|
|
|
|
|
RETURN_IF_STMT(mDBGetAnnotationsForPage, NS_LITERAL_CSTRING(
|
|
|
|
"SELECT n.name "
|
|
|
|
"FROM moz_anno_attributes n "
|
|
|
|
"JOIN moz_annos a ON a.anno_attribute_id = n.id "
|
2010-08-09 15:59:59 +00:00
|
|
|
"JOIN moz_places h ON h.id = a.place_id "
|
|
|
|
"WHERE h.url = :page_url"));
|
2009-12-18 10:30:40 +00:00
|
|
|
|
|
|
|
RETURN_IF_STMT(mDBGetPageAnnotationValue, NS_LITERAL_CSTRING(
|
2010-04-27 11:24:58 +00:00
|
|
|
"SELECT a.id, a.place_id, :anno_name, a.mime_type, a.content, a.flags, "
|
2009-12-18 10:30:40 +00:00
|
|
|
"a.expiration, a.type "
|
|
|
|
"FROM moz_anno_attributes n "
|
|
|
|
"JOIN moz_annos a ON n.id = a.anno_attribute_id "
|
2010-08-09 15:59:59 +00:00
|
|
|
"JOIN moz_places h ON h.id = a.place_id "
|
|
|
|
"WHERE h.url = :page_url "
|
|
|
|
"AND n.name = :anno_name"));
|
2009-12-18 10:30:40 +00:00
|
|
|
|
|
|
|
RETURN_IF_STMT(mDBGetItemAnnotationValue, NS_LITERAL_CSTRING(
|
2010-04-27 11:24:58 +00:00
|
|
|
"SELECT a.id, a.item_id, :anno_name, a.mime_type, a.content, a.flags, "
|
2009-12-18 10:30:40 +00:00
|
|
|
"a.expiration, a.type "
|
|
|
|
"FROM moz_anno_attributes n "
|
|
|
|
"JOIN moz_items_annos a ON a.anno_attribute_id = n.id "
|
2010-04-27 11:24:58 +00:00
|
|
|
"WHERE a.item_id = :item_id "
|
|
|
|
"AND n.name = :anno_name"));
|
2009-12-18 10:30:40 +00:00
|
|
|
|
|
|
|
RETURN_IF_STMT(mDBAddAnnotationName, NS_LITERAL_CSTRING(
|
2010-04-27 11:24:58 +00:00
|
|
|
"INSERT OR IGNORE INTO moz_anno_attributes (name) VALUES (:anno_name)"));
|
2009-12-18 10:30:40 +00:00
|
|
|
|
|
|
|
RETURN_IF_STMT(mDBAddPageAnnotation, NS_LITERAL_CSTRING(
|
|
|
|
"INSERT OR REPLACE INTO moz_annos "
|
|
|
|
"(id, place_id, anno_attribute_id, mime_type, content, flags, "
|
|
|
|
"expiration, type, dateAdded, lastModified) "
|
2010-04-27 11:24:58 +00:00
|
|
|
"VALUES (:id, :fk, :name_id, :mime_type, :content, :flags, "
|
|
|
|
":expiration, :type, :date_added, :last_modified)"));
|
2009-12-18 10:30:40 +00:00
|
|
|
|
|
|
|
RETURN_IF_STMT(mDBAddItemAnnotation, NS_LITERAL_CSTRING(
|
|
|
|
"INSERT OR REPLACE INTO moz_items_annos "
|
|
|
|
"(id, item_id, anno_attribute_id, mime_type, content, flags, "
|
|
|
|
"expiration, type, dateAdded, lastModified) "
|
2010-04-27 11:24:58 +00:00
|
|
|
"VALUES (:id, :fk, :name_id, :mime_type, :content, :flags, "
|
|
|
|
":expiration, :type, :date_added, :last_modified)"));
|
2009-12-18 10:30:40 +00:00
|
|
|
|
|
|
|
RETURN_IF_STMT(mDBRemovePageAnnotation, NS_LITERAL_CSTRING(
|
|
|
|
"DELETE FROM moz_annos "
|
2010-08-09 15:59:59 +00:00
|
|
|
"WHERE place_id = (SELECT id FROM moz_places WHERE url = :page_url) "
|
|
|
|
"AND anno_attribute_id = "
|
|
|
|
"(SELECT id FROM moz_anno_attributes WHERE name = :anno_name)"));
|
2006-07-18 16:48:10 +00:00
|
|
|
|
2009-12-18 10:30:40 +00:00
|
|
|
RETURN_IF_STMT(mDBRemoveItemAnnotation, NS_LITERAL_CSTRING(
|
|
|
|
"DELETE FROM moz_items_annos "
|
2010-04-27 11:24:58 +00:00
|
|
|
"WHERE item_id = :item_id "
|
2010-08-09 15:59:59 +00:00
|
|
|
"AND anno_attribute_id = "
|
|
|
|
"(SELECT id FROM moz_anno_attributes WHERE name = :anno_name)"));
|
2007-05-10 08:05:19 +00:00
|
|
|
|
2009-12-18 10:30:40 +00:00
|
|
|
RETURN_IF_STMT(mDBGetPagesWithAnnotation, NS_LITERAL_CSTRING(
|
2010-08-09 15:59:59 +00:00
|
|
|
"SELECT h.url "
|
2009-12-18 10:30:40 +00:00
|
|
|
"FROM moz_anno_attributes n "
|
|
|
|
"JOIN moz_annos a ON n.id = a.anno_attribute_id "
|
2010-08-09 15:59:59 +00:00
|
|
|
"JOIN moz_places h ON h.id = a.place_id "
|
|
|
|
"WHERE n.name = :anno_name"));
|
2009-12-18 10:30:40 +00:00
|
|
|
|
|
|
|
RETURN_IF_STMT(mDBGetItemsWithAnnotation, NS_LITERAL_CSTRING(
|
|
|
|
"SELECT a.item_id "
|
|
|
|
"FROM moz_anno_attributes n "
|
|
|
|
"JOIN moz_items_annos a ON n.id = a.anno_attribute_id "
|
2010-04-27 11:24:58 +00:00
|
|
|
"WHERE n.name = :anno_name"));
|
2009-12-18 10:30:40 +00:00
|
|
|
|
|
|
|
RETURN_IF_STMT(mDBCheckPageAnnotation, NS_LITERAL_CSTRING(
|
|
|
|
"SELECT h.id, "
|
2010-04-27 11:24:58 +00:00
|
|
|
"(SELECT id FROM moz_anno_attributes WHERE name = :anno_name) AS nameid, "
|
2009-12-18 10:30:40 +00:00
|
|
|
"a.id, a.dateAdded "
|
2010-08-09 15:59:59 +00:00
|
|
|
"FROM moz_places h "
|
2009-12-18 10:30:40 +00:00
|
|
|
"LEFT JOIN moz_annos a ON a.place_id = h.id "
|
2010-08-09 15:59:59 +00:00
|
|
|
"AND a.anno_attribute_id = nameid "
|
|
|
|
"WHERE h.url = :page_url"));
|
2009-12-18 10:30:40 +00:00
|
|
|
|
|
|
|
RETURN_IF_STMT(mDBCheckItemAnnotation, NS_LITERAL_CSTRING(
|
|
|
|
"SELECT b.id, "
|
2010-04-27 11:24:58 +00:00
|
|
|
"(SELECT id FROM moz_anno_attributes WHERE name = :anno_name) AS nameid, "
|
2009-12-18 10:30:40 +00:00
|
|
|
"a.id, a.dateAdded "
|
|
|
|
"FROM moz_bookmarks b "
|
|
|
|
"LEFT JOIN moz_items_annos a ON a.item_id = b.id "
|
|
|
|
"AND a.anno_attribute_id = nameid "
|
2010-04-27 11:24:58 +00:00
|
|
|
"WHERE b.id = :item_id"));
|
2009-12-18 10:30:37 +00:00
|
|
|
|
2009-12-18 10:30:40 +00:00
|
|
|
return nsnull;
|
2006-07-18 16:48:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-18 16:51:51 +00:00
|
|
|
// nsAnnotationService::InitTables
|
|
|
|
//
|
|
|
|
// All commands that initialize the schema of the DB go in here. This is
|
|
|
|
// called from history init before the dummy DB connection is started that
|
|
|
|
// will prevent us from modifying the schema.
|
|
|
|
//
|
|
|
|
// The history service will always be created before us (we get it at the
|
|
|
|
// beginning of the init function which covers us if it's not).
|
|
|
|
|
|
|
|
nsresult // static
|
|
|
|
nsAnnotationService::InitTables(mozIStorageConnection* aDBConn)
|
|
|
|
{
|
|
|
|
PRBool exists;
|
2009-12-18 10:30:37 +00:00
|
|
|
nsresult rv = aDBConn->TableExists(NS_LITERAL_CSTRING("moz_annos"), &exists);
|
2006-07-18 16:51:51 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-12-18 10:30:37 +00:00
|
|
|
if (!exists) {
|
2008-08-04 17:14:17 +00:00
|
|
|
rv = aDBConn->ExecuteSimpleSQL(CREATE_MOZ_ANNOS);
|
2006-07-18 16:51:51 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-02-14 17:33:30 +00:00
|
|
|
|
2009-05-11 09:05:56 +00:00
|
|
|
rv = aDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_ANNOS_PLACEATTRIBUTE);
|
2006-07-18 16:52:37 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2006-12-08 19:57:12 +00:00
|
|
|
rv = aDBConn->TableExists(NS_LITERAL_CSTRING("moz_anno_attributes"), &exists);
|
2006-07-18 16:52:37 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-12-18 10:30:37 +00:00
|
|
|
if (!exists) {
|
2008-08-04 17:14:17 +00:00
|
|
|
rv = aDBConn->ExecuteSimpleSQL(CREATE_MOZ_ANNO_ATTRIBUTES);
|
2006-07-18 16:52:37 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
rv = aDBConn->TableExists(NS_LITERAL_CSTRING("moz_items_annos"), &exists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-12-18 10:30:37 +00:00
|
|
|
if (!exists) {
|
2008-08-04 17:14:17 +00:00
|
|
|
rv = aDBConn->ExecuteSimpleSQL(CREATE_MOZ_ITEMS_ANNOS);
|
2007-05-10 08:05:19 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-05-11 09:05:56 +00:00
|
|
|
rv = aDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_ITEMSANNOS_PLACEATTRIBUTE);
|
2007-05-10 08:05:19 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2006-07-18 16:51:51 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
nsresult
|
2009-12-18 10:30:37 +00:00
|
|
|
nsAnnotationService::SetAnnotationStringInternal(nsIURI* aURI,
|
|
|
|
PRInt64 aItemId,
|
2007-05-10 08:05:19 +00:00
|
|
|
const nsACString& aName,
|
|
|
|
const nsAString& aValue,
|
|
|
|
PRInt32 aFlags,
|
|
|
|
PRUint16 aExpiration)
|
2006-07-18 16:48:10 +00:00
|
|
|
{
|
|
|
|
mozStorageTransaction transaction(mDBConn, PR_FALSE);
|
2009-12-18 10:30:37 +00:00
|
|
|
mozIStorageStatement* statement;
|
|
|
|
nsresult rv = StartSetAnnotation(aURI, aItemId, aName, aFlags, aExpiration,
|
2007-05-10 08:05:19 +00:00
|
|
|
nsIAnnotationService::TYPE_STRING,
|
|
|
|
&statement);
|
2006-07-18 16:48:10 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-12-18 10:30:37 +00:00
|
|
|
mozStorageStatementScoper scoper(statement);
|
2006-07-18 16:48:10 +00:00
|
|
|
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = statement->BindStringByName(NS_LITERAL_CSTRING("content"), aValue);
|
2006-07-18 16:48:10 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = statement->BindNullByName(NS_LITERAL_CSTRING("mime_type"));
|
2006-07-18 16:48:10 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = statement->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 16:48:56 +00:00
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
rv = transaction.Commit();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
|
2007-07-11 09:57:59 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAnnotationService::SetPageAnnotation(nsIURI* aURI,
|
|
|
|
const nsACString& aName,
|
|
|
|
nsIVariant* aValue,
|
|
|
|
PRInt32 aFlags,
|
|
|
|
PRUint16 aExpiration)
|
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
2007-07-11 09:57:59 +00:00
|
|
|
NS_ENSURE_ARG(aValue);
|
|
|
|
|
|
|
|
PRUint16 dataType;
|
|
|
|
nsresult rv = aValue->GetDataType(&dataType);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
switch (dataType) {
|
|
|
|
case nsIDataType::VTYPE_INT8:
|
|
|
|
case nsIDataType::VTYPE_UINT8:
|
|
|
|
case nsIDataType::VTYPE_INT16:
|
|
|
|
case nsIDataType::VTYPE_UINT16:
|
|
|
|
case nsIDataType::VTYPE_INT32:
|
|
|
|
case nsIDataType::VTYPE_UINT32:
|
|
|
|
case nsIDataType::VTYPE_BOOL: {
|
|
|
|
PRInt32 valueInt;
|
|
|
|
rv = aValue->GetAsInt32(&valueInt);
|
2009-12-18 10:30:37 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2007-07-11 09:57:59 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = SetPageAnnotationInt32(aURI, aName, valueInt, aFlags, aExpiration);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-12-18 10:30:37 +00:00
|
|
|
// Fall through PRInt64 case otherwise.
|
2007-07-11 09:57:59 +00:00
|
|
|
}
|
|
|
|
case nsIDataType::VTYPE_INT64:
|
|
|
|
case nsIDataType::VTYPE_UINT64: {
|
|
|
|
PRInt64 valueLong;
|
|
|
|
rv = aValue->GetAsInt64(&valueLong);
|
2009-12-18 10:30:37 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2007-07-11 09:57:59 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = SetPageAnnotationInt64(aURI, aName, valueLong, aFlags, aExpiration);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-12-18 10:30:37 +00:00
|
|
|
// Fall through double case otherwise.
|
2007-07-11 09:57:59 +00:00
|
|
|
}
|
|
|
|
case nsIDataType::VTYPE_FLOAT:
|
|
|
|
case nsIDataType::VTYPE_DOUBLE: {
|
|
|
|
double valueDouble;
|
|
|
|
rv = aValue->GetAsDouble(&valueDouble);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = SetPageAnnotationDouble(aURI, aName, valueDouble, aFlags, aExpiration);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
case nsIDataType::VTYPE_CHAR:
|
|
|
|
case nsIDataType::VTYPE_WCHAR:
|
|
|
|
case nsIDataType::VTYPE_DOMSTRING:
|
|
|
|
case nsIDataType::VTYPE_CHAR_STR:
|
|
|
|
case nsIDataType::VTYPE_WCHAR_STR:
|
|
|
|
case nsIDataType::VTYPE_STRING_SIZE_IS:
|
|
|
|
case nsIDataType::VTYPE_WSTRING_SIZE_IS:
|
|
|
|
case nsIDataType::VTYPE_UTF8STRING:
|
|
|
|
case nsIDataType::VTYPE_CSTRING:
|
|
|
|
case nsIDataType::VTYPE_ASTRING: {
|
|
|
|
nsAutoString stringValue;
|
|
|
|
rv = aValue->GetAsAString(stringValue);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = SetPageAnnotationString(aURI, aName, stringValue, aFlags, aExpiration);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
|
2007-07-11 09:57:59 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAnnotationService::SetItemAnnotation(PRInt64 aItemId,
|
|
|
|
const nsACString& aName,
|
|
|
|
nsIVariant* aValue,
|
|
|
|
PRInt32 aFlags,
|
|
|
|
PRUint16 aExpiration)
|
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
2007-07-11 09:57:59 +00:00
|
|
|
NS_ENSURE_ARG(aValue);
|
|
|
|
|
2007-08-19 20:02:48 +00:00
|
|
|
if (aExpiration == EXPIRE_WITH_HISTORY)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2007-07-11 09:57:59 +00:00
|
|
|
PRUint16 dataType;
|
|
|
|
nsresult rv = aValue->GetDataType(&dataType);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
switch (dataType) {
|
|
|
|
case nsIDataType::VTYPE_INT8:
|
|
|
|
case nsIDataType::VTYPE_UINT8:
|
|
|
|
case nsIDataType::VTYPE_INT16:
|
|
|
|
case nsIDataType::VTYPE_UINT16:
|
|
|
|
case nsIDataType::VTYPE_INT32:
|
|
|
|
case nsIDataType::VTYPE_UINT32:
|
|
|
|
case nsIDataType::VTYPE_BOOL: {
|
|
|
|
PRInt32 valueInt;
|
|
|
|
rv = aValue->GetAsInt32(&valueInt);
|
2009-12-18 10:30:37 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2007-07-11 09:57:59 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = SetItemAnnotationInt32(aItemId, aName, valueInt, aFlags, aExpiration);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-12-18 10:30:37 +00:00
|
|
|
// Fall through PRInt64 case otherwise.
|
2007-07-11 09:57:59 +00:00
|
|
|
}
|
|
|
|
case nsIDataType::VTYPE_INT64:
|
|
|
|
case nsIDataType::VTYPE_UINT64: {
|
|
|
|
PRInt64 valueLong;
|
|
|
|
rv = aValue->GetAsInt64(&valueLong);
|
2009-12-18 10:30:37 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2007-07-11 09:57:59 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = SetItemAnnotationInt64(aItemId, aName, valueLong, aFlags, aExpiration);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-12-18 10:30:37 +00:00
|
|
|
// Fall through double case otherwise.
|
2007-07-11 09:57:59 +00:00
|
|
|
}
|
|
|
|
case nsIDataType::VTYPE_FLOAT:
|
|
|
|
case nsIDataType::VTYPE_DOUBLE: {
|
|
|
|
double valueDouble;
|
|
|
|
rv = aValue->GetAsDouble(&valueDouble);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = SetItemAnnotationDouble(aItemId, aName, valueDouble, aFlags, aExpiration);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
case nsIDataType::VTYPE_CHAR:
|
|
|
|
case nsIDataType::VTYPE_WCHAR:
|
|
|
|
case nsIDataType::VTYPE_DOMSTRING:
|
|
|
|
case nsIDataType::VTYPE_CHAR_STR:
|
|
|
|
case nsIDataType::VTYPE_WCHAR_STR:
|
|
|
|
case nsIDataType::VTYPE_STRING_SIZE_IS:
|
|
|
|
case nsIDataType::VTYPE_WSTRING_SIZE_IS:
|
|
|
|
case nsIDataType::VTYPE_UTF8STRING:
|
|
|
|
case nsIDataType::VTYPE_CSTRING:
|
|
|
|
case nsIDataType::VTYPE_ASTRING: {
|
|
|
|
nsAutoString stringValue;
|
|
|
|
rv = aValue->GetAsAString(stringValue);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = SetItemAnnotationString(aItemId, aName, stringValue, aFlags, aExpiration);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAnnotationService::SetPageAnnotationString(nsIURI* aURI,
|
|
|
|
const nsACString& aName,
|
|
|
|
const nsAString& aValue,
|
|
|
|
PRInt32 aFlags,
|
|
|
|
PRUint16 aExpiration)
|
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
|
|
|
|
2008-10-19 21:14:59 +00:00
|
|
|
if (InPrivateBrowsingMode())
|
|
|
|
return NS_OK;
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
nsresult rv = SetAnnotationStringInternal(aURI, 0, aName, aValue,
|
|
|
|
aFlags, aExpiration);
|
2007-05-10 08:05:19 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
NOTIFY_ANNOS_OBSERVERS(OnPageAnnotationSet(aURI, aName));
|
2007-05-10 08:05:19 +00:00
|
|
|
|
2006-07-18 16:48:10 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2007-05-10 08:05:19 +00:00
|
|
|
nsAnnotationService::SetItemAnnotationString(PRInt64 aItemId,
|
|
|
|
const nsACString& aName,
|
|
|
|
const nsAString& aValue,
|
|
|
|
PRInt32 aFlags,
|
|
|
|
PRUint16 aExpiration)
|
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
|
|
|
|
2007-08-19 20:02:48 +00:00
|
|
|
if (aExpiration == EXPIRE_WITH_HISTORY)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
nsresult rv = SetAnnotationStringInternal(nsnull, aItemId, aName, aValue,
|
2007-05-10 08:05:19 +00:00
|
|
|
aFlags, aExpiration);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
NOTIFY_ANNOS_OBSERVERS(OnItemAnnotationSet(aItemId, aName));
|
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
2009-12-18 10:30:37 +00:00
|
|
|
nsAnnotationService::SetAnnotationInt32Internal(nsIURI* aURI,
|
|
|
|
PRInt64 aItemId,
|
2007-05-10 08:05:19 +00:00
|
|
|
const nsACString& aName,
|
|
|
|
PRInt32 aValue,
|
|
|
|
PRInt32 aFlags,
|
|
|
|
PRUint16 aExpiration)
|
2006-07-18 16:48:10 +00:00
|
|
|
{
|
|
|
|
mozStorageTransaction transaction(mDBConn, PR_FALSE);
|
2009-12-18 10:30:37 +00:00
|
|
|
mozIStorageStatement* statement;
|
|
|
|
nsresult rv = StartSetAnnotation(aURI, aItemId, aName, aFlags, aExpiration,
|
2007-04-22 21:48:52 +00:00
|
|
|
nsIAnnotationService::TYPE_INT32,
|
|
|
|
&statement);
|
2006-07-18 16:48:10 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-12-18 10:30:37 +00:00
|
|
|
mozStorageStatementScoper scoper(statement);
|
2006-07-18 16:48:10 +00:00
|
|
|
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = statement->BindInt32ByName(NS_LITERAL_CSTRING("content"), aValue);
|
2006-07-18 16:48:10 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = statement->BindNullByName(NS_LITERAL_CSTRING("mime_type"));
|
2006-07-18 16:48:10 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = statement->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 16:48:56 +00:00
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
rv = transaction.Commit();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-07-18 16:48:10 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAnnotationService::SetPageAnnotationInt32(nsIURI* aURI,
|
|
|
|
const nsACString& aName,
|
|
|
|
PRInt32 aValue,
|
|
|
|
PRInt32 aFlags,
|
|
|
|
PRUint16 aExpiration)
|
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
|
|
|
|
2008-10-19 21:14:59 +00:00
|
|
|
if (InPrivateBrowsingMode())
|
|
|
|
return NS_OK;
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
nsresult rv = SetAnnotationInt32Internal(aURI, 0, aName, aValue,
|
|
|
|
aFlags, aExpiration);
|
2007-05-10 08:05:19 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
NOTIFY_ANNOS_OBSERVERS(OnPageAnnotationSet(aURI, aName));
|
2007-05-10 08:05:19 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-07-18 16:50:42 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2007-05-10 08:05:19 +00:00
|
|
|
nsAnnotationService::SetItemAnnotationInt32(PRInt64 aItemId,
|
|
|
|
const nsACString& aName,
|
|
|
|
PRInt32 aValue,
|
|
|
|
PRInt32 aFlags,
|
|
|
|
PRUint16 aExpiration)
|
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
|
|
|
|
2007-08-19 20:02:48 +00:00
|
|
|
if (aExpiration == EXPIRE_WITH_HISTORY)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
nsresult rv = SetAnnotationInt32Internal(nsnull, aItemId, aName, aValue,
|
2007-05-10 08:05:19 +00:00
|
|
|
aFlags, aExpiration);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
NOTIFY_ANNOS_OBSERVERS(OnItemAnnotationSet(aItemId, aName));
|
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
2009-12-18 10:30:37 +00:00
|
|
|
nsAnnotationService::SetAnnotationInt64Internal(nsIURI* aURI,
|
|
|
|
PRInt64 aItemId,
|
2007-05-10 08:05:19 +00:00
|
|
|
const nsACString& aName,
|
|
|
|
PRInt64 aValue,
|
|
|
|
PRInt32 aFlags,
|
|
|
|
PRUint16 aExpiration)
|
2006-07-18 16:50:42 +00:00
|
|
|
{
|
|
|
|
mozStorageTransaction transaction(mDBConn, PR_FALSE);
|
2009-12-18 10:30:37 +00:00
|
|
|
mozIStorageStatement* statement;
|
|
|
|
nsresult rv = StartSetAnnotation(aURI, aItemId, aName, aFlags, aExpiration,
|
2007-04-22 21:48:52 +00:00
|
|
|
nsIAnnotationService::TYPE_INT64,
|
|
|
|
&statement);
|
2006-07-18 16:50:42 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-12-18 10:30:37 +00:00
|
|
|
mozStorageStatementScoper scoper(statement);
|
2006-07-18 16:50:42 +00:00
|
|
|
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = statement->BindInt64ByName(NS_LITERAL_CSTRING("content"), aValue);
|
2006-07-18 16:50:42 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = statement->BindNullByName(NS_LITERAL_CSTRING("mime_type"));
|
2006-07-18 16:50:42 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = statement->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
rv = transaction.Commit();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-07-18 16:50:42 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAnnotationService::SetPageAnnotationInt64(nsIURI* aURI,
|
|
|
|
const nsACString& aName,
|
|
|
|
PRInt64 aValue,
|
|
|
|
PRInt32 aFlags,
|
|
|
|
PRUint16 aExpiration)
|
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
|
|
|
|
2008-10-19 21:14:59 +00:00
|
|
|
if (InPrivateBrowsingMode())
|
|
|
|
return NS_OK;
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
nsresult rv = SetAnnotationInt64Internal(aURI, 0, aName, aValue,
|
|
|
|
aFlags, aExpiration);
|
2007-05-10 08:05:19 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
NOTIFY_ANNOS_OBSERVERS(OnPageAnnotationSet(aURI, aName));
|
2007-05-10 08:05:19 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-07-18 16:48:10 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2007-05-10 08:05:19 +00:00
|
|
|
nsAnnotationService::SetItemAnnotationInt64(PRInt64 aItemId,
|
|
|
|
const nsACString& aName,
|
|
|
|
PRInt64 aValue,
|
|
|
|
PRInt32 aFlags,
|
|
|
|
PRUint16 aExpiration)
|
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
|
|
|
|
2007-08-19 20:02:48 +00:00
|
|
|
if (aExpiration == EXPIRE_WITH_HISTORY)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
nsresult rv = SetAnnotationInt64Internal(nsnull, aItemId, aName, aValue,
|
2007-05-10 08:05:19 +00:00
|
|
|
aFlags, aExpiration);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
NOTIFY_ANNOS_OBSERVERS(OnItemAnnotationSet(aItemId, aName));
|
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
2009-12-18 10:30:37 +00:00
|
|
|
nsAnnotationService::SetAnnotationDoubleInternal(nsIURI* aURI,
|
|
|
|
PRInt64 aItemId,
|
2007-05-10 08:05:19 +00:00
|
|
|
const nsACString& aName,
|
|
|
|
double aValue,
|
|
|
|
PRInt32 aFlags,
|
|
|
|
PRUint16 aExpiration)
|
2006-07-18 16:48:10 +00:00
|
|
|
{
|
|
|
|
mozStorageTransaction transaction(mDBConn, PR_FALSE);
|
2009-12-18 10:30:37 +00:00
|
|
|
mozIStorageStatement* statement;
|
|
|
|
nsresult rv = StartSetAnnotation(aURI, aItemId, aName, aFlags, aExpiration,
|
2007-04-22 21:48:52 +00:00
|
|
|
nsIAnnotationService::TYPE_DOUBLE,
|
|
|
|
&statement);
|
2006-07-18 16:48:10 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-12-18 10:30:37 +00:00
|
|
|
mozStorageStatementScoper scoper(statement);
|
2006-07-18 16:48:10 +00:00
|
|
|
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = statement->BindDoubleByName(NS_LITERAL_CSTRING("content"), aValue);
|
2006-07-18 16:48:10 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = statement->BindNullByName(NS_LITERAL_CSTRING("mime_type"));
|
2006-07-18 16:48:10 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = statement->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 16:48:56 +00:00
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
rv = transaction.Commit();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-07-18 16:48:10 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAnnotationService::SetPageAnnotationDouble(nsIURI* aURI,
|
|
|
|
const nsACString& aName,
|
|
|
|
double aValue,
|
|
|
|
PRInt32 aFlags,
|
|
|
|
PRUint16 aExpiration)
|
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
|
|
|
|
2008-10-19 21:14:59 +00:00
|
|
|
if (InPrivateBrowsingMode())
|
|
|
|
return NS_OK;
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
nsresult rv = SetAnnotationDoubleInternal(aURI, 0, aName, aValue,
|
|
|
|
aFlags, aExpiration);
|
2007-05-10 08:05:19 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
NOTIFY_ANNOS_OBSERVERS(OnPageAnnotationSet(aURI, aName));
|
2007-05-10 08:05:19 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-07-18 16:48:10 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2007-05-10 08:05:19 +00:00
|
|
|
nsAnnotationService::SetItemAnnotationDouble(PRInt64 aItemId,
|
|
|
|
const nsACString& aName,
|
|
|
|
double aValue,
|
|
|
|
PRInt32 aFlags,
|
|
|
|
PRUint16 aExpiration)
|
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
|
|
|
|
2007-08-19 20:02:48 +00:00
|
|
|
if (aExpiration == EXPIRE_WITH_HISTORY)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
nsresult rv = SetAnnotationDoubleInternal(nsnull, aItemId, aName, aValue,
|
|
|
|
aFlags, aExpiration);
|
2007-05-10 08:05:19 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
NOTIFY_ANNOS_OBSERVERS(OnItemAnnotationSet(aItemId, aName));
|
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
2009-12-18 10:30:37 +00:00
|
|
|
nsAnnotationService::SetAnnotationBinaryInternal(nsIURI* aURI,
|
|
|
|
PRInt64 aItemId,
|
2007-05-10 08:05:19 +00:00
|
|
|
const nsACString& aName,
|
2009-12-18 10:30:37 +00:00
|
|
|
const PRUint8* aData,
|
2007-05-10 08:05:19 +00:00
|
|
|
PRUint32 aDataLen,
|
|
|
|
const nsACString& aMimeType,
|
|
|
|
PRInt32 aFlags,
|
|
|
|
PRUint16 aExpiration)
|
2006-07-18 16:48:10 +00:00
|
|
|
{
|
2006-07-18 16:51:05 +00:00
|
|
|
if (aMimeType.Length() == 0)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
mozStorageTransaction transaction(mDBConn, PR_FALSE);
|
2009-12-18 10:30:37 +00:00
|
|
|
mozIStorageStatement* statement;
|
|
|
|
nsresult rv = StartSetAnnotation(aURI, aItemId, aName, aFlags, aExpiration,
|
2007-04-22 21:48:52 +00:00
|
|
|
nsIAnnotationService::TYPE_BINARY,
|
|
|
|
&statement);
|
2006-07-18 16:48:10 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-12-18 10:30:37 +00:00
|
|
|
mozStorageStatementScoper scoper(statement);
|
2006-07-18 16:48:10 +00:00
|
|
|
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = statement->BindBlobByName(NS_LITERAL_CSTRING("content"), aData, aDataLen);
|
2006-07-18 16:51:05 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = statement->BindUTF8StringByName(NS_LITERAL_CSTRING("mime_type"), aMimeType);
|
2006-07-18 16:48:10 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 16:51:05 +00:00
|
|
|
|
|
|
|
rv = statement->Execute();
|
2006-07-18 16:48:10 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
rv = transaction.Commit();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-07-18 16:48:10 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAnnotationService::SetPageAnnotationBinary(nsIURI* aURI,
|
|
|
|
const nsACString& aName,
|
2009-12-18 10:30:37 +00:00
|
|
|
const PRUint8* aData,
|
2007-05-10 08:05:19 +00:00
|
|
|
PRUint32 aDataLen,
|
|
|
|
const nsACString& aMimeType,
|
|
|
|
PRInt32 aFlags,
|
|
|
|
PRUint16 aExpiration)
|
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
|
|
|
|
2008-10-19 21:14:59 +00:00
|
|
|
if (InPrivateBrowsingMode())
|
|
|
|
return NS_OK;
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
nsresult rv = SetAnnotationBinaryInternal(aURI, 0, aName, aData, aDataLen,
|
|
|
|
aMimeType, aFlags, aExpiration);
|
2007-05-10 08:05:19 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
NOTIFY_ANNOS_OBSERVERS(OnPageAnnotationSet(aURI, aName));
|
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-07-18 16:48:10 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2007-05-10 08:05:19 +00:00
|
|
|
nsAnnotationService::SetItemAnnotationBinary(PRInt64 aItemId,
|
|
|
|
const nsACString& aName,
|
2009-12-18 10:30:37 +00:00
|
|
|
const PRUint8* aData,
|
2007-05-10 08:05:19 +00:00
|
|
|
PRUint32 aDataLen,
|
|
|
|
const nsACString& aMimeType,
|
|
|
|
PRInt32 aFlags,
|
|
|
|
PRUint16 aExpiration)
|
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
|
|
|
|
2007-08-19 20:02:48 +00:00
|
|
|
if (aExpiration == EXPIRE_WITH_HISTORY)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
nsresult rv = SetAnnotationBinaryInternal(nsnull, aItemId, aName, aData,
|
2007-05-10 08:05:19 +00:00
|
|
|
aDataLen, aMimeType, aFlags,
|
|
|
|
aExpiration);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
NOTIFY_ANNOS_OBSERVERS(OnItemAnnotationSet(aItemId, aName));
|
2007-05-10 08:05:19 +00:00
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-05-10 08:05:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAnnotationService::GetPageAnnotationString(nsIURI* aURI,
|
|
|
|
const nsACString& aName,
|
|
|
|
nsAString& _retval)
|
2006-07-18 16:48:10 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
mozIStorageStatement* statement;
|
|
|
|
nsresult rv = StartGetAnnotation(aURI, 0, aName, &statement);
|
2006-07-18 16:49:19 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2006-07-18 16:48:10 +00:00
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
mozStorageStatementScoper scoper(statement);
|
|
|
|
ENSURE_ANNO_TYPE(TYPE_STRING, statement);
|
|
|
|
rv = statement->GetString(kAnnoIndex_Content, _retval);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-07-18 16:48:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2007-05-10 08:05:19 +00:00
|
|
|
nsAnnotationService::GetItemAnnotationString(PRInt64 aItemId,
|
|
|
|
const nsACString& aName,
|
|
|
|
nsAString& _retval)
|
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
mozIStorageStatement* statement;
|
|
|
|
nsresult rv = StartGetAnnotation(nsnull, aItemId, aName, &statement);
|
2007-05-10 08:05:19 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2009-12-18 10:30:37 +00:00
|
|
|
|
|
|
|
mozStorageStatementScoper scoper(statement);
|
|
|
|
ENSURE_ANNO_TYPE(TYPE_STRING, statement);
|
|
|
|
rv = statement->GetString(kAnnoIndex_Content, _retval);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
2007-05-10 08:05:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-11 09:57:59 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAnnotationService::GetPageAnnotation(nsIURI* aURI,
|
|
|
|
const nsACString& aName,
|
|
|
|
nsIVariant** _retval)
|
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
2009-12-18 10:30:37 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2009-06-12 07:34:35 +00:00
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
mozIStorageStatement* statement;
|
|
|
|
nsresult rv = StartGetAnnotation(aURI, 0, aName, &statement);
|
2007-07-11 09:57:59 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
mozStorageStatementScoper scoper(statement);
|
|
|
|
|
2007-07-11 09:57:59 +00:00
|
|
|
nsCOMPtr<nsIWritableVariant> value = new nsVariant();
|
2009-12-18 10:30:37 +00:00
|
|
|
PRInt32 type = statement->AsInt32(kAnnoIndex_Type);
|
2007-07-11 09:57:59 +00:00
|
|
|
switch (type) {
|
|
|
|
case nsIAnnotationService::TYPE_INT32:
|
|
|
|
case nsIAnnotationService::TYPE_INT64:
|
|
|
|
case nsIAnnotationService::TYPE_DOUBLE: {
|
2009-12-18 10:30:37 +00:00
|
|
|
rv = value->SetAsDouble(statement->AsDouble(kAnnoIndex_Content));
|
2007-07-11 09:57:59 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case nsIAnnotationService::TYPE_STRING: {
|
|
|
|
nsAutoString valueString;
|
2009-12-18 10:30:37 +00:00
|
|
|
rv = statement->GetString(kAnnoIndex_Content, valueString);
|
2007-07-11 09:57:59 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = value->SetAsAString(valueString);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case nsIAnnotationService::TYPE_BINARY: {
|
|
|
|
rv = NS_ERROR_INVALID_ARG;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
rv = NS_ERROR_UNEXPECTED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
NS_ADDREF(*_retval = value);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
|
2007-07-11 09:57:59 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAnnotationService::GetItemAnnotation(PRInt64 aItemId,
|
|
|
|
const nsACString& aName,
|
|
|
|
nsIVariant** _retval)
|
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
mozIStorageStatement* statement;
|
|
|
|
nsresult rv = StartGetAnnotation(nsnull, aItemId, aName, &statement);
|
2007-07-11 09:57:59 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
mozStorageStatementScoper scoper(statement);
|
|
|
|
|
2007-07-11 09:57:59 +00:00
|
|
|
nsCOMPtr<nsIWritableVariant> value = new nsVariant();
|
2009-12-18 10:30:37 +00:00
|
|
|
PRInt32 type = statement->AsInt32(kAnnoIndex_Type);
|
2007-07-11 09:57:59 +00:00
|
|
|
switch (type) {
|
|
|
|
case nsIAnnotationService::TYPE_INT32:
|
|
|
|
case nsIAnnotationService::TYPE_INT64:
|
|
|
|
case nsIAnnotationService::TYPE_DOUBLE: {
|
2009-12-18 10:30:37 +00:00
|
|
|
rv = value->SetAsDouble(statement->AsDouble(kAnnoIndex_Content));
|
2007-07-11 09:57:59 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case nsIAnnotationService::TYPE_STRING: {
|
|
|
|
nsAutoString valueString;
|
2009-12-18 10:30:37 +00:00
|
|
|
rv = statement->GetString(kAnnoIndex_Content, valueString);
|
2007-07-11 09:57:59 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = value->SetAsAString(valueString);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case nsIAnnotationService::TYPE_BINARY: {
|
|
|
|
rv = NS_ERROR_INVALID_ARG;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
rv = NS_ERROR_UNEXPECTED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
NS_ADDREF(*_retval = value);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAnnotationService::GetPageAnnotationInt32(nsIURI* aURI,
|
2006-07-18 16:48:10 +00:00
|
|
|
const nsACString& aName,
|
2009-12-18 10:30:37 +00:00
|
|
|
PRInt32* _retval)
|
2006-07-18 16:48:10 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
2009-12-18 10:30:37 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2009-06-12 07:34:35 +00:00
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
mozIStorageStatement* statement;
|
|
|
|
nsresult rv = StartGetAnnotation(aURI, 0, aName, &statement);
|
2006-07-18 16:49:19 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2009-12-18 10:30:37 +00:00
|
|
|
|
|
|
|
mozStorageStatementScoper scoper(statement);
|
|
|
|
ENSURE_ANNO_TYPE(TYPE_INT32, statement);
|
|
|
|
*_retval = statement->AsInt32(kAnnoIndex_Content);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-07-18 16:48:33 +00:00
|
|
|
return NS_OK;
|
2006-07-18 16:48:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-18 16:50:42 +00:00
|
|
|
NS_IMETHODIMP
|
2007-05-10 08:05:19 +00:00
|
|
|
nsAnnotationService::GetItemAnnotationInt32(PRInt64 aItemId,
|
|
|
|
const nsACString& aName,
|
2009-12-18 10:30:37 +00:00
|
|
|
PRInt32* _retval)
|
2007-05-10 08:05:19 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
2009-12-18 10:30:37 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2009-06-12 07:34:35 +00:00
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
mozIStorageStatement* statement;
|
|
|
|
nsresult rv = StartGetAnnotation(nsnull, aItemId, aName, &statement);
|
2007-05-10 08:05:19 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2009-12-18 10:30:37 +00:00
|
|
|
|
|
|
|
mozStorageStatementScoper scoper(statement);
|
|
|
|
ENSURE_ANNO_TYPE(TYPE_INT32, statement);
|
|
|
|
*_retval = statement->AsInt32(kAnnoIndex_Content);
|
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAnnotationService::GetPageAnnotationInt64(nsIURI* aURI,
|
|
|
|
const nsACString& aName,
|
2009-12-18 10:30:37 +00:00
|
|
|
PRInt64* _retval)
|
2006-07-18 16:50:42 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
2009-12-18 10:30:37 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
|
|
|
|
mozIStorageStatement* statement;
|
|
|
|
nsresult rv = StartGetAnnotation(aURI, 0, aName, &statement);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
mozStorageStatementScoper scoper(statement);
|
|
|
|
ENSURE_ANNO_TYPE(TYPE_INT64, statement);
|
|
|
|
*_retval = statement->AsInt64(kAnnoIndex_Content);
|
2009-06-12 07:34:35 +00:00
|
|
|
|
2006-07-18 16:50:42 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
|
2007-04-22 22:20:25 +00:00
|
|
|
NS_IMETHODIMP
|
2007-05-10 08:05:19 +00:00
|
|
|
nsAnnotationService::GetItemAnnotationInt64(PRInt64 aItemId,
|
|
|
|
const nsACString& aName,
|
2009-12-18 10:30:37 +00:00
|
|
|
PRInt64* _retval)
|
2007-05-10 08:05:19 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
2009-12-18 10:30:37 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
|
|
|
|
mozIStorageStatement* statement;
|
|
|
|
nsresult rv = StartGetAnnotation(nsnull, aItemId, aName, &statement);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
mozStorageStatementScoper scoper(statement);
|
|
|
|
ENSURE_ANNO_TYPE(TYPE_INT64, statement);
|
|
|
|
*_retval = statement->AsInt64(kAnnoIndex_Content);
|
2009-06-12 07:34:35 +00:00
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAnnotationService::GetPageAnnotationType(nsIURI* aURI,
|
|
|
|
const nsACString& aName,
|
|
|
|
PRUint16* _retval)
|
2007-04-22 22:20:25 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
mozIStorageStatement* statement;
|
|
|
|
nsresult rv = StartGetAnnotation(aURI, 0, aName, &statement);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
mozStorageStatementScoper scoper(statement);
|
|
|
|
*_retval = statement->AsInt32(kAnnoIndex_Type);
|
|
|
|
|
2007-04-22 22:20:25 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-07-18 16:50:42 +00:00
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAnnotationService::GetItemAnnotationType(PRInt64 aItemId,
|
|
|
|
const nsACString& aName,
|
|
|
|
PRUint16* _retval)
|
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2009-12-18 10:30:37 +00:00
|
|
|
|
|
|
|
mozIStorageStatement* statement;
|
|
|
|
nsresult rv = StartGetAnnotation(nsnull, aItemId, aName, &statement);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
mozStorageStatementScoper scoper(statement);
|
|
|
|
*_retval = statement->AsInt32(kAnnoIndex_Type);
|
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-07-18 16:51:05 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2007-05-10 08:05:19 +00:00
|
|
|
nsAnnotationService::GetPageAnnotationDouble(nsIURI* aURI,
|
|
|
|
const nsACString& aName,
|
2009-12-18 10:30:37 +00:00
|
|
|
double* _retval)
|
2006-07-18 16:51:05 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
mozIStorageStatement* statement;
|
|
|
|
nsresult rv = StartGetAnnotation(aURI, 0, aName, &statement);
|
2006-07-18 16:51:05 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2009-12-18 10:30:37 +00:00
|
|
|
|
|
|
|
mozStorageStatementScoper scoper(statement);
|
|
|
|
ENSURE_ANNO_TYPE(TYPE_DOUBLE, statement);
|
|
|
|
*_retval = statement->AsDouble(kAnnoIndex_Content);
|
|
|
|
|
2006-07-18 16:51:05 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAnnotationService::GetItemAnnotationDouble(PRInt64 aItemId,
|
|
|
|
const nsACString& aName,
|
2009-12-18 10:30:37 +00:00
|
|
|
double* _retval)
|
2007-05-10 08:05:19 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
2009-12-18 10:30:37 +00:00
|
|
|
|
|
|
|
mozIStorageStatement* statement;
|
|
|
|
nsresult rv = StartGetAnnotation(nsnull, aItemId, aName, &statement);
|
2007-05-10 08:05:19 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2009-12-18 10:30:37 +00:00
|
|
|
|
|
|
|
mozStorageStatementScoper scoper(statement);
|
|
|
|
ENSURE_ANNO_TYPE(TYPE_DOUBLE, statement);
|
|
|
|
*_retval = statement->AsDouble(kAnnoIndex_Content);
|
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-07-18 16:48:10 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2007-05-10 08:05:19 +00:00
|
|
|
nsAnnotationService::GetPageAnnotationBinary(nsIURI* aURI,
|
|
|
|
const nsACString& aName,
|
2009-12-18 10:30:37 +00:00
|
|
|
PRUint8** _data,
|
|
|
|
PRUint32* _dataLen,
|
|
|
|
nsACString& _mimeType)
|
2006-07-18 16:48:10 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
2009-12-18 10:30:37 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(_data);
|
|
|
|
NS_ENSURE_ARG_POINTER(_dataLen);
|
2009-06-12 07:34:35 +00:00
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
mozIStorageStatement* statement;
|
|
|
|
nsresult rv = StartGetAnnotation(aURI, 0, aName, &statement);
|
2006-07-18 16:49:19 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2009-12-18 10:30:37 +00:00
|
|
|
|
|
|
|
mozStorageStatementScoper scoper(statement);
|
|
|
|
ENSURE_ANNO_TYPE(TYPE_BINARY, statement);
|
|
|
|
rv = statement->GetBlob(kAnnoIndex_Content, _dataLen, _data);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = statement->GetUTF8String(kAnnoIndex_MimeType, _mimeType);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
2006-07-18 16:48:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAnnotationService::GetItemAnnotationBinary(PRInt64 aItemId,
|
|
|
|
const nsACString& aName,
|
2009-12-18 10:30:37 +00:00
|
|
|
PRUint8** _data,
|
|
|
|
PRUint32* _dataLen,
|
|
|
|
nsACString& _mimeType)
|
2007-05-10 08:05:19 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
2009-12-18 10:30:37 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(_data);
|
|
|
|
NS_ENSURE_ARG_POINTER(_dataLen);
|
|
|
|
|
|
|
|
mozIStorageStatement* statement;
|
|
|
|
nsresult rv = StartGetAnnotation(nsnull, aItemId, aName, &statement);
|
2007-05-10 08:05:19 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2009-12-18 10:30:37 +00:00
|
|
|
|
|
|
|
mozStorageStatementScoper scoper(statement);
|
|
|
|
ENSURE_ANNO_TYPE(TYPE_BINARY, statement);
|
|
|
|
rv = statement->GetBlob(kAnnoIndex_Content, _dataLen, _data);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = statement->GetUTF8String(kAnnoIndex_MimeType, _mimeType);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
2007-05-10 08:05:19 +00:00
|
|
|
}
|
|
|
|
|
2006-07-18 16:48:10 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2007-05-10 08:05:19 +00:00
|
|
|
nsAnnotationService::GetPageAnnotationInfo(nsIURI* aURI,
|
|
|
|
const nsACString& aName,
|
2009-12-18 10:30:37 +00:00
|
|
|
PRInt32* _flags,
|
|
|
|
PRUint16* _expiration,
|
|
|
|
nsACString& _mimeType,
|
|
|
|
PRUint16* _storageType)
|
2006-07-18 16:48:10 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
2009-12-18 10:30:37 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(_flags);
|
|
|
|
NS_ENSURE_ARG_POINTER(_expiration);
|
|
|
|
NS_ENSURE_ARG_POINTER(_storageType);
|
2009-06-12 07:34:35 +00:00
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
mozIStorageStatement* statement;
|
|
|
|
nsresult rv = StartGetAnnotation(aURI, 0, aName, &statement);
|
2006-07-18 16:49:19 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2006-07-18 16:48:10 +00:00
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
mozStorageStatementScoper scoper(statement);
|
|
|
|
*_flags = statement->AsInt32(kAnnoIndex_Flags);
|
|
|
|
*_expiration = (PRUint16)statement->AsInt32(kAnnoIndex_Expiration);
|
|
|
|
rv = statement->GetUTF8String(kAnnoIndex_MimeType, _mimeType);
|
2006-07-18 16:48:10 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-12-18 10:30:37 +00:00
|
|
|
PRInt32 type = (PRUint16)statement->AsInt32(kAnnoIndex_Type);
|
2007-04-22 21:48:52 +00:00
|
|
|
if (type == 0) {
|
|
|
|
// For annotations created before explicit typing,
|
|
|
|
// we can't determine type, just return as string type.
|
2009-12-18 10:30:37 +00:00
|
|
|
*_storageType = nsIAnnotationService::TYPE_STRING;
|
2007-04-22 21:48:52 +00:00
|
|
|
}
|
2009-12-18 10:30:37 +00:00
|
|
|
else
|
|
|
|
*_storageType = type;
|
|
|
|
|
|
|
|
return NS_OK;
|
2006-07-18 16:48:10 +00:00
|
|
|
}
|
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAnnotationService::GetItemAnnotationInfo(PRInt64 aItemId,
|
|
|
|
const nsACString& aName,
|
2009-12-18 10:30:37 +00:00
|
|
|
PRInt32* _flags,
|
|
|
|
PRUint16* _expiration,
|
|
|
|
nsACString& _mimeType,
|
|
|
|
PRUint16* _storageType)
|
2007-05-10 08:05:19 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
2009-12-18 10:30:37 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(_flags);
|
|
|
|
NS_ENSURE_ARG_POINTER(_expiration);
|
|
|
|
NS_ENSURE_ARG_POINTER(_storageType);
|
2009-06-12 07:34:35 +00:00
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
mozIStorageStatement* statement;
|
|
|
|
nsresult rv = StartGetAnnotation(nsnull, aItemId, aName, &statement);
|
2007-05-10 08:05:19 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
mozStorageStatementScoper scoper(statement);
|
|
|
|
*_flags = statement->AsInt32(kAnnoIndex_Flags);
|
|
|
|
*_expiration = (PRUint16)statement->AsInt32(kAnnoIndex_Expiration);
|
|
|
|
rv = statement->GetUTF8String(kAnnoIndex_MimeType, _mimeType);
|
2007-05-10 08:05:19 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-12-18 10:30:37 +00:00
|
|
|
PRInt32 type = (PRUint16)statement->AsInt32(kAnnoIndex_Type);
|
2007-05-10 08:05:19 +00:00
|
|
|
if (type == 0) {
|
|
|
|
// For annotations created before explicit typing,
|
|
|
|
// we can't determine type, just return as string type.
|
2009-12-18 10:30:37 +00:00
|
|
|
*_storageType = nsIAnnotationService::TYPE_STRING;
|
2007-05-10 08:05:19 +00:00
|
|
|
}
|
2009-12-18 10:30:37 +00:00
|
|
|
else {
|
|
|
|
*_storageType = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2007-05-10 08:05:19 +00:00
|
|
|
}
|
2006-07-18 16:48:10 +00:00
|
|
|
|
2006-07-18 16:50:05 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAnnotationService::GetPagesWithAnnotation(const nsACString& aName,
|
2009-12-18 10:30:37 +00:00
|
|
|
PRUint32* _resultCount,
|
|
|
|
nsIURI*** _results)
|
2006-07-18 16:50:05 +00:00
|
|
|
{
|
2009-12-18 10:30:37 +00:00
|
|
|
NS_ENSURE_TRUE(!aName.IsEmpty(), NS_ERROR_INVALID_ARG);
|
|
|
|
NS_ENSURE_ARG_POINTER(_resultCount);
|
|
|
|
NS_ENSURE_ARG_POINTER(_results);
|
|
|
|
|
|
|
|
*_resultCount = 0;
|
|
|
|
*_results = nsnull;
|
2006-07-18 16:53:00 +00:00
|
|
|
nsCOMArray<nsIURI> results;
|
|
|
|
|
|
|
|
nsresult rv = GetPagesWithAnnotationCOMArray(aName, &results);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
// Convert to raw array.
|
2006-07-18 16:53:00 +00:00
|
|
|
if (results.Count() == 0)
|
|
|
|
return NS_OK;
|
2009-12-18 10:30:37 +00:00
|
|
|
|
|
|
|
*_results = static_cast<nsIURI**>
|
2007-07-08 07:08:04 +00:00
|
|
|
(nsMemory::Alloc(results.Count() * sizeof(nsIURI*)));
|
2009-12-18 10:30:37 +00:00
|
|
|
NS_ENSURE_TRUE(*_results, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
*_resultCount = results.Count();
|
|
|
|
for (PRUint32 i = 0; i < *_resultCount; i ++) {
|
|
|
|
(*_results)[i] = results[i];
|
|
|
|
NS_ADDREF((*_results)[i]);
|
2006-07-18 16:53:00 +00:00
|
|
|
}
|
2009-12-18 10:30:37 +00:00
|
|
|
|
2006-07-18 16:53:00 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-07-18 16:50:05 +00:00
|
|
|
|
2006-07-18 16:53:00 +00:00
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
nsresult
|
2009-12-18 10:30:37 +00:00
|
|
|
nsAnnotationService::GetPagesWithAnnotationCOMArray(const nsACString& aName,
|
|
|
|
nsCOMArray<nsIURI>* _results)
|
|
|
|
{
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetPagesWithAnnotation);
|
2010-04-27 11:24:58 +00:00
|
|
|
nsresult rv = stmt->BindUTF8StringByName(NS_LITERAL_CSTRING("anno_name"), aName);
|
2006-07-18 16:50:05 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRBool hasMore = PR_FALSE;
|
2009-12-18 10:30:40 +00:00
|
|
|
while (NS_SUCCEEDED(rv = stmt->ExecuteStep(&hasMore)) &&
|
2009-12-18 10:30:37 +00:00
|
|
|
hasMore) {
|
2006-07-18 16:50:05 +00:00
|
|
|
nsCAutoString uristring;
|
2009-12-18 10:30:40 +00:00
|
|
|
rv = stmt->GetUTF8String(0, uristring);
|
2006-07-18 16:50:05 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-07-18 16:53:47 +00:00
|
|
|
// convert to a URI, in case of some invalid URI, just ignore this row
|
|
|
|
// so we can mostly continue.
|
2006-07-18 16:50:05 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
rv = NS_NewURI(getter_AddRefs(uri), uristring);
|
2006-07-18 16:53:47 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
continue;
|
2009-12-18 10:30:37 +00:00
|
|
|
|
|
|
|
PRBool added = _results->AppendObject(uri);
|
2006-07-18 16:50:05 +00:00
|
|
|
NS_ENSURE_TRUE(added, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
}
|
2009-12-18 10:30:37 +00:00
|
|
|
|
2006-07-18 16:50:05 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAnnotationService::GetItemsWithAnnotation(const nsACString& aName,
|
2009-12-18 10:30:37 +00:00
|
|
|
PRUint32* _resultCount,
|
|
|
|
PRInt64** _results)
|
2007-05-10 08:05:19 +00:00
|
|
|
{
|
2009-12-18 10:30:37 +00:00
|
|
|
NS_ENSURE_TRUE(!aName.IsEmpty(), NS_ERROR_INVALID_ARG);
|
|
|
|
NS_ENSURE_ARG_POINTER(_resultCount);
|
|
|
|
NS_ENSURE_ARG_POINTER(_results);
|
2009-06-12 07:34:35 +00:00
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
*_resultCount = 0;
|
|
|
|
*_results = nsnull;
|
2007-05-10 08:05:19 +00:00
|
|
|
nsTArray<PRInt64> results;
|
|
|
|
|
|
|
|
nsresult rv = GetItemsWithAnnotationTArray(aName, &results);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
// Convert to raw array.
|
2007-05-10 08:05:19 +00:00
|
|
|
if (results.Length() == 0)
|
|
|
|
return NS_OK;
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
*_results = static_cast<PRInt64*>
|
2007-07-08 07:08:04 +00:00
|
|
|
(nsMemory::Alloc(results.Length() * sizeof(PRInt64)));
|
2009-12-18 10:30:37 +00:00
|
|
|
NS_ENSURE_TRUE(*_results, NS_ERROR_OUT_OF_MEMORY);
|
2007-05-10 08:05:19 +00:00
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
*_resultCount = results.Length();
|
|
|
|
for (PRUint32 i = 0; i < *_resultCount; i ++) {
|
|
|
|
(*_results)[i] = results[i];
|
2007-05-10 08:05:19 +00:00
|
|
|
}
|
2009-12-18 10:30:37 +00:00
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
nsresult
|
|
|
|
nsAnnotationService::GetItemsWithAnnotationTArray(const nsACString& aName,
|
2009-12-18 10:30:37 +00:00
|
|
|
nsTArray<PRInt64>* _results)
|
|
|
|
{
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetItemsWithAnnotation);
|
2010-04-27 11:24:58 +00:00
|
|
|
nsresult rv = stmt->BindUTF8StringByName(NS_LITERAL_CSTRING("anno_name"), aName);
|
2007-05-10 08:05:19 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRBool hasMore = PR_FALSE;
|
2009-12-18 10:30:40 +00:00
|
|
|
while (NS_SUCCEEDED(stmt->ExecuteStep(&hasMore)) &&
|
2009-12-18 10:30:37 +00:00
|
|
|
hasMore) {
|
2009-12-18 10:30:40 +00:00
|
|
|
if (!_results->AppendElement(stmt->AsInt64(0)))
|
2007-05-10 08:05:19 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2009-12-18 10:30:37 +00:00
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-12-18 10:30:37 +00:00
|
|
|
|
2006-07-18 16:51:28 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-12-18 10:30:37 +00:00
|
|
|
nsAnnotationService::GetPageAnnotationNames(nsIURI* aURI,
|
|
|
|
PRUint32* _count,
|
2006-07-18 16:51:28 +00:00
|
|
|
nsIVariant*** _result)
|
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
2009-12-18 10:30:37 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(_count);
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(_result);
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
*_count = 0;
|
2006-07-18 16:51:28 +00:00
|
|
|
*_result = nsnull;
|
|
|
|
|
|
|
|
nsTArray<nsCString> names;
|
2009-12-18 10:30:37 +00:00
|
|
|
nsresult rv = GetAnnotationNamesTArray(aURI, 0, &names);
|
2006-07-18 16:51:28 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-12-18 10:30:37 +00:00
|
|
|
|
2006-07-18 16:51:28 +00:00
|
|
|
if (names.Length() == 0)
|
|
|
|
return NS_OK;
|
|
|
|
|
2007-07-08 07:08:04 +00:00
|
|
|
*_result = static_cast<nsIVariant**>
|
|
|
|
(nsMemory::Alloc(sizeof(nsIVariant*) * names.Length()));
|
2006-07-18 16:51:28 +00:00
|
|
|
NS_ENSURE_TRUE(*_result, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < names.Length(); i ++) {
|
2007-07-11 09:57:59 +00:00
|
|
|
nsCOMPtr<nsIWritableVariant> var = new nsVariant();
|
2009-12-18 10:30:37 +00:00
|
|
|
if (!var) {
|
2006-07-18 16:51:28 +00:00
|
|
|
// need to release all the variants we've already created
|
|
|
|
for (PRUint32 j = 0; j < i; j ++)
|
|
|
|
NS_RELEASE((*_result)[j]);
|
|
|
|
nsMemory::Free(*_result);
|
|
|
|
*_result = nsnull;
|
2007-05-10 08:05:19 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2006-07-18 16:51:28 +00:00
|
|
|
}
|
|
|
|
var->SetAsAUTF8String(names[i]);
|
|
|
|
NS_ADDREF((*_result)[i] = var);
|
|
|
|
}
|
2009-12-18 10:30:37 +00:00
|
|
|
*_count = names.Length();
|
2006-07-18 16:51:28 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-03 08:56:41 +00:00
|
|
|
nsresult
|
2009-12-18 10:30:37 +00:00
|
|
|
nsAnnotationService::GetAnnotationNamesTArray(nsIURI* aURI,
|
|
|
|
PRInt64 aItemId,
|
|
|
|
nsTArray<nsCString>* _result)
|
2006-07-18 16:51:28 +00:00
|
|
|
{
|
2009-12-18 10:30:37 +00:00
|
|
|
bool isItemAnnotation = (aItemId > 0);
|
|
|
|
mozIStorageStatement* statement = isItemAnnotation ?
|
2009-12-18 10:30:40 +00:00
|
|
|
GetStatement(mDBGetAnnotationsForItem) : GetStatement(mDBGetAnnotationsForPage);
|
|
|
|
NS_ENSURE_STATE(statement);
|
2006-07-18 16:51:28 +00:00
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
_result->Clear();
|
2006-07-18 16:51:28 +00:00
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
mozStorageStatementScoper scoper(statement);
|
2009-12-18 10:30:37 +00:00
|
|
|
nsresult rv;
|
|
|
|
if (isItemAnnotation)
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = statement->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2009-12-18 10:30:37 +00:00
|
|
|
else
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = URIBinder::Bind(statement, NS_LITERAL_CSTRING("page_url"), aURI);
|
2006-07-18 16:51:28 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
PRBool hasResult = PR_FALSE;
|
2007-05-10 08:05:19 +00:00
|
|
|
while (NS_SUCCEEDED(statement->ExecuteStep(&hasResult)) &&
|
2006-07-18 16:51:28 +00:00
|
|
|
hasResult) {
|
2009-12-18 10:30:37 +00:00
|
|
|
nsCAutoString name;
|
2007-05-10 08:05:19 +00:00
|
|
|
rv = statement->GetUTF8String(0, name);
|
2006-07-18 16:51:28 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-12-18 10:30:37 +00:00
|
|
|
if (!_result->AppendElement(name))
|
2006-07-18 16:51:28 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
NS_IMETHODIMP
|
2009-12-18 10:30:37 +00:00
|
|
|
nsAnnotationService::GetItemAnnotationNames(PRInt64 aItemId,
|
|
|
|
PRUint32* _count,
|
2007-05-10 08:05:19 +00:00
|
|
|
nsIVariant*** _result)
|
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
2009-12-18 10:30:37 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(_count);
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(_result);
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
*_count = 0;
|
2007-05-10 08:05:19 +00:00
|
|
|
*_result = nsnull;
|
|
|
|
|
|
|
|
nsTArray<nsCString> names;
|
2009-12-18 10:30:37 +00:00
|
|
|
nsresult rv = GetAnnotationNamesTArray(nsnull, aItemId, &names);
|
2007-05-10 08:05:19 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-12-18 10:30:37 +00:00
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
if (names.Length() == 0)
|
|
|
|
return NS_OK;
|
|
|
|
|
2007-07-08 07:08:04 +00:00
|
|
|
*_result = static_cast<nsIVariant**>
|
|
|
|
(nsMemory::Alloc(sizeof(nsIVariant*) * names.Length()));
|
2007-05-10 08:05:19 +00:00
|
|
|
NS_ENSURE_TRUE(*_result, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < names.Length(); i ++) {
|
2007-07-11 09:57:59 +00:00
|
|
|
nsCOMPtr<nsIWritableVariant> var = new nsVariant();
|
2009-12-18 10:30:37 +00:00
|
|
|
if (!var) {
|
2007-05-10 08:05:19 +00:00
|
|
|
// need to release all the variants we've already created
|
|
|
|
for (PRUint32 j = 0; j < i; j ++)
|
|
|
|
NS_RELEASE((*_result)[j]);
|
|
|
|
nsMemory::Free(*_result);
|
|
|
|
*_result = nsnull;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
var->SetAsAUTF8String(names[i]);
|
|
|
|
NS_ADDREF((*_result)[i] = var);
|
|
|
|
}
|
2009-12-18 10:30:37 +00:00
|
|
|
*_count = names.Length();
|
2007-05-10 08:05:19 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-07-18 16:48:10 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2007-05-10 08:05:19 +00:00
|
|
|
nsAnnotationService::PageHasAnnotation(nsIURI* aURI,
|
|
|
|
const nsACString& aName,
|
2009-12-18 10:30:37 +00:00
|
|
|
PRBool* _retval)
|
2006-07-18 16:48:10 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
nsresult rv = HasAnnotationInternal(aURI, 0, aName, _retval);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 16:48:10 +00:00
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-07-18 16:48:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2007-05-10 08:05:19 +00:00
|
|
|
nsAnnotationService::ItemHasAnnotation(PRInt64 aItemId,
|
|
|
|
const nsACString& aName,
|
2009-12-18 10:30:37 +00:00
|
|
|
PRBool* _retval)
|
2006-07-18 16:48:10 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
nsresult rv = HasAnnotationInternal(nsnull, aItemId, aName, _retval);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
2007-05-10 08:05:19 +00:00
|
|
|
}
|
2006-07-18 16:50:42 +00:00
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @note We don't remove anything from the moz_anno_attributes table. If we
|
|
|
|
* delete the last item of a given name, that item really should go away.
|
|
|
|
* It will be cleaned up by expiration.
|
|
|
|
*/
|
2007-05-10 08:05:19 +00:00
|
|
|
nsresult
|
2009-12-18 10:30:37 +00:00
|
|
|
nsAnnotationService::RemoveAnnotationInternal(nsIURI* aURI,
|
|
|
|
PRInt64 aItemId,
|
2007-05-10 08:05:19 +00:00
|
|
|
const nsACString& aName)
|
|
|
|
{
|
2009-12-18 10:30:37 +00:00
|
|
|
bool isItemAnnotation = (aItemId > 0);
|
|
|
|
mozIStorageStatement* statement = isItemAnnotation ?
|
2009-12-18 10:30:40 +00:00
|
|
|
GetStatement(mDBRemoveItemAnnotation) : GetStatement(mDBRemovePageAnnotation);
|
|
|
|
NS_ENSURE_STATE(statement);
|
2009-12-18 10:30:37 +00:00
|
|
|
mozStorageStatementScoper scoper(statement);
|
2006-07-18 16:50:42 +00:00
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
nsresult rv;
|
|
|
|
if (isItemAnnotation)
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = statement->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2009-12-18 10:30:37 +00:00
|
|
|
else
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = URIBinder::Bind(statement, NS_LITERAL_CSTRING("page_url"), aURI);
|
2006-07-18 16:50:42 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = statement->BindUTF8StringByName(NS_LITERAL_CSTRING("anno_name"), aName);
|
2006-07-18 16:50:42 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
rv = statement->Execute();
|
2006-07-18 16:50:42 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAnnotationService::RemovePageAnnotation(nsIURI* aURI,
|
|
|
|
const nsACString& aName)
|
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
nsresult rv = RemoveAnnotationInternal(aURI, 0, aName);
|
2007-05-10 08:05:19 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 16:51:28 +00:00
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
NOTIFY_ANNOS_OBSERVERS(OnPageAnnotationRemoved(aURI, aName));
|
2006-07-18 16:50:42 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
2006-07-18 16:48:10 +00:00
|
|
|
}
|
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAnnotationService::RemoveItemAnnotation(PRInt64 aItemId,
|
|
|
|
const nsACString& aName)
|
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
nsresult rv = RemoveAnnotationInternal(nsnull, aItemId, aName);
|
2007-05-10 08:05:19 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
NOTIFY_ANNOS_OBSERVERS(OnItemAnnotationRemoved(aItemId, aName));
|
2007-05-10 08:05:19 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-07-18 16:48:10 +00:00
|
|
|
|
2006-07-18 16:51:28 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAnnotationService::RemovePageAnnotations(nsIURI* aURI)
|
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
// Should this be precompiled or a getter?
|
2006-07-18 16:51:28 +00:00
|
|
|
nsCOMPtr<mozIStorageStatement> statement;
|
2009-12-18 10:30:37 +00:00
|
|
|
nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
|
|
|
"DELETE FROM moz_annos WHERE place_id = "
|
2010-08-09 15:59:59 +00:00
|
|
|
"(SELECT id FROM moz_places WHERE url = :page_url)"),
|
2006-07-18 16:51:28 +00:00
|
|
|
getter_AddRefs(statement));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = URIBinder::Bind(statement, NS_LITERAL_CSTRING("page_url"), aURI);
|
2006-07-18 16:51:28 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = statement->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Update observers
|
2009-12-18 10:30:37 +00:00
|
|
|
NOTIFY_ANNOS_OBSERVERS(OnPageAnnotationRemoved(aURI, EmptyCString()));
|
|
|
|
|
2006-07-18 16:51:28 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAnnotationService::RemoveItemAnnotations(PRInt64 aItemId)
|
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
// Should this be precompiled or a getter?
|
2007-05-10 08:05:19 +00:00
|
|
|
nsCOMPtr<mozIStorageStatement> statement;
|
|
|
|
nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2010-04-27 11:24:58 +00:00
|
|
|
"DELETE FROM moz_items_annos WHERE item_id = :item_id"),
|
2007-05-10 08:05:19 +00:00
|
|
|
getter_AddRefs(statement));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = statement->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2007-05-10 08:05:19 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = statement->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
NOTIFY_ANNOS_OBSERVERS(OnItemAnnotationRemoved(aItemId, EmptyCString()));
|
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-07-18 16:52:14 +00:00
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
/**
|
|
|
|
* @note If we use annotations for some standard items like GeckoFlags, it
|
|
|
|
* might be a good idea to blacklist these standard annotations from this
|
|
|
|
* copy function.
|
|
|
|
*/
|
2006-07-18 16:52:14 +00:00
|
|
|
NS_IMETHODIMP
|
2007-05-10 08:05:19 +00:00
|
|
|
nsAnnotationService::CopyPageAnnotations(nsIURI* aSourceURI,
|
|
|
|
nsIURI* aDestURI,
|
|
|
|
PRBool aOverwriteDest)
|
2006-07-18 16:52:14 +00:00
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG(aSourceURI);
|
|
|
|
NS_ENSURE_ARG(aDestURI);
|
|
|
|
|
2008-10-19 21:14:59 +00:00
|
|
|
if (InPrivateBrowsingMode())
|
|
|
|
return NS_OK;
|
|
|
|
|
2006-07-18 16:52:14 +00:00
|
|
|
mozStorageTransaction transaction(mDBConn, PR_FALSE);
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
nsCOMPtr<mozIStorageStatement> sourceStmt;
|
|
|
|
nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
|
|
|
"SELECT h.id, n.id, n.name, a2.id "
|
2010-08-09 15:59:59 +00:00
|
|
|
"FROM moz_places h "
|
2009-12-18 10:30:37 +00:00
|
|
|
"JOIN moz_annos a ON a.place_id = h.id "
|
|
|
|
"JOIN moz_anno_attributes n ON n.id = a.anno_attribute_id "
|
2010-08-09 15:59:59 +00:00
|
|
|
"LEFT JOIN moz_annos a2 ON a2.place_id = "
|
|
|
|
"(SELECT id FROM moz_places WHERE url = :dest_url) "
|
|
|
|
"AND a2.anno_attribute_id = n.id "
|
|
|
|
"WHERE url = :source_url"),
|
2009-12-18 10:30:37 +00:00
|
|
|
getter_AddRefs(sourceStmt));
|
2006-07-18 16:52:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = URIBinder::Bind(sourceStmt, NS_LITERAL_CSTRING("source_url"), aSourceURI);
|
2007-05-10 08:05:19 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = URIBinder::Bind(sourceStmt, NS_LITERAL_CSTRING("dest_url"), aDestURI);
|
2006-07-18 16:52:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
nsCOMPtr<mozIStorageStatement> copyStmt;
|
2006-07-18 16:52:14 +00:00
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2008-10-27 22:52:20 +00:00
|
|
|
"INSERT INTO moz_annos "
|
2009-12-18 10:30:37 +00:00
|
|
|
"(place_id, anno_attribute_id, mime_type, content, flags, expiration, "
|
|
|
|
"type, dateAdded, lastModified) "
|
2010-08-09 15:59:59 +00:00
|
|
|
"SELECT (SELECT id FROM moz_places WHERE url = :page_url), "
|
|
|
|
"anno_attribute_id, mime_type, content, flags, expiration, type, "
|
|
|
|
":date, :date "
|
2008-10-27 22:52:20 +00:00
|
|
|
"FROM moz_annos "
|
2010-04-27 11:24:58 +00:00
|
|
|
"WHERE place_id = :page_id "
|
|
|
|
"AND anno_attribute_id = :name_id"),
|
2009-12-18 10:30:37 +00:00
|
|
|
getter_AddRefs(copyStmt));
|
2006-07-18 16:52:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
PRBool hasResult;
|
|
|
|
while (NS_SUCCEEDED(sourceStmt->ExecuteStep(&hasResult)) && hasResult) {
|
|
|
|
PRInt64 sourcePlaceId = sourceStmt->AsInt64(0);
|
|
|
|
PRInt64 annoNameID = sourceStmt->AsInt64(1);
|
|
|
|
nsCAutoString annoName;
|
|
|
|
rv = sourceStmt->GetUTF8String(2, annoName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
PRInt64 annoExistsOnDest = sourceStmt->AsInt64(3);
|
2006-07-18 16:52:14 +00:00
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
if (annoExistsOnDest) {
|
|
|
|
if (!aOverwriteDest)
|
|
|
|
continue;
|
|
|
|
rv = RemovePageAnnotation(aDestURI, annoName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2006-07-18 16:52:14 +00:00
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
// Copy the annotation.
|
|
|
|
mozStorageStatementScoper scoper(copyStmt);
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = URIBinder::Bind(copyStmt, NS_LITERAL_CSTRING("page_url"), aDestURI);
|
2009-12-18 10:30:37 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = copyStmt->BindInt64ByName(NS_LITERAL_CSTRING("page_id"), sourcePlaceId);
|
2009-12-18 10:30:37 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = copyStmt->BindInt64ByName(NS_LITERAL_CSTRING("name_id"), annoNameID);
|
2009-12-18 10:30:37 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = copyStmt->BindInt64ByName(NS_LITERAL_CSTRING("date"), PR_Now());
|
2009-12-18 10:30:37 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 16:52:14 +00:00
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
rv = copyStmt->Execute();
|
2006-07-18 16:52:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-12-18 10:30:37 +00:00
|
|
|
|
|
|
|
NOTIFY_ANNOS_OBSERVERS(OnPageAnnotationSet(aDestURI, annoName));
|
2006-07-18 16:52:14 +00:00
|
|
|
}
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
rv = transaction.Commit();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-07-18 16:52:14 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAnnotationService::CopyItemAnnotations(PRInt64 aSourceItemId,
|
|
|
|
PRInt64 aDestItemId,
|
|
|
|
PRBool aOverwriteDest)
|
|
|
|
{
|
2009-12-18 10:30:37 +00:00
|
|
|
NS_ENSURE_ARG_MIN(aSourceItemId, 1);
|
|
|
|
NS_ENSURE_ARG_MIN(aDestItemId, 1);
|
|
|
|
|
|
|
|
mozStorageTransaction transaction(mDBConn, PR_FALSE);
|
|
|
|
|
|
|
|
nsCOMPtr<mozIStorageStatement> sourceStmt;
|
|
|
|
nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
|
|
|
"SELECT n.id, n.name, a2.id "
|
|
|
|
"FROM moz_bookmarks b "
|
|
|
|
"JOIN moz_items_annos a ON a.item_id = b.id "
|
|
|
|
"JOIN moz_anno_attributes n ON n.id = a.anno_attribute_id "
|
2010-04-27 11:24:58 +00:00
|
|
|
"LEFT JOIN moz_items_annos a2 ON a2.item_id = :dest_item_id "
|
2009-12-18 10:30:37 +00:00
|
|
|
"AND a2.anno_attribute_id = n.id "
|
2010-04-27 11:24:58 +00:00
|
|
|
"WHERE b.id = :source_item_id"),
|
2009-12-18 10:30:37 +00:00
|
|
|
getter_AddRefs(sourceStmt));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = sourceStmt->BindInt64ByName(NS_LITERAL_CSTRING("source_item_id"), aSourceItemId);
|
2009-12-18 10:30:37 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = sourceStmt->BindInt64ByName(NS_LITERAL_CSTRING("dest_item_id"), aDestItemId);
|
2009-12-18 10:30:37 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<mozIStorageStatement> copyStmt;
|
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
|
|
|
"INSERT OR REPLACE INTO moz_items_annos "
|
|
|
|
"(item_id, anno_attribute_id, mime_type, content, flags, expiration, "
|
|
|
|
"type, dateAdded, lastModified) "
|
2010-04-27 11:24:58 +00:00
|
|
|
"SELECT :dest_item_id, anno_attribute_id, mime_type, content, flags, expiration, "
|
|
|
|
"type, :date, :date "
|
2009-12-18 10:30:37 +00:00
|
|
|
"FROM moz_items_annos "
|
2010-04-27 11:24:58 +00:00
|
|
|
"WHERE item_id = :source_item_id "
|
|
|
|
"AND anno_attribute_id = :name_id"),
|
2009-12-18 10:30:37 +00:00
|
|
|
getter_AddRefs(copyStmt));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRBool hasResult;
|
|
|
|
while (NS_SUCCEEDED(sourceStmt->ExecuteStep(&hasResult)) && hasResult) {
|
|
|
|
PRInt64 annoNameID = sourceStmt->AsInt64(0);
|
|
|
|
nsCAutoString annoName;
|
|
|
|
rv = sourceStmt->GetUTF8String(1, annoName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
PRInt64 annoExistsOnDest = sourceStmt->AsInt64(2);
|
|
|
|
|
|
|
|
if (annoExistsOnDest) {
|
|
|
|
if (!aOverwriteDest)
|
|
|
|
continue;
|
|
|
|
rv = RemoveItemAnnotation(aDestItemId, annoName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy the annotation.
|
|
|
|
mozStorageStatementScoper scoper(copyStmt);
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = copyStmt->BindInt64ByName(NS_LITERAL_CSTRING("dest_item_id"), aDestItemId);
|
2009-12-18 10:30:37 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = copyStmt->BindInt64ByName(NS_LITERAL_CSTRING("source_item_id"), aSourceItemId);
|
2009-12-18 10:30:37 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = copyStmt->BindInt64ByName(NS_LITERAL_CSTRING("name_id"), annoNameID);
|
2009-12-18 10:30:37 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = copyStmt->BindInt64ByName(NS_LITERAL_CSTRING("date"), PR_Now());
|
2009-12-18 10:30:37 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = copyStmt->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
NOTIFY_ANNOS_OBSERVERS(OnItemAnnotationSet(aDestItemId, annoName));
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = transaction.Commit();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
2007-05-10 08:05:19 +00:00
|
|
|
}
|
2006-07-18 16:52:14 +00:00
|
|
|
|
2006-07-18 16:48:56 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAnnotationService::AddObserver(nsIAnnotationObserver* aObserver)
|
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG(aObserver);
|
|
|
|
|
2006-07-18 16:48:56 +00:00
|
|
|
if (mObservers.IndexOfObject(aObserver) >= 0)
|
2009-12-18 10:30:37 +00:00
|
|
|
return NS_ERROR_INVALID_ARG; // Already registered.
|
2006-07-18 16:48:56 +00:00
|
|
|
if (!mObservers.AppendObject(aObserver))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAnnotationService::RemoveObserver(nsIAnnotationObserver* aObserver)
|
|
|
|
{
|
2009-06-12 07:34:35 +00:00
|
|
|
NS_ENSURE_ARG(aObserver);
|
|
|
|
|
2006-07-18 16:48:56 +00:00
|
|
|
if (!mObservers.RemoveObject(aObserver))
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// nsAnnotationService::GetAnnotationURI
|
2007-05-10 08:05:19 +00:00
|
|
|
//
|
|
|
|
// XXX: does not support item-annotations
|
2006-07-18 16:48:56 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-12-18 10:30:37 +00:00
|
|
|
nsAnnotationService::GetAnnotationURI(nsIURI* aURI,
|
|
|
|
const nsACString& aName,
|
2006-07-18 16:48:56 +00:00
|
|
|
nsIURI** _result)
|
|
|
|
{
|
|
|
|
if (aName.IsEmpty())
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
nsCAutoString annoSpec;
|
|
|
|
nsresult rv = aURI->GetSpec(annoSpec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCAutoString spec;
|
|
|
|
spec.AssignLiteral("moz-anno:");
|
|
|
|
spec += aName;
|
|
|
|
spec += NS_LITERAL_CSTRING(":");
|
|
|
|
spec += annoSpec;
|
|
|
|
|
|
|
|
return NS_NewURI(_result, spec);
|
|
|
|
}
|
|
|
|
|
2006-07-18 16:48:10 +00:00
|
|
|
|
|
|
|
nsresult
|
2009-12-18 10:30:37 +00:00
|
|
|
nsAnnotationService::HasAnnotationInternal(nsIURI* aURI,
|
|
|
|
PRInt64 aItemId,
|
2006-07-18 16:48:10 +00:00
|
|
|
const nsACString& aName,
|
2009-12-18 10:30:37 +00:00
|
|
|
PRBool* _hasAnno)
|
2006-07-18 16:48:10 +00:00
|
|
|
{
|
2009-12-18 10:30:37 +00:00
|
|
|
bool isItemAnnotation = (aItemId > 0);
|
|
|
|
mozIStorageStatement* stmt = isItemAnnotation ?
|
2009-12-18 10:30:40 +00:00
|
|
|
GetStatement(mDBCheckItemAnnotation) : GetStatement(mDBCheckPageAnnotation);
|
|
|
|
NS_ENSURE_STATE(stmt);
|
2009-12-18 10:30:37 +00:00
|
|
|
mozStorageStatementScoper checkAnnoScoper(stmt);
|
2006-07-18 16:48:10 +00:00
|
|
|
|
2010-04-27 11:24:58 +00:00
|
|
|
nsresult rv = stmt->BindUTF8StringByName(NS_LITERAL_CSTRING("anno_name"), aName);
|
2006-07-18 16:48:10 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-12-18 10:30:37 +00:00
|
|
|
if (isItemAnnotation)
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2009-12-18 10:30:37 +00:00
|
|
|
else
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("page_url"), aURI);
|
2006-07-18 16:48:10 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
PRBool hasResult;
|
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!hasResult) {
|
|
|
|
// We are trying to get an annotation on an invalid bookmarks or
|
|
|
|
// history entry.
|
|
|
|
// Here we preserve the old behavior, returning that we don't have the
|
|
|
|
// annotation, ignoring the fact itemId is invalid.
|
|
|
|
// Otherwise we should return NS_ERROR_INVALID_ARG, but this will somehow
|
|
|
|
// break the API. In future we could want to be pickier.
|
|
|
|
*_hasAnno = PR_FALSE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PRInt64 annotationId = stmt->AsInt64(2);
|
|
|
|
*_hasAnno = (annotationId > 0);
|
|
|
|
}
|
2006-07-18 16:48:10 +00:00
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
return NS_OK;
|
2006-07-18 16:48:10 +00:00
|
|
|
}
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This loads the statement and steps it once so you can get data out of it.
|
|
|
|
*
|
|
|
|
* @note You have to reset the statement when you're done if this succeeds.
|
|
|
|
* @throws NS_ERROR_NOT_AVAILABLE if the annotation is not found.
|
|
|
|
*/
|
2006-07-18 16:48:10 +00:00
|
|
|
|
|
|
|
nsresult
|
2009-12-18 10:30:37 +00:00
|
|
|
nsAnnotationService::StartGetAnnotation(nsIURI* aURI,
|
|
|
|
PRInt64 aItemId,
|
|
|
|
const nsACString& aName,
|
|
|
|
mozIStorageStatement** _statement)
|
2006-07-18 16:48:10 +00:00
|
|
|
{
|
2009-12-18 10:30:37 +00:00
|
|
|
bool isItemAnnotation = (aItemId > 0);
|
2006-07-18 16:48:10 +00:00
|
|
|
|
2009-12-18 10:30:40 +00:00
|
|
|
*_statement = isItemAnnotation ? GetStatement(mDBGetItemAnnotationValue)
|
|
|
|
: GetStatement(mDBGetPageAnnotationValue);
|
2010-03-12 06:50:10 +00:00
|
|
|
NS_ENSURE_STATE(*_statement);
|
2009-12-18 10:30:37 +00:00
|
|
|
mozStorageStatementScoper getAnnoScoper(*_statement);
|
2006-07-18 16:48:10 +00:00
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
nsresult rv;
|
2009-12-18 10:30:37 +00:00
|
|
|
if (isItemAnnotation)
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = (*_statement)->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2009-12-18 10:30:37 +00:00
|
|
|
else
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = URIBinder::Bind(*_statement, NS_LITERAL_CSTRING("page_url"), aURI);
|
2007-05-10 08:05:19 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-12-18 10:30:37 +00:00
|
|
|
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = (*_statement)->BindUTF8StringByName(NS_LITERAL_CSTRING("anno_name"), aName);
|
2007-05-10 08:05:19 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRBool hasResult = PR_FALSE;
|
2009-12-18 10:30:37 +00:00
|
|
|
rv = (*_statement)->ExecuteStep(&hasResult);
|
|
|
|
if (NS_FAILED(rv) || !hasResult)
|
2007-05-10 08:05:19 +00:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
// on success, DON'T reset the statement, the caller needs to read from it,
|
2009-12-18 10:30:37 +00:00
|
|
|
// and it is the caller's job to reset it.
|
|
|
|
getAnnoScoper.Abandon();
|
|
|
|
|
2007-05-10 08:05:19 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-19 21:14:59 +00:00
|
|
|
PRBool
|
|
|
|
nsAnnotationService::InPrivateBrowsingMode() const
|
|
|
|
{
|
2009-12-18 10:30:37 +00:00
|
|
|
nsNavHistory* history = nsNavHistory::GetHistoryService();
|
2008-10-19 21:14:59 +00:00
|
|
|
return history && history->InPrivateBrowsingMode();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
/**
|
|
|
|
* This does most of the setup work needed to set an annotation, except for
|
|
|
|
* binding the the actual value and MIME type and executing the statement.
|
|
|
|
* It will either update an existing annotation or insert a new one.
|
|
|
|
*
|
|
|
|
* @note The aStatement RESULT IS NOT ADDREFED. This is just one of the class
|
|
|
|
* vars, which control its scope. DO NOT RELEASE.
|
|
|
|
* The caller must take care of resetting the statement if this succeeds.
|
|
|
|
*/
|
2007-05-10 08:05:19 +00:00
|
|
|
nsresult
|
2009-12-18 10:30:37 +00:00
|
|
|
nsAnnotationService::StartSetAnnotation(nsIURI* aURI,
|
|
|
|
PRInt64 aItemId,
|
2006-07-18 16:48:10 +00:00
|
|
|
const nsACString& aName,
|
2007-05-10 08:05:19 +00:00
|
|
|
PRInt32 aFlags,
|
|
|
|
PRUint16 aExpiration,
|
|
|
|
PRUint16 aType,
|
2009-12-18 10:30:37 +00:00
|
|
|
mozIStorageStatement** _statement)
|
2006-07-18 16:48:10 +00:00
|
|
|
{
|
2009-12-18 10:30:37 +00:00
|
|
|
bool isItemAnnotation = (aItemId > 0);
|
2007-06-26 01:08:54 +00:00
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
// Ensure the annotation name exists.
|
2010-01-16 11:38:02 +00:00
|
|
|
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(addNameStmt, mDBAddAnnotationName);
|
2010-04-27 11:24:58 +00:00
|
|
|
nsresult rv = addNameStmt->BindUTF8StringByName(NS_LITERAL_CSTRING("anno_name"), aName);
|
2009-12-18 10:30:37 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-12-18 10:30:40 +00:00
|
|
|
rv = addNameStmt->Execute();
|
2006-07-18 16:48:10 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
// We have to check 2 things:
|
|
|
|
// - if the annotation already exists we should update it.
|
|
|
|
// - we should not allow setting annotations on invalid URIs or itemIds.
|
|
|
|
// This query will tell us:
|
|
|
|
// - whether the item or page exists.
|
|
|
|
// - whether the annotation already exists.
|
|
|
|
// - the nameID associated with the annotation name.
|
|
|
|
// - the id and dateAdded of the old annotation, if it exists.
|
|
|
|
mozIStorageStatement* stmt = isItemAnnotation ?
|
2009-12-18 10:30:40 +00:00
|
|
|
GetStatement(mDBCheckItemAnnotation) : GetStatement(mDBCheckPageAnnotation);
|
|
|
|
NS_ENSURE_STATE(stmt);
|
2009-12-18 10:30:37 +00:00
|
|
|
mozStorageStatementScoper checkAnnoScoper(stmt);
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = stmt->BindUTF8StringByName(NS_LITERAL_CSTRING("anno_name"), aName);
|
2009-12-18 10:30:37 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (isItemAnnotation)
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2009-12-18 10:30:37 +00:00
|
|
|
else
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("page_url"), aURI);
|
2009-12-18 10:30:37 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 16:52:37 +00:00
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
PRBool hasResult;
|
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!hasResult) {
|
|
|
|
// We are trying to create an annotation on an invalid bookmark
|
|
|
|
// or history entry.
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2006-07-18 16:52:37 +00:00
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
PRInt64 fkId = stmt->AsInt64(0);
|
|
|
|
PRInt64 nameID = stmt->AsInt64(1);
|
|
|
|
PRInt64 oldAnnoId = stmt->AsInt64(2);
|
|
|
|
PRInt64 oldAnnoDate = stmt->AsInt64(3);
|
2008-08-16 22:28:28 +00:00
|
|
|
|
2009-12-18 10:30:40 +00:00
|
|
|
*_statement = isItemAnnotation ? GetStatement(mDBAddItemAnnotation)
|
|
|
|
: GetStatement(mDBAddPageAnnotation);
|
2010-03-12 06:50:10 +00:00
|
|
|
NS_ENSURE_STATE(*_statement);
|
2009-12-18 10:30:37 +00:00
|
|
|
mozStorageStatementScoper setAnnoScoper(*_statement);
|
2008-08-16 22:28:28 +00:00
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
// Don't replace existing annotations.
|
|
|
|
if (oldAnnoId > 0) {
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = (*_statement)->BindInt64ByName(NS_LITERAL_CSTRING("id"), oldAnnoId);
|
2009-12-18 10:30:37 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = (*_statement)->BindInt64ByName(NS_LITERAL_CSTRING("date_added"), oldAnnoDate);
|
2007-07-26 16:23:11 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 16:48:10 +00:00
|
|
|
}
|
2009-12-18 10:30:37 +00:00
|
|
|
else {
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = (*_statement)->BindNullByName(NS_LITERAL_CSTRING("id"));
|
2009-12-18 10:30:37 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = (*_statement)->BindInt64ByName(NS_LITERAL_CSTRING("date_added"), PR_Now());
|
2009-12-18 10:30:37 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = (*_statement)->BindInt64ByName(NS_LITERAL_CSTRING("fk"), fkId);
|
2006-07-18 16:48:10 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = (*_statement)->BindInt64ByName(NS_LITERAL_CSTRING("name_id"), nameID);
|
2006-07-18 16:48:10 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-12-18 10:30:37 +00:00
|
|
|
// MimeType and Content will be bound by the caller.
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = (*_statement)->BindInt32ByName(NS_LITERAL_CSTRING("flags"), aFlags);
|
2006-07-18 16:48:10 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = (*_statement)->BindInt32ByName(NS_LITERAL_CSTRING("expiration"), aExpiration);
|
2009-12-18 10:30:37 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = (*_statement)->BindInt32ByName(NS_LITERAL_CSTRING("type"), aType);
|
2009-12-18 10:30:37 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:24:58 +00:00
|
|
|
rv = (*_statement)->BindInt64ByName(NS_LITERAL_CSTRING("last_modified"), PR_Now());
|
2007-04-22 21:48:52 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 16:48:10 +00:00
|
|
|
|
|
|
|
// on success, leave the statement open, the caller will set the value
|
|
|
|
// and MIME type and execute the statement
|
2009-12-18 10:30:37 +00:00
|
|
|
setAnnoScoper.Abandon();
|
2007-05-10 08:05:19 +00:00
|
|
|
|
2009-12-18 10:30:37 +00:00
|
|
|
return NS_OK;
|
2007-05-10 08:05:19 +00:00
|
|
|
}
|
|
|
|
|
2008-11-14 06:45:49 +00:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsAnnotationService::FinalizeStatements() {
|
2009-12-18 10:30:40 +00:00
|
|
|
mShuttingDown = true;
|
|
|
|
|
2008-11-14 06:45:49 +00:00
|
|
|
mozIStorageStatement* stmts[] = {
|
2009-12-18 10:30:37 +00:00
|
|
|
mDBGetAnnotationsForPage
|
|
|
|
, mDBGetAnnotationsForItem
|
|
|
|
, mDBGetPageAnnotationValue
|
|
|
|
, mDBGetItemAnnotationValue
|
|
|
|
, mDBAddAnnotationName
|
|
|
|
, mDBAddPageAnnotation
|
|
|
|
, mDBAddItemAnnotation
|
|
|
|
, mDBRemovePageAnnotation
|
|
|
|
, mDBRemoveItemAnnotation
|
|
|
|
, mDBGetPagesWithAnnotation
|
|
|
|
, mDBGetItemsWithAnnotation
|
|
|
|
, mDBCheckPageAnnotation
|
|
|
|
, mDBCheckItemAnnotation
|
2008-11-14 06:45:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(stmts); i++) {
|
|
|
|
nsresult rv = nsNavHistory::FinalizeStatement(stmts[i]);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|