Bug 1600963 - reduce boilerplate for serialized keys in principals; r=mccr8

Differential Revision: https://phabricator.services.mozilla.com/D55686

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Nathan Froyd 2019-12-03 17:30:09 +00:00
parent 874e5c0f9e
commit 3c6e6ca1c9
4 changed files with 16 additions and 24 deletions

View File

@ -256,6 +256,16 @@ class BasePrincipal : public nsJSPrincipals {
void FinishInit(BasePrincipal* aOther,
const OriginAttributes& aOriginAttributes);
// KeyValT holds a principal subtype-specific key value and the associated
// parsed value after JSON parsing.
template<typename SerializedKey>
struct KeyValT
{
bool valueWasSerialized;
nsCString value;
SerializedKey key;
};
private:
static already_AddRefed<BasePrincipal> CreateContentPrincipal(
nsIURI* aURI, const OriginAttributes& aAttrs,

View File

@ -60,14 +60,8 @@ class ContentPrincipal final : public BasePrincipal {
virtual nsresult PopulateJSONObject(Json::Value& aObject) override;
// Serializable keys are the valid enum fields the serialization supports
enum SerializableKeys { eURI = 0, eDomain, eSuffix, eMax = eSuffix };
// KeyVal is a lightweight storage that passes
// SerializableKeys and values after JSON parsing in the BasePrincipal to
// FromProperties
struct KeyVal {
bool valueWasSerialized;
nsCString value;
SerializableKeys key;
};
typedef mozilla::BasePrincipal::KeyValT<SerializableKeys> KeyVal;
static already_AddRefed<BasePrincipal> FromProperties(
nsTArray<ContentPrincipal::KeyVal>& aFields);

View File

@ -63,14 +63,8 @@ class ExpandedPrincipal : public nsIExpandedPrincipal,
virtual nsresult PopulateJSONObject(Json::Value& aObject) override;
// Serializable keys are the valid enum fields the serialization supports
enum SerializableKeys { eSpecs = 0, eSuffix, eMax = eSuffix };
// KeyVal is a lightweight storage that passes
// SerializableKeys and values after JSON parsing in the BasePrincipal to
// FromProperties
struct KeyVal {
bool valueWasSerialized;
nsCString value;
SerializableKeys key;
};
typedef mozilla::BasePrincipal::KeyValT<SerializableKeys> KeyVal;
static already_AddRefed<BasePrincipal> FromProperties(
nsTArray<ExpandedPrincipal::KeyVal>& aFields);

View File

@ -87,14 +87,8 @@ class NullPrincipal final : public BasePrincipal {
// Serializable keys are the valid enum fields the serialization supports
enum SerializableKeys { eSpec = 0, eSuffix, eMax = eSuffix };
// KeyVal is a lightweight storage that passes
// SerializableKeys and values after JSON parsing in the BasePrincipal to
// FromProperties
struct KeyVal {
bool valueWasSerialized;
nsCString value;
SerializableKeys key;
};
typedef mozilla::BasePrincipal::KeyValT<SerializableKeys> KeyVal;
static already_AddRefed<BasePrincipal> FromProperties(
nsTArray<NullPrincipal::KeyVal>& aFields);