Diff
Modified: trunk/Source/WebCore/ChangeLog (253934 => 253935)
--- trunk/Source/WebCore/ChangeLog 2019-12-29 15:59:01 UTC (rev 253934)
+++ trunk/Source/WebCore/ChangeLog 2019-12-29 17:18:35 UTC (rev 253935)
@@ -1,3 +1,43 @@
+2019-12-29 Antti Koivisto <[email protected]>
+
+ Make RuleSet refcounted
+ https://bugs.webkit.org/show_bug.cgi?id=205628
+
+ Reviewed by Zalan Bujtas.
+
+ For safety, and to support shared ownership.
+
+ Also convert a bunch of places that use raw RuleSet pointers to use Ref/RefPtr instead.
+
+ * style/ElementRuleCollector.cpp:
+ (WebCore::Style::ElementRuleCollector::collectMatchingAuthorRules):
+ (WebCore::Style::ElementRuleCollector::collectSlottedPseudoElementRulesForSlot):
+ (WebCore::Style::ElementRuleCollector::matchUserRules):
+ * style/ElementRuleCollector.h:
+ * style/RuleSet.cpp:
+ (WebCore::Style::RuleSet::evaluteDynamicMediaQueryRules):
+ * style/RuleSet.h:
+ (WebCore::Style::RuleSet::create):
+ (WebCore::Style::RuleSet::RuleSetSelectorPair::RuleSetSelectorPair): Deleted.
+ * style/StyleInvalidator.cpp:
+ (WebCore::Style::Invalidator::Invalidator):
+ (WebCore::Style::Invalidator::collectRuleInformation):
+ (WebCore::Style::Invalidator::invalidateIfNeeded):
+ (WebCore::Style::Invalidator::addToMatchElementRuleSets):
+ * style/StyleInvalidator.h:
+ * style/StyleScopeRuleSets.cpp:
+ (WebCore::Style::ScopeRuleSets::ScopeRuleSets):
+ (WebCore::Style::ScopeRuleSets::updateUserAgentMediaQueryStyleIfNeeded const):
+ (WebCore::Style::ScopeRuleSets::initializeUserStyle):
+ (WebCore::Style::makeRuleSet):
+ (WebCore::Style::ScopeRuleSets::resetAuthorStyle):
+ (WebCore::Style::ensureInvalidationRuleSets):
+ * style/StyleScopeRuleSets.h:
+ (WebCore::Style::ScopeRuleSets::authorStyle const):
+ * style/UserAgentStyle.cpp:
+ (WebCore::Style::UserAgentStyle::loadFullDefaultStyle):
+ (WebCore::Style::UserAgentStyle::loadSimpleDefaultStyle):
+
2019-12-29 Zalan Bujtas <[email protected]>
[LFC][IFC] Move soft wrap opportunity code out of LineBreaker
Modified: trunk/Source/WebCore/style/ElementRuleCollector.cpp (253934 => 253935)
--- trunk/Source/WebCore/style/ElementRuleCollector.cpp 2019-12-29 15:59:01 UTC (rev 253934)
+++ trunk/Source/WebCore/style/ElementRuleCollector.cpp 2019-12-29 17:18:35 UTC (rev 253935)
@@ -228,7 +228,7 @@
void ElementRuleCollector::collectMatchingAuthorRules()
{
{
- MatchRequest matchRequest(&m_authorStyle);
+ MatchRequest matchRequest(m_authorStyle.ptr());
collectMatchingRules(matchRequest);
}
@@ -354,8 +354,8 @@
m_mode = SelectorChecker::Mode::CollectingRules;
// Match global author rules.
- MatchRequest matchRequest(&m_authorStyle);
- collectMatchingRulesForList(&m_authorStyle.slottedPseudoElementRules(), matchRequest);
+ MatchRequest matchRequest(m_authorStyle.ptr());
+ collectMatchingRulesForList(&m_authorStyle->slottedPseudoElementRules(), matchRequest);
if (m_matchedRules.isEmpty())
return { };
@@ -375,7 +375,7 @@
clearMatchedRules();
- MatchRequest matchRequest(m_userStyle);
+ MatchRequest matchRequest(m_userStyle.get());
collectMatchingRules(matchRequest);
sortAndTransferMatchedRules(DeclarationOrigin::User);
Modified: trunk/Source/WebCore/style/ElementRuleCollector.h (253934 => 253935)
--- trunk/Source/WebCore/style/ElementRuleCollector.h 2019-12-29 15:59:01 UTC (rev 253934)
+++ trunk/Source/WebCore/style/ElementRuleCollector.h 2019-12-29 17:18:35 UTC (rev 253935)
@@ -152,10 +152,10 @@
const Element& element() const { return m_element.get(); }
const Ref<const Element> m_element;
- const RuleSet& m_authorStyle;
- const RuleSet* m_userStyle { nullptr };
- const RuleSet* m_userAgentMediaQueryStyle { nullptr };
- const SelectorFilter* m_selectorFilter { nullptr };
+ Ref<const RuleSet> m_authorStyle;
+ RefPtr<const RuleSet> m_userStyle;
+ RefPtr<const RuleSet> m_userAgentMediaQueryStyle;
+ const SelectorFilter* m_selectorFilter;
bool m_shouldIncludeEmptyRules { false };
bool m_isPrintStyle { false };
Modified: trunk/Source/WebCore/style/RuleSet.cpp (253934 => 253935)
--- trunk/Source/WebCore/style/RuleSet.cpp 2019-12-29 15:59:01 UTC (rev 253934)
+++ trunk/Source/WebCore/style/RuleSet.cpp 2019-12-29 17:18:35 UTC (rev 253935)
@@ -422,7 +422,7 @@
return { };
auto& ruleSet = m_mediaQueryInvalidationRuleSetCache.ensure(collectedChanges.changedQueryIndexes, [&] {
- auto ruleSet = makeUnique<RuleSet>();
+ auto ruleSet = RuleSet::create();
for (auto* featureVector : collectedChanges.ruleFeatures) {
for (auto& feature : *featureVector)
ruleSet->addRule(*feature.rule, feature.selectorIndex, feature.selectorListIndex);
@@ -430,7 +430,7 @@
return ruleSet;
}).iterator->value;
- return { { DynamicMediaQueryEvaluationChanges::Type::InvalidateStyle, { ruleSet.get() } } };
+ return { { DynamicMediaQueryEvaluationChanges::Type::InvalidateStyle, { ruleSet.copyRef() } } };
}
RuleSet::CollectedMediaQueryChanges RuleSet::evaluteDynamicMediaQueryRules(const MediaQueryEvaluator& evaluator, size_t startIndex)
Modified: trunk/Source/WebCore/style/RuleSet.h (253934 => 253935)
--- trunk/Source/WebCore/style/RuleSet.h 2019-12-29 15:59:01 UTC (rev 253934)
+++ trunk/Source/WebCore/style/RuleSet.h 2019-12-29 17:18:35 UTC (rev 253935)
@@ -43,10 +43,12 @@
class Resolver;
class RuleSet;
+using InvalidationRuleSetVector = Vector<RefPtr<const RuleSet>, 1>;
+
struct DynamicMediaQueryEvaluationChanges {
enum class Type { InvalidateStyle, ResetStyle };
Type type;
- Vector<const RuleSet*, 1> invalidationRuleSets { };
+ InvalidationRuleSetVector invalidationRuleSets { };
void append(DynamicMediaQueryEvaluationChanges&& other)
{
@@ -58,22 +60,11 @@
};
};
-class RuleSet {
- WTF_MAKE_NONCOPYABLE(RuleSet); WTF_MAKE_FAST_ALLOCATED;
+class RuleSet : public RefCounted<RuleSet> {
+ WTF_MAKE_NONCOPYABLE(RuleSet);
public:
- struct RuleSetSelectorPair {
- RuleSetSelectorPair(const CSSSelector* selector, std::unique_ptr<RuleSet> ruleSet)
- : selector(selector), ruleSet(WTFMove(ruleSet))
- { }
- RuleSetSelectorPair(const RuleSetSelectorPair& pair)
- : selector(pair.selector), ruleSet(const_cast<RuleSetSelectorPair*>(&pair)->ruleSet.release())
- { }
+ static Ref<RuleSet> create() { return adoptRef(*new RuleSet); }
- const CSSSelector* selector;
- std::unique_ptr<RuleSet> ruleSet;
- };
-
- RuleSet();
~RuleSet();
typedef Vector<RuleData, 1> RuleDataVector;
@@ -148,6 +139,8 @@
bool hasHostPseudoClassRulesMatchingInShadowTree() const { return m_hasHostPseudoClassRulesMatchingInShadowTree; }
private:
+ RuleSet();
+
enum class AddRulesMode { Normal, ResolverMutationScan };
void addRulesFromSheet(StyleSheetContents&, MediaQueryCollector&, Style::Resolver*, AddRulesMode);
void addChildRules(const Vector<RefPtr<StyleRuleBase>>&, MediaQueryCollector&, Style::Resolver*, AddRulesMode);
@@ -182,7 +175,7 @@
RuleFeatureSet m_features;
bool m_hasViewportDependentMediaQueries { false };
Vector<DynamicMediaQueryRules> m_dynamicMediaQueryRules;
- HashMap<Vector<size_t>, std::unique_ptr<const RuleSet>> m_mediaQueryInvalidationRuleSetCache;
+ HashMap<Vector<size_t>, Ref<const RuleSet>> m_mediaQueryInvalidationRuleSetCache;
};
inline const RuleSet::RuleDataVector* RuleSet::tagRules(const AtomString& key, bool isHTMLName) const
Modified: trunk/Source/WebCore/style/StyleInvalidator.cpp (253934 => 253935)
--- trunk/Source/WebCore/style/StyleInvalidator.cpp 2019-12-29 15:59:01 UTC (rev 253934)
+++ trunk/Source/WebCore/style/StyleInvalidator.cpp 2019-12-29 17:18:35 UTC (rev 253935)
@@ -83,8 +83,8 @@
}
Invalidator::Invalidator(const Vector<StyleSheetContents*>& sheets, const MediaQueryEvaluator& mediaQueryEvaluator)
- : m_ownedRuleSet(makeUnique<RuleSet>())
- , m_ruleSets({ m_ownedRuleSet.get() })
+ : m_ownedRuleSet(RuleSet::create())
+ , m_ruleSets({ m_ownedRuleSet })
, m_dirtiesAllStyle(shouldDirtyAllStyle(sheets))
{
if (m_dirtiesAllStyle)
@@ -97,7 +97,7 @@
m_ruleInformation = collectRuleInformation();
}
-Invalidator::Invalidator(const Vector<const RuleSet*, 1>& ruleSets)
+Invalidator::Invalidator(const InvalidationRuleSetVector& ruleSets)
: m_ruleSets(ruleSets)
, m_ruleInformation(collectRuleInformation())
{
@@ -104,10 +104,12 @@
ASSERT(m_ruleSets.size());
}
+Invalidator::~Invalidator() = default;
+
Invalidator::RuleInformation Invalidator::collectRuleInformation()
{
RuleInformation information;
- for (auto* ruleSet : m_ruleSets) {
+ for (auto& ruleSet : m_ruleSets) {
if (!ruleSet->slottedPseudoElementRules().isEmpty())
information.hasSlottedPseudoElementRules = true;
if (!ruleSet->hostPseudoClassRules().isEmpty())
@@ -137,7 +139,7 @@
switch (element.styleValidity()) {
case Style::Validity::Valid: {
- for (auto* ruleSet : m_ruleSets) {
+ for (auto& ruleSet : m_ruleSets) {
ElementRuleCollector ruleCollector(element, *ruleSet, filter);
ruleCollector.setMode(SelectorChecker::Mode::CollectingRulesIgnoringVirtualPseudoElements);
@@ -321,8 +323,8 @@
void Invalidator::addToMatchElementRuleSets(Invalidator::MatchElementRuleSets& matchElementRuleSets, const InvalidationRuleSet& invalidationRuleSet)
{
matchElementRuleSets.ensure(invalidationRuleSet.matchElement, [] {
- return Vector<const RuleSet*, 1> { };
- }).iterator->value.append(invalidationRuleSet.ruleSet.get());
+ return InvalidationRuleSetVector { };
+ }).iterator->value.append(invalidationRuleSet.ruleSet.copyRef());
}
void Invalidator::invalidateWithMatchElementRuleSets(Element& element, const MatchElementRuleSets& matchElementRuleSets)
Modified: trunk/Source/WebCore/style/StyleInvalidator.h (253934 => 253935)
--- trunk/Source/WebCore/style/StyleInvalidator.h 2019-12-29 15:59:01 UTC (rev 253934)
+++ trunk/Source/WebCore/style/StyleInvalidator.h 2019-12-29 17:18:35 UTC (rev 253935)
@@ -26,6 +26,7 @@
#pragma once
#include "RuleFeature.h"
+#include "RuleSet.h"
#include <wtf/Forward.h>
#include <wtf/HashMap.h>
@@ -40,14 +41,15 @@
namespace Style {
-class RuleSet;
struct InvalidationRuleSet;
class Invalidator {
public:
Invalidator(const Vector<StyleSheetContents*>&, const MediaQueryEvaluator&);
- Invalidator(const Vector<const RuleSet*, 1>&);
+ Invalidator(const InvalidationRuleSetVector&);
+ ~Invalidator();
+
bool dirtiesAllStyle() const { return m_dirtiesAllStyle; }
void invalidateStyle(Document&);
void invalidateStyle(ShadowRoot&);
@@ -55,7 +57,7 @@
static void invalidateShadowParts(ShadowRoot&);
- using MatchElementRuleSets = HashMap<MatchElement, Vector<const RuleSet*, 1>, WTF::IntHash<MatchElement>, WTF::StrongEnumHashTraits<MatchElement>>;
+ using MatchElementRuleSets = HashMap<MatchElement, InvalidationRuleSetVector, WTF::IntHash<MatchElement>, WTF::StrongEnumHashTraits<MatchElement>>;
static void addToMatchElementRuleSets(Invalidator::MatchElementRuleSets&, const InvalidationRuleSet&);
static void invalidateWithMatchElementRuleSets(Element&, const MatchElementRuleSets&);
@@ -75,8 +77,8 @@
};
RuleInformation collectRuleInformation();
- std::unique_ptr<RuleSet> m_ownedRuleSet;
- const Vector<const RuleSet*, 1> m_ruleSets;
+ RefPtr<RuleSet> m_ownedRuleSet;
+ const InvalidationRuleSetVector m_ruleSets;
RuleInformation m_ruleInformation;
Modified: trunk/Source/WebCore/style/StyleScopeRuleSets.cpp (253934 => 253935)
--- trunk/Source/WebCore/style/StyleScopeRuleSets.cpp 2019-12-29 15:59:01 UTC (rev 253934)
+++ trunk/Source/WebCore/style/StyleScopeRuleSets.cpp 2019-12-29 17:18:35 UTC (rev 253935)
@@ -41,7 +41,7 @@
ScopeRuleSets::ScopeRuleSets(Resolver& styleResolver)
: m_styleResolver(styleResolver)
{
- m_authorStyle = makeUnique<RuleSet>();
+ m_authorStyle = RuleSet::create();
m_authorStyle->disableAutoShrinkToFit();
}
@@ -68,7 +68,7 @@
// Media queries on user agent sheet need to evaluated in document context. They behave like author sheets in this respect.
auto& mediaQueryEvaluator = m_styleResolver.mediaQueryEvaluator();
- m_userAgentMediaQueryStyle = makeUnique<RuleSet>();
+ m_userAgentMediaQueryStyle = RuleSet::create();
m_userAgentMediaQueryStyle->addRulesFromSheet(*UserAgentStyle::mediaQueryStyleSheet, nullptr, mediaQueryEvaluator, m_styleResolver);
}
@@ -84,11 +84,11 @@
{
auto& extensionStyleSheets = m_styleResolver.document().extensionStyleSheets();
auto& mediaQueryEvaluator = m_styleResolver.mediaQueryEvaluator();
- auto tempUserStyle = makeUnique<RuleSet>();
+ auto tempUserStyle = RuleSet::create();
if (CSSStyleSheet* pageUserSheet = extensionStyleSheets.pageUserSheet())
tempUserStyle->addRulesFromSheet(pageUserSheet->contents(), nullptr, mediaQueryEvaluator, m_styleResolver);
- collectRulesFromUserStyleSheets(extensionStyleSheets.injectedUserStyleSheets(), *tempUserStyle, mediaQueryEvaluator);
- collectRulesFromUserStyleSheets(extensionStyleSheets.documentUserStyleSheets(), *tempUserStyle, mediaQueryEvaluator);
+ collectRulesFromUserStyleSheets(extensionStyleSheets.injectedUserStyleSheets(), tempUserStyle.get(), mediaQueryEvaluator);
+ collectRulesFromUserStyleSheets(extensionStyleSheets.documentUserStyleSheets(), tempUserStyle.get(), mediaQueryEvaluator);
if (tempUserStyle->ruleCount() > 0 || tempUserStyle->pageRules().size() > 0)
m_userStyle = WTFMove(tempUserStyle);
}
@@ -101,12 +101,12 @@
}
}
-static std::unique_ptr<RuleSet> makeRuleSet(const Vector<RuleFeature>& rules)
+static RefPtr<RuleSet> makeRuleSet(const Vector<RuleFeature>& rules)
{
size_t size = rules.size();
if (!size)
return nullptr;
- auto ruleSet = makeUnique<RuleSet>();
+ auto ruleSet = RuleSet::create();
for (size_t i = 0; i < size; ++i)
ruleSet->addRule(*rules[i].rule, rules[i].selectorIndex, rules[i].selectorListIndex);
ruleSet->shrinkToFit();
@@ -116,7 +116,7 @@
void ScopeRuleSets::resetAuthorStyle()
{
m_isAuthorStyleDefined = true;
- m_authorStyle = makeUnique<RuleSet>();
+ m_authorStyle = RuleSet::create();
m_authorStyle->disableAutoShrinkToFit();
}
@@ -208,13 +208,13 @@
if (!features)
return nullptr;
- std::array<std::unique_ptr<RuleSet>, matchElementCount> matchElementArray;
+ std::array<RefPtr<RuleSet>, matchElementCount> matchElementArray;
std::array<Vector<const CSSSelector*>, matchElementCount> invalidationSelectorArray;
for (auto& feature : *features) {
auto arrayIndex = static_cast<unsigned>(*feature.matchElement);
auto& ruleSet = matchElementArray[arrayIndex];
if (!ruleSet)
- ruleSet = makeUnique<RuleSet>();
+ ruleSet = RuleSet::create();
ruleSet->addRule(*feature.rule, feature.selectorIndex, feature.selectorListIndex);
if (feature.invalidationSelector)
invalidationSelectorArray[arrayIndex].append(feature.invalidationSelector);
@@ -222,7 +222,7 @@
auto invalidationRuleSets = makeUnique<Vector<InvalidationRuleSet>>();
for (unsigned i = 0; i < matchElementArray.size(); ++i) {
if (matchElementArray[i])
- invalidationRuleSets->append({ static_cast<MatchElement>(i), WTFMove(matchElementArray[i]), WTFMove(invalidationSelectorArray[i]) });
+ invalidationRuleSets->append({ static_cast<MatchElement>(i), *matchElementArray[i], WTFMove(invalidationSelectorArray[i]) });
}
return invalidationRuleSets;
}).iterator->value.get();
Modified: trunk/Source/WebCore/style/StyleScopeRuleSets.h (253934 => 253935)
--- trunk/Source/WebCore/style/StyleScopeRuleSets.h 2019-12-29 15:59:01 UTC (rev 253934)
+++ trunk/Source/WebCore/style/StyleScopeRuleSets.h 2019-12-29 17:18:35 UTC (rev 253935)
@@ -44,7 +44,7 @@
struct InvalidationRuleSet {
MatchElement matchElement;
- std::unique_ptr<RuleSet> ruleSet;
+ Ref<RuleSet> ruleSet;
Vector<const CSSSelector*> invalidationSelectors;
WTF_MAKE_FAST_ALLOCATED;
@@ -57,7 +57,7 @@
bool isAuthorStyleDefined() const { return m_isAuthorStyleDefined; }
RuleSet* userAgentMediaQueryStyle() const;
- RuleSet& authorStyle() const { return *m_authorStyle.get(); }
+ RuleSet& authorStyle() const { return *m_authorStyle; }
RuleSet* userStyle() const;
const RuleFeatureSet& features() const;
RuleSet* sibling() const { return m_siblingRuleSet.get(); }
@@ -91,14 +91,14 @@
void collectRulesFromUserStyleSheets(const Vector<RefPtr<CSSStyleSheet>>&, RuleSet& userStyle, const MediaQueryEvaluator&);
void updateUserAgentMediaQueryStyleIfNeeded() const;
- std::unique_ptr<RuleSet> m_authorStyle;
- mutable std::unique_ptr<RuleSet> m_userAgentMediaQueryStyle;
- std::unique_ptr<RuleSet> m_userStyle;
+ RefPtr<RuleSet> m_authorStyle;
+ mutable RefPtr<RuleSet> m_userAgentMediaQueryStyle;
+ RefPtr<RuleSet> m_userStyle;
Resolver& m_styleResolver;
mutable RuleFeatureSet m_features;
- mutable std::unique_ptr<RuleSet> m_siblingRuleSet;
- mutable std::unique_ptr<RuleSet> m_uncommonAttributeRuleSet;
+ mutable RefPtr<RuleSet> m_siblingRuleSet;
+ mutable RefPtr<RuleSet> m_uncommonAttributeRuleSet;
mutable HashMap<AtomString, std::unique_ptr<Vector<InvalidationRuleSet>>> m_classInvalidationRuleSets;
mutable HashMap<AtomString, std::unique_ptr<Vector<InvalidationRuleSet>>> m_attributeInvalidationRuleSets;
Modified: trunk/Source/WebCore/style/UserAgentStyle.cpp (253934 => 253935)
--- trunk/Source/WebCore/style/UserAgentStyle.cpp 2019-12-29 15:59:01 UTC (rev 253934)
+++ trunk/Source/WebCore/style/UserAgentStyle.cpp 2019-12-29 17:18:35 UTC (rev 253935)
@@ -178,11 +178,11 @@
simpleDefaultStyleSheet = nullptr;
} else {
ASSERT(!defaultStyle);
- defaultQuirksStyle = makeUnique<RuleSet>().release();
+ defaultQuirksStyle = &RuleSet::create().leakRef();
}
- defaultStyle = makeUnique<RuleSet>().release();
- defaultPrintStyle = makeUnique<RuleSet>().release();
+ defaultStyle = &RuleSet::create().leakRef();
+ defaultPrintStyle = &RuleSet::create().leakRef();
mediaQueryStyleSheet = &StyleSheetContents::create(CSSParserContext(UASheetMode)).leakRef();
// Strict-mode rules.
@@ -201,10 +201,10 @@
ASSERT(!defaultStyle);
ASSERT(!simpleDefaultStyleSheet);
- defaultStyle = makeUnique<RuleSet>().release();
+ defaultStyle = &RuleSet::create().leakRef();
// There are no media-specific rules in the simple default style.
defaultPrintStyle = defaultStyle;
- defaultQuirksStyle = makeUnique<RuleSet>().release();
+ defaultQuirksStyle = &RuleSet::create().leakRef();
simpleDefaultStyleSheet = parseUASheet(simpleUserAgentStyleSheet, strlen(simpleUserAgentStyleSheet));
defaultStyle->addRulesFromSheet(*simpleDefaultStyleSheet, screenEval());