Web Inspector: Autogenerate stack traces and line numbers when possible.
https://bugs.webkit.org/show_bug.cgi?id=100650

Reviewed by Yury Semikhatsky.

Source/WebCore:

Console messages generated in WebCore generally are asked to do a bit of
work in order to provide a developer with a detailed report. We ask the
caller to either generate stack traces, or pass in a url/line number
pair, which can be a bit of work. Predictably, most callers don't pass
in what we'd like to see.

This patch creates a new, simpler console message generation API that we
expect most call sites to use. Source, type, level, and message are
required, and an optional request ID can be passed in. Everything else
will be autogenerated inside ConsoleMessage when appropriate.

In a subsequent patch, we expect to be able to trim down more of the
external call sites (ContentSecurityPolicy springs to mind) in order to
further consolidate the external interface. Simple is good.

* Modules/websockets/WebSocket.cpp:
(WebCore::WebSocket::connect):
* Modules/websockets/WebSocketChannel.cpp:
(WebCore::WebSocketChannel::didFailSocketStream):
    Drop the now-redundant URL parameter from various WebSocket errors.
* css/MediaList.cpp:
(WebCore::addResolutionWarningMessageToConsole):
    Switch to Document::addConsoleMessage, which means that we can move
    line-number generation out of MediaList.
* dom/Document.cpp:
(WebCore::Document::logExceptionToConsole):
    Use the long-form 'addMessage()' rather than the public interface.
(WebCore::Document::processHttpEquiv):
    Drop the URL parameter, as it's now autogenerated.
(WebCore::Document::addConsoleMessage):
(WebCore):
* dom/Document.h:
(Document):
    Override the pure virtual method on ScriptExecutionContext, and pass
    the call through to the new Console::addMessage, which accepts a
    pointer to the Document in order to do line-number generation.
* dom/ScriptExecutionContext.h:
(ScriptExecutionContext):
    Add a pure virtual variant of addConsoleMessage which accepts only
    bare minimum data, and expects autogeneration of the rest.
    Additionally, ensure that the other variants always have either a
    URL/line number, or a stack trace.
* dom/ViewportArguments.cpp:
(WebCore::reportViewportWarning):
    Drop line numbers and URLs from Viewport warnings. We can generate
    these now.
* html/HTMLFormElement.cpp:
(WebCore::HTMLFormElement::validateInteractively):
    Drop the URL from form autofocus warnings
* html/HTMLIFrameElement.cpp:
(WebCore::HTMLIFrameElement::parseAttribute):
    Drop the URL and line from sandbox attribute warnings.
* html/canvas/WebGLRenderingContext.cpp:
(WebCore):
(WebCore::WebGLRenderingContext::printWarningToConsole):
    Drop the URL from WebGL warnings.
* inspector/ConsoleMessage.cpp:
(WebCore::ConsoleMessage::ConsoleMessage):
    Call 'autogenerateMetadata' to ensure that a stack trace is
    generated if one isn't provided. Create a new constructor that
    accepts a ScriptState/ScriptArguments pair, and use it for console
    API calls.
(WebCore):
(WebCore::ConsoleMessage::autogenerateMetadata):
    Generate a stack trace given whatever information we've got.
* inspector/ConsoleMessage.h:
(ConsoleMessage):
    Create a new constructor that accepts a ScriptState/ScriptArguments
    pair, and use it for console API calls.
* inspector/InspectorConsoleAgent.cpp:
(WebCore::InspectorConsoleAgent::enable):
    Use the short-form ConsoleMessage constructor.
(WebCore::InspectorConsoleAgent::addMessageToConsole):
    Use the stack-only constructor, or the ScriptState
    constructor, as appropriate.
(WebCore::InspectorConsoleAgent::count):
    We generated a stack, pass it in.
