// Copyright 2016 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_INSPECTOR_THREAD_DEBUGGER_H_ #define THIRD_PARTY_BLINK_RENDERER_CORE_INSPECTOR_THREAD_DEBUGGER_H_ #include #include "base/macros.h" #include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/dom/user_gesture_indicator.h" #include "third_party/blink/renderer/core/inspector/console_types.h" #include "third_party/blink/renderer/platform/bindings/v8_per_isolate_data.h" #include "third_party/blink/renderer/platform/timer.h" #include "third_party/blink/renderer/platform/wtf/forward.h" #include "third_party/blink/renderer/platform/wtf/vector.h" #include "v8/include/v8-inspector.h" #include "v8/include/v8-profiler.h" #include "v8/include/v8.h" namespace blink { class ExecutionContext; class SourceLocation; class CORE_EXPORT ThreadDebugger : public v8_inspector::V8InspectorClient, public V8PerIsolateData::Data { public: explicit ThreadDebugger(v8::Isolate*); ~ThreadDebugger() override; static ThreadDebugger* From(v8::Isolate*); virtual bool IsWorker() = 0; v8_inspector::V8Inspector* GetV8Inspector() const { return v8_inspector_.get(); } static void IdleStarted(v8::Isolate*); static void IdleFinished(v8::Isolate*); void AsyncTaskScheduled(const StringView& task_name, void* task, bool recurring); void AsyncTaskCanceled(void* task); void AllAsyncTasksCanceled(); void AsyncTaskStarted(void* task); void AsyncTaskFinished(void* task); unsigned PromiseRejected(v8::Local, const String& error_message, v8::Local exception, std::unique_ptr); void PromiseRejectionRevoked(v8::Local, unsigned promise_rejection_id); v8_inspector::V8StackTraceId StoreCurrentStackTrace( const StringView& description); void ExternalAsyncTaskStarted(const v8_inspector::V8StackTraceId& parent); void ExternalAsyncTaskFinished(const v8_inspector::V8StackTraceId& parent); protected: virtual int ContextGroupId(ExecutionContext*) = 0; virtual void ReportConsoleMessage(ExecutionContext*, MessageSource, MessageLevel, const String& message, SourceLocation*) = 0; void installAdditionalCommandLineAPI(v8::Local, v8::Local) override; void CreateFunctionProperty(v8::Local, v8::Local, const char* name, v8::FunctionCallback, const char* description); static v8::Maybe CreateDataPropertyInArray(v8::Local, v8::Local, int index, v8::Local); static MessageLevel V8MessageLevelToMessageLevel( v8::Isolate::MessageErrorLevel); v8::Isolate* isolate_; private: // V8InspectorClient implementation. void beginUserGesture() override; void endUserGesture() override; std::unique_ptr valueSubtype( v8::Local) override; bool formatAccessorsAsProperties(v8::Local) override; double currentTimeMS() override; bool isInspectableHeapObject(v8::Local) override; void consoleTime(const v8_inspector::StringView& title) override; void consoleTimeEnd(const v8_inspector::StringView& title) override; void consoleTimeStamp(const v8_inspector::StringView& title) override; void startRepeatingTimer(double, v8_inspector::V8InspectorClient::TimerCallback, void* data) override; void cancelTimer(void* data) override; void OnTimer(TimerBase*); static void SetMonitorEventsCallback( const v8::FunctionCallbackInfo&, bool enabled); static void MonitorEventsCallback(const v8::FunctionCallbackInfo&); static void UnmonitorEventsCallback( const v8::FunctionCallbackInfo&); static void GetEventListenersCallback( const v8::FunctionCallbackInfo&); std::unique_ptr v8_inspector_; std::unique_ptr v8_tracing_cpu_profiler_; Vector>> timers_; Vector timer_callbacks_; Vector timer_data_; std::unique_ptr user_gesture_indicator_; DISALLOW_COPY_AND_ASSIGN(ThreadDebugger); }; template <> struct CrossThreadCopier { typedef v8_inspector::V8StackTraceId Type; static Type Copy(const Type& id) { return id; } }; } // namespace blink #endif // THIRD_PARTY_BLINK_RENDERER_CORE_INSPECTOR_THREAD_DEBUGGER_H_