Web Inspector: Include ConsoleAgent in Workers - real console.log support
https://bugs.webkit.org/show_bug.cgi?id=163844
<rdar://problem/28903328>

Reviewed by Brian Burg.

LayoutTests/imported/w3c:

* web-platform-tests/fetch/api/policies/csp-blocked-worker-expected.txt:
* web-platform-tests/streams/readable-streams/garbage-collection.https-expected.txt:

Source/JavaScriptCore:

* inspector/protocol/Worker.json:

Source/WebCore:

Test: inspector/worker/console-basic.html

This introduces a real ConsoleAgent in the Worker InspectorController.
We no longer need to pass partial ConsoleMessage objects to be logged
through the Page, we can just send the full ConsoleMessages to a
frontend once it connects to the Worker.

In order to guarantee that the Worker InspectorController is properly
all Workers will start paused if there is an Inspector attached to
the Page. The frontend _must_ call the new Worker.initialized method
after sending its setup commands to the Worker. This ensures we get
handle all initialization commands (like Agent.enable(), and
setting state like breakpoints) before any script executes in the
Worker. This mirrors the Inspector.initialized method that does the
same thing for JSContext auto-attach of the Main target.

In the backend, the wait until initialized state is just running
the WorkerThread's RunLoop in a special debugger mode to only process
debugger commands until we are ready. This will effectively be
the same as pausing so it is generalized into WorkerThread.

* CMakeLists.txt:
* WebCore.xcodeproj/project.pbxproj:
* inspector/InspectorAllInOne.cpp:
New files.

* inspector/InspectorWorkerAgent.cpp:
(WebCore::InspectorWorkerAgent::initialized):
(WebCore::InspectorWorkerAgent::shouldWaitForDebuggerOnStart):
* inspector/InspectorWorkerAgent.h:
Add the new initialized method. This just uses the proxy to send
a message to be handled on the Worker Thread and unpause.

* inspector/WorkerConsoleAgent.cpp:
(WebCore::WorkerConsoleAgent::WorkerConsoleAgent):
(WebCore::WorkerConsoleAgent::addInspectedNode):
* inspector/WorkerConsoleAgent.h:
* inspector/WorkerInspectorController.cpp:
(WebCore::WorkerInspectorController::WorkerInspectorController):
Add a ConsoleAgent to WorkerInspectorController.

* workers/WorkerInspectorProxy.h:
* workers/WorkerInspectorProxy.cpp:
(WebCore::WorkerInspectorProxy::workerStartMode):
(WebCore::WorkerInspectorProxy::resumeWorkerIfPaused):
(WebCore::WorkerInspectorProxy::connectToWorkerInspector):
(WebCore::WorkerInspectorProxy::disconnectFromWorkerInspector):
(WebCore::WorkerInspectorProxy::sendMessageToWorkerInspector):
Use the debugger mode when sending messages to the WorkerThread.

* workers/Worker.cpp:
(WebCore::Worker::notifyFinished):
* workers/WorkerMessagingProxy.cpp:
(WebCore::WorkerMessagingProxy::startWorkerGlobalScope):
(WebCore::WorkerMessagingProxy::postConsoleMessageToWorkerObject): Deleted.
* workers/WorkerMessagingProxy.h:
* workers/WorkerReportingProxy.h:
* workers/WorkerGlobalScope.cpp:
(WebCore::WorkerGlobalScope::addConsoleMessage):
(WebCore::WorkerGlobalScope::addMessage):
* workers/WorkerGlobalScope.h:
* workers/WorkerGlobalScopeProxy.h:
Remove legacy partial console support.

* workers/WorkerRunLoop.h:
* workers/WorkerRunLoop.cpp:
(WebCore::WorkerRunLoop::debuggerMode):
* workers/WorkerThread.h:
* workers/WorkerThread.cpp:
(WebCore::WorkerThread::workerThread):
(WebCore::WorkerThread::startRunningDebuggerTasks):
(WebCore::WorkerThread::stopRunningDebuggerTasks):
General code for spinning the WorkerThread and only processing debugger
(Inspector) commands. Use this when starting the thread to ensure the
frontend initializes the Worker's Agents before any JavaScript executes.