* inspector/InspectorConsoleAgent.cpp:
(WebCore::InspectorConsoleAgent::isWorkerAgent):
* inspector/PageConsoleAgent.h:
(WebCore::PageConsoleAgent::isWorkerAgent):
* inspector/PageConsoleAgent.h:
(WebCore::PageConsoleAgent::isWorkerAgent):
    We only want to generate call stacks for non-Workers (because
    createScriptCallStack explodes in JSC if we're not on the main
    thread). This method will allow us to distinguish between those
    messages generated from Workers, and those from Pages.
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::shouldInterruptLoadForXFrameOptions):
* loader/MainResourceLoader.cpp:
(WebCore::MainResourceLoader::didReceiveResponse):
    Drop the URL parameter from the console message for X-Frame-Options
    parsing errors.
* page/Console.cpp:
(WebCore::Console::addMessage):
    When given a Document*, generate a line number if: 1) the document
    is still being parsed, 2) the document is not in document.write(),
    3) the parser isn't waiting for script, and 4) the parser isn't
    executing script. Many callsites didn't check all of these, which
    is why the SVG rebaseline (for example) drops lots and lots of line
    numbers which point at a closing '</script>' tag.
(WebCore):
* page/Console.h:
(WebCore):
(Console):
    Update the public API to accept a Document* and little else.
* page/DOMWindow.cpp:
(WebCore::DOMWindow::printErrorMessage):
    Don't generate a stack here. We can do it later.
* svg/SVGDocumentExtensions.cpp:
(WebCore::reportMessage):
    Drop the URL and line number. We'll generate them. It'll be sweet.
* workers/WorkerContext.cpp:
(WebCore::WorkerContext::addConsoleMessage):
(WebCore):
* workers/WorkerContext.h:
(WorkerContext):
    Implement the new addConsoleMessage variant.

LayoutTests:

