1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 #include "core/workers/WorkerInspectorProxy.h"
9 #include "core/dom/CrossThreadTask.h"
10 #include "core/inspector/InspectorInstrumentation.h"
11 #include "core/inspector/InspectorTraceEvents.h"
12 #include "core/inspector/WorkerInspectorController.h"
13 #include "core/workers/WorkerThread.h"
14 #include "platform/TraceEvent.h"
15 #include "platform/weborigin/KURL.h"
19 WorkerInspectorProxy::WorkerInspectorProxy()
20 : m_workerThread(nullptr)
21 , m_executionContext(nullptr)
22 , m_pageInspector(nullptr)
26 PassOwnPtr<WorkerInspectorProxy> WorkerInspectorProxy::create()
28 return adoptPtr(new WorkerInspectorProxy());
31 WorkerInspectorProxy::~WorkerInspectorProxy()
35 void WorkerInspectorProxy::workerThreadCreated(ExecutionContext* context, WorkerThread* workerThread, const KURL& url)
37 m_workerThread = workerThread;
38 m_executionContext = context;
39 InspectorInstrumentation::didStartWorker(context, this, url);
42 void WorkerInspectorProxy::workerThreadTerminated()
45 InspectorInstrumentation::workerTerminated(m_executionContext, this);
46 m_workerThread = nullptr;
47 m_pageInspector = nullptr;
50 static void connectToWorkerGlobalScopeInspectorTask(ExecutionContext* context, bool)
52 toWorkerGlobalScope(context)->workerInspectorController()->connectFrontend();
55 void WorkerInspectorProxy::connectToInspector(WorkerInspectorProxy::PageInspector* pageInspector)
59 ASSERT(!m_pageInspector);
60 m_pageInspector = pageInspector;
61 m_workerThread->postDebuggerTask(createCrossThreadTask(connectToWorkerGlobalScopeInspectorTask, true));
64 static void disconnectFromWorkerGlobalScopeInspectorTask(ExecutionContext* context, bool)
66 toWorkerGlobalScope(context)->workerInspectorController()->disconnectFrontend();
69 void WorkerInspectorProxy::disconnectFromInspector()
71 m_pageInspector = nullptr;
74 m_workerThread->postDebuggerTask(createCrossThreadTask(disconnectFromWorkerGlobalScopeInspectorTask, true));
77 static void dispatchOnInspectorBackendTask(ExecutionContext* context, const String& message)
79 toWorkerGlobalScope(context)->workerInspectorController()->dispatchMessageFromFrontend(message);
82 void WorkerInspectorProxy::sendMessageToInspector(const String& message)
86 m_workerThread->postDebuggerTask(createCrossThreadTask(dispatchOnInspectorBackendTask, String(message)));
87 m_workerThread->interruptAndDispatchInspectorCommands();
90 void WorkerInspectorProxy::writeTimelineStartedEvent(const String& sessionId)
94 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "TracingSessionIdForWorker", "data", InspectorTracingSessionIdForWorkerEvent::data(sessionId, m_workerThread));