Title: [112727] trunk/Source/WebCore
Revision
112727
Author
an...@apple.com
Date
2012-03-30 14:23:35 -0700 (Fri, 30 Mar 2012)

Log Message

Cache origin check result to RuleData
https://bugs.webkit.org/show_bug.cgi?id=82774

Reviewed by Andreas Kling.

You wan't be able to get back to the stylesheet from a css style rule soon. 
We need to do the origin check when we know the sheet it came from.

* css/CSSStyleSelector.cpp:
(RuleData):
(WebCore::RuleData::hasDocumentSecurityOrigin):
(RuleSet):
(WebCore::makeRuleSet):
(WebCore::CSSStyleSelector::collectMatchingRulesForList):
* css/CSSStyleSelector.h:
(WebCore::CSSStyleSelector::RuleFeature::RuleFeature):
(RuleFeature):
(Features):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (112726 => 112727)


--- trunk/Source/WebCore/ChangeLog	2012-03-30 21:16:40 UTC (rev 112726)
+++ trunk/Source/WebCore/ChangeLog	2012-03-30 21:23:35 UTC (rev 112727)
@@ -1,3 +1,24 @@
+2012-03-30  Antti Koivisto  <an...@apple.com>
+
+        Cache origin check result to RuleData
+        https://bugs.webkit.org/show_bug.cgi?id=82774
+
+        Reviewed by Andreas Kling.
+
+        You wan't be able to get back to the stylesheet from a css style rule soon. 
+        We need to do the origin check when we know the sheet it came from.
+
+        * css/CSSStyleSelector.cpp:
+        (RuleData):
+        (WebCore::RuleData::hasDocumentSecurityOrigin):
+        (RuleSet):
+        (WebCore::makeRuleSet):
+        (WebCore::CSSStyleSelector::collectMatchingRulesForList):
+        * css/CSSStyleSelector.h:
+        (WebCore::CSSStyleSelector::RuleFeature::RuleFeature):
+        (RuleFeature):
+        (Features):
+
 2012-03-30  Mike Reed  <r...@google.com>
 
         Remove deadcode behind "SafeSkia" flag

Modified: trunk/Source/WebCore/css/CSSStyleSelector.cpp (112726 => 112727)


