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" | |
9 #include "platform/JSONValues.h" | 7 #include "platform/JSONValues.h" |
10 #include "wtf/Vector.h" | 8 #include "wtf/Vector.h" |
11 #include "wtf/text/WTFString.h" | 9 #include "wtf/text/WTFString.h" |
12 | 10 |
13 namespace blink { | 11 namespace blink { |
14 | 12 |
15 InjectedScriptNative::InjectedScriptNative(v8::Isolate* isolate) | 13 InjectedScriptNative::InjectedScriptNative(v8::Isolate* isolate) |
16 : m_lastBoundObjectId(1) | 14 : m_lastBoundObjectId(1) |
17 , m_isolate(isolate) | 15 , m_isolate(isolate) |
18 , m_idToWrappedObject(m_isolate) | 16 , m_idToWrappedObject(m_isolate) |
19 { | 17 { |
20 } | 18 } |
21 | 19 |
20 static const char privateKeyName[] = "v8-inspector#injectedScript"; | |
dgozman
2016/01/28 00:21:48
Either name it more specificly or put into anonymo
pfeldman
2016/01/28 00:29:42
Why?
| |
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 V8HiddenValue::setHiddenValue(ScriptState::current(m_isolate), injectedScrip tHost, V8HiddenValue::injectedScriptNative(m_isolate), external); | 28 v8::Local<v8::Private> privateKey = v8::Private::ForApi(m_isolate, v8::Strin g::NewFromUtf8(m_isolate, privateKeyName)); |
29 injectedScriptHost->SetPrivate(m_isolate->GetCurrentContext(), privateKey, e xternal); | |
dgozman
2016/01/28 00:21:48
Let's pass context explicitly?
pfeldman
2016/01/28 00:29:42
Did not do that on purpose - the fetch goes over t
| |
29 } | 30 } |
30 | 31 |
31 InjectedScriptNative* InjectedScriptNative::fromInjectedScriptHost(v8::Local<v8: :Object> injectedScriptObject) | 32 InjectedScriptNative* InjectedScriptNative::fromInjectedScriptHost(v8::Local<v8: :Object> injectedScriptObject) |
32 { | 33 { |
33 v8::Isolate* isolate = injectedScriptObject->GetIsolate(); | 34 v8::Isolate* isolate = injectedScriptObject->GetIsolate(); |
34 v8::HandleScope handleScope(isolate); | 35 v8::HandleScope handleScope(isolate); |
35 v8::Local<v8::Value> value = V8HiddenValue::getHiddenValue(ScriptState::curr ent(isolate), injectedScriptObject, V8HiddenValue::injectedScriptNative(isolate) ); | 36 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
36 ASSERT(!value.IsEmpty()); | 37 v8::Local<v8::Private> privateKey = v8::Private::ForApi(isolate, v8::String: :NewFromUtf8(isolate, privateKeyName)); |
38 v8::Local<v8::Value> value; | |
39 RELEASE_ASSERT(injectedScriptObject->GetPrivate(context, privateKey).ToLocal (&value)); | |
37 v8::Local<v8::External> external = value.As<v8::External>(); | 40 v8::Local<v8::External> external = value.As<v8::External>(); |
38 void* ptr = external->Value(); | 41 void* ptr = external->Value(); |
39 ASSERT(ptr); | 42 ASSERT(ptr); |
40 return static_cast<InjectedScriptNative*>(ptr); | 43 return static_cast<InjectedScriptNative*>(ptr); |
41 } | 44 } |
42 | 45 |
43 int InjectedScriptNative::bind(v8::Local<v8::Value> value, const String& groupNa me) | 46 int InjectedScriptNative::bind(v8::Local<v8::Value> value, const String& groupNa me) |
44 { | 47 { |
45 if (m_lastBoundObjectId <= 0) | 48 if (m_lastBoundObjectId <= 0) |
46 m_lastBoundObjectId = 1; | 49 m_lastBoundObjectId = 1; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 | 92 |
90 String InjectedScriptNative::groupName(int objectId) const | 93 String InjectedScriptNative::groupName(int objectId) const |
91 { | 94 { |
92 if (objectId <= 0) | 95 if (objectId <= 0) |
93 return String(); | 96 return String(); |
94 return m_idToObjectGroupName.get(objectId); | 97 return m_idToObjectGroupName.get(objectId); |
95 } | 98 } |
96 | 99 |
97 } // namespace blink | 100 } // namespace blink |
98 | 101 |
OLD | NEW |