1999-08-20 13:51:02 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The contents of this file are subject to the Netscape 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/NPL/
|
1999-08-20 13:51:02 +04:00
|
|
|
*
|
1999-11-06 06:43:54 +03: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-08-20 13:51:02 +04:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1999-08-20 13:51:02 +04:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
2000-02-10 07:56:56 +03:00
|
|
|
* Copyright (C) 1998-2000 Netscape Communications Corporation. All
|
1999-11-06 06:43:54 +03:00
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2000-04-05 06:32:07 +04:00
|
|
|
* Norris Boyd
|
2000-09-09 04:53:21 +04:00
|
|
|
* Mitch Stoltz
|
|
|
|
* IBM Corporation
|
1999-08-20 13:51:02 +04:00
|
|
|
*/
|
2000-02-10 07:56:56 +03:00
|
|
|
|
1999-08-20 13:51:02 +04:00
|
|
|
#ifndef _NS_SCRIPT_SECURITY_MANAGER_H_
|
|
|
|
#define _NS_SCRIPT_SECURITY_MANAGER_H_
|
|
|
|
|
|
|
|
#include "nsIScriptSecurityManager.h"
|
|
|
|
#include "nsIPrincipal.h"
|
|
|
|
#include "jsapi.h"
|
2000-04-14 07:14:53 +04:00
|
|
|
#include "jsdbgapi.h"
|
1999-09-07 06:54:19 +04:00
|
|
|
#include "nsIXPCSecurityManager.h"
|
1999-11-12 01:10:36 +03:00
|
|
|
#include "nsHashtable.h"
|
1999-11-20 10:28:34 +03:00
|
|
|
#include "nsDOMPropEnums.h"
|
2000-01-19 00:54:01 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2000-07-26 08:53:01 +04:00
|
|
|
#include "nsIPref.h"
|
|
|
|
#include "nsISecurityPref.h"
|
2000-01-23 07:23:14 +03:00
|
|
|
|
2000-08-22 10:02:14 +04:00
|
|
|
#include "nsIJSContextStack.h"
|
|
|
|
|
2000-03-21 07:05:35 +03:00
|
|
|
/////////////////////
|
|
|
|
// nsIPrincipalKey //
|
|
|
|
/////////////////////
|
|
|
|
|
|
|
|
class nsIPrincipalKey : public nsHashKey {
|
|
|
|
public:
|
|
|
|
nsIPrincipalKey(nsIPrincipal* key) {
|
|
|
|
mKey = key;
|
|
|
|
NS_IF_ADDREF(mKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
~nsIPrincipalKey(void) {
|
|
|
|
NS_IF_RELEASE(mKey);
|
|
|
|
}
|
|
|
|
|
2000-08-10 10:19:37 +04:00
|
|
|
PRUint32 HashCode(void) const {
|
2000-03-21 07:05:35 +03:00
|
|
|
PRUint32 hash;
|
|
|
|
mKey->HashValue(&hash);
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool Equals(const nsHashKey *aKey) const {
|
|
|
|
PRBool eq;
|
|
|
|
mKey->Equals(((nsIPrincipalKey *) aKey)->mKey, &eq);
|
|
|
|
return eq;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHashKey *Clone(void) const {
|
|
|
|
return new nsIPrincipalKey(mKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsIPrincipal* mKey;
|
|
|
|
};
|
|
|
|
|
1999-08-20 13:51:02 +04:00
|
|
|
#define NS_SCRIPTSECURITYMANAGER_CID \
|
|
|
|
{ 0x7ee2a4c0, 0x4b93, 0x17d3, \
|
|
|
|
{ 0xba, 0x18, 0x00, 0x60, 0xb0, 0xf1, 0x99, 0xa2 }}
|
|
|
|
|
1999-09-07 06:54:19 +04:00
|
|
|
class nsScriptSecurityManager : public nsIScriptSecurityManager,
|
|
|
|
public nsIXPCSecurityManager
|
|
|
|
{
|
1999-08-20 13:51:02 +04:00
|
|
|
public:
|
1999-08-30 01:58:42 +04:00
|
|
|
nsScriptSecurityManager();
|
|
|
|
virtual ~nsScriptSecurityManager();
|
|
|
|
|
|
|
|
NS_DEFINE_STATIC_CID_ACCESSOR(NS_SCRIPTSECURITYMANAGER_CID)
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSISCRIPTSECURITYMANAGER
|
1999-09-07 06:54:19 +04:00
|
|
|
NS_DECL_NSIXPCSECURITYMANAGER
|
1999-08-30 01:58:42 +04:00
|
|
|
|
|
|
|
static nsScriptSecurityManager *
|
|
|
|
GetScriptSecurityManager();
|
2000-08-22 10:02:14 +04:00
|
|
|
|
|
|
|
JSContext * GetCurrentContextQuick();
|
1999-08-20 13:51:02 +04:00
|
|
|
private:
|
2000-01-19 00:54:01 +03:00
|
|
|
|
1999-08-30 01:58:42 +04:00
|
|
|
NS_IMETHOD
|
|
|
|
GetSubjectPrincipal(JSContext *aCx, nsIPrincipal **result);
|
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
GetObjectPrincipal(JSContext *aCx, JSObject *aObj, nsIPrincipal **result);
|
|
|
|
|
|
|
|
NS_IMETHOD
|
2000-02-02 03:22:58 +03:00
|
|
|
CheckPermissions(JSContext *aCx, JSObject *aObj, const char *aCapability);
|
|
|
|
|
1999-08-30 01:58:42 +04:00
|
|
|
PRInt32
|
2000-01-08 19:51:54 +03:00
|
|
|
GetSecurityLevel(nsIPrincipal *principal, nsDOMProp domProp,
|
2000-01-23 07:23:14 +03:00
|
|
|
PRBool isWrite, nsCString &capability);
|
1999-08-30 01:58:42 +04:00
|
|
|
|
1999-11-16 08:07:31 +03:00
|
|
|
NS_IMETHOD
|
2000-01-23 07:23:14 +03:00
|
|
|
GetPrefName(nsIPrincipal *principal, nsDOMProp domProp,
|
|
|
|
nsCString &result);
|
1999-09-01 04:54:35 +04:00
|
|
|
|
2000-06-23 18:32:38 +04:00
|
|
|
nsresult
|
|
|
|
CheckXPCCapability(JSContext *aJSContext, const char *aCapability);
|
|
|
|
|
1999-09-07 06:54:19 +04:00
|
|
|
NS_IMETHOD
|
2000-05-17 06:38:22 +04:00
|
|
|
CheckXPCPermissions(JSContext *cx, nsISupports* aObj);
|
1999-09-07 06:54:19 +04:00
|
|
|
|
2000-04-14 07:14:53 +04:00
|
|
|
NS_IMETHOD
|
|
|
|
GetFramePrincipal(JSContext *cx, JSStackFrame *fp, nsIPrincipal **result);
|
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
GetScriptPrincipal(JSContext *cx, JSScript *script, nsIPrincipal **result);
|
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
GetFunctionObjectPrincipal(JSContext *cx, JSObject *obj,
|
|
|
|
nsIPrincipal **result);
|
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
GetPrincipalAndFrame(JSContext *cx, nsIPrincipal **result,
|
|
|
|
JSStackFrame **frameResult);
|
|
|
|
|
2000-04-26 07:50:07 +04:00
|
|
|
NS_IMETHOD
|
|
|
|
SavePrincipal(nsIPrincipal* aToSave);
|
|
|
|
|
1999-11-12 01:10:36 +03:00
|
|
|
NS_IMETHOD
|
2000-07-26 08:53:01 +04:00
|
|
|
InitPrefs();
|
|
|
|
|
2000-05-16 07:40:51 +04:00
|
|
|
static nsresult
|
|
|
|
PrincipalPrefNames(const char* pref, char** grantedPref, char** deniedPref);
|
|
|
|
|
1999-11-25 08:28:18 +03:00
|
|
|
static void
|
2000-02-10 07:56:56 +03:00
|
|
|
EnumeratePolicyCallback(const char *prefName, void *data);
|
1999-11-25 08:28:18 +03:00
|
|
|
|
2000-01-19 00:54:01 +03:00
|
|
|
static void
|
2000-02-10 07:56:56 +03:00
|
|
|
EnumeratePrincipalsCallback(const char *prefName, void *data);
|
2000-01-19 00:54:01 +03:00
|
|
|
|
2000-04-05 06:32:07 +04:00
|
|
|
static int PR_CALLBACK
|
2000-01-06 03:59:18 +03:00
|
|
|
JSEnabledPrefChanged(const char *pref, void *data);
|
|
|
|
|
2000-05-16 07:40:51 +04:00
|
|
|
static int PR_CALLBACK
|
2000-02-10 07:56:56 +03:00
|
|
|
PrincipalPrefChanged(const char *pref, void *data);
|
|
|
|
|
2000-01-23 07:23:14 +03:00
|
|
|
nsObjectHashtable *mOriginToPolicyMap;
|
2000-07-26 08:53:01 +04:00
|
|
|
nsCOMPtr<nsIPref> mPrefs;
|
|
|
|
nsCOMPtr<nsISecurityPref> mSecurityPrefs;
|
1999-11-12 01:10:36 +03:00
|
|
|
nsIPrincipal *mSystemPrincipal;
|
2000-04-26 07:50:07 +04:00
|
|
|
nsCOMPtr<nsIPrincipal> mSystemCertificate;
|
1999-11-12 01:10:36 +03:00
|
|
|
nsSupportsHashtable *mPrincipals;
|
2000-01-06 03:59:18 +03:00
|
|
|
PRBool mIsJavaScriptEnabled;
|
2000-01-08 19:51:54 +03:00
|
|
|
PRBool mIsMailJavaScriptEnabled;
|
2000-07-20 05:16:15 +04:00
|
|
|
PRBool mIsWritingPrefs;
|
1999-11-25 08:28:18 +03:00
|
|
|
unsigned char hasDomainPolicyVector[(NS_DOM_PROP_MAX >> 3) + 1];
|
2000-08-22 10:02:14 +04:00
|
|
|
nsCOMPtr<nsIJSContextStack> mThreadJSContextStack;
|
1999-10-29 02:09:03 +04:00
|
|
|
};
|
|
|
|
|
1999-08-20 13:51:02 +04:00
|
|
|
#endif /*_NS_SCRIPT_SECURITY_MANAGER_H_*/
|