Title: [288509] branches/safari-613-branch
Revision
288509
Author
repst...@apple.com
Date
2022-01-24 17:55:29 -0800 (Mon, 24 Jan 2022)

Log Message

Cherry-pick r288099. rdar://problem/86586969

    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.

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@288099 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Added Paths

Diff

Modified: branches/safari-613-branch/LayoutTests/ChangeLog (288508 => 288509)


--- branches/safari-613-branch/LayoutTests/ChangeLog	2022-01-25 01:55:26 UTC (rev 288508)
+++ branches/safari-613-branch/LayoutTests/ChangeLog	2022-01-25 01:55:29 UTC (rev 288509)
@@ -1,5 +1,46 @@
 2022-01-24  Alan Coon  <alanc...@apple.com>
 
+        Cherry-pick r288099. rdar://problem/86586969
+
+    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.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@288099 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2022-01-17  Antti Koivisto  <an...@apple.com>
+
+            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-24  Alan Coon  <alanc...@apple.com>
+
         Cherry-pick r288025. rdar://problem/83407577
 
     gl.texImage2D upload of getUserMedia streams via <video> element fails

Added: branches/safari-613-branch/LayoutTests/http/tests/loading/preload-css-import-layer-expected.txt (0 => 288509)


--- branches/safari-613-branch/LayoutTests/http/tests/loading/preload-css-import-layer-expected.txt	                        (rev 0)
+++ branches/safari-613-branch/LayoutTests/http/tests/loading/preload-css-import-layer-expected.txt	2022-01-25 01:55:29 UTC (rev 288509)
@@ -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: branches/safari-613-branch/LayoutTests/http/tests/loading/preload-css-import-layer.html (0 => 288509)


--- branches/safari-613-branch/LayoutTests/http/tests/loading/preload-css-import-layer.html	                        (rev 0)
+++ branches/safari-613-branch/LayoutTests/http/tests/loading/preload-css-import-layer.html	2022-01-25 01:55:29 UTC (rev 288509)
@@ -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: branches/safari-613-branch/Source/WebCore/ChangeLog (288508 => 288509)


--- branches/safari-613-branch/Source/WebCore/ChangeLog	2022-01-25 01:55:26 UTC (rev 288508)
+++ branches/safari-613-branch/Source/WebCore/ChangeLog	2022-01-25 01:55:29 UTC (rev 288509)
@@ -1,5 +1,53 @@
 2022-01-24  Alan Coon  <alanc...@apple.com>
 
+        Cherry-pick r288099. rdar://problem/86586969
+
+    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.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@288099 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2022-01-17  Antti Koivisto  <an...@apple.com>
+
+            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-24  Alan Coon  <alanc...@apple.com>
+
         Cherry-pick r288025. rdar://problem/83407577
 
     gl.texImage2D upload of getUserMedia streams via <video> element fails

Modified: branches/safari-613-branch/Source/WebCore/html/parser/CSSPreloadScanner.cpp (288508 => 288509)


--- branches/safari-613-branch/Source/WebCore/html/parser/CSSPreloadScanner.cpp	2022-01-25 01:55:26 UTC (rev 288508)
+++ branches/safari-613-branch/Source/WebCore/html/parser/CSSPreloadScanner.cpp	2022-01-25 01:55:29 UTC (rev 288509)
@@ -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: branches/safari-613-branch/Source/WebCore/html/parser/CSSPreloadScanner.h (288508 => 288509)


--- branches/safari-613-branch/Source/WebCore/html/parser/CSSPreloadScanner.h	2022-01-25 01:55:26 UTC (rev 288508)
+++ branches/safari-613-branch/Source/WebCore/html/parser/CSSPreloadScanner.h	2022-01-25 01:55:29 UTC (rev 288509)
@@ -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
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to