Bug 1297687 - Part 2: Allow specifying an OriginAttribute when creating an expanded principal; r=bholley

This commit is contained in:
Ehsan Akhgari 2016-09-09 18:52:55 -04:00
parent 6b65aceec2
commit 5404c2dc93
4 changed files with 17 additions and 5 deletions

View File

@ -674,7 +674,7 @@ struct OriginComparator
}
};
nsExpandedPrincipal::nsExpandedPrincipal(nsTArray<nsCOMPtr <nsIPrincipal> > &aWhiteList)
nsExpandedPrincipal::nsExpandedPrincipal(nsTArray<nsCOMPtr<nsIPrincipal>> &aWhiteList)
{
// We force the principals to be sorted by origin so that nsExpandedPrincipal
// origins can have a canonical form.
@ -684,6 +684,13 @@ nsExpandedPrincipal::nsExpandedPrincipal(nsTArray<nsCOMPtr <nsIPrincipal> > &aWh
}
}
nsExpandedPrincipal::nsExpandedPrincipal(nsTArray<nsCOMPtr<nsIPrincipal>> &aWhiteList,
const PrincipalOriginAttributes& aAttrs)
: nsExpandedPrincipal(aWhiteList)
{
mOriginAttributes = aAttrs;
}
nsExpandedPrincipal::~nsExpandedPrincipal()
{ }

View File

@ -67,7 +67,9 @@ protected:
class nsExpandedPrincipal : public nsIExpandedPrincipal, public mozilla::BasePrincipal
{
public:
explicit nsExpandedPrincipal(nsTArray< nsCOMPtr<nsIPrincipal> > &aWhiteList);
nsExpandedPrincipal(nsTArray<nsCOMPtr<nsIPrincipal>> &aWhiteList,
const mozilla::PrincipalOriginAttributes& aAttrs);
explicit nsExpandedPrincipal(nsTArray<nsCOMPtr<nsIPrincipal>> &aWhiteList);
NS_DECL_NSIEXPANDEDPRINCIPAL
NS_DECL_NSISERIALIZABLE

View File

@ -93,7 +93,7 @@ PrincipalInfoToPrincipal(const PrincipalInfo& aPrincipalInfo,
case PrincipalInfo::TExpandedPrincipalInfo: {
const ExpandedPrincipalInfo& info = aPrincipalInfo.get_ExpandedPrincipalInfo();
nsTArray< nsCOMPtr<nsIPrincipal> > whitelist;
nsTArray<nsCOMPtr<nsIPrincipal>> whitelist;
nsCOMPtr<nsIPrincipal> wlPrincipal;
for (uint32_t i = 0; i < info.whitelist().Length(); i++) {
@ -105,7 +105,7 @@ PrincipalInfoToPrincipal(const PrincipalInfo& aPrincipalInfo,
whitelist.AppendElement(wlPrincipal);
}
RefPtr<nsExpandedPrincipal> expandedPrincipal = new nsExpandedPrincipal(whitelist);
RefPtr<nsExpandedPrincipal> expandedPrincipal = new nsExpandedPrincipal(whitelist, info.attrs());
if (!expandedPrincipal) {
NS_WARNING("could not instantiate expanded principal");
return nullptr;
@ -173,7 +173,9 @@ PrincipalToPrincipalInfo(nsIPrincipal* aPrincipal,
whitelistInfo.AppendElement(info);
}
*aPrincipalInfo = ExpandedPrincipalInfo(Move(whitelistInfo));
*aPrincipalInfo =
ExpandedPrincipalInfo(BasePrincipal::Cast(aPrincipal)->OriginAttributesRef(),
Move(whitelistInfo));
return NS_OK;
}

View File

@ -24,6 +24,7 @@ struct NullPrincipalInfo
struct ExpandedPrincipalInfo
{
PrincipalOriginAttributes attrs;
PrincipalInfo[] whitelist;
};