Changeset 288099 in webkit


Ignore:
Timestamp:
Jan 17, 2022 11:44:14 AM (6 months ago)
Author:
Antti Koivisto
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.
Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r288096 r288099  
     12022-01-17  Antti Koivisto  <antti@apple.com>
     2
     3        Layered @import rules in <style> should be preloaded
     4        https://bugs.webkit.org/show_bug.cgi?id=234094
     5        <rdar://problem/86586969>
     6
     7        Reviewed by Dean Jackson.
     8
     9        * http/tests/loading/preload-css-import-layer-expected.txt: Added.
     10        * http/tests/loading/preload-css-import-layer.html: Added.
     11
    1122022-01-17  Arcady Goldmints-Orlov  <agoldmints@igalia.com>
    213
  • trunk/Source/WebCore/ChangeLog

    r288095 r288099  
     12022-01-17  Antti Koivisto  <antti@apple.com>
     2
     3        Layered @import rules in <style> should be preloaded
     4        https://bugs.webkit.org/show_bug.cgi?id=234094
     5        <rdar://problem/86586969>
     6
     7        Reviewed by Dean Jackson.
     8
     9        Test: http/tests/loading/preload-css-import-layer.html
     10
     11        * html/parser/CSSPreloadScanner.cpp:
     12        (WebCore::CSSPreloadScanner::tokenize):
     13        (WebCore::hasValidImportConditions):
     14        (WebCore::CSSPreloadScanner::emitRule):
     15        * html/parser/CSSPreloadScanner.h:
     16
     17        Allow @import rule containing layer condition to be preloaded.
     18
    1192022-01-17  Alan Bujtas  <zalan@apple.com>
    220
  • trunk/Source/WebCore/html/parser/CSSPreloadScanner.cpp

    r248846 r288099  
    9999            m_rule.clear();
    100100            m_ruleValue.clear();
     101            m_ruleConditions.clear();
    101102            m_rule.append(c);
    102103            m_state = Rule;
     
    140141            m_state = DoneParsingImportRules;
    141142        else {
    142             // FIXME: media rules
    143             m_state = Initial;
     143            m_state = RuleConditions;
     144            m_ruleConditions.append(c);
    144145        }
     146        break;
     147    case RuleConditions:
     148        if (c == ';')
     149            emitRule();
     150        else if (c == '{')
     151            m_state = DoneParsingImportRules;
     152        else
     153            m_ruleConditions.append(c);
    145154        break;
    146155    case DoneParsingImportRules:
     
    194203}
    195204
     205static bool hasValidImportConditions(StringView conditions)
     206{
     207    if (conditions.isEmpty())
     208        return true;
     209
     210    conditions = conditions.stripLeadingAndTrailingMatchedCharacters(isHTMLSpace<UChar>);
     211
     212    // FIXME: Support multiple conditions.
     213    // FIXME: Support media queries.
     214    // FIXME: Support supports().
     215
     216    auto end = conditions.find(')');
     217    if (end != notFound)
     218        return end == conditions.length() - 1 && conditions.startsWith("layer(");
     219
     220    return conditions == "layer";
     221}
     222
    196223void CSSPreloadScanner::emitRule()
    197224{
     
    199226    if (equalLettersIgnoringASCIICase(rule, "import")) {
    200227        String url = parseCSSStringOrURL(m_ruleValue.data(), m_ruleValue.size());
    201         if (!url.isEmpty()) {
     228        StringView conditions(m_ruleConditions.data(), m_ruleConditions.size());
     229        if (!url.isEmpty() && hasValidImportConditions(conditions)) {
    202230            URL baseElementURL; // FIXME: This should be passed in from the HTMLPreloadScanner via scan(): without it we will get relative URLs wrong.
    203231            // FIXME: Should this be including the charset in the preload request?
     
    211239    m_rule.clear();
    212240    m_ruleValue.clear();
    213 }
    214 
    215 }
     241    m_ruleConditions.clear();
     242}
     243
     244}
  • trunk/Source/WebCore/html/parser/CSSPreloadScanner.h

    r208179 r288099  
    5454        RuleValue,
    5555        AfterRuleValue,
     56        RuleConditions,
    5657        DoneParsingImportRules,
    5758    };
     
    6364    Vector<UChar> m_rule;
    6465    Vector<UChar> m_ruleValue;
     66    Vector<UChar> m_ruleConditions;
    6567
    6668    // Only non-zero during scan()
Note: See TracChangeset for help on using the changeset viewer.