OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_TEST_INSPECTOR_PROTOCOL_INSPECTOR_IMPL_H_ | 5 #ifndef V8_TEST_INSPECTOR_PROTOCOL_INSPECTOR_IMPL_H_ |
6 #define V8_TEST_INSPECTOR_PROTOCOL_INSPECTOR_IMPL_H_ | 6 #define V8_TEST_INSPECTOR_PROTOCOL_INSPECTOR_IMPL_H_ |
7 | 7 |
| 8 #include <map> |
| 9 #include <vector> |
| 10 |
8 #include "include/v8-inspector.h" | 11 #include "include/v8-inspector.h" |
9 #include "include/v8.h" | 12 #include "include/v8.h" |
10 #include "src/base/macros.h" | 13 #include "src/base/macros.h" |
11 #include "src/base/platform/platform.h" | 14 #include "src/base/platform/platform.h" |
12 #include "test/inspector/task-runner.h" | 15 |
| 16 class TaskRunner; |
13 | 17 |
14 class InspectorClientImpl : public v8_inspector::V8InspectorClient { | 18 class InspectorClientImpl : public v8_inspector::V8InspectorClient { |
15 public: | 19 public: |
16 class FrontendChannel { | 20 class FrontendChannel { |
17 public: | 21 public: |
18 virtual ~FrontendChannel() = default; | 22 virtual ~FrontendChannel() = default; |
19 virtual void SendMessageToFrontend( | 23 virtual void SendMessageToFrontend( |
20 const v8_inspector::StringView& message) = 0; | 24 int session_id, const v8_inspector::StringView& message) = 0; |
21 }; | 25 }; |
22 | 26 |
23 InspectorClientImpl(TaskRunner* task_runner, | 27 InspectorClientImpl(v8::Isolate* isolate, TaskRunner* task_runner, |
24 FrontendChannel* frontend_channel, | 28 FrontendChannel* frontend_channel); |
25 v8::base::Semaphore* ready_semaphore); | |
26 virtual ~InspectorClientImpl(); | 29 virtual ~InspectorClientImpl(); |
27 | 30 |
28 void scheduleReconnect(v8::base::Semaphore* ready_semaphore); | 31 v8_inspector::V8Inspector* inspector() const { return inspector_.get(); } |
29 void scheduleDisconnect(v8::base::Semaphore* ready_semaphore); | 32 int ConnectSession(int context_group_id, |
30 void scheduleCreateContextGroup( | 33 const v8_inspector::StringView& state); |
31 IsolateData::SetupGlobalTasks setup_global_tasks, | 34 std::unique_ptr<v8_inspector::StringBuffer> DisconnectSession(int session_id); |
32 v8::base::Semaphore* ready_semaphore, int* context_group_id); | 35 void SendMessage(int session_id, const v8_inspector::StringView& message); |
33 | 36 void BreakProgram(int context_group_id, |
34 static v8_inspector::V8Inspector* InspectorFromContext( | 37 const v8_inspector::StringView& reason, |
35 v8::Local<v8::Context> context); | 38 const v8_inspector::StringView& details); |
36 static v8_inspector::V8InspectorSession* SessionFromContext( | 39 void SchedulePauseOnNextStatement(int context_group_id, |
37 v8::Local<v8::Context> context); | 40 const v8_inspector::StringView& reason, |
38 | 41 const v8_inspector::StringView& details); |
39 // context_group_id = 0 means default context group. | 42 void CancelPauseOnNextStatement(int context_group_id); |
40 v8_inspector::V8InspectorSession* session(int context_group_id = 0); | 43 void SetCurrentTimeMSForTest(double time); |
41 | 44 void SetMemoryInfoForTest(v8::Local<v8::Value> memory_info); |
42 void setCurrentTimeMSForTest(double time); | 45 void SetLogConsoleApiMessageCalls(bool log); |
43 void setMemoryInfoForTest(v8::Local<v8::Value> memory_info); | 46 void ContextCreated(v8::Local<v8::Context> context, int context_group_id); |
44 void setLogConsoleApiMessageCalls(bool log); | 47 void ContextDestroyed(v8::Local<v8::Context> context); |
45 | 48 |
46 private: | 49 private: |
47 // V8InspectorClient implementation. | 50 // V8InspectorClient implementation. |
48 bool formatAccessorsAsProperties(v8::Local<v8::Value>) override; | 51 bool formatAccessorsAsProperties(v8::Local<v8::Value>) override; |
49 v8::Local<v8::Context> ensureDefaultContextInGroup( | 52 v8::Local<v8::Context> ensureDefaultContextInGroup( |
50 int context_group_id) override; | 53 int context_group_id) override; |
51 double currentTimeMS() override; | 54 double currentTimeMS() override; |
52 v8::MaybeLocal<v8::Value> memoryInfo(v8::Isolate* isolate, | 55 v8::MaybeLocal<v8::Value> memoryInfo(v8::Isolate* isolate, |
53 v8::Local<v8::Context>) override; | 56 v8::Local<v8::Context>) override; |
54 void runMessageLoopOnPause(int context_group_id) override; | 57 void runMessageLoopOnPause(int context_group_id) override; |
55 void quitMessageLoopOnPause() override; | 58 void quitMessageLoopOnPause() override; |
56 void consoleAPIMessage(int contextGroupId, | 59 void consoleAPIMessage(int contextGroupId, |
57 v8::Isolate::MessageErrorLevel level, | 60 v8::Isolate::MessageErrorLevel level, |
58 const v8_inspector::StringView& message, | 61 const v8_inspector::StringView& message, |
59 const v8_inspector::StringView& url, | 62 const v8_inspector::StringView& url, |
60 unsigned lineNumber, unsigned columnNumber, | 63 unsigned lineNumber, unsigned columnNumber, |
61 v8_inspector::V8StackTrace*) override; | 64 v8_inspector::V8StackTrace*) override; |
62 friend class SendMessageToBackendTask; | |
63 | 65 |
64 friend class ConnectTask; | 66 std::vector<int> GetSessionIds(int context_group_id); |
65 void connect(); | |
66 void ConnectToContextGroup(int context_group_id, | |
67 v8_inspector::StringView state); | |
68 friend class DisconnectTask; | |
69 void disconnect(bool reset_inspector); | |
70 friend class CreateContextGroupTask; | |
71 int createContextGroup( | |
72 const IsolateData::SetupGlobalTasks& setup_global_tasks); | |
73 | 67 |
74 std::unique_ptr<v8_inspector::V8Inspector> inspector_; | 68 std::unique_ptr<v8_inspector::V8Inspector> inspector_; |
75 std::unique_ptr<v8_inspector::V8Inspector::Channel> channel_; | 69 int last_session_id_ = 0; |
76 | |
77 std::map<int, std::unique_ptr<v8_inspector::V8InspectorSession>> sessions_; | 70 std::map<int, std::unique_ptr<v8_inspector::V8InspectorSession>> sessions_; |
78 std::map<int, std::unique_ptr<v8_inspector::StringBuffer>> states_; | 71 std::map<v8_inspector::V8InspectorSession*, int> context_group_by_session_; |
79 | 72 std::map<int, std::unique_ptr<v8_inspector::V8Inspector::Channel>> channels_; |
| 73 TaskRunner* task_runner_; |
80 v8::Isolate* isolate_; | 74 v8::Isolate* isolate_; |
81 v8::Global<v8::Value> memory_info_; | 75 v8::Global<v8::Value> memory_info_; |
82 | |
83 TaskRunner* task_runner_; | |
84 FrontendChannel* frontend_channel_; | 76 FrontendChannel* frontend_channel_; |
85 | |
86 bool current_time_set_for_test_ = false; | 77 bool current_time_set_for_test_ = false; |
87 double current_time_ = 0.0; | 78 double current_time_ = 0.0; |
88 bool log_console_api_message_calls_ = false; | 79 bool log_console_api_message_calls_ = false; |
89 | 80 |
90 DISALLOW_COPY_AND_ASSIGN(InspectorClientImpl); | 81 DISALLOW_COPY_AND_ASSIGN(InspectorClientImpl); |
91 }; | 82 }; |
92 | 83 |
93 class SendMessageToBackendExtension : public IsolateData::SetupGlobalTask { | |
94 public: | |
95 void Run(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> global) override; | |
96 | |
97 static void set_backend_task_runner(TaskRunner* task_runner) { | |
98 backend_task_runner_ = task_runner; | |
99 } | |
100 | |
101 private: | |
102 static void SendMessageToBackend( | |
103 const v8::FunctionCallbackInfo<v8::Value>& args); | |
104 | |
105 static TaskRunner* backend_task_runner_; | |
106 }; | |
107 | |
108 #endif // V8_TEST_INSPECTOR_PROTOCOL_INSPECTOR_IMPL_H_ | 84 #endif // V8_TEST_INSPECTOR_PROTOCOL_INSPECTOR_IMPL_H_ |
OLD | NEW |