diff --git a/mozilla/caps/include/nsCCapsManager.h b/mozilla/caps/include/nsCCapsManager.h index 28e1c570990..827071c6a30 100644 --- a/mozilla/caps/include/nsCCapsManager.h +++ b/mozilla/caps/include/nsCCapsManager.h @@ -113,9 +113,6 @@ public: NS_IMETHOD Initialize(PRBool *result); - NS_IMETHOD - InitializeFrameWalker(nsICapsSecurityCallbacks* aInterface); - /** * Registers the given Principal with the system. * @@ -212,9 +209,6 @@ public: NS_IMETHOD NewPrincipalArray(PRUint32 count, void* *result); - NS_IMETHOD - CreateMixedPrincipalArray(void *zig, char* name, const char* codebase, void** result); - NS_IMETHOD FreePrincipalArray(void *prinArray); diff --git a/mozilla/caps/public/MANIFEST b/mozilla/caps/public/MANIFEST index f8386b9c4c4..ee600b67f55 100644 --- a/mozilla/caps/public/MANIFEST +++ b/mozilla/caps/public/MANIFEST @@ -4,4 +4,3 @@ nsICodebasePrincipal.h nsICodeSourcePrincipal.h nsIPrincipal.h nsCapsPublicEnums.h -nsICapsSecurityCallbacks.h diff --git a/mozilla/caps/public/Makefile.in b/mozilla/caps/public/Makefile.in index 5b4876a17a2..a4b9f9f6ada 100644 --- a/mozilla/caps/public/Makefile.in +++ b/mozilla/caps/public/Makefile.in @@ -28,8 +28,7 @@ EXPORTS = nsIPrincipal.h \ nsICertPrincipal.h \ nsICapsManager.h \ nsICodeSourcePrincipal.h \ - nsCapsPublicEnums.h \ - nsICapsSecurityCallbacks.h + nsCapsPublicEnums.h EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS)) diff --git a/mozilla/caps/public/makefile.win b/mozilla/caps/public/makefile.win index 088969c49e8..49bb028d775 100644 --- a/mozilla/caps/public/makefile.win +++ b/mozilla/caps/public/makefile.win @@ -34,8 +34,8 @@ EXPORTS= \ nsICertPrincipal.h \ nsICapsManager.h \ nsICodeSourcePrincipal.h \ - nsCapsPublicEnums.h \ - nsICapsSecurityCallbacks.h + nsCapsPublicEnums.h + include <$(DEPTH)/config/rules.mak> diff --git a/mozilla/caps/public/nsICapsManager.h b/mozilla/caps/public/nsICapsManager.h index 0d6d0eafff0..532a18b2bcf 100644 --- a/mozilla/caps/public/nsICapsManager.h +++ b/mozilla/caps/public/nsICapsManager.h @@ -25,7 +25,6 @@ #include "nsCapsPublicEnums.h" class nsITarget; -class nsICapsSecurityCallbacks; #define NS_ALL_PRIVILEGES ((nsITarget*)NULL) @@ -133,14 +132,6 @@ public: NS_IMETHOD Initialize(PRBool *result) = 0; - /** - * Initializes the capabilities frame walking code. - * - * @param aInterface - interface for calling frame walking code. - */ - NS_IMETHOD - InitializeFrameWalker(nsICapsSecurityCallbacks* aInterface) = 0; - /** * Registers the given Principal with the system. * @@ -237,9 +228,6 @@ public: NS_IMETHOD NewPrincipalArray(PRUint32 count, void* *result) = 0; - NS_IMETHOD - CreateMixedPrincipalArray(void *zig, char* name, const char* codebase, void** result) = 0; - NS_IMETHOD FreePrincipalArray(void *prinArray) = 0; diff --git a/mozilla/caps/public/nsICapsSecurityCallbacks.h b/mozilla/caps/public/nsICapsSecurityCallbacks.h deleted file mode 100644 index aa3619b78fc..00000000000 --- a/mozilla/caps/public/nsICapsSecurityCallbacks.h +++ /dev/null @@ -1,49 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#ifndef nsICapsSecurityCallbacks_h__ -#define nsICapsSecurityCallbacks_h__ - -#include "nsISupports.h" - -#define NS_ICAPSSECURITYCALLBACKS_IID \ -{ /* 480c65f0-9396-11d2-bd92-00805f8ae3f4 */ \ -0x480c65f0, 0x9396, 0x11d2, \ -{0xbd, 0x92, 0x00, 0x80, 0x5f, 0x8a, 0xe3, 0xf4} } - -typedef struct nsFrameWrapper { - void *iterator; -} nsFrameWrapper; - -class nsICapsSecurityCallbacks : public nsISupports { - -public: - - NS_IMETHOD NewNSJSJavaFrameWrapper(void *aContext, struct nsFrameWrapper ** aWrapper) = 0; - NS_IMETHOD FreeNSJSJavaFrameWrapper(struct nsFrameWrapper *aWrapper) = 0; - NS_IMETHOD GetStartFrame(struct nsFrameWrapper *aWrapper) = 0; - NS_IMETHOD IsEndOfFrame(struct nsFrameWrapper *aWrapper, PRBool* aReturn) = 0; - NS_IMETHOD IsValidFrame(struct nsFrameWrapper *aWrapper, PRBool* aReturn) = 0; - NS_IMETHOD GetNextFrame(struct nsFrameWrapper *aWrapper, int *aDepth, void** aReturn) = 0; - NS_IMETHOD OJIGetPrincipalArray(struct nsFrameWrapper *aWrapper, void** aReturn) = 0; - NS_IMETHOD OJIGetAnnotation(struct nsFrameWrapper *aWrapper, void** aReturn) = 0; - NS_IMETHOD OJISetAnnotation(struct nsFrameWrapper *aWrapper, void *aPrivTable, void** aReturn) = 0; - -}; - -#endif // nsICapsSecurityCallbacks_h__ diff --git a/mozilla/caps/src/nsCCapsManager.cpp b/mozilla/caps/src/nsCCapsManager.cpp index 9f6eb26de42..0e923b06263 100644 --- a/mozilla/caps/src/nsCCapsManager.cpp +++ b/mozilla/caps/src/nsCCapsManager.cpp @@ -24,14 +24,6 @@ #include "nsCCertPrincipal.h" #include "nsCCodeSourcePrincipal.h" #include "nsCaps.h" -#include "nsICapsSecurityCallbacks.h" -#include "nsLoadZig.h" -#include "secnav.h" - -#ifdef MOZ_SECURITY -#include "navhook.h" -#include "jarutil.h" -#endif /* MOZ_SECURITY */ static NS_DEFINE_CID(kCCapsManagerCID, NS_CCAPSMANAGER_CID); static NS_DEFINE_IID(kICapsManagerIID, NS_ICAPSMANAGER_IID); @@ -244,19 +236,6 @@ nsCCapsManager::Initialize(PRBool *result) return NS_OK; } -/** - * Initializes the capabilities frame walking code. - * - * @param aInterface - interface for calling frame walking code. - */ -NS_METHOD -nsCCapsManager::InitializeFrameWalker(nsICapsSecurityCallbacks* aInterface) -{ - //XXX write me - - return NS_OK; -} - /** * Registers the given Principal with the system. * @@ -540,95 +519,6 @@ nsCCapsManager::NewPrincipalArray(PRUint32 count, void* *ret_val) return NS_OK; } -/* - * CreateMixedPrincipalArray take codebase and ZIG file information and returns a - * pointer to an array of nsIPrincipal objects. - */ -NS_METHOD -nsCCapsManager::CreateMixedPrincipalArray(void *aZig, char* name, const char* codebase, void** result) -{ - *result = NULL; - PRBool hasCodebase; - int i; - PRUint32 count; - nsIPrincipal *principal; - - hasCodebase = (PRBool)codebase; - - /* First count the number of principals */ - count = codebase ? 1 : 0; - -//Should possibly be #ifdef MOZ_SECURITY but I don't want to break the sec build -#if 0 - SOBITEM *item; - ZIG_Context * zig_aCx = NULL; - ZIG *zig = (ZIG*)aZig; - - if (zig && name) { - /* Make sure file is signed */ - if ((zig_aCx = SOB_find(zig, name, ZIG_SIGN)) != NULL) { - int zig_count=0; - /* count the number of signers */ - while (SOB_find_next(zig_aCx, &item) >= 0) { - zig_count++; - } - SOB_find_end(zig_aCx); - count += zig_count; - } - else { - zig = NULL; - } - } -#endif - if (count == 0) { - return NS_OK; - } - - NewPrincipalArray(count, result); - - if (*result == NULL) { - return NS_ERROR_FAILURE; - } - -#if 0 - if (zig && ((zig_aCx = SOB_find(zig, name, ZIG_SIGN)) == NULL)) { - return NS_ERROR_FAILURE; - } - i = 0; - while (zig && SOB_find_next(zig_aCx, &item) >= 0) { - FINGERZIG *fingPrint; - - fingPrint = (FINGERZIG *) item->data; - - /* create a new nsIPrincipal(CERT_KEY, fingPrint->key) */ - NewPrincipal(nsPrincipalType_CertKey, - fingPrint->key, - fingPrint->length, - zig, - &principal); - RegisterPrincipal(principal, NULL); - SetPrincipalArrayElement(*result, i++, principal); - } - - if (zig) { - SOB_find_end(zig_aCx); - } -#endif - - if (codebase) { - // Add a codebase principal. - NewPrincipal(nsPrincipalType_CodebaseExact, - (void*)codebase, - PL_strlen(codebase), - NULL, - &principal); - RegisterPrincipal(principal, NULL); - SetPrincipalArrayElement(*result, i++, principal); - } - - return NS_OK; -} - NS_METHOD nsCCapsManager::FreePrincipalArray(void *prinArray) { diff --git a/mozilla/content/events/src/nsEventListenerManager.cpp b/mozilla/content/events/src/nsEventListenerManager.cpp index dd5ce86aa55..416abf79bef 100644 --- a/mozilla/content/events/src/nsEventListenerManager.cpp +++ b/mozilla/content/events/src/nsEventListenerManager.cpp @@ -38,14 +38,11 @@ #include "nsIScriptEventListener.h" #include "nsDOMEventsIIDs.h" #include "prmem.h" -#include "nsIScriptGlobalObject.h" -#include "nsIScriptGlobalObjectData.h" static NS_DEFINE_IID(kIEventListenerManagerIID, NS_IEVENTLISTENERMANAGER_IID); static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID); static NS_DEFINE_IID(kIDOMEventIID, NS_IDOMEVENT_IID); static NS_DEFINE_IID(kIScriptEventListenerIID, NS_ISCRIPTEVENTLISTENER_IID); -static NS_DEFINE_IID(kIScriptGlobalObjectDataIID, NS_ISCRIPTGLOBALOBJECTDATA_IID); nsEventListenerManager::nsEventListenerManager() { @@ -416,20 +413,6 @@ nsresult nsEventListenerManager::AddScriptEventListener(nsIScriptContext* aConte nsIAtom *aName, const nsString& aFunc, REFNSIID aIID) { JSObject *mScriptObject; - nsIScriptGlobalObject *global; - nsIScriptGlobalObjectData *globalData; - JSPrincipals* principals = nsnull; - - global = aContext->GetGlobalObject(); - if (global && NS_SUCCEEDED(global->QueryInterface(kIScriptGlobalObjectDataIID, (void**)&globalData))) { - if (NS_FAILED(globalData->GetPrincipals((void**)&principals))) { - NS_RELEASE(global); - NS_RELEASE(globalData); - return NS_ERROR_FAILURE; - } - NS_RELEASE(globalData); - } - NS_IF_RELEASE(global); if (NS_OK == aScriptObjectOwner->GetScriptObject(aContext, (void**)&mScriptObject)) { JSContext* mJSContext = (JSContext*)aContext->GetNativeContext(); @@ -440,9 +423,8 @@ nsresult nsEventListenerManager::AddScriptEventListener(nsIScriptContext* aConte mName.ToLowerCase(mLowerName); mCharName = mLowerName.ToNewCString(); - if (nsnull != mCharName) { - JS_CompileUCFunctionForPrincipals(mJSContext, mScriptObject, principals, mCharName, + JS_CompileUCFunction(mJSContext, mScriptObject, mCharName, 1, mEventArgv, (jschar*)aFunc.GetUnicode(), aFunc.Length(), nsnull, 0); delete[] mCharName; diff --git a/mozilla/dom/public/MANIFEST b/mozilla/dom/public/MANIFEST index b4934f4614d..5d976cbad6e 100644 --- a/mozilla/dom/public/MANIFEST +++ b/mozilla/dom/public/MANIFEST @@ -27,8 +27,6 @@ nsIDOMScriptObjectFactory.h nsIDOMNativeObjectRegistry.h nsDOMCID.h nsIScriptSecurityManager.h -nsIScriptGlobalObjectData.h -nsIScriptSecurityManager.h nsIScriptNameSetRegistry.h nsIScriptExternalNameSet.h nsIScriptNameSpaceManager.h diff --git a/mozilla/dom/public/Makefile.in b/mozilla/dom/public/Makefile.in index 0696a04aaff..f80b54d1b8c 100644 --- a/mozilla/dom/public/Makefile.in +++ b/mozilla/dom/public/Makefile.in @@ -40,7 +40,6 @@ EXPORTS = \ nsIDOMNativeObjectRegistry.h \ nsDOMCID.h \ nsIScriptSecurityManager.h \ - nsIScriptGlobalObjectData.h \ nsIScriptNameSetRegistry.h \ nsIScriptExternalNameSet.h \ nsIScriptNameSpaceManager.h \ diff --git a/mozilla/dom/public/makefile.win b/mozilla/dom/public/makefile.win index c5b9247b4fe..2b645a08e45 100644 --- a/mozilla/dom/public/makefile.win +++ b/mozilla/dom/public/makefile.win @@ -36,8 +36,7 @@ EXPORTS=nsIScriptContext.h \ nsIScriptSecurityManager.h \ nsIScriptNameSetRegistry.h \ nsIScriptExternalNameSet.h \ - nsIScriptNameSpaceManager.h \ - nsIScriptGlobalObjectData.h + nsIScriptNameSpaceManager.h MODULE=dom diff --git a/mozilla/dom/public/nsIScriptGlobalObjectData.h b/mozilla/dom/public/nsIScriptGlobalObjectData.h deleted file mode 100644 index a67ec6afeb3..00000000000 --- a/mozilla/dom/public/nsIScriptGlobalObjectData.h +++ /dev/null @@ -1,40 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#ifndef nsIScriptGlobalObjectData_h__ -#define nsIScriptGlobalObjectData_h__ - -#include "nsISupports.h" -#include "nsString.h" - -#define NS_ISCRIPTGLOBALOBJECTDATA_IID \ -{ 0x98485f80, 0x9615, 0x11d2, \ -{ 0xbd, 0x92, 0x00, 0x80, 0x5f, 0x8a, 0xe3, 0xf4} } - -/** - * JS Global Object information. - */ - -class nsIScriptGlobalObjectData : public nsISupports { -public: - NS_IMETHOD GetPrincipals(void** aPrincipals) = 0; - NS_IMETHOD SetPrincipals(void* aPrincipals) = 0; - NS_IMETHOD GetOrigin(nsString* aOrigin) = 0; -}; - -#endif //nsIScriptGlobalObjectData_h__ diff --git a/mozilla/dom/public/nsIScriptSecurityManager.h b/mozilla/dom/public/nsIScriptSecurityManager.h index a576a9a973b..a45cf632cea 100644 --- a/mozilla/dom/public/nsIScriptSecurityManager.h +++ b/mozilla/dom/public/nsIScriptSecurityManager.h @@ -20,14 +20,9 @@ #define nsIScriptSecurityManager_h__ #include "nscore.h" -#include "jsapi.h" -#include "nsString.h" #include "nsISupports.h" -class nsIScriptGlobalObject; class nsIScriptContext; -class nsIDOMEvent; -class nsIURI; /* * Event listener interface. @@ -38,23 +33,6 @@ class nsIURI; 0x58df5780, 0x8006, 0x11d2, \ {0xbd, 0x91, 0x00, 0x80, 0x5f, 0x8a, 0xe3, 0xf4} } -typedef enum eJSTarget { - eJSTarget_UniversalBrowserRead, - eJSTarget_UniversalBrowserWrite, - eJSTarget_UniversalSendMail, - eJSTarget_UniversalFileRead, - eJSTarget_UniversalFileWrite, - eJSTarget_UniversalPreferencesRead, - eJSTarget_UniversalPreferencesWrite, - eJSTarget_UniversalDialerAccess, - eJSTarget_Max -} eJSTarget; - -typedef struct nsJSPrincipalsList { - JSPrincipals *principals; - struct nsJSPrincipalsList *next; -} nsJSPrincipalsList; - class nsIScriptSecurityManager : public nsISupports { public: @@ -65,45 +43,14 @@ public: */ NS_IMETHOD Init() = 0; - NS_IMETHOD CheckScriptAccess(nsIScriptContext* aContext, void* aObj, const char* aProp, PRBool* aResult) = 0; -/** - * Existing API from lib/libmocha/lm_taint.c. I'm maintaining the api largely as is, just xpcom'ifying - * it. After I get security working I'll reevaluate the need for each of these individually -joki + /** + * Checks script access to the property/method in question */ - NS_IMETHOD GetSubjectOriginURL(JSContext *aCx, nsString* aOrigin) = 0; - NS_IMETHOD GetObjectOriginURL(JSContext *aCx, JSObject *object, nsString* aOrigin) = 0; - NS_IMETHOD GetPrincipalsFromStackFrame(JSContext *aCx, JSPrincipals** aPrincipals) = 0; - NS_IMETHOD GetCompilationPrincipals(nsIScriptContext *aContext, nsIScriptGlobalObject* aGlobal, - JSPrincipals *aLayoutPrincipals, JSPrincipals** aPrincipals) = 0; - NS_IMETHOD CanAccessTarget(JSContext *cx, eJSTarget target, PRBool* aReturn) = 0; - NS_IMETHOD CheckPermissions(JSContext *cx, JSObject *obj, eJSTarget target, PRBool* aReturn) = 0; - NS_IMETHOD CheckContainerAccess(JSContext *aCx, JSObject *aObj, eJSTarget aTarget, PRBool* aReturn) = 0; - NS_IMETHOD GetContainerPrincipals(JSContext *aCx, JSObject *aContainer, JSPrincipals** aPrincipals) = 0; - NS_IMETHOD SetContainerPrincipals(JSContext *aCx, JSObject *aContainer, JSPrincipals* aPrincipals) = 0; - NS_IMETHOD CanCaptureEvent(JSContext *aCx, JSFunction *aFun, JSObject *aEventTarget, PRBool* aReturn) = 0; - NS_IMETHOD SetExternalCapture(JSContext *aCx, JSPrincipals *aPrincipals, PRBool aBool) = 0; - NS_IMETHOD CheckSetParentSlot(JSContext *aCx, JSObject *aObj, jsval aId, jsval *aVp, PRBool* aReturn) = 0; - NS_IMETHOD SetDocumentDomain(JSContext *aCx, JSPrincipals *aPrincipals, - nsString* aNewDomain, PRBool* aReturn) = 0; - NS_IMETHOD DestroyPrincipalsList(JSContext *aCx, nsJSPrincipalsList *aList) = 0; - NS_IMETHOD NewJSPrincipals(nsIURI *aURL, nsString* aName, nsString* aCodebase, JSPrincipals** aPrincipals) = 0; -#ifdef DO_JAVA_STUFF - NS_IMETHOD ExtractFromPrincipalsArchive(JSPrincipals *aPrincipals, char *aName, - uint *aLength, char** aReturn) = 0; - NS_IMETHOD SetUntransformedSource(JSPrincipals *principals, char *original, - char *transformed, PRBool* aReturn) = 0; - NS_IMETHOD GetJSPrincipalsFromJavaCaller(JSContext *cx, void *principalsArray, void *pNSISecurityContext, JSPrincipals** aPrincipals) = 0; -#endif -#if 0 - NS_IMETHOD CanAccessTargetStr(JSContext *cx, const char *target, PRBool* aReturn)= 0; -#endif - NS_IMETHOD RegisterPrincipals(nsIScriptContext *aContext, nsIScriptGlobalObject* aGlobal, JSPrincipals *principals, - nsString* aName, nsString* aSrc, JSPrincipals** aPrincipals) = 0; + NS_IMETHOD CheckScriptAccess(nsIScriptContext* aContext, void* aObj, const char* aProp, PRBool* aResult) = 0; }; //Security flags -#define SCRIPT_SECURITY_ALL_ACCESS 0x0000 #define SCRIPT_SECURITY_NO_ACCESS 0x0001 #define SCRIPT_SECURITY_SAME_DOMAIN_ACCESS 0x0002 //XXX expand this flag out once we know the privileges we'll support diff --git a/mozilla/dom/src/base/Makefile.in b/mozilla/dom/src/base/Makefile.in index 73e6316f5a6..d5244743b74 100644 --- a/mozilla/dom/src/base/Makefile.in +++ b/mozilla/dom/src/base/Makefile.in @@ -26,7 +26,7 @@ LIBRARY_NAME = jsdombase_s MODULE=dom -REQUIRES = xpcom raptor dom js netlib caps oji +REQUIRES = xpcom raptor dom js netlib DEFINES += -D_IMPL_NS_DOM diff --git a/mozilla/dom/src/base/makefile.win b/mozilla/dom/src/base/makefile.win index 083a8f29e83..b2d9d709f9c 100644 --- a/mozilla/dom/src/base/makefile.win +++ b/mozilla/dom/src/base/makefile.win @@ -51,7 +51,7 @@ EXPORTS=nsJSUtils.h MODULE=raptor -REQUIRES=xpcom raptor js netlib caps oji +REQUIRES=xpcom raptor js netlib CPP_OBJS= \ .\$(OBJDIR)\nsBarProps.obj \ @@ -80,7 +80,7 @@ CPP_OBJS= \ LINCS=-I$(XPDIST)\public\xpcom -I$(XPDIST)\public\raptor \ -I$(XPDIST)\public\dom -I$(XPDIST)\public\js -I$(PUBLIC)\netlib -I$(PUBLIC)\plugin -I$(PUBLIC)\oji \ - -I$(PUBLIC)\java -I$(PUBLIC)\xpconnect -I$(PUBLIC)\pref -I$(PUBLIC)\caps + -I$(PUBLIC)\java -I$(PUBLIC)\xpconnect -I$(PUBLIC)\pref LCFLAGS = \ $(LCFLAGS) \ diff --git a/mozilla/dom/src/base/nsGlobalWindow.cpp b/mozilla/dom/src/base/nsGlobalWindow.cpp index 759f9bc845e..73d267bc27f 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.cpp +++ b/mozilla/dom/src/base/nsGlobalWindow.cpp @@ -60,7 +60,6 @@ #include "nsScreen.h" #include "nsHistory.h" #include "nsBarProps.h" -#include "nsIScriptSecurityManager.h" #ifndef NECKO #include "nsINetService.h" #else @@ -80,7 +79,6 @@ static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID); -static NS_DEFINE_IID(kIScriptGlobalObjectDataIID, NS_ISCRIPTGLOBALOBJECTDATA_IID); static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); static NS_DEFINE_IID(kIScriptEventListenerIID, NS_ISCRIPTEVENTLISTENER_IID); static NS_DEFINE_IID(kIDOMWindowIID, NS_IDOMWINDOW_IID); @@ -129,7 +127,6 @@ GlobalWindowImpl::GlobalWindowImpl() mLocation = nsnull; mFrames = nsnull; mOpener = nsnull; - mPrincipals = nsnull; mTimeouts = nsnull; mTimeoutInsertionPoint = nsnull; @@ -144,10 +141,6 @@ GlobalWindowImpl::GlobalWindowImpl() GlobalWindowImpl::~GlobalWindowImpl() { - if (mPrincipals && mContext) { - JSPRINCIPALS_DROP((JSContext*)mContext->GetNativeContext(), mPrincipals); - } - NS_IF_RELEASE(mContext); NS_IF_RELEASE(mDocument); NS_IF_RELEASE(mNavigator); @@ -186,11 +179,6 @@ GlobalWindowImpl::QueryInterface(const nsIID& aIID, AddRef(); return NS_OK; } - if (aIID.Equals(kIScriptGlobalObjectDataIID)) { - *aInstancePtrResult = (void*) ((nsIScriptGlobalObjectData*)this); - AddRef(); - return NS_OK; - } if (aIID.Equals(kIDOMWindowIID)) { *aInstancePtrResult = (void*) ((nsIDOMWindow*)this); AddRef(); @@ -277,18 +265,13 @@ GlobalWindowImpl::SetNewDocument(nsIDOMDocument *aDocument) ClearAllTimeouts(); - if (mPrincipals && mContext) { - JSPRINCIPALS_DROP((JSContext *)mContext->GetNativeContext(), mPrincipals); - mPrincipals = nsnull; - } - if ((nsnull != mScriptObject) && (nsnull != mContext) /* && (nsnull != aDocument) */ ) { JS_ClearScope((JSContext *)mContext->GetNativeContext(), (JSObject *)mScriptObject); } - + if (nsnull != mDocument) { NS_RELEASE(mDocument); } @@ -1530,7 +1513,7 @@ GlobalWindowImpl::RunTimeout(nsTimeoutImpl *aTimeout) timeout->filename, timeout->lineno, nsAutoString(""), &isundefined); #endif - JS_EvaluateScriptForPrincipals(cx, (JSObject *)mScriptObject, timeout->principals, + JS_EvaluateScript(cx, (JSObject *)mScriptObject, timeout->expr, PL_strlen(timeout->expr), timeout->filename, timeout->lineno, @@ -1649,11 +1632,6 @@ GlobalWindowImpl::SetTimeoutOrInterval(JSContext *cx, nsTimeoutImpl *timeout, **insertion_point; jsdouble interval; PRInt64 now, delta; - JSPrincipals* principals; - - if (NS_FAILED(GetPrincipals((void**)&principals))) { - return NS_ERROR_FAILURE; - } if (argc >= 2) { if (!JS_ValueToNumber(cx, argv[1], &interval)) { @@ -1692,7 +1670,7 @@ GlobalWindowImpl::SetTimeoutOrInterval(JSContext *cx, timeout->interval = (PRInt32)interval; timeout->expr = expr; timeout->funobj = funobj; - timeout->principals = principals; + timeout->principals = nsnull; if (expr) { timeout->argv = 0; timeout->argc = 0; @@ -2578,117 +2556,6 @@ GlobalWindowImpl::ReleaseEvent(const nsString& aType) return NS_ERROR_FAILURE; } -NS_IMETHODIMP -GlobalWindowImpl::GetPrincipals(void** aPrincipals) -{ - if (!mPrincipals) { - if (mContext) { - nsIScriptSecurityManager* secMan = nsnull; - mContext->GetSecurityManager(&secMan); - if (secMan) { - nsAutoString codebase; - if (NS_SUCCEEDED(GetOrigin(&codebase))) { - secMan->NewJSPrincipals(nsnull, nsnull, &codebase, &mPrincipals); - } - NS_RELEASE(secMan); - } - } - - if (!mPrincipals) { - return NS_ERROR_FAILURE; - } - if (mContext) { - JSPRINCIPALS_HOLD((JSContext *)mContext->GetNativeContext(), mPrincipals); - } - } - - *aPrincipals = (void*)mPrincipals; - return NS_OK; -} - -NS_IMETHODIMP -GlobalWindowImpl::SetPrincipals(void* aPrincipals) -{ - if (mPrincipals && mContext) { - JSPRINCIPALS_DROP((JSContext *)mContext->GetNativeContext(), mPrincipals); - } - - mPrincipals = (JSPrincipals*)aPrincipals; - - if (mPrincipals && mContext) { - JSPRINCIPALS_HOLD((JSContext *)mContext->GetNativeContext(), mPrincipals); - } - - return NS_OK; -} - -NS_IMETHODIMP -GlobalWindowImpl::GetOrigin(nsString* aOrigin) -{ - nsIDocument* doc; - if (mDocument && NS_OK == mDocument->QueryInterface(kIDocumentIID, (void**)&doc)) { - nsIURI* docURL = doc->GetDocumentURL(); - if (docURL) { - PRUnichar* str; - docURL->ToString(&str); - *aOrigin = str; - delete str; - NS_RELEASE(docURL); - } - NS_RELEASE(doc); - } - - -#if 0 - //Old code from 4.0 to show what funcitonality needs replicating - History_entry *he; - const char *address; - JSContext *aCx; - MochaDecoder *decoder; - - he = SHIST_GetCurrent(&context->hist); - if (he) { - address = he->wysiwyg_url; - if (!address) - address = he->address; - switch (NET_URL_Type(address)) { - case MOCHA_TYPE_URL: - /* This type cannot name the true origin (server) of JS code. */ - break; - case VIEW_SOURCE_TYPE_URL: - NS_ASSERTION(0, "Invalid url type"); - default: - return address; - } - } - - if (context->grid_parent) { - address = FindCreatorURL(context->grid_parent); - if (address) - return address; - } - - aCx = context->mocha_context; - if (aCx) { - decoder = JS_GetPrivate(aCx, JS_GetGlobalObject(aCx)); - if (decoder && decoder->opener) { - /* self.opener property is valid, check its MWContext. */ - MochaDecoder *opener = JS_GetPrivate(aCx, decoder->opener); - if (!opener->visited) { - opener->visited = PR_TRUE; - address = opener->window_context - ? FindCreatorURL(opener->window_context) - : nsnull; - opener->visited = PR_FALSE; - if (address) - return address; - } - } - } -#endif - return NS_OK; -} - extern "C" NS_DOM nsresult NS_NewScriptGlobalObject(nsIScriptGlobalObject **aResult) { @@ -2706,8 +2573,6 @@ NS_NewScriptGlobalObject(nsIScriptGlobalObject **aResult) return global->QueryInterface(kIScriptGlobalObjectIID, (void **)aResult); } - - // // Navigator class implementation // diff --git a/mozilla/dom/src/base/nsGlobalWindow.h b/mozilla/dom/src/base/nsGlobalWindow.h index d1b921d17c3..b633b1e7c2c 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.h +++ b/mozilla/dom/src/base/nsGlobalWindow.h @@ -32,8 +32,6 @@ #include "nsIJSScriptObject.h" #include "nsIDOMEventCapturer.h" #include "nsGUIEvent.h" -#include "nsFrameList.h" -#include "nsIScriptGlobalObjectData.h" #include "nsDOMWindowList.h" #include "nsIDOMEventTarget.h" @@ -59,8 +57,8 @@ class ScreenImpl; class HistoryImpl; // Global object for scripting -class GlobalWindowImpl : public nsIScriptObjectOwner, public nsIScriptGlobalObject, public nsIDOMWindow, - public nsIJSScriptObject, public nsIDOMEventCapturer, public nsIScriptGlobalObjectData +class GlobalWindowImpl : public nsIScriptObjectOwner, public nsIScriptGlobalObject, public nsIDOMWindow, + public nsIJSScriptObject, public nsIDOMEventCapturer { public: GlobalWindowImpl(); @@ -203,11 +201,6 @@ public: virtual PRBool Convert(JSContext *aContext, jsval aID); virtual void Finalize(JSContext *aContext); - // nsIScriptGlobalObjectData interface - NS_IMETHOD GetPrincipals(void** aPrincipals); - NS_IMETHOD SetPrincipals(void* aPrincipals); - NS_IMETHOD GetOrigin(nsString* aOrigin); - friend void nsGlobalWindow_RunTimeout(nsITimer *aTimer, void *aClosure); protected: @@ -244,8 +237,6 @@ protected: HistoryImpl *mHistory; nsIWebShell *mWebShell; nsIDOMWindow *mOpener; - JSPrincipals *mPrincipals; - BarPropImpl *mMenubar; BarPropImpl *mToolbar; BarPropImpl *mLocationbar; diff --git a/mozilla/dom/src/base/nsJSEnvironment.cpp b/mozilla/dom/src/base/nsJSEnvironment.cpp index 04ba61db840..39e97aec7d9 100644 --- a/mozilla/dom/src/base/nsJSEnvironment.cpp +++ b/mozilla/dom/src/base/nsJSEnvironment.cpp @@ -19,7 +19,6 @@ #include "nsJSEnvironment.h" #include "nsIScriptObjectOwner.h" #include "nsIScriptGlobalObject.h" -#include "nsIScriptGlobalObjectData.h" #include "nsIDOMWindow.h" #include "nsIDOMNode.h" #include "nsIDOMElement.h" @@ -48,7 +47,6 @@ const size_t gStackSize = 8192; static NS_DEFINE_IID(kIScriptContextIID, NS_ISCRIPTCONTEXT_IID); static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID); -static NS_DEFINE_IID(kIScriptGlobalObjectDataIID, NS_ISCRIPTGLOBALOBJECTDATA_IID); static NS_DEFINE_IID(kIScriptNameSetRegistryIID, NS_ISCRIPTNAMESETREGISTRY_IID); static NS_DEFINE_IID(kCScriptNameSetRegistryCID, NS_SCRIPT_NAMESET_REGISTRY_CID); static NS_DEFINE_CID(kXPConnectCID, NS_XPCONNECT_CID); @@ -129,23 +127,10 @@ nsJSContext::EvaluateString(const nsString& aScript, PRBool* aIsUndefined) { jsval val; - nsIScriptGlobalObject *global = GetGlobalObject(); - nsIScriptGlobalObjectData *globalData; - JSPrincipals* principals = nsnull; - - if (global && NS_SUCCEEDED(global->QueryInterface(kIScriptGlobalObjectDataIID, (void**)&globalData))) { - if (NS_FAILED(globalData->GetPrincipals((void**)&principals))) { - NS_RELEASE(global); - NS_RELEASE(globalData); - return NS_ERROR_FAILURE; - } - NS_RELEASE(globalData); - } - NS_IF_RELEASE(global); PRBool ret = ::JS_EvaluateUCScriptForPrincipals(mContext, JS_GetGlobalObject(mContext), - principals, + nsnull, (jschar*)aScript.GetUnicode(), aScript.Length(), aURL, diff --git a/mozilla/dom/src/base/nsJSSecurityManager.cpp b/mozilla/dom/src/base/nsJSSecurityManager.cpp index 98c5bafbb17..42bfae255f5 100644 --- a/mozilla/dom/src/base/nsJSSecurityManager.cpp +++ b/mozilla/dom/src/base/nsJSSecurityManager.cpp @@ -17,2084 +17,43 @@ */ #include "nsJSSecurityManager.h" -#include "nsICapsManager.h" #include "nsIServiceManager.h" -#ifdef OJI -#include "jvmmgr.h" -#endif -#include "nsIScriptObjectOwner.h" -#include "nspr.h" -#include "plstr.h" -#include "nsIScriptGlobalObject.h" -#include "nsIScriptGlobalObjectData.h" #include "nsIPref.h" -#include "nsIURL.h" +#include "plstr.h" +#include "nspr.h" +#include "prmem.h" static NS_DEFINE_IID(kIScriptSecurityManagerIID, NS_ISCRIPTSECURITYMANAGER_IID); -static NS_DEFINE_IID(kICapsSecurityCallbacksIID, NS_ICAPSSECURITYCALLBACKS_IID); -static NS_DEFINE_IID(kICapsManagerIID, NS_ICAPSMANAGER_IID); -static NS_DEFINE_IID(kCCapsManagerCID, NS_CCAPSMANAGER_CID); -static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); -static NS_DEFINE_IID(kIScriptGlobalObjectDataIID, NS_ISCRIPTGLOBALOBJECTDATA_IID); static NS_DEFINE_IID(kIPrefIID, NS_IPREF_IID); static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID); nsJSSecurityManager::nsJSSecurityManager() { NS_INIT_REFCNT(); - mCapsManager = nsnull; mPrefs = nsnull; } nsJSSecurityManager::~nsJSSecurityManager() { nsServiceManager::ReleaseService(kPrefServiceCID, mPrefs); - NS_IF_RELEASE(mCapsManager); } -nsresult nsJSSecurityManager::QueryInterface(REFNSIID aIID, void** aInstancePtr) -{ - if (nsnull == aInstancePtr) { - return NS_ERROR_NULL_POINTER; - } - if (aIID.Equals(kIScriptSecurityManagerIID)) { - *aInstancePtr = (void*)(nsIScriptSecurityManager*)this; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(kICapsSecurityCallbacksIID)) { - *aInstancePtr = (void*)(nsICapsSecurityCallbacks*)this; - NS_ADDREF_THIS(); - return NS_OK; - } - return NS_NOINTERFACE; -} - -NS_IMPL_ADDREF(nsJSSecurityManager) -NS_IMPL_RELEASE(nsJSSecurityManager) +NS_IMPL_ISUPPORTS(nsJSSecurityManager, kIScriptSecurityManagerIID) NS_IMETHODIMP nsJSSecurityManager::Init() { return nsServiceManager::GetService(kPrefServiceCID, nsIPref::GetIID(), (nsISupports**)&mPrefs); } -/********************/ + NS_IMETHODIMP nsJSSecurityManager::CheckScriptAccess(nsIScriptContext* aContext, void* aObj, const char* aProp, PRBool* aResult) { - //XXX Comment this out to enable security checking. *aResult = PR_TRUE; return NS_OK; - - *aResult = PR_FALSE; - JSContext* cx = (JSContext*)aContext->GetNativeContext(); - PRInt32 secLevel = CheckForPrivilege(cx, (char*)aProp, nsnull); - - if (SCRIPT_SECURITY_ALL_ACCESS == secLevel) { - *aResult = PR_TRUE; - } - else if (SCRIPT_SECURITY_SAME_DOMAIN_ACCESS == secLevel) { - return CheckPermissions(cx, (JSObject*)aObj, eJSTarget_Max, aResult); - } - //Default is no access - return NS_OK; -} -/***********************/ -void -nsJSSecurityManager::InitCaps(void) -{ - if (nsnull == mCapsManager) { - return; - } - - nsresult res = nsServiceManager::GetService(kCCapsManagerCID, kICapsManagerIID, - (nsISupports**)&mCapsManager); - - if ((NS_OK == res) && (nsnull != mCapsManager)) { - mCapsManager->InitializeFrameWalker(this); - } -} - -static nsString gUnknownOriginStr("[unknown origin]"); -static nsString gFileDoubleSlashUrlPrefix("file://"); -static nsString gFileUrlPrefix("file:"); - -/* This array must be kept in sync with the eJSTarget enum in nsIScripSecurityManager.h */ -static char * targetStrings[] = { - "UniversalBrowserRead", - "UniversalBrowserWrite", - "UniversalSendMail", - "UniversalFileRead", - "UniversalFileWrite", - "UniversalPreferencesRead", - "UniversalPreferencesWrite", - "UniversalDialerAccess", - "Max", - "AccountSetup", - /* See Target.java for more targets */ -}; - -static char access_error_message[] = - "access disallowed from scripts at %s to documents at another domain"; -static char container_error_message[] = - "script at '%s' is not signed by sufficient principals to access " - "signed container"; - - -#if JS_SECURITY_OBJ -/* -static char enablePrivilegeStr[] = "enablePrivilege"; -static char isPrivilegeEnabledStr[] = "isPrivilegeEnabled"; -static char disablePrivilegeStr[] = "disablePrivilege"; -static char revertPrivilegeStr[] = "revertPrivilege"; - -//XXX what about the PREXTERN? -typedef PRBool -(*nsCapsFn)(void* context, struct nsTarget *target, PRInt32 callerDepth); - -static JSBool -callCapsCode(JSContext *aCx, JSObject *obj, uintN argc, jsval *argv, - jsval *rval, nsCapsFn fn, char *name) -{ - JSString *str; - char *cstr; - struct nsTarget *target; - - if (argc == 0 || !JSVAL_IS_STRING(argv[0])) { - JS_ReportError(aCx, "String argument expected for %s.", name); - return JS_FALSE; - } - // We don't want to use JS_ValueToString because we want to be able - // to have an object to represent a target in subsequent versions. - // XXX but then use of an object will cause errors here.... - str = JSVAL_TO_STRING(argv[0]); - if (!str) - return JS_FALSE; - - cstr = JS_GetStringBytes(str); - if (cstr == nsnull) - return JS_FALSE; - - target = nsCapsFindTarget(cstr); - if (target == nsnull) - return JS_FALSE; - // stack depth of 1: first frame is for the native function called - if (!(*fn)(aCx, target, 1)) { - //XXX report error, later, throw exception - return JS_FALSE; - } - return JS_TRUE; -} - - -JSBool -lm_netscape_security_isPrivilegeEnabled(JSContext *aCx, JSObject *obj, uintN argc, - jsval *argv, jsval *rval) -{ - return callCapsCode(aCx, obj, argc, argv, rval, nsCapsIsPrivilegeEnabled, - isPrivilegeEnabledStr); -} - -JSBool -lm_netscape_security_enablePrivilege(JSContext *aCx, JSObject *obj, uintN argc, - jsval *argv, jsval *rval) -{ - return callCapsCode(aCx, obj, argc, argv, rval, nsCapsEnablePrivilege, - enablePrivilegeStr); -} - -JSBool -lm_netscape_security_disablePrivilege(JSContext *aCx, JSObject *obj, uintN argc, - jsval *argv, jsval *rval) -{ - return callCapsCode(aCx, obj, argc, argv, rval, nsCapsDisablePrivilege, - disablePrivilegeStr); -} - -JSBool -lm_netscape_security_revertPrivilege(JSContext *aCx, JSObject *obj, uintN argc, - jsval *argv, jsval *rval) -{ - return callCapsCode(aCx, obj, argc, argv, rval, nsCapsRevertPrivilege, - revertPrivilegeStr); -} - -static JSFunctionSpec PrivilegeManager_static_methods[] = { - { isPrivilegeEnabledStr, lm_netscape_security_isPrivilegeEnabled, 1}, - { enablePrivilegeStr, lm_netscape_security_enablePrivilege, 1}, - { disablePrivilegeStr, lm_netscape_security_disablePrivilege, 1}, - { revertPrivilegeStr, lm_netscape_security_revertPrivilege, 1}, - {0} -}; - -JSBool -lm_InitSecurity(MochaDecoder *decoder) -{ - JSContext *aCx; - JSObject *obj; - JSObject *proto; - JSClass *objectClass; - jsval v; - JSObject *securityObj; - - //XXX * "Steal" calls to netscape.security.PrivilegeManager.enablePrivilege, - //et. al. so that code that worked with 4.0 can still work. - - // Find Object.prototype's class by walking up the window object's - // prototype chain. - aCx = decoder->js_context; - obj = decoder->window_object; - while (proto = JS_GetPrototype(aCx, obj)) - obj = proto; - objectClass = JS_GetClass(aCx, obj); - - if (!JS_GetProperty(aCx, decoder->window_object, "netscape", &v)) - return JS_FALSE; - if (JSVAL_IS_OBJECT(v)) { - // "netscape" property of window object exists; must be LiveConnect - // package. Get the "security" property. - obj = JSVAL_TO_OBJECT(v); - if (!JS_GetProperty(aCx, obj, "security", &v) || !JSVAL_IS_OBJECT(v)) - return JS_FALSE; - securityObj = JSVAL_TO_OBJECT(v); - } else { - //define netscape.security object - obj = JS_DefineObject(aCx, decoder->window_object, "netscape", - objectClass, nsnull, 0); - if (obj == nsnull) - return JS_FALSE; - securityObj = JS_DefineObject(aCx, obj, "security", objectClass, - nsnull, 0); - if (securityObj == nsnull) - return JS_FALSE; - } - - // Define PrivilegeManager object with the necessary "static" methods. - obj = JS_DefineObject(aCx, securityObj, "PrivilegeManager", objectClass, - nsnull, 0); - if (obj == nsnull) - return JS_FALSE; - - return JS_DefineFunctions(aCx, obj, PrivilegeManager_static_methods); -} -*/ -#endif //JS_SECURITY_OBJ - - -/** - * nsIScriptSecurityManager interface - */ - -NS_IMETHODIMP -nsJSSecurityManager::GetSubjectOriginURL(JSContext *aCx, nsString* aOrigin) -{ - /* - * Get origin from script of innermost interpreted frame. - */ - JSPrincipals *principals; - JSStackFrame *fp; - JSScript *script; - -#ifdef OJI - JSStackFrame *pFrameToStartLooking = *JVM_GetStartJSFrameFromParallelStack(); - JSStackFrame *pFrameToEndLooking = JVM_GetEndJSFrameFromParallelStack(pFrameToStartLooking); - if (pFrameToStartLooking == nsnull) { - pFrameToStartLooking = JS_FrameIterator(aCx, &pFrameToStartLooking); - if (pFrameToStartLooking == nsnull) { - /* - ** There are no frames or scripts at this point. - */ - pFrameToEndLooking = nsnull; - } - } -#else - JSStackFrame *pFrameToStartLooking = JS_FrameIterator(aCx, &fp); - JSStackFrame *pFrameToEndLooking = nsnull; -#endif - - fp = pFrameToStartLooking; - while (fp != pFrameToEndLooking) { - script = JS_GetFrameScript(aCx, fp); - if (script) { - principals = JS_GetScriptPrincipals(aCx, script); - aOrigin = new nsString(principals ? principals->codebase : JS_GetScriptFilename(aCx, script)); - return NS_OK; - } - fp = JS_FrameIterator(aCx, &fp); - } -#ifdef OJI - principals = JVM_GetJavaPrincipalsFromStack(pFrameToStartLooking); - if (nsnull == principals) { - aOrigin = new nsString(principals->codebase); - return NS_OK; - } -#endif - - /* - * Not called from either JS or Java. We must be called - * from the interpreter. Get the origin from the decoder. - */ - return GetObjectOriginURL(aCx, JS_GetGlobalObject(aCx), aOrigin); -} - -NS_IMETHODIMP -nsJSSecurityManager::GetObjectOriginURL(JSContext *aCx, JSObject *aObj, nsString* aOrigin) -{ - JSPrincipals *principals; - GetContainerPrincipals(aCx, aObj, &principals); - aOrigin = new nsString(principals ? principals->codebase : nsnull); - return NS_OK; -} - -//+++ -NS_IMETHODIMP -nsJSSecurityManager::GetPrincipalsFromStackFrame(JSContext *aCx, JSPrincipals** aPrincipals) -{ - /* - * Get principals from script of innermost interpreted frame. - */ - JSStackFrame *fp; - JSScript *script; -#ifdef OJI - JSStackFrame *pFrameToStartLooking = *JVM_GetStartJSFrameFromParallelStack(); - JSStackFrame *pFrameToEndLooking = JVM_GetEndJSFrameFromParallelStack(pFrameToStartLooking); - if (pFrameToStartLooking == nsnull) { - pFrameToStartLooking = JS_FrameIterator(aCx, &pFrameToStartLooking); - if (pFrameToStartLooking == nsnull) { - /* - ** There are no frames or scripts at this point. - */ - pFrameToEndLooking = nsnull; - } - } -#else - JSStackFrame *pFrameToStartLooking = JS_FrameIterator(aCx, &fp); - JSStackFrame *pFrameToEndLooking = nsnull; -#endif - - fp = pFrameToStartLooking; - while ((fp = JS_FrameIterator(aCx, &fp)) != pFrameToEndLooking) { - script = JS_GetFrameScript(aCx, fp); - if (script) { - *aPrincipals = JS_GetScriptPrincipals(aCx, script); - return NS_OK; - } - } -#ifdef OJI - *aPrincipals = JVM_GetJavaPrincipalsFromStack(pFrameToStartLooking); - return NS_OK; -#endif - *aPrincipals = nsnull; - return NS_OK; -} - -NS_IMETHODIMP -nsJSSecurityManager::GetCompilationPrincipals(nsIScriptContext *aContext, - nsIScriptGlobalObject* aGlobal, - JSPrincipals *aLayoutPrincipals, - JSPrincipals** aPrincipals) -{ - JSContext *cx; - *aPrincipals = nsnull; - - cx = (JSContext*)(aContext->GetNativeContext()); - - if (0) {//script from doc.write(decoder->writing_input && lm_writing_context != nsnull) { - /* - * Compiling a script added due to a document.write. - * Get principals from stack frame. We can't just use these - * principals since the document.write code will fail signature - * verification. So just grab the codebase and form a new set - * of principals. - */ - GetPrincipalsFromStackFrame(cx, aPrincipals); - //XXX Mac doesn't like this. Fix it!!! - nsAutoString cb("");//*aPrincipals ? (*aPrincipals)->codebase : gUnknownOriginStr); - NewJSPrincipals(nsnull, nsnull, &cb, aPrincipals); - if (*aPrincipals == nsnull) { - JS_ReportOutOfMemory(cx); - return NS_ERROR_FAILURE; - } - InvalidateCertPrincipals(cx, *aPrincipals); - return NS_OK; - } - - if (aLayoutPrincipals) { - *aPrincipals = aLayoutPrincipals; - return NS_OK; - } - - /* - * Just get principals corresponding to the window or layer we're - * currently parsing. - */ - nsIScriptObjectOwner* globalOwner; - JSObject* global = nsnull; - - if (NS_OK == aGlobal->QueryInterface(kIScriptObjectOwnerIID, (void**)&globalOwner)) { - globalOwner->GetScriptObject(aContext, (void**)&global); - } - if (nsnull != global) { - return GetContainerPrincipals(cx, global, aPrincipals); - } - - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -nsJSSecurityManager::CanAccessTarget(JSContext *aCx, eJSTarget aTarget, PRBool* aReturn) -{ - JSPrincipals *principals; - *aReturn = PR_TRUE; - - GetPrincipalsFromStackFrame(aCx, &principals); - -#if 0 - if ((nsCapsGetRegistrationModeFlag()) && principals && - (NET_URL_Type(principals->codebase) == FILE_TYPE_URL)) { - return NS_OK; - } - else -#endif - if (principals && !principals->globalPrivilegesEnabled(aCx, principals)) { - *aReturn = PR_FALSE; - } - else if (!PrincipalsCanAccessTarget(aCx, aTarget)) { - *aReturn = PR_FALSE; - } - - return NS_OK; -} - -/* - * If given principals can access the given target, return true. Otherwise - * return false. The script must already have explicitly requested access - * to the given target. - */ -PRBool -nsJSSecurityManager::PrincipalsCanAccessTarget(JSContext *aCx, eJSTarget aTarget) -{ - struct nsPrivilegeTable *annotation; - JSStackFrame *fp; - void *annotationRef; - void *principalArray = nsnull; -#ifdef OJI - JSStackFrame *pFrameToStartLooking = *JVM_GetStartJSFrameFromParallelStack(); - JSStackFrame *pFrameToEndLooking = JVM_GetEndJSFrameFromParallelStack(pFrameToStartLooking); - PRBool bCalledFromJava = (pFrameToEndLooking != nsnull); - if (pFrameToStartLooking == nsnull) { - pFrameToStartLooking = JS_FrameIterator(aCx, &pFrameToStartLooking); - if (pFrameToStartLooking == nsnull) { - /* - ** There are no frames or scripts at this point. - */ - pFrameToEndLooking = nsnull; - } - } -#else - JSStackFrame *pFrameToStartLooking = JS_FrameIterator(aCx, &fp); - JSStackFrame *pFrameToEndLooking = nsnull; -#endif - - InitCaps(); - - /* Map eJSTarget to nsTarget */ - NS_ASSERTION(aTarget >= 0, "No target in PrincipalsCanAccessTarget"); - //NS_ASSERTION(aTarget < sizeof(targetStrings)/sizeof(targetStrings[0]), ""); - - /* Find annotation */ - annotationRef = nsnull; - principalArray = nsnull; - fp = pFrameToStartLooking; - while ((fp = JS_FrameIterator(aCx, &fp)) != pFrameToEndLooking) { - void *current; - if (JS_GetFrameScript(aCx, fp) == nsnull) - continue; - current = JS_GetFramePrincipalArray(aCx, fp); - if (current == nsnull) { - return PR_FALSE; - } - annotationRef = (void *) JS_GetFrameAnnotation(aCx, fp); - if (annotationRef) { - if (nsnull != principalArray) { - PRBool canExtend; - mCapsManager->CanExtendTrust(current, principalArray, &canExtend); - if (!canExtend) { - return PR_FALSE; - } - break; - } - } - if (nsnull != principalArray) { - mCapsManager->IntersectPrincipalArray(principalArray, current, &principalArray); - } - else { - principalArray = current; - } - } - - if (annotationRef) { - annotation = (struct nsPrivilegeTable *)annotationRef; - } - else { -#ifdef OJI - /* - * Call from Java into JS. Just call the Java routine for checking - * privileges. - */ - if (nsnull == pFrameToEndLooking) { - if (principalArray) { - /* - * Must check that the principals that signed the Java applet are - * a subset of the principals that signed this script. - */ - void *javaPrincipals = JVM_GetJavaPrincipalsFromStackAsNSVector(pFrameToStartLooking); - - if (!CanExtendTrust(aCx, javaPrincipals, principalArray)) { - return PR_FALSE; - } - } - /* - * XXX sudu: TODO: Setup the parameters representing a target. - */ - return JVM_NSISecurityContextImplies(pFrameToStartLooking, targetStrings[aTarget], NULL); - } -#endif /* OJI */ - // No annotation in stack - return PR_FALSE; - } - - // Now find permission for (annotation, target) pair. - PRBool allowed; - mCapsManager->IsAllowed(annotation, targetStrings[aTarget], &allowed); - - return allowed; -} - -NS_IMETHODIMP -nsJSSecurityManager::CheckPermissions(JSContext *aCx, JSObject *aObj, eJSTarget aTarget, PRBool* aReturn) -{ - nsString* subjectOrigin = nsnull; - nsString* objectOrigin = nsnull; - nsISupports* running; - nsIScriptGlobalObjectData *globalData; - JSPrincipals *principals; - - /* May be in a layer loaded from a different origin.*/ - GetSubjectOriginURL(aCx, subjectOrigin); - - /* - * Hold onto reference to the running decoder's principals - * in case a call to GetObjectOriginURL ends up - * dropping a reference due to an origin changing - * underneath us. - */ - running = (nsISupports*)JS_GetPrivate(aCx, JS_GetGlobalObject(aCx)); - if (nsnull != running && - NS_OK == running->QueryInterface(kIScriptGlobalObjectDataIID, (void**)&globalData)) { - globalData->GetPrincipals((void**)&principals); - NS_RELEASE(globalData); - } - - if (principals) { - JSPRINCIPALS_HOLD(aCx, principals); - } - - GetObjectOriginURL(aCx, aObj, objectOrigin); - - if (!subjectOrigin || !objectOrigin) { - *aReturn = PR_FALSE; - goto out; - } - - /* Now see whether the origin methods and servers match. */ - if (SameOriginsStr(aCx, subjectOrigin, objectOrigin)) { - *aReturn = PR_TRUE; - goto out; - } - - /* - * If we failed the origin tests it still might be the case that we - * are a signed script and have permissions to do this operation. - * Check for that here - */ - if (aTarget != eJSTarget_Max) { - PRBool canAccess; - - CanAccessTarget(aCx, aTarget, &canAccess); - if (canAccess) { - *aReturn = PR_TRUE; - goto out; - } - } - - JS_ReportError(aCx, "Access error message", subjectOrigin->ToNewCString()); - *aReturn = PR_FALSE; - -out: - if (subjectOrigin) { - delete subjectOrigin; - } - if (objectOrigin) { - delete subjectOrigin; - } - - if (principals) { - JSPRINCIPALS_DROP(aCx, principals); - } - return NS_OK; -} - -NS_IMETHODIMP -nsJSSecurityManager::CheckContainerAccess(JSContext *aCx, JSObject *aObj, - eJSTarget aTarget, PRBool* aReturn) -{ - JSPrincipals *principals; - nsJSPrincipalsData *data; - JSStackFrame *fp; - JSScript *script; - JSPrincipals *subjPrincipals; - nsString* fn = nsnull; - - /* The decoder's js_context isn't in a request, so we should put it - * in one during this call. */ - //XXXJoki, why the begin request? Does it needs to be aObj's cx? - JS_BeginRequest(aCx); - GetContainerPrincipals(aCx, aObj, &principals); - JS_EndRequest(aCx); - - if (principals == nsnull) { -#ifdef EARLY_ACCESS_STUFF - /* - * Attempt to access container before container has any scripts. - * Most of these accesses come from natives when initializing a - * window. Check for that by seeing if we have an executing script. - * If we do, remember the principals of the script that performed - * the access so we can report an error later if need be. - */ - fp = nsnull; - GetPrincipalsFromStackFrame(aCx, &subjPrincipals); - if (subjPrincipals == nsnull) { - *aReturn = PR_TRUE; - return NS_OK; - } - - /* See if subjPrincipals are already on list */ - list = (nsJSPrincipalsList *) decoder->early_access_list; - while (list && list->principals != subjPrincipals) { - list = list->next; - } - if (list == nsnull) { - list = PR_MALLOC(sizeof(*list)); - if (list == nsnull) { - JS_ReportOutOfMemory(aCx); - *aReturn = PR_FALSE; - return NS_ERROR_FAILURE; - } - list->principals = subjPrincipals; - JSPRINCIPALS_HOLD(aCx, list->principals); - list->next = (nsJSPrincipalsList *) decoder->early_access_list; - decoder->early_access_list = list; - } - /* - * XXX - Still possible to modify contents of another page - * even if cross-origin access is disabled by setting to - * about:blank, modifying, and then loading the attackee. - * Similarly with window.open(""). - */ -#endif - *aReturn = PR_TRUE; - return NS_OK; - } - /* - * If object doesn't have signed scripts and cross-origin access - * is enabled, return true. - */ - data = (nsJSPrincipalsData *) principals; - if (data->signedness != HAS_SIGNED_SCRIPTS) {//XXXGlobalAPI && GetCrossOriginEnabled()) { - *aReturn = PR_TRUE; - return NS_OK; - } - - /* Check if user requested lower privileges */ - - if (data->signedness == HAS_SIGNED_SCRIPTS) { - //XXX Do we need CompromisePrincipals?XXX && !GetPrincipalsCompromise(aCx, obj)) { - /* - * We have signed scripts. Must check that the object principals are - * a subset of the the subject principals. - */ - fp = nsnull; - fp = JS_FrameIterator(aCx, &fp); - if (fp == nsnull || (script = JS_GetFrameScript(aCx, fp)) == nsnull) { - /* haven't begun execution yet; allow the r to create functions */ - *aReturn = PR_TRUE; - return NS_OK; - } - subjPrincipals = JS_GetScriptPrincipals(aCx, script); - if (subjPrincipals && - CanExtendTrust(aCx, - principals->getPrincipalArray(aCx, principals), - subjPrincipals->getPrincipalArray(aCx, subjPrincipals))) - { - *aReturn = PR_TRUE; - return NS_OK; - } - GetSubjectOriginURL(aCx, fn); - if (!fn) { - *aReturn = PR_FALSE; - return NS_OK; - } - if (subjPrincipals && principals) { - PrintToConsole("Principals of script: "); - PrintPrincipalsToConsole(aCx, subjPrincipals); - PrintToConsole("Principals of signed container: "); - PrintPrincipalsToConsole(aCx, principals); - } - char fnChar[128]; - - JS_ReportError(aCx, "Container error message", fn->ToCString(fnChar, 128)); - *aReturn = PR_FALSE; - delete fn; - return NS_ERROR_FAILURE; - } - - /* The signed script has called compromisePrincipals(), so - * we do the weaker origin check. - */ - return CheckPermissions(aCx, aObj, aTarget, aReturn); -} - -NS_IMETHODIMP -nsJSSecurityManager::GetContainerPrincipals(JSContext *aCx, JSObject *container, JSPrincipals** aPrincipals) -{ - //Start from topmost item. - while (nsnull != (container = JS_GetParent(aCx, container))); - - *aPrincipals = nsnull; - - // Need to check that the origin hasn't changed underneath us - char* originUrl = FindOriginURL(aCx, container); - - if (!originUrl) { - return NS_ERROR_FAILURE; - } - - nsISupports *tmp; - nsIScriptGlobalObjectData *globalData; - - tmp = (nsISupports*)JS_GetPrivate(aCx, container); - if (nsnull != tmp && - NS_OK == tmp->QueryInterface(kIScriptGlobalObjectDataIID, (void**)&globalData)) { - globalData->GetPrincipals((void**)aPrincipals); - } - - if (nsnull != *aPrincipals) { - if (SameOrigins(aCx, originUrl, (*aPrincipals)->codebase)) { - delete originUrl; - return NS_OK; - } - - nsJSPrincipalsData* data; - data = (nsJSPrincipalsData*)*aPrincipals; - if (data->codebaseBeforeSettingDomain && - SameOrigins(aCx, originUrl, data->codebaseBeforeSettingDomain)) { - /* document.domain was set, so principals are okay */ - delete originUrl; - return NS_OK; - } - /* Principals have changed underneath us. Remove them. */ - globalData->SetPrincipals(nsnull); - } - /* Create new principals and return them. */ - nsAutoString originUrlStr(originUrl); - - if (NS_OK != NewJSPrincipals(nsnull, nsnull, &originUrlStr, aPrincipals)) { - delete originUrl; - return NS_ERROR_FAILURE; - } - - globalData->SetPrincipals((void*)*aPrincipals); - - delete originUrl; - return NS_OK; -} - -NS_IMETHODIMP -nsJSSecurityManager::SetContainerPrincipals(JSContext *aCx, JSObject *aContainer, JSPrincipals *aPrincipals) -{ - //Start from topmost item. - while (nsnull != (aContainer = JS_GetParent(aCx, aContainer))); - - nsISupports *tmp; - nsIScriptGlobalObjectData *globalData; - - tmp = (nsISupports*)JS_GetPrivate(aCx, aContainer); - if (nsnull != tmp && - NS_OK == tmp->QueryInterface(kIScriptGlobalObjectDataIID, (void**)&globalData)) { - globalData->SetPrincipals((void*)aPrincipals); - } - - return NS_OK; -} - -NS_IMETHODIMP -nsJSSecurityManager::CanCaptureEvent(JSContext *aCx, JSFunction *aFun, JSObject *aEventTarget, PRBool* aReturn) -{ - JSScript *script; - JSPrincipals *principals; - nsString* origin = nsnull; - - script = JS_GetFunctionScript(aCx, aFun); - if (script == nsnull) { - *aReturn = PR_FALSE; - return NS_OK; - } - principals = JS_GetScriptPrincipals(aCx, script); - if (principals == nsnull) { - *aReturn = PR_FALSE; - return NS_OK; - } - GetObjectOriginURL(aCx, aEventTarget, origin); - char* originChar; - if (origin) { - originChar = origin->ToNewCString(); - } - if (!originChar) { - if (origin) { - delete origin; - } - *aReturn = PR_FALSE; - return NS_OK; - } - - *aReturn = (PRBool)(SameOrigins(aCx, originChar, principals->codebase) || - IsExternalCaptureEnabled(aCx, principals)); - - delete origin; - delete originChar; - return NS_OK; -} - -PRBool -nsJSSecurityManager::IsExternalCaptureEnabled(JSContext *aCx, JSPrincipals *aPrincipals) -{ - nsJSPrincipalsData *data = (nsJSPrincipalsData*)aPrincipals; - - if (data->externalCapturePrincipalsCount == 0) { - return PR_FALSE; - } - else { - PRUint32 count = GetPrincipalsCount(aCx, aPrincipals); - return (PRBool)(data->externalCapturePrincipalsCount == count); - } -} - -NS_IMETHODIMP -nsJSSecurityManager::SetExternalCapture(JSContext *aCx, JSPrincipals *aPrincipals, PRBool aBool) -{ - nsJSPrincipalsData *data = (nsJSPrincipalsData*)aPrincipals; - - if (aBool) { - PRUint32 count = GetPrincipalsCount(aCx, aPrincipals); - data->externalCapturePrincipalsCount = count; - } else { - data->externalCapturePrincipalsCount = 0; - } - - return NS_OK; -} - -NS_IMETHODIMP -nsJSSecurityManager::CheckSetParentSlot(JSContext *aCx, JSObject *aObj, jsval aId, jsval *aVp, PRBool* aReturn) -{ - JSObject *newParent; - *aReturn = PR_TRUE; - - if (!JSVAL_IS_OBJECT(*aVp)) { - return NS_OK; - } - newParent = JSVAL_TO_OBJECT(*aVp); - if (newParent) { - nsString* oldOrigin = nsnull; - nsString* newOrigin = nsnull; - - GetObjectOriginURL(aCx, aObj, oldOrigin); - if (!oldOrigin) { - return NS_ERROR_FAILURE; - } - GetObjectOriginURL(aCx, newParent, newOrigin); - if (!newOrigin) { - delete oldOrigin; - return NS_ERROR_FAILURE; - } - if (!SameOriginsStr(aCx, oldOrigin, newOrigin)) { - delete oldOrigin; - delete newOrigin; - return NS_OK; - } - delete oldOrigin; - delete newOrigin; - } - else { - //Should only be called from window - if (JS_GetParent(aCx, aObj)) { - return NS_OK; - } - JSPrincipals *principals; - GetContainerPrincipals(aCx, aObj, &principals); - if (!principals) { - *aReturn = PR_FALSE; - return NS_ERROR_FAILURE; - } - } - return NS_OK; -} - -NS_IMETHODIMP -nsJSSecurityManager::SetDocumentDomain(JSContext *aCx, JSPrincipals *aPrincipals, - nsString* aNewDomain, PRBool* aReturn) -{ - nsJSPrincipalsData *data; - - if (aNewDomain->Equals(aPrincipals->codebase)) { - *aReturn = PR_TRUE; - return NS_OK; - } - data = (nsJSPrincipalsData *) aPrincipals; - if (!data->codebaseBeforeSettingDomain) { - data->codebaseBeforeSettingDomain = aPrincipals->codebase; - } - else { - delete aPrincipals->codebase; - } - nsString* codebaseStr = GetOriginFromSourceURL(aNewDomain); - - if (!codebaseStr) { - return NS_ERROR_FAILURE; - } - - aPrincipals->codebase = codebaseStr->ToNewCString(); - delete codebaseStr; - if (aPrincipals->codebase == nsnull) { - JS_ReportOutOfMemory(aCx); - *aReturn = PR_FALSE; - return NS_ERROR_FAILURE; - } - if (data->principalsArrayRef != nsnull) { - mCapsManager->FreePrincipalArray((void*)(data->principalsArrayRef)); - data->principalsArrayRef = nsnull; - } - *aReturn = PR_TRUE; - return NS_OK; -} - -NS_IMETHODIMP -nsJSSecurityManager::DestroyPrincipalsList(JSContext *aCx, nsJSPrincipalsList *aList) -{ - //early access stuff - while (aList) { - nsJSPrincipalsList *next = aList->next; - if (aList->principals) - JSPRINCIPALS_DROP(aCx, aList->principals); - PR_Free(aList); - aList = next; - } - return NS_OK; -} - -void -nsJSSecurityManager::PrintToConsole(const char *data) -{ - /* XXX: raman: We should write to JS console when it is ready */ - /* JS_PrintToConsole(data); */ - printf("%s", data); -} - -PRBool -nsJSSecurityManager::SameOrigins(JSContext *aCx, const char* aOrigin1, const char* aOrigin2) -{ - if (!aOrigin1 || !aOrigin2) { - return PR_FALSE; - } - - nsAutoString origin1(aOrigin1); - nsAutoString origin2(aOrigin2); - - return SameOriginsStr(aCx, &origin1, &origin2); -} - -PRBool -nsJSSecurityManager::SameOriginsStr(JSContext *aCx, nsString* aOrigin1, nsString* aOrigin2) -{ - if (!aOrigin1 || !aOrigin2) { - return PR_FALSE; - } - - // Shouldn't return true if both origin1 and origin2 are unknownOriginStr. - if (gUnknownOriginStr.EqualsIgnoreCase(*aOrigin1)) { - return PR_FALSE; - } - - if (aOrigin1 == aOrigin2) { - return PR_TRUE; - } - - nsString* cmp1 = GetCanonicalizedOrigin(aCx, aOrigin1); - nsString* cmp2 = GetCanonicalizedOrigin(aCx, aOrigin2); - - if (cmp1 && cmp2) { - if (cmp1 == cmp2) { - delete cmp1; - delete cmp2; - return PR_TRUE; - } - if (cmp1->Find(gFileUrlPrefix) == 0 && - cmp2->Find(gFileUrlPrefix) == 0) { - delete cmp1; - delete cmp2; - return PR_TRUE; - } - } - if (cmp1) { - delete cmp1; - } - if (cmp2) { - delete cmp2; - } - return PR_FALSE; -} - -nsString* -nsJSSecurityManager::GetCanonicalizedOrigin(JSContext* aCx, nsString* aUrlString) -{ - char* origin; - char* urlChar = aUrlString->ToNewCString(); - - if (!urlChar) { - JS_ReportOutOfMemory(aCx); - return nsnull; - } - - origin = ParseURL(urlChar, GET_PROTOCOL_PART | GET_HOST_PART); - - if (!origin) { - delete urlChar; - JS_ReportOutOfMemory(aCx); - return nsnull; - } - delete urlChar; - return new nsString(origin); -} - -PR_STATIC_CALLBACK(void) -DestroyJSPrincipals(JSContext *aCx, JSPrincipals *principals); - -PR_STATIC_CALLBACK(void *) -GetPrincipalArray(JSContext *aCx, struct JSPrincipals *principals); - -PR_STATIC_CALLBACK(PRBool) -GlobalPrivilegesEnabled(JSContext *aCx, JSPrincipals *principals); - -static nsJSPrincipalsData unknownPrincipals = { - { - gUnknownOriginStr.ToNewCString(), - GetPrincipalArray, - GlobalPrivilegesEnabled, - 0, - DestroyJSPrincipals - }, - nsnull -}; - -nsString* -nsJSSecurityManager::GetOriginFromSourceURL(nsString* aSourceURL) -{ - if (aSourceURL->Length() == 0 || aSourceURL->EqualsIgnoreCase(gUnknownOriginStr)) { - return &gUnknownOriginStr; - } -#if 0 //need to get url type - int urlType; - - urlType = NET_URL_Type(sourceURL); - if (urlType == MOCHA_TYPE_URL) { - NS_ASSERTION(PR_FALSE, "Invalid URL type");/* this shouldn't occur */ - return &gUnknownOriginStr; - } -#endif - nsAutoString sourceURL(*aSourceURL); - - //Stripfiledoubleslash - if (!sourceURL.Find(gFileDoubleSlashUrlPrefix)) { - sourceURL = sourceURL.Cut(gFileDoubleSlashUrlPrefix.Length(), 2); - } - - char* chS = sourceURL.ToNewCString(); - if (!chS) { - return &gUnknownOriginStr; - } - - char *result = ParseURL(chS, GET_PROTOCOL_PART|GET_HOST_PART|GET_PATH_PART); - delete chS; - - return new nsString(result); -} - -NS_IMETHODIMP -nsJSSecurityManager::NewJSPrincipals(nsIURI *aURL, nsString* aName, nsString* aCodebase, JSPrincipals** aPrincipals) -{ - nsJSPrincipalsData *result; - PRBool needUnlock = PR_FALSE; - void *zip = nsnull; //ns_zip_t - - InitCaps(); - -#if 0 - if (aURL) { - char *fn = nsnull; - - if (NET_IsLocalFileURL(archive->address)) { - char* pathPart = ParseURL(archive->address, GET_PATH_PART); - fn = WH_FileName(pathPart, xpURL); - PR_Free(pathPart); - } - else if (archive->cache_file && NET_ChangeCacheFileLock(archive, TRUE)) { - fn = WH_FileName(archive->cache_file, xpCache); - needUnlock = PR_TRUE; - } - - if (fn) { -#ifdef XP_MAC - /* - * Unfortunately, ns_zip_open wants a Unix-style name. Convert - * Mac path to a Unix-style path. This code is copied from - * appletStubs.c. - */ - OSErr ConvertMacPathToUnixPath(const char *macPath, char **unixPath); - char *unixPath = nsnull; - - if (ConvertMacPathToUnixPath(fn, &unixPath) == 0) { - zip = ns_zip_open(unixPath); - } - PR_FREEIF(unixPath); -#else - zip = ns_zip_open(fn); -#endif - PR_Free(fn); - } - } -#endif - - //Allocate and fill the nsJSPrincipalsData struct - result = PR_NEWZAP(nsJSPrincipalsData); - if (result == nsnull) { - return NS_ERROR_FAILURE; - } - - nsString* codebaseStr = GetOriginFromSourceURL(aCodebase); - - if (!codebaseStr) { - PR_Free(result); - return NS_ERROR_FAILURE; - } - - result->principals.codebase = codebaseStr->ToNewCString(); - delete codebaseStr; - if (result->principals.codebase == nsnull) { - PR_Free(result); - return NS_ERROR_FAILURE; - } - - if (aName) { - result->name = aName ? aName->ToNewCString() : nsnull; - if (result->name == nsnull) { - delete result->principals.codebase; - PR_Free(result); - return NS_ERROR_FAILURE; - } - } - - result->principals.destroy = DestroyJSPrincipals; - result->principals.getPrincipalArray = GetPrincipalArray; - result->principals.globalPrivilegesEnabled = GlobalPrivilegesEnabled; - result->url = aURL; - NS_IF_ADDREF(aURL); - result->zip = zip; - result->needUnlock = needUnlock; - - *aPrincipals = (JSPrincipals*)result; - return NS_OK; -} - -//JSPrincipal callback -PR_STATIC_CALLBACK(void) -DestroyJSPrincipals(JSContext *aCx, JSPrincipals *aPrincipals) -{ - if (aPrincipals != nsnull && - aPrincipals != (JSPrincipals*)&unknownPrincipals) { - nsJSPrincipalsData* data = (nsJSPrincipalsData*)aPrincipals; - - if (aPrincipals->codebase) { - delete aPrincipals->codebase; - } - if (data->principalsArrayRef != nsnull) { - /* XXX: raman: Should we free up the principals that are in that array also? */ - nsICapsManager* capsMan; - nsresult res = nsServiceManager::GetService(kCCapsManagerCID, kICapsManagerIID, - (nsISupports**)&capsMan); - - if ((NS_OK == res) && (nsnull != capsMan)) { - capsMan->FreePrincipalArray((void*)(data->principalsArrayRef)); - NS_RELEASE(capsMan); - } - } - //XXX - if (data->name) { - delete data->name; - } - //data->untransformed - //data->transformed - if (data->codebaseBeforeSettingDomain) { - delete data->codebaseBeforeSettingDomain; - } - - if (data->zip) - //ns_zip_close(data->zip); - if (data->url) - NS_RELEASE(data->url); - PR_Free(data); - } -} - -//JSPrincipal callback -PR_STATIC_CALLBACK(void *) -GetPrincipalArray(JSContext *aCx, struct JSPrincipals *aPrincipals) -{ - nsJSPrincipalsData *data = (nsJSPrincipalsData *)aPrincipals; - - //Get array of principals - if (data->principalsArrayRef == nsnull) { - nsICapsManager* capsMan; - nsresult res = nsServiceManager::GetService(kCCapsManagerCID, kICapsManagerIID, - (nsISupports**)&capsMan); - - if ((NS_OK == res) && (nsnull != capsMan)) { - capsMan->CreateMixedPrincipalArray(nsnull, nsnull, - aPrincipals->codebase, - (void**)&(data->principalsArrayRef)); - NS_RELEASE(capsMan); - } - } - - return data->principalsArrayRef; -} - -//JSPrincipal callback -PR_STATIC_CALLBACK(PRBool) -GlobalPrivilegesEnabled(JSContext *aCx, JSPrincipals *aPrincipals) -{ - nsJSPrincipalsData *data = (nsJSPrincipalsData *) aPrincipals; - - return (PRBool)(nsnull != data->principalsArrayRef || - gUnknownOriginStr.Equals(aPrincipals->codebase)); -} - -void -nsJSSecurityManager::PrintPrincipalsToConsole(JSContext *aCx, JSPrincipals *aPrincipals) -{ - void *principalsArray; - nsIPrincipal *principal; - char *vendor; - PRUint32 i, count; - static char emptyStr[] = "\n"; - - principalsArray = aPrincipals->getPrincipalArray(aCx, aPrincipals); - - if (principalsArray == nsnull) { - PrintToConsole(emptyStr); - return; - } - - PrintToConsole("[\n"); - mCapsManager->GetPrincipalArraySize(principalsArray, &count); - for (i = 0; i < count; i++) { - mCapsManager->GetPrincipalArrayElement(principalsArray, i, &principal); - mCapsManager->GetVendor(principal, &vendor); - if (vendor == nsnull) { - JS_ReportOutOfMemory(aCx); - return; - } - PrintToConsole(vendor); - PrintToConsole(",\n"); - } - PrintToConsole("]\n"); -} - -void -nsJSSecurityManager::InvalidateCertPrincipals(JSContext *aCx, JSPrincipals *aPrincipals) -{ - nsJSPrincipalsData *data = (nsJSPrincipalsData*)aPrincipals; - - if (data->principalsArrayRef) { - PrintToConsole("Invalidating certificate principals in "); - PrintPrincipalsToConsole(aCx, aPrincipals); - mCapsManager->FreePrincipalArray((void*)(data->principalsArrayRef)); - data->principalsArrayRef = nsnull; - } - data->signedness = HAS_UNSIGNED_SCRIPTS; -} - -char* -nsJSSecurityManager::FindOriginURL(JSContext *aCx, JSObject *aGlobal) -{ - nsISupports *tmp1, *tmp2; - nsIScriptGlobalObjectData* globalData = nsnull; - nsAutoString urlString; - - tmp1 = (nsISupports*)JS_GetPrivate(aCx, aGlobal); - if (nsnull != tmp1 && - NS_OK == tmp1->QueryInterface(kIScriptGlobalObjectDataIID, (void**)&globalData)) { - globalData->GetOrigin(&urlString); - } - - if (urlString.Length() == 0) { - /* Must be a new, empty window? Use running origin. */ - tmp2 = (nsISupports*)JS_GetPrivate(aCx, JS_GetGlobalObject(aCx)); - - /* Compare running and current to avoid infinite recursion. */ - if (tmp1 == tmp2) { - urlString = gUnknownOriginStr; - } - else if (nsnull != tmp2 && - NS_OK == tmp2->QueryInterface(kIScriptGlobalObjectDataIID, (void**)&globalData)) { - globalData->GetOrigin(&urlString); - } - } - NS_IF_RELEASE(globalData); - - return urlString.ToNewCString(); -} - -PRBool -nsJSSecurityManager::CanExtendTrust(JSContext *aCx, void *aFrom, void *aTo) -{ - if (aFrom == nsnull || aTo == nsnull) { - return PR_FALSE; - } - if (aFrom == aTo) { - return PR_TRUE; - } - - PRBool canExtend; - mCapsManager->CanExtendTrust(aFrom, aTo, &canExtend); - - return canExtend; -} - -PRUint32 -nsJSSecurityManager::GetPrincipalsCount(JSContext *aCx, JSPrincipals *aPrincipals) -{ - void *principalArray; - PRUint32 count; - - principalArray = aPrincipals->getPrincipalArray(aCx, aPrincipals); - if (nsnull == principalArray) { - return 0; - } - - mCapsManager->GetPrincipalArraySize(principalArray, &count); - return count; -} - -char * -nsJSSecurityManager::GetJavaCodebaseFromOrigin(const char *origin) -{ - /* Remove filename part. */ - char *result = PL_strdup(origin); - if (result) { - char *slash = PL_strrchr(result, '/'); - if (slash && slash > result && slash[-1] != '/') - slash[1] = '\0'; - } - return result; -} - - - -#ifdef DO_JAVA_STUFF -/* - -PR_PUBLIC_API(char *) -LM_LoadFromZipFile(void *zip, char *fn) -{ - struct stat st; - char* data; - - if (!ns_zip_stat((ns_zip_t *)zip, fn, &st)) { - return nsnull; - } - if ((data = malloc((size_t)st.st_size + 1)) == 0) { - return nsnull; - } - if (!ns_zip_get((ns_zip_t *)zip, fn, data, st.st_size)) { - PR_Free(data); - return nsnull; - } - data[st.st_size] = '\0'; - return data; -} - -extern char * -LM_ExtractFromPrincipalsArchive(JSPrincipals *principals, char *name, - uint *length) -{ - nsJSPrincipalsData *data = (nsJSPrincipalsData *) principals; - char *result = nsnull; - - result = LM_LoadFromZipFile(data->zip, name); - *length = result ? PL_strlen(result) : 0; - - return result; -} - -extern PRBool -LM_SetUntransformedSource(JSPrincipals *principals, char *original, - char *transformed) -{ - nsJSPrincipalsData *data = (nsJSPrincipalsData *) principals; - - NS_ASSERTION(data->untransformed == nsnull); - data->untransformed = PL_strdup(original); - if (data->untransformed == nsnull) - return PR_FALSE; - data->transformed = PL_strdup(transformed); - if (data->transformed == nsnull) - return PR_FALSE; - return PR_TRUE; -} - - -JSPrincipals * PR_CALLBACK -LM_GetJSPrincipalsFromJavaCaller(JSContext *aCx, void *principalsArray, void *pNSISecurityContext) -{ - setupJSCapsCallbacks(); - if (principalsArray == nsnull) - return nsnull; - - return newJSPrincipalsFromArray(aCx, principalsArray, pNSISecurityContext); -} - -static JSPrincipals * -newJSPrincipalsFromArray(JSContext *aCx, void *principalsArray, void *pNSISecurityContext) -{ - JSPrincipals *result; - nsIPrincipal *principal; - const char *codebase; - nsJSPrincipalsData *data; - uint32 i, count; - - setupJSCapsCallbacks(); - - count = nsCapsGetPrincipalArraySize(principalsArray); - if (count == 0) { - JS_ReportError(aCx, "No principals found for Java caller"); - return nsnull; - } - - codebase = nsnull; - for (i = count; i > 0; i--) { - principal = nsCapsGetPrincipalArrayElement(principalsArray, i-1); - if (nsCapsIsCodebaseExact(principal)) { - codebase = nsCapsPrincipalToString(principal); - break; - } - } - - result = NewJSPrincipals(nsnull, nsnull, (char *) codebase); - if (result == nsnull) { - JS_ReportOutOfMemory(aCx); - return nsnull; - } - - data = (nsJSPrincipalsData *) result; - data->principalsArrayRef = principalsArray; - data->pNSISecurityContext = pNSISecurityContext; - data->signedness = count == 1 && codebase - ? HAS_UNSIGNED_SCRIPTS - : HAS_SIGNED_SCRIPTS; - - return result; -} -*/ -#endif //DO_JAVA_STUFF - -#ifdef NEED_CANACCESSTARGETSTR -/* -int -findTarget(const char *target) -{ - int i=0; - for(i=0; iGetNativeContext(); - *aRetPrincipals = nsnull; - - if (NS_OK == aGlobal->QueryInterface(kIScriptObjectOwnerIID, (void**)&aGlobalObjOwner)) { - aGlobalObjOwner->GetScriptObject(aContext, (void**)&inner); - } - if (inner == nsnull) { - return NS_ERROR_FAILURE; - } - - if (NS_OK != GetContainerPrincipals(cx, inner, &containerPrincipals)) { - return NS_ERROR_FAILURE; - } - - containerData = (nsJSPrincipalsData *)containerPrincipals; - JSObject* container = inner; - - if (!aName && aPrincipals != containerPrincipals && aPrincipals) { - /* - * "name" argument omitted since it was specified when "principals" - * was created. Get it from "principals". - */ - aName = new nsString(data->name); - } -#if 0 - implicitName = nsnull; - if (!aName && data && data->signedness == HAS_SIGNED_SCRIPTS) { - /* - * Name is unspecified. Use the implicit name formed from the - * origin URL and the ordinal within the page. For example, the - * third implicit name on http://www.co.com/dir/mypage.html - * would be "_mypage2". - */ - char *url; - char *path; - - url = FindOriginURL(cx, inner); - if (!url) { - return nsnull; - } - path = *url? ParseURL(url, GET_PATH_PART) : nsnull; - if (path && *path) { - char *s; - s = PL_strrchr(path, '.'); - if (s) - *s = '\0'; - s = PL_strrchr(path, '/'); - //XXXGlobalApi - implicitName = PR_sprintf_append(nsnull, "_%s%d", s ? s+1 : path, - aGlobal->signature_ordinal++); - name = implicitName; - } - PR_FREEIF(path); - delete url; - } -#endif - untransformed = nsnull; - if (data && data->untransformed && data->transformed == aSrc) { - /* Perform verification on original source. */ - aSrc = untransformed = data->untransformed; - data->untransformed = nsnull; - PR_Free(data->transformed); - data->transformed = nsnull; - } - - PR_FREEIF(untransformed); - aSrc = nsnull; - PR_FREEIF(implicitName); - aName = nsnull; - - /* - * Now that we've attempted verification, we need to set the appropriate - * level of signedness based on whether verification succeeded. - * We avoid setting signedness if principals is the same as container - * principals (i.e., we "inherited" the principals from a script earlier - * in the page) and we are not in a subcontainer of the container where - * the principals were found. In that case we will create a new set of - * principals for the inner container. - */ - if (data && !(aPrincipals == containerPrincipals && container != inner)) { - data->signedness = HAS_UNSIGNED_SCRIPTS; - } - -#ifdef EARLY_ACCESS_STUFF - /* - //XXXGlobalApi - if (verified && aGlobal->early_access_list && - !CheckEarlyAccess(cx, aGlobal, principals)) - { - return nsnull; - } - */ -#endif - - if (!verified) { - //Add pref check of "javascript.all.unsigngedExecution" - if (0) {//!GetUnsignedExecutionEnabled()) { - /* Execution of unsigned scripts disabled. Return now. */ - return NS_ERROR_FAILURE; - } - /* No cert principals; try codebase principal */ - if (!aPrincipals || aPrincipals == containerPrincipals) { - if (container == inner || - containerData->signedness == HAS_UNSIGNED_SCRIPTS) { - aPrincipals = containerPrincipals; - data = (nsJSPrincipalsData *)aPrincipals; - } - else { - /* Just put restricted principals in inner */ - nsAutoString contCodebase(containerPrincipals->codebase); - - NewJSPrincipals(nsnull, nsnull, - &contCodebase, &aPrincipals); - if (!aPrincipals) { - JS_ReportOutOfMemory(cx); - return NS_ERROR_FAILURE; - } - data = (nsJSPrincipalsData *)aPrincipals; - } - } - InvalidateCertPrincipals(cx, aPrincipals); - -#ifdef EARLY_ACCESS_STUFF - /* - //XXXGlobalApi - if (aGlobal->early_access_list && !GetCrossOriginEnabled() && - !CheckEarlyAccess(cx, aGlobal, principals)) - { - return nsnull; - } - */ -#endif - - if (container == inner) { - InvalidateCertPrincipals(cx, containerPrincipals); - - /* compare codebase principals */ - if (!SameOrigins(cx, containerPrincipals->codebase, - aPrincipals->codebase)) { - /* Codebases don't match; evaluate under different - principals than container */ - *aRetPrincipals = aPrincipals; - return NS_OK; - } - /* Codebases match */ - *aRetPrincipals = containerPrincipals; - return NS_OK; - } - - /* Just put restricted principals in inner */ - SetContainerPrincipals(cx, inner, aPrincipals); - *aRetPrincipals = aPrincipals; - return NS_OK; - } - - if (!PrincipalsEqual(cx, aPrincipals, containerPrincipals)) { - /* We have two unequal sets of principals. */ - if (containerData->signedness == HAS_NO_SCRIPTS && - SameOrigins(cx, aPrincipals->codebase, - containerPrincipals->codebase)) { - /* - * Principals are unequal because we have container principals - * carrying only a codebase, and the principals of this script - * that carry cert principals as well. - */ - SetContainerPrincipals(cx, container, aPrincipals); - *aRetPrincipals = aPrincipals; - return NS_OK; - } - if (inner == container) { - if (containerData->signedness == HAS_NO_SCRIPTS) { - SetContainerPrincipals(cx, container, aPrincipals); - *aRetPrincipals = aPrincipals; - return NS_OK; - } - /* - * Intersect principals and container principals, - * modifying the container principals. - */ - PrintToConsole("Intersecting principals "); - PrintPrincipalsToConsole(cx, containerPrincipals); - PrintToConsole("with "); - PrintPrincipalsToConsole(cx, aPrincipals); - if (!IntersectPrincipals(cx, containerPrincipals, - aPrincipals)) { - return NS_OK; - } - PrintToConsole("yielding "); - PrintPrincipalsToConsole(cx, containerPrincipals); - } - else { - /* - * Store the disjoint set of principals in the - * innermost container - */ - SetContainerPrincipals(cx, inner, aPrincipals); - *aRetPrincipals = aPrincipals; - return NS_OK; - } - - } - *aRetPrincipals = containerPrincipals; - return NS_OK; -} - -#ifdef EARLY_ACCESS_STUFF -/* -PRBool -nsJSSecurityManager::CheckEarlyAccess(JSContext* aCx, JSPrincipals *aPrincipals) -{ - nsJSPrincipalsData *data; - JSPrincipalsList *p; - PRBool ok; - - data = (nsJSPrincipalsData*)aPrincipals; - ok = PR_TRUE; - - for (p = (JSPrincipalsList *) decoder->early_access_list; p; p = p->next) { - if (data->signedness == HAS_SIGNED_SCRIPTS) { - if (!CanExtendTrust(aCx, - aPrincipals->getPrincipalArray(aCx, aPrincipals), - p->principals->getPrincipalArray(aCx, p->principals))) { - JS_ReportError(aCx, container_error_message, - p->principals->codebase); - ok = PR_FALSE; - break; - } - } - else { - if (!SameOrigins(aCx, p->principals->codebase, - aPrincipals->codebase)) { - // Check to see if early access violated the cross-origin - // container check. - JS_ReportError(aCx, access_error_message, - p->principals->codebase); - ok = PR_FALSE; - break; - } - } - } - DestroyPrincipalsList(aCx, decoder->early_access_list); - decoder->early_access_list = nsnull; - return ok; -} -*/ -#endif - -/* - * Compute the intersection of "principals" and "other", saving in - * "principals". Return true iff the intersection is nonnsnull. - */ -PRBool -nsJSSecurityManager::IntersectPrincipals(JSContext *aCx, JSPrincipals *aPrincipals, - JSPrincipals *aNewPrincipals) -{ - nsJSPrincipalsData* data = (nsJSPrincipalsData*)aPrincipals; - nsJSPrincipalsData* newData = (nsJSPrincipalsData*)aNewPrincipals; - - NS_ASSERTION(data->signedness != HAS_NO_SCRIPTS, "Signed page with no scripts"); - NS_ASSERTION(newData->signedness != HAS_NO_SCRIPTS, "Signed page with no scripts"); - - if (!SameOrigins(aCx, aPrincipals->codebase, aNewPrincipals->codebase)) { - delete aPrincipals->codebase; - aPrincipals->codebase = gUnknownOriginStr.ToNewCString(); - if (aPrincipals->codebase == nsnull) { - return PR_FALSE; - } - } - - if (data->signedness == HAS_UNSIGNED_SCRIPTS || - newData->signedness == HAS_UNSIGNED_SCRIPTS) { - // No cert principals. Nonempty only if there is a codebase - // principal. - InvalidateCertPrincipals(aCx, aPrincipals); - return PR_TRUE; - } - // Compute the intersection. - void* principalArray = aPrincipals->getPrincipalArray(aCx, aPrincipals); - void* newPrincipalArray = aNewPrincipals->getPrincipalArray(aCx, aNewPrincipals); - - if (principalArray == nsnull || newPrincipalArray == nsnull) { - InvalidateCertPrincipals(aCx, aPrincipals); - return PR_TRUE; - } - - void* intersectArray; - mCapsManager->IntersectPrincipalArray(principalArray, - newPrincipalArray, - &intersectArray); - - if (nsnull == intersectArray) { - InvalidateCertPrincipals(aCx, aPrincipals); - return PR_TRUE; - } - - data->principalsArrayRef = intersectArray; - return PR_TRUE; -} - -PRBool -nsJSSecurityManager::PrincipalsEqual(JSContext *aCx, JSPrincipals *aPrinA, JSPrincipals *aPrinB) -{ - if (aPrinA == aPrinB) - return PR_TRUE; - - nsJSPrincipalsData *dataA, *dataB; - dataA = (nsJSPrincipalsData*)aPrinA; - dataB = (nsJSPrincipalsData*)aPrinB; - - if (dataA->signedness != dataB->signedness) - return PR_FALSE; - - void* arrayA = aPrinA->getPrincipalArray(aCx, aPrinA); - void* arrayB = aPrinB->getPrincipalArray(aCx, aPrinB); - - nsSetComparisonType prinCompare; - mCapsManager->ComparePrincipalArray(arrayA, arrayB, &prinCompare); - - return (PRBool)(nsSetComparisonType_Equal == prinCompare); -} - -/******************************************************************************* - * Glue code for JS stack crawling callbacks - ******************************************************************************/ - -nsJSFrameIterator * -nsJSSecurityManager::NewJSFrameIterator(void *aContext) -{ - JSContext *aCx = (JSContext *)aContext; - nsJSFrameIterator *result; - void *array; - - result = (nsJSFrameIterator*)PR_MALLOC(sizeof(nsJSFrameIterator)); - if (result == nsnull) { - return nsnull; - } - - if (aCx == nsnull) { - return nsnull; - } - - result->fp = nsnull; - result->cx = aCx; - result->fp = JS_FrameIterator(aCx, &result->fp); - array = result->fp - ? JS_GetFramePrincipalArray(aCx, result->fp) - : nsnull; - result->intersect = array; - result->sawEmptyPrincipals = - (result->intersect == nsnull && result->fp && - JS_GetFrameScript(aCx, result->fp)) - ? PR_TRUE : PR_FALSE; - - return result; -} - - -PRBool -nsJSSecurityManager::NextJSJavaFrame(struct nsJSFrameIterator *aIterator) -{ - void *current; - void *previous; - - if (aIterator->fp == 0) { - return PR_FALSE; - } - - current = JS_GetFramePrincipalArray(aIterator->cx, aIterator->fp); - if (current == nsnull) { - if (JS_GetFrameScript(aIterator->cx, aIterator->fp)) - aIterator->sawEmptyPrincipals = PR_TRUE; - } else { - void* arrayIntersect; - if (aIterator->intersect) { - previous = aIterator->intersect; - mCapsManager->IntersectPrincipalArray(current, previous, &arrayIntersect); - /* XXX: raman: should we do a free the previous principal Array */ - mCapsManager->FreePrincipalArray((void*)(aIterator->intersect)); - } - aIterator->intersect = current; - } - aIterator->fp = JS_FrameIterator(aIterator->cx, &aIterator->fp); - return aIterator->fp != nsnull; -} - -PRBool -nsJSSecurityManager::NextJSFrame(struct nsJSFrameIterator **aIterator) -{ - nsJSFrameIterator *iterator = *aIterator; - PRBool result = NextJSJavaFrame(iterator); - if (!result) { - if (iterator->intersect) { - mCapsManager->FreePrincipalArray((void*)(iterator->intersect)); - } - PR_Free(iterator); - *aIterator = nsnull; - } - return result; -} - -/** - * nsICapsSecurityCallbacks interface - */ - -NS_IMETHODIMP -nsJSSecurityManager::NewNSJSJavaFrameWrapper(void *aContext, struct nsFrameWrapper ** aWrapper) -{ - struct nsFrameWrapper *result; - - result = (struct nsFrameWrapper *)PR_MALLOC(sizeof(struct nsFrameWrapper)); - if (result == nsnull) { - return NS_ERROR_FAILURE; - } - - result->iterator = (void*)NewJSFrameIterator(aContext); - *aWrapper = result; - return NS_OK; -} - -NS_IMETHODIMP -nsJSSecurityManager::FreeNSJSJavaFrameWrapper(struct nsFrameWrapper *aWrapper) -{ - PR_FREEIF(aWrapper); - return NS_OK; -} - -NS_IMETHODIMP -nsJSSecurityManager::GetStartFrame(struct nsFrameWrapper *aWrapper) -{ - return NS_OK; -} - -NS_IMETHODIMP -nsJSSecurityManager::IsEndOfFrame(struct nsFrameWrapper *aWrapper, PRBool* aReturn) -{ - *aReturn = PR_FALSE; - - if ((aWrapper == nsnull) || (aWrapper->iterator == nsnull)) { - *aReturn = PR_TRUE; - } - return NS_OK; -} - -NS_IMETHODIMP -nsJSSecurityManager::IsValidFrame(struct nsFrameWrapper *aWrapper, PRBool* aReturn) -{ - *aReturn = (aWrapper->iterator != nsnull); - return NS_OK; -} - -NS_IMETHODIMP -nsJSSecurityManager::GetNextFrame(struct nsFrameWrapper *aWrapper, int *aDepth, void** aReturn) -{ - nsJSFrameIterator *iterator; - if (aWrapper->iterator == nsnull) { - return NS_ERROR_FAILURE; - } - iterator = (nsJSFrameIterator*)(aWrapper->iterator); - - if (!NextJSFrame(&iterator)) { - return NS_ERROR_FAILURE; - } - - (*aDepth)++; - *aReturn = aWrapper->iterator; - return NS_OK; -} - -NS_IMETHODIMP -nsJSSecurityManager::OJIGetPrincipalArray(struct nsFrameWrapper *aWrapper, void** aReturn) -{ - nsJSFrameIterator *iterator; - if (aWrapper->iterator == nsnull) { - return NS_ERROR_FAILURE; - } - iterator = (nsJSFrameIterator*)(aWrapper->iterator); - *aReturn = JS_GetFramePrincipalArray(iterator->cx, iterator->fp); - return NS_OK; -} - -NS_IMETHODIMP -nsJSSecurityManager::OJIGetAnnotation(struct nsFrameWrapper *aWrapper, void** aReturn) -{ - nsJSFrameIterator *iterator; - void *annotation; - void *current; - - if (aWrapper->iterator == nsnull) { - return NS_ERROR_FAILURE; - } - iterator = (nsJSFrameIterator*)(aWrapper->iterator); - - annotation = JS_GetFrameAnnotation(iterator->cx, iterator->fp); - if (annotation == nsnull) - return NS_ERROR_FAILURE; - - current = JS_GetFramePrincipalArray(iterator->cx, iterator->fp); - - if (iterator->sawEmptyPrincipals || current == nsnull || - (iterator->intersect && - !CanExtendTrust(iterator->cx, current, iterator->intersect))) - return NS_ERROR_FAILURE; - - *aReturn = annotation; - return NS_OK; -} - -NS_IMETHODIMP -nsJSSecurityManager::OJISetAnnotation(struct nsFrameWrapper *aWrapper, void *aPrivTable, void** aReturn) -{ - if (aWrapper->iterator) { - nsJSFrameIterator *iterator = (nsJSFrameIterator*)(aWrapper->iterator); - JS_SetFrameAnnotation(iterator->cx, iterator->fp, aPrivTable); - } - *aReturn = aPrivTable; - return NS_OK; } char * @@ -2108,9 +67,9 @@ nsJSSecurityManager::AddSecPolicyPrefix(JSContext *cx, char *pref_str) /* No site-specific policy. Get global policy name. */ if (NS_OK != mPrefs->CopyCharPref("javascript.security_policy", (char**)&policy_str)) - policy_str = PL_strcpy(policy_str, "default"); + policy_str = 0; } - if (policy_str) { //why can't this be default? && PL_strcasecmp(policy_str, "default") != 0) { + if (policy_str != 0 && PL_strcasecmp(policy_str, "default") != 0) { retval = PR_sprintf_append(NULL, "js_security.%s.%s", policy_str, pref_str); } @@ -2228,23 +187,21 @@ nsJSSecurityManager::CheckForPrivilege(JSContext *cx, char *prop_name, int priv_ JSBool priv = JS_TRUE; if(prop_name == NULL) { - return SCRIPT_SECURITY_NO_ACCESS; + return NS_SECURITY_FLAG_NO_ACCESS; } tmp_prop_name = AddSecPolicyPrefix(cx, prop_name); if(tmp_prop_name == NULL) { - return SCRIPT_SECURITY_NO_ACCESS; + return JS_TRUE; } - PRInt32 secLevel = SCRIPT_SECURITY_NO_ACCESS; + PRInt32 secLevel; if (NS_OK == mPrefs->GetIntPref(tmp_prop_name, &secLevel)) { - PR_FREEIF(tmp_prop_name); return secLevel; } - PR_FREEIF(tmp_prop_name); - return SCRIPT_SECURITY_ALL_ACCESS; + return NS_SECURITY_FLAG_NO_ACCESS; } static const char* continue_on_violation = "continue_on_access_violation"; @@ -2335,12 +292,12 @@ lm_GetObjectACL(JSContext *cx, JSObject *obj) fprintf(stderr, "*#*#*#*#* doc = %s #*#*#*#*\n", doc_str); if (PREF_CopyCharPref(doc_str, &acl) != PREF_OK) acl = 0; - PR_FREEIF(doc_str); + XP_FREEIF(doc_str); if (acl == 0) { // Get the default value acl = lm_GetObjectOriginURL(cx, obj); - if (acl == 0 || PL_strcmp(acl, lm_unknown_origin_str) == 0 + if (acl == 0 || XP_STRCMP(acl, lm_unknown_origin_str) == 0 #if 0 // ??? || (PL_strlen(origin) <= 1) #else // there really seem to be such! @@ -2353,7 +310,7 @@ lm_GetObjectACL(JSContext *cx, JSObject *obj) fflush(stderr); // Default ACL for object is protocol://host[:port]. - acl = ParseURL(acl, GET_PROTOCOL_PART | GET_HOST_PART); + acl = NET_ParseURL(acl, GET_PROTOCOL_PART | GET_HOST_PART); } fprintf(stderr, "ACL -> %s\n", acl); @@ -2390,14 +347,14 @@ CheckTrustedHosts(JSContext *cx, char *subjectOriginURL, char *objectOriginURL) } acl_len = sizeof(objectHostList); - PR_BZERO(objectHostList, acl_len); + XP_BZERO(objectHostList, acl_len); PREF_GetCharPref(hostlist, objectHostList, &acl_len); - acl_len = PL_strlen(objectHostList); + acl_len = XP_STRLEN(objectHostList); j = k = 0; while(j < acl_len) { k++; - PR_BZERO(substr, 1024); + XP_BZERO(substr, 1024); for(i = 0; (j < acl_len) && (objectHostList[j] != ','); j++) { if(!isspace(objectHostList[j])) { @@ -2406,7 +363,7 @@ CheckTrustedHosts(JSContext *cx, char *subjectOriginURL, char *objectOriginURL) } if(k % 2) { - if(PL_strcmp(substr, subjectOriginDomain)) { + if(XP_STRCMP(substr, subjectOriginDomain)) { no_match = JS_FALSE; continue; } @@ -2420,7 +377,7 @@ CheckTrustedHosts(JSContext *cx, char *subjectOriginURL, char *objectOriginURL) substr[i] = '\0'; - if(PL_strcmp(objectOriginDomain, substr) == 0) + if(XP_STRCMP(objectOriginDomain, substr) == 0) return JS_TRUE; @@ -2453,10 +410,12 @@ lm_CheckACL(JSContext *cx, JSObject *obj, JSTarget target) // Get the subject origin. sOrigin = lm_GetSubjectOriginURL(cx); + if (NET_URL_Type(sOrigin) == WYSIWYG_TYPE_URL) + sOrigin = LM_SkipWysiwygURLPrefix(sOrigin); // Object is always on its own ACL. oOrigin = lm_GetObjectOriginURL(cx, obj); - if (PL_strcmp(sOrigin, oOrigin) == 0) { + if (XP_STRCMP(sOrigin, oOrigin) == 0) { allow = JS_TRUE; goto done; } @@ -2468,10 +427,10 @@ lm_CheckACL(JSContext *cx, JSObject *obj, JSTarget target) // of ACL member against sOrigin. // First strip last part of sOrigin path. - subj = ParseURL(sOrigin, GET_PROTOCOL_PART | GET_HOST_PART | GET_PATH_PART); - if ((slash = PL_strrchr(subj, '/')) != 0) + subj = NET_ParseURL(sOrigin, GET_PROTOCOL_PART | GET_HOST_PART | GET_PATH_PART); + if ((slash = XP_STRRCHR(subj, '/')) != 0) *slash = '\0'; - acl = PL_strdup(objectACL); + acl = XP_STRDUP(objectACL); // Walk through the ACL to see whether the subject host/URL is in // the ACL. There are two styles of check: @@ -2486,47 +445,47 @@ lm_CheckACL(JSContext *cx, JSObject *obj, JSTarget target) char *prot; // Chop up list, trim leading spaces. - if ((nextmem = PL_strchr(aclmem, ' ')) != 0) + if ((nextmem = XP_STRCHR(aclmem, ' ')) != 0) *nextmem++ = '\0'; aclmem += strspn(aclmem, " "); - memlen = PL_strlen(aclmem); + memlen = XP_STRLEN(aclmem); // Decide which case we've got. - if ((prot = ParseURL(aclmem, GET_PROTOCOL_PART)) != 0 && *prot != '\0') { + if ((prot = NET_ParseURL(aclmem, GET_PROTOCOL_PART)) != 0 && *prot != '\0') { // URL case. Do prefix match, make sure we're at proper boundaries. - if ( PL_strncmp(subj, aclmem, memlen) == 0 + if ( XP_STRNCMP(subj, aclmem, memlen) == 0 && ( subj[memlen] == '\0' // exact match || aclmem[memlen-1] == '/' // ACL ends with / || subj[memlen] == '/' // ACL doesn't, but subj starts ) ) { allow = JS_TRUE; - PR_Free(prot); + XP_FREE(prot); break; } } else { // Host-only case. - PR_FREEIF(prot); + XP_FREEIF(prot); if (subjhost == 0) - subjhost = ParseURL(sOrigin, GET_HOST_PART); - if ((allow = (PL_strcasecmp(subjhost, aclmem) == 0)) != 0) + subjhost = NET_ParseURL(sOrigin, GET_HOST_PART); + if ((allow = (XP_STRCASECMP(subjhost, aclmem) == 0)) != 0) break; } } - PR_FREEIF(subjhost); + XP_FREEIF(subjhost); if(allow == JS_FALSE) { char *err_mesg = PR_smprintf("Access disallowed from scripts at %s to documents at %s", sOrigin, lm_GetObjectOriginURL(cx,obj)); JS_ReportError(cx, err_mesg); - PR_FREEIF(err_mesg); + XP_FREEIF(err_mesg); } - PR_FREEIF(subj); - PR_FREEIF(acl); + XP_FREEIF(subj); + XP_FREEIF(acl); done:; fprintf(stderr, "-- returns %s\n", allow == JS_TRUE ? "true" : "false"); @@ -2549,9 +508,9 @@ lm_NotifyUserAboutACLExpansion(JSContext *cx) return NULL; uhl_len = sizeof(untrustedHostsBuf); - PR_BZERO(untrustedHostsBuf, uhl_len); + XP_BZERO(untrustedHostsBuf, uhl_len); PREF_GetCharPref(pref, untrustedHostsBuf, &uhl_len); - PR_FREEIF(pref); + XP_FREEIF(pref); if(!untrustedHostsBuf[0]) return NULL; @@ -2567,7 +526,7 @@ lm_NotifyUserAboutACLExpansion(JSContext *cx) uhl_len = PL_strlen(untrustedHostsBuf); j = 0; while(j < uhl_len) { - PR_BZERO(substr, 1024); + XP_BZERO(substr, 1024); for(i = 0; (j < uhl_len) && (untrustedHostsBuf[j] != ','); j++) { if(!isspace(untrustedHostsBuf[j])) { @@ -2581,7 +540,7 @@ lm_NotifyUserAboutACLExpansion(JSContext *cx) substr[i] = '\0'; - if(PL_strcmp(substr, subjectOriginDomain) == 0) { + if(XP_STRCMP(substr, subjectOriginDomain) == 0) { char *message_str = PR_smprintf("Script from untrusted domain: %s trying to expand ACL\n Allow?", subjectOriginDomain); return message_str; } @@ -2617,8 +576,8 @@ lm_CheckPrivateTag(JSContext *cx, JSObject *obj, jsval id) // If the subjectURL and objectURL don't match, stop here if ( subjectOrigin != 0 && objectOrigin != 0 - && PL_strcmp(subjectOrigin, objectOrigin) == 0 - && PL_strcmp(subjectOrigin, lm_unknown_origin_str) != 0 + && XP_STRCMP(subjectOrigin, objectOrigin) == 0 + && XP_STRCMP(subjectOrigin, lm_unknown_origin_str) != 0 ) return JS_FALSE; @@ -2640,10 +599,10 @@ lm_CheckPrivateTag(JSContext *cx, JSObject *obj, jsval id) // Now check for private tag on composite objects obj = parent; - PR_Free(name); + XP_FREE(name); name = lm_GetPrivateName_obj(obj); } - PR_Free(name); + XP_FREE(name); return JS_FALSE; } */ @@ -2668,7 +627,7 @@ nsJSSecurityManager::ParseURL (const char *url, int parts_requested) if(colon) { char val = *(colon+1); *(colon+1) = '\0'; - rv = SACopy(rv, url); + SACopy(rv, url); *(colon+1) = val; /* If the user wants more url info, tack on extra slashes. */ @@ -2676,11 +635,11 @@ nsJSSecurityManager::ParseURL (const char *url, int parts_requested) (parts_requested & GET_USERNAME_PART) || (parts_requested & GET_PASSWORD_PART)) { if( *(colon+1) == '/' && *(colon+2) == '/') { - rv = SACat(rv, "//"); + SACat(rv, "//"); } /* If there's a third slash consider it file:/// and tack on the last slash. */ if ( *(colon+3) == '/' ) { - rv = SACat(rv, "/"); + SACat(rv, "/"); } } } @@ -2701,17 +660,17 @@ nsJSSecurityManager::ParseURL (const char *url, int parts_requested) if ( (passwordColon = PL_strchr(colon+3, ':')) != NULL) { *passwordColon = '\0'; } - rv = SACat(rv, colon+3); + SACat(rv, colon+3); /* Get the password if one exists */ if (parts_requested & GET_PASSWORD_PART) { if (passwordColon) { - rv = SACat(rv, ":"); - rv = SACat(rv, passwordColon+1); + SACat(rv, ":"); + SACat(rv, passwordColon+1); } } if (parts_requested & GET_HOST_PART) { - rv = SACat(rv, "@"); + SACat(rv, "@"); } if (passwordColon) { *passwordColon = ':'; @@ -2765,12 +724,12 @@ nsJSSecurityManager::ParseURL (const char *url, int parts_requested) *cp = '\0'; - rv = SACat(rv, host); + SACat(rv, host); *cp = old_char; } else { - rv = SACat(rv, host); + SACat(rv, host); } if(slash) { @@ -2813,7 +772,7 @@ nsJSSecurityManager::ParseURL (const char *url, int parts_requested) *hash_mark = '\0'; } - rv = SACat(rv, slash); + SACat(rv, slash); if(ques_mark) { *ques_mark = '?'; @@ -2836,7 +795,7 @@ nsJSSecurityManager::ParseURL (const char *url, int parts_requested) *ques_mark = '\0'; } - rv = SACat(rv, hash_mark); + SACat(rv, hash_mark); if(ques_mark) { *ques_mark = '?'; @@ -2854,7 +813,7 @@ nsJSSecurityManager::ParseURL (const char *url, int parts_requested) *hash_mark = '\0'; } - rv = SACat(rv, ques_mark); + SACat(rv, ques_mark); if(hash_mark) { *hash_mark = '#'; @@ -2865,7 +824,7 @@ nsJSSecurityManager::ParseURL (const char *url, int parts_requested) /* copy in a null string if nothing was copied in */ if(!rv) { - rv = SACopy(rv, ""); + SACopy(rv, ""); } return rv; @@ -2918,6 +877,8 @@ nsJSSecurityManager::SACat (char *destination, const char *source) return destination; } + + extern "C" NS_DOM nsresult NS_NewScriptSecurityManager(nsIScriptSecurityManager ** aInstancePtrResult) { nsIScriptSecurityManager* it = new nsJSSecurityManager(); diff --git a/mozilla/dom/src/base/nsJSSecurityManager.h b/mozilla/dom/src/base/nsJSSecurityManager.h index ed9ad4699b2..27db31aa3d9 100644 --- a/mozilla/dom/src/base/nsJSSecurityManager.h +++ b/mozilla/dom/src/base/nsJSSecurityManager.h @@ -19,52 +19,18 @@ #define nsJSSecurityManager_h___ #include "nsIScriptSecurityManager.h" -#include "nsICapsSecurityCallbacks.h" #include "nsIScriptContext.h" #include "jsapi.h" -#include "jsdbgapi.h" -class nsICapsManager; class nsIPref; -typedef struct nsJSFrameIterator { - JSStackFrame *fp; - JSContext *cx; - void *intersect; - PRBool sawEmptyPrincipals; -} nsJSFrameIterator; - -enum Signedness { - HAS_NO_SCRIPTS, - HAS_UNSIGNED_SCRIPTS, - HAS_SIGNED_SCRIPTS -}; - -typedef struct nsJSPrincipalsData { - JSPrincipals principals; - void* principalsArrayRef; - nsIURI *url; - char* name; - void* zip; //ns_zip_t - uint32 externalCapturePrincipalsCount; - nsString* untransformed; - nsString* transformed; - PRBool needUnlock; - char* codebaseBeforeSettingDomain; - enum Signedness signedness; - void* pNSISecurityContext; -// nsJSSecurityManager* secManager; -} nsJSPrincipalsData; - -class nsJSSecurityManager : public nsIScriptSecurityManager, - public nsICapsSecurityCallbacks { +class nsJSSecurityManager : public nsIScriptSecurityManager { public: nsJSSecurityManager(); virtual ~nsJSSecurityManager(); NS_DECL_ISUPPORTS - //nsIScriptSecurityManager interface NS_IMETHOD Init(); NS_IMETHOD CheckScriptAccess(nsIScriptContext* aContext, @@ -72,87 +38,7 @@ public: const char* aProp, PRBool* aResult); - //XXX From lib/libmocha/lm.h - NS_IMETHOD GetSubjectOriginURL(JSContext *aCx, nsString* aOrigin); - NS_IMETHOD GetObjectOriginURL(JSContext *aCx, JSObject *object, nsString* aOrigin); - NS_IMETHOD GetPrincipalsFromStackFrame(JSContext *aCx, JSPrincipals** aPrincipals); - NS_IMETHOD GetCompilationPrincipals(nsIScriptContext *aContext, nsIScriptGlobalObject* aGlobal, - JSPrincipals *aLayoutPrincipals, JSPrincipals** aPrincipals); - NS_IMETHOD CanAccessTarget(JSContext *aCx, eJSTarget target, PRBool* aReturn); - NS_IMETHOD CheckPermissions(JSContext *aCx, JSObject *aObj, eJSTarget target, PRBool* aReturn); - NS_IMETHOD CheckContainerAccess(JSContext *aCx, JSObject *aObj, eJSTarget aTarget, PRBool* aReturn); - NS_IMETHOD GetContainerPrincipals(JSContext *aCx, JSObject *aContainer, JSPrincipals** aPrincipals); - NS_IMETHOD SetContainerPrincipals(JSContext *aCx, JSObject *aContainer, JSPrincipals* aPrincipals); - NS_IMETHOD CanCaptureEvent(JSContext *aCx, JSFunction *aFun, JSObject *aEventTarget, PRBool* aReturn); - NS_IMETHOD SetExternalCapture(JSContext *aCx, JSPrincipals* aPrincipals, PRBool aBool); - NS_IMETHOD CheckSetParentSlot(JSContext *aCx, JSObject *aObj, jsval id, jsval *vp, PRBool* aReturn); - NS_IMETHOD SetDocumentDomain(JSContext *aCx, JSPrincipals *principals, - nsString* newDomain, PRBool* aReturn); - NS_IMETHOD DestroyPrincipalsList(JSContext *aCx, nsJSPrincipalsList *list); - //XXX End from lib/libmocha/lm.h - - //XXX From include/libmocha.h - NS_IMETHOD NewJSPrincipals(nsIURI *aURL, nsString* aName, nsString* aCodebase, JSPrincipals** aPrincipals); -#ifdef DO_JAVA_STUFF - NS_IMETHOD ExtractFromPrincipalsArchive(JSPrincipals *aPrincipals, char *aName, - uint *aLength, char** aReturn); - NS_IMETHOD SetUntransformedSource(JSPrincipals *principals, char *original, - char *transformed, PRBool* aReturn); - NS_IMETHOD GetJSPrincipalsFromJavaCaller(JSContext *aCx, void *principalsArray, void *pNSISecurityContext, JSPrincipals** aPrincipals); -#endif -#if 0 - NS_IMETHOD CanAccessTargetStr(JSContext *aCx, const char *target, PRBool* aReturn); -#endif - NS_IMETHOD RegisterPrincipals(nsIScriptContext *aContext, nsIScriptGlobalObject* aGlobal, JSPrincipals *aPrincipals, - nsString* aName, nsString* aSrc, JSPrincipals** aRetPrincipals); - //XXX End from include/libmocha.h - - - //nsICapsSecurityCallbacks interface - NS_IMETHOD NewNSJSJavaFrameWrapper(void *aContext, struct nsFrameWrapper ** aWrapper); - NS_IMETHOD FreeNSJSJavaFrameWrapper(struct nsFrameWrapper *aWrapper); - NS_IMETHOD GetStartFrame(struct nsFrameWrapper *aWrapper); - NS_IMETHOD IsEndOfFrame(struct nsFrameWrapper *aWrapper, PRBool* aReturn); - NS_IMETHOD IsValidFrame(struct nsFrameWrapper *aWrapper, PRBool* aReturn); - NS_IMETHOD GetNextFrame(struct nsFrameWrapper *aWrapper, int *aDepth, void** aReturn); - NS_IMETHOD OJIGetPrincipalArray(struct nsFrameWrapper *aWrapper, void** aReturn); - NS_IMETHOD OJIGetAnnotation(struct nsFrameWrapper *aWrapper, void** aReturn); - NS_IMETHOD OJISetAnnotation(struct nsFrameWrapper *aWrapper, void *aPrivTable, void** aReturn); - private: - void PrintToConsole(const char *data); - void PrintPrincipalsToConsole(JSContext *cx, JSPrincipals *principals); - - PRUint32 GetPrincipalsCount(JSContext *aCx, JSPrincipals *aPrincipals); - PRBool PrincipalsCanAccessTarget(JSContext *cx, eJSTarget target); - void InvalidateCertPrincipals(JSContext *cx, JSPrincipals *principals); - - //Helper funcs for RegisterPrincipals -#ifdef EARLY_ACCESS_STUFF - PRBool CheckEarlyAccess(MochaDecoder *decoder, JSPrincipals *principals); -#endif - PRBool IntersectPrincipals(JSContext *aCx, JSPrincipals *principals, - JSPrincipals *newPrincipals); - PRBool PrincipalsEqual(JSContext *aCx, JSPrincipals *aA, JSPrincipals *aB); - - PRBool IsExternalCaptureEnabled(JSContext *cx, JSPrincipals *principals); - PRBool CanExtendTrust(JSContext *cx, void *from, void *to); - char* GetJavaCodebaseFromOrigin(const char *origin); - - nsString* GetOriginFromSourceURL(nsString* sourceURL); - char* FindOriginURL(JSContext *aCx, JSObject *aGlobal); - - PRBool SameOrigins(JSContext *aCx, const char* aOrigin1, const char* aOrigin2); - PRBool SameOriginsStr(JSContext *aCx, nsString* aOrigin1, nsString* aOrigin2); - nsString* GetCanonicalizedOrigin(JSContext *cx, nsString* aUrlString); - - // Glue code for JS stack crawling callbacks - nsJSFrameIterator* NewJSFrameIterator(void *aContext); - PRBool NextJSJavaFrame(struct nsJSFrameIterator *aIterator); - PRBool NextJSFrame(struct nsJSFrameIterator **aIterator); - - void InitCaps(void); - //Helper funcs char* AddSecPolicyPrefix(JSContext *cx, char *pref_str); char* GetSitePolicy(const char *org); @@ -167,9 +53,15 @@ private: //Local vars nsIPref* mPrefs; - nsICapsManager* mCapsManager; }; + +#define NS_SECURITY_FLAG_SAME_ORIGINS 0x0001 +#define NS_SECURITY_FLAG_NO_ACCESS 0x0002 +#define NS_SECURITY_FLAG_READ_ONLY 0x0004 +//xxx break into privilege levels +#define NS_SECURITY_FLAG_SIGNED 0x0008 + //XXX temporarily bit flags for determining what we want to parse from the URL #define GET_ALL_PARTS 127 #define GET_PASSWORD_PART 64 diff --git a/mozilla/dom/src/build/Makefile.in b/mozilla/dom/src/build/Makefile.in index eab061fe456..95d350a6e1f 100644 --- a/mozilla/dom/src/build/Makefile.in +++ b/mozilla/dom/src/build/Makefile.in @@ -29,7 +29,7 @@ LIBRARY_NAME = jsdom MODULE=dom -REQUIRES=xpcom raptor caps oji +REQUIRES=xpcom raptor CPPSRCS=nsDOMFactory.cpp \ nsHTMLTagsEnums.cpp \ diff --git a/mozilla/dom/src/build/makefile.win b/mozilla/dom/src/build/makefile.win index 22526e9b85f..98c1ab99e16 100644 --- a/mozilla/dom/src/build/makefile.win +++ b/mozilla/dom/src/build/makefile.win @@ -20,7 +20,7 @@ DEPTH=..\..\.. DEFINES=-D_IMPL_NS_DOM MODULE=raptor -REQUIRES=xpcom raptor dom caps oji +REQUIRES=xpcom raptor dom CPPSRCS = nsDOMFactory.cpp \ nsHTMLTagsEnums.cpp \ @@ -57,8 +57,6 @@ MISCDEP = \ $(DIST)\lib\xpcom.lib \ $(DIST)\lib\plds3.lib \ $(DIST)\lib\plc3.lib \ - $(DIST)\lib\caps.lib \ - $(DIST)\lib\oji.lib \ $(LIBNSPR) LCFLAGS = \ @@ -85,8 +83,6 @@ LLIBS= \ $(DIST)\lib\xpcom.lib \ $(DIST)\lib\plds3.lib \ $(DIST)\lib\plc3.lib \ - $(DIST)\lib\caps.lib \ - $(DIST)\lib\oji.lib \ $(LIBNSPR) include <$(DEPTH)\config\rules.mak> diff --git a/mozilla/layout/events/src/nsEventListenerManager.cpp b/mozilla/layout/events/src/nsEventListenerManager.cpp index dd5ce86aa55..416abf79bef 100644 --- a/mozilla/layout/events/src/nsEventListenerManager.cpp +++ b/mozilla/layout/events/src/nsEventListenerManager.cpp @@ -38,14 +38,11 @@ #include "nsIScriptEventListener.h" #include "nsDOMEventsIIDs.h" #include "prmem.h" -#include "nsIScriptGlobalObject.h" -#include "nsIScriptGlobalObjectData.h" static NS_DEFINE_IID(kIEventListenerManagerIID, NS_IEVENTLISTENERMANAGER_IID); static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID); static NS_DEFINE_IID(kIDOMEventIID, NS_IDOMEVENT_IID); static NS_DEFINE_IID(kIScriptEventListenerIID, NS_ISCRIPTEVENTLISTENER_IID); -static NS_DEFINE_IID(kIScriptGlobalObjectDataIID, NS_ISCRIPTGLOBALOBJECTDATA_IID); nsEventListenerManager::nsEventListenerManager() { @@ -416,20 +413,6 @@ nsresult nsEventListenerManager::AddScriptEventListener(nsIScriptContext* aConte nsIAtom *aName, const nsString& aFunc, REFNSIID aIID) { JSObject *mScriptObject; - nsIScriptGlobalObject *global; - nsIScriptGlobalObjectData *globalData; - JSPrincipals* principals = nsnull; - - global = aContext->GetGlobalObject(); - if (global && NS_SUCCEEDED(global->QueryInterface(kIScriptGlobalObjectDataIID, (void**)&globalData))) { - if (NS_FAILED(globalData->GetPrincipals((void**)&principals))) { - NS_RELEASE(global); - NS_RELEASE(globalData); - return NS_ERROR_FAILURE; - } - NS_RELEASE(globalData); - } - NS_IF_RELEASE(global); if (NS_OK == aScriptObjectOwner->GetScriptObject(aContext, (void**)&mScriptObject)) { JSContext* mJSContext = (JSContext*)aContext->GetNativeContext(); @@ -440,9 +423,8 @@ nsresult nsEventListenerManager::AddScriptEventListener(nsIScriptContext* aConte mName.ToLowerCase(mLowerName); mCharName = mLowerName.ToNewCString(); - if (nsnull != mCharName) { - JS_CompileUCFunctionForPrincipals(mJSContext, mScriptObject, principals, mCharName, + JS_CompileUCFunction(mJSContext, mScriptObject, mCharName, 1, mEventArgv, (jschar*)aFunc.GetUnicode(), aFunc.Length(), nsnull, 0); delete[] mCharName;