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