From 9c988d6c4038c7cb845a852ea8a7f588d8acf709 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Tue, 6 May 2014 15:43:02 -0700 Subject: [PATCH] Bug 997987 - Remove nsIScriptSecurityManager::GetCxSubjectPrincipal. r=Ms2ger --- caps/idl/nsIScriptSecurityManager.idl | 10 +--------- caps/src/nsScriptSecurityManager.cpp | 14 -------------- content/base/src/nsContentUtils.cpp | 14 ++------------ dom/base/nsLocation.cpp | 2 +- dom/workers/WorkerPrivate.cpp | 5 +---- js/xpconnect/src/Sandbox.cpp | 7 ++----- 6 files changed, 7 insertions(+), 45 deletions(-) diff --git a/caps/idl/nsIScriptSecurityManager.idl b/caps/idl/nsIScriptSecurityManager.idl index d1fcafe85f81..eda4b8eb30fc 100644 --- a/caps/idl/nsIScriptSecurityManager.idl +++ b/caps/idl/nsIScriptSecurityManager.idl @@ -11,7 +11,7 @@ interface nsIChannel; interface nsIDocShell; interface nsIDomainPolicy; -[scriptable, uuid(4c087cc3-e0cc-4ec3-88df-8d68f3023b45)] +[scriptable, uuid(176f2aed-fb78-4420-b372-07ab2c4c04c3)] interface nsIScriptSecurityManager : nsIXPCSecurityManager { /** @@ -193,14 +193,6 @@ interface nsIScriptSecurityManager : nsIXPCSecurityManager } %} - /** - * Same as getSubjectPrincipal(), only faster. cx must *never* be - * passed null, and it must be the context on the top of the - * context stack. Does *not* reference count the returned - * principal. - */ - [noscript,notxpcom] nsIPrincipal getCxSubjectPrincipal(in JSContextPtr cx); - const unsigned long NO_APP_ID = 0; const unsigned long UNKNOWN_APP_ID = 4294967295; // UINT32_MAX const unsigned long SAFEBROWSING_APP_ID = 4294967294; // UINT32_MAX - 1 diff --git a/caps/src/nsScriptSecurityManager.cpp b/caps/src/nsScriptSecurityManager.cpp index 08b2f1bf16c4..bc0eebd03ee5 100644 --- a/caps/src/nsScriptSecurityManager.cpp +++ b/caps/src/nsScriptSecurityManager.cpp @@ -318,20 +318,6 @@ nsScriptSecurityManager::IsSystemPrincipal(nsIPrincipal* aPrincipal, return NS_OK; } -NS_IMETHODIMP_(nsIPrincipal *) -nsScriptSecurityManager::GetCxSubjectPrincipal(JSContext *cx) -{ - NS_ASSERTION(cx == GetCurrentJSContext(), - "Uh, cx is not the current JS context!"); - - nsresult rv = NS_ERROR_FAILURE; - nsIPrincipal *principal = GetSubjectPrincipal(cx, &rv); - if (NS_FAILED(rv)) - return nullptr; - - return principal; -} - ///////////////////////////// // nsScriptSecurityManager // ///////////////////////////// diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index 6f04aea5439d..c35ea8cae3f5 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -6106,20 +6106,10 @@ nsContentUtils::GetContentSecurityPolicy(JSContext* aCx, nsIContentSecurityPolicy** aCSP) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); - - // Get the security manager - nsCOMPtr ssm = nsContentUtils::GetSecurityManager(); - - if (!ssm) { - NS_ERROR("Failed to get security manager service"); - return false; - } - - nsCOMPtr subjectPrincipal = ssm->GetCxSubjectPrincipal(aCx); - NS_ASSERTION(subjectPrincipal, "Failed to get subjectPrincipal"); + MOZ_ASSERT(aCx == GetCurrentJSContext()); nsCOMPtr csp; - nsresult rv = subjectPrincipal->GetCsp(getter_AddRefs(csp)); + nsresult rv = GetSubjectPrincipal()->GetCsp(getter_AddRefs(csp)); if (NS_FAILED(rv)) { NS_ERROR("CSP: Failed to get CSP from principal."); return false; diff --git a/dom/base/nsLocation.cpp b/dom/base/nsLocation.cpp index e9e5da38c28a..bd115166c9a8 100644 --- a/dom/base/nsLocation.cpp +++ b/dom/base/nsLocation.cpp @@ -160,7 +160,7 @@ nsLocation::CheckURL(nsIURI* aURI, nsIDocShellLoadInfo** aLoadInfo) } } - owner = do_QueryInterface(ssm->GetCxSubjectPrincipal(cx)); + owner = nsContentUtils::GetSubjectPrincipal(); } // Create load info diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index 6c8355487b26..94797e54b85a 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -3717,6 +3717,7 @@ WorkerPrivate::GetLoadInfo(JSContext* aCx, nsPIDOMWindow* aWindow, using namespace mozilla::dom::workers::scriptloader; MOZ_ASSERT(aCx); + MOZ_ASSERT_IF(NS_IsMainThread(), aCx == nsContentUtils::GetCurrentJSContext()); if (aWindow) { AssertIsOnMainThread(); @@ -3913,10 +3914,6 @@ WorkerPrivate::GetLoadInfo(JSContext* aCx, nsPIDOMWindow* aWindow, MOZ_ASSERT(loadInfo.mPrincipal); MOZ_ASSERT(isChrome || !loadInfo.mDomain.IsEmpty()); - // XXXbent Use subject principal here instead of the one we already have? - nsCOMPtr subjectPrincipal = ssm->GetCxSubjectPrincipal(aCx); - MOZ_ASSERT(subjectPrincipal); - if (!nsContentUtils::GetContentSecurityPolicy(aCx, getter_AddRefs(loadInfo.mCSP))) { NS_WARNING("Failed to get CSP!"); diff --git a/js/xpconnect/src/Sandbox.cpp b/js/xpconnect/src/Sandbox.cpp index c6740607c3a6..cd0fc3dca390 100644 --- a/js/xpconnect/src/Sandbox.cpp +++ b/js/xpconnect/src/Sandbox.cpp @@ -203,10 +203,6 @@ CreateXMLHttpRequest(JSContext *cx, unsigned argc, jsval *vp) if (!ssm) return false; - nsIPrincipal *subjectPrincipal = ssm->GetCxSubjectPrincipal(cx); - if (!subjectPrincipal) - return false; - RootedObject global(cx, JS::CurrentGlobalOrNull(cx)); MOZ_ASSERT(global); @@ -215,7 +211,8 @@ CreateXMLHttpRequest(JSContext *cx, unsigned argc, jsval *vp) nsCOMPtr iglobal = do_QueryInterface(sop); nsCOMPtr xhr = new nsXMLHttpRequest(); - nsresult rv = xhr->Init(subjectPrincipal, nullptr, iglobal, nullptr); + nsresult rv = xhr->Init(nsContentUtils::GetSubjectPrincipal(), nullptr, + iglobal, nullptr); if (NS_FAILED(rv)) return false;