OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef V8_TEST_INSPECTOR_PROTOCOL_INSPECTOR_IMPL_H_ | |
6 #define V8_TEST_INSPECTOR_PROTOCOL_INSPECTOR_IMPL_H_ | |
7 | |
8 #include "include/v8-inspector.h" | |
9 #include "include/v8.h" | |
10 #include "src/base/macros.h" | |
11 #include "src/base/platform/platform.h" | |
12 #include "test/inspector/task-runner.h" | |
13 | |
14 class InspectorClientImpl : public v8_inspector::V8InspectorClient { | |
15 public: | |
16 class FrontendChannel { | |
17 public: | |
18 virtual ~FrontendChannel() = default; | |
19 virtual void SendMessageToFrontend( | |
20 const v8_inspector::StringView& message) = 0; | |
21 }; | |
22 | |
23 InspectorClientImpl(TaskRunner* task_runner, | |
24 FrontendChannel* frontend_channel, | |
25 v8::base::Semaphore* ready_semaphore); | |
26 virtual ~InspectorClientImpl(); | |
27 | |
28 private: | |
29 // V8InspectorClient implementation. | |
30 v8::Local<v8::Context> ensureDefaultContextInGroup( | |
31 int context_group_id) override; | |
32 double currentTimeMS() override; | |
33 void runMessageLoopOnPause(int context_group_id) override; | |
34 void quitMessageLoopOnPause() override; | |
35 | |
36 static v8_inspector::V8InspectorSession* SessionFromContext( | |
37 v8::Local<v8::Context> context); | |
38 | |
39 friend class SendMessageToBackendTask; | |
40 | |
41 friend class ConnectTask; | |
42 void connect(v8::Local<v8::Context> context); | |
43 | |
44 std::unique_ptr<v8_inspector::V8Inspector> inspector_; | |
45 std::unique_ptr<v8_inspector::V8InspectorSession> session_; | |
46 std::unique_ptr<v8_inspector::V8Inspector::Channel> channel_; | |
47 | |
48 v8::Isolate* isolate_; | |
49 v8::Global<v8::Context> context_; | |
50 | |
51 TaskRunner* task_runner_; | |
52 FrontendChannel* frontend_channel_; | |
53 | |
54 DISALLOW_COPY_AND_ASSIGN(InspectorClientImpl); | |
55 }; | |
56 | |
57 class SendMessageToBackendExtension : public v8::Extension { | |
58 public: | |
59 SendMessageToBackendExtension() | |
60 : v8::Extension("v8_inspector/frontend", | |
61 "native function sendMessageToBackend();") {} | |
62 virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate( | |
63 v8::Isolate* isolate, v8::Local<v8::String> name); | |
64 | |
65 static void set_backend_task_runner(TaskRunner* task_runner) { | |
66 backend_task_runner_ = task_runner; | |
67 } | |
68 | |
69 private: | |
70 static void SendMessageToBackend( | |
71 const v8::FunctionCallbackInfo<v8::Value>& args); | |
72 | |
73 static TaskRunner* backend_task_runner_; | |
74 }; | |
75 | |
76 #endif // V8_TEST_INSPECTOR_PROTOCOL_INSPECTOR_IMPL_H_ | |
OLD | NEW |