2007-03-22 10:30:00 -07:00
|
|
|
//* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is 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)
|
2009-12-18 02:30:37 -08:00
|
|
|
* Marco Bonardo <mak77@bonardo.net>
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#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 "mozIStorageService.h"
|
|
|
|
#include "mozIStorageConnection.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
2009-12-01 05:00:45 -08:00
|
|
|
#include "nsToolkitCompsCID.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class nsAnnotationService : public nsIAnnotationService
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
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();
|
|
|
|
|
|
|
|
static nsresult InitTables(mozIStorageConnection* aDBConn);
|
|
|
|
|
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);
|
|
|
|
NS_ENSURE_TRUE(serv, nsnull);
|
|
|
|
NS_ASSERTION(gAnnotationService,
|
|
|
|
"Should have static instance pointer now");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return gAnnotationService;
|
|
|
|
}
|
|
|
|
|
2008-11-13 22:45:49 -08:00
|
|
|
/**
|
|
|
|
* Finalize all internal statements.
|
|
|
|
*/
|
|
|
|
nsresult FinalizeStatements();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIANNOTATIONSERVICE
|
|
|
|
|
|
|
|
private:
|
|
|
|
~nsAnnotationService();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsCOMPtr<mozIStorageService> mDBService;
|
|
|
|
nsCOMPtr<mozIStorageConnection> mDBConn;
|
|
|
|
|
2009-12-18 02:30:40 -08:00
|
|
|
/**
|
|
|
|
* Always use this getter and never use directly the statement nsCOMPtr.
|
|
|
|
*/
|
|
|
|
mozIStorageStatement* GetStatement(const nsCOMPtr<mozIStorageStatement>& aStmt);
|
2009-12-18 02:30:37 -08:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBGetAnnotationsForPage;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mDBGetAnnotationsForItem;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mDBGetPageAnnotationValue;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mDBGetItemAnnotationValue;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBAddAnnotationName;
|
2009-12-18 02:30:37 -08:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBAddPageAnnotation;
|
2007-05-10 01:05:19 -07:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBAddItemAnnotation;
|
2009-12-18 02:30:37 -08:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBRemovePageAnnotation;
|
2007-05-10 01:05:19 -07:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBRemoveItemAnnotation;
|
2009-12-18 02:30:37 -08:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBGetPagesWithAnnotation;
|
2007-12-04 08:46:40 -08:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBGetItemsWithAnnotation;
|
2009-12-18 02:30:37 -08:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBCheckPageAnnotation;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mDBCheckItemAnnotation;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMArray<nsIAnnotationObserver> mObservers;
|
|
|
|
|
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,
|
|
|
|
PRInt64 aItemId,
|
|
|
|
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,
|
|
|
|
PRInt64 aItemId,
|
|
|
|
const nsACString& aName,
|
|
|
|
mozIStorageStatement** _statement);
|
|
|
|
|
|
|
|
nsresult StartSetAnnotation(nsIURI* aURI,
|
|
|
|
PRInt64 aItemId,
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsACString& aName,
|
2007-05-10 01:05:19 -07:00
|
|
|
PRInt32 aFlags,
|
|
|
|
PRUint16 aExpiration,
|
|
|
|
PRUint16 aType,
|
2009-12-18 02:30:37 -08:00
|
|
|
mozIStorageStatement** _statement);
|
|
|
|
|
|
|
|
nsresult SetAnnotationStringInternal(nsIURI* aURI,
|
|
|
|
PRInt64 aItemId,
|
2007-05-10 01:05:19 -07:00
|
|
|
const nsACString& aName,
|
|
|
|
const nsAString& aValue,
|
|
|
|
PRInt32 aFlags,
|
|
|
|
PRUint16 aExpiration);
|
2009-12-18 02:30:37 -08:00
|
|
|
nsresult SetAnnotationInt32Internal(nsIURI* aURI,
|
|
|
|
PRInt64 aItemId,
|
2007-05-10 01:05:19 -07:00
|
|
|
const nsACString& aName,
|
|
|
|
PRInt32 aValue,
|
|
|
|
PRInt32 aFlags,
|
|
|
|
PRUint16 aExpiration);
|
2009-12-18 02:30:37 -08:00
|
|
|
nsresult SetAnnotationInt64Internal(nsIURI* aURI,
|
|
|
|
PRInt64 aItemId,
|
2007-05-10 01:05:19 -07:00
|
|
|
const nsACString& aName,
|
|
|
|
PRInt64 aValue,
|
|
|
|
PRInt32 aFlags,
|
|
|
|
PRUint16 aExpiration);
|
2009-12-18 02:30:37 -08:00
|
|
|
nsresult SetAnnotationDoubleInternal(nsIURI* aURI,
|
|
|
|
PRInt64 aItemId,
|
2007-05-10 01:05:19 -07:00
|
|
|
const nsACString& aName,
|
|
|
|
double aValue,
|
|
|
|
PRInt32 aFlags,
|
|
|
|
PRUint16 aExpiration);
|
2009-12-18 02:30:37 -08:00
|
|
|
nsresult SetAnnotationBinaryInternal(nsIURI* aURI,
|
|
|
|
PRInt64 aItemId,
|
2007-05-10 01:05:19 -07:00
|
|
|
const nsACString& aName,
|
2009-12-18 02:30:37 -08:00
|
|
|
const PRUint8* aData,
|
2007-05-10 01:05:19 -07:00
|
|
|
PRUint32 aDataLen,
|
|
|
|
const nsACString& aMimeType,
|
|
|
|
PRInt32 aFlags,
|
|
|
|
PRUint16 aExpiration);
|
2009-12-18 02:30:37 -08:00
|
|
|
|
|
|
|
nsresult RemoveAnnotationInternal(nsIURI* aURI,
|
|
|
|
PRInt64 aItemId,
|
2007-05-10 01:05:19 -07:00
|
|
|
const nsACString& aName);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool InPrivateBrowsingMode() const;
|
2008-10-19 14:14:59 -07:00
|
|
|
|
2009-12-18 02:30:40 -08:00
|
|
|
bool mShuttingDown;
|
|
|
|
|
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,
|
2009-12-18 02:30:37 -08:00
|
|
|
nsTArray<PRInt64>* _result);
|
|
|
|
nsresult GetAnnotationNamesTArray(nsIURI* aURI,
|
|
|
|
PRInt64 aItemId,
|
|
|
|
nsTArray<nsCString>* _result);
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* nsAnnotationService_h___ */
|