Web Inspector: Plumbing CSS warnings

https://bugs.webkit.org/show_bug.cgi?id=111334

Patch by Sergey Ryazanov <serya@chromium.org> on 2013-03-20
Reviewed by Pavel Feldman.

Adding a framework for plumbing CSS warnings from CSSParser/grammar to the Inspector console.

* css/CSSParser.cpp:
(WebCore::CSSParser::CSSParser):
(WebCore::CSSParser::parseSheet):
(WebCore::CSSParser::syntaxError):
(WebCore):
(WebCore::CSSParser::isLoggingErrors):
(WebCore::CSSParser::logError):
* css/CSSParser.h:
(CSSParser):
(CSSParser::Location):
(WebCore):
* css/StyleSheetContents.cpp:
(WebCore::StyleSheetContents::parseAuthorStyleSheet):
(WebCore::StyleSheetContents::parseString):
(WebCore::StyleSheetContents::parseStringAtLine):
* css/StyleSheetContents.h:
(StyleSheetContents):
* dom/StyleElement.cpp:
(WebCore::StyleElement::createSheet):
* page/PageConsole.cpp:
(WebCore::PageConsole::addMessage):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@146353 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent bea8cd4a
2013-03-20 Sergey Ryazanov <serya@chromium.org>
Web Inspector: Plumbing CSS warnings
https://bugs.webkit.org/show_bug.cgi?id=111334
Reviewed by Pavel Feldman.
Adding a framework for plumbing CSS warnings from CSSParser/grammar to the Inspector console.
* css/CSSParser.cpp:
(WebCore::CSSParser::CSSParser):
(WebCore::CSSParser::parseSheet):
(WebCore::CSSParser::syntaxError):
(WebCore):
(WebCore::CSSParser::isLoggingErrors):
(WebCore::CSSParser::logError):
* css/CSSParser.h:
(CSSParser):
(CSSParser::Location):
(WebCore):
* css/StyleSheetContents.cpp:
(WebCore::StyleSheetContents::parseAuthorStyleSheet):
(WebCore::StyleSheetContents::parseString):
(WebCore::StyleSheetContents::parseStringAtLine):
* css/StyleSheetContents.h:
(StyleSheetContents):
* dom/StyleElement.cpp:
(WebCore::StyleElement::createSheet):
* page/PageConsole.cpp:
(WebCore::PageConsole::addMessage):
2013-03-20 Justin Novosad <junov@google.com>
[Chromium] Code cleanup: removing support for non-deferred 2d canvas rendering
......@@ -67,6 +67,7 @@
#include "MediaList.h"
#include "MediaQueryExp.h"
#include "Page.h"
#include "PageConsole.h"
#include "Pair.h"
#include "Rect.h"
#include "RenderTheme.h"
......@@ -318,6 +319,7 @@ CSSParser::CSSParser(const CSSParserContext& context)
, m_implicitShorthand(false)
, m_hasFontFaceOnlyValues(false)
, m_hadSyntacticallyValidCSSRule(false)
, m_logErrors(false)
#if ENABLE(CSS_SHADERS)
, m_inFilterRule(false)
#endif
......@@ -453,7 +455,7 @@ void CSSParser::setupParser(const char* prefix, unsigned prefixLength, const Str
m_lexFunc = &CSSParser::realLex<UChar>;
}
void CSSParser::parseSheet(StyleSheetContents* sheet, const String& string, int startLineNumber, RuleSourceDataList* ruleSourceDataResult)
void CSSParser::parseSheet(StyleSheetContents* sheet, const String& string, int startLineNumber, RuleSourceDataList* ruleSourceDataResult, bool logErrors)
{
setStyleSheet(sheet);
m_defaultNamespace = starAtom; // Reset the default namespace.
......@@ -461,6 +463,7 @@ void CSSParser::parseSheet(StyleSheetContents* sheet, const String& string, int
m_currentRuleDataStack = adoptPtr(new RuleSourceDataList());
m_ruleSourceDataResult = ruleSourceDataResult;
m_logErrors = logErrors && sheet->singleOwnerDocument() && !sheet->baseURL().isEmpty() && sheet->singleOwnerDocument()->page();
m_lineNumber = startLineNumber;
setupParser("", string, "");
cssyyparse(this);
......@@ -468,6 +471,7 @@ void CSSParser::parseSheet(StyleSheetContents* sheet, const String& string, int
m_currentRuleDataStack.clear();
m_ruleSourceDataResult = 0;
m_rule = 0;
m_logErrors = false;
}
PassRefPtr<StyleRuleBase> CSSParser::parseRule(StyleSheetContents* sheet, const String& string)
......@@ -11210,6 +11214,30 @@ PassRefPtr<CSSRuleSourceData> CSSParser::popRuleData()
return data.release();
}
void CSSParser::syntaxError(Location location)
{
if (!isLoggingErrors())
return;
StringBuilder builder;
builder.appendLiteral("Unexpected CSS token: ");
if (location.token.is8Bit())
builder.append(location.token.characters8(), location.token.length());
else
builder.append(location.token.characters16(), location.token.length());
logError(builder.toString(), location.lineNumber);
}
bool CSSParser::isLoggingErrors()
{
return m_logErrors;
}
void CSSParser::logError(const String& message, int lineNumber)
{
PageConsole* console = m_styleSheet->singleOwnerDocument()->page()->console();
console->addMessage(CSSMessageSource, WarningMessageLevel, message, m_styleSheet->baseURL().string(), lineNumber + 1);
}
StyleRuleKeyframes* CSSParser::createKeyframesRule(const String& name, PassOwnPtr<Vector<RefPtr<StyleKeyframe> > > popKeyframes)
{
OwnPtr<Vector<RefPtr<StyleKeyframe> > > keyframes = popKeyframes;
......
......@@ -75,11 +75,13 @@ class CSSParser {
friend inline int cssyylex(void*, CSSParser*);
public:
struct Location;
CSSParser(const CSSParserContext&);
~CSSParser();
void parseSheet(StyleSheetContents*, const String&, int startLineNumber = 0, RuleSourceDataList* = 0);
void parseSheet(StyleSheetContents*, const String&, int startLineNumber = 0, RuleSourceDataList* = 0, bool = false);
PassRefPtr<StyleRuleBase> parseRule(StyleSheetContents*, const String&);
PassRefPtr<StyleKeyframe> parseKeyframeRule(StyleSheetContents*, const String&);
#if ENABLE(CSS3_CONDITIONAL_RULES)
......@@ -385,6 +387,7 @@ public:
bool m_hasFontFaceOnlyValues;
bool m_hadSyntacticallyValidCSSRule;
bool m_logErrors;
#if ENABLE(CSS_SHADERS)
bool m_inFilterRule;
......@@ -414,6 +417,7 @@ public:
PassRefPtr<CSSRuleSourceData> popRuleData();
void resetPropertyRange() { m_propertyRange.start = m_propertyRange.end = UINT_MAX; }
bool isExtractingSourceData() const { return !!m_currentRuleDataStack; }
void syntaxError(Location);
inline int lex(void* yylval) { return (this->*m_lexFunc)(yylval); }
......@@ -638,6 +642,9 @@ private:
DoNotReleaseParsedCalcValue
};
bool isLoggingErrors();
void logError(const String& message, int lineNumber);
bool validCalculationUnit(CSSParserValue*, Units, ReleaseParsedCalcValueCondition releaseCalc = DoNotReleaseParsedCalcValue);
bool shouldAcceptUnitLessValues(CSSParserValue*, Units, CSSParserMode);
......@@ -681,6 +688,11 @@ private:
CSSParser* m_parser;
};
struct CSSParser::Location {
int lineNumber;
CSSParserString token;
};
String quoteCSSString(const String&);
String quoteCSSStringIfNeeded(const String&);
String quoteCSSURLIfNeeded(const String&);
......
......@@ -285,7 +285,7 @@ void StyleSheetContents::parseAuthorStyleSheet(const CachedCSSStyleSheet* cached
String sheetText = cachedStyleSheet->sheetText(enforceMIMEType, &hasValidMIMEType);
CSSParser p(parserContext());
p.parseSheet(this, sheetText, 0);
p.parseSheet(this, sheetText, 0, 0, true);
// If we're loading a stylesheet cross-origin, and the MIME type is not standard, require the CSS
// to at least start with a syntactically valid CSS rule.
......@@ -310,13 +310,13 @@ void StyleSheetContents::parseAuthorStyleSheet(const CachedCSSStyleSheet* cached
bool StyleSheetContents::parseString(const String& sheetText)
{
return parseStringAtLine(sheetText, 0);
return parseStringAtLine(sheetText, 0, false);
}
bool StyleSheetContents::parseStringAtLine(const String& sheetText, int startLineNumber)
bool StyleSheetContents::parseStringAtLine(const String& sheetText, int startLineNumber, bool createdByParser)
{
CSSParser p(parserContext());
p.parseSheet(this, sheetText, startLineNumber);
p.parseSheet(this, sheetText, startLineNumber, 0, createdByParser);
return true;
}
......
......@@ -62,7 +62,7 @@ public:
void parseAuthorStyleSheet(const CachedCSSStyleSheet*, const SecurityOrigin*);
bool parseString(const String&);
bool parseStringAtLine(const String&, int startLineNumber);
bool parseStringAtLine(const String&, int startLineNumber, bool);
bool isCacheable() const;
......
......@@ -175,7 +175,7 @@ void StyleElement::createSheet(Element* e, WTF::OrdinalNumber startLineNumber, c
m_sheet = CSSStyleSheet::createInline(e, KURL(), document->inputEncoding());
m_sheet->setMediaQueries(mediaQueries.release());
m_sheet->setTitle(e->title());
m_sheet->contents()->parseStringAtLine(text, startLineNumber.zeroBasedInt());
m_sheet->contents()->parseStringAtLine(text, startLineNumber.zeroBasedInt(), m_createdByParser);
m_loading = false;
}
......
......@@ -169,6 +169,9 @@ void PageConsole::addMessage(MessageSource source, MessageLevel level, const Str
else
InspectorInstrumentation::addMessageToConsole(page, source, LogMessageType, level, message, url, lineNumber, state, requestIdentifier);
if (source == CSSMessageSource)
return;
if (page->settings()->privateBrowsingEnabled())
return;
......
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