Title: [205455] trunk
Revision
205455
Author
[email protected]
Date
2016-09-05 09:58:48 -0700 (Mon, 05 Sep 2016)

Log Message

Clean CSS stylesheets should be accessible from _javascript_
https://bugs.webkit.org/show_bug.cgi?id=158728

Patch by Youenn Fablet <[email protected]> on 2016-09-05
Reviewed by Darin Adler.

Source/WebCore:

Covered by updated tests.

Making use of the resource response type to evaluate whether to make the CSS stylesheets visible
for stylesheet link elements and for stylesheet processing instructions.
Ideally, the origin flag should be a boolean.

To keep behavior consistent in cors-check-unaware cases, the flag might remain unset.
In that case, the behavior remains the same (checking of the stylesheet URL).
The origin flag is set to true or false only in case of fetch mode being set to cors using the crossorigin attribute.

Updated CSSStyleSheet::create to take a Node reference. Updated callers accordingly.

* contentextensions/ContentExtensionStyleSheet.cpp:
(WebCore::ContentExtensions::ContentExtensionStyleSheet::ContentExtensionStyleSheet): Updated to pass a Node reference and not pointer.
* css/CSSStyleSheet.cpp:
(WebCore::CSSStyleSheet::create): Makes origin flag undefined if boolean parameter is not passed.
Otherwise origin flag is set according given boolean value.
(WebCore::CSSStyleSheet::createInline): Makes origin flag set to true.
(WebCore::CSSStyleSheet::CSSStyleSheet): Adding origin flag initialization.
(WebCore::CSSStyleSheet::canAccessRules): Returning according the origin flag if set.
Returning as before in case the flag is not set.
* css/CSSStyleSheet.h: Adding origin clean flag.
* dom/ExtensionStyleSheets.cpp:
(WebCore::ExtensionStyleSheets::addUserStyleSheet):
(WebCore::ExtensionStyleSheets::addAuthorStyleSheetForTesting):
(WebCore::ExtensionStyleSheets::maybeAddContentExtensionSheet):
* html/HTMLLinkElement.cpp:
(WebCore::HTMLLinkElement::initializeStyleSheet): Helper routine used in setCSSStyleSheet.
Sets origin clean flag if the resource is clean.
(WebCore::HTMLLinkElement::setCSSStyleSheet): Making use of initializeStyleSheet.
* html/HTMLLinkElement.h:

LayoutTests:

* http/tests/security/cannot-read-cssrules-expected.txt:
* http/tests/security/cannot-read-cssrules-redirect-expected.txt:
* http/tests/security/cannot-read-cssrules-redirect.html:
* http/tests/security/cannot-read-cssrules.html:
* http/tests/security/cross-origin-css-9.html:
* http/tests/security/resources/xorigincss1-allow-star.php: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (205454 => 205455)


--- trunk/LayoutTests/ChangeLog	2016-09-05 16:42:23 UTC (rev 205454)
+++ trunk/LayoutTests/ChangeLog	2016-09-05 16:58:48 UTC (rev 205455)
@@ -1,3 +1,17 @@
+2016-09-05  Youenn Fablet  <[email protected]>
+
+        Clean CSS stylesheets should be accessible from _javascript_
+        https://bugs.webkit.org/show_bug.cgi?id=158728
+
+        Reviewed by Darin Adler.
+
+        * http/tests/security/cannot-read-cssrules-expected.txt:
+        * http/tests/security/cannot-read-cssrules-redirect-expected.txt:
+        * http/tests/security/cannot-read-cssrules-redirect.html:
+        * http/tests/security/cannot-read-cssrules.html:
+        * http/tests/security/cross-origin-css-9.html:
+        * http/tests/security/resources/xorigincss1-allow-star.php: Added.
+
 2016-09-05  Philippe Normand  <[email protected]>
 
         WebRTC: Several media stream tests crashing

Modified: trunk/LayoutTests/http/tests/security/cannot-read-cssrules-expected.txt (205454 => 205455)


--- trunk/LayoutTests/http/tests/security/cannot-read-cssrules-expected.txt	2016-09-05 16:42:23 UTC (rev 205454)
+++ trunk/LayoutTests/http/tests/security/cannot-read-cssrules-expected.txt	2016-09-05 16:58:48 UTC (rev 205455)
@@ -1,10 +1,21 @@
+CONSOLE MESSAGE: Origin http://127.0.0.1:8000 is not allowed by Access-Control-Allow-Origin.
 This test whether a script can read the rules from a cross-origin style sheet. For more information on why we block this, please see https://bugs.webkit.org/show_bug.cgi?id=20527.
 
 Test begins.
