mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 758344 - Make ContextHolder implement nsIScriptContextPrincipal. r=mrbkap
This commit is contained in:
parent
0ddcce9080
commit
552229b617
@ -3630,10 +3630,11 @@ nsXPCComponents_utils_Sandbox::CallOrConstruct(nsIXPConnectWrappedNative *wrappe
|
||||
return rv;
|
||||
}
|
||||
|
||||
class ContextHolder : public nsISupports
|
||||
class ContextHolder : public nsIScriptObjectPrincipal
|
||||
, public nsIScriptContextPrincipal
|
||||
{
|
||||
public:
|
||||
ContextHolder(JSContext *aOuterCx, JSObject *aSandbox, bool isChrome);
|
||||
ContextHolder(JSContext *aOuterCx, JSObject *aSandbox, nsIPrincipal *aPrincipal);
|
||||
virtual ~ContextHolder();
|
||||
|
||||
JSContext * GetJSContext()
|
||||
@ -3641,6 +3642,9 @@ public:
|
||||
return mJSContext;
|
||||
}
|
||||
|
||||
nsIScriptObjectPrincipal * GetObjectPrincipal() { return this; }
|
||||
nsIPrincipal * GetPrincipal() { return mPrincipal; }
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
private:
|
||||
@ -3648,17 +3652,23 @@ private:
|
||||
|
||||
JSContext* mJSContext;
|
||||
JSContext* mOrigCx;
|
||||
nsCOMPtr<nsIPrincipal> mPrincipal;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS0(ContextHolder)
|
||||
NS_IMPL_ISUPPORTS2(ContextHolder, nsIScriptObjectPrincipal, nsIScriptContextPrincipal)
|
||||
|
||||
ContextHolder::ContextHolder(JSContext *aOuterCx,
|
||||
JSObject *aSandbox,
|
||||
bool isChrome)
|
||||
nsIPrincipal *aPrincipal)
|
||||
: mJSContext(JS_NewContext(JS_GetRuntime(aOuterCx), 1024)),
|
||||
mOrigCx(aOuterCx)
|
||||
mOrigCx(aOuterCx),
|
||||
mPrincipal(aPrincipal)
|
||||
{
|
||||
if (mJSContext) {
|
||||
bool isChrome;
|
||||
DebugOnly<nsresult> rv = XPCWrapper::GetSecurityManager()->
|
||||
IsSystemPrincipal(mPrincipal, &isChrome);
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||
bool allowXML = Preferences::GetBool(isChrome ?
|
||||
"javascript.options.xml.chrome" :
|
||||
"javascript.options.xml.content");
|
||||
@ -3816,10 +3826,7 @@ xpc_EvalInSandbox(JSContext *cx, JSObject *sandbox, const nsAString& source,
|
||||
}
|
||||
}
|
||||
|
||||
bool isChrome;
|
||||
nsresult rv = XPCWrapper::GetSecurityManager()->IsSystemPrincipal(prin, &isChrome);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsRefPtr<ContextHolder> sandcx = new ContextHolder(cx, sandbox, isChrome);
|
||||
nsRefPtr<ContextHolder> sandcx = new ContextHolder(cx, sandbox, prin);
|
||||
if (!sandcx || !sandcx->GetJSContext()) {
|
||||
JS_ReportError(cx, "Can't prepare context for evalInSandbox");
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
@ -3835,7 +3842,7 @@ xpc_EvalInSandbox(JSContext *cx, JSObject *sandbox, const nsAString& source,
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
rv = NS_OK;
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
{
|
||||
JSAutoRequest req(sandcx->GetJSContext());
|
||||
|
Loading…
Reference in New Issue
Block a user