• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_INSPECTOR_V8_INSPECTOR_SESSION_IMPL_H_
6 #define V8_INSPECTOR_V8_INSPECTOR_SESSION_IMPL_H_
7 
8 #include <memory>
9 #include <vector>
10 
11 #include "src/base/macros.h"
12 #include "src/inspector/protocol/Forward.h"
13 #include "src/inspector/protocol/Runtime.h"
14 #include "src/inspector/protocol/Schema.h"
15 
16 #include "include/v8-inspector.h"
17 
18 namespace v8_inspector {
19 
20 class InjectedScript;
21 class RemoteObjectIdBase;
22 class V8ConsoleAgentImpl;
23 class V8DebuggerAgentImpl;
24 class V8InspectorImpl;
25 class V8HeapProfilerAgentImpl;
26 class V8ProfilerAgentImpl;
27 class V8RuntimeAgentImpl;
28 class V8SchemaAgentImpl;
29 
30 using protocol::Response;
31 
32 class V8InspectorSessionImpl : public V8InspectorSession,
33                                public protocol::FrontendChannel {
34  public:
35   static std::unique_ptr<V8InspectorSessionImpl> create(V8InspectorImpl*,
36                                                         int contextGroupId,
37                                                         int sessionId,
38                                                         V8Inspector::Channel*,
39                                                         StringView state);
40   ~V8InspectorSessionImpl() override;
41   V8InspectorSessionImpl(const V8InspectorSessionImpl&) = delete;
42   V8InspectorSessionImpl& operator=(const V8InspectorSessionImpl&) = delete;
43 
inspector()44   V8InspectorImpl* inspector() const { return m_inspector; }
consoleAgent()45   V8ConsoleAgentImpl* consoleAgent() { return m_consoleAgent.get(); }
debuggerAgent()46   V8DebuggerAgentImpl* debuggerAgent() { return m_debuggerAgent.get(); }
schemaAgent()47   V8SchemaAgentImpl* schemaAgent() { return m_schemaAgent.get(); }
profilerAgent()48   V8ProfilerAgentImpl* profilerAgent() { return m_profilerAgent.get(); }
runtimeAgent()49   V8RuntimeAgentImpl* runtimeAgent() { return m_runtimeAgent.get(); }
contextGroupId()50   int contextGroupId() const { return m_contextGroupId; }
sessionId()51   int sessionId() const { return m_sessionId; }
52 
53   std::unique_ptr<V8InspectorSession::CommandLineAPIScope>
54   initializeCommandLineAPIScope(int executionContextId) override;
55 
56   Response findInjectedScript(int contextId, InjectedScript*&);
57   Response findInjectedScript(RemoteObjectIdBase*, InjectedScript*&);
58   void reset();
59   void discardInjectedScripts();
60   void reportAllContexts(V8RuntimeAgentImpl*);
61   void setCustomObjectFormatterEnabled(bool);
62   std::unique_ptr<protocol::Runtime::RemoteObject> wrapObject(
63       v8::Local<v8::Context>, v8::Local<v8::Value>, const String16& groupName,
64       bool generatePreview);
65   std::unique_ptr<protocol::Runtime::RemoteObject> wrapTable(
66       v8::Local<v8::Context>, v8::Local<v8::Object> table,
67       v8::MaybeLocal<v8::Array> columns);
68   std::vector<std::unique_ptr<protocol::Schema::Domain>> supportedDomainsImpl();
69   Response unwrapObject(const String16& objectId, v8::Local<v8::Value>*,
70                         v8::Local<v8::Context>*, String16* objectGroup);
71   void releaseObjectGroup(const String16& objectGroup);
72 
73   // V8InspectorSession implementation.
74   void dispatchProtocolMessage(StringView message) override;
75   std::vector<uint8_t> state() override;
76   std::vector<std::unique_ptr<protocol::Schema::API::Domain>> supportedDomains()
77       override;
78   void addInspectedObject(
79       std::unique_ptr<V8InspectorSession::Inspectable>) override;
80   void schedulePauseOnNextStatement(StringView breakReason,
81                                     StringView breakDetails) override;
82   void cancelPauseOnNextStatement() override;
83   void breakProgram(StringView breakReason, StringView breakDetails) override;
84   void setSkipAllPauses(bool) override;
85   void resume(bool terminateOnResume = false) override;
86   void stepOver() override;
87   std::vector<std::unique_ptr<protocol::Debugger::API::SearchMatch>>
88   searchInTextByLines(StringView text, StringView query, bool caseSensitive,
89                       bool isRegex) override;
90   void releaseObjectGroup(StringView objectGroup) override;
91   bool unwrapObject(std::unique_ptr<StringBuffer>*, StringView objectId,
92                     v8::Local<v8::Value>*, v8::Local<v8::Context>*,
93                     std::unique_ptr<StringBuffer>* objectGroup) override;
94   std::unique_ptr<protocol::Runtime::API::RemoteObject> wrapObject(
95       v8::Local<v8::Context>, v8::Local<v8::Value>, StringView groupName,
96       bool generatePreview) override;
97 
98   V8InspectorSession::Inspectable* inspectedObject(unsigned num);
99   static const unsigned kInspectedObjectBufferSize = 5;
100 
101   void triggerPreciseCoverageDeltaUpdate(StringView occasion) override;
102 
103  private:
104   V8InspectorSessionImpl(V8InspectorImpl*, int contextGroupId, int sessionId,
105                          V8Inspector::Channel*, StringView state);
106   protocol::DictionaryValue* agentState(const String16& name);
107 
108   // protocol::FrontendChannel implementation.
109   void SendProtocolResponse(
110       int callId, std::unique_ptr<protocol::Serializable> message) override;
111   void SendProtocolNotification(
112       std::unique_ptr<protocol::Serializable> message) override;
113   void FallThrough(int callId, v8_crdtp::span<uint8_t> method,
114                    v8_crdtp::span<uint8_t> message) override;
115   void FlushProtocolNotifications() override;
116 
117   std::unique_ptr<StringBuffer> serializeForFrontend(
118       std::unique_ptr<protocol::Serializable> message);
119   int m_contextGroupId;
120   int m_sessionId;
121   V8InspectorImpl* m_inspector;
122   V8Inspector::Channel* m_channel;
123   bool m_customObjectFormatterEnabled;
124 
125   protocol::UberDispatcher m_dispatcher;
126   std::unique_ptr<protocol::DictionaryValue> m_state;
127 
128   std::unique_ptr<V8RuntimeAgentImpl> m_runtimeAgent;
129   std::unique_ptr<V8DebuggerAgentImpl> m_debuggerAgent;
130   std::unique_ptr<V8HeapProfilerAgentImpl> m_heapProfilerAgent;
131   std::unique_ptr<V8ProfilerAgentImpl> m_profilerAgent;
132   std::unique_ptr<V8ConsoleAgentImpl> m_consoleAgent;
133   std::unique_ptr<V8SchemaAgentImpl> m_schemaAgent;
134   std::vector<std::unique_ptr<V8InspectorSession::Inspectable>>
135       m_inspectedObjects;
136   bool use_binary_protocol_ = false;
137 };
138 
139 }  // namespace v8_inspector
140 
141 #endif  // V8_INSPECTOR_V8_INSPECTOR_SESSION_IMPL_H_
142