<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[225650] trunk/Source/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/225650">225650</a></dd>
<dt>Author</dt> <dd>antti@apple.com</dd>
<dt>Date</dt> <dd>2017-12-07 15:58:39 -0800 (Thu, 07 Dec 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>Move security origin filtering for getMatchedCSSRules out of StyleResolver
https://bugs.webkit.org/show_bug.cgi?id=180468

Reviewed by Zalan Bujtas.

The non-standard getMatchedCSSRules API should not return rules from stylesheets in different security origins.
To implement this we currently have lots of invasive code in StyleResolver, RuleSets and ElementRuleCollector
basically passing around a bit. This also makes RuleSets document specific blocking optimizations.

This patches replaces the mechanism with a bit in StyleRule which is much simpler.

* css/DocumentRuleSets.cpp:
(WebCore::makeRuleSet):
* css/ElementRuleCollector.cpp:
(WebCore::ElementRuleCollector::collectMatchingRulesForList):
* css/ElementRuleCollector.h:
(WebCore::ElementRuleCollector::setPseudoStyleRequest):
(WebCore::ElementRuleCollector::setSameOriginOnly): Deleted.
* css/RuleFeature.cpp:
(WebCore::RuleFeatureSet::collectFeatures):
* css/RuleFeature.h:
(WebCore::RuleFeature::RuleFeature):
* css/RuleSet.cpp:
(WebCore::RuleData::RuleData):
(WebCore::RuleSet::addRule):
(WebCore::RuleSet::addChildRules):
(WebCore::RuleSet::addRulesFromSheet):
(WebCore::RuleSet::addStyleRule):
* css/RuleSet.h:
(WebCore::RuleData::linkMatchType const):
(WebCore::RuleData::hasDocumentSecurityOrigin const): Deleted.
* css/StyleResolver.cpp:
(WebCore::StyleResolver::pseudoStyleRulesForElement):
* css/StyleResolver.h:
* css/StyleRule.cpp:
(WebCore::StyleRule::StyleRule):
(WebCore::StyleRule::createForSplitting):
(WebCore::StyleRule::splitIntoMultipleRulesWithMaximumSelectorComponentCount const):
(WebCore::StyleRule::create): Deleted.
* css/StyleRule.h:
(WebCore::StyleRuleBase::StyleRuleBase):
(WebCore::StyleRuleBase::hasDocumentSecurityOrigin const):

    Add a bit.

* css/parser/CSSParser.cpp:
(WebCore::CSSParserContext::CSSParserContext):

    Include hasDocumentSecurityOrigin bit to parser context. This means that a stylesheet data structures
    can't be shared between a contexts where this differs. This likely very rare in practice.

(WebCore::operator==):
* css/parser/CSSParserImpl.cpp:
(WebCore::CSSParserImpl::consumeStyleRule):
* css/parser/CSSParserMode.h:
(WebCore::CSSParserContextHash::hash):
* editing/EditingStyle.cpp:
(WebCore::EditingStyle::mergeStyleFromRules):
* page/DOMWindow.cpp:
(WebCore::DOMWindow::getMatchedCSSRules const):

    Filter out rules from different security origin after getting them from style resolver.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorecssDocumentRuleSetscpp">trunk/Source/WebCore/css/DocumentRuleSets.cpp</a></li>
<li><a href="#trunkSourceWebCorecssElementRuleCollectorcpp">trunk/Source/WebCore/css/ElementRuleCollector.cpp</a></li>
<li><a href="#trunkSourceWebCorecssElementRuleCollectorh">trunk/Source/WebCore/css/ElementRuleCollector.h</a></li>
<li><a href="#trunkSourceWebCorecssRuleFeaturecpp">trunk/Source/WebCore/css/RuleFeature.cpp</a></li>
<li><a href="#trunkSourceWebCorecssRuleFeatureh">trunk/Source/WebCore/css/RuleFeature.h</a></li>
<li><a href="#trunkSourceWebCorecssRuleSetcpp">trunk/Source/WebCore/css/RuleSet.cpp</a></li>
<li><a href="#trunkSourceWebCorecssRuleSeth">trunk/Source/WebCore/css/RuleSet.h</a></li>
<li><a href="#trunkSourceWebCorecssStyleResolvercpp">trunk/Source/WebCore/css/StyleResolver.cpp</a></li>
<li><a href="#trunkSourceWebCorecssStyleResolverh">trunk/Source/WebCore/css/StyleResolver.h</a></li>
<li><a href="#trunkSourceWebCorecssStyleRulecpp">trunk/Source/WebCore/css/StyleRule.cpp</a></li>
<li><a href="#trunkSourceWebCorecssStyleRuleh">trunk/Source/WebCore/css/StyleRule.h</a></li>
<li><a href="#trunkSourceWebCorecssparserCSSParsercpp">trunk/Source/WebCore/css/parser/CSSParser.cpp</a></li>
<li><a href="#trunkSourceWebCorecssparserCSSParserImplcpp">trunk/Source/WebCore/css/parser/CSSParserImpl.cpp</a></li>
<li><a href="#trunkSourceWebCorecssparserCSSParserModeh">trunk/Source/WebCore/css/parser/CSSParserMode.h</a></li>
<li><a href="#trunkSourceWebCoreeditingEditingStylecpp">trunk/Source/WebCore/editing/EditingStyle.cpp</a></li>
<li><a href="#trunkSourceWebCorepageDOMWindowcpp">trunk/Source/WebCore/page/DOMWindow.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (225649 => 225650)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2017-12-07 23:55:42 UTC (rev 225649)
+++ trunk/Source/WebCore/ChangeLog      2017-12-07 23:58:39 UTC (rev 225650)
</span><span class="lines">@@ -1,3 +1,68 @@
</span><ins>+2017-12-07  Antti Koivisto  <antti@apple.com>
+
+        Move security origin filtering for getMatchedCSSRules out of StyleResolver
+        https://bugs.webkit.org/show_bug.cgi?id=180468
+
+        Reviewed by Zalan Bujtas.
+
+        The non-standard getMatchedCSSRules API should not return rules from stylesheets in different security origins.
+        To implement this we currently have lots of invasive code in StyleResolver, RuleSets and ElementRuleCollector
+        basically passing around a bit. This also makes RuleSets document specific blocking optimizations.
+
+        This patches replaces the mechanism with a bit in StyleRule which is much simpler.
+
+        * css/DocumentRuleSets.cpp:
+        (WebCore::makeRuleSet):
+        * css/ElementRuleCollector.cpp:
+        (WebCore::ElementRuleCollector::collectMatchingRulesForList):
+        * css/ElementRuleCollector.h:
+        (WebCore::ElementRuleCollector::setPseudoStyleRequest):
+        (WebCore::ElementRuleCollector::setSameOriginOnly): Deleted.
+        * css/RuleFeature.cpp:
+        (WebCore::RuleFeatureSet::collectFeatures):
+        * css/RuleFeature.h:
+        (WebCore::RuleFeature::RuleFeature):
+        * css/RuleSet.cpp:
+        (WebCore::RuleData::RuleData):
+        (WebCore::RuleSet::addRule):
+        (WebCore::RuleSet::addChildRules):
+        (WebCore::RuleSet::addRulesFromSheet):
+        (WebCore::RuleSet::addStyleRule):
+        * css/RuleSet.h:
+        (WebCore::RuleData::linkMatchType const):
+        (WebCore::RuleData::hasDocumentSecurityOrigin const): Deleted.
+        * css/StyleResolver.cpp:
+        (WebCore::StyleResolver::pseudoStyleRulesForElement):
+        * css/StyleResolver.h:
+        * css/StyleRule.cpp:
+        (WebCore::StyleRule::StyleRule):
+        (WebCore::StyleRule::createForSplitting):
+        (WebCore::StyleRule::splitIntoMultipleRulesWithMaximumSelectorComponentCount const):
+        (WebCore::StyleRule::create): Deleted.
+        * css/StyleRule.h:
+        (WebCore::StyleRuleBase::StyleRuleBase):
+        (WebCore::StyleRuleBase::hasDocumentSecurityOrigin const):
+
+            Add a bit.
+
+        * css/parser/CSSParser.cpp:
+        (WebCore::CSSParserContext::CSSParserContext):
+
+            Include hasDocumentSecurityOrigin bit to parser context. This means that a stylesheet data structures
+            can't be shared between a contexts where this differs. This likely very rare in practice.
+
+        (WebCore::operator==):
+        * css/parser/CSSParserImpl.cpp:
+        (WebCore::CSSParserImpl::consumeStyleRule):
+        * css/parser/CSSParserMode.h:
+        (WebCore::CSSParserContextHash::hash):
+        * editing/EditingStyle.cpp:
+        (WebCore::EditingStyle::mergeStyleFromRules):
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::getMatchedCSSRules const):
+
+            Filter out rules from different security origin after getting them from style resolver.
+
</ins><span class="cx"> 2017-12-07  Zalan Bujtas  <zalan@apple.com>
</span><span class="cx"> 
</span><span class="cx">         AX: Document::existingAXObjectCache() should always return the existing AXObjectCache.
</span></span></pre></div>
<a id="trunkSourceWebCorecssDocumentRuleSetscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/DocumentRuleSets.cpp (225649 => 225650)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/DocumentRuleSets.cpp    2017-12-07 23:55:42 UTC (rev 225649)
+++ trunk/Source/WebCore/css/DocumentRuleSets.cpp       2017-12-07 23:58:39 UTC (rev 225650)
</span><span class="lines">@@ -114,7 +114,7 @@
</span><span class="cx">         return nullptr;
</span><span class="cx">     auto ruleSet = std::make_unique<RuleSet>();
</span><span class="cx">     for (size_t i = 0; i < size; ++i)
</span><del>-        ruleSet->addRule(rules[i].rule, rules[i].selectorIndex, rules[i].hasDocumentSecurityOrigin ? RuleHasDocumentSecurityOrigin : RuleHasNoSpecialState);
</del><ins>+        ruleSet->addRule(rules[i].rule, rules[i].selectorIndex);
</ins><span class="cx">     ruleSet->shrinkToFit();
</span><span class="cx">     return ruleSet;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCorecssElementRuleCollectorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/ElementRuleCollector.cpp (225649 => 225650)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/ElementRuleCollector.cpp        2017-12-07 23:55:42 UTC (rev 225649)
+++ trunk/Source/WebCore/css/ElementRuleCollector.cpp   2017-12-07 23:58:39 UTC (rev 225650)
</span><span class="lines">@@ -476,10 +476,6 @@
</span><span class="cx">         if (properties && properties->isEmpty() && !matchRequest.includeEmptyRules)
</span><span class="cx">             continue;
</span><span class="cx"> 
</span><del>-        // FIXME: Exposing the non-standard getMatchedCSSRules API to web is the only reason this is needed.
-        if (m_sameOriginOnly && !ruleData.hasDocumentSecurityOrigin())
-            continue;
-
</del><span class="cx">         unsigned specificity;
</span><span class="cx">         if (ruleMatches(ruleData, specificity))
</span><span class="cx">             addMatchedRule(ruleData, specificity, matchRequest.styleScopeOrdinal, ruleRange);
</span></span></pre></div>
<a id="trunkSourceWebCorecssElementRuleCollectorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/ElementRuleCollector.h (225649 => 225650)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/ElementRuleCollector.h  2017-12-07 23:55:42 UTC (rev 225649)
+++ trunk/Source/WebCore/css/ElementRuleCollector.h     2017-12-07 23:58:39 UTC (rev 225650)
</span><span class="lines">@@ -54,7 +54,6 @@
</span><span class="cx"> 
</span><span class="cx">     void setMode(SelectorChecker::Mode mode) { m_mode = mode; }
</span><span class="cx">     void setPseudoStyleRequest(const PseudoStyleRequest& request) { m_pseudoStyleRequest = request; }
</span><del>-    void setSameOriginOnly(bool f) { m_sameOriginOnly = f; } 
</del><span class="cx">     void setMedium(const MediaQueryEvaluator* medium) { m_isPrintStyle = medium->mediaTypeMatchSpecific("print"); }
</span><span class="cx"> 
</span><span class="cx">     bool hasAnyMatchingRules(const RuleSet*);
</span><span class="lines">@@ -97,7 +96,6 @@
</span><span class="cx"> 
</span><span class="cx">     bool m_isPrintStyle { false };
</span><span class="cx">     PseudoStyleRequest m_pseudoStyleRequest { NOPSEUDO };
</span><del>-    bool m_sameOriginOnly { false };
</del><span class="cx">     SelectorChecker::Mode m_mode { SelectorChecker::Mode::ResolvingStyle };
</span><span class="cx">     bool m_isMatchingSlottedPseudoElements { false };
</span><span class="cx">     bool m_isMatchingHostPseudoClass { false };
</span></span></pre></div>
<a id="trunkSourceWebCorecssRuleFeaturecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/RuleFeature.cpp (225649 => 225650)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/RuleFeature.cpp 2017-12-07 23:55:42 UTC (rev 225649)
+++ trunk/Source/WebCore/css/RuleFeature.cpp    2017-12-07 23:58:39 UTC (rev 225650)
</span><span class="lines">@@ -96,14 +96,14 @@
</span><span class="cx">     SelectorFeatures selectorFeatures;
</span><span class="cx">     recursivelyCollectFeaturesFromSelector(selectorFeatures, *ruleData.selector());
</span><span class="cx">     if (selectorFeatures.hasSiblingSelector)
</span><del>-        siblingRules.append(RuleFeature(ruleData.rule(), ruleData.selectorIndex(), ruleData.hasDocumentSecurityOrigin()));
</del><ins>+        siblingRules.append(RuleFeature(ruleData.rule(), ruleData.selectorIndex()));
</ins><span class="cx">     if (ruleData.containsUncommonAttributeSelector())
</span><del>-        uncommonAttributeRules.append(RuleFeature(ruleData.rule(), ruleData.selectorIndex(), ruleData.hasDocumentSecurityOrigin()));
</del><ins>+        uncommonAttributeRules.append(RuleFeature(ruleData.rule(), ruleData.selectorIndex()));
</ins><span class="cx">     for (auto& className : selectorFeatures.classesMatchingAncestors) {
</span><span class="cx">         auto addResult = ancestorClassRules.ensure(className, [] {
</span><span class="cx">             return std::make_unique<Vector<RuleFeature>>();
</span><span class="cx">         });
</span><del>-        addResult.iterator->value->append(RuleFeature(ruleData.rule(), ruleData.selectorIndex(), ruleData.hasDocumentSecurityOrigin()));
</del><ins>+        addResult.iterator->value->append(RuleFeature(ruleData.rule(), ruleData.selectorIndex()));
</ins><span class="cx">     }
</span><span class="cx">     for (auto* selector : selectorFeatures.attributeSelectorsMatchingAncestors) {
</span><span class="cx">         // Hashing by attributeCanonicalLocalName makes this HTML specific.
</span><span class="lines">@@ -111,7 +111,7 @@
</span><span class="cx">             return std::make_unique<AttributeRules>();
</span><span class="cx">         });
</span><span class="cx">         auto& rules = *addResult.iterator->value;
</span><del>-        rules.features.append(RuleFeature(ruleData.rule(), ruleData.selectorIndex(), ruleData.hasDocumentSecurityOrigin()));
</del><ins>+        rules.features.append(RuleFeature(ruleData.rule(), ruleData.selectorIndex()));
</ins><span class="cx">         // Deduplicate selectors.
</span><span class="cx">         rules.selectors.add(makeAttributeSelectorKey(*selector), selector);
</span><span class="cx">     }
</span></span></pre></div>
<a id="trunkSourceWebCorecssRuleFeatureh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/RuleFeature.h (225649 => 225650)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/RuleFeature.h   2017-12-07 23:55:42 UTC (rev 225649)
+++ trunk/Source/WebCore/css/RuleFeature.h      2017-12-07 23:58:39 UTC (rev 225650)
</span><span class="lines">@@ -34,15 +34,13 @@
</span><span class="cx"> class StyleRule;
</span><span class="cx"> 
</span><span class="cx"> struct RuleFeature {
</span><del>-    RuleFeature(StyleRule* rule, unsigned selectorIndex, bool hasDocumentSecurityOrigin)
</del><ins>+    RuleFeature(StyleRule* rule, unsigned selectorIndex)
</ins><span class="cx">         : rule(rule)
</span><span class="cx">         , selectorIndex(selectorIndex)
</span><del>-        , hasDocumentSecurityOrigin(hasDocumentSecurityOrigin) 
-    { 
</del><ins>+    {
</ins><span class="cx">     }
</span><span class="cx">     StyleRule* rule;
</span><span class="cx">     unsigned selectorIndex;
</span><del>-    bool hasDocumentSecurityOrigin;
</del><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> struct RuleFeatureSet {
</span></span></pre></div>
<a id="trunkSourceWebCorecssRuleSetcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/RuleSet.cpp (225649 => 225650)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/RuleSet.cpp     2017-12-07 23:55:42 UTC (rev 225649)
+++ trunk/Source/WebCore/css/RuleSet.cpp        2017-12-07 23:58:39 UTC (rev 225650)
</span><span class="lines">@@ -148,10 +148,9 @@
</span><span class="cx">     return PropertyWhitelistNone;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-RuleData::RuleData(StyleRule* rule, unsigned selectorIndex, unsigned position, AddRuleFlags addRuleFlags)
</del><ins>+RuleData::RuleData(StyleRule* rule, unsigned selectorIndex, unsigned position)
</ins><span class="cx">     : m_rule(rule)
</span><span class="cx">     , m_selectorIndex(selectorIndex)
</span><del>-    , m_hasDocumentSecurityOrigin(addRuleFlags & RuleHasDocumentSecurityOrigin)
</del><span class="cx">     , m_position(position)
</span><span class="cx">     , m_matchBasedOnRuleHash(static_cast<unsigned>(computeMatchBasedOnRuleHash(*selector())))
</span><span class="cx">     , m_canMatchPseudoElement(selectorCanMatchPseudoElement(*selector()))
</span><span class="lines">@@ -202,9 +201,9 @@
</span><span class="cx">     return leftmostSelector->match() == CSSSelector::PseudoClass && leftmostSelector->pseudoClassType() == CSSSelector::PseudoClassHost;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void RuleSet::addRule(StyleRule* rule, unsigned selectorIndex, AddRuleFlags addRuleFlags)
</del><ins>+void RuleSet::addRule(StyleRule* rule, unsigned selectorIndex)
</ins><span class="cx"> {
</span><del>-    RuleData ruleData(rule, selectorIndex, m_ruleCount++, addRuleFlags);
</del><ins>+    RuleData ruleData(rule, selectorIndex, m_ruleCount++);
</ins><span class="cx">     m_features.collectFeatures(ruleData);
</span><span class="cx"> 
</span><span class="cx">     unsigned classBucketSize = 0;
</span><span class="lines">@@ -360,17 +359,17 @@
</span><span class="cx">     m_pageRules.append(rule);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void RuleSet::addChildRules(const Vector<RefPtr<StyleRuleBase>>& rules, const MediaQueryEvaluator& medium, StyleResolver* resolver, bool hasDocumentSecurityOrigin, bool isInitiatingElementInUserAgentShadowTree, AddRuleFlags addRuleFlags)
</del><ins>+void RuleSet::addChildRules(const Vector<RefPtr<StyleRuleBase>>& rules, const MediaQueryEvaluator& medium, StyleResolver* resolver, bool isInitiatingElementInUserAgentShadowTree)
</ins><span class="cx"> {
</span><span class="cx">     for (auto& rule : rules) {
</span><span class="cx">         if (is<StyleRule>(*rule))
</span><del>-            addStyleRule(downcast<StyleRule>(rule.get()), addRuleFlags);
</del><ins>+            addStyleRule(downcast<StyleRule>(rule.get()));
</ins><span class="cx">         else if (is<StyleRulePage>(*rule))
</span><span class="cx">             addPageRule(downcast<StyleRulePage>(rule.get()));
</span><span class="cx">         else if (is<StyleRuleMedia>(*rule)) {
</span><span class="cx">             auto& mediaRule = downcast<StyleRuleMedia>(*rule);
</span><span class="cx">             if ((!mediaRule.mediaQueries() || medium.evaluate(*mediaRule.mediaQueries(), resolver)))
</span><del>-                addChildRules(mediaRule.childRules(), medium, resolver, hasDocumentSecurityOrigin, isInitiatingElementInUserAgentShadowTree, addRuleFlags);
</del><ins>+                addChildRules(mediaRule.childRules(), medium, resolver, isInitiatingElementInUserAgentShadowTree);
</ins><span class="cx">         } else if (is<StyleRuleFontFace>(*rule) && resolver) {
</span><span class="cx">             // Add this font face to our set.
</span><span class="cx">             resolver->document().fontSelector().addFontFaceRule(downcast<StyleRuleFontFace>(*rule.get()), isInitiatingElementInUserAgentShadowTree);
</span><span class="lines">@@ -378,7 +377,7 @@
</span><span class="cx">         } else if (is<StyleRuleKeyframes>(*rule) && resolver)
</span><span class="cx">             resolver->addKeyframeStyle(downcast<StyleRuleKeyframes>(*rule));
</span><span class="cx">         else if (is<StyleRuleSupports>(*rule) && downcast<StyleRuleSupports>(*rule).conditionIsSupported())
</span><del>-            addChildRules(downcast<StyleRuleSupports>(*rule).childRules(), medium, resolver, hasDocumentSecurityOrigin, isInitiatingElementInUserAgentShadowTree, addRuleFlags);
</del><ins>+            addChildRules(downcast<StyleRuleSupports>(*rule).childRules(), medium, resolver, isInitiatingElementInUserAgentShadowTree);
</ins><span class="cx"> #if ENABLE(CSS_DEVICE_ADAPTATION)
</span><span class="cx">         else if (is<StyleRuleViewport>(*rule) && resolver) {
</span><span class="cx">             resolver->viewportStyleResolver()->addViewportRule(downcast<StyleRuleViewport>(rule.get()));
</span><span class="lines">@@ -394,22 +393,19 @@
</span><span class="cx">             addRulesFromSheet(*rule->styleSheet(), medium, resolver);
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    bool hasDocumentSecurityOrigin = resolver && resolver->document().securityOrigin().canRequest(sheet.baseURL());
-    AddRuleFlags addRuleFlags = static_cast<AddRuleFlags>((hasDocumentSecurityOrigin ? RuleHasDocumentSecurityOrigin : 0));
-
</del><span class="cx">     // FIXME: Skip Content Security Policy check when stylesheet is in a user agent shadow tree.
</span><span class="cx">     // See <https://bugs.webkit.org/show_bug.cgi?id=146663>.
</span><span class="cx">     bool isInitiatingElementInUserAgentShadowTree = false;
</span><del>-    addChildRules(sheet.childRules(), medium, resolver, hasDocumentSecurityOrigin, isInitiatingElementInUserAgentShadowTree, addRuleFlags);
</del><ins>+    addChildRules(sheet.childRules(), medium, resolver, isInitiatingElementInUserAgentShadowTree);
</ins><span class="cx"> 
</span><span class="cx">     if (m_autoShrinkToFitEnabled)
</span><span class="cx">         shrinkToFit();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void RuleSet::addStyleRule(StyleRule* rule, AddRuleFlags addRuleFlags)
</del><ins>+void RuleSet::addStyleRule(StyleRule* rule)
</ins><span class="cx"> {
</span><span class="cx">     for (size_t selectorIndex = 0; selectorIndex != notFound; selectorIndex = rule->selectorList().indexOfNextSelectorAfter(selectorIndex))
</span><del>-        addRule(rule, selectorIndex, addRuleFlags);
</del><ins>+        addRule(rule, selectorIndex);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool RuleSet::hasShadowPseudoElementRules() const
</span></span></pre></div>
<a id="trunkSourceWebCorecssRuleSeth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/RuleSet.h (225649 => 225650)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/RuleSet.h       2017-12-07 23:55:42 UTC (rev 225649)
+++ trunk/Source/WebCore/css/RuleSet.h  2017-12-07 23:58:39 UTC (rev 225650)
</span><span class="lines">@@ -32,11 +32,6 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><del>-enum AddRuleFlags {
-    RuleHasNoSpecialState         = 0,
-    RuleHasDocumentSecurityOrigin = 1,
-};
-    
</del><span class="cx"> enum PropertyWhitelistType {
</span><span class="cx">     PropertyWhitelistNone   = 0,
</span><span class="cx">     PropertyWhitelistMarker,
</span><span class="lines">@@ -64,7 +59,7 @@
</span><span class="cx"> public:
</span><span class="cx">     static const unsigned maximumSelectorComponentCount = 8192;
</span><span class="cx"> 
</span><del>-    RuleData(StyleRule*, unsigned selectorIndex, unsigned position, AddRuleFlags);
</del><ins>+    RuleData(StyleRule*, unsigned selectorIndex, unsigned position);
</ins><span class="cx"> 
</span><span class="cx">     unsigned position() const { return m_position; }
</span><span class="cx">     StyleRule* rule() const { return m_rule.get(); }
</span><span class="lines">@@ -75,7 +70,6 @@
</span><span class="cx">     MatchBasedOnRuleHash matchBasedOnRuleHash() const { return static_cast<MatchBasedOnRuleHash>(m_matchBasedOnRuleHash); }
</span><span class="cx">     bool containsUncommonAttributeSelector() const { return m_containsUncommonAttributeSelector; }
</span><span class="cx">     unsigned linkMatchType() const { return m_linkMatchType; }
</span><del>-    bool hasDocumentSecurityOrigin() const { return m_hasDocumentSecurityOrigin; }
</del><span class="cx">     PropertyWhitelistType propertyWhitelistType() const { return static_cast<PropertyWhitelistType>(m_propertyWhitelistType); }
</span><span class="cx">     const SelectorFilter::Hashes& descendantSelectorIdentifierHashes() const { return m_descendantSelectorIdentifierHashes; }
</span><span class="cx"> 
</span><span class="lines">@@ -102,7 +96,6 @@
</span><span class="cx"> private:
</span><span class="cx">     RefPtr<StyleRule> m_rule;
</span><span class="cx">     unsigned m_selectorIndex : 13;
</span><del>-    unsigned m_hasDocumentSecurityOrigin : 1;
</del><span class="cx">     // This number was picked fairly arbitrarily. We can probably lower it if we need to.
</span><span class="cx">     // Some simple testing showed <100,000 RuleData's on large sites.
</span><span class="cx">     unsigned m_position : 18;
</span><span class="lines">@@ -158,8 +151,8 @@
</span><span class="cx"> 
</span><span class="cx">     void addRulesFromSheet(StyleSheetContents&, const MediaQueryEvaluator&, StyleResolver* = 0);
</span><span class="cx"> 
</span><del>-    void addStyleRule(StyleRule*, AddRuleFlags);
-    void addRule(StyleRule*, unsigned selectorIndex, AddRuleFlags);
</del><ins>+    void addStyleRule(StyleRule*);
+    void addRule(StyleRule*, unsigned selectorIndex);
</ins><span class="cx">     void addPageRule(StyleRulePage*);
</span><span class="cx">     void addToRuleSet(const AtomicString& key, AtomRuleMap&, const RuleData&);
</span><span class="cx">     void shrinkToFit();
</span><span class="lines">@@ -188,7 +181,7 @@
</span><span class="cx">     bool hasHostPseudoClassRulesMatchingInShadowTree() const { return m_hasHostPseudoClassRulesMatchingInShadowTree; }
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    void addChildRules(const Vector<RefPtr<StyleRuleBase>>&, const MediaQueryEvaluator& medium, StyleResolver*, bool hasDocumentSecurityOrigin, bool isInitiatingElementInUserAgentShadowTree, AddRuleFlags);
</del><ins>+    void addChildRules(const Vector<RefPtr<StyleRuleBase>>&, const MediaQueryEvaluator& medium, StyleResolver*, bool isInitiatingElementInUserAgentShadowTree);
</ins><span class="cx"> 
</span><span class="cx">     AtomRuleMap m_idRules;
</span><span class="cx">     AtomRuleMap m_classRules;
</span></span></pre></div>
<a id="trunkSourceWebCorecssStyleResolvercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/StyleResolver.cpp (225649 => 225650)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/StyleResolver.cpp       2017-12-07 23:55:42 UTC (rev 225649)
+++ trunk/Source/WebCore/css/StyleResolver.cpp  2017-12-07 23:58:39 UTC (rev 225650)
</span><span class="lines">@@ -1132,12 +1132,8 @@
</span><span class="cx">             collector.matchUserRules(rulesToInclude & EmptyCSSRules);
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    if (m_matchAuthorAndUserStyles && (rulesToInclude & AuthorCSSRules)) {
-        collector.setSameOriginOnly(!(rulesToInclude & CrossOriginCSSRules));
-
-        // Check the rules in author sheets.
</del><ins>+    if (m_matchAuthorAndUserStyles && (rulesToInclude & AuthorCSSRules))
</ins><span class="cx">         collector.matchAuthorRules(rulesToInclude & EmptyCSSRules);
</span><del>-    }
</del><span class="cx"> 
</span><span class="cx">     return collector.matchedRuleList();
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCorecssStyleResolverh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/StyleResolver.h (225649 => 225650)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/StyleResolver.h 2017-12-07 23:55:42 UTC (rev 225649)
+++ trunk/Source/WebCore/css/StyleResolver.h    2017-12-07 23:58:39 UTC (rev 225650)
</span><span class="lines">@@ -167,8 +167,7 @@
</span><span class="cx">         UAAndUserCSSRules   = 1 << 1,
</span><span class="cx">         AuthorCSSRules      = 1 << 2,
</span><span class="cx">         EmptyCSSRules       = 1 << 3,
</span><del>-        CrossOriginCSSRules = 1 << 4,
-        AllButEmptyCSSRules = UAAndUserCSSRules | AuthorCSSRules | CrossOriginCSSRules,
</del><ins>+        AllButEmptyCSSRules = UAAndUserCSSRules | AuthorCSSRules,
</ins><span class="cx">         AllCSSRules         = AllButEmptyCSSRules | EmptyCSSRules,
</span><span class="cx">     };
</span><span class="cx">     Vector<RefPtr<StyleRule>> styleRulesForElement(const Element*, unsigned rulesToInclude = AllButEmptyCSSRules);
</span></span></pre></div>
<a id="trunkSourceWebCorecssStyleRulecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/StyleRule.cpp (225649 => 225650)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/StyleRule.cpp   2017-12-07 23:55:42 UTC (rev 225649)
+++ trunk/Source/WebCore/css/StyleRule.cpp      2017-12-07 23:58:39 UTC (rev 225650)
</span><span class="lines">@@ -181,8 +181,8 @@
</span><span class="cx">     return sizeof(StyleRule) + sizeof(CSSSelector) + StyleProperties::averageSizeInBytes();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-StyleRule::StyleRule(Ref<StylePropertiesBase>&& properties)
-    : StyleRuleBase(Style)
</del><ins>+StyleRule::StyleRule(Ref<StylePropertiesBase>&& properties, bool hasDocumentSecurityOrigin)
+    : StyleRuleBase(Style, hasDocumentSecurityOrigin)
</ins><span class="cx">     , m_properties(WTFMove(properties))
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="lines">@@ -210,7 +210,7 @@
</span><span class="cx">     return downcast<MutableStyleProperties>(m_properties.get());
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-Ref<StyleRule> StyleRule::create(const Vector<const CSSSelector*>& selectors, Ref<StyleProperties>&& properties)
</del><ins>+Ref<StyleRule> StyleRule::createForSplitting(const Vector<const CSSSelector*>& selectors, Ref<StyleProperties>&& properties, bool hasDocumentSecurityOrigin)
</ins><span class="cx"> {
</span><span class="cx">     ASSERT_WITH_SECURITY_IMPLICATION(!selectors.isEmpty());
</span><span class="cx">     CSSSelector* selectorListArray = reinterpret_cast<CSSSelector*>(fastMalloc(sizeof(CSSSelector) * selectors.size()));
</span><span class="lines">@@ -217,7 +217,7 @@
</span><span class="cx">     for (unsigned i = 0; i < selectors.size(); ++i)
</span><span class="cx">         new (NotNull, &selectorListArray[i]) CSSSelector(*selectors.at(i));
</span><span class="cx">     selectorListArray[selectors.size() - 1].setLastInSelectorList();
</span><del>-    auto rule = StyleRule::create(WTFMove(properties));
</del><ins>+    auto rule = StyleRule::create(WTFMove(properties), hasDocumentSecurityOrigin);
</ins><span class="cx">     rule.get().parserAdoptSelectorArray(selectorListArray);
</span><span class="cx">     return rule;
</span><span class="cx"> }
</span><span class="lines">@@ -235,7 +235,7 @@
</span><span class="cx">             componentsInThisSelector.append(component);
</span><span class="cx"> 
</span><span class="cx">         if (componentsInThisSelector.size() + componentsSinceLastSplit.size() > maxCount && !componentsSinceLastSplit.isEmpty()) {
</span><del>-            rules.append(create(componentsSinceLastSplit, const_cast<StyleProperties&>(properties())));
</del><ins>+            rules.append(createForSplitting(componentsSinceLastSplit, const_cast<StyleProperties&>(properties()), hasDocumentSecurityOrigin()));
</ins><span class="cx">             componentsSinceLastSplit.clear();
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -243,7 +243,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if (!componentsSinceLastSplit.isEmpty())
</span><del>-        rules.append(create(componentsSinceLastSplit, const_cast<StyleProperties&>(properties())));
</del><ins>+        rules.append(createForSplitting(componentsSinceLastSplit, const_cast<StyleProperties&>(properties()), hasDocumentSecurityOrigin()));
</ins><span class="cx"> 
</span><span class="cx">     return rules;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCorecssStyleRuleh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/StyleRule.h (225649 => 225650)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/StyleRule.h     2017-12-07 23:55:42 UTC (rev 225649)
+++ trunk/Source/WebCore/css/StyleRule.h        2017-12-07 23:58:39 UTC (rev 225650)
</span><span class="lines">@@ -86,17 +86,23 @@
</span><span class="cx">     RefPtr<CSSRule> createCSSOMWrapper(CSSRule* parentRule) const;
</span><span class="cx"> 
</span><span class="cx"> protected:
</span><del>-    StyleRuleBase(Type type)
</del><ins>+    StyleRuleBase(Type type, bool hasDocumentSecurityOrigin = false)
</ins><span class="cx">         : m_type(type)
</span><del>-        { }
</del><ins>+        , m_hasDocumentSecurityOrigin(hasDocumentSecurityOrigin)
+    {
+    }
</ins><span class="cx"> 
</span><span class="cx">     StyleRuleBase(const StyleRuleBase& o)
</span><span class="cx">         : WTF::RefCountedBase()
</span><span class="cx">         , m_type(o.m_type)
</span><del>-        { }
</del><ins>+        , m_hasDocumentSecurityOrigin(o.m_hasDocumentSecurityOrigin)
+    {
+    }
</ins><span class="cx"> 
</span><span class="cx">     ~StyleRuleBase() = default;
</span><span class="cx"> 
</span><ins>+    bool hasDocumentSecurityOrigin() const { return m_hasDocumentSecurityOrigin; }
+
</ins><span class="cx"> private:
</span><span class="cx">     WEBCORE_EXPORT void destroy();
</span><span class="cx">     
</span><span class="lines">@@ -103,14 +109,16 @@
</span><span class="cx">     RefPtr<CSSRule> createCSSOMWrapper(CSSStyleSheet* parentSheet, CSSRule* parentRule) const;
</span><span class="cx"> 
</span><span class="cx">     unsigned m_type : 5;
</span><ins>+    // This is only needed to support getMatchedCSSRules.
+    unsigned m_hasDocumentSecurityOrigin : 1;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> class StyleRule final : public StyleRuleBase {
</span><span class="cx">     WTF_MAKE_FAST_ALLOCATED;
</span><span class="cx"> public:
</span><del>-    static Ref<StyleRule> create(Ref<StylePropertiesBase>&& properties)
</del><ins>+    static Ref<StyleRule> create(Ref<StylePropertiesBase>&& properties, bool hasDocumentSecurityOrigin)
</ins><span class="cx">     {
</span><del>-        return adoptRef(*new StyleRule(WTFMove(properties)));
</del><ins>+        return adoptRef(*new StyleRule(WTFMove(properties), hasDocumentSecurityOrigin));
</ins><span class="cx">     }
</span><span class="cx">     
</span><span class="cx">     ~StyleRule();
</span><span class="lines">@@ -121,6 +129,8 @@
</span><span class="cx">     MutableStyleProperties& mutableProperties();
</span><span class="cx">     const StyleProperties* propertiesWithoutDeferredParsing() const;
</span><span class="cx"> 
</span><ins>+    using StyleRuleBase::hasDocumentSecurityOrigin;
+
</ins><span class="cx">     void parserAdoptSelectorVector(Vector<std::unique_ptr<CSSParserSelector>>& selectors) { m_selectorList.adoptSelectorVector(selectors); }
</span><span class="cx">     void wrapperAdoptSelectorList(CSSSelectorList& selectors) { m_selectorList = WTFMove(selectors); }
</span><span class="cx">     void parserAdoptSelectorArray(CSSSelector* selectors) { m_selectorList.adoptSelectorArray(selectors); }
</span><span class="lines">@@ -132,10 +142,10 @@
</span><span class="cx">     static unsigned averageSizeInBytes();
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    StyleRule(Ref<StylePropertiesBase>&&);
</del><ins>+    StyleRule(Ref<StylePropertiesBase>&&, bool hasDocumentSecurityOrigin);
</ins><span class="cx">     StyleRule(const StyleRule&);
</span><span class="cx"> 
</span><del>-    static Ref<StyleRule> create(const Vector<const CSSSelector*>&, Ref<StyleProperties>&&);
</del><ins>+    static Ref<StyleRule> createForSplitting(const Vector<const CSSSelector*>&, Ref<StyleProperties>&&, bool hasDocumentSecurityOrigin);
</ins><span class="cx"> 
</span><span class="cx">     mutable Ref<StylePropertiesBase> m_properties;
</span><span class="cx">     CSSSelectorList m_selectorList;
</span></span></pre></div>
<a id="trunkSourceWebCorecssparserCSSParsercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/parser/CSSParser.cpp (225649 => 225650)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/parser/CSSParser.cpp    2017-12-07 23:55:42 UTC (rev 225649)
+++ trunk/Source/WebCore/css/parser/CSSParser.cpp       2017-12-07 23:58:39 UTC (rev 225650)
</span><span class="lines">@@ -72,12 +72,13 @@
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-CSSParserContext::CSSParserContext(Document& document, const URL& baseURL, const String& charset)
-    : baseURL(baseURL.isNull() ? document.baseURL() : baseURL)
</del><ins>+CSSParserContext::CSSParserContext(Document& document, const URL& sheetBaseURL, const String& charset)
+    : baseURL(sheetBaseURL.isNull() ? document.baseURL() : sheetBaseURL)
</ins><span class="cx">     , charset(charset)
</span><span class="cx">     , mode(document.inQuirksMode() ? HTMLQuirksMode : HTMLStandardMode)
</span><span class="cx">     , isHTMLDocument(document.isHTMLDocument())
</span><span class="cx">     , cssGridLayoutEnabled(document.isCSSGridLayoutEnabled())
</span><ins>+    , hasDocumentSecurityOrigin(document.securityOrigin().canRequest(baseURL))
</ins><span class="cx"> {
</span><span class="cx">     needsSiteSpecificQuirks = document.settings().needsSiteSpecificQuirks();
</span><span class="cx">     enforcesCSSMIMETypeInNoQuirksMode = document.settings().enforceCSSMIMETypeInNoQuirksMode();
</span><span class="lines">@@ -111,7 +112,8 @@
</span><span class="cx">         && a.springTimingFunctionEnabled == b.springTimingFunctionEnabled
</span><span class="cx">         && a.constantPropertiesEnabled == b.constantPropertiesEnabled
</span><span class="cx">         && a.conicGradientsEnabled == b.conicGradientsEnabled
</span><del>-        && a.deferredCSSParserEnabled == b.deferredCSSParserEnabled;
</del><ins>+        && a.deferredCSSParserEnabled == b.deferredCSSParserEnabled
+        && a.hasDocumentSecurityOrigin == b.hasDocumentSecurityOrigin;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> CSSParser::CSSParser(const CSSParserContext& context)
</span></span></pre></div>
<a id="trunkSourceWebCorecssparserCSSParserImplcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/parser/CSSParserImpl.cpp (225649 => 225650)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/parser/CSSParserImpl.cpp        2017-12-07 23:55:42 UTC (rev 225649)
+++ trunk/Source/WebCore/css/parser/CSSParserImpl.cpp   2017-12-07 23:58:39 UTC (rev 225650)
</span><span class="lines">@@ -738,7 +738,7 @@
</span><span class="cx">         CSSParserTokenRange blockCopy = block;
</span><span class="cx">         blockCopy.consumeWhitespace();
</span><span class="cx">         if (!blockCopy.atEnd()) {
</span><del>-            rule = StyleRule::create(createDeferredStyleProperties(block));
</del><ins>+            rule = StyleRule::create(createDeferredStyleProperties(block), m_context.hasDocumentSecurityOrigin);
</ins><span class="cx">             rule->wrapperAdoptSelectorList(selectorList);
</span><span class="cx">             return rule;
</span><span class="cx">         }
</span><span class="lines">@@ -745,7 +745,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     consumeDeclarationList(block, StyleRule::Style);
</span><del>-    rule = StyleRule::create(createStyleProperties(m_parsedProperties, m_context.mode));
</del><ins>+    rule = StyleRule::create(createStyleProperties(m_parsedProperties, m_context.mode), m_context.hasDocumentSecurityOrigin);
</ins><span class="cx">     rule->wrapperAdoptSelectorList(selectorList);
</span><span class="cx">     return rule;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCorecssparserCSSParserModeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/parser/CSSParserMode.h (225649 => 225650)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/parser/CSSParserMode.h  2017-12-07 23:55:42 UTC (rev 225649)
+++ trunk/Source/WebCore/css/parser/CSSParserMode.h     2017-12-07 23:58:39 UTC (rev 225650)
</span><span class="lines">@@ -107,6 +107,8 @@
</span><span class="cx">     bool constantPropertiesEnabled { false };
</span><span class="cx">     bool conicGradientsEnabled { false };
</span><span class="cx">     bool deferredCSSParserEnabled { false };
</span><ins>+    // This is only needed to support getMatchedCSSRules.
+    bool hasDocumentSecurityOrigin { false };
</ins><span class="cx"> 
</span><span class="cx">     URL completeURL(const String& url) const
</span><span class="cx">     {
</span><span class="lines">@@ -141,7 +143,8 @@
</span><span class="cx">             & key.springTimingFunctionEnabled               << 7
</span><span class="cx">             & key.conicGradientsEnabled                     << 8
</span><span class="cx">             & key.deferredCSSParserEnabled                  << 9
</span><del>-            & key.mode                                      << 10;
</del><ins>+            & key.hasDocumentSecurityOrigin                 << 10
+            & key.mode                                      << 11;
</ins><span class="cx">         hash ^= WTF::intHash(bits);
</span><span class="cx">         return hash;
</span><span class="cx">     }
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingEditingStylecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/EditingStyle.cpp (225649 => 225650)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/EditingStyle.cpp    2017-12-07 23:55:42 UTC (rev 225649)
+++ trunk/Source/WebCore/editing/EditingStyle.cpp       2017-12-07 23:58:39 UTC (rev 225650)
</span><span class="lines">@@ -1269,7 +1269,7 @@
</span><span class="cx"> void EditingStyle::mergeStyleFromRules(StyledElement& element)
</span><span class="cx"> {
</span><span class="cx">     RefPtr<MutableStyleProperties> styleFromMatchedRules = styleFromMatchedRulesForElement(element,
</span><del>-        StyleResolver::AuthorCSSRules | StyleResolver::CrossOriginCSSRules);
</del><ins>+        StyleResolver::AuthorCSSRules);
</ins><span class="cx">     // Styles from the inline style declaration, held in the variable "style", take precedence 
</span><span class="cx">     // over those from matched rules.
</span><span class="cx">     if (m_mutableStyle)
</span></span></pre></div>
<a id="trunkSourceWebCorepageDOMWindowcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/DOMWindow.cpp (225649 => 225650)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/DOMWindow.cpp  2017-12-07 23:55:42 UTC (rev 225649)
+++ trunk/Source/WebCore/page/DOMWindow.cpp     2017-12-07 23:58:39 UTC (rev 225650)
</span><span class="lines">@@ -1482,8 +1482,6 @@
</span><span class="cx">     unsigned rulesToInclude = StyleResolver::AuthorCSSRules;
</span><span class="cx">     if (!authorOnly)
</span><span class="cx">         rulesToInclude |= StyleResolver::UAAndUserCSSRules;
</span><del>-    if (m_frame->settings().crossOriginCheckInGetMatchedCSSRulesDisabled())
-        rulesToInclude |= StyleResolver::CrossOriginCSSRules;
</del><span class="cx"> 
</span><span class="cx">     PseudoId pseudoId = CSSSelector::pseudoId(pseudoType);
</span><span class="cx"> 
</span><span class="lines">@@ -1491,10 +1489,18 @@
</span><span class="cx">     if (matchedRules.isEmpty())
</span><span class="cx">         return nullptr;
</span><span class="cx"> 
</span><ins>+    bool allowCrossOrigin = m_frame->settings().crossOriginCheckInGetMatchedCSSRulesDisabled();
+
</ins><span class="cx">     RefPtr<StaticCSSRuleList> ruleList = StaticCSSRuleList::create();
</span><del>-    for (auto& rule : matchedRules)
</del><ins>+    for (auto& rule : matchedRules) {
+        if (!allowCrossOrigin && !rule->hasDocumentSecurityOrigin())
+            continue;
</ins><span class="cx">         ruleList->rules().append(rule->createCSSOMWrapper());
</span><ins>+    }
</ins><span class="cx"> 
</span><ins>+    if (ruleList->rules().isEmpty())
+        return nullptr;
+
</ins><span class="cx">     return ruleList;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>