--- trunk/Source/WebCore/css/CSSStyleSelector.cpp	2012-03-30 21:16:40 UTC (rev 112726)
+++ trunk/Source/WebCore/css/CSSStyleSelector.cpp	2012-03-30 21:23:35 UTC (rev 112727)
@@ -181,7 +181,7 @@
 
 class RuleData {
 public:
-    RuleData(StyleRule*, CSSSelector*, unsigned position, bool canUseFastCheckSelector, bool inRegionRule);
+    RuleData(StyleRule*, CSSSelector*, unsigned position, bool hasDocumentSecurityOrigin, bool canUseFastCheckSelector, bool inRegionRule);
 
     unsigned position() const { return m_position; }
     StyleRule* rule() const { return m_rule; }
@@ -193,6 +193,7 @@
     bool containsUncommonAttributeSelector() const { return m_containsUncommonAttributeSelector; }
     unsigned specificity() const { return m_specificity; }
     unsigned linkMatchType() const { return m_linkMatchType; }
+    bool hasDocumentSecurityOrigin() const { return m_hasDocumentSecurityOrigin; }
     bool isInRegionRule() const { return m_isInRegionRule; }
 
     // Try to balance between memory usage (there can be lots of RuleData objects) and good filtering performance.
@@ -205,12 +206,13 @@
     unsigned m_specificity;
     // This number was picked fairly arbitrarily. We can probably lower it if we need to.
     // Some simple testing showed <100,000 RuleData's on large sites.
-    unsigned m_position : 25;
+    unsigned m_position : 24;
     unsigned m_hasFastCheckableSelector : 1;
     unsigned m_hasMultipartSelector : 1;
     unsigned m_hasRightmostSelectorMatchingHTMLBasedOnRuleHash : 1;
     unsigned m_containsUncommonAttributeSelector : 1;
     unsigned m_linkMatchType : 2; //  SelectorChecker::LinkMatchMask
+    unsigned m_hasDocumentSecurityOrigin : 1;
     unsigned m_isInRegionRule : 1;
     // Use plain array instead of a Vector to minimize memory overhead.
     unsigned m_descendantSelectorIdentifierHashes[maximumIdentifierCount];
@@ -235,11 +237,11 @@
 
     void addRulesFromSheet(CSSStyleSheet*, const MediaQueryEvaluator&, CSSStyleSelector* = 0, const ContainerNode* = 0);
 
-    void addStyleRule(StyleRule*, bool canUseFastCheckSelector = true, bool isInRegionRule = false);
-    void addRule(StyleRule*, CSSSelector*, bool canUseFastCheckSelector = true, bool isInRegionRule = false);
+    void addStyleRule(StyleRule*, bool hasDocumentSecurityOrigin, bool canUseFastCheckSelector, bool isInRegionRule = false);
+    void addRule(StyleRule*, CSSSelector*, bool hasDocumentSecurityOrigin, bool canUseFastCheckSelector, bool isInRegionRule = false);
     void addPageRule(CSSPageRule*);
     void addToRuleSet(AtomicStringImpl* key, AtomRuleMap&, const RuleData&);
-    void addRegionRule(WebKitCSSRegionRule*);
+    void addRegionRule(WebKitCSSRegionRule*, bool hasDocumentSecurityOrigin);
     void shrinkToFit();
     void disableAutoShrinkToFit() { m_autoShrinkToFitEnabled = false; }
 
@@ -422,14 +424,14 @@
     appendAuthorStylesheets(0, document->styleSheets()->vector());
 }
     
-static PassOwnPtr<RuleSet> makeRuleSet(const Vector<CSSStyleSelector::RuleSelectorPair>& rules)
+static PassOwnPtr<RuleSet> makeRuleSet(const Vector<CSSStyleSelector::RuleFeature>& rules)
 {
     size_t size = rules.size();
     if (!size)
         return nullptr;
     OwnPtr<RuleSet> ruleSet = adoptPtr(new RuleSet);
     for (size_t i = 0; i < size; ++i)
-        ruleSet->addRule(rules[i].rule, rules[i].selector);
+        ruleSet->addRule(rules[i].rule, rules[i].selector, rules[i].hasDocumentSecurityOrigin, false);
     return ruleSet.release();
 }
 
@@ -1024,8 +1026,8 @@
                 InspectorInstrumentation::didMatchRule(cookie, false);
                 continue;
             }
-            // FIXME: Exposing getMatchedCSSRules as a web facing API is forcing us to have a way to get the base URL per-rule.
-            if (m_sameOriginOnly && !m_checker.document()->securityOrigin()->canRequest(rule->ensureCSSStyleRule()->baseURL())) {
+            // FIXME: Exposing the non-standard getMatchedCSSRules API to web is the only reason this is needed.
+            if (m_sameOriginOnly && !ruleData.hasDocumentSecurityOrigin()) {
                 InspectorInstrumentation::didMatchRule(cookie, false);
                 continue;
             }
@@ -2311,7 +2313,7 @@
     return false;
 }
 
-RuleData::RuleData(StyleRule* rule, CSSSelector* selector, unsigned position, bool canUseFastCheckSelector, bool inRegionRule)
+RuleData::RuleData(StyleRule* rule, CSSSelector* selector, unsigned position, bool hasDocumentSecurityOrigin, bool canUseFastCheckSelector, bool inRegionRule)
     : m_rule(rule)
     , m_selector(selector)
     , m_specificity(selector->specificity())
@@ -2321,6 +2323,7 @@
     , m_hasRightmostSelectorMatchingHTMLBasedOnRuleHash(isSelectorMatchingHTMLBasedOnRuleHash(selector))
     , m_containsUncommonAttributeSelector(WebCore::containsUncommonAttributeSelector(selector))
     , m_linkMatchType(SelectorChecker::determineLinkMatchType(selector))