-== Cross-Origin ==
+== Cross-Origin resource, no-cors mode ==
 cssRules: null
 rules: null
-== Same-Origin ==
+== Same-Origin resource, no-cors mode ==
 cssRules: [object CSSRuleList]
+cssRules length: 1
 rules: [object CSSRuleList]
+rules length: 1
+== Cross-Origin resource, cors mode, failing cors check ==
+cssRules: null
+rules: null
+== Cross-Origin resource, cors mode, successful cors check ==
+cssRules: [object CSSRuleList]
+cssRules length: 1
+rules: [object CSSRuleList]
+rules length: 1
 Test ends.

Modified: trunk/LayoutTests/http/tests/security/cannot-read-cssrules-redirect-expected.txt (205454 => 205455)


--- trunk/LayoutTests/http/tests/security/cannot-read-cssrules-redirect-expected.txt	2016-09-05 16:42:23 UTC (rev 205454)
+++ trunk/LayoutTests/http/tests/security/cannot-read-cssrules-redirect-expected.txt	2016-09-05 16:58:48 UTC (rev 205455)
@@ -1,10 +1,26 @@
+CONSOLE MESSAGE: Cross-origin redirection to http://127.0.0.1:8000/security/resources/xorigincss1.css denied by Cross-Origin Resource Sharing policy: Origin http://127.0.0.1:8000 is not allowed by Access-Control-Allow-Origin.
 This test whether a script can read the rules from a cross-origin style sheet in the presence of redirects. For more information on why we block this, please see https://bugs.webkit.org/show_bug.cgi?id=20527.
 
 Test begins.
-== Same-Origin to Cross-Origin ==
+== Same-Origin to Cross-Origin, no-cors mode ==
 cssRules: null
 rules: null
-== Cross-Origin to Same-Origin ==
+== Cross-Origin to Same-Origin, no-cors mode ==
 cssRules: [object CSSRuleList]
+cssRules length: 1
 rules: [object CSSRuleList]
+rules length: 1
+== Same-Origin to Same-Origin, cors mode ==
+cssRules: [object CSSRuleList]
+cssRules length: 1
+rules: [object CSSRuleList]
+rules length: 1
+== Cross-Origin to Same-Origin, cors mode, successful cors check ==
+cssRules: [object CSSRuleList]
+cssRules length: 1
+rules: [object CSSRuleList]
+rules length: 1
+== Cross-Origin to Same-Origin, cors mode, failing cors check ==
+cssRules: null
+rules: null
 Test ends.

Modified: trunk/LayoutTests/http/tests/security/cannot-read-cssrules-redirect.html (205454 => 205455)


--- trunk/LayoutTests/http/tests/security/cannot-read-cssrules-redirect.html	2016-09-05 16:42:23 UTC (rev 205454)
+++ trunk/LayoutTests/http/tests/security/cannot-read-cssrules-redirect.html	2016-09-05 16:58:48 UTC (rev 205455)
@@ -5,6 +5,12 @@
       href=""
 <link rel="stylesheet"
       href=""
+<link rel="stylesheet"
+      href="" crossorigin="">
+<link rel="stylesheet"
+      href="" crossorigin="">
+<link rel="stylesheet"
+      href="" crossorigin="">
 <script>
 if (window.testRunner)
     testRunner.dumpAsText();
@@ -15,16 +21,38 @@
     document.getElementById("console").appendChild(div);
 }
 
