Bug 952192 - getObjectPrincipal should be script callable. r=bholley

This commit is contained in:
Gabor Krizsanits 2014-01-09 11:31:33 +01:00
parent 2edda57c4f
commit 421ebe4af8
6 changed files with 17 additions and 26 deletions

View File

@ -11,7 +11,7 @@ interface nsIChannel;
interface nsIDocShell;
interface nsIDomainPolicy;
[scriptable, uuid(2911ae60-1b5f-47e6-941e-1bb7b53a167d)]
[scriptable, uuid(712aa338-50a1-497b-be6f-dc3d97867c01)]
interface nsIScriptSecurityManager : nsIXPCSecurityManager
{
///////////////// Security Checks //////////////////
@ -160,12 +160,10 @@ interface nsIScriptSecurityManager : nsIXPCSecurityManager
*/
[deprecated] nsIPrincipal getCodebasePrincipal(in nsIURI uri);
///////////////////////
/**
* Return the principal of the specified object in the specified context.
*/
[noscript] nsIPrincipal getObjectPrincipal(in JSContextPtr cx,
in JSObjectPtr obj);
[implicit_jscontext] nsIPrincipal getObjectPrincipal(in jsval aObject);
/**
* Returns true if the principal of the currently running script is the

View File

@ -1487,14 +1487,14 @@ nsScriptSecurityManager::GetSubjectPrincipal(JSContext *cx,
}
NS_IMETHODIMP
nsScriptSecurityManager::GetObjectPrincipal(JSContext *aCx, JSObject *aObj,
nsScriptSecurityManager::GetObjectPrincipal(const JS::Value &aObjectVal,
JSContext *aCx,
nsIPrincipal **result)
{
JS::Rooted<JSObject*> obj(aCx, aObj);
*result = doGetObjectPrincipal(obj);
if (!*result)
return NS_ERROR_FAILURE;
NS_ADDREF(*result);
NS_ENSURE_TRUE(aObjectVal.isObject(), NS_ERROR_FAILURE);
JS::RootedObject obj(aCx, &aObjectVal.toObject());
nsCOMPtr<nsIPrincipal> principal = doGetObjectPrincipal(obj);
principal.forget(result);
return NS_OK;
}

View File

@ -258,15 +258,8 @@ mozJSSubScriptLoader::DoLoadSubScriptWithOptions(const nsAString& url,
if (!targetObj)
return NS_ERROR_FAILURE;
if (targetObj != result_obj) {
nsCOMPtr<nsIScriptSecurityManager> secman =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID);
if (!secman)
return NS_ERROR_FAILURE;
rv = secman->GetObjectPrincipal(cx, targetObj, getter_AddRefs(principal));
NS_ENSURE_SUCCESS(rv, rv);
}
if (targetObj != result_obj)
principal = GetObjectPrincipal(targetObj);
JSAutoCompartment ac(cx, targetObj);

View File

@ -652,14 +652,9 @@ nsXPCWrappedJSClass::DelegatedQueryInterface(nsXPCWrappedJS* self,
return NS_NOINTERFACE;
RootedObject selfObj(ccx, self->GetJSObject());
nsCOMPtr<nsIPrincipal> objPrin;
nsresult rv = secMan->GetObjectPrincipal(ccx, selfObj,
getter_AddRefs(objPrin));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIPrincipal> objPrin = GetObjectPrincipal(selfObj);
bool isSystem;
rv = secMan->IsSystemPrincipal(objPrin, &isSystem);
nsresult rv = secMan->IsSystemPrincipal(objPrin, &isSystem);
if ((NS_FAILED(rv) || !isSystem) && !IS_WN_REFLECTOR(selfObj)) {
// A content object.
nsRefPtr<SameOriginCheckedComponent> checked =

View File

@ -0,0 +1,4 @@
function run_test() {
var secMan = Cc["@mozilla.org/scriptsecuritymanager;1"].getService(Ci.nsIScriptSecurityManager);
do_check_true(secMan.isSystemPrincipal(secMan.getObjectPrincipal({})));
}

View File

@ -73,6 +73,7 @@ fail-if = os == "android"
[test_sandbox_atob.js]
[test_isProxy.js]
[test_watchdog_enable.js]
[test_getObjectPrincipal.js]
head = head_watchdog.js
[test_watchdog_disable.js]
head = head_watchdog.js