mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 624621 part 2. Add an origin principal argument on nsIScriptContext::EvaluateString and pass that through to the JS engine. r=mrbkap
This commit is contained in:
parent
da0004bf73
commit
f78b6a85f7
@ -896,9 +896,10 @@ nsScriptLoader::EvaluateScript(nsScriptLoadRequest* aRequest,
|
||||
|
||||
bool isUndefined;
|
||||
rv = context->EvaluateString(aScript, globalObject->GetGlobalJSObject(),
|
||||
mDocument->NodePrincipal(), url.get(),
|
||||
aRequest->mLineNo, aRequest->mJSVersion, nsnull,
|
||||
&isUndefined);
|
||||
mDocument->NodePrincipal(),
|
||||
mDocument->NodePrincipal(),
|
||||
url.get(), aRequest->mLineNo,
|
||||
aRequest->mJSVersion, nsnull, &isUndefined);
|
||||
|
||||
// Put the old script back in case it wants to do anything else.
|
||||
mCurrentScript = oldCurrent;
|
||||
|
@ -9261,7 +9261,8 @@ nsGlobalWindow::RunTimeout(nsTimeout *aTimeout)
|
||||
|
||||
bool is_undefined;
|
||||
scx->EvaluateString(nsDependentString(script), FastGetGlobalJSObject(),
|
||||
timeout->mPrincipal, filename, lineNo,
|
||||
timeout->mPrincipal, timeout->mPrincipal,
|
||||
filename, lineNo,
|
||||
handler->GetScriptVersion(), nsnull,
|
||||
&is_undefined);
|
||||
} else {
|
||||
|
@ -74,8 +74,8 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsIScriptContextPrincipal,
|
||||
NS_ISCRIPTCONTEXTPRINCIPAL_IID)
|
||||
|
||||
#define NS_ISCRIPTCONTEXT_IID \
|
||||
{ 0xb36103bd, 0x304e, 0x4ef2, \
|
||||
{ 0x81, 0x12, 0x83, 0x42, 0xe5, 0xbd, 0xf3, 0xd4 } }
|
||||
{ 0xf3840057, 0x4fe5, 0x4f92, \
|
||||
{ 0xa3, 0xb8, 0x27, 0xd7, 0x44, 0x6f, 0x72, 0x4d } }
|
||||
|
||||
/* This MUST match JSVERSION_DEFAULT. This version stuff if we don't
|
||||
know what language we have is a little silly... */
|
||||
@ -99,7 +99,9 @@ public:
|
||||
* @param aScript a string representing the script to be executed
|
||||
* @param aScopeObject a script object for the scope to execute in, or
|
||||
* nsnull to use a default scope
|
||||
* @param aPrincipal the principal that produced the script
|
||||
* @param aPrincipal the principal the script should be evaluated with
|
||||
* @param aOriginPrincipal the principal the script originates from. If null,
|
||||
* aPrincipal is used.
|
||||
* @param aURL the URL or filename for error messages
|
||||
* @param aLineNo the starting line number of the script for error messages
|
||||
* @param aVersion the script language version to use when executing
|
||||
@ -115,6 +117,7 @@ public:
|
||||
virtual nsresult EvaluateString(const nsAString& aScript,
|
||||
JSObject* aScopeObject,
|
||||
nsIPrincipal *aPrincipal,
|
||||
nsIPrincipal *aOriginPrincipal,
|
||||
const char *aURL,
|
||||
PRUint32 aLineNo,
|
||||
PRUint32 aVersion,
|
||||
|
@ -1389,6 +1389,7 @@ nsresult
|
||||
nsJSContext::EvaluateString(const nsAString& aScript,
|
||||
JSObject* aScopeObject,
|
||||
nsIPrincipal *aPrincipal,
|
||||
nsIPrincipal *aOriginPrincipal,
|
||||
const char *aURL,
|
||||
PRUint32 aLineNo,
|
||||
PRUint32 aVersion,
|
||||
@ -1436,6 +1437,13 @@ nsJSContext::EvaluateString(const nsAString& aScript,
|
||||
principal->GetJSPrincipals(mContext, &jsprin);
|
||||
}
|
||||
|
||||
JSPrincipals *originJSprin;
|
||||
if (aOriginPrincipal) {
|
||||
aOriginPrincipal->GetJSPrincipals(mContext, &originJSprin);
|
||||
} else {
|
||||
originJSprin = nsnull;
|
||||
}
|
||||
|
||||
// From here on, we must JSPRINCIPALS_DROP(jsprin) before returning...
|
||||
|
||||
bool ok = false;
|
||||
@ -1443,6 +1451,9 @@ nsJSContext::EvaluateString(const nsAString& aScript,
|
||||
nsresult rv = sSecurityManager->CanExecuteScripts(mContext, principal, &ok);
|
||||
if (NS_FAILED(rv)) {
|
||||
JSPRINCIPALS_DROP(mContext, jsprin);
|
||||
if (originJSprin) {
|
||||
JSPRINCIPALS_DROP(mContext, originJSprin);
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@ -1454,6 +1465,9 @@ nsJSContext::EvaluateString(const nsAString& aScript,
|
||||
do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv);
|
||||
if (NS_FAILED(rv) || NS_FAILED(stack->Push(mContext))) {
|
||||
JSPRINCIPALS_DROP(mContext, jsprin);
|
||||
if (originJSprin) {
|
||||
JSPRINCIPALS_DROP(mContext, originJSprin);
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@ -1479,11 +1493,14 @@ nsJSContext::EvaluateString(const nsAString& aScript,
|
||||
if (!ac.enter(mContext, aScopeObject)) {
|
||||
stack->Pop(nsnull);
|
||||
JSPRINCIPALS_DROP(mContext, jsprin);
|
||||
if (originJSprin) {
|
||||
JSPRINCIPALS_DROP(mContext, originJSprin);
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
ok = JS_EvaluateUCScriptForPrincipalsVersion(
|
||||
mContext, aScopeObject, jsprin,
|
||||
ok = JS_EvaluateUCScriptForPrincipalsVersionOrigin(
|
||||
mContext, aScopeObject, jsprin, originJSprin,
|
||||
static_cast<const jschar*>(PromiseFlatString(aScript).get()),
|
||||
aScript.Length(), aURL, aLineNo, vp, JSVersion(aVersion));
|
||||
|
||||
@ -1498,6 +1515,9 @@ nsJSContext::EvaluateString(const nsAString& aScript,
|
||||
|
||||
// Whew! Finally done with these manually ref-counted things.
|
||||
JSPRINCIPALS_DROP(mContext, jsprin);
|
||||
if (originJSprin) {
|
||||
JSPRINCIPALS_DROP(mContext, originJSprin);
|
||||
}
|
||||
|
||||
// If all went well, convert val to a string if one is wanted.
|
||||
if (ok) {
|
||||
|
@ -75,6 +75,7 @@ public:
|
||||
virtual nsresult EvaluateString(const nsAString& aScript,
|
||||
JSObject* aScopeObject,
|
||||
nsIPrincipal *principal,
|
||||
nsIPrincipal *originPrincipal,
|
||||
const char *aURL,
|
||||
PRUint32 aLineNo,
|
||||
PRUint32 aVersion,
|
||||
|
@ -360,6 +360,7 @@ nsresult nsJSThunk::EvaluateScript(nsIChannel *aChannel,
|
||||
rv = scriptContext->EvaluateString(NS_ConvertUTF8toUTF16(script),
|
||||
globalJSObject, // obj
|
||||
principal,
|
||||
principal,
|
||||
mURL.get(), // url
|
||||
1, // line no
|
||||
nsnull,
|
||||
|
Loading…
Reference in New Issue
Block a user