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> 2011-04-05 Kent Tamura <tkent@chromium.org>
Update a test affected by the behavior change of r82908. Update a test affected by the behavior change of r82908.
...@@ -2,6 +2,18 @@ style1.css has MIME type text/css ...@@ -2,6 +2,18 @@ style1.css has MIME type text/css
This test requires DumpRenderTree to see the log of what resources are loaded. This test requires DumpRenderTree to see the log of what resources are loaded.
<style> <style>
@charset "ascii";
/* */
@import "resources/style1.css"; @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> </style>
...@@ -9,5 +9,17 @@ This test requires DumpRenderTree to see the log of what resources are loaded. ...@@ -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 src=resources/non-existant.js></script>
<script>document.write("<plaintext>");</script> <script>document.write("<plaintext>");</script>
<style> <style>
@charset "ascii";
/* */
@import "resources/style1.css"; @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> </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> 2011-04-05 Takayoshi Kochi <kochi@chromium.org>
Reviewed by Tony Chang. Reviewed by Tony Chang.
...@@ -54,7 +54,7 @@ void CSSPreloadScanner::scan(const HTMLToken& token, bool scanningBody) ...@@ -54,7 +54,7 @@ void CSSPreloadScanner::scan(const HTMLToken& token, bool scanningBody)
m_scanningBody = scanningBody; m_scanningBody = scanningBody;
const HTMLToken::DataVector& characters = token.characters(); 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); tokenize(*iter);
} }
...@@ -64,10 +64,14 @@ inline void CSSPreloadScanner::tokenize(UChar c) ...@@ -64,10 +64,14 @@ inline void CSSPreloadScanner::tokenize(UChar c)
// Searching for other types of resources is probably low payoff. // Searching for other types of resources is probably low payoff.
switch (m_state) { switch (m_state) {
case Initial: case Initial:
if (isHTMLSpace(c))
break;
if (c == '@') if (c == '@')
m_state = RuleStart; m_state = RuleStart;
else if (c == '/') else if (c == '/')
m_state = MaybeComment; m_state = MaybeComment;
else
m_state = DoneParsingImportRules;
break; break;
case MaybeComment: case MaybeComment:
if (c == '*') if (c == '*')
...@@ -80,10 +84,10 @@ inline void CSSPreloadScanner::tokenize(UChar c) ...@@ -80,10 +84,10 @@ inline void CSSPreloadScanner::tokenize(UChar c)
m_state = MaybeCommentEnd; m_state = MaybeCommentEnd;
break; break;
case MaybeCommentEnd: case MaybeCommentEnd:
if (c == '*')
break;
if (c == '/') if (c == '/')
m_state = Initial; m_state = Initial;
else if (c == '*')
;
else else
m_state = Comment; m_state = Comment;
break; break;
...@@ -106,9 +110,11 @@ inline void CSSPreloadScanner::tokenize(UChar c) ...@@ -106,9 +110,11 @@ inline void CSSPreloadScanner::tokenize(UChar c)
break; break;
case AfterRule: case AfterRule:
if (isHTMLSpace(c)) if (isHTMLSpace(c))
; break;
else if (c == ';') if (c == ';')
m_state = Initial; m_state = Initial;
else if (c == '{')
m_state = DoneParsingImportRules;
else { else {
m_state = RuleValue; m_state = RuleValue;
m_ruleValue.append(c); m_ruleValue.append(c);
...@@ -117,23 +123,26 @@ inline void CSSPreloadScanner::tokenize(UChar c) ...@@ -117,23 +123,26 @@ inline void CSSPreloadScanner::tokenize(UChar c)
case RuleValue: case RuleValue:
if (isHTMLSpace(c)) if (isHTMLSpace(c))
m_state = AfterRuleValue; m_state = AfterRuleValue;
else if (c == ';') { else if (c == ';')
emitRule(); emitRule();
m_state = Initial; else
} else
m_ruleValue.append(c); m_ruleValue.append(c);
break; break;
case AfterRuleValue: case AfterRuleValue:
if (isHTMLSpace(c)) if (isHTMLSpace(c))
; break;
else if (c == ';') { if (c == ';')
emitRule(); emitRule();
m_state = Initial; else if (c == '{')
} else { m_state = DoneParsingImportRules;
else {
// FIXME: media rules // FIXME: media rules
m_state = Initial; m_state = Initial;
} }
break; break;
case DoneParsingImportRules:
ASSERT_NOT_REACHED();
break;
} }
} }
...@@ -187,7 +196,11 @@ void CSSPreloadScanner::emitRule() ...@@ -187,7 +196,11 @@ void CSSPreloadScanner::emitRule()
String value = parseCSSStringOrURL(m_ruleValue.data(), m_ruleValue.size()); String value = parseCSSStringOrURL(m_ruleValue.data(), m_ruleValue.size());
if (!value.isEmpty()) if (!value.isEmpty())
m_document->cachedResourceLoader()->preload(CachedResource::CSSStyleSheet, value, String(), m_scanningBody); 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_rule.clear();
m_ruleValue.clear(); m_ruleValue.clear();
} }
......
...@@ -53,7 +53,8 @@ private: ...@@ -53,7 +53,8 @@ private:
Rule, Rule,
AfterRule, AfterRule,
RuleValue, RuleValue,
AfterRuleValue AfterRuleValue,
DoneParsingImportRules,
}; };
inline void tokenize(UChar c); 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