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_INSPECTED_CONTEXT_H_ 6 #define V8_INSPECTOR_INSPECTED_CONTEXT_H_ 7 8 #include <memory> 9 #include <unordered_map> 10 #include <unordered_set> 11 12 #include "src/base/macros.h" 13 #include "src/debug/debug-interface.h" 14 #include "src/inspector/string-16.h" 15 16 #include "include/v8.h" 17 18 namespace v8_inspector { 19 20 class InjectedScript; 21 class InjectedScriptHost; 22 class V8ContextInfo; 23 class V8InspectorImpl; 24 25 enum class V8InternalValueType { kNone, kEntry, kScope, kScopeList }; 26 27 class InspectedContext { 28 public: 29 ~InspectedContext(); 30 31 static int contextId(v8::Local<v8::Context>); 32 33 v8::Local<v8::Context> context() const; contextId()34 int contextId() const { return m_contextId; } contextGroupId()35 int contextGroupId() const { return m_contextGroupId; } origin()36 String16 origin() const { return m_origin; } humanReadableName()37 String16 humanReadableName() const { return m_humanReadableName; } auxData()38 String16 auxData() const { return m_auxData; } 39 40 bool isReported(int sessionId) const; 41 void setReported(int sessionId, bool reported); 42 43 v8::Isolate* isolate() const; inspector()44 V8InspectorImpl* inspector() const { return m_inspector; } 45 46 InjectedScript* getInjectedScript(int sessionId); 47 InjectedScript* createInjectedScript(int sessionId); 48 void discardInjectedScript(int sessionId); 49 50 bool addInternalObject(v8::Local<v8::Object> object, 51 V8InternalValueType type); 52 V8InternalValueType getInternalType(v8::Local<v8::Object> object); 53 54 private: 55 friend class V8InspectorImpl; 56 InspectedContext(V8InspectorImpl*, const V8ContextInfo&, int contextId); 57 58 class WeakCallbackData; 59 60 V8InspectorImpl* m_inspector; 61 v8::Global<v8::Context> m_context; 62 int m_contextId; 63 int m_contextGroupId; 64 const String16 m_origin; 65 const String16 m_humanReadableName; 66 const String16 m_auxData; 67 std::unordered_set<int> m_reportedSessionIds; 68 std::unordered_map<int, std::unique_ptr<InjectedScript>> m_injectedScripts; 69 WeakCallbackData* m_weakCallbackData; 70 v8::Global<v8::debug::WeakMap> m_internalObjects; 71 72 DISALLOW_COPY_AND_ASSIGN(InspectedContext); 73 }; 74 75 } // namespace v8_inspector 76 77 #endif // V8_INSPECTOR_INSPECTED_CONTEXT_H_ 78