From e4d8cf285ce51219bdb4f423abe60be3db4fbec9 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Thu, 7 Jun 2012 14:28:22 +0200 Subject: [PATCH] Bug 754202 - Remove mContextPrincipal usage from within nsScriptSecurityManager. r=mrbkap --- caps/include/nsScriptSecurityManager.h | 12 ------ caps/src/nsScriptSecurityManager.cpp | 59 ++------------------------ 2 files changed, 4 insertions(+), 67 deletions(-) diff --git a/caps/include/nsScriptSecurityManager.h b/caps/include/nsScriptSecurityManager.h index f7b94fabcd0..84948f351b8 100644 --- a/caps/include/nsScriptSecurityManager.h +++ b/caps/include/nsScriptSecurityManager.h @@ -553,17 +553,6 @@ private: PrintPolicyDB(); #endif - struct ContextPrincipal { - ContextPrincipal(ContextPrincipal *next, JSContext *cx, - JSStackFrame *fp, nsIPrincipal *principal) - : mNext(next), mCx(cx), mFp(fp), mPrincipal(principal) {} - - ContextPrincipal *mNext; - JSContext *mCx; - JSStackFrame *mFp; - nsCOMPtr mPrincipal; - }; - // JS strings we need to clean up on shutdown static jsid sEnabledID; @@ -576,7 +565,6 @@ private: nsCOMPtr mSystemPrincipal; nsCOMPtr mSystemCertificate; - ContextPrincipal *mContextPrincipals; nsInterfaceHashtable mPrincipals; bool mPrefInitialized; bool mIsJavaScriptEnabled; diff --git a/caps/src/nsScriptSecurityManager.cpp b/caps/src/nsScriptSecurityManager.cpp index 15d10289eb5..4d28e87f2b1 100644 --- a/caps/src/nsScriptSecurityManager.cpp +++ b/caps/src/nsScriptSecurityManager.cpp @@ -2222,24 +2222,10 @@ nsScriptSecurityManager::GetPrincipalAndFrame(JSContext *cx, if (cx) { - JSStackFrame *target = nsnull; - nsIPrincipal *targetPrincipal = nsnull; - for (ContextPrincipal *cp = mContextPrincipals; cp; cp = cp->mNext) - { - if (cp->mCx == cx) - { - target = cp->mFp; - targetPrincipal = cp->mPrincipal; - break; - } - } - // Get principals from innermost JavaScript frame. JSStackFrame *fp = nsnull; // tell JS_FrameIterator to start at innermost for (fp = JS_FrameIterator(cx, &fp); fp; fp = JS_FrameIterator(cx, &fp)) { - if (fp == target) - break; nsIPrincipal* result = GetFramePrincipal(cx, fp, rv); if (result) { @@ -2249,25 +2235,6 @@ nsScriptSecurityManager::GetPrincipalAndFrame(JSContext *cx, } } - // If targetPrincipal is non-null, then it means that someone wants to - // clamp the principals on this context to this principal. Note that - // fp might not equal target here (fp might be null) because someone - // could have set aside the frame chain in the meantime. - if (targetPrincipal) - { - if (fp && fp == target) - { - *frameResult = fp; - } - else - { - JSStackFrame *inner = nsnull; - *frameResult = JS_FrameIterator(cx, &inner); - } - - return targetPrincipal; - } - nsIScriptContextPrincipal* scp = GetScriptContextPrincipalFromJSContext(cx); if (scp) @@ -2452,27 +2419,11 @@ nsScriptSecurityManager::IsCapabilityEnabled(const char *capability, JSContext *cx = GetCurrentJSContext(); fp = cx ? JS_FrameIterator(cx, &fp) : nsnull; - JSStackFrame *target = nsnull; - nsIPrincipal *targetPrincipal = nsnull; - for (ContextPrincipal *cp = mContextPrincipals; cp; cp = cp->mNext) - { - if (cp->mCx == cx) - { - target = cp->mFp; - targetPrincipal = cp->mPrincipal; - break; - } - } - if (!fp) { - // No script code on stack. If we had a principal pushed for this - // context and fp is null, then we use that principal. Otherwise, we - // don't have enough information and have to allow execution. - - *result = (targetPrincipal && !target) - ? (targetPrincipal == mSystemPrincipal) - : true; + // No script code on stack. We don't have enough information and have + // to allow execution. + *result = true; return NS_OK; } @@ -2516,7 +2467,7 @@ nsScriptSecurityManager::IsCapabilityEnabled(const char *capability, // the JS engine via JS_EvaluateScript or similar APIs. if (JS_IsGlobalFrame(cx, fp)) break; - } while (fp != target && (fp = JS_FrameIterator(cx, &fp)) != nsnull); + } while ((fp = JS_FrameIterator(cx, &fp)) != nsnull); if (!previousPrincipal) { @@ -3000,7 +2951,6 @@ nsScriptSecurityManager::nsScriptSecurityManager(void) : mOriginToPolicyMap(nsnull), mDefaultPolicy(nsnull), mCapabilities(nsnull), - mContextPrincipals(nsnull), mPrefInitialized(false), mIsJavaScriptEnabled(false), mIsWritingPrefs(false), @@ -3080,7 +3030,6 @@ jsid nsScriptSecurityManager::sEnabledID = JSID_VOID; nsScriptSecurityManager::~nsScriptSecurityManager(void) { Preferences::RemoveObservers(this, kObservedPrefs); - NS_ASSERTION(!mContextPrincipals, "Leaking mContextPrincipals"); delete mOriginToPolicyMap; if(mDefaultPolicy) mDefaultPolicy->Drop();