2007-03-22 10:30:00 -07:00
|
|
|
//* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef nsAnnotationService_h___
|
|
|
|
#define nsAnnotationService_h___
|
|
|
|
|
|
|
|
#include "nsIAnnotationService.h"
|
2007-05-10 01:05:19 -07:00
|
|
|
#include "nsTArray.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCOMArray.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
2011-10-27 02:11:47 -07:00
|
|
|
#include "nsWeakReference.h"
|
2009-12-01 05:00:45 -08:00
|
|
|
#include "nsToolkitCompsCID.h"
|
2011-10-27 02:11:34 -07:00
|
|
|
#include "Database.h"
|
2011-10-28 00:35:45 -07:00
|
|
|
#include "nsString.h"
|
2012-06-19 20:58:39 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-12-21 06:19:04 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace places {
|
|
|
|
|
|
|
|
class AnnotatedResult MOZ_FINAL : public mozIAnnotatedResult
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_MOZIANNOTATEDRESULT
|
|
|
|
|
|
|
|
AnnotatedResult(const nsCString& aGUID, nsIURI* aURI, int64_t aItemd,
|
|
|
|
const nsACString& aAnnotationName,
|
|
|
|
nsIVariant* aAnnotationValue);
|
|
|
|
|
|
|
|
private:
|
|
|
|
const nsCString mGUID;
|
|
|
|
nsCOMPtr<nsIURI> mURI;
|
|
|
|
const int64_t mItemId;
|
|
|
|
const nsCString mAnnotationName;
|
|
|
|
nsCOMPtr<nsIVariant> mAnnotationValue;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace places
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2012-06-19 20:58:39 -07:00
|
|
|
class nsAnnotationService MOZ_FINAL : public nsIAnnotationService
|
|
|
|
, public nsIObserver
|
|
|
|
, public nsSupportsWeakReference
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
2011-10-27 02:11:47 -07:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIANNOTATIONSERVICE
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAnnotationService();
|
|
|
|
|
2009-12-01 05:00:45 -08:00
|
|
|
/**
|
|
|
|
* Obtains the service's object.
|
|
|
|
*/
|
2009-12-18 02:30:37 -08:00
|
|
|
static nsAnnotationService* GetSingleton();
|
2009-12-01 05:00:45 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the service's object. This should only be called once.
|
|
|
|
*/
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult Init();
|
|
|
|
|
2011-09-21 11:14:40 -07:00
|
|
|
static nsAnnotationService* GetAnnotationServiceIfAvailable() {
|
|
|
|
return gAnnotationService;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Returns a cached pointer to the annotation service for consumers in the
|
|
|
|
* places directory.
|
|
|
|
*/
|
2009-12-18 02:30:37 -08:00
|
|
|
static nsAnnotationService* GetAnnotationService()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-12-01 05:00:45 -08:00
|
|
|
if (!gAnnotationService) {
|
|
|
|
nsCOMPtr<nsIAnnotationService> serv =
|
|
|
|
do_GetService(NS_ANNOTATIONSERVICE_CONTRACTID);
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ENSURE_TRUE(serv, nullptr);
|
2009-12-01 05:00:45 -08:00
|
|
|
NS_ASSERTION(gAnnotationService,
|
|
|
|
"Should have static instance pointer now");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return gAnnotationService;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
~nsAnnotationService();
|
|
|
|
|
|
|
|
protected:
|
2011-10-27 02:11:34 -07:00
|
|
|
nsRefPtr<mozilla::places::Database> mDB;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMArray<nsIAnnotationObserver> mObservers;
|
2011-10-27 02:11:47 -07:00
|
|
|
bool mHasSessionAnnotations;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-12-18 02:30:37 -08:00
|
|
|
static nsAnnotationService* gAnnotationService;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
static const int kAnnoIndex_ID;
|
2007-05-10 01:05:19 -07:00
|
|
|
static const int kAnnoIndex_PageOrItem;
|
2009-12-18 02:30:37 -08:00
|
|
|
static const int kAnnoIndex_NameID;
|
2007-03-22 10:30:00 -07:00
|
|
|
static const int kAnnoIndex_MimeType;
|
|
|
|
static const int kAnnoIndex_Content;
|
|
|
|
static const int kAnnoIndex_Flags;
|
|
|
|
static const int kAnnoIndex_Expiration;
|
2007-04-22 14:48:52 -07:00
|
|
|
static const int kAnnoIndex_Type;
|
2007-07-26 09:23:11 -07:00
|
|
|
static const int kAnnoIndex_DateAdded;
|
|
|
|
static const int kAnnoIndex_LastModified;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-12-18 02:30:37 -08:00
|
|
|
nsresult HasAnnotationInternal(nsIURI* aURI,
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t aItemId,
|
2009-12-18 02:30:37 -08:00
|
|
|
const nsACString& aName,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* _hasAnno);
|
2009-12-18 02:30:37 -08:00
|
|
|
|
|
|
|
nsresult StartGetAnnotation(nsIURI* aURI,
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t aItemId,
|
2009-12-18 02:30:37 -08:00
|
|
|
const nsACString& aName,
|
2011-10-27 02:11:34 -07:00
|
|
|
nsCOMPtr<mozIStorageStatement>& aStatement);
|
2009-12-18 02:30:37 -08:00
|
|
|
|
|
|
|
nsresult StartSetAnnotation(nsIURI* aURI,
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t aItemId,
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsACString& aName,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aFlags,
|
|
|
|
uint16_t aExpiration,
|
|
|
|
uint16_t aType,
|
2011-10-27 02:11:34 -07:00
|
|
|
nsCOMPtr<mozIStorageStatement>& aStatement);
|
2009-12-18 02:30:37 -08:00
|
|
|
|
|
|
|
nsresult SetAnnotationStringInternal(nsIURI* aURI,
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t aItemId,
|
2007-05-10 01:05:19 -07:00
|
|
|
const nsACString& aName,
|
|
|
|
const nsAString& aValue,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aFlags,
|
|
|
|
uint16_t aExpiration);
|
2009-12-18 02:30:37 -08:00
|
|
|
nsresult SetAnnotationInt32Internal(nsIURI* aURI,
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t aItemId,
|
2007-05-10 01:05:19 -07:00
|
|
|
const nsACString& aName,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aValue,
|
|
|
|
int32_t aFlags,
|
|
|
|
uint16_t aExpiration);
|
2009-12-18 02:30:37 -08:00
|
|
|
nsresult SetAnnotationInt64Internal(nsIURI* aURI,
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t aItemId,
|
2007-05-10 01:05:19 -07:00
|
|
|
const nsACString& aName,
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t aValue,
|
|
|
|
int32_t aFlags,
|
|
|
|
uint16_t aExpiration);
|
2009-12-18 02:30:37 -08:00
|
|
|
nsresult SetAnnotationDoubleInternal(nsIURI* aURI,
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t aItemId,
|
2007-05-10 01:05:19 -07:00
|
|
|
const nsACString& aName,
|
|
|
|
double aValue,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aFlags,
|
|
|
|
uint16_t aExpiration);
|
2009-12-18 02:30:37 -08:00
|
|
|
nsresult SetAnnotationBinaryInternal(nsIURI* aURI,
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t aItemId,
|
2007-05-10 01:05:19 -07:00
|
|
|
const nsACString& aName,
|
2012-08-22 08:56:38 -07:00
|
|
|
const uint8_t* aData,
|
|
|
|
uint32_t aDataLen,
|
2007-05-10 01:05:19 -07:00
|
|
|
const nsACString& aMimeType,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aFlags,
|
|
|
|
uint16_t aExpiration);
|
2009-12-18 02:30:37 -08:00
|
|
|
|
|
|
|
nsresult RemoveAnnotationInternal(nsIURI* aURI,
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t aItemId,
|
2007-05-10 01:05:19 -07:00
|
|
|
const nsACString& aName);
|
|
|
|
|
2007-05-31 17:35:49 -07:00
|
|
|
public:
|
2007-05-10 01:05:19 -07:00
|
|
|
nsresult GetPagesWithAnnotationCOMArray(const nsACString& aName,
|
2009-12-18 02:30:37 -08:00
|
|
|
nsCOMArray<nsIURI>* _results);
|
2007-05-10 01:05:19 -07:00
|
|
|
nsresult GetItemsWithAnnotationTArray(const nsACString& aName,
|
2012-08-22 08:56:38 -07:00
|
|
|
nsTArray<int64_t>* _result);
|
2009-12-18 02:30:37 -08:00
|
|
|
nsresult GetAnnotationNamesTArray(nsIURI* aURI,
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t aItemId,
|
2009-12-18 02:30:37 -08:00
|
|
|
nsTArray<nsCString>* _result);
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* nsAnnotationService_h___ */
|