diff --git a/caps/idl/nsIScriptSecurityManager.idl b/caps/idl/nsIScriptSecurityManager.idl index 7dfa1ab7f535..63c224d0e5be 100644 --- a/caps/idl/nsIScriptSecurityManager.idl +++ b/caps/idl/nsIScriptSecurityManager.idl @@ -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 diff --git a/caps/src/nsScriptSecurityManager.cpp b/caps/src/nsScriptSecurityManager.cpp index 1898bd182136..d196273dfd62 100644 --- a/caps/src/nsScriptSecurityManager.cpp +++ b/caps/src/nsScriptSecurityManager.cpp @@ -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 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 principal = doGetObjectPrincipal(obj); + principal.forget(result); return NS_OK; } diff --git a/js/xpconnect/loader/mozJSSubScriptLoader.cpp b/js/xpconnect/loader/mozJSSubScriptLoader.cpp index ce348e78750e..67e2305a94ae 100644 --- a/js/xpconnect/loader/mozJSSubScriptLoader.cpp +++ b/js/xpconnect/loader/mozJSSubScriptLoader.cpp @@ -258,15 +258,8 @@ mozJSSubScriptLoader::DoLoadSubScriptWithOptions(const nsAString& url, if (!targetObj) return NS_ERROR_FAILURE; - if (targetObj != result_obj) { - nsCOMPtr 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); diff --git a/js/xpconnect/src/XPCWrappedJSClass.cpp b/js/xpconnect/src/XPCWrappedJSClass.cpp index a4af49e708a8..58bd93ea6b9d 100644 --- a/js/xpconnect/src/XPCWrappedJSClass.cpp +++ b/js/xpconnect/src/XPCWrappedJSClass.cpp @@ -652,14 +652,9 @@ nsXPCWrappedJSClass::DelegatedQueryInterface(nsXPCWrappedJS* self, return NS_NOINTERFACE; RootedObject selfObj(ccx, self->GetJSObject()); - nsCOMPtr objPrin; - nsresult rv = secMan->GetObjectPrincipal(ccx, selfObj, - getter_AddRefs(objPrin)); - if (NS_FAILED(rv)) - return rv; - + nsCOMPtr 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 checked = diff --git a/js/xpconnect/tests/unit/test_getObjectPrincipal.js b/js/xpconnect/tests/unit/test_getObjectPrincipal.js new file mode 100644 index 000000000000..e2f3c88ba5f3 --- /dev/null +++ b/js/xpconnect/tests/unit/test_getObjectPrincipal.js @@ -0,0 +1,4 @@ +function run_test() { + var secMan = Cc["@mozilla.org/scriptsecuritymanager;1"].getService(Ci.nsIScriptSecurityManager); + do_check_true(secMan.isSystemPrincipal(secMan.getObjectPrincipal({}))); +} diff --git a/js/xpconnect/tests/unit/xpcshell.ini b/js/xpconnect/tests/unit/xpcshell.ini index a39d909a384c..378a73887299 100644 --- a/js/xpconnect/tests/unit/xpcshell.ini +++ b/js/xpconnect/tests/unit/xpcshell.ini @@ -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