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 inspector()42 V8InspectorImpl* inspector() const { return m_inspector; } consoleAgent()43 V8ConsoleAgentImpl* consoleAgent() { return m_consoleAgent.get(); } debuggerAgent()44 V8DebuggerAgentImpl* debuggerAgent() { return m_debuggerAgent.get(); } schemaAgent()45 V8SchemaAgentImpl* schemaAgent() { return m_schemaAgent.get(); } profilerAgent()46 V8ProfilerAgentImpl* profilerAgent() { return m_profilerAgent.get(); } runtimeAgent()47 V8RuntimeAgentImpl* runtimeAgent() { return m_runtimeAgent.get(); } contextGroupId()48 int contextGroupId() const { return m_contextGroupId; } sessionId()49 int sessionId() const { return m_sessionId; } 50 51 Response findInjectedScript(int contextId, InjectedScript*&); 52 Response findInjectedScript(RemoteObjectIdBase*, InjectedScript*&); 53 void reset(); 54 void discardInjectedScripts(); 55 void reportAllContexts(V8RuntimeAgentImpl*); 56 void setCustomObjectFormatterEnabled(bool); 57 std::unique_ptr<protocol::Runtime::RemoteObject> wrapObject( 58 v8::Local<v8::Context>, v8::Local<v8::Value>, const String16& groupName, 59 bool generatePreview); 60 std::unique_ptr<protocol::Runtime::RemoteObject> wrapTable( 61 v8::Local<v8::Context>, v8::Local<v8::Object> table, 62 v8::MaybeLocal<v8::Array> columns); 63 std::vector<std::unique_ptr<protocol::Schema::Domain>> supportedDomainsImpl(); 64 Response unwrapObject(const String16& objectId, v8::Local<v8::Value>*, 65 v8::Local<v8::Context>*, String16* objectGroup); 66 void releaseObjectGroup(const String16& objectGroup); 67 68 // V8InspectorSession implementation. 69 void dispatchProtocolMessage(StringView message) override; 70 std::vector<uint8_t> state() override; 71 std::vector<std::unique_ptr<protocol::Schema::API::Domain>> supportedDomains() 72 override; 73 void addInspectedObject( 74 std::unique_ptr<V8InspectorSession::Inspectable>) override; 75 void schedulePauseOnNextStatement(StringView breakReason, 76 StringView breakDetails) override; 77 void cancelPauseOnNextStatement() override; 78 void breakProgram(StringView breakReason, StringView breakDetails) override; 79 void setSkipAllPauses(bool) override; 80 void resume(bool terminateOnResume = false) override; 81 void stepOver() override; 82 std::vector<std::unique_ptr<protocol::Debugger::API::SearchMatch>> 83 searchInTextByLines(StringView text, StringView query, bool caseSensitive, 84 bool isRegex) override; 85 void releaseObjectGroup(StringView objectGroup) override; 86 bool unwrapObject(std::unique_ptr<StringBuffer>*, StringView objectId, 87 v8::Local<v8::Value>*, v8::Local<v8::Context>*, 88 std::unique_ptr<StringBuffer>* objectGroup) override; 89 std::unique_ptr<protocol::Runtime::API::RemoteObject> wrapObject( 90 v8::Local<v8::Context>, v8::Local<v8::Value>, StringView groupName, 91 bool generatePreview) override; 92 93 V8InspectorSession::Inspectable* inspectedObject(unsigned num); 94 static const unsigned kInspectedObjectBufferSize = 5; 95 96 void triggerPreciseCoverageDeltaUpdate(StringView occassion) override; 97 98 private: 99 V8InspectorSessionImpl(V8InspectorImpl*, int contextGroupId, int sessionId, 100 V8Inspector::Channel*, StringView state); 101 protocol::DictionaryValue* agentState(const String16& name); 102 103 // protocol::FrontendChannel implementation. 104 void SendProtocolResponse( 105 int callId, std::unique_ptr<protocol::Serializable> message) override; 106 void SendProtocolNotification( 107 std::unique_ptr<protocol::Serializable> message) override; 108 void FallThrough(int callId, v8_crdtp::span<uint8_t> method, 109 v8_crdtp::span<uint8_t> message) override; 110 void FlushProtocolNotifications() override; 111 112 std::unique_ptr<StringBuffer> serializeForFrontend( 113 std::unique_ptr<protocol::Serializable> message); 114 int m_contextGroupId; 115 int m_sessionId; 116 V8InspectorImpl* m_inspector; 117 V8Inspector::Channel* m_channel; 118 bool m_customObjectFormatterEnabled; 119 120 protocol::UberDispatcher m_dispatcher; 121 std::unique_ptr<protocol::DictionaryValue> m_state; 122 123 std::unique_ptr<V8RuntimeAgentImpl> m_runtimeAgent; 124 std::unique_ptr<V8DebuggerAgentImpl> m_debuggerAgent; 125 std::unique_ptr<V8HeapProfilerAgentImpl> m_heapProfilerAgent; 126 std::unique_ptr<V8ProfilerAgentImpl> m_profilerAgent; 127 std::unique_ptr<V8ConsoleAgentImpl> m_consoleAgent; 128 std::unique_ptr<V8SchemaAgentImpl> m_schemaAgent; 129 std::vector<std::unique_ptr<V8InspectorSession::Inspectable>> 130 m_inspectedObjects; 131 bool use_binary_protocol_ = false; 132 133 DISALLOW_COPY_AND_ASSIGN(V8InspectorSessionImpl); 134 }; 135 136 } // namespace v8_inspector 137 138 #endif // V8_INSPECTOR_V8_INSPECTOR_SESSION_IMPL_H_ 139