PageConsole::addMessage should automatically determine column number alongside line number

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

Patch by László Langó <lango@inf.u-szeged.hu> on 2013-12-10
Reviewed by Joseph Pecoraro.

Source/WebCore:

* dom/InlineStyleSheetOwner.cpp:
(WebCore::InlineStyleSheetOwner::InlineStyleSheetOwner):
* dom/ScriptElement.cpp:
(WebCore::ScriptElement::ScriptElement):
* dom/ScriptableDocumentParser.h:
* dom/StyledElement.cpp:
(WebCore::StyledElement::styleAttributeChanged):
* html/parser/HTMLDocumentParser.cpp:
(WebCore::HTMLDocumentParser::didReceiveParsedChunkFromBackgroundParser):
(WebCore::HTMLDocumentParser::pumpPendingSpeculations):
* html/parser/HTMLDocumentParser.h:
* inspector/InspectorResourceAgent.cpp:
(WebCore::InspectorResourceAgent::buildInitiatorObject):
* page/Console.cpp:
(WebCore::internalAddMessage):
* page/PageConsole.cpp:
(WebCore::PageConsole::printSourceURLAndPosition):
(WebCore::PageConsole::addMessage):
* page/PageConsole.h:
* xml/parser/XMLDocumentParser.h:
* xml/parser/XMLDocumentParserLibxml2.cpp:
(WebCore::XMLDocumentParser::error):

LayoutTests:

