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 "include/v8-inspector.h" | 8 #include "include/v8-inspector.h" |
9 #include "include/v8.h" | 9 #include "include/v8.h" |
10 #include "src/base/macros.h" | 10 #include "src/base/macros.h" |
11 #include "src/base/platform/platform.h" | 11 #include "src/base/platform/platform.h" |
12 #include "test/inspector/task-runner.h" | 12 #include "test/inspector/task-runner.h" |
13 | 13 |
14 class InspectorClientImpl : public v8_inspector::V8InspectorClient { | 14 class InspectorClientImpl : public v8_inspector::V8InspectorClient { |
15 public: | 15 public: |
16 class FrontendChannel { | 16 class FrontendChannel { |
17 public: | 17 public: |
18 virtual ~FrontendChannel() = default; | 18 virtual ~FrontendChannel() = default; |
19 virtual void SendMessageToFrontend( | 19 virtual void SendMessageToFrontend( |
20 const v8_inspector::StringView& message) = 0; | 20 const v8_inspector::StringView& message) = 0; |
21 }; | 21 }; |
22 | 22 |
23 InspectorClientImpl(TaskRunner* task_runner, | 23 InspectorClientImpl(TaskRunner* task_runner, |
24 FrontendChannel* frontend_channel, | 24 FrontendChannel* frontend_channel, |
25 v8::base::Semaphore* ready_semaphore); | 25 v8::base::Semaphore* ready_semaphore); |
26 virtual ~InspectorClientImpl(); | 26 virtual ~InspectorClientImpl(); |
27 | 27 |
28 void scheduleReconnect(v8::base::Semaphore* ready_semaphore); | 28 void scheduleReconnect(v8::base::Semaphore* ready_semaphore); |
29 void scheduleCreateContextGroup(v8::ExtensionConfiguration* extensions, | 29 void scheduleCreateContextGroup( |
30 v8::base::Semaphore* ready_semaphore, | 30 TaskRunner::SetupGlobalTasks setup_global_tasks, |
31 int* context_group_id); | 31 v8::base::Semaphore* ready_semaphore, int* context_group_id); |
32 | 32 |
33 static v8_inspector::V8Inspector* InspectorFromContext( | 33 static v8_inspector::V8Inspector* InspectorFromContext( |
34 v8::Local<v8::Context> context); | 34 v8::Local<v8::Context> context); |
35 static v8_inspector::V8InspectorSession* SessionFromContext( | 35 static v8_inspector::V8InspectorSession* SessionFromContext( |
36 v8::Local<v8::Context> context); | 36 v8::Local<v8::Context> context); |
37 | 37 |
38 // context_group_id = 0 means default context group. | 38 // context_group_id = 0 means default context group. |
39 v8_inspector::V8InspectorSession* session(int context_group_id = 0); | 39 v8_inspector::V8InspectorSession* session(int context_group_id = 0); |
40 | 40 |
41 void setCurrentTimeMSForTest(double time); | 41 void setCurrentTimeMSForTest(double time); |
(...skipping 16 matching lines...) Expand all Loading... |
58 const v8_inspector::StringView& url, | 58 const v8_inspector::StringView& url, |
59 unsigned lineNumber, unsigned columnNumber, | 59 unsigned lineNumber, unsigned columnNumber, |
60 v8_inspector::V8StackTrace*) override; | 60 v8_inspector::V8StackTrace*) override; |
61 friend class SendMessageToBackendTask; | 61 friend class SendMessageToBackendTask; |
62 | 62 |
63 friend class ConnectTask; | 63 friend class ConnectTask; |
64 void connect(v8::Local<v8::Context> context); | 64 void connect(v8::Local<v8::Context> context); |
65 friend class DisconnectTask; | 65 friend class DisconnectTask; |
66 void disconnect(); | 66 void disconnect(); |
67 friend class CreateContextGroupTask; | 67 friend class CreateContextGroupTask; |
68 int createContextGroup(v8::ExtensionConfiguration* extensions); | 68 int createContextGroup( |
| 69 const TaskRunner::SetupGlobalTasks& setup_global_tasks); |
69 | 70 |
70 std::unique_ptr<v8_inspector::V8Inspector> inspector_; | 71 std::unique_ptr<v8_inspector::V8Inspector> inspector_; |
71 std::unique_ptr<v8_inspector::V8Inspector::Channel> channel_; | 72 std::unique_ptr<v8_inspector::V8Inspector::Channel> channel_; |
72 | 73 |
73 std::map<int, std::unique_ptr<v8_inspector::V8InspectorSession>> sessions_; | 74 std::map<int, std::unique_ptr<v8_inspector::V8InspectorSession>> sessions_; |
74 std::map<int, std::unique_ptr<v8_inspector::StringBuffer>> states_; | 75 std::map<int, std::unique_ptr<v8_inspector::StringBuffer>> states_; |
75 | 76 |
76 v8::Isolate* isolate_; | 77 v8::Isolate* isolate_; |
77 v8::Global<v8::Value> memory_info_; | 78 v8::Global<v8::Value> memory_info_; |
78 | 79 |
79 TaskRunner* task_runner_; | 80 TaskRunner* task_runner_; |
80 FrontendChannel* frontend_channel_; | 81 FrontendChannel* frontend_channel_; |
81 | 82 |
82 bool current_time_set_for_test_ = false; | 83 bool current_time_set_for_test_ = false; |
83 double current_time_ = 0.0; | 84 double current_time_ = 0.0; |
84 bool log_console_api_message_calls_ = false; | 85 bool log_console_api_message_calls_ = false; |
85 | 86 |
86 DISALLOW_COPY_AND_ASSIGN(InspectorClientImpl); | 87 DISALLOW_COPY_AND_ASSIGN(InspectorClientImpl); |
87 }; | 88 }; |
88 | 89 |
89 class SendMessageToBackendExtension : public v8::Extension { | 90 class SendMessageToBackendExtension : public TaskRunner::SetupGlobalTask { |
90 public: | 91 public: |
91 SendMessageToBackendExtension() | 92 void Run(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> global) override; |
92 : v8::Extension("v8_inspector/frontend", | |
93 "native function sendMessageToBackend();") {} | |
94 virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate( | |
95 v8::Isolate* isolate, v8::Local<v8::String> name); | |
96 | 93 |
97 static void set_backend_task_runner(TaskRunner* task_runner) { | 94 static void set_backend_task_runner(TaskRunner* task_runner) { |
98 backend_task_runner_ = task_runner; | 95 backend_task_runner_ = task_runner; |
99 } | 96 } |
100 | 97 |
101 private: | 98 private: |
102 static void SendMessageToBackend( | 99 static void SendMessageToBackend( |
103 const v8::FunctionCallbackInfo<v8::Value>& args); | 100 const v8::FunctionCallbackInfo<v8::Value>& args); |
104 | 101 |
105 static TaskRunner* backend_task_runner_; | 102 static TaskRunner* backend_task_runner_; |
106 }; | 103 }; |
107 | 104 |
108 #endif // V8_TEST_INSPECTOR_PROTOCOL_INSPECTOR_IMPL_H_ | 105 #endif // V8_TEST_INSPECTOR_PROTOCOL_INSPECTOR_IMPL_H_ |
OLD | NEW |