mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 05:41:12 +00:00
Bug 952192 - getObjectPrincipal should be script callable. r=bholley
This commit is contained in:
parent
2edda57c4f
commit
421ebe4af8
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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 =
|
||||
|
4
js/xpconnect/tests/unit/test_getObjectPrincipal.js
Normal file
4
js/xpconnect/tests/unit/test_getObjectPrincipal.js
Normal 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({})));
|
||||
}
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user