+function checkCSSRules(sheet)
+{
+    try {
+        var cssRules = sheet.cssRules;
+        log("cssRules: " + cssRules);
+        if (cssRules)
+            log("cssRules length: " + cssRules.length);
+    } catch(e) {
+        log("exception thrown for cssRules: " + e);
+    }
+    try {
+        var rules = sheet.rules;
+        log("rules: " + rules);
+        if (rules)
+            log("rules length: " + rules.length);
+    } catch(e) {
+        log("exception thrown for rules: " + e);
+    }
+}
+
 window._onload_ = function() {
     log("Test begins.");
-    log("== Same-Origin to Cross-Origin ==");
-    var sheet1 = document.styleSheets[0];
-    log("cssRules: " + sheet1.cssRules);
-    log("rules: " + sheet1.rules);
-    log("== Cross-Origin to Same-Origin ==");
-    var sheet2 = document.styleSheets[1];
-    log("cssRules: " + sheet2.cssRules);
-    log("rules: " + sheet2.rules);
+    log("== Same-Origin to Cross-Origin, no-cors mode ==");
+    checkCSSRules(document.styleSheets[0]);
+    log("== Cross-Origin to Same-Origin, no-cors mode ==");
+    checkCSSRules(document.styleSheets[1]);
+    log("== Same-Origin to Same-Origin, cors mode ==");
+    checkCSSRules(document.styleSheets[2]);
+    log("== Cross-Origin to Same-Origin, cors mode, successful cors check ==");
+    checkCSSRules(document.styleSheets[3]);
+    log("== Cross-Origin to Same-Origin, cors mode, failing cors check ==");
+    checkCSSRules(document.styleSheets[4]);
     log("Test ends.");
 }
 </script>

Modified: trunk/LayoutTests/http/tests/security/cannot-read-cssrules.html (205454 => 205455)


--- trunk/LayoutTests/http/tests/security/cannot-read-cssrules.html	2016-09-05 16:42:23 UTC (rev 205454)
+++ trunk/LayoutTests/http/tests/security/cannot-read-cssrules.html	2016-09-05 16:58:48 UTC (rev 205455)
@@ -4,6 +4,10 @@
 <link rel="stylesheet"
       href=""
 <link rel="stylesheet" href=""
+<link rel="stylesheet"
+      href="" crossorigin="">
+<link rel="stylesheet"
+      href="" crossorigin="">
 <script>
 if (window.testRunner)
     testRunner.dumpAsText();
@@ -14,16 +18,36 @@
     document.getElementById("console").appendChild(div);
 }
 
+function checkCSSRules(sheet)
+{
+    try {
+        var cssRules = sheet.cssRules;
+        log("cssRules: " + cssRules);
+        if (cssRules)
+            log("cssRules length: " + cssRules.length);
+    } catch(e) {
+        log("exception thrown for cssRules: " + e);
+    }
+    try {
+        var rules = sheet.rules;
+        log("rules: " + rules);
+        if (rules)
+            log("rules length: " + rules.length);
+    } catch(e) {
+        log("exception thrown for rules: " + e);
+    }
+}
+
 window._onload_ = function() {
     log("Test begins.");
-    log("== Cross-Origin ==");
-    var sheet1 = document.styleSheets[0];
-    log("cssRules: " + sheet1.cssRules);
-    log("rules: " + sheet1.rules);
-    log("== Same-Origin ==");
-    var sheet2 = document.styleSheets[1];
-    log("cssRules: " + sheet2.cssRules);
-    log("rules: " + sheet2.rules);
+    log("== Cross-Origin resource, no-cors mode ==");
+    checkCSSRules(document.styleSheets[0]);
+    log("== Same-Origin resource, no-cors mode ==");
+    checkCSSRules(document.styleSheets[1]);
+    log("== Cross-Origin resource, cors mode, failing cors check ==");
+    checkCSSRules(document.styleSheets[2]);
+    log("== Cross-Origin resource, cors mode, successful cors check ==");
+    checkCSSRules(document.styleSheets[3]);
     log("Test ends.");
 }
 </script>

Modified: trunk/LayoutTests/http/tests/security/cross-origin-css-9.html (205454 => 205455)


--- trunk/LayoutTests/http/tests/security/cross-origin-css-9.html	2016-09-05 16:42:23 UTC (rev 205454)
+++ trunk/LayoutTests/http/tests/security/cross-origin-css-9.html	2016-09-05 16:58:48 UTC (rev 205455)
@@ -21,8 +21,7 @@
 {
     expectedColor = expectToIncludeOrigin ? "rgb(255, 255, 0)" : "rgb(0, 0, 255)";
     assert_equals(getBackgroundColorForId(id), expectedColor);
-    // FIXME: cssRules should be made visible according resource tainted status, not only based on the resource URL being cross origin.
-    // assert_equals(document.getElementById("link-" + id).sheet.cssRules !== null, expectVisibility);
+    assert_equals(document.getElementById("link-" + id).sheet.cssRules !== null, expectVisibility);
 }
 
 var _onloadTest_ = async_test(" Testing that link element to load stylesheets correctly handle crossorigin mode.");