New line numbers! Huzzah! (Also, removing some that shouldn't be there).

* http/tests/inspector/console-xhr-logging-expected.txt:
* platform/chromium/http/tests/inspector/console-xhr-logging-expected.txt:
    One new stack trace! OMG!
* fast/frames/sandboxed-iframe-autofocus-denied-expected.txt:
* fast/frames/sandboxed-iframe-parsing-space-characters-expected.txt:
* fast/frames/xss-auditor-handles-file-urls-expected.txt:
* html5lib/run-test11-expected.txt:
* http/tests/misc/bubble-drag-events-expected.txt:
* http/tests/misc/drag-over-iframe-invalid-source-crash-expected.txt:
* http/tests/misc/iframe-invalid-source-crash-expected.txt:
* http/tests/misc/image-blocked-src-change-expected.txt:
* http/tests/misc/image-blocked-src-no-change-expected.txt:
* http/tests/security/cross-origin-xsl-BLOCKED-expected.txt:
* http/tests/security/frame-loading-via-document-write-expected.txt:
* http/tests/security/mixedContent/insecure-css-in-iframe-expected.txt:
* http/tests/security/mixedContent/insecure-css-in-main-frame-expected.txt:
* http/tests/security/mixedContent/insecure-image-in-main-frame-expected.txt:
* http/tests/security/xss-DENIED-xml-external-entity-expected.txt:
* http/tests/security/xssAuditor/base-href-control-char-expected.txt:
* http/tests/security/xssAuditor/base-href-expected.txt:
* http/tests/security/xssAuditor/base-href-null-char-expected.txt:
* http/tests/security/xssAuditor/base-href-scheme-relative-expected.txt:
* http/tests/security/xssAuditor/cookie-injection-expected.txt:
* http/tests/security/xssAuditor/embed-tag-code-attribute-2-expected.txt:
* http/tests/security/xssAuditor/embed-tag-code-attribute-expected.txt:
* http/tests/security/xssAuditor/embed-tag-control-char-expected.txt:
* http/tests/security/xssAuditor/embed-tag-expected.txt:
* http/tests/security/xssAuditor/embed-tag-javascript-url-expected.txt:
* http/tests/security/xssAuditor/embed-tag-null-char-expected.txt:
* http/tests/security/xssAuditor/form-action-expected.txt:
* http/tests/security/xssAuditor/full-block-base-href-expected.txt:
* http/tests/security/xssAuditor/full-block-get-from-iframe-expected.txt:
* http/tests/security/xssAuditor/full-block-iframe-javascript-url-expected.txt:
* http/tests/security/xssAuditor/full-block-iframe-no-inherit-expected.txt:
* http/tests/security/xssAuditor/full-block-javascript-link-expected.txt:
* http/tests/security/xssAuditor/full-block-link-onclick-expected.txt:
* http/tests/security/xssAuditor/full-block-object-tag-expected.txt:
* http/tests/security/xssAuditor/full-block-post-from-iframe-expected.txt:
* http/tests/security/xssAuditor/full-block-script-tag-expected.txt:
* http/tests/security/xssAuditor/full-block-script-tag-with-source-expected.txt:
* http/tests/security/xssAuditor/get-from-iframe-expected.txt:
* http/tests/security/xssAuditor/iframe-injection-expected.txt:
* http/tests/security/xssAuditor/iframe-javascript-url-expected.txt:
* http/tests/security/xssAuditor/iframe-javascript-url-more-encoding-expected.txt:
* http/tests/security/xssAuditor/iframe-javascript-url-twice-url-encode-expected.txt:
* http/tests/security/xssAuditor/iframe-javascript-url-twice-url-encode2-expected.txt:
* http/tests/security/xssAuditor/iframe-javascript-url-twice-url-encode3-expected.txt:
* http/tests/security/xssAuditor/iframe-javascript-url-url-encoded-expected.txt:
* http/tests/security/xssAuditor/iframe-onload-GBK-char-expected.txt:
* http/tests/security/xssAuditor/iframe-onload-in-svg-tag-expected.txt:
* http/tests/security/xssAuditor/iframe-srcdoc-expected.txt:
* http/tests/security/xssAuditor/img-onerror-GBK-char-expected.txt:
* http/tests/security/xssAuditor/img-onerror-accented-char-expected.txt:
* http/tests/security/xssAuditor/img-onerror-non-ASCII-char-default-encoding-expected.txt:
* http/tests/security/xssAuditor/img-onerror-non-ASCII-char-expected.txt:
* http/tests/security/xssAuditor/img-onerror-non-ASCII-char2-default-encoding-expected.txt:
* http/tests/security/xssAuditor/img-onerror-non-ASCII-char2-expected.txt:
* http/tests/security/xssAuditor/inline-event-HTML-entities-expected.txt:
* http/tests/security/xssAuditor/javascript-link-HTML-entities-control-char-expected.txt:
* http/tests/security/xssAuditor/javascript-link-HTML-entities-expected.txt:
* http/tests/security/xssAuditor/javascript-link-HTML-entities-named-expected.txt:
* http/tests/security/xssAuditor/javascript-link-HTML-entities-null-char-expected.txt:
* http/tests/security/xssAuditor/javascript-link-ampersand-expected.txt:
* http/tests/security/xssAuditor/javascript-link-control-char-expected.txt:
* http/tests/security/xssAuditor/javascript-link-expected.txt:
* http/tests/security/xssAuditor/javascript-link-null-char-expected.txt:
* http/tests/security/xssAuditor/javascript-link-one-plus-one-expected.txt:
* http/tests/security/xssAuditor/javascript-link-url-encoded-expected.txt:
* http/tests/security/xssAuditor/link-onclick-ampersand-expected.txt:
* http/tests/security/xssAuditor/link-onclick-control-char-expected.txt:
* http/tests/security/xssAuditor/link-onclick-entities-expected.txt:
* http/tests/security/xssAuditor/link-onclick-expected.txt:
* http/tests/security/xssAuditor/link-onclick-null-char-expected.txt:
* http/tests/security/xssAuditor/link-opens-new-window-expected.txt:
* http/tests/security/xssAuditor/malformed-HTML-expected.txt:
* http/tests/security/xssAuditor/malformed-xss-protection-header-1-expected.txt:
* http/tests/security/xssAuditor/malformed-xss-protection-header-2-expected.txt:
* http/tests/security/xssAuditor/malformed-xss-protection-header-3-expected.txt:
* http/tests/security/xssAuditor/malformed-xss-protection-header-4-expected.txt:
* http/tests/security/xssAuditor/malformed-xss-protection-header-5-expected.txt:
* http/tests/security/xssAuditor/malformed-xss-protection-header-6-expected.txt:
* http/tests/security/xssAuditor/malformed-xss-protection-header-7-expected.txt:
* http/tests/security/xssAuditor/malformed-xss-protection-header-8-expected.txt:
* http/tests/security/xssAuditor/malformed-xss-protection-header-9-expected.txt:
* http/tests/security/xssAuditor/meta-tag-http-refresh-javascript-url-expected.txt:
* http/tests/security/xssAuditor/object-embed-tag-control-char-expected.txt:
* http/tests/security/xssAuditor/object-embed-tag-expected.txt:
* http/tests/security/xssAuditor/object-embed-tag-null-char-expected.txt:
* http/tests/security/xssAuditor/object-tag-expected.txt:
* http/tests/security/xssAuditor/object-tag-javascript-url-expected.txt:
* http/tests/security/xssAuditor/open-attribute-body-expected.txt:
* http/tests/security/xssAuditor/open-event-handler-iframe-expected.txt:
* http/tests/security/xssAuditor/open-iframe-src-expected.txt:
* http/tests/security/xssAuditor/open-script-src-expected.txt:
* http/tests/security/xssAuditor/post-from-iframe-expected.txt:
* http/tests/security/xssAuditor/property-escape-comment-expected.txt:
* http/tests/security/xssAuditor/property-escape-entity-expected.txt:
* http/tests/security/xssAuditor/property-escape-expected.txt:
* http/tests/security/xssAuditor/property-escape-long-expected.txt:
* http/tests/security/xssAuditor/property-escape-quote-expected.txt:
* http/tests/security/xssAuditor/report-script-tag-expected.txt:
* http/tests/security/xssAuditor/script-tag-Big5-char-expected.txt:
* http/tests/security/xssAuditor/script-tag-Big5-char-twice-url-encode-16bit-unicode-expected.txt:
* http/tests/security/xssAuditor/script-tag-Big5-char-twice-url-encode-expected.txt:
* http/tests/security/xssAuditor/script-tag-Big5-char2-expected.txt:
* http/tests/security/xssAuditor/script-tag-addslashes-backslash-expected.txt:
* http/tests/security/xssAuditor/script-tag-addslashes-double-quote-expected.txt:
* http/tests/security/xssAuditor/script-tag-addslashes-null-char-expected.txt:
* http/tests/security/xssAuditor/script-tag-addslashes-single-quote-expected.txt:
* http/tests/security/xssAuditor/script-tag-control-char-expected.txt:
* http/tests/security/xssAuditor/script-tag-convoluted-expected.txt:
* http/tests/security/xssAuditor/script-tag-entities-expected.txt:
* http/tests/security/xssAuditor/script-tag-expected.txt:
* http/tests/security/xssAuditor/script-tag-inside-svg-tag-expected.txt:
* http/tests/security/xssAuditor/script-tag-inside-svg-tag2-expected.txt:
* http/tests/security/xssAuditor/script-tag-inside-svg-tag3-expected.txt:
* http/tests/security/xssAuditor/script-tag-null-char-expected.txt:
* http/tests/security/xssAuditor/script-tag-open-redirect-expected.txt:
* http/tests/security/xssAuditor/script-tag-post-control-char-expected.txt:
* http/tests/security/xssAuditor/script-tag-post-expected.txt:
* http/tests/security/xssAuditor/script-tag-post-null-char-expected.txt:
* http/tests/security/xssAuditor/script-tag-redirect-expected.txt:
* http/tests/security/xssAuditor/script-tag-with-16bit-unicode-expected.txt:
* http/tests/security/xssAuditor/script-tag-with-16bit-unicode-surrogate-pair-expected.txt:
* http/tests/security/xssAuditor/script-tag-with-16bit-unicode2-expected.txt:
* http/tests/security/xssAuditor/script-tag-with-16bit-unicode3-expected.txt:
* http/tests/security/xssAuditor/script-tag-with-16bit-unicode4-expected.txt:
* http/tests/security/xssAuditor/script-tag-with-16bit-unicode5-expected.txt:
* http/tests/security/xssAuditor/script-tag-with-actual-comma-expected.txt:
* http/tests/security/xssAuditor/script-tag-with-callbacks-expected.txt:
* http/tests/security/xssAuditor/script-tag-with-comma-expected.txt:
* http/tests/security/xssAuditor/script-tag-with-fancy-unicode-expected.txt:
* http/tests/security/xssAuditor/script-tag-with-invalid-closing-tag-expected.txt:
* http/tests/security/xssAuditor/script-tag-with-invalid-url-encoding-expected.txt:
* http/tests/security/xssAuditor/script-tag-with-source-control-char-expected.txt:
* http/tests/security/xssAuditor/script-tag-with-source-data-url-expected.txt:
* http/tests/security/xssAuditor/script-tag-with-source-data-url2-expected.txt:
* http/tests/security/xssAuditor/script-tag-with-source-data-url3-expected.txt:
* http/tests/security/xssAuditor/script-tag-with-source-double-quote-expected.txt:
* http/tests/security/xssAuditor/script-tag-with-source-entities-expected.txt:
* http/tests/security/xssAuditor/script-tag-with-source-expected.txt:
* http/tests/security/xssAuditor/script-tag-with-source-no-quote-expected.txt:
* http/tests/security/xssAuditor/script-tag-with-source-null-char-expected.txt:
* http/tests/security/xssAuditor/script-tag-with-source-relative-scheme-expected.txt:
* http/tests/security/xssAuditor/script-tag-with-source-same-host-with-query-expected.txt:
* http/tests/security/xssAuditor/script-tag-with-source-unterminated-expected.txt:
* http/tests/security/xssAuditor/script-tag-with-three-times-url-encoded-16bit-unicode-expected.txt:
* http/tests/security/xssAuditor/script-tag-with-trailing-comment-U2028-expected.txt:
* http/tests/security/xssAuditor/script-tag-with-trailing-comment-expected.txt:
* http/tests/security/xssAuditor/script-tag-with-trailing-comment2-expected.txt:
* http/tests/security/xssAuditor/script-tag-with-trailing-comment3-expected.txt:
* http/tests/security/xssAuditor/script-tag-with-trailing-comment4-expected.txt:
* http/tests/security/xssAuditor/xss-filter-bypass-big5-expected.txt:
* http/tests/security/xssAuditor/xss-filter-bypass-long-string-expected.txt:
* http/tests/security/xssAuditor/xss-filter-bypass-sjis-expected.txt:
* http/tests/security/xssAuditor/xss-protection-parsing-01-expected.txt:
* http/tests/security/xssAuditor/xss-protection-parsing-02-expected.txt:
* http/tests/security/xssAuditor/xss-protection-parsing-03-expected.txt:
* http/tests/security/xssAuditor/xss-protection-parsing-04-expected.txt:
* platform/chromium-mac/http/tests/security/cross-origin-xsl-BLOCKED-expected.txt:
* platform/chromium/http/tests/misc/bubble-drag-events-expected.txt:
* platform/chromium/http/tests/misc/drag-over-iframe-invalid-source-crash-expected.txt:
* platform/chromium/http/tests/misc/iframe-invalid-source-crash-expected.txt:
* platform/chromium/http/tests/security/mixedContent/insecure-image-in-main-frame-allowed-expected.txt:
* platform/chromium/http/tests/security/mixedContent/insecure-image-in-main-frame-blocked-expected.txt:
* platform/chromium/http/tests/security/xssAuditor/javascript-link-control-char2-expected.txt:
* platform/chromium/svg/custom/polyline-setattribute-points-null-expected.txt:
* platform/mac/svg/custom/clip-path-referencing-use2-expected.txt:
* platform/mac/svg/custom/polyline-setattribute-points-null-expected.txt:
* svg/custom/invalid-length-units-expected.txt:
* svg/custom/poly-parsing-error-expected.txt:
* svg/dom/SVGScriptElement/script-onerror-bubbling-expected.txt:
* svg/dom/fuzz-path-parser-expected.txt:
* svg/dom/path-parser-expected.txt:
* svg/dom/points-parser-expected.txt:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@136657 268f45cc-cd09-0410-ab3c-d52691b4dbfc