+    , m_hasDocumentSecurityOrigin(hasDocumentSecurityOrigin)
     , m_isInRegionRule(inRegionRule)
 {
     SelectorChecker::collectIdentifierHashes(m_selector, m_descendantSelectorIdentifierHashes, maximumIdentifierCount);
@@ -2371,9 +2374,9 @@
             foundSiblingSelector = true;
     }
     if (foundSiblingSelector)
-        features.siblingRules.append(CSSStyleSelector::RuleSelectorPair(ruleData.rule(), ruleData.selector()));
+        features.siblingRules.append(CSSStyleSelector::RuleFeature(ruleData.rule(), ruleData.selector(), ruleData.hasDocumentSecurityOrigin()));
     if (ruleData.containsUncommonAttributeSelector())
-        features.uncommonAttributeRules.append(CSSStyleSelector::RuleSelectorPair(ruleData.rule(), ruleData.selector()));
+        features.uncommonAttributeRules.append(CSSStyleSelector::RuleFeature(ruleData.rule(), ruleData.selector(), ruleData.hasDocumentSecurityOrigin()));
 }
     
 void RuleSet::addToRuleSet(AtomicStringImpl* key, AtomRuleMap& map, const RuleData& ruleData)
@@ -2386,9 +2389,9 @@
     rules->append(ruleData);
 }
 