* inspector-protocol/page/deny-X-FrameOption-expected.txt: Added.
* inspector-protocol/page/deny-X-FrameOption.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@160374 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 382b8825
2013-12-10 László Langó <lango@inf.u-szeged.hu>
PageConsole::addMessage should automatically determine column number alongside line number
https://bugs.webkit.org/show_bug.cgi?id=114319
Reviewed by Joseph Pecoraro.
* inspector-protocol/page/deny-X-FrameOption-expected.txt: Added.
* inspector-protocol/page/deny-X-FrameOption.html: Added.
2013-12-10 Michał Pakuła vel Rutka <m.pakula@samsung.com>
Unreviewed EFL gardening
CONSOLE MESSAGE: Refused to display 'deny-X-FrameOption.html' in a frame because it set 'X-Frame-Options' to 'deny'.
deny-X-FrameOption.html:0:0
<html>
<head>
<script type="text/javascript" src="../../http/tests/inspector-protocol/resources/protocol-test.js"></script>
<script>
function test()
{
InspectorTest.importScript("../../../../inspector-protocol/resources/console-helper.js");
InspectorTest.sendCommand("Console.enable", {});
InspectorTest.eventHandler["Console.messageAdded"] = function(messageObject)
{
var simplifiedMessage = ConsoleHelper.simplifiedConsoleMessage(messageObject);
// FIXME The line and column values will be zeros until this fix:
// https://bugs.webkit.org/show_bug.cgi?id=125340
// After this probably we should update the expected.txt.
InspectorTest.log(simplifiedMessage.location);
InspectorTest.completeTest();
}
}
</script>
</head>
<body onload="runTest()">
<iframe id=foo></iframe>
<script>
var fooFrame = document.getElementById('foo');
var fooDoc = fooFrame.contentWindow.document;
fooDoc.write('<meta http-equiv="X-Frame-Options" content="deny"/>');
</script>
</body>
</html>
2013-12-10 László Langó <lango@inf.u-szeged.hu>
PageConsole::addMessage should automatically determine column number alongside line number
https://bugs.webkit.org/show_bug.cgi?id=114319
Reviewed by Joseph Pecoraro.
* dom/InlineStyleSheetOwner.cpp:
(WebCore::InlineStyleSheetOwner::InlineStyleSheetOwner):
* dom/ScriptElement.cpp:
(WebCore::ScriptElement::ScriptElement):
* dom/ScriptableDocumentParser.h:
* dom/StyledElement.cpp:
(WebCore::StyledElement::styleAttributeChanged):
* html/parser/HTMLDocumentParser.cpp:
(WebCore::HTMLDocumentParser::didReceiveParsedChunkFromBackgroundParser):
(WebCore::HTMLDocumentParser::pumpPendingSpeculations):
* html/parser/HTMLDocumentParser.h:
* inspector/InspectorResourceAgent.cpp:
(WebCore::InspectorResourceAgent::buildInitiatorObject):
* page/Console.cpp:
(WebCore::internalAddMessage):
* page/PageConsole.cpp:
(WebCore::PageConsole::printSourceURLAndPosition):
(WebCore::PageConsole::addMessage):
* page/PageConsole.h:
* xml/parser/XMLDocumentParser.h:
* xml/parser/XMLDocumentParserLibxml2.cpp:
(WebCore::XMLDocumentParser::error):
2013-12-10 Andreas Kling <akling@apple.com>
Jettison all StyleResolver data on memory pressure.
......@@ -38,7 +38,7 @@ InlineStyleSheetOwner::InlineStyleSheetOwner(Document& document, bool createdByP
, m_startLineNumber(WTF::OrdinalNumber::beforeFirst())
{
if (createdByParser && document.scriptableDocumentParser() && !document.isInDocumentWrite())
m_startLineNumber = document.scriptableDocumentParser()->lineNumber();
m_startLineNumber = document.scriptableDocumentParser()->textPosition().m_line;
}
InlineStyleSheetOwner::~InlineStyleSheetOwner()
......
......@@ -75,7 +75,7 @@ ScriptElement::ScriptElement(Element* element, bool parserInserted, bool already
{
ASSERT(m_element);
if (parserInserted && m_element->document().scriptableDocumentParser() && !m_element->document().isInDocumentWrite())
m_startLineNumber = m_element->document().scriptableDocumentParser()->lineNumber();
m_startLineNumber = m_element->document().scriptableDocumentParser()->textPosition().m_line;
}
ScriptElement::~ScriptElement()
......
......@@ -44,8 +44,6 @@ public:
virtual bool isWaitingForScripts() const = 0;
// These are used to expose the current line/column to the scripting system.
virtual OrdinalNumber lineNumber() const = 0;
virtual TextPosition textPosition() const = 0;
void setWasCreatedByScript(bool wasCreatedByScript) { m_wasCreatedByScript = wasCreatedByScript; }
......
......@@ -195,7 +195,7 @@ void StyledElement::styleAttributeChanged(const AtomicString& newStyleString, At
{
WTF::OrdinalNumber startLineNumber = WTF::OrdinalNumber::beforeFirst();
if (document().scriptableDocumentParser() && !document().isInDocumentWrite())
startLineNumber = document().scriptableDocumentParser()->lineNumber();
startLineNumber = document().scriptableDocumentParser()->textPosition().m_line;
if (newStyleString.isNull()) {
if (PropertySetCSSStyleDeclaration* cssomWrapper = inlineStyleCSSOMWrapper())
......
......@@ -314,13 +314,13 @@ void HTMLDocumentParser::didReceiveParsedChunkFromBackgroundParser(OwnPtr<Parsed
// but we need to ensure it isn't deleted yet.
Ref<HTMLDocumentParser> protect(*this);
InspectorInstrumentationCookie cookie = InspectorInstrumentation::willWriteHTML(document(), lineNumber().zeroBasedInt());
InspectorInstrumentationCookie cookie = InspectorInstrumentation::willWriteHTML(document(), textPosition().m_line.zeroBasedInt());
ASSERT(m_speculations.isEmpty());
chunk->preloads.clear(); // We don't need to preload because we're going to parse immediately.
processParsedChunkFromBackgroundParser(chunk);
InspectorInstrumentation::didWriteHTML(cookie, lineNumber().zeroBasedInt());
InspectorInstrumentation::didWriteHTML(cookie, textPosition().m_line.zeroBasedInt());
}
void HTMLDocumentParser::validateSpeculations(OwnPtr<ParsedChunk> chunk)
......@@ -458,7 +458,7 @@ void HTMLDocumentParser::pumpPendingSpeculations()
ASSERT(!m_lastChunkBeforeScript);
// FIXME: Pass in current input length.
InspectorInstrumentationCookie cookie = InspectorInstrumentation::willWriteHTML(document(), lineNumber().zeroBasedInt());
InspectorInstrumentationCookie cookie = InspectorInstrumentation::willWriteHTML(document(), textPosition().m_line.zeroBasedInt());
double startTime = monotonicallyIncreasingTime();
......@@ -474,7 +474,7 @@ void HTMLDocumentParser::pumpPendingSpeculations()
}
}
InspectorInstrumentation::didWriteHTML(cookie, lineNumber().zeroBasedInt());
InspectorInstrumentation::didWriteHTML(cookie, textPosition().m_line.zeroBasedInt());
}
#endif // ENABLE(THREADED_HTML_PARSER)
......@@ -828,16 +828,6 @@ bool HTMLDocumentParser::isExecutingScript() const
return m_scriptRunner->isExecutingScript();
}
OrdinalNumber HTMLDocumentParser::lineNumber() const
{
#if ENABLE(THREADED_HTML_PARSER)
if (m_haveBackgroundParser)
return m_textPosition.m_line;
#endif
return m_input.current().currentLine();
}
TextPosition HTMLDocumentParser::textPosition() const
{
#if ENABLE(THREADED_HTML_PARSER)
......
......@@ -80,7 +80,6 @@ public:
HTMLTokenizer* tokenizer() const { return m_tokenizer.get(); }
virtual TextPosition textPosition() const;
virtual OrdinalNumber lineNumber() const;
virtual void suspendScheduledTasks();
virtual void resumeScheduledTasks();
......
......@@ -454,7 +454,7 @@ PassRefPtr<TypeBuilder::Network::Initiator> InspectorResourceAgent::buildInitiat
RefPtr<TypeBuilder::Network::Initiator> initiatorObject = TypeBuilder::Network::Initiator::create()
.setType(TypeBuilder::Network::Initiator::Type::Parser);
initiatorObject->setUrl(document->url().string());
initiatorObject->setLineNumber(document->scriptableDocumentParser()->lineNumber().oneBasedInt());
initiatorObject->setLineNumber(document->scriptableDocumentParser()->textPosition().m_line.oneBasedInt());
return initiatorObject;
}
......
......@@ -92,7 +92,7 @@ static void internalAddMessage(Page* page, MessageType type, MessageLevel level,
if (!page->settings().logsPageMessagesToSystemConsoleEnabled() && !PageConsole::shouldPrintExceptions())
return;
PageConsole::printSourceURLAndLine(lastCaller.sourceURL(), lastCaller.lineNumber());
PageConsole::printSourceURLAndPosition(lastCaller.sourceURL(), lastCaller.lineNumber());
PageConsole::printMessageSourceAndLevelPrefix(ConsoleAPIMessageSource, level);
for (size_t i = 0; i < arguments->argumentCount(); ++i) {
......
......@@ -64,11 +64,11 @@ PageConsole::~PageConsole()
{
}
void PageConsole::printSourceURLAndLine(const String& sourceURL, unsigned lineNumber)
void PageConsole::printSourceURLAndPosition(const String& sourceURL, unsigned lineNumber, unsigned columnNumber)
{
if (!sourceURL.isEmpty()) {
if (lineNumber > 0)
printf("%s:%d: ", sourceURL.utf8().data(), lineNumber);
if (lineNumber > 0 && columnNumber > 0)
printf("%s:%u:%u: ", sourceURL.utf8().data(), lineNumber, columnNumber);
else
printf("%s: ", sourceURL.utf8().data());
}
......@@ -142,18 +142,22 @@ void PageConsole::addMessage(MessageSource source, MessageLevel level, const Str
String url;
if (document)
url = document->url().string();
// FIXME: <http://webkit.org/b/114319> PageConsole::addMessage should automatically determine column number alongside line number.
// FIXME: The below code attempts to determine line numbers for parser generated errors, but this is not the only reason why we can get here.
// For example, if we are still parsing and get a WebSocket network error, it will be erroneously attributed to a line where parsing was paused.
// Also, we should determine line numbers for script generated messages (e.g. calling getImageData on a canvas).
// We probably need to split this function into multiple ones, as appropriate for different call sites. Or maybe decide based on MessageSource.
// https://bugs.webkit.org/show_bug.cgi?id=125340
unsigned line = 0;
unsigned column = 0;
if (document && document->parsing() && !document->isInDocumentWrite() && document->scriptableDocumentParser()) {
ScriptableDocumentParser* parser = document->scriptableDocumentParser();
if (!parser->isWaitingForScripts() && !JSMainThreadExecState::currentState())
line = parser->lineNumber().oneBasedInt();
if (!parser->isWaitingForScripts() && !JSMainThreadExecState::currentState()) {
TextPosition position = parser->textPosition();
line = position.m_line.oneBasedInt();
column = position.m_column.oneBasedInt();
}
}
addMessage(source, level, message, url, line, 0, 0, 0, requestIdentifier);
addMessage(source, level, message, url, line, column, 0, 0, requestIdentifier);
}
void PageConsole::addMessage(MessageSource source, MessageLevel level, const String& message, PassRefPtr<ScriptCallStack> callStack)
......@@ -182,7 +186,7 @@ void PageConsole::addMessage(MessageSource source, MessageLevel level, const Str
if (!m_page.settings().logsPageMessagesToSystemConsoleEnabled() && !shouldPrintExceptions())
return;
printSourceURLAndLine(url, lineNumber);
printSourceURLAndPosition(url, lineNumber, columnNumber);
printMessageSourceAndLevelPrefix(source, level);
printf(" %s\n", message.utf8().data());
......
......@@ -48,7 +48,7 @@ public:
PageConsole(Page&);
~PageConsole();
static void printSourceURLAndLine(const String& sourceURL, unsigned lineNumber);
static void printSourceURLAndPosition(const String& sourceURL, unsigned lineNumber, unsigned columnNumber = 0);
static void printMessageSourceAndLevelPrefix(MessageSource, MessageLevel);
void addMessage(MessageSource, MessageLevel, const String& message, const String& sourceURL, unsigned lineNumber, unsigned columnNumber, PassRefPtr<ScriptCallStack> = 0, JSC::ExecState* = 0, unsigned long requestIdentifier = 0);
......
......@@ -105,8 +105,6 @@ class Text;
virtual bool isWaitingForScripts() const;
virtual void stopParsing();
virtual void detach();
virtual OrdinalNumber lineNumber() const;
OrdinalNumber columnNumber() const;
// from CachedResourceClient
virtual void notifyFinished(CachedResource*);
......
......@@ -972,8 +972,9 @@ void XMLDocumentParser::error(XMLErrors::ErrorType type, const char* message, va
vsnprintf(m, sizeof(m) - 1, message, args);
#endif
TextPosition position = textPosition();
if (m_parserPaused)
m_pendingCallbacks->appendErrorCallback(type, reinterpret_cast<const xmlChar*>(m), lineNumber(), columnNumber());
m_pendingCallbacks->appendErrorCallback(type, reinterpret_cast<const xmlChar*>(m), position.m_line, position.m_column);
else
handleError(type, m, textPosition());
......@@ -1426,16 +1427,6 @@ void* xmlDocPtrForString(CachedResourceLoader* cachedResourceLoader, const Strin
}
#endif
OrdinalNumber XMLDocumentParser::lineNumber() const
{
return OrdinalNumber::fromOneBasedInt(context() ? context()->input->line : 1);
}
OrdinalNumber XMLDocumentParser::columnNumber() const
{
return OrdinalNumber::fromOneBasedInt(context() ? context()->input->col : 1);
}
TextPosition XMLDocumentParser::textPosition() const
{
xmlParserCtxtPtr context = this->context();
......
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