* page/PageConsoleClient.cpp:
* workers/WorkerConsoleClient.cpp:
(WebCore::WorkerConsoleClient::count):
(WebCore::WorkerConsoleClient::time):
(WebCore::WorkerConsoleClient::timeEnd):
* inspector/InspectorConsoleInstrumentation.h: Removed.
* inspector/InspectorInstrumentation.cpp:
(WebCore::InspectorInstrumentation::startConsoleTimingImpl):
(WebCore::InspectorInstrumentation::stopConsoleTimingImpl):
(WebCore::InspectorInstrumentation::shouldWaitForDebuggerOnStartImpl):
* inspector/InspectorInstrumentation.h:
(WebCore::InspectorInstrumentation::shouldWaitForDebuggerOnStart):
(WebCore::InspectorInstrumentation::addMessageToConsole):
(WebCore::InspectorInstrumentation::consoleCount):
(WebCore::InspectorInstrumentation::takeHeapSnapshot):
(WebCore::InspectorInstrumentation::startConsoleTiming):
(WebCore::InspectorInstrumentation::stopConsoleTiming):
(WebCore::InspectorInstrumentation::consoleTimeStamp):
(WebCore::InspectorInstrumentation::startProfiling):
(WebCore::InspectorInstrumentation::stopProfiling):
Implement a few more basic console APIs that required ConsoleAgent.

Source/WebInspectorUI:

* UserInterface/Protocol/Target.js:
(WebInspector.Target.prototype.get ConsoleAgent):
(WebInspector.Target.prototype._initializeNonMainTarget):
* UserInterface/Protocol/Connection.js:
(InspectorBackend.WorkerConnection):
Add ConsoleAgent.

* UserInterface/Controllers/LogManager.js:
(WebInspector.LogManager.prototype.messageWasAdded):
(WebInspector.LogManager.prototype.requestClearMessages):
Handle ConsoleAgent calls with multiple targets.

* UserInterface/Protocol/ConsoleObserver.js:
(WebInspector.ConsoleObserver.prototype.messageAdded):
Dispatch with the target in case we create Model objects.

* UserInterface/Controllers/WorkerManager.js:
(WebInspector.WorkerManager.prototype.workerCreated):
The frontend must now call "initialized" on Workers after
sending our setup messages (enable, set breakpoints, etc).

* UserInterface/Protocol/RemoteObject.js:
(WebInspector.RemoteObject.prototype.get target):
Expose an accessor for tests.

* UserInterface/Protocol/LoggingProtocolTracer.js:
(WebInspector.LoggingProtocolTracer.prototype._processEntry):
Actually output the Exception, useful when debugging failures in tests.

LayoutTests:

* inspector/console/messageAdded-from-worker-expected.txt: Removed.
* inspector/console/messageAdded-from-worker.html: Removed.
* inspector/console/resources/worker-console-log.js: Removed.
Remove the old partial console in Worker test.

* inspector/worker/console-basic-expected.txt: Added.
* inspector/worker/console-basic.html: Added.
* inspector/worker/resources/worker-console.js: Added.
New console in Worker test.

* inspector/worker/worker-create-and-terminate.html:
The frontend must call initialize on Workers, otherwise they
are paused forever.

* http/tests/security/contentSecurityPolicy/worker-blob-inherits-csp-expected.txt:
* http/tests/security/contentSecurityPolicy/worker-blob-inherits-csp-importScripts-block-aborts-all-subsequent-imports-expected.txt:
* http/tests/security/contentSecurityPolicy/worker-connect-src-blocked-expected.txt:
* http/tests/security/contentSecurityPolicy/worker-csp-blocks-xhr-redirect-cross-origin-expected.txt:
* http/tests/security/contentSecurityPolicy/worker-importscripts-blocked-expected.txt:
* http/tests/security/contentSecurityPolicy/worker-multiple-csp-headers-expected.txt:
* http/tests/security/contentSecurityPolicy/worker-set-timeout-blocked-expected.txt:
* http/tests/websocket/tests/hybi/workers/close-expected.txt:
* http/tests/xmlhttprequest/workers/access-control-basic-get-fail-non-simple-expected.txt:
* security/contentSecurityPolicy/worker-inherits-blocks-xhr-expected.txt:
Rebaseline. We no longer send Worker console messages through the Page, and likewise
we don't send them to the WebKit client, so they will no longer appear in test output.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@208010 268f45cc-cd09-0410-ab3c-d52691b4dbfc
62 files changed