Added: trunk/LayoutTests/http/tests/security/resources/xorigincss1-allow-star.php (0 => 205455)


--- trunk/LayoutTests/http/tests/security/resources/xorigincss1-allow-star.php	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/resources/xorigincss1-allow-star.php	2016-09-05 16:58:48 UTC (rev 205455)
@@ -0,0 +1,11 @@
+<?php
+header("Access-Control-Allow-Origin: *");
+
+$name = 'xorigincss1.css';
+$fp = fopen($name, 'rb');
+header("Content-Type: text/css");
+header("Content-Length: " . filesize($name));
+
+fpassthru($fp);
+exit;
+?>

Modified: trunk/Source/WebCore/ChangeLog (205454 => 205455)


--- trunk/Source/WebCore/ChangeLog	2016-09-05 16:42:23 UTC (rev 205454)
+++ trunk/Source/WebCore/ChangeLog	2016-09-05 16:58:48 UTC (rev 205455)
@@ -1,5 +1,44 @@
 2016-09-05  Youenn Fablet  <[email protected]>
 
+        Clean CSS stylesheets should be accessible from _javascript_
+        https://bugs.webkit.org/show_bug.cgi?id=158728
+
+        Reviewed by Darin Adler.
+
+        Covered by updated tests.
+
+        Making use of the resource response type to evaluate whether to make the CSS stylesheets visible
+        for stylesheet link elements and for stylesheet processing instructions.
+        Ideally, the origin flag should be a boolean.
+
+        To keep behavior consistent in cors-check-unaware cases, the flag might remain unset.
+        In that case, the behavior remains the same (checking of the stylesheet URL).
+        The origin flag is set to true or false only in case of fetch mode being set to cors using the crossorigin attribute.
+
+        Updated CSSStyleSheet::create to take a Node reference. Updated callers accordingly.
+
+        * contentextensions/ContentExtensionStyleSheet.cpp:
+        (WebCore::ContentExtensions::ContentExtensionStyleSheet::ContentExtensionStyleSheet): Updated to pass a Node reference and not pointer.
+        * css/CSSStyleSheet.cpp:
+        (WebCore::CSSStyleSheet::create): Makes origin flag undefined if boolean parameter is not passed.
+        Otherwise origin flag is set according given boolean value.
+        (WebCore::CSSStyleSheet::createInline): Makes origin flag set to true.
+        (WebCore::CSSStyleSheet::CSSStyleSheet): Adding origin flag initialization.
+        (WebCore::CSSStyleSheet::canAccessRules): Returning according the origin flag if set.
+        Returning as before in case the flag is not set.
+        * css/CSSStyleSheet.h: Adding origin clean flag.
+        * dom/ExtensionStyleSheets.cpp:
+        (WebCore::ExtensionStyleSheets::addUserStyleSheet):
+        (WebCore::ExtensionStyleSheets::addAuthorStyleSheetForTesting):
+        (WebCore::ExtensionStyleSheets::maybeAddContentExtensionSheet):
+        * html/HTMLLinkElement.cpp:
+        (WebCore::HTMLLinkElement::initializeStyleSheet): Helper routine used in setCSSStyleSheet.
+        Sets origin clean flag if the resource is clean.
+        (WebCore::HTMLLinkElement::setCSSStyleSheet): Making use of initializeStyleSheet.
+        * html/HTMLLinkElement.h:
+
+2016-09-05  Youenn Fablet  <[email protected]>
+
         CachedResourceLoader is not taking into account fetch options to use or not cached resources
         https://bugs.webkit.org/show_bug.cgi?id=161389
 

Modified: trunk/Source/WebCore/contentextensions/ContentExtensionStyleSheet.cpp (205454 => 205455)


