Changeset 82916 in webkit


Ignore:
Timestamp:
Apr 5, 2011 2:27:58 AM (13 years ago)
Author:
simonjam@chromium.org
Message:

2011-04-05 James Simonsen <simonjam@chromium.org>

Reviewed by Adam Barth.

Stop preload scanning CSS when it&apos;s impossible to have another @import.
https://bugs.webkit.org/show_bug.cgi?id=57664

  • fast/preloader/style-expected.txt:
  • fast/preloader/style.html: Updated to test invalid @import statements.

2011-04-05 James Simonsen <simonjam@chromium.org>

Reviewed by Adam Barth.

Stop preload scanning CSS when it&apos;s impossible to have another @import.
https://bugs.webkit.org/show_bug.cgi?id=57664

@import statements are only allowed at the beginning of a CSS file.
Only comments or @charset can precede them. After seeing anything else,
abort early so that we:

  • don't have to parse the rest of the CSS.
  • don't preload something that the regular parser won't load.
  • html/parser/CSSPreloadScanner.cpp: (WebCore::CSSPreloadScanner::scan): Terminate early if we're done with @imports. (WebCore::CSSPreloadScanner::tokenize): Terminate early if we see a {} or any style rule. (WebCore::CSSPreloadScanner::emitRule): Only @charset or @import are allowed to precede @import.
  • html/parser/CSSPreloadScanner.h: Add DoneParsingImportRules state.
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r82913 r82916  
     12011-04-05  James Simonsen  <simonjam@chromium.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        Stop preload scanning CSS when it&apos;s impossible to have another @import.
     6        https://bugs.webkit.org/show_bug.cgi?id=57664
     7
     8        * fast/preloader/style-expected.txt:
     9        * fast/preloader/style.html: Updated to test invalid @import statements.
     10
    1112011-04-05  Kent Tamura  <tkent@chromium.org>
    212
  • trunk/LayoutTests/fast/preloader/style-expected.txt

    r61366 r82916  
    33
    44<style>
     5@charset "ascii";
     6/* */
    57@import "resources/style1.css";
     8em {
     9    @import "resources/fail.css";
     10}
     11@import "resources/fail.css";
     12</style>
     13<style>
     14@media print {
     15    @import "resources/fail.css";
     16}
     17@import "resources/fail.css";
    618</style>
    719
  • trunk/LayoutTests/fast/preloader/style.html

    r61370 r82916  
    1010<script>document.write("<plaintext>");</script>
    1111<style>
     12@charset "ascii";
     13/* */
    1214@import "resources/style1.css";
     15em {
     16    @import "resources/fail.css";
     17}
     18@import "resources/fail.css";
    1319</style>
     20<style>
     21@media print {
     22    @import "resources/fail.css";
     23}
     24@import "resources/fail.css";
     25</style>
  • trunk/Source/WebCore/ChangeLog

    r82915 r82916  
     12011-04-05  James Simonsen  <simonjam@chromium.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        Stop preload scanning CSS when it&apos;s impossible to have another @import.
     6        https://bugs.webkit.org/show_bug.cgi?id=57664
     7
     8        @import statements are only allowed at the beginning of a CSS file.
     9        Only comments or @charset can precede them. After seeing anything else,
     10        abort early so that we:
     11        - don't have to parse the rest of the CSS.
     12        - don't preload something that the regular parser won't load.
     13
     14        * html/parser/CSSPreloadScanner.cpp:
     15        (WebCore::CSSPreloadScanner::scan): Terminate early if we're done with @imports.
     16        (WebCore::CSSPreloadScanner::tokenize): Terminate early if we see a {} or any style rule.
     17        (WebCore::CSSPreloadScanner::emitRule): Only @charset or @import are allowed to precede @import.
     18        * html/parser/CSSPreloadScanner.h: Add DoneParsingImportRules state.
     19
    1202011-04-05  Takayoshi Kochi <kochi@chromium.org>
    221
  • trunk/Source/WebCore/html/parser/CSSPreloadScanner.cpp

    r68854 r82916  
    5555
    5656    const HTMLToken::DataVector& characters = token.characters();
    57     for (HTMLToken::DataVector::const_iterator iter = characters.begin(); iter != characters.end(); ++iter)
     57    for (HTMLToken::DataVector::const_iterator iter = characters.begin(); iter != characters.end() && m_state != DoneParsingImportRules; ++iter)
    5858        tokenize(*iter);
    5959}
     
    6565    switch (m_state) {
    6666    case Initial:
     67        if (isHTMLSpace(c))
     68            break;
    6769        if (c == '@')
    6870            m_state = RuleStart;
    6971        else if (c == '/')
    7072            m_state = MaybeComment;
     73        else
     74            m_state = DoneParsingImportRules;
    7175        break;
    7276    case MaybeComment:
     
    8185        break;
    8286    case MaybeCommentEnd:
     87        if (c == '*')
     88            break;
    8389        if (c == '/')
    8490            m_state = Initial;
    85         else if (c == '*')
    86             ;
    8791        else
    8892            m_state = Comment;
     
    107111    case AfterRule:
    108112        if (isHTMLSpace(c))
    109             ;
    110         else if (c == ';')
    111             m_state = Initial;
     113            break;
     114        if (c == ';')
     115            m_state = Initial;
     116        else if (c == '{')
     117            m_state = DoneParsingImportRules;
    112118        else {
    113119            m_state = RuleValue;
     
    118124        if (isHTMLSpace(c))
    119125            m_state = AfterRuleValue;
    120         else if (c == ';') {
     126        else if (c == ';')
    121127            emitRule();
    122             m_state = Initial;
    123         } else
     128        else
    124129            m_ruleValue.append(c);
    125130        break;
    126131    case AfterRuleValue:
    127132        if (isHTMLSpace(c))
    128             ;
    129         else if (c == ';') {
     133            break;
     134        if (c == ';')
    130135            emitRule();
    131             m_state = Initial;
    132         } else {
     136        else if (c == '{')
     137            m_state = DoneParsingImportRules;
     138        else {
    133139            // FIXME: media rules
    134140            m_state = Initial;
    135141        }
     142        break;
     143    case DoneParsingImportRules:
     144        ASSERT_NOT_REACHED();
    136145        break;
    137146    }
     
    188197        if (!value.isEmpty())
    189198            m_document->cachedResourceLoader()->preload(CachedResource::CSSStyleSheet, value, String(), m_scanningBody);
    190     }
     199        m_state = Initial;
     200    } else if (equalIgnoringCase("charset", m_rule.data(), m_rule.size()))
     201        m_state = Initial;
     202    else
     203        m_state = DoneParsingImportRules;
    191204    m_rule.clear();
    192205    m_ruleValue.clear();
  • trunk/Source/WebCore/html/parser/CSSPreloadScanner.h

    r76248 r82916  
    5454        AfterRule,
    5555        RuleValue,
    56         AfterRuleValue
     56        AfterRuleValue,
     57        DoneParsingImportRules,
    5758    };
    5859
Note: See TracChangeset for help on using the changeset viewer.