Title: [288099] trunk
Revision
288099
Author
[email protected]
Date
2022-01-17 11:44:14 -0800 (Mon, 17 Jan 2022)

Log Message

Layered @import rules in <style> should be preloaded
https://bugs.webkit.org/show_bug.cgi?id=234094
<rdar://problem/86586969>

Reviewed by Dean Jackson.

Source/WebCore:

Test: http/tests/loading/preload-css-import-layer.html

* html/parser/CSSPreloadScanner.cpp:
(WebCore::CSSPreloadScanner::tokenize):
(WebCore::hasValidImportConditions):
(WebCore::CSSPreloadScanner::emitRule):
* html/parser/CSSPreloadScanner.h:

Allow @import rule containing layer condition to be preloaded.

LayoutTests:

* http/tests/loading/preload-css-import-layer-expected.txt: Added.
* http/tests/loading/preload-css-import-layer.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (288098 => 288099)


--- trunk/LayoutTests/ChangeLog	2022-01-17 19:35:37 UTC (rev 288098)
+++ trunk/LayoutTests/ChangeLog	2022-01-17 19:44:14 UTC (rev 288099)
@@ -1,3 +1,14 @@
+2022-01-17  Antti Koivisto  <[email protected]>
+
+        Layered @import rules in <style> should be preloaded
+        https://bugs.webkit.org/show_bug.cgi?id=234094
+        <rdar://problem/86586969>
+
+        Reviewed by Dean Jackson.
+
+        * http/tests/loading/preload-css-import-layer-expected.txt: Added.
+        * http/tests/loading/preload-css-import-layer.html: Added.
+
 2022-01-17  Arcady Goldmints-Orlov  <[email protected]>
 
         [GLIB] Update test expectations after r288070 allowed LFC integration to work on GTK.

Added: trunk/LayoutTests/http/tests/loading/preload-css-import-layer-expected.txt (0 => 288099)


--- trunk/LayoutTests/http/tests/loading/preload-css-import-layer-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/loading/preload-css-import-layer-expected.txt	2022-01-17 19:44:14 UTC (rev 288099)
@@ -0,0 +1,13 @@
+main frame - didStartProvisionalLoadForFrame
+main frame - didCommitLoadForFrame
+main frame - didFinishDocumentLoadForFrame
+main frame - didHandleOnloadEventsForFrame
+main frame - didFinishLoadForFrame
+Preload scanner should preload @import rules with layers
+
+PASS
+PASS
+PASS
+PASS
+PASS
+

Added: trunk/LayoutTests/http/tests/loading/preload-css-import-layer.html (0 => 288099)


--- trunk/LayoutTests/http/tests/loading/preload-css-import-layer.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/loading/preload-css-import-layer.html	2022-01-17 19:44:14 UTC (rev 288099)
@@ -0,0 +1,40 @@
+<head>
+<script>
+if (window.testRunner)
+    testRunner.dumpAsText();
+
+var results=[];
+function checkForPreload(url, shouldbe) {
+    var preloaded = internals.isPreloaded(url);
+    if ((preloaded && shouldbe) || (!preloaded && !shouldbe))
+        results.push("PASS\n");
+    else
+        results.push("FAIL\n");
+}
+function printResults(){
+    for(var i = 0; i < results.length; i++)
+        log.textContent += results[i];
+}
+    
+</script>
+<script src=""
+<script>
+checkForPreload("resources/small_mq.css?1", true);
+checkForPreload("resources/small_mq.css?2", true);
+checkForPreload("resources/small_mq.css?3", true);
+checkForPreload("resources/small_mq.css?4", true);
+checkForPreload("resources/small_mq.css?5", false);
+</script>
+<style>
+@import url("resources/small_mq.css?1");
+@import url("resources/small_mq.css?2") layer;
+@import url("resources/small_mq.css?3") layer(foo);
+@import url("resources/small_mq.css?4")  layer(foo bar) ;
+@import url("resources/small_mq.css?5") layer(foo) speech;
+</style>
+<body>
+<p>Preload scanner should preload @import rules with layers</p>
+<pre id=log></pre>
+<script>
+printResults();
+</script>

Modified: trunk/Source/WebCore/ChangeLog (288098 => 288099)


