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