2009-12-18 13:30:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2006-07-18 20:48:10 +04:00
|
|
|
|
2013-12-09 06:52:54 +04:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2011-10-11 09:50:08 +04:00
|
|
|
|
2006-07-18 20:48:10 +04:00
|
|
|
#include "nsAnnotationService.h"
|
|
|
|
#include "nsNavHistory.h"
|
2008-08-04 21:14:17 +04:00
|
|
|
#include "nsPlacesTables.h"
|
2009-05-11 13:05:56 +04:00
|
|
|
#include "nsPlacesIndexes.h"
|
2009-12-01 16:00:45 +03:00
|
|
|
#include "nsPlacesMacros.h"
|
2010-01-16 14:38:02 +03:00
|
|
|
#include "Helpers.h"
|
2006-07-18 20:48:10 +04:00
|
|
|
|
2011-10-27 13:11:34 +04:00
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsIVariant.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsVariant.h"
|
2009-12-18 13:30:37 +03:00
|
|
|
#include "mozilla/storage.h"
|
|
|
|
|
2013-03-18 18:25:50 +04:00
|
|
|
#include "GeckoProfiler.h"
|
2012-01-18 00:33:04 +04:00
|
|
|
|
2012-02-18 10:40:10 +04:00
|
|
|
#include "nsNetCID.h"
|
|
|
|
|
2011-10-11 09:50:08 +04:00
|
|
|
using namespace mozilla;
|
2012-12-21 18:19:04 +04:00
|
|
|
using namespace mozilla::places;
|
2011-10-11 09:50:08 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
const int32_t nsAnnotationService::kAnnoIndex_ID = 0;
|
|
|
|
const int32_t nsAnnotationService::kAnnoIndex_PageOrItem = 1;
|
|
|
|
const int32_t nsAnnotationService::kAnnoIndex_NameID = 2;
|
2013-08-03 15:06:47 +04:00
|
|
|
const int32_t nsAnnotationService::kAnnoIndex_Content = 3;
|
|
|
|
const int32_t nsAnnotationService::kAnnoIndex_Flags = 4;
|
|
|
|
const int32_t nsAnnotationService::kAnnoIndex_Expiration = 5;
|
|
|
|
const int32_t nsAnnotationService::kAnnoIndex_Type = 6;
|
|
|
|
const int32_t nsAnnotationService::kAnnoIndex_DateAdded = 7;
|
|
|
|
const int32_t nsAnnotationService::kAnnoIndex_LastModified = 8;
|
2006-07-18 20:48:10 +04:00
|
|
|
|
2009-12-01 16:00:45 +03:00
|
|
|
PLACES_FACTORY_SINGLETON_IMPLEMENTATION(nsAnnotationService, gAnnotationService)
|
2006-07-18 20:52:14 +04:00
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsAnnotationService, nsIAnnotationService,
|
2011-10-27 13:11:47 +04:00
|
|
|
nsISupportsWeakReference)
|
2006-07-18 20:48:10 +04:00
|
|
|
|
2011-10-27 13:11:34 +04:00
|
|
|
nsAnnotationService::nsAnnotationService() {
|
2006-07-18 20:52:14 +04:00
|
|
|
NS_ASSERTION(!gAnnotationService,
|
2009-12-01 16:00:45 +03:00
|
|
|
"Attempting to create two instances of the service!");
|
2006-07-18 20:52:14 +04:00
|
|
|
gAnnotationService = this;
|
2006-07-18 20:48:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAnnotationService::~nsAnnotationService() {
|
2006-07-18 20:52:37 +04:00
|
|
|
NS_ASSERTION(gAnnotationService == this,
|
2009-12-01 16:00:45 +03:00
|
|
|
"Deleting a non-singleton instance of the service");
|
2006-07-18 20:52:14 +04:00
|
|
|
if (gAnnotationService == this) gAnnotationService = nullptr;
|
2006-07-18 20:48:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsAnnotationService::Init() {
|
2011-10-27 13:11:34 +04:00
|
|
|
mDB = Database::GetDatabase();
|
|
|
|
NS_ENSURE_STATE(mDB);
|
2006-07-18 20:48:10 +04:00
|
|
|
|
2009-12-18 13:30:40 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-12-18 13:30:37 +03:00
|
|
|
|
2018-08-01 12:47:24 +03:00
|
|
|
nsresult nsAnnotationService::SetAnnotationStringInternal(
|
2007-05-10 12:05:19 +04:00
|
|
|
int64_t aItemId, BookmarkData* aBookmark, const nsACString& aName,
|
|
|
|
const nsAString& aValue, int32_t aFlags, uint16_t aExpiration) {
|
2011-10-27 13:11:34 +04:00
|
|
|
mozStorageTransaction transaction(mDB->MainConn(), false);
|
|
|
|
nsCOMPtr<mozIStorageStatement> statement;
|
2017-11-17 03:49:03 +03:00
|
|
|
|
2018-08-01 12:47:24 +03:00
|
|
|
nsresult rv =
|
|
|
|
StartSetAnnotation(aItemId, aBookmark, aName, aFlags, aExpiration,
|
2017-11-18 03:48:42 +03:00
|
|
|
nsIAnnotationService::TYPE_STRING, statement);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2017-11-17 03:49:03 +03:00
|
|
|
|
2017-11-18 03:48:42 +03:00
|
|
|
mozStorageStatementScoper scoper(statement);
|
2006-07-18 20:48:10 +04:00
|
|
|
|
2017-11-18 03:48:42 +03:00
|
|
|
rv = statement->BindStringByName(NS_LITERAL_CSTRING("content"), aValue);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 20:48:56 +04:00
|
|
|
|
2017-11-18 03:48:42 +03:00
|
|
|
rv = statement->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-12-18 13:30:37 +03:00
|
|
|
|
2017-11-18 03:48:42 +03:00
|
|
|
rv = transaction.Commit();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2017-11-17 03:49:03 +03:00
|
|
|
|
2017-11-18 03:48:42 +03:00
|
|
|
return NS_OK;
|
2007-05-10 12:05:19 +04:00
|
|
|
}
|
|
|
|
|
2007-07-11 13:57:59 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsAnnotationService::SetItemAnnotation(int64_t aItemId, const nsACString& aName,
|
2007-07-11 13:57:59 +04:00
|
|
|
nsIVariant* aValue, int32_t aFlags,
|
2016-08-11 23:13:22 +03:00
|
|
|
uint16_t aExpiration, uint16_t aSource,
|
2017-10-03 23:18:10 +03:00
|
|
|
bool aDontUpdateLastModified) {
|
Bug 1375392 - Tweak the PROFILER_LABEL* macros. r=mstange.
This patch makes the following changes to the macros.
- Removes PROFILER_LABEL_FUNC. It's only suitable for use in functions outside
classes, due to PROFILER_FUNCTION_NAME not getting class names, and it was
mostly misused.
- Removes PROFILER_FUNCTION_NAME. It's no longer used, and __func__ is
universally available now anyway.
- Combines the first two string literal arguments of PROFILER_LABEL and
PROFILER_LABEL_DYNAMIC into a single argument. There was no good reason for
them to be separate, and it forced a '::' in the label, which isn't always
appropriate. Also, the meaning of the "name_space" argument was interpreted
in an interesting variety of ways.
- Adds an "AUTO_" prefix to PROFILER_LABEL and PROFILER_LABEL_DYNAMIC, to make
it clearer they construct RAII objects rather than just being function calls.
(I myself have screwed up the scoping because of this in the past.)
- Fills in the 'js::ProfileEntry::Category::' qualifier within the macro, so
the caller doesn't need to. This makes a *lot* more of the uses fit onto a
single line.
The patch also makes the following changes to the macro uses (beyond those
required by the changes described above).
- Fixes a bunch of labels that had gotten out of sync with the name of the
class and/or function that encloses them.
- Removes a useless PROFILER_LABEL use within a trivial scope in
EventStateManager::DispatchMouseOrPointerEvent(). It clearly wasn't serving
any useful purpose. It also serves as extra evidence that the AUTO_ prefix is
a good idea.
- Tweaks DecodePool::SyncRunIf{Preferred,Possible} so that the labelling is
done within them, instead of at their callsites, because that's a more
standard way of doing things.
--HG--
extra : rebase_source : 318d1bc6fc1425a94aacbf489dd46e4f83211de4
2017-06-22 10:08:53 +03:00
|
|
|
AUTO_PROFILER_LABEL("nsAnnotationService::SetItemAnnotation", OTHER);
|
2014-05-24 01:12:29 +04:00
|
|
|
|
2009-06-12 11:34:35 +04:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
2007-07-11 13:57:59 +04:00
|
|
|
NS_ENSURE_ARG(aValue);
|
|
|
|
|
2018-11-20 04:20:05 +03:00
|
|
|
uint16_t dataType = aValue->GetDataType();
|
2018-07-31 14:40:55 +03:00
|
|
|
BookmarkData bookmark;
|
2007-07-11 13:57:59 +04:00
|
|
|
|
|
|
|
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: {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t valueInt;
|
2018-11-20 04:20:05 +03:00
|
|
|
nsresult rv = aValue->GetAsInt32(&valueInt);
|
2009-12-18 13:30:37 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2007-07-11 13:57:59 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2018-08-01 12:47:24 +03:00
|
|
|
rv = SetAnnotationInt32Internal(aItemId, &bookmark, aName, valueInt,
|
2018-07-31 14:40:55 +03:00
|
|
|
aFlags, aExpiration);
|
2007-07-11 13:57:59 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2018-07-31 14:40:55 +03:00
|
|
|
break;
|
2007-07-11 13:57:59 +04:00
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
// Fall through int64_t case otherwise.
|
2015-11-23 00:59:54 +03:00
|
|
|
MOZ_FALLTHROUGH;
|
2007-07-11 13:57:59 +04:00
|
|
|
}
|
|
|
|
case nsIDataType::VTYPE_INT64:
|
|
|
|
case nsIDataType::VTYPE_UINT64: {
|
2012-08-22 19:56:38 +04:00
|
|
|
int64_t valueLong;
|
2018-11-20 04:20:05 +03:00
|
|
|
nsresult rv = aValue->GetAsInt64(&valueLong);
|
2009-12-18 13:30:37 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2007-07-11 13:57:59 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2018-08-01 12:47:24 +03:00
|
|
|
rv = SetAnnotationInt64Internal(aItemId, &bookmark, aName, valueLong,
|
2018-07-31 14:40:55 +03:00
|
|
|
aFlags, aExpiration);
|
2007-07-11 13:57:59 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2018-07-31 14:40:55 +03:00
|
|
|
break;
|
2007-07-11 13:57:59 +04:00
|
|
|
}
|
2009-12-18 13:30:37 +03:00
|
|
|
// Fall through double case otherwise.
|
2015-11-23 00:59:54 +03:00
|
|
|
MOZ_FALLTHROUGH;
|
2007-07-11 13:57:59 +04:00
|
|
|
}
|
|
|
|
case nsIDataType::VTYPE_FLOAT:
|
|
|
|
case nsIDataType::VTYPE_DOUBLE: {
|
|
|
|
double valueDouble;
|
2018-11-20 04:20:05 +03:00
|
|
|
nsresult rv = aValue->GetAsDouble(&valueDouble);
|
2007-07-11 13:57:59 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2018-08-01 12:47:24 +03:00
|
|
|
rv = SetAnnotationDoubleInternal(aItemId, &bookmark, aName, valueDouble,
|
2018-07-31 14:40:55 +03:00
|
|
|
aFlags, aExpiration);
|
2007-07-11 13:57:59 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2018-07-31 14:40:55 +03:00
|
|
|
break;
|
2007-07-11 13:57:59 +04:00
|
|
|
}
|
|
|
|
case nsIDataType::VTYPE_CHAR:
|
|
|
|
case nsIDataType::VTYPE_WCHAR:
|
|
|
|
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;
|
2018-11-20 04:20:05 +03:00
|
|
|
nsresult rv = aValue->GetAsAString(stringValue);
|
2007-07-11 13:57:59 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2018-08-01 12:47:24 +03:00
|
|
|
rv = SetAnnotationStringInternal(aItemId, &bookmark, aName, stringValue,
|
2018-07-31 14:40:55 +03:00
|
|
|
aFlags, aExpiration);
|
2007-07-11 13:57:59 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2018-07-31 14:40:55 +03:00
|
|
|
break;
|
2007-07-11 13:57:59 +04:00
|
|
|
}
|
2018-07-31 14:40:55 +03:00
|
|
|
default:
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2007-07-11 13:57:59 +04:00
|
|
|
}
|
|
|
|
|
2007-05-10 12:05:19 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-08-01 12:47:24 +03:00
|
|
|
nsresult nsAnnotationService::SetAnnotationInt32Internal(
|
2007-05-10 12:05:19 +04:00
|
|
|
int64_t aItemId, BookmarkData* aBookmark, const nsACString& aName,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aValue, int32_t aFlags, uint16_t aExpiration) {
|
2011-10-27 13:11:34 +04:00
|
|
|
mozStorageTransaction transaction(mDB->MainConn(), false);
|
|
|
|
nsCOMPtr<mozIStorageStatement> statement;
|
2018-08-01 12:47:24 +03:00
|
|
|
nsresult rv =
|
|
|
|
StartSetAnnotation(aItemId, aBookmark, aName, aFlags, aExpiration,
|
2017-11-18 03:48:42 +03:00
|
|
|
nsIAnnotationService::TYPE_INT32, statement);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2017-11-17 03:49:03 +03:00
|
|
|
|
2017-11-18 03:48:42 +03:00
|
|
|
mozStorageStatementScoper scoper(statement);
|
2009-12-18 13:30:37 +03:00
|
|
|
|
2017-11-18 03:48:42 +03:00
|
|
|
rv = statement->BindInt32ByName(NS_LITERAL_CSTRING("content"), aValue);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = statement->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = transaction.Commit();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
2006-07-18 20:48:10 +04:00
|
|
|
}
|
|
|
|
|
2018-08-01 12:47:24 +03:00
|
|
|
nsresult nsAnnotationService::SetAnnotationInt64Internal(
|
2007-05-10 12:05:19 +04:00
|
|
|
int64_t aItemId, BookmarkData* aBookmark, const nsACString& aName,
|
2012-08-22 19:56:38 +04:00
|
|
|
int64_t aValue, int32_t aFlags, uint16_t aExpiration) {
|
2011-10-27 13:11:34 +04:00
|
|
|
mozStorageTransaction transaction(mDB->MainConn(), false);
|
|
|
|
nsCOMPtr<mozIStorageStatement> statement;
|
2018-08-01 12:47:24 +03:00
|
|
|
nsresult rv =
|
|
|
|
StartSetAnnotation(aItemId, aBookmark, aName, aFlags, aExpiration,
|
2017-11-18 03:48:42 +03:00
|
|
|
nsIAnnotationService::TYPE_INT64, statement);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2017-11-17 03:49:03 +03:00
|
|
|
|
2017-11-18 03:48:42 +03:00
|
|
|
mozStorageStatementScoper scoper(statement);
|
2009-12-18 13:30:37 +03:00
|
|
|
|
2017-11-18 03:48:42 +03:00
|
|
|
rv = statement->BindInt64ByName(NS_LITERAL_CSTRING("content"), aValue);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = statement->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = transaction.Commit();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
2006-07-18 20:50:42 +04:00
|
|
|
}
|
|
|
|
|
2018-08-01 12:47:24 +03:00
|
|
|
nsresult nsAnnotationService::SetAnnotationDoubleInternal(
|
2007-05-10 12:05:19 +04:00
|
|
|
int64_t aItemId, BookmarkData* aBookmark, const nsACString& aName,
|
2012-08-22 19:56:38 +04:00
|
|
|
double aValue, int32_t aFlags, uint16_t aExpiration) {
|
2011-10-27 13:11:34 +04:00
|
|
|
mozStorageTransaction transaction(mDB->MainConn(), false);
|
|
|
|
nsCOMPtr<mozIStorageStatement> statement;
|
2018-08-01 12:47:24 +03:00
|
|
|
nsresult rv =
|
|
|
|
StartSetAnnotation(aItemId, aBookmark, aName, aFlags, aExpiration,
|
2017-11-18 03:48:42 +03:00
|
|
|
nsIAnnotationService::TYPE_DOUBLE, statement);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2017-11-17 03:49:03 +03:00
|
|
|
|
2017-11-18 03:48:42 +03:00
|
|
|
mozStorageStatementScoper scoper(statement);
|
2009-12-18 13:30:37 +03:00
|
|
|
|
2017-11-18 03:48:42 +03:00
|
|
|
rv = statement->BindDoubleByName(NS_LITERAL_CSTRING("content"), aValue);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = statement->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = transaction.Commit();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
2006-07-18 20:48:10 +04:00
|
|
|
}
|
|
|
|
|
2018-03-28 23:05:27 +03:00
|
|
|
nsresult nsAnnotationService::GetValueFromStatement(
|
|
|
|
nsCOMPtr<mozIStorageStatement>& aStatement, nsIVariant** _retval) {
|
|
|
|
nsresult rv;
|
2009-12-18 13:30:37 +03:00
|
|
|
|
2007-07-11 13:57:59 +04:00
|
|
|
nsCOMPtr<nsIWritableVariant> value = new nsVariant();
|
2018-03-28 23:05:27 +03:00
|
|
|
int32_t type = aStatement->AsInt32(kAnnoIndex_Type);
|
2007-07-11 13:57:59 +04:00
|
|
|
switch (type) {
|
|
|
|
case nsIAnnotationService::TYPE_INT32:
|
|
|
|
case nsIAnnotationService::TYPE_INT64:
|
|
|
|
case nsIAnnotationService::TYPE_DOUBLE: {
|
2018-03-28 23:05:27 +03:00
|
|
|
rv = value->SetAsDouble(aStatement->AsDouble(kAnnoIndex_Content));
|
2007-07-11 13:57:59 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case nsIAnnotationService::TYPE_STRING: {
|
|
|
|
nsAutoString valueString;
|
2018-03-28 23:05:27 +03:00
|
|
|
rv = aStatement->GetString(kAnnoIndex_Content, valueString);
|
2007-07-11 13:57:59 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) rv = value->SetAsAString(valueString);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
rv = NS_ERROR_UNEXPECTED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-03-31 17:03:49 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
value.forget(_retval);
|
|
|
|
}
|
2007-07-11 13:57:59 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2018-03-28 23:05:27 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAnnotationService::GetItemAnnotation(int64_t aItemId, const nsACString& aName,
|
|
|
|
nsIVariant** _retval) {
|
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
|
|
|
|
nsCOMPtr<mozIStorageStatement> statement;
|
2018-08-23 12:59:50 +03:00
|
|
|
nsresult rv = StartGetAnnotation(aItemId, aName, statement);
|
2018-03-28 23:05:27 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
mozStorageStatementScoper scoper(statement);
|
|
|
|
|
|
|
|
return GetValueFromStatement(statement, _retval);
|
|
|
|
}
|
|
|
|
|
2009-12-18 13:30:37 +03: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.
|
|
|
|
*/
|
2018-08-01 12:47:24 +03:00
|
|
|
nsresult nsAnnotationService::RemoveAnnotationInternal(
|
2007-05-10 12:05:19 +04:00
|
|
|
int64_t aItemId, BookmarkData* aBookmark, const nsACString& aName) {
|
2011-10-27 13:11:34 +04:00
|
|
|
nsCOMPtr<mozIStorageStatement> statement;
|
2018-08-01 12:47:24 +03:00
|
|
|
statement = mDB->GetStatement(
|
|
|
|
"DELETE FROM moz_items_annos "
|
|
|
|
"WHERE item_id = :item_id "
|
|
|
|
"AND anno_attribute_id = "
|
|
|
|
"(SELECT id FROM moz_anno_attributes WHERE name = :anno_name)");
|
2017-11-18 03:48:42 +03:00
|
|
|
NS_ENSURE_STATE(statement);
|
2009-12-18 13:30:37 +03:00
|
|
|
mozStorageStatementScoper scoper(statement);
|
2006-07-18 20:50:42 +04:00
|
|
|
|
2009-12-18 13:30:37 +03:00
|
|
|
nsresult rv;
|
2018-08-01 12:47:24 +03:00
|
|
|
rv = statement->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2017-11-18 03:48:42 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 20:50:42 +04:00
|
|
|
|
2010-04-27 15:24:58 +04:00
|
|
|
rv = statement->BindUTF8StringByName(NS_LITERAL_CSTRING("anno_name"), aName);
|
2017-11-18 03:48:42 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 20:50:42 +04:00
|
|
|
|
2007-05-10 12:05:19 +04:00
|
|
|
rv = statement->Execute();
|
2017-11-18 03:48:42 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 20:50:42 +04:00
|
|
|
|
2018-08-01 12:47:24 +03:00
|
|
|
nsNavBookmarks* bookmarks = nsNavBookmarks::GetBookmarksService();
|
|
|
|
if (bookmarks) {
|
|
|
|
MOZ_ASSERT(aBookmark);
|
|
|
|
if (NS_FAILED(bookmarks->FetchItemInfo(aItemId, *aBookmark))) {
|
|
|
|
aBookmark->id = -1;
|
2017-11-17 03:49:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-18 03:48:42 +03:00
|
|
|
return NS_OK;
|
2007-05-10 12:05:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsAnnotationService::RemoveItemAnnotation(int64_t aItemId,
|
2016-08-11 23:13:22 +03:00
|
|
|
const nsACString& aName,
|
|
|
|
uint16_t aSource) {
|
2009-06-12 11:34:35 +04:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
|
|
|
|
2017-11-17 03:49:03 +03:00
|
|
|
BookmarkData bookmark;
|
2018-08-01 12:47:24 +03:00
|
|
|
nsresult rv = RemoveAnnotationInternal(aItemId, &bookmark, aName);
|
2017-11-18 03:48:42 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-05-10 12:05:19 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-07-18 20:48:10 +04:00
|
|
|
|
2018-08-01 00:34:42 +03:00
|
|
|
nsresult nsAnnotationService::RemoveItemAnnotations(int64_t aItemId) {
|
2009-06-12 11:34:35 +04:00
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
|
|
|
|
2009-12-18 13:30:37 +03:00
|
|
|
// Should this be precompiled or a getter?
|
2011-10-27 13:11:34 +04:00
|
|
|
nsCOMPtr<mozIStorageStatement> statement =
|
|
|
|
mDB->GetStatement("DELETE FROM moz_items_annos WHERE item_id = :item_id");
|
|
|
|
NS_ENSURE_STATE(statement);
|
|
|
|
mozStorageStatementScoper scoper(statement);
|
|
|
|
|
|
|
|
nsresult rv =
|
|
|
|
statement->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2007-05-10 12:05:19 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = statement->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-07-12 17:48:17 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAnnotationService::ItemHasAnnotation(int64_t aItemId, const nsACString& aName,
|
|
|
|
bool* _hasAnno) {
|
|
|
|
NS_ENSURE_ARG_MIN(aItemId, 1);
|
|
|
|
NS_ENSURE_ARG_POINTER(_hasAnno);
|
|
|
|
|
|
|
|
nsCOMPtr<mozIStorageStatement> stmt = mDB->GetStatement(
|
|
|
|
"SELECT b.id, "
|
|
|
|
"(SELECT id FROM moz_anno_attributes WHERE name = :anno_name) AS nameid, "
|
|
|
|
"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 "
|
|
|
|
"WHERE b.id = :item_id");
|
2009-12-18 13:30:40 +03:00
|
|
|
NS_ENSURE_STATE(stmt);
|
2009-12-18 13:30:37 +03:00
|
|
|
mozStorageStatementScoper checkAnnoScoper(stmt);
|
2006-07-18 20:48:10 +04:00
|
|
|
|
2010-04-27 15:24:58 +04:00
|
|
|
nsresult rv =
|
|
|
|
stmt->BindUTF8StringByName(NS_LITERAL_CSTRING("anno_name"), aName);
|
2006-07-18 20:48:10 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2018-07-12 17:48:17 +03:00
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2006-07-18 20:48:10 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool hasResult;
|
2009-12-18 13:30:37 +03:00
|
|
|
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.
|
2011-10-17 18:59:28 +04:00
|
|
|
*_hasAnno = false;
|
2009-12-18 13:30:37 +03:00
|
|
|
} else {
|
2012-08-22 19:56:38 +04:00
|
|
|
int64_t annotationId = stmt->AsInt64(2);
|
2009-12-18 13:30:37 +03:00
|
|
|
*_hasAnno = (annotationId > 0);
|
|
|
|
}
|
2006-07-18 20:48:10 +04:00
|
|
|
|
2009-12-18 13:30:37 +03:00
|
|
|
return NS_OK;
|
2006-07-18 20:48:10 +04:00
|
|
|
}
|
|
|
|
|
2009-12-18 13:30:37 +03: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 20:48:10 +04:00
|
|
|
|
2018-08-23 12:59:50 +03:00
|
|
|
nsresult nsAnnotationService::StartGetAnnotation(
|
2009-12-18 13:30:37 +03:00
|
|
|
int64_t aItemId, const nsACString& aName,
|
2011-10-27 13:11:34 +04:00
|
|
|
nsCOMPtr<mozIStorageStatement>& aStatement) {
|
2018-08-23 12:59:50 +03:00
|
|
|
aStatement = mDB->GetStatement(
|
|
|
|
"SELECT a.id, a.item_id, :anno_name, a.content, a.flags, "
|
|
|
|
"a.expiration, a.type "
|
|
|
|
"FROM moz_anno_attributes n "
|
|
|
|
"JOIN moz_items_annos a ON a.anno_attribute_id = n.id "
|
|
|
|
"WHERE a.item_id = :item_id "
|
|
|
|
"AND n.name = :anno_name");
|
2011-10-27 13:11:34 +04:00
|
|
|
NS_ENSURE_STATE(aStatement);
|
|
|
|
mozStorageStatementScoper getAnnoScoper(aStatement);
|
2006-07-18 20:48:10 +04:00
|
|
|
|
2007-05-10 12:05:19 +04:00
|
|
|
nsresult rv;
|
2018-08-23 12:59:50 +03:00
|
|
|
rv = aStatement->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2007-05-10 12:05:19 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-12-18 13:30:37 +03:00
|
|
|
|
2011-10-27 13:11:34 +04:00
|
|
|
rv = aStatement->BindUTF8StringByName(NS_LITERAL_CSTRING("anno_name"), aName);
|
2007-05-10 12:05:19 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool hasResult = false;
|
2011-10-27 13:11:34 +04:00
|
|
|
rv = aStatement->ExecuteStep(&hasResult);
|
2009-12-18 13:30:37 +03:00
|
|
|
if (NS_FAILED(rv) || !hasResult) return NS_ERROR_NOT_AVAILABLE;
|
2007-05-10 12:05:19 +04:00
|
|
|
|
|
|
|
// on success, DON'T reset the statement, the caller needs to read from it,
|
2009-12-18 13:30:37 +03:00
|
|
|
// and it is the caller's job to reset it.
|
|
|
|
getAnnoScoper.Abandon();
|
|
|
|
|
2007-05-10 12:05:19 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-12-18 13:30:37 +03:00
|
|
|
/**
|
|
|
|
* This does most of the setup work needed to set an annotation, except for
|
2013-08-03 15:06:47 +04:00
|
|
|
* binding the the actual value and executing the statement.
|
2009-12-18 13:30:37 +03:00
|
|
|
* 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.
|
|
|
|
*/
|
2018-08-01 12:47:24 +03:00
|
|
|
nsresult nsAnnotationService::StartSetAnnotation(
|
2006-07-18 20:48:10 +04:00
|
|
|
int64_t aItemId, BookmarkData* aBookmark, const nsACString& aName,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aFlags, uint16_t aExpiration, uint16_t aType,
|
2011-10-27 13:11:34 +04:00
|
|
|
nsCOMPtr<mozIStorageStatement>& aStatement) {
|
2018-07-25 19:40:30 +03:00
|
|
|
MOZ_ASSERT(aExpiration == EXPIRE_NEVER, "Only EXPIRE_NEVER is supported");
|
|
|
|
NS_ENSURE_ARG(aExpiration == EXPIRE_NEVER);
|
2007-06-26 05:08:54 +04:00
|
|
|
|
2009-12-18 13:30:37 +03:00
|
|
|
// Ensure the annotation name exists.
|
2011-10-27 13:11:34 +04:00
|
|
|
nsCOMPtr<mozIStorageStatement> addNameStmt = mDB->GetStatement(
|
|
|
|
"INSERT OR IGNORE INTO moz_anno_attributes (name) VALUES (:anno_name)");
|
2017-11-18 03:48:42 +03:00
|
|
|
NS_ENSURE_STATE(addNameStmt);
|
2011-10-27 13:11:34 +04:00
|
|
|
mozStorageStatementScoper scoper(addNameStmt);
|
|
|
|
|
2010-04-27 15:24:58 +04:00
|
|
|
nsresult rv =
|
|
|
|
addNameStmt->BindUTF8StringByName(NS_LITERAL_CSTRING("anno_name"), aName);
|
2017-11-18 03:48:42 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-12-18 13:30:40 +03:00
|
|
|
rv = addNameStmt->Execute();
|
2017-11-18 03:48:42 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 20:48:10 +04:00
|
|
|
|
2009-12-18 13:30:37 +03: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.
|
2018-08-01 12:47:24 +03:00
|
|
|
nsCOMPtr<mozIStorageStatement> stmt = mDB->GetStatement(
|
|
|
|
"SELECT b.id, "
|
|
|
|
"(SELECT id FROM moz_anno_attributes WHERE name = :anno_name) AS nameid, "
|
|
|
|
"a.id, a.dateAdded, b.parent, b.type, b.lastModified, b.guid, p.guid "
|
|
|
|
"FROM moz_bookmarks b "
|
|
|
|
"JOIN moz_bookmarks p ON p.id = b.parent "
|
|
|
|
"LEFT JOIN moz_items_annos a ON a.item_id = b.id "
|
|
|
|
"AND a.anno_attribute_id = nameid "
|
|
|
|
"WHERE b.id = :item_id");
|
2017-11-18 03:48:42 +03:00
|
|
|
NS_ENSURE_STATE(stmt);
|
2009-12-18 13:30:37 +03:00
|
|
|
mozStorageStatementScoper checkAnnoScoper(stmt);
|
2011-10-27 13:11:34 +04:00
|
|
|
|
2010-04-27 15:24:58 +04:00
|
|
|
rv = stmt->BindUTF8StringByName(NS_LITERAL_CSTRING("anno_name"), aName);
|
2017-11-18 03:48:42 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2018-08-01 12:47:24 +03:00
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
|
2017-11-18 03:48:42 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 20:52:37 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool hasResult;
|
2009-12-18 13:30:37 +03:00
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
2017-11-18 03:48:42 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-12-18 13:30:37 +03:00
|
|
|
if (!hasResult) {
|
|
|
|
// We are trying to create an annotation on an invalid bookmark
|
|
|
|
// or history entry.
|
2017-11-18 03:48:42 +03:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
2009-12-18 13:30:37 +03:00
|
|
|
}
|
2006-07-18 20:52:37 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int64_t fkId = stmt->AsInt64(0);
|
|
|
|
int64_t nameID = stmt->AsInt64(1);
|
|
|
|
int64_t oldAnnoId = stmt->AsInt64(2);
|
|
|
|
int64_t oldAnnoDate = stmt->AsInt64(3);
|
2008-08-17 02:28:28 +04:00
|
|
|
|
2018-08-01 12:47:24 +03:00
|
|
|
aStatement = mDB->GetStatement(
|
|
|
|
"INSERT OR REPLACE INTO moz_items_annos "
|
|
|
|
"(id, item_id, anno_attribute_id, content, flags, "
|
|
|
|
"expiration, type, dateAdded, lastModified) "
|
|
|
|
"VALUES (:id, :fk, :name_id, :content, :flags, "
|
|
|
|
":expiration, :type, :date_added, :last_modified)");
|
2017-11-17 03:49:03 +03:00
|
|
|
|
2018-08-01 12:47:24 +03:00
|
|
|
// Since we're already querying `moz_bookmarks`, we fetch the changed
|
|
|
|
// bookmark's info here, instead of using `FetchItemInfo`.
|
|
|
|
MOZ_ASSERT(aBookmark);
|
|
|
|
aBookmark->id = fkId;
|
|
|
|
aBookmark->parentId = stmt->AsInt64(4);
|
|
|
|
aBookmark->type = stmt->AsInt64(5);
|
|
|
|
|
|
|
|
aBookmark->lastModified = static_cast<PRTime>(stmt->AsInt64(6));
|
|
|
|
if (NS_FAILED(stmt->GetUTF8String(7, aBookmark->guid)) ||
|
|
|
|
NS_FAILED(stmt->GetUTF8String(8, aBookmark->parentGuid))) {
|
|
|
|
aBookmark->id = -1;
|
2011-10-27 13:11:34 +04:00
|
|
|
}
|
2017-11-18 03:48:42 +03:00
|
|
|
NS_ENSURE_STATE(aStatement);
|
2011-10-27 13:11:34 +04:00
|
|
|
mozStorageStatementScoper setAnnoScoper(aStatement);
|
2008-08-17 02:28:28 +04:00
|
|
|
|
2009-12-18 13:30:37 +03:00
|
|
|
// Don't replace existing annotations.
|
|
|
|
if (oldAnnoId > 0) {
|
2011-10-27 13:11:34 +04:00
|
|
|
rv = aStatement->BindInt64ByName(NS_LITERAL_CSTRING("id"), oldAnnoId);
|
2017-11-18 03:48:42 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-10-27 13:11:34 +04:00
|
|
|
rv = aStatement->BindInt64ByName(NS_LITERAL_CSTRING("date_added"),
|
|
|
|
oldAnnoDate);
|
2017-11-18 03:48:42 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-12-18 13:30:37 +03:00
|
|
|
} else {
|
2011-10-27 13:11:34 +04:00
|
|
|
rv = aStatement->BindNullByName(NS_LITERAL_CSTRING("id"));
|
2017-11-18 03:48:42 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2014-12-05 01:09:48 +03:00
|
|
|
rv = aStatement->BindInt64ByName(NS_LITERAL_CSTRING("date_added"),
|
|
|
|
RoundedPRNow());
|
2017-11-18 03:48:42 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-12-18 13:30:37 +03:00
|
|
|
}
|
|
|
|
|
2011-10-27 13:11:34 +04:00
|
|
|
rv = aStatement->BindInt64ByName(NS_LITERAL_CSTRING("fk"), fkId);
|
2017-11-18 03:48:42 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-10-27 13:11:34 +04:00
|
|
|
rv = aStatement->BindInt64ByName(NS_LITERAL_CSTRING("name_id"), nameID);
|
2017-11-18 03:48:42 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-08-03 15:06:47 +04:00
|
|
|
|
2011-10-27 13:11:34 +04:00
|
|
|
rv = aStatement->BindInt32ByName(NS_LITERAL_CSTRING("flags"), aFlags);
|
2017-11-18 03:48:42 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-10-27 13:11:34 +04:00
|
|
|
rv = aStatement->BindInt32ByName(NS_LITERAL_CSTRING("expiration"),
|
|
|
|
aExpiration);
|
2017-11-18 03:48:42 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-10-27 13:11:34 +04:00
|
|
|
rv = aStatement->BindInt32ByName(NS_LITERAL_CSTRING("type"), aType);
|
2017-11-18 03:48:42 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2014-12-05 01:09:48 +03:00
|
|
|
rv = aStatement->BindInt64ByName(NS_LITERAL_CSTRING("last_modified"),
|
|
|
|
RoundedPRNow());
|
2017-11-18 03:48:42 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 20:48:10 +04:00
|
|
|
|
2013-08-03 15:06:47 +04:00
|
|
|
// On success, leave the statement open, the caller will set the value
|
|
|
|
// and execute the statement.
|
2009-12-18 13:30:37 +03:00
|
|
|
setAnnoScoper.Abandon();
|
2007-05-10 12:05:19 +04:00
|
|
|
|
2017-11-18 03:48:42 +03:00
|
|
|
return NS_OK;
|
2007-05-10 12:05:19 +04:00
|
|
|
}
|