--- trunk/Source/WebCore/ChangeLog	2022-01-17 19:35:37 UTC (rev 288098)
+++ trunk/Source/WebCore/ChangeLog	2022-01-17 19:44:14 UTC (rev 288099)
@@ -1,3 +1,21 @@
+2022-01-17  Antti Koivisto  <[email protected]>
+
+        Layered @import rules in <style> should be preloaded
+        https://bugs.webkit.org/show_bug.cgi?id=234094
+        <rdar://problem/86586969>
+
+        Reviewed by Dean Jackson.
+
+        Test: http/tests/loading/preload-css-import-layer.html
+
+        * html/parser/CSSPreloadScanner.cpp:
+        (WebCore::CSSPreloadScanner::tokenize):
+        (WebCore::hasValidImportConditions):
+        (WebCore::CSSPreloadScanner::emitRule):
+        * html/parser/CSSPreloadScanner.h:
+
+        Allow @import rule containing layer condition to be preloaded.
+
 2022-01-17  Alan Bujtas  <[email protected]>
 
         [LFC][IFC] ASSERT in InlineContentBreaker::tryBreakingPreviousNonOverflowingRuns (!partialRun->length) when webinspector is open

Modified: trunk/Source/WebCore/html/parser/CSSPreloadScanner.cpp (288098 => 288099)


--- trunk/Source/WebCore/html/parser/CSSPreloadScanner.cpp	2022-01-17 19:35:37 UTC (rev 288098)
+++ trunk/Source/WebCore/html/parser/CSSPreloadScanner.cpp	2022-01-17 19:44:14 UTC (rev 288099)
@@ -98,6 +98,7 @@
         if (isASCIIAlpha(c)) {
             m_rule.clear();
             m_ruleValue.clear();
+            m_ruleConditions.clear();
             m_rule.append(c);
             m_state = Rule;
         } else
@@ -139,10 +140,18 @@
         else if (c == '{')
             m_state = DoneParsingImportRules;
         else {
-            // FIXME: media rules
-            m_state = Initial;
+            m_state = RuleConditions;
+            m_ruleConditions.append(c);
         }
         break;
+    case RuleConditions:
+        if (c == ';')
+            emitRule();
+        else if (c == '{')
+            m_state = DoneParsingImportRules;
+        else
+            m_ruleConditions.append(c);
+        break;
     case DoneParsingImportRules:
         ASSERT_NOT_REACHED();
         break;
@@ -193,12 +202,31 @@
     return String(characters + offset, reducedLength);
 }
 
+static bool hasValidImportConditions(StringView conditions)
+{
+    if (conditions.isEmpty())
+        return true;
+
+    conditions = conditions.stripLeadingAndTrailingMatchedCharacters(isHTMLSpace<UChar>);
+
+    // FIXME: Support multiple conditions.
+    // FIXME: Support media queries.
+    // FIXME: Support supports().
+
+    auto end = conditions.find(')');
+    if (end != notFound)
+        return end == conditions.length() - 1 && conditions.startsWith("layer(");
+
+    return conditions == "layer";
+}
+
 void CSSPreloadScanner::emitRule()
 {
     StringView rule(m_rule.data(), m_rule.size());
     if (equalLettersIgnoringASCIICase(rule, "import")) {
         String url = "" m_ruleValue.size());
-        if (!url.isEmpty()) {
+        StringView conditions(m_ruleConditions.data(), m_ruleConditions.size());
+        if (!url.isEmpty() && hasValidImportConditions(conditions)) {
             URL baseElementURL; // FIXME: This should be passed in from the HTMLPreloadScanner via scan(): without it we will get relative URLs wrong.
             // FIXME: Should this be including the charset in the preload request?
             m_requests->append(makeUnique<PreloadRequest>("css", url, baseElementURL, CachedResource::Type::CSSStyleSheet, String(), PreloadRequest::ModuleScript::No, ReferrerPolicy::EmptyString));
@@ -210,6 +238,7 @@
         m_state = DoneParsingImportRules;
     m_rule.clear();
     m_ruleValue.clear();
+    m_ruleConditions.clear();
 }
 
 }

Modified: trunk/Source/WebCore/html/parser/CSSPreloadScanner.h (288098 => 288099)


--- trunk/Source/WebCore/html/parser/CSSPreloadScanner.h	2022-01-17 19:35:37 UTC (rev 288098)
+++ trunk/Source/WebCore/html/parser/CSSPreloadScanner.h	2022-01-17 19:44:14 UTC (rev 288099)
@@ -53,6 +53,7 @@
         AfterRule,
         RuleValue,
         AfterRuleValue,
+        RuleConditions,
         DoneParsingImportRules,
     };
 
@@ -62,6 +63,7 @@
     State m_state;
     Vector<UChar> m_rule;
     Vector<UChar> m_ruleValue;
+    Vector<UChar> m_ruleConditions;
 
     // Only non-zero during scan()
     PreloadRequestStream* m_requests;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to