Changeset 216069 in webkit
- Timestamp:
- May 2, 2017, 7:30:30 AM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r216068 r216069 1 2017-05-02 Antti Koivisto <antti@apple.com> 2 3 Document style resolvers should share user rulesets 4 https://bugs.webkit.org/show_bug.cgi?id=171549 5 6 Reviewed by Andreas Kling. 7 8 Large user stylesheets (like those used by ad blockers) can end up using lots of memory if 9 a document uses large number of shadow trees. User style is inherently per-document and 10 the resulting rulesets can be shared between the document and the shadow trees. 11 12 * css/DocumentRuleSets.cpp: 13 (WebCore::DocumentRuleSets::DocumentRuleSets): 14 (WebCore::DocumentRuleSets::userStyle): 15 16 Return per-document user style for shadow trees. 17 18 (WebCore::DocumentRuleSets::collectFeatures): 19 * css/DocumentRuleSets.h: 20 (WebCore::DocumentRuleSets::setUsesSharedUserStyle): 21 (WebCore::DocumentRuleSets::userStyle): Deleted. 22 * css/StyleResolver.cpp: 23 (WebCore::StyleResolver::StyleResolver): 24 (WebCore::StyleResolver::initializeUserStyle): 25 26 Separate user style initialization from construction. 27 28 * css/StyleResolver.h: 29 * style/StyleScope.cpp: 30 (WebCore::Style::Scope::resolver): 31 32 Don't initialize user style for user agents shadow trees. 33 1 34 2017-05-02 Gwang Yoon Hwang <yoon@igalia.com> 2 35 -
trunk/Source/WebCore/css/DocumentRuleSets.cpp
r214255 r216069 38 38 namespace WebCore { 39 39 40 DocumentRuleSets::DocumentRuleSets() 40 DocumentRuleSets::DocumentRuleSets(StyleResolver& styleResolver) 41 : m_styleResolver(styleResolver) 41 42 { 42 43 m_authorStyle = std::make_unique<RuleSet>(); … … 46 47 DocumentRuleSets::~DocumentRuleSets() 47 48 { 49 } 50 51 RuleSet* DocumentRuleSets::userStyle() const 52 { 53 if (m_usesSharedUserStyle) 54 return m_styleResolver.document().styleScope().resolver().ruleSets().userStyle(); 55 return m_userStyle.get(); 48 56 } 49 57 … … 113 121 if (m_authorStyle) 114 122 m_features.add(m_authorStyle->features()); 115 if ( m_userStyle)116 m_features.add( m_userStyle->features());123 if (auto* userStyle = this->userStyle()) 124 m_features.add(userStyle->features()); 117 125 118 126 m_siblingRuleSet = makeRuleSet(m_features.siblingRules); -
trunk/Source/WebCore/css/DocumentRuleSets.h
r214255 r216069 41 41 class DocumentRuleSets { 42 42 public: 43 DocumentRuleSets( );43 DocumentRuleSets(StyleResolver&); 44 44 ~DocumentRuleSets(); 45 45 46 46 bool isAuthorStyleDefined() const { return m_isAuthorStyleDefined; } 47 47 RuleSet& authorStyle() const { return *m_authorStyle.get(); } 48 RuleSet* userStyle() const { return m_userStyle.get(); }48 RuleSet* userStyle() const; 49 49 const RuleFeatureSet& features() const; 50 50 RuleSet* sibling() const { return m_siblingRuleSet.get(); } … … 60 60 const AttributeRules* ancestorAttributeRulesForHTML(const AtomicString&) const; 61 61 62 void setUsesSharedUserStyle(bool b) { m_usesSharedUserStyle = true; } 62 63 void initUserStyle(ExtensionStyleSheets&, const MediaQueryEvaluator&, StyleResolver&); 64 63 65 void resetAuthorStyle(); 64 66 void appendAuthorStyleSheets(const Vector<RefPtr<CSSStyleSheet>>&, MediaQueryEvaluator*, InspectorCSSOMWrappers&, StyleResolver*); … … 73 75 std::unique_ptr<RuleSet> m_authorStyle; 74 76 std::unique_ptr<RuleSet> m_userStyle; 77 bool m_usesSharedUserStyle { false }; 75 78 79 StyleResolver& m_styleResolver; 76 80 mutable RuleFeatureSet m_features; 77 81 mutable unsigned m_defaultStyleVersionOnFeatureCollection { 0 }; -
trunk/Source/WebCore/css/StyleResolver.cpp
r215375 r216069 229 229 230 230 StyleResolver::StyleResolver(Document& document) 231 : m_matchedPropertiesCacheAdditionsSinceLastSweep(0) 231 : m_ruleSets(*this) 232 , m_matchedPropertiesCacheAdditionsSinceLastSweep(0) 232 233 , m_matchedPropertiesCacheSweepTimer(*this, &StyleResolver::sweepMatchedPropertiesCache) 233 234 , m_document(document) … … 268 269 m_ruleSets.resetAuthorStyle(); 269 270 270 m_ruleSets.initUserStyle(m_document.extensionStyleSheets(), m_mediaQueryEvaluator, *this);271 272 271 #if ENABLE(SVG_FONTS) 273 272 if (m_document.svgExtensions()) { … … 277 276 } 278 277 #endif 278 } 279 280 void StyleResolver::initializeUserStyle() 281 { 282 m_ruleSets.initUserStyle(m_document.extensionStyleSheets(), m_mediaQueryEvaluator, *this); 279 283 } 280 284 -
trunk/Source/WebCore/css/StyleResolver.h
r214255 r216069 153 153 const Settings& settings() const { return m_document.settings(); } 154 154 155 void initializeUserStyle(); 155 156 void appendAuthorStyleSheets(const Vector<RefPtr<CSSStyleSheet>>&); 156 157 -
trunk/Source/WebCore/style/StyleScope.cpp
r215160 r216069 97 97 SetForScope<bool> isUpdatingStyleResolver { m_isUpdatingStyleResolver, true }; 98 98 m_resolver = std::make_unique<StyleResolver>(m_document); 99 100 if (!m_shadowRoot) 101 m_resolver->initializeUserStyle(); 102 else if (m_shadowRoot->mode() != ShadowRootMode::UserAgent) 103 m_resolver->ruleSets().setUsesSharedUserStyle(); 104 99 105 m_resolver->appendAuthorStyleSheets(m_activeStyleSheets); 100 106 }
Note:
See TracChangeset
for help on using the changeset viewer.