| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/inspector/inspected-context.h" | 5 #include "src/inspector/inspected-context.h" |
| 6 | 6 |
| 7 #include "src/debug/debug-interface.h" | 7 #include "src/debug/debug-interface.h" |
| 8 #include "src/inspector/injected-script.h" | 8 #include "src/inspector/injected-script.h" |
| 9 #include "src/inspector/string-util.h" | 9 #include "src/inspector/string-util.h" |
| 10 #include "src/inspector/v8-console.h" | 10 #include "src/inspector/v8-console.h" |
| 11 #include "src/inspector/v8-inspector-impl.h" | 11 #include "src/inspector/v8-inspector-impl.h" |
| 12 #include "src/inspector/v8-value-copier.h" | 12 #include "src/inspector/v8-value-copier.h" |
| 13 | 13 |
| 14 #include "include/v8-inspector.h" | 14 #include "include/v8-inspector.h" |
| 15 | 15 |
| 16 namespace v8_inspector { | 16 namespace v8_inspector { |
| 17 | 17 |
| 18 InspectedContext::InspectedContext(V8InspectorImpl* inspector, | 18 InspectedContext::InspectedContext(V8InspectorImpl* inspector, |
| 19 const V8ContextInfo& info, int contextId) | 19 const V8ContextInfo& info, int contextId) |
| 20 : m_inspector(inspector), | 20 : m_inspector(inspector), |
| 21 m_context(info.context->GetIsolate(), info.context), | 21 m_context(info.context->GetIsolate(), info.context), |
| 22 m_contextId(contextId), | 22 m_contextId(contextId), |
| 23 m_contextGroupId(info.contextGroupId), | 23 m_contextGroupId(info.contextGroupId), |
| 24 m_origin(toString16(info.origin)), | 24 m_origin(toString16(info.origin)), |
| 25 m_humanReadableName(toString16(info.humanReadableName)), | 25 m_humanReadableName(toString16(info.humanReadableName)), |
| 26 m_auxData(toString16(info.auxData)), | 26 m_auxData(toString16(info.auxData)) { |
| 27 m_reported(false) { | |
| 28 v8::debug::SetContextId(info.context, contextId); | 27 v8::debug::SetContextId(info.context, contextId); |
| 29 if (!info.hasMemoryOnConsole) return; | 28 if (!info.hasMemoryOnConsole) return; |
| 30 v8::Context::Scope contextScope(info.context); | 29 v8::Context::Scope contextScope(info.context); |
| 31 v8::Local<v8::Object> global = info.context->Global(); | 30 v8::Local<v8::Object> global = info.context->Global(); |
| 32 v8::Local<v8::Value> console; | 31 v8::Local<v8::Value> console; |
| 33 if (global->Get(info.context, toV8String(m_inspector->isolate(), "console")) | 32 if (global->Get(info.context, toV8String(m_inspector->isolate(), "console")) |
| 34 .ToLocal(&console) && | 33 .ToLocal(&console) && |
| 35 console->IsObject()) { | 34 console->IsObject()) { |
| 36 m_inspector->console()->installMemoryGetter( | 35 m_inspector->console()->installMemoryGetter( |
| 37 info.context, v8::Local<v8::Object>::Cast(console)); | 36 info.context, v8::Local<v8::Object>::Cast(console)); |
| 38 } | 37 } |
| 39 } | 38 } |
| 40 | 39 |
| 41 InspectedContext::~InspectedContext() { | 40 InspectedContext::~InspectedContext() { |
| 42 } | 41 } |
| 43 | 42 |
| 44 // static | 43 // static |
| 45 int InspectedContext::contextId(v8::Local<v8::Context> context) { | 44 int InspectedContext::contextId(v8::Local<v8::Context> context) { |
| 46 return v8::debug::GetContextId(context); | 45 return v8::debug::GetContextId(context); |
| 47 } | 46 } |
| 48 | 47 |
| 49 v8::Local<v8::Context> InspectedContext::context() const { | 48 v8::Local<v8::Context> InspectedContext::context() const { |
| 50 return m_context.Get(isolate()); | 49 return m_context.Get(isolate()); |
| 51 } | 50 } |
| 52 | 51 |
| 53 v8::Isolate* InspectedContext::isolate() const { | 52 v8::Isolate* InspectedContext::isolate() const { |
| 54 return m_inspector->isolate(); | 53 return m_inspector->isolate(); |
| 55 } | 54 } |
| 56 | 55 |
| 56 bool InspectedContext::isReported(int sessionId) const { |
| 57 return m_reportedSessionIds.find(sessionId) != m_reportedSessionIds.cend(); |
| 58 } |
| 59 |
| 60 void InspectedContext::setReported(int sessionId, bool reported) { |
| 61 if (reported) |
| 62 m_reportedSessionIds.insert(sessionId); |
| 63 else |
| 64 m_reportedSessionIds.erase(sessionId); |
| 65 } |
| 66 |
| 57 bool InspectedContext::createInjectedScript() { | 67 bool InspectedContext::createInjectedScript() { |
| 58 DCHECK(!m_injectedScript); | 68 DCHECK(!m_injectedScript); |
| 59 std::unique_ptr<InjectedScript> injectedScript = InjectedScript::create(this); | 69 std::unique_ptr<InjectedScript> injectedScript = InjectedScript::create(this); |
| 60 // InjectedScript::create can destroy |this|. | 70 // InjectedScript::create can destroy |this|. |
| 61 if (!injectedScript) return false; | 71 if (!injectedScript) return false; |
| 62 m_injectedScript = std::move(injectedScript); | 72 m_injectedScript = std::move(injectedScript); |
| 63 return true; | 73 return true; |
| 64 } | 74 } |
| 65 | 75 |
| 66 void InspectedContext::discardInjectedScript() { m_injectedScript.reset(); } | 76 void InspectedContext::discardInjectedScript() { m_injectedScript.reset(); } |
| 67 | 77 |
| 68 } // namespace v8_inspector | 78 } // namespace v8_inspector |
| OLD | NEW |