-void RuleSet::addRule(StyleRule* rule, CSSSelector* selector, bool canUseFastCheckSelector, bool inRegionRule)
+void RuleSet::addRule(StyleRule* rule, CSSSelector* selector, bool hasDocumentSecurityOrigin, bool canUseFastCheckSelector, bool inRegionRule)
 {
-    RuleData ruleData(rule, selector, m_ruleCount++, canUseFastCheckSelector, inRegionRule);
+    RuleData ruleData(rule, selector, m_ruleCount++, hasDocumentSecurityOrigin, canUseFastCheckSelector, inRegionRule);
     collectFeaturesFromRuleData(m_features, ruleData);
 
     if (selector->m_match == CSSSelector::Id) {
@@ -2431,7 +2434,7 @@
     m_pageRules.append(rule);
 }
 
-void RuleSet::addRegionRule(WebKitCSSRegionRule* regionRule)
+void RuleSet::addRegionRule(WebKitCSSRegionRule* regionRule, bool hasDocumentSecurityOrigin)
 {
     RuleSet* regionRuleSet = new RuleSet;
     // The region rule set should take into account the position inside the parent rule set.
@@ -2444,7 +2447,7 @@
     for (unsigned i = 0; i < rulesSize; ++i) {
         CSSRule* regionStylingRule = regionRule->ruleAt(i);
         if (regionStylingRule->isStyleRule())
-            regionRuleSet->addStyleRule(static_cast<CSSStyleRule*>(regionStylingRule)->styleRule(), true, true);
+            regionRuleSet->addStyleRule(static_cast<CSSStyleRule*>(regionStylingRule)->styleRule(), hasDocumentSecurityOrigin, true, true);
     }
     // Update the "global" rule count so that proper order is maintained
     m_ruleCount = regionRuleSet->m_ruleCount;
@@ -2467,6 +2470,7 @@
         if (importRule->styleSheet() && (!importRule->mediaQueries() || medium.eval(importRule->mediaQueries(), styleSelector)))
             addRulesFromSheet(importRule->styleSheet(), medium, styleSelector, scope);
     }
+    bool hasDocumentSecurityOrigin = styleSelector && styleSelector->document()->securityOrigin()->canRequest(sheet->baseURL());
 
     const Vector<RefPtr<CSSRule> >& rules = sheet->childRules();
     for (unsigned i = 0; i < rules.size(); ++i) {
@@ -2474,7 +2478,7 @@
 
         ASSERT(!rule->isImportRule());
         if (rule->isStyleRule())
-            addStyleRule(static_cast<CSSStyleRule*>(rule)->styleRule(), !scope);
+            addStyleRule(static_cast<CSSStyleRule*>(rule)->styleRule(), hasDocumentSecurityOrigin, !scope);
         else if (rule->isPageRule())
             addPageRule(static_cast<CSSPageRule*>(rule));
         else if (rule->isMediaRule()) {
@@ -2485,7 +2489,7 @@
                 for (unsigned j = 0; j < mediaRule->ruleCount(); j++) {
                     CSSRule* childRule = mediaRule->ruleAt(j);
                     if (childRule->isStyleRule())
-                        addStyleRule(static_cast<CSSStyleRule*>(childRule)->styleRule(), !scope);
+                        addStyleRule(static_cast<CSSStyleRule*>(childRule)->styleRule(), hasDocumentSecurityOrigin, !scope);
                     else if (childRule->isPageRule())
                         addPageRule(static_cast<CSSPageRule*>(childRule));
                     else if (childRule->isFontFaceRule() && styleSelector) {
@@ -2522,17 +2526,17 @@
             // FIXME (BUG 72472): We don't add @-webkit-region rules of scoped style sheets for the moment.
             if (scope)
                 continue;
-            addRegionRule(static_cast<WebKitCSSRegionRule*>(rule));
+            addRegionRule(static_cast<WebKitCSSRegionRule*>(rule), hasDocumentSecurityOrigin);
         }
     }
     if (m_autoShrinkToFitEnabled)
         shrinkToFit();
 }
 
-void RuleSet::addStyleRule(StyleRule* rule, bool canUseFastCheckSelector, bool isInRegionRule)
+void RuleSet::addStyleRule(StyleRule* rule, bool hasDocumentSecurityOrigin, bool canUseFastCheckSelector, bool isInRegionRule)
 {
     for (CSSSelector* s = rule->selectorList().first(); s; s = CSSSelectorList::next(s))
-        addRule(rule, s, canUseFastCheckSelector, isInRegionRule);
+        addRule(rule, s, hasDocumentSecurityOrigin, canUseFastCheckSelector, isInRegionRule);
 }
 
 static inline void shrinkMapVectorsToFit(RuleSet::AtomRuleMap& map)

Modified: trunk/Source/WebCore/css/CSSStyleSelector.h (112726 => 112727)


--- trunk/Source/WebCore/css/CSSStyleSelector.h	2012-03-30 21:16:40 UTC (rev 112726)
+++ trunk/Source/WebCore/css/CSSStyleSelector.h	2012-03-30 21:23:35 UTC (rev 112727)
@@ -238,10 +238,16 @@
 #endif
 #endif // ENABLE(CSS_FILTERS)
 
-    struct RuleSelectorPair {
-        RuleSelectorPair(StyleRule* rule, CSSSelector* selector) : rule(rule), selector(selector) { }
+    struct RuleFeature {
+        RuleFeature(StyleRule* rule, CSSSelector* selector, bool hasDocumentSecurityOrigin)
+            : rule(rule)
+            , selector(selector)
+            , hasDocumentSecurityOrigin(hasDocumentSecurityOrigin) 
+        { 
+        }
         StyleRule* rule;
         CSSSelector* selector;
+        bool hasDocumentSecurityOrigin;
     };
     struct Features {
         Features();
@@ -250,8 +256,8 @@
         void clear();
         HashSet<AtomicStringImpl*> idsInRules;
         HashSet<AtomicStringImpl*> attrsInRules;
-        Vector<RuleSelectorPair> siblingRules;
-        Vector<RuleSelectorPair> uncommonAttributeRules;
+        Vector<RuleFeature> siblingRules;
+        Vector<RuleFeature> uncommonAttributeRules;
         bool usesFirstLineRules;
         bool usesBeforeAfterRules;
         bool usesLinkRules;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to