| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "core/inspector/InjectedScriptNative.h" | 5 #include "core/inspector/InjectedScriptNative.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptState.h" |
| 8 #include "bindings/core/v8/V8HiddenValue.h" |
| 7 #include "platform/JSONValues.h" | 9 #include "platform/JSONValues.h" |
| 8 #include "wtf/Vector.h" | 10 #include "wtf/Vector.h" |
| 9 #include "wtf/text/WTFString.h" | 11 #include "wtf/text/WTFString.h" |
| 10 | 12 |
| 11 namespace blink { | 13 namespace blink { |
| 12 | 14 |
| 13 InjectedScriptNative::InjectedScriptNative(v8::Isolate* isolate) | 15 InjectedScriptNative::InjectedScriptNative(v8::Isolate* isolate) |
| 14 : m_lastBoundObjectId(1) | 16 : m_lastBoundObjectId(1) |
| 15 , m_isolate(isolate) | 17 , m_isolate(isolate) |
| 16 , m_idToWrappedObject(m_isolate) | 18 , m_idToWrappedObject(m_isolate) |
| 17 { | 19 { |
| 18 } | 20 } |
| 19 | 21 |
| 20 static const char privateKeyName[] = "v8-inspector#injectedScript"; | |
| 21 | |
| 22 InjectedScriptNative::~InjectedScriptNative() { } | 22 InjectedScriptNative::~InjectedScriptNative() { } |
| 23 | 23 |
| 24 void InjectedScriptNative::setOnInjectedScriptHost(v8::Local<v8::Object> injecte
dScriptHost) | 24 void InjectedScriptNative::setOnInjectedScriptHost(v8::Local<v8::Object> injecte
dScriptHost) |
| 25 { | 25 { |
| 26 v8::HandleScope handleScope(m_isolate); | 26 v8::HandleScope handleScope(m_isolate); |
| 27 v8::Local<v8::External> external = v8::External::New(m_isolate, this); | 27 v8::Local<v8::External> external = v8::External::New(m_isolate, this); |
| 28 v8::Local<v8::Private> privateKey = v8::Private::ForApi(m_isolate, v8::Strin
g::NewFromUtf8(m_isolate, privateKeyName)); | 28 V8HiddenValue::setHiddenValue(ScriptState::current(m_isolate), injectedScrip
tHost, V8HiddenValue::injectedScriptNative(m_isolate), external); |
| 29 injectedScriptHost->SetPrivate(m_isolate->GetCurrentContext(), privateKey, e
xternal); | |
| 30 } | 29 } |
| 31 | 30 |
| 32 InjectedScriptNative* InjectedScriptNative::fromInjectedScriptHost(v8::Local<v8:
:Object> injectedScriptObject) | 31 InjectedScriptNative* InjectedScriptNative::fromInjectedScriptHost(v8::Local<v8:
:Object> injectedScriptObject) |
| 33 { | 32 { |
| 34 v8::Isolate* isolate = injectedScriptObject->GetIsolate(); | 33 v8::Isolate* isolate = injectedScriptObject->GetIsolate(); |
| 35 v8::HandleScope handleScope(isolate); | 34 v8::HandleScope handleScope(isolate); |
| 36 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 35 v8::Local<v8::Value> value = V8HiddenValue::getHiddenValue(ScriptState::curr
ent(isolate), injectedScriptObject, V8HiddenValue::injectedScriptNative(isolate)
); |
| 37 v8::Local<v8::Private> privateKey = v8::Private::ForApi(isolate, v8::String:
:NewFromUtf8(isolate, privateKeyName)); | 36 ASSERT(!value.IsEmpty()); |
| 38 v8::Local<v8::Value> value; | |
| 39 RELEASE_ASSERT(injectedScriptObject->GetPrivate(context, privateKey).ToLocal
(&value)); | |
| 40 v8::Local<v8::External> external = value.As<v8::External>(); | 37 v8::Local<v8::External> external = value.As<v8::External>(); |
| 41 void* ptr = external->Value(); | 38 void* ptr = external->Value(); |
| 42 ASSERT(ptr); | 39 ASSERT(ptr); |
| 43 return static_cast<InjectedScriptNative*>(ptr); | 40 return static_cast<InjectedScriptNative*>(ptr); |
| 44 } | 41 } |
| 45 | 42 |
| 46 int InjectedScriptNative::bind(v8::Local<v8::Value> value, const String& groupNa
me) | 43 int InjectedScriptNative::bind(v8::Local<v8::Value> value, const String& groupNa
me) |
| 47 { | 44 { |
| 48 if (m_lastBoundObjectId <= 0) | 45 if (m_lastBoundObjectId <= 0) |
| 49 m_lastBoundObjectId = 1; | 46 m_lastBoundObjectId = 1; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 | 89 |
| 93 String InjectedScriptNative::groupName(int objectId) const | 90 String InjectedScriptNative::groupName(int objectId) const |
| 94 { | 91 { |
| 95 if (objectId <= 0) | 92 if (objectId <= 0) |
| 96 return String(); | 93 return String(); |
| 97 return m_idToObjectGroupName.get(objectId); | 94 return m_idToObjectGroupName.get(objectId); |
| 98 } | 95 } |
| 99 | 96 |
| 100 } // namespace blink | 97 } // namespace blink |
| 101 | 98 |
| OLD | NEW |