| 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 "platform/v8_inspector/InjectedScriptNative.h" | 5 #include "platform/v8_inspector/InjectedScriptNative.h" |
| 6 | 6 |
| 7 #include "platform/inspector_protocol/Values.h" | 7 #include "platform/inspector_protocol/Values.h" |
| 8 | 8 |
| 9 namespace blink { | 9 namespace blink { |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 v8::Isolate* isolate = injectedScriptObject->GetIsolate(); | 31 v8::Isolate* isolate = injectedScriptObject->GetIsolate(); |
| 32 v8::HandleScope handleScope(isolate); | 32 v8::HandleScope handleScope(isolate); |
| 33 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 33 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 34 v8::Local<v8::Private> privateKey = v8::Private::ForApi(isolate, v8::String:
:NewFromUtf8(isolate, privateKeyName, v8::NewStringType::kInternalized).ToLocalC
hecked()); | 34 v8::Local<v8::Private> privateKey = v8::Private::ForApi(isolate, v8::String:
:NewFromUtf8(isolate, privateKeyName, v8::NewStringType::kInternalized).ToLocalC
hecked()); |
| 35 v8::Local<v8::Value> value = injectedScriptObject->GetPrivate(context, priva
teKey).ToLocalChecked(); | 35 v8::Local<v8::Value> value = injectedScriptObject->GetPrivate(context, priva
teKey).ToLocalChecked(); |
| 36 ASSERT(value->IsExternal()); | 36 ASSERT(value->IsExternal()); |
| 37 v8::Local<v8::External> external = value.As<v8::External>(); | 37 v8::Local<v8::External> external = value.As<v8::External>(); |
| 38 return static_cast<InjectedScriptNative*>(external->Value()); | 38 return static_cast<InjectedScriptNative*>(external->Value()); |
| 39 } | 39 } |
| 40 | 40 |
| 41 int InjectedScriptNative::bind(v8::Local<v8::Value> value, const String& groupNa
me) | 41 int InjectedScriptNative::bind(v8::Local<v8::Value> value, const String16& group
Name) |
| 42 { | 42 { |
| 43 if (m_lastBoundObjectId <= 0) | 43 if (m_lastBoundObjectId <= 0) |
| 44 m_lastBoundObjectId = 1; | 44 m_lastBoundObjectId = 1; |
| 45 int id = m_lastBoundObjectId++; | 45 int id = m_lastBoundObjectId++; |
| 46 m_idToWrappedObject.set(id, adoptPtr(new v8::Global<v8::Value>(m_isolate, va
lue))); | 46 m_idToWrappedObject.set(id, adoptPtr(new v8::Global<v8::Value>(m_isolate, va
lue))); |
| 47 addObjectToGroup(id, groupName); | 47 addObjectToGroup(id, groupName); |
| 48 return id; | 48 return id; |
| 49 } | 49 } |
| 50 | 50 |
| 51 void InjectedScriptNative::unbind(int id) | 51 void InjectedScriptNative::unbind(int id) |
| 52 { | 52 { |
| 53 m_idToWrappedObject.remove(id); | 53 m_idToWrappedObject.remove(id); |
| 54 m_idToObjectGroupName.remove(id); | 54 m_idToObjectGroupName.remove(id); |
| 55 } | 55 } |
| 56 | 56 |
| 57 v8::Local<v8::Value> InjectedScriptNative::objectForId(int id) | 57 v8::Local<v8::Value> InjectedScriptNative::objectForId(int id) |
| 58 { | 58 { |
| 59 return m_idToWrappedObject.contains(id) ? m_idToWrappedObject.get(id)->Get(m
_isolate) : v8::Local<v8::Value>(); | 59 return m_idToWrappedObject.contains(id) ? m_idToWrappedObject.get(id)->Get(m
_isolate) : v8::Local<v8::Value>(); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void InjectedScriptNative::addObjectToGroup(int objectId, const String& groupNam
e) | 62 void InjectedScriptNative::addObjectToGroup(int objectId, const String16& groupN
ame) |
| 63 { | 63 { |
| 64 if (groupName.isEmpty()) | 64 if (groupName.isEmpty()) |
| 65 return; | 65 return; |
| 66 if (objectId <= 0) | 66 if (objectId <= 0) |
| 67 return; | 67 return; |
| 68 m_idToObjectGroupName.set(objectId, groupName); | 68 m_idToObjectGroupName.set(objectId, groupName); |
| 69 auto it = m_nameToObjectGroup.find(groupName); | 69 auto it = m_nameToObjectGroup.find(groupName); |
| 70 if (it == m_nameToObjectGroup.end()) { | 70 if (it == m_nameToObjectGroup.end()) { |
| 71 m_nameToObjectGroup.set(groupName, protocol::Vector<int>()); | 71 m_nameToObjectGroup.set(groupName, protocol::Vector<int>()); |
| 72 it = m_nameToObjectGroup.find(groupName); | 72 it = m_nameToObjectGroup.find(groupName); |
| 73 } | 73 } |
| 74 it->second->append(objectId); | 74 it->second->append(objectId); |
| 75 } | 75 } |
| 76 | 76 |
| 77 void InjectedScriptNative::releaseObjectGroup(const String& groupName) | 77 void InjectedScriptNative::releaseObjectGroup(const String16& groupName) |
| 78 { | 78 { |
| 79 if (groupName.isEmpty()) | 79 if (groupName.isEmpty()) |
| 80 return; | 80 return; |
| 81 NameToObjectGroup::iterator groupIt = m_nameToObjectGroup.find(groupName); | 81 NameToObjectGroup::iterator groupIt = m_nameToObjectGroup.find(groupName); |
| 82 if (groupIt == m_nameToObjectGroup.end()) | 82 if (groupIt == m_nameToObjectGroup.end()) |
| 83 return; | 83 return; |
| 84 for (int id : *groupIt->second) | 84 for (int id : *groupIt->second) |
| 85 unbind(id); | 85 unbind(id); |
| 86 m_nameToObjectGroup.remove(groupName); | 86 m_nameToObjectGroup.remove(groupName); |
| 87 } | 87 } |
| 88 | 88 |
| 89 String InjectedScriptNative::groupName(int objectId) const | 89 String16 InjectedScriptNative::groupName(int objectId) const |
| 90 { | 90 { |
| 91 if (objectId <= 0) | 91 if (objectId <= 0) |
| 92 return String(); | 92 return String16(); |
| 93 return m_idToObjectGroupName.get(objectId); | 93 return m_idToObjectGroupName.get(objectId); |
| 94 } | 94 } |
| 95 | 95 |
| 96 } // namespace blink | 96 } // namespace blink |
| 97 | 97 |
| OLD | NEW |