Home | History | Annotate | Download | only in inspector
      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_V8INSPECTORSESSIONIMPL_H_
      6 #define V8_INSPECTOR_V8INSPECTORSESSIONIMPL_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, V8Inspector::Channel*,
     36       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 
     47   Response findInjectedScript(int contextId, InjectedScript*&);
     48   Response findInjectedScript(RemoteObjectIdBase*, InjectedScript*&);
     49   void reset();
     50   void discardInjectedScripts();
     51   void reportAllContexts(V8RuntimeAgentImpl*);
     52   void setCustomObjectFormatterEnabled(bool);
     53   std::unique_ptr<protocol::Runtime::RemoteObject> wrapObject(
     54       v8::Local<v8::Context>, v8::Local<v8::Value>, const String16& groupName,
     55       bool generatePreview);
     56   std::unique_ptr<protocol::Runtime::RemoteObject> wrapTable(
     57       v8::Local<v8::Context>, v8::Local<v8::Value> table,
     58       v8::Local<v8::Value> columns);
     59   std::vector<std::unique_ptr<protocol::Schema::Domain>> supportedDomainsImpl();
     60   Response unwrapObject(const String16& objectId, v8::Local<v8::Value>*,
     61                         v8::Local<v8::Context>*, String16* objectGroup);
     62   void releaseObjectGroup(const String16& objectGroup);
     63 
     64   // V8InspectorSession implementation.
     65   void dispatchProtocolMessage(const StringView& message) override;
     66   std::unique_ptr<StringBuffer> stateJSON() override;
     67   std::vector<std::unique_ptr<protocol::Schema::API::Domain>> supportedDomains()
     68       override;
     69   void addInspectedObject(
     70       std::unique_ptr<V8InspectorSession::Inspectable>) override;
     71   void schedulePauseOnNextStatement(const StringView& breakReason,
     72                                     const StringView& breakDetails) override;
     73   void cancelPauseOnNextStatement() override;
     74   void breakProgram(const StringView& breakReason,
     75                     const StringView& breakDetails) override;
     76   void setSkipAllPauses(bool) override;
     77   void resume() override;
     78   void stepOver() override;
     79   std::vector<std::unique_ptr<protocol::Debugger::API::SearchMatch>>
     80   searchInTextByLines(const StringView& text, const StringView& query,
     81                       bool caseSensitive, bool isRegex) override;
     82   void releaseObjectGroup(const StringView& objectGroup) override;
     83   bool unwrapObject(std::unique_ptr<StringBuffer>*, const StringView& objectId,
     84                     v8::Local<v8::Value>*, v8::Local<v8::Context>*,
     85                     std::unique_ptr<StringBuffer>* objectGroup) override;
     86   std::unique_ptr<protocol::Runtime::API::RemoteObject> wrapObject(
     87       v8::Local<v8::Context>, v8::Local<v8::Value>,
     88       const StringView& groupName) override;
     89 
     90   V8InspectorSession::Inspectable* inspectedObject(unsigned num);
     91   static const unsigned kInspectedObjectBufferSize = 5;
     92 
     93  private:
     94   V8InspectorSessionImpl(V8InspectorImpl*, int contextGroupId,
     95                          V8Inspector::Channel*, const StringView& state);
     96   protocol::DictionaryValue* agentState(const String16& name);
     97 
     98   // protocol::FrontendChannel implementation.
     99   void sendProtocolResponse(
    100       int callId, std::unique_ptr<protocol::Serializable> message) override;
    101   void sendProtocolNotification(
    102       std::unique_ptr<protocol::Serializable> message) override;
    103   void flushProtocolNotifications() override;
    104 
    105   int m_contextGroupId;
    106   V8InspectorImpl* m_inspector;
    107   V8Inspector::Channel* m_channel;
    108   bool m_customObjectFormatterEnabled;
    109 
    110   protocol::UberDispatcher m_dispatcher;
    111   std::unique_ptr<protocol::DictionaryValue> m_state;
    112 
    113   std::unique_ptr<V8RuntimeAgentImpl> m_runtimeAgent;
    114   std::unique_ptr<V8DebuggerAgentImpl> m_debuggerAgent;
    115   std::unique_ptr<V8HeapProfilerAgentImpl> m_heapProfilerAgent;
    116   std::unique_ptr<V8ProfilerAgentImpl> m_profilerAgent;
    117   std::unique_ptr<V8ConsoleAgentImpl> m_consoleAgent;
    118   std::unique_ptr<V8SchemaAgentImpl> m_schemaAgent;
    119   std::vector<std::unique_ptr<V8InspectorSession::Inspectable>>
    120       m_inspectedObjects;
    121 
    122   DISALLOW_COPY_AND_ASSIGN(V8InspectorSessionImpl);
    123 };
    124 
    125 }  // namespace v8_inspector
    126 
    127 #endif  // V8_INSPECTOR_V8INSPECTORSESSIONIMPL_H_
    128