| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium 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 #include "platform/v8_inspector/InspectedContext.h" | |
| 6 | |
| 7 #include "platform/v8_inspector/InjectedScript.h" | |
| 8 #include "platform/v8_inspector/StringUtil.h" | |
| 9 #include "platform/v8_inspector/V8Console.h" | |
| 10 #include "platform/v8_inspector/V8InspectorImpl.h" | |
| 11 #include "platform/v8_inspector/V8ValueCopier.h" | |
| 12 #include "platform/v8_inspector/public/V8ContextInfo.h" | |
| 13 #include "platform/v8_inspector/public/V8InspectorClient.h" | |
| 14 | |
| 15 namespace v8_inspector { | |
| 16 | |
| 17 void InspectedContext::weakCallback(const v8::WeakCallbackInfo<InspectedContext>
& data) | |
| 18 { | |
| 19 InspectedContext* context = data.GetParameter(); | |
| 20 if (!context->m_context.IsEmpty()) { | |
| 21 context->m_context.Reset(); | |
| 22 data.SetSecondPassCallback(&InspectedContext::weakCallback); | |
| 23 } else { | |
| 24 context->m_inspector->discardInspectedContext(context->m_contextGroupId,
context->m_contextId); | |
| 25 } | |
| 26 } | |
| 27 | |
| 28 void InspectedContext::consoleWeakCallback(const v8::WeakCallbackInfo<InspectedC
ontext>& data) | |
| 29 { | |
| 30 data.GetParameter()->m_console.Reset(); | |
| 31 } | |
| 32 | |
| 33 InspectedContext::InspectedContext(V8InspectorImpl* inspector, const V8ContextIn
fo& info, int contextId) | |
| 34 : m_inspector(inspector) | |
| 35 , m_context(info.context->GetIsolate(), info.context) | |
| 36 , m_contextId(contextId) | |
| 37 , m_contextGroupId(info.contextGroupId) | |
| 38 , m_origin(toString16(info.origin)) | |
| 39 , m_humanReadableName(toString16(info.humanReadableName)) | |
| 40 , m_auxData(toString16(info.auxData)) | |
| 41 , m_reported(false) | |
| 42 { | |
| 43 m_context.SetWeak(this, &InspectedContext::weakCallback, v8::WeakCallbackTyp
e::kParameter); | |
| 44 | |
| 45 v8::Isolate* isolate = m_inspector->isolate(); | |
| 46 v8::Local<v8::Object> global = info.context->Global(); | |
| 47 v8::Local<v8::Object> console = V8Console::createConsole(this, info.hasMemor
yOnConsole); | |
| 48 if (!global->Set(info.context, toV8StringInternalized(isolate, "console"), c
onsole).FromMaybe(false)) | |
| 49 return; | |
| 50 m_console.Reset(isolate, console); | |
| 51 m_console.SetWeak(this, &InspectedContext::consoleWeakCallback, v8::WeakCall
backType::kParameter); | |
| 52 } | |
| 53 | |
| 54 InspectedContext::~InspectedContext() | |
| 55 { | |
| 56 if (!m_context.IsEmpty() && !m_console.IsEmpty()) { | |
| 57 v8::HandleScope scope(isolate()); | |
| 58 V8Console::clearInspectedContextIfNeeded(context(), m_console.Get(isolat
e())); | |
| 59 } | |
| 60 } | |
| 61 | |
| 62 v8::Local<v8::Context> InspectedContext::context() const | |
| 63 { | |
| 64 return m_context.Get(isolate()); | |
| 65 } | |
| 66 | |
| 67 v8::Isolate* InspectedContext::isolate() const | |
| 68 { | |
| 69 return m_inspector->isolate(); | |
| 70 } | |
| 71 | |
| 72 void InspectedContext::createInjectedScript() | |
| 73 { | |
| 74 DCHECK(!m_injectedScript); | |
| 75 m_injectedScript = InjectedScript::create(this); | |
| 76 } | |
| 77 | |
| 78 void InspectedContext::discardInjectedScript() | |
| 79 { | |
| 80 m_injectedScript.reset(); | |
| 81 } | |
| 82 | |
| 83 } // namespace v8_inspector | |
| OLD | NEW |