Commit aae248dd authored by simonjam@chromium.org's avatar simonjam@chromium.org

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.

git-svn-id: svn://svn.chromium.org/blink/trunk@82916 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 90a67b3d
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 Kent Tamura <tkent@chromium.org>
Update a test affected by the behavior change of r82908.
......@@ -2,6 +2,18 @@ style1.css has MIME type text/css
This test requires DumpRenderTree to see the log of what resources are loaded.
<style>
@charset "ascii";
/* */
@import "resources/style1.css";
em {
@import "resources/fail.css";
}
@import "resources/fail.css";
</style>
<style>
@media print {
@import "resources/fail.css";
}
@import "resources/fail.css";
</style>
......@@ -9,5 +9,17 @@ This test requires DumpRenderTree to see the log of what resources are loaded.
<script src=resources/non-existant.js></script>
<script>document.write("<plaintext>");</script>
<style>
@charset "ascii";
/* */
@import "resources/style1.css";
em {
@import "resources/fail.css";
}
@import "resources/fail.css";
</style>
<style>
@media print {
@import "resources/fail.css";
}
@import "resources/fail.css";
</style>
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.
2011-04-05 Takayoshi Kochi <kochi@chromium.org>
Reviewed by Tony Chang.
......@@ -54,7 +54,7 @@ void CSSPreloadScanner::scan(const HTMLToken& token, bool scanningBody)
m_scanningBody = scanningBody;
const HTMLToken::DataVector& characters = token.characters();
for (HTMLToken::DataVector::const_iterator iter = characters.begin(); iter != characters.end(); ++iter)
for (HTMLToken::DataVector::const_iterator iter = characters.begin(); iter != characters.end() && m_state != DoneParsingImportRules; ++iter)
tokenize(*iter);
}
......@@ -64,10 +64,14 @@ inline void CSSPreloadScanner::tokenize(UChar c)
// Searching for other types of resources is probably low payoff.
switch (m_state) {
case Initial:
if (isHTMLSpace(c))
break;
if (c == '@')
m_state = RuleStart;
else if (c == '/')
m_state = MaybeComment;
else
m_state = DoneParsingImportRules;
break;
case MaybeComment:
if (c == '*')
......@@ -80,10 +84,10 @@ inline void CSSPreloadScanner::tokenize(UChar c)
m_state = MaybeCommentEnd;
break;
case MaybeCommentEnd:
if (c == '*')
break;
if (c == '/')
m_state = Initial;
else if (c == '*')
;
else
m_state = Comment;
break;
......@@ -106,9 +110,11 @@ inline void CSSPreloadScanner::tokenize(UChar c)
break;
case AfterRule:
if (isHTMLSpace(c))
;
else if (c == ';')
break;
if (c == ';')
m_state = Initial;
else if (c == '{')
m_state = DoneParsingImportRules;
else {
m_state = RuleValue;
m_ruleValue.append(c);
......@@ -117,23 +123,26 @@ inline void CSSPreloadScanner::tokenize(UChar c)
case RuleValue:
if (isHTMLSpace(c))
m_state = AfterRuleValue;
else if (c == ';') {
else if (c == ';')
emitRule();
m_state = Initial;
} else
else
m_ruleValue.append(c);
break;
case AfterRuleValue:
if (isHTMLSpace(c))
;
else if (c == ';') {
break;
if (c == ';')
emitRule();
m_state = Initial;
} else {
else if (c == '{')
m_state = DoneParsingImportRules;
else {
// FIXME: media rules
m_state = Initial;
}
break;
case DoneParsingImportRules:
ASSERT_NOT_REACHED();
break;
}
}
......@@ -187,7 +196,11 @@ void CSSPreloadScanner::emitRule()
String value = parseCSSStringOrURL(m_ruleValue.data(), m_ruleValue.size());
if (!value.isEmpty())
m_document->cachedResourceLoader()->preload(CachedResource::CSSStyleSheet, value, String(), m_scanningBody);
}
m_state = Initial;
} else if (equalIgnoringCase("charset", m_rule.data(), m_rule.size()))
m_state = Initial;
else
m_state = DoneParsingImportRules;
m_rule.clear();
m_ruleValue.clear();
}
......
......@@ -53,7 +53,8 @@ private:
Rule,
AfterRule,
RuleValue,
AfterRuleValue
AfterRuleValue,
DoneParsingImportRules,
};
inline void tokenize(UChar c);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment