Bug 1449827 - Introduce a typedef AtomsTable within nsTreeSanitizer. r=hsivonen

This is much shorter than nsTHashtable<nsRefPtrHashKey<nsAtom>>, which is
repeated often.

MozReview-Commit-ID: 85MR0PQ6klI

--HG--
extra : rebase_source : b9d157b2deb68f4d9aee94bdcff6737caf4336ba
This commit is contained in:
Nicholas Nethercote 2018-03-29 15:51:39 +11:00
parent 1b4b4f5a56
commit 6d1da3fee2
2 changed files with 28 additions and 30 deletions

View File

@ -931,13 +931,13 @@ nsStaticAtom* const kURLAttributesMathML[] = {
nullptr
};
nsTHashtable<nsRefPtrHashKey<nsAtom>>* nsTreeSanitizer::sElementsHTML = nullptr;
nsTHashtable<nsRefPtrHashKey<nsAtom>>* nsTreeSanitizer::sAttributesHTML = nullptr;
nsTHashtable<nsRefPtrHashKey<nsAtom>>* nsTreeSanitizer::sPresAttributesHTML = nullptr;
nsTHashtable<nsRefPtrHashKey<nsAtom>>* nsTreeSanitizer::sElementsSVG = nullptr;
nsTHashtable<nsRefPtrHashKey<nsAtom>>* nsTreeSanitizer::sAttributesSVG = nullptr;
nsTHashtable<nsRefPtrHashKey<nsAtom>>* nsTreeSanitizer::sElementsMathML = nullptr;
nsTHashtable<nsRefPtrHashKey<nsAtom>>* nsTreeSanitizer::sAttributesMathML = nullptr;
nsTreeSanitizer::AtomsTable* nsTreeSanitizer::sElementsHTML = nullptr;
nsTreeSanitizer::AtomsTable* nsTreeSanitizer::sAttributesHTML = nullptr;
nsTreeSanitizer::AtomsTable* nsTreeSanitizer::sPresAttributesHTML = nullptr;
nsTreeSanitizer::AtomsTable* nsTreeSanitizer::sElementsSVG = nullptr;
nsTreeSanitizer::AtomsTable* nsTreeSanitizer::sAttributesSVG = nullptr;
nsTreeSanitizer::AtomsTable* nsTreeSanitizer::sElementsMathML = nullptr;
nsTreeSanitizer::AtomsTable* nsTreeSanitizer::sAttributesMathML = nullptr;
nsIPrincipal* nsTreeSanitizer::sNullPrincipal = nullptr;
nsTreeSanitizer::nsTreeSanitizer(uint32_t aFlags)
@ -1154,7 +1154,7 @@ nsTreeSanitizer::SanitizeStyleSheet(const nsAString& aOriginal,
void
nsTreeSanitizer::SanitizeAttributes(mozilla::dom::Element* aElement,
nsTHashtable<nsRefPtrHashKey<nsAtom>>* aAllowed,
AtomsTable* aAllowed,
nsStaticAtom* const* aURLs,
bool aAllowXLink,
bool aAllowStyle,
@ -1544,44 +1544,37 @@ nsTreeSanitizer::InitializeStatics()
{
NS_PRECONDITION(!sElementsHTML, "Initializing a second time.");
sElementsHTML =
new nsTHashtable<nsRefPtrHashKey<nsAtom>>(ArrayLength(kElementsHTML));
sElementsHTML = new AtomsTable(ArrayLength(kElementsHTML));
for (uint32_t i = 0; kElementsHTML[i]; i++) {
sElementsHTML->PutEntry(kElementsHTML[i]);
}
sAttributesHTML =
new nsTHashtable<nsRefPtrHashKey<nsAtom>>(ArrayLength(kAttributesHTML));
sAttributesHTML = new AtomsTable(ArrayLength(kAttributesHTML));
for (uint32_t i = 0; kAttributesHTML[i]; i++) {
sAttributesHTML->PutEntry(kAttributesHTML[i]);
}
sPresAttributesHTML =
new nsTHashtable<nsRefPtrHashKey<nsAtom>>(ArrayLength(kPresAttributesHTML));
sPresAttributesHTML = new AtomsTable(ArrayLength(kPresAttributesHTML));
for (uint32_t i = 0; kPresAttributesHTML[i]; i++) {
sPresAttributesHTML->PutEntry(kPresAttributesHTML[i]);
}
sElementsSVG =
new nsTHashtable<nsRefPtrHashKey<nsAtom>>(ArrayLength(kElementsSVG));
sElementsSVG = new AtomsTable(ArrayLength(kElementsSVG));
for (uint32_t i = 0; kElementsSVG[i]; i++) {
sElementsSVG->PutEntry(kElementsSVG[i]);
}
sAttributesSVG =
new nsTHashtable<nsRefPtrHashKey<nsAtom>>(ArrayLength(kAttributesSVG));
sAttributesSVG = new AtomsTable(ArrayLength(kAttributesSVG));
for (uint32_t i = 0; kAttributesSVG[i]; i++) {
sAttributesSVG->PutEntry(kAttributesSVG[i]);
}
sElementsMathML =
new nsTHashtable<nsRefPtrHashKey<nsAtom>>(ArrayLength(kElementsMathML));
sElementsMathML = new AtomsTable(ArrayLength(kElementsMathML));
for (uint32_t i = 0; kElementsMathML[i]; i++) {
sElementsMathML->PutEntry(kElementsMathML[i]);
}
sAttributesMathML =
new nsTHashtable<nsRefPtrHashKey<nsAtom>>(ArrayLength(kAttributesMathML));
sAttributesMathML = new AtomsTable(ArrayLength(kAttributesMathML));
for (uint32_t i = 0; kAttributesMathML[i]; i++) {
sAttributesMathML->PutEntry(kAttributesMathML[i]);
}

View File

@ -87,6 +87,11 @@ class MOZ_STACK_CLASS nsTreeSanitizer {
*/
bool mLogRemovals;
/**
* We have various tables of static atoms for elements and attributes.
*/
typedef nsTHashtable<nsRefPtrHashKey<nsAtom>> AtomsTable;
void SanitizeChildren(nsINode* aRoot);
/**
@ -134,7 +139,7 @@ class MOZ_STACK_CLASS nsTreeSanitizer {
* attribute unsanitized
*/
void SanitizeAttributes(mozilla::dom::Element* aElement,
nsTHashtable<nsRefPtrHashKey<nsAtom>>* aAllowed,
AtomsTable* aAllowed,
nsStaticAtom* const* aURLs,
bool aAllowXLink,
bool aAllowStyle,
@ -201,37 +206,37 @@ class MOZ_STACK_CLASS nsTreeSanitizer {
/**
* The whitelist of HTML elements.
*/
static nsTHashtable<nsRefPtrHashKey<nsAtom>>* sElementsHTML;
static AtomsTable* sElementsHTML;
/**
* The whitelist of non-presentational HTML attributes.
*/
static nsTHashtable<nsRefPtrHashKey<nsAtom>>* sAttributesHTML;
static AtomsTable* sAttributesHTML;
/**
* The whitelist of presentational HTML attributes.
*/
static nsTHashtable<nsRefPtrHashKey<nsAtom>>* sPresAttributesHTML;
static AtomsTable* sPresAttributesHTML;
/**
* The whitelist of SVG elements.
*/
static nsTHashtable<nsRefPtrHashKey<nsAtom>>* sElementsSVG;
static AtomsTable* sElementsSVG;
/**
* The whitelist of SVG attributes.
*/
static nsTHashtable<nsRefPtrHashKey<nsAtom>>* sAttributesSVG;
static AtomsTable* sAttributesSVG;
/**
* The whitelist of SVG elements.
*/
static nsTHashtable<nsRefPtrHashKey<nsAtom>>* sElementsMathML;
static AtomsTable* sElementsMathML;
/**
* The whitelist of MathML attributes.
*/
static nsTHashtable<nsRefPtrHashKey<nsAtom>>* sAttributesMathML;
static AtomsTable* sAttributesMathML;
/**
* Reusable null principal for URL checks.