Bug 996069 - Part1: nsContentUtils::IsSystemOrExpandedPrincipal. r=bz

This commit is contained in:
Gabor Krizsanits 2014-04-16 22:29:12 +02:00
Родитель 66aea42178
Коммит 2434cfbdd2
2 изменённых файлов: 12 добавлений и 9 удалений

Просмотреть файл

@ -1326,6 +1326,14 @@ public:
*/
static bool IsExpandedPrincipal(nsIPrincipal* aPrincipal);
/**
* Returns true if aPrincipal is the system or an nsExpandedPrincipal.
*/
static bool IsSystemOrExpandedPrincipal(nsIPrincipal* aPrincipal)
{
return IsSystemPrincipal(aPrincipal) || IsExpandedPrincipal(aPrincipal);
}
/**
* Gets the system principal from the security manager.
*/

Просмотреть файл

@ -1544,17 +1544,9 @@ nsDocShell::LoadURI(nsIURI * aURI,
// for in InternalLoad is data:, javascript:, and about:blank
// URIs. For other URIs this would all be dead wrong!
nsCOMPtr<nsIScriptSecurityManager> secMan =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
if (owner && mItemType != typeChrome) {
nsCOMPtr<nsIPrincipal> ownerPrincipal = do_QueryInterface(owner);
bool isSystem;
rv = secMan->IsSystemPrincipal(ownerPrincipal, &isSystem);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIExpandedPrincipal> ep = do_QueryInterface(ownerPrincipal);
if (isSystem || ep) {
if (nsContentUtils::IsSystemOrExpandedPrincipal(ownerPrincipal)) {
if (ownerIsExplicit) {
return NS_ERROR_DOM_SECURITY_ERR;
}
@ -1564,6 +1556,9 @@ nsDocShell::LoadURI(nsIURI * aURI,
}
if (!owner && !inheritOwner && !ownerIsExplicit) {
// See if there's system or chrome JS code running
nsCOMPtr<nsIScriptSecurityManager> secMan =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = secMan->SubjectPrincipalIsSystem(&inheritOwner);
if (NS_FAILED(rv)) {
// Set it back to false