| 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 25 matching lines...) Expand all Loading... |
| 36 DCHECK(value->IsExternal()); | 36 DCHECK(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 String16& group
Name) | 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, wrapUnique(new v8::Global<v8::Value>(m_isolate,
value))); | 46 m_idToWrappedObject[id] = wrapUnique(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.erase(id); |
| 54 m_idToObjectGroupName.remove(id); | 54 m_idToObjectGroupName.erase(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 auto iter = m_idToWrappedObject.find(id); |
| 60 return iter != m_idToWrappedObject.end() ? iter->second->Get(m_isolate) : v8
::Local<v8::Value>(); |
| 60 } | 61 } |
| 61 | 62 |
| 62 void InjectedScriptNative::addObjectToGroup(int objectId, const String16& groupN
ame) | 63 void InjectedScriptNative::addObjectToGroup(int objectId, const String16& groupN
ame) |
| 63 { | 64 { |
| 64 if (groupName.isEmpty()) | 65 if (groupName.isEmpty()) |
| 65 return; | 66 return; |
| 66 if (objectId <= 0) | 67 if (objectId <= 0) |
| 67 return; | 68 return; |
| 68 m_idToObjectGroupName.set(objectId, groupName); | 69 m_idToObjectGroupName[objectId] = groupName; |
| 69 auto it = m_nameToObjectGroup.find(groupName); | 70 m_nameToObjectGroup[groupName].push_back(objectId); // Creates an empty vect
or if key is not there |
| 70 if (it == m_nameToObjectGroup.end()) { | |
| 71 m_nameToObjectGroup.set(groupName, protocol::Vector<int>()); | |
| 72 it = m_nameToObjectGroup.find(groupName); | |
| 73 } | |
| 74 it->second->append(objectId); | |
| 75 } | 71 } |
| 76 | 72 |
| 77 void InjectedScriptNative::releaseObjectGroup(const String16& groupName) | 73 void InjectedScriptNative::releaseObjectGroup(const String16& groupName) |
| 78 { | 74 { |
| 79 if (groupName.isEmpty()) | 75 if (groupName.isEmpty()) |
| 80 return; | 76 return; |
| 81 NameToObjectGroup::iterator groupIt = m_nameToObjectGroup.find(groupName); | 77 NameToObjectGroup::iterator groupIt = m_nameToObjectGroup.find(groupName); |
| 82 if (groupIt == m_nameToObjectGroup.end()) | 78 if (groupIt == m_nameToObjectGroup.end()) |
| 83 return; | 79 return; |
| 84 for (int id : *groupIt->second) | 80 for (int id : groupIt->second) |
| 85 unbind(id); | 81 unbind(id); |
| 86 m_nameToObjectGroup.remove(groupName); | 82 m_nameToObjectGroup.erase(groupIt); |
| 87 } | 83 } |
| 88 | 84 |
| 89 String16 InjectedScriptNative::groupName(int objectId) const | 85 String16 InjectedScriptNative::groupName(int objectId) const |
| 90 { | 86 { |
| 91 if (objectId <= 0) | 87 if (objectId <= 0) |
| 92 return String16(); | 88 return String16(); |
| 93 return m_idToObjectGroupName.get(objectId); | 89 IdToObjectGroupName::const_iterator iterator = m_idToObjectGroupName.find(ob
jectId); |
| 90 return iterator != m_idToObjectGroupName.end() ? iterator->second : String16
(); |
| 94 } | 91 } |
| 95 | 92 |
| 96 } // namespace blink | 93 } // namespace blink |
| 97 | 94 |
| OLD | NEW |