Minimal fix for bug 504021. r=jst a=dveditz
git-svn-id: svn://10.0.0.236/trunk@259482 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -454,6 +454,32 @@ nsScriptSecurityManager::GetCxSubjectPrincipalAndFrame(JSContext *cx, JSStackFra
|
||||
return principal;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScriptSecurityManager::PushContextPrincipal(JSContext *cx,
|
||||
JSStackFrame *fp,
|
||||
nsIPrincipal *principal)
|
||||
{
|
||||
ContextPrincipal *cp = new ContextPrincipal(mContextPrincipals, cx, fp,
|
||||
principal);
|
||||
if (!cp)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
mContextPrincipals = cp;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScriptSecurityManager::PopContextPrincipal(JSContext *cx)
|
||||
{
|
||||
NS_ASSERTION(mContextPrincipals->mCx == cx, "Mismatched push/pop");
|
||||
|
||||
ContextPrincipal *next = mContextPrincipals->mNext;
|
||||
delete mContextPrincipals;
|
||||
mContextPrincipals = next;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////
|
||||
// Policy Storage //
|
||||
////////////////////
|
||||
@@ -529,13 +555,14 @@ DeleteDomainEntry(nsHashKey *aKey, void *aData, void* closure)
|
||||
////////////////////////////////////
|
||||
// Methods implementing ISupports //
|
||||
////////////////////////////////////
|
||||
NS_IMPL_ISUPPORTS6(nsScriptSecurityManager,
|
||||
NS_IMPL_ISUPPORTS7(nsScriptSecurityManager,
|
||||
nsIScriptSecurityManager,
|
||||
nsIXPCSecurityManager,
|
||||
nsIPrefSecurityCheck,
|
||||
nsIChannelEventSink,
|
||||
nsIObserver,
|
||||
nsIScriptSecurityManager_1_9_0_BRANCH)
|
||||
nsIScriptSecurityManager_1_9_0_BRANCH,
|
||||
nsIScriptSecurityManager_1_9_2)
|
||||
|
||||
///////////////////////////////////////////////////
|
||||
// Methods implementing nsIScriptSecurityManager //
|
||||
@@ -2249,7 +2276,6 @@ nsScriptSecurityManager::GetFunctionObjectPrincipal(JSContext *cx,
|
||||
return GetScriptPrincipal(cx, script, rv);
|
||||
}
|
||||
|
||||
// static
|
||||
nsIPrincipal*
|
||||
nsScriptSecurityManager::GetFramePrincipal(JSContext *cx,
|
||||
JSStackFrame *fp,
|
||||
@@ -2279,22 +2305,36 @@ nsScriptSecurityManager::GetFramePrincipal(JSContext *cx,
|
||||
return result;
|
||||
}
|
||||
|
||||
// static
|
||||
nsIPrincipal*
|
||||
nsScriptSecurityManager::GetPrincipalAndFrame(JSContext *cx,
|
||||
JSStackFrame **frameResult,
|
||||
nsresult* rv)
|
||||
{
|
||||
NS_PRECONDITION(rv, "Null out param");
|
||||
NS_PRECONDITION(rv, "Null out param");
|
||||
//-- If there's no principal on the stack, look at the global object
|
||||
// and return the innermost frame for annotations.
|
||||
*rv = NS_OK;
|
||||
|
||||
if (cx)
|
||||
{
|
||||
// Get principals from innermost frame of JavaScript or Java.
|
||||
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)
|
||||
{
|
||||
@@ -2304,6 +2344,25 @@ 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;
|
||||
}
|
||||
|
||||
nsIScriptContext *scriptContext = GetScriptContext(cx);
|
||||
if (scriptContext)
|
||||
{
|
||||
@@ -2330,7 +2389,6 @@ nsScriptSecurityManager::GetPrincipalAndFrame(JSContext *cx,
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
// static
|
||||
nsIPrincipal*
|
||||
nsScriptSecurityManager::GetSubjectPrincipal(JSContext *cx,
|
||||
nsresult* rv)
|
||||
@@ -3293,6 +3351,7 @@ nsScriptSecurityManager::nsScriptSecurityManager(void)
|
||||
: mOriginToPolicyMap(nsnull),
|
||||
mDefaultPolicy(nsnull),
|
||||
mCapabilities(nsnull),
|
||||
mContextPrincipals(nsnull),
|
||||
mIsJavaScriptEnabled(PR_FALSE),
|
||||
mIsMailJavaScriptEnabled(PR_FALSE),
|
||||
mIsWritingPrefs(PR_FALSE),
|
||||
@@ -3369,6 +3428,7 @@ jsval nsScriptSecurityManager::sEnabledID = JSVAL_VOID;
|
||||
|
||||
nsScriptSecurityManager::~nsScriptSecurityManager(void)
|
||||
{
|
||||
NS_ASSERTION(!mContextPrincipals, "Leaking mContextPrincipals");
|
||||
delete mOriginToPolicyMap;
|
||||
if(mDefaultPolicy)
|
||||
mDefaultPolicy->Drop();
|
||||
|
||||
Reference in New Issue
Block a user