2001-09-20 00:09:47 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* ----- BEGIN LICENSE BLOCK -----
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-11-12 01:10:36 +03:00
|
|
|
*
|
2001-09-20 00:09:47 +04:00
|
|
|
* 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/
|
1999-11-12 01:10:36 +03:00
|
|
|
*
|
2001-09-20 00:09:47 +04:00
|
|
|
* 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.
|
1999-11-12 01:10:36 +03:00
|
|
|
*
|
2001-09-20 00:09:47 +04:00
|
|
|
* The Original Code is .
|
2000-02-10 07:56:56 +03:00
|
|
|
*
|
2001-09-20 00:09:47 +04:00
|
|
|
* The Initial Developer of the Original Code is Communications Corporation.
|
|
|
|
* Portions created by Communications Corporation are
|
|
|
|
* Copyright (C) 1999-2000 Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of 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 LGPL or the GPL. 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 ----- */
|
1999-11-12 01:10:36 +03:00
|
|
|
|
|
|
|
/* Shared implementation code for principals. */
|
|
|
|
|
|
|
|
#ifndef _NS_BASE_PRINCIPAL_H_
|
|
|
|
#define _NS_BASE_PRINCIPAL_H_
|
|
|
|
|
|
|
|
#include "jsapi.h"
|
|
|
|
#include "nsJSPrincipals.h"
|
|
|
|
#include "nsVoidArray.h"
|
|
|
|
#include "nsHashtable.h"
|
2001-07-31 23:05:34 +04:00
|
|
|
#include "nsIObjectInputStream.h"
|
|
|
|
#include "nsIObjectOutputStream.h"
|
1999-11-12 01:10:36 +03:00
|
|
|
|
|
|
|
class nsBasePrincipal: public nsIPrincipal {
|
|
|
|
public:
|
|
|
|
|
|
|
|
nsBasePrincipal();
|
|
|
|
|
|
|
|
virtual ~nsBasePrincipal(void);
|
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
GetJSPrincipals(JSPrincipals **jsprin);
|
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
CanEnableCapability(const char *capability, PRInt16 *result);
|
2000-01-19 00:54:01 +03:00
|
|
|
|
1999-11-12 01:10:36 +03:00
|
|
|
NS_IMETHOD
|
|
|
|
SetCanEnableCapability(const char *capability, PRInt16 canEnable);
|
2000-01-19 00:54:01 +03:00
|
|
|
|
1999-11-12 01:10:36 +03:00
|
|
|
NS_IMETHOD
|
|
|
|
IsCapabilityEnabled(const char *capability, void *annotation,
|
|
|
|
PRBool *result);
|
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
EnableCapability(const char *capability, void **annotation);
|
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
RevertCapability(const char *capability, void **annotation);
|
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
DisableCapability(const char *capability, void **annotation);
|
2000-05-16 07:40:51 +04:00
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
GetPreferences(char** aPrefName, char** aID,
|
|
|
|
char** aGrantedList, char** aDeniedList);
|
2000-01-19 00:54:01 +03:00
|
|
|
|
|
|
|
nsresult
|
2000-05-16 07:40:51 +04:00
|
|
|
InitFromPersistent(const char* aPrefName,const char* aID,
|
|
|
|
const char* aGrantedList, const char* aDeniedList);
|
2000-04-26 07:50:07 +04:00
|
|
|
|
2001-07-31 23:05:34 +04:00
|
|
|
NS_IMETHOD
|
|
|
|
Read(nsIObjectInputStream* aStream);
|
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
Write(nsIObjectOutputStream* aStream);
|
|
|
|
|
2000-04-26 07:50:07 +04:00
|
|
|
static const char Invalid[];
|
2000-02-10 07:56:56 +03:00
|
|
|
|
1999-11-12 01:10:36 +03:00
|
|
|
protected:
|
|
|
|
enum AnnotationValue { AnnotationEnabled=1, AnnotationDisabled };
|
|
|
|
|
2000-03-21 07:05:35 +03:00
|
|
|
NS_IMETHOD
|
1999-11-12 01:10:36 +03:00
|
|
|
SetCapability(const char *capability, void **annotation,
|
|
|
|
AnnotationValue value);
|
|
|
|
|
|
|
|
nsJSPrincipals mJSPrincipals;
|
|
|
|
nsVoidArray mAnnotations;
|
|
|
|
nsHashtable *mCapabilities;
|
2000-02-10 07:56:56 +03:00
|
|
|
char *mPrefName;
|
|
|
|
static int mCapabilitiesOrdinal;
|
1999-11-12 01:10:36 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// special AddRef/Release to unify reference counts between XPCOM
|
|
|
|
// and JSPrincipals
|
|
|
|
|
|
|
|
#define NSBASEPRINCIPALS_ADDREF(className) \
|
|
|
|
NS_IMETHODIMP_(nsrefcnt) \
|
|
|
|
className::AddRef(void) \
|
|
|
|
{ \
|
|
|
|
NS_PRECONDITION(PRInt32(mRefCnt) == 0, "illegal mRefCnt"); \
|
|
|
|
NS_PRECONDITION(PRInt32(mJSPrincipals.refcount) >= 0, "illegal refcnt");\
|
2000-03-22 02:12:16 +03:00
|
|
|
nsrefcnt count = PR_AtomicIncrement((PRInt32 *)&mJSPrincipals.refcount);\
|
|
|
|
NS_LOG_ADDREF(this, count, #className, sizeof(*this)); \
|
|
|
|
return count; \
|
1999-11-12 01:10:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#define NSBASEPRINCIPALS_RELEASE(className) \
|
|
|
|
NS_IMETHODIMP_(nsrefcnt) \
|
|
|
|
className::Release(void) \
|
|
|
|
{ \
|
|
|
|
NS_PRECONDITION(PRInt32(mRefCnt) == 0, "illegal mRefCnt"); \
|
|
|
|
NS_PRECONDITION(0 != mJSPrincipals.refcount, "dup release"); \
|
2000-03-22 02:12:16 +03:00
|
|
|
nsrefcnt count = PR_AtomicDecrement((PRInt32 *)&mJSPrincipals.refcount);\
|
|
|
|
NS_LOG_RELEASE(this, count, #className); \
|
|
|
|
if (count == 0) { \
|
1999-11-12 01:10:36 +03:00
|
|
|
NS_DELETEXPCOM(this); \
|
|
|
|
return 0; \
|
|
|
|
} \
|
2000-03-22 02:12:16 +03:00
|
|
|
return count; \
|
1999-11-12 01:10:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // _NS_BASE_PRINCIPAL_H_
|