--- trunk/Source/WebCore/contentextensions/ContentExtensionStyleSheet.cpp	2016-09-05 16:42:23 UTC (rev 205454)
+++ trunk/Source/WebCore/contentextensions/ContentExtensionStyleSheet.cpp	2016-09-05 16:58:48 UTC (rev 205455)
@@ -38,7 +38,7 @@
 namespace ContentExtensions {
 
 ContentExtensionStyleSheet::ContentExtensionStyleSheet(Document& document)
-    : m_styleSheet(CSSStyleSheet::create(StyleSheetContents::create(), &document))
+    : m_styleSheet(CSSStyleSheet::create(StyleSheetContents::create(), document))
 {
     m_styleSheet->contents().setIsUserStyleSheet(true);
 }

Modified: trunk/Source/WebCore/css/CSSStyleSheet.cpp (205454 => 205455)


--- trunk/Source/WebCore/css/CSSStyleSheet.cpp	2016-09-05 16:42:23 UTC (rev 205454)
+++ trunk/Source/WebCore/css/CSSStyleSheet.cpp	2016-09-05 16:58:48 UTC (rev 205455)
@@ -78,19 +78,19 @@
 #endif
 
 Ref<CSSStyleSheet> CSSStyleSheet::create(Ref<StyleSheetContents>&& sheet, CSSImportRule* ownerRule)
-{ 
+{
     return adoptRef(*new CSSStyleSheet(WTFMove(sheet), ownerRule));
 }
 
-Ref<CSSStyleSheet> CSSStyleSheet::create(Ref<StyleSheetContents>&& sheet, Node* ownerNode)
-{ 
-    return adoptRef(*new CSSStyleSheet(WTFMove(sheet), ownerNode, TextPosition::minimumPosition(), false));
+Ref<CSSStyleSheet> CSSStyleSheet::create(Ref<StyleSheetContents>&& sheet, Node& ownerNode, const Optional<bool>& isCleanOrigin)
+{
+    return adoptRef(*new CSSStyleSheet(WTFMove(sheet), ownerNode, TextPosition::minimumPosition(), false, isCleanOrigin));
 }
 
 Ref<CSSStyleSheet> CSSStyleSheet::createInline(Node& ownerNode, const URL& baseURL, const TextPosition& startPosition, const String& encoding)
 {
     CSSParserContext parserContext(ownerNode.document(), baseURL, encoding);
-    return adoptRef(*new CSSStyleSheet(StyleSheetContents::create(baseURL.string(), parserContext), &ownerNode, startPosition, true));
+    return adoptRef(*new CSSStyleSheet(StyleSheetContents::create(baseURL.string(), parserContext), ownerNode, startPosition, true, true));
 }
 
 CSSStyleSheet::CSSStyleSheet(Ref<StyleSheetContents>&& contents, CSSImportRule* ownerRule)
@@ -105,16 +105,17 @@
     m_contents->registerClient(this);
 }
 
-CSSStyleSheet::CSSStyleSheet(Ref<StyleSheetContents>&& contents, Node* ownerNode, const TextPosition& startPosition, bool isInlineStylesheet)
+CSSStyleSheet::CSSStyleSheet(Ref<StyleSheetContents>&& contents, Node& ownerNode, const TextPosition& startPosition, bool isInlineStylesheet, const Optional<bool>& isOriginClean)
     : m_contents(WTFMove(contents))
     , m_isInlineStylesheet(isInlineStylesheet)
     , m_isDisabled(false)
     , m_mutatedRules(false)
-    , m_ownerNode(ownerNode)
+    , m_isOriginClean(isOriginClean)
+    , m_ownerNode(&ownerNode)
     , m_ownerRule(0)
     , m_startPosition(startPosition)
 {
-    ASSERT(isAcceptableCSSStyleSheetParent(ownerNode));
+    ASSERT(isAcceptableCSSStyleSheetParent(&ownerNode));
     m_contents->registerClient(this);
 }
 
@@ -258,8 +259,9 @@
 
 bool CSSStyleSheet::canAccessRules() const
 {
-    if (m_isInlineStylesheet)
-        return true;
+    if (m_isOriginClean)
+        return m_isOriginClean.value();
+
     URL baseURL = m_contents->baseURL();
     if (baseURL.isEmpty())
         return true;
@@ -266,9 +268,7 @@
     Document* document = ownerDocument();
     if (!document)
         return true;
-    if (document->securityOrigin()->canRequest(baseURL))
-        return true;
-    return false;
+    return document->securityOrigin()->canRequest(baseURL);
 }
 
 RefPtr<CSSRuleList> CSSStyleSheet::rules()

Modified: trunk/Source/WebCore/css/CSSStyleSheet.h (205454 => 205455)


--- trunk/Source/WebCore/css/CSSStyleSheet.h	2016-09-05 16:42:23 UTC (rev 205454)
+++ trunk/Source/WebCore/css/CSSStyleSheet.h	2016-09-05 16:58:48 UTC (rev 205455)
@@ -49,7 +49,7 @@
 class CSSStyleSheet final : public StyleSheet {
 public:
     static Ref<CSSStyleSheet> create(Ref<StyleSheetContents>&&, CSSImportRule* ownerRule = 0);
-    static Ref<CSSStyleSheet> create(Ref<StyleSheetContents>&&, Node* ownerNode);
+    static Ref<CSSStyleSheet> create(Ref<StyleSheetContents>&&, Node& ownerNode, const Optional<bool>& isOriginClean = Nullopt);
     static Ref<CSSStyleSheet> createInline(Node&, const URL&, const TextPosition& startPosition = TextPosition::minimumPosition(), const String& encoding = String());
 
     virtual ~CSSStyleSheet();
@@ -125,16 +125,18 @@
 private:
     CSSStyleSheet(Ref<StyleSheetContents>&&, CSSImportRule* ownerRule);
     CSSStyleSheet(Ref<StyleSheetContents>&&, Node* ownerNode, const TextPosition& startPosition, bool isInlineStylesheet);
+    CSSStyleSheet(Ref<StyleSheetContents>&&, Node& ownerNode, const TextPosition& startPosition, bool isInlineStylesheet, const Optional<bool>&);
 
     bool isCSSStyleSheet() const final { return true; }
     String type() const final { return ASCIILiteral("text/css"); }
 
     bool canAccessRules() const;
-    
+
     Ref<StyleSheetContents> m_contents;
     bool m_isInlineStylesheet;
     bool m_isDisabled;
     bool m_mutatedRules;
+    Optional<bool> m_isOriginClean;
     String m_title;
     RefPtr<MediaQuerySet> m_mediaQueries;
 

Modified: trunk/Source/WebCore/dom/ExtensionStyleSheets.cpp (205454 => 205455)


--- trunk/Source/WebCore/dom/ExtensionStyleSheets.cpp	2016-09-05 16:42:23 UTC (rev 205454)
+++ trunk/Source/WebCore/dom/ExtensionStyleSheets.cpp	2016-09-05 16:58:48 UTC (rev 205455)
@@ -160,7 +160,7 @@
 void ExtensionStyleSheets::addUserStyleSheet(Ref<StyleSheetContents>&& userSheet)
 {
     ASSERT(userSheet.get().isUserStyleSheet());
-    m_userStyleSheets.append(CSSStyleSheet::create(WTFMove(userSheet), &m_document));
+    m_userStyleSheets.append(CSSStyleSheet::create(WTFMove(userSheet), m_document));
     m_document.styleResolverChanged(RecalcStyleImmediately);
 }
 
@@ -167,7 +167,7 @@
 void ExtensionStyleSheets::addAuthorStyleSheetForTesting(Ref<StyleSheetContents>&& authorSheet)
 {
     ASSERT(!authorSheet.get().isUserStyleSheet());
-    m_authorStyleSheetsForTesting.append(CSSStyleSheet::create(WTFMove(authorSheet), &m_document));
+    m_authorStyleSheetsForTesting.append(CSSStyleSheet::create(WTFMove(authorSheet), m_document));
     m_document.styleResolverChanged(RecalcStyleImmediately);
 }
 
@@ -191,7 +191,7 @@
     if (m_contentExtensionSheets.contains(identifier))
         return;
 
-    Ref<CSSStyleSheet> cssSheet = CSSStyleSheet::create(sheet, &m_document);
+    Ref<CSSStyleSheet> cssSheet = CSSStyleSheet::create(sheet, m_document);
     m_contentExtensionSheets.set(identifier, &cssSheet.get());
     m_userStyleSheets.append(adoptRef(cssSheet.leakRef()));
     m_styleResolverChangedTimer.startOneShot(0);

Modified: trunk/Source/WebCore/dom/ProcessingInstruction.cpp (205454 => 205455)


--- trunk/Source/WebCore/dom/ProcessingInstruction.cpp	2016-09-05 16:42:23 UTC (rev 205454)
+++ trunk/Source/WebCore/dom/ProcessingInstruction.cpp	2016-09-05 16:58:48 UTC (rev 205455)
@@ -190,7 +190,7 @@
     ASSERT(m_isCSS);
     CSSParserContext parserContext(document(), baseURL, charset);
 
-    auto cssSheet = CSSStyleSheet::create(StyleSheetContents::create(href, parserContext), this);
+    auto cssSheet = CSSStyleSheet::create(StyleSheetContents::create(href, parserContext), *this);
     cssSheet.get().setDisabled(m_alternate);
     cssSheet.get().setTitle(m_title);
     cssSheet.get().setMediaQueries(MediaQuerySet::create(m_media));

Modified: trunk/Source/WebCore/html/HTMLLinkElement.cpp (205454 => 205455)


--- trunk/Source/WebCore/html/HTMLLinkElement.cpp	2016-09-05 16:42:23 UTC (rev 205454)
+++ trunk/Source/WebCore/html/HTMLLinkElement.cpp	2016-09-05 16:58:48 UTC (rev 205455)
@@ -339,6 +339,18 @@
     HTMLElement::finishParsingChildren();
 }
 
+void HTMLLinkElement::initializeStyleSheet(Ref<StyleSheetContents>&& styleSheet, const CachedCSSStyleSheet& cachedStyleSheet)
+{
+    // FIXME: originClean should be turned to false except if fetch mode is CORS.
+    Optional<bool> originClean;
+    if (cachedStyleSheet.options().mode == FetchOptions::Mode::Cors)
+        originClean = cachedStyleSheet.isClean();
+
+    m_sheet = CSSStyleSheet::create(WTFMove(styleSheet), *this, originClean);
+    m_sheet->setMediaQueries(MediaQuerySet::createAllowingDescriptionSyntax(m_media));
+    m_sheet->setTitle(title());
+}
+
 void HTMLLinkElement::setCSSStyleSheet(const String& href, const URL& baseURL, const String& charset, const CachedCSSStyleSheet* cachedStyleSheet)
 {
     if (!inDocument()) {
@@ -358,11 +370,8 @@
     if (RefPtr<StyleSheetContents> restoredSheet = const_cast<CachedCSSStyleSheet*>(cachedStyleSheet)->restoreParsedStyleSheet(parserContext, cachePolicy)) {
         ASSERT(restoredSheet->isCacheable());
         ASSERT(!restoredSheet->isLoading());
+        initializeStyleSheet(restoredSheet.releaseNonNull(), *cachedStyleSheet);
 
-        m_sheet = CSSStyleSheet::create(restoredSheet.releaseNonNull(), this);
-        m_sheet->setMediaQueries(MediaQuerySet::createAllowingDescriptionSyntax(m_media));
-        m_sheet->setTitle(title());
-
         m_loading = false;
         sheetLoaded();
         notifyLoadedSheetAndAllCriticalSubresources(false);
@@ -370,9 +379,7 @@
     }
 
     auto styleSheet = StyleSheetContents::create(href, parserContext);
-    m_sheet = CSSStyleSheet::create(styleSheet.copyRef(), this);
-    m_sheet->setMediaQueries(MediaQuerySet::createAllowingDescriptionSyntax(m_media));
-    m_sheet->setTitle(title());
+    initializeStyleSheet(styleSheet.copyRef(), *cachedStyleSheet);
 
     styleSheet.get().parseAuthorStyleSheet(cachedStyleSheet, document().securityOrigin());
 

Modified: trunk/Source/WebCore/html/HTMLLinkElement.h (205454 => 205455)


--- trunk/Source/WebCore/html/HTMLLinkElement.h	2016-09-05 16:42:23 UTC (rev 205454)
+++ trunk/Source/WebCore/html/HTMLLinkElement.h	2016-09-05 16:58:48 UTC (rev 205455)
@@ -82,6 +82,8 @@
     InsertionNotificationRequest insertedInto(ContainerNode&) final;
     void removedFrom(ContainerNode&) final;
 
+    void initializeStyleSheet(Ref<StyleSheetContents>&&, const CachedCSSStyleSheet&);
+
     // from CachedResourceClient
     void setCSSStyleSheet(const String& href, const URL& baseURL, const String& charset, const CachedCSSStyleSheet*) final;
     bool sheetLoaded() final;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to