From f90c7ffe445b54f0484b00f6879b0ccef9623873 Mon Sep 17 00:00:00 2001 From: Christoph Kerschbaumer Date: Thu, 26 Feb 2015 12:14:27 -0800 Subject: [PATCH] Bug 1133189 - Extend PrincipalInfo to handle expanded principals (r=bent,sicking) --- ipc/glue/BackgroundUtils.cpp | 53 ++++++++++++++++++++++++++- ipc/glue/PBackgroundSharedTypes.ipdlh | 6 +++ ipc/glue/moz.build | 1 + 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/ipc/glue/BackgroundUtils.cpp b/ipc/glue/BackgroundUtils.cpp index 9cc5f561efb6..68f37fa0f717 100644 --- a/ipc/glue/BackgroundUtils.cpp +++ b/ipc/glue/BackgroundUtils.cpp @@ -7,7 +7,7 @@ #include "MainThreadUtils.h" #include "mozilla/Assertions.h" #include "mozilla/ipc/PBackgroundSharedTypes.h" -#include "nsIPrincipal.h" +#include "nsPrincipal.h" #include "nsIScriptSecurityManager.h" #include "nsIURI.h" #include "nsNetUtil.h" @@ -80,6 +80,31 @@ PrincipalInfoToPrincipal(const PrincipalInfo& aPrincipalInfo, return principal.forget(); } + case PrincipalInfo::TExpandedPrincipalInfo: { + const ExpandedPrincipalInfo& info = aPrincipalInfo.get_ExpandedPrincipalInfo(); + + nsTArray< nsCOMPtr > whitelist; + nsCOMPtr wlPrincipal; + + for (uint32_t i = 0; i < info.whitelist().Length(); i++) { + wlPrincipal = PrincipalInfoToPrincipal(info.whitelist()[i], &rv); + if (NS_WARN_IF(NS_FAILED(rv))) { + return nullptr; + } + // append that principal to the whitelist + whitelist.AppendElement(wlPrincipal); + } + + nsRefPtr expandedPrincipal = new nsExpandedPrincipal(whitelist); + if (!expandedPrincipal) { + NS_WARNING("could not instantiate expanded principal"); + return nullptr; + } + + principal = expandedPrincipal; + return principal.forget(); + } + default: MOZ_CRASH("Unknown PrincipalInfo type!"); } @@ -123,6 +148,32 @@ PrincipalToPrincipalInfo(nsIPrincipal* aPrincipal, return NS_OK; } + // might be an expanded principal + nsCOMPtr expanded = + do_QueryInterface(aPrincipal); + + if (expanded) { + nsTArray whitelistInfo; + PrincipalInfo info; + + nsTArray< nsCOMPtr >* whitelist; + MOZ_ALWAYS_TRUE(NS_SUCCEEDED(expanded->GetWhiteList(&whitelist))); + + for (uint32_t i = 0; i < whitelist->Length(); i++) { + rv = PrincipalToPrincipalInfo((*whitelist)[i], &info); + if (NS_WARN_IF(NS_FAILED(rv))) { + return rv; + } + // append that spec to the whitelist + whitelistInfo.AppendElement(info); + } + + *aPrincipalInfo = ExpandedPrincipalInfo(Move(whitelistInfo)); + return NS_OK; + } + + // must be a content principal + nsCOMPtr uri; rv = aPrincipal->GetURI(getter_AddRefs(uri)); if (NS_WARN_IF(NS_FAILED(rv))) { diff --git a/ipc/glue/PBackgroundSharedTypes.ipdlh b/ipc/glue/PBackgroundSharedTypes.ipdlh index 78d9f87298bd..c0fe2939ca39 100644 --- a/ipc/glue/PBackgroundSharedTypes.ipdlh +++ b/ipc/glue/PBackgroundSharedTypes.ipdlh @@ -20,11 +20,17 @@ struct SystemPrincipalInfo struct NullPrincipalInfo { }; +struct ExpandedPrincipalInfo +{ + PrincipalInfo[] whitelist; +}; + union PrincipalInfo { ContentPrincipalInfo; SystemPrincipalInfo; NullPrincipalInfo; + ExpandedPrincipalInfo; }; union OptionalPrincipalInfo diff --git a/ipc/glue/moz.build b/ipc/glue/moz.build index fa4918a44b56..e508d3523433 100644 --- a/ipc/glue/moz.build +++ b/ipc/glue/moz.build @@ -130,6 +130,7 @@ SOURCES += [ ] LOCAL_INCLUDES += [ + '/caps', '/dom/broadcastchannel', '/dom/indexedDB', '/xpcom/build',