| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> | 3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> |
| 4 * Copyright (C) 2012 Google Inc. All rights reserved. | 4 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * | 9 * |
| 10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 | 62 |
| 63 InjectedScriptHost* InjectedScriptManager::injectedScriptHost() | 63 InjectedScriptHost* InjectedScriptManager::injectedScriptHost() |
| 64 { | 64 { |
| 65 return m_injectedScriptHost.get(); | 65 return m_injectedScriptHost.get(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 InjectedScript* InjectedScriptManager::findInjectedScript(int id) const | 68 InjectedScript* InjectedScriptManager::findInjectedScript(int id) const |
| 69 { | 69 { |
| 70 IdToInjectedScriptMap::const_iterator it = m_idToInjectedScript.find(id); | 70 IdToInjectedScriptMap::const_iterator it = m_idToInjectedScript.find(id); |
| 71 if (it != m_idToInjectedScript.end()) | 71 if (it != m_idToInjectedScript.end()) |
| 72 return it->value.get(); | 72 return it->second; |
| 73 return nullptr; | 73 return nullptr; |
| 74 } | 74 } |
| 75 | 75 |
| 76 InjectedScript* InjectedScriptManager::findInjectedScript(RemoteObjectIdBase* ob
jectId) const | 76 InjectedScript* InjectedScriptManager::findInjectedScript(RemoteObjectIdBase* ob
jectId) const |
| 77 { | 77 { |
| 78 return objectId ? findInjectedScript(objectId->contextId()) : nullptr; | 78 return objectId ? findInjectedScript(objectId->contextId()) : nullptr; |
| 79 } | 79 } |
| 80 | 80 |
| 81 void InjectedScriptManager::discardInjectedScripts() | 81 void InjectedScriptManager::discardInjectedScripts() |
| 82 { | 82 { |
| 83 m_idToInjectedScript.clear(); | 83 m_idToInjectedScript.clear(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 int InjectedScriptManager::discardInjectedScriptFor(v8::Local<v8::Context> conte
xt) | 86 int InjectedScriptManager::discardInjectedScriptFor(v8::Local<v8::Context> conte
xt) |
| 87 { | 87 { |
| 88 int contextId = V8Debugger::contextId(context); | 88 int contextId = V8Debugger::contextId(context); |
| 89 discardInjectedScript(contextId); | 89 discardInjectedScript(contextId); |
| 90 return contextId; | 90 return contextId; |
| 91 } | 91 } |
| 92 | 92 |
| 93 void InjectedScriptManager::discardInjectedScript(int contextId) | 93 void InjectedScriptManager::discardInjectedScript(int contextId) |
| 94 { | 94 { |
| 95 m_idToInjectedScript.remove(contextId); | 95 m_idToInjectedScript.remove(contextId); |
| 96 } | 96 } |
| 97 | 97 |
| 98 void InjectedScriptManager::releaseObjectGroup(const String& objectGroup) | 98 void InjectedScriptManager::releaseObjectGroup(const String& objectGroup) |
| 99 { | 99 { |
| 100 Vector<int> keys; | 100 protocol::Vector<int> keys; |
| 101 keys.appendRange(m_idToInjectedScript.keys().begin(), m_idToInjectedScript.k
eys().end()); | 101 for (auto& it : m_idToInjectedScript) |
| 102 keys.append(it.first); |
| 102 for (auto& key : keys) { | 103 for (auto& key : keys) { |
| 103 IdToInjectedScriptMap::iterator s = m_idToInjectedScript.find(key); | 104 if (m_idToInjectedScript.contains(key)) // m_idToInjectedScript may chan
ge here. |
| 104 if (s != m_idToInjectedScript.end()) | 105 m_idToInjectedScript.get(key)->releaseObjectGroup(objectGroup); |
| 105 s->value->releaseObjectGroup(objectGroup); // m_idToInjectedScript m
ay change here. | |
| 106 } | 106 } |
| 107 } | 107 } |
| 108 | 108 |
| 109 void InjectedScriptManager::setCustomObjectFormatterEnabled(bool enabled) | 109 void InjectedScriptManager::setCustomObjectFormatterEnabled(bool enabled) |
| 110 { | 110 { |
| 111 m_customObjectFormatterEnabled = enabled; | 111 m_customObjectFormatterEnabled = enabled; |
| 112 IdToInjectedScriptMap::iterator end = m_idToInjectedScript.end(); | 112 IdToInjectedScriptMap::iterator end = m_idToInjectedScript.end(); |
| 113 for (IdToInjectedScriptMap::iterator it = m_idToInjectedScript.begin(); it !
= end; ++it) { | 113 for (IdToInjectedScriptMap::iterator it = m_idToInjectedScript.begin(); it !
= end; ++it) { |
| 114 it->value->setCustomObjectFormatterEnabled(enabled); | 114 it->second->setCustomObjectFormatterEnabled(enabled); |
| 115 } | 115 } |
| 116 } | 116 } |
| 117 | 117 |
| 118 InjectedScript* InjectedScriptManager::injectedScriptFor(v8::Local<v8::Context>
context) | 118 InjectedScript* InjectedScriptManager::injectedScriptFor(v8::Local<v8::Context>
context) |
| 119 { | 119 { |
| 120 v8::Context::Scope scope(context); | 120 v8::Context::Scope scope(context); |
| 121 int contextId = V8Debugger::contextId(context); | 121 int contextId = V8Debugger::contextId(context); |
| 122 | 122 |
| 123 IdToInjectedScriptMap::iterator it = m_idToInjectedScript.find(contextId); | 123 IdToInjectedScriptMap::iterator it = m_idToInjectedScript.find(contextId); |
| 124 if (it != m_idToInjectedScript.end()) | 124 if (it != m_idToInjectedScript.end()) |
| 125 return it->value.get(); | 125 return it->second; |
| 126 | 126 |
| 127 v8::Local<v8::Context> callingContext = context->GetIsolate()->GetCallingCon
text(); | 127 v8::Local<v8::Context> callingContext = context->GetIsolate()->GetCallingCon
text(); |
| 128 if (!callingContext.IsEmpty() && !m_client->callingContextCanAccessContext(c
allingContext, context)) | 128 if (!callingContext.IsEmpty() && !m_client->callingContextCanAccessContext(c
allingContext, context)) |
| 129 return nullptr; | 129 return nullptr; |
| 130 | 130 |
| 131 OwnPtr<InjectedScriptNative> injectedScriptNative = adoptPtr(new InjectedScr
iptNative(context->GetIsolate())); | 131 OwnPtr<InjectedScriptNative> injectedScriptNative = adoptPtr(new InjectedScr
iptNative(context->GetIsolate())); |
| 132 String injectedScriptSource(reinterpret_cast<const char*>(InjectedScriptSour
ce_js), sizeof(InjectedScriptSource_js)); | 132 String injectedScriptSource(reinterpret_cast<const char*>(InjectedScriptSour
ce_js), sizeof(InjectedScriptSource_js)); |
| 133 | 133 |
| 134 v8::Local<v8::Object> object = createInjectedScript(injectedScriptSource, co
ntext, contextId, injectedScriptNative.get()); | 134 v8::Local<v8::Object> object = createInjectedScript(injectedScriptSource, co
ntext, contextId, injectedScriptNative.get()); |
| 135 OwnPtr<InjectedScript> result = adoptPtr(new InjectedScript(this, context, o
bject, m_client, injectedScriptNative.release(), contextId)); | 135 OwnPtr<InjectedScript> result = adoptPtr(new InjectedScript(this, context, o
bject, m_client, injectedScriptNative.release(), contextId)); |
| 136 InjectedScript* resultPtr = result.get(); | 136 InjectedScript* resultPtr = result.get(); |
| 137 if (m_customObjectFormatterEnabled) | 137 if (m_customObjectFormatterEnabled) |
| 138 result->setCustomObjectFormatterEnabled(m_customObjectFormatterEnabled); | 138 result->setCustomObjectFormatterEnabled(m_customObjectFormatterEnabled); |
| 139 m_idToInjectedScript.set(contextId, result.release()); | 139 m_idToInjectedScript.set(contextId, result.release()); |
| 140 |
| 140 return resultPtr; | 141 return resultPtr; |
| 141 } | 142 } |
| 142 | 143 |
| 143 v8::Local<v8::Object> InjectedScriptManager::createInjectedScript(const String&
source, v8::Local<v8::Context> context, int id, InjectedScriptNative* injectedSc
riptNative) | 144 v8::Local<v8::Object> InjectedScriptManager::createInjectedScript(const String&
source, v8::Local<v8::Context> context, int id, InjectedScriptNative* injectedSc
riptNative) |
| 144 { | 145 { |
| 145 v8::Isolate* isolate = context->GetIsolate(); | 146 v8::Isolate* isolate = context->GetIsolate(); |
| 146 v8::Context::Scope scope(context); | 147 v8::Context::Scope scope(context); |
| 147 | 148 |
| 148 v8::Local<v8::FunctionTemplate> wrapperTemplate = m_injectedScriptHost->wrap
perTemplate(isolate); | 149 v8::Local<v8::FunctionTemplate> wrapperTemplate = m_injectedScriptHost->wrap
perTemplate(isolate); |
| 149 if (wrapperTemplate.IsEmpty()) { | 150 if (wrapperTemplate.IsEmpty()) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 171 v8::Local<v8::Value> info[] = { scriptHostWrapper, windowGlobal, v8::Number:
:New(context->GetIsolate(), id) }; | 172 v8::Local<v8::Value> info[] = { scriptHostWrapper, windowGlobal, v8::Number:
:New(context->GetIsolate(), id) }; |
| 172 v8::Local<v8::Value> injectedScriptValue; | 173 v8::Local<v8::Value> injectedScriptValue; |
| 173 if (!m_client->callInternalFunction(v8::Local<v8::Function>::Cast(value), wi
ndowGlobal, WTF_ARRAY_LENGTH(info), info).ToLocal(&injectedScriptValue)) | 174 if (!m_client->callInternalFunction(v8::Local<v8::Function>::Cast(value), wi
ndowGlobal, WTF_ARRAY_LENGTH(info), info).ToLocal(&injectedScriptValue)) |
| 174 return v8::Local<v8::Object>(); | 175 return v8::Local<v8::Object>(); |
| 175 if (!injectedScriptValue->IsObject()) | 176 if (!injectedScriptValue->IsObject()) |
| 176 return v8::Local<v8::Object>(); | 177 return v8::Local<v8::Object>(); |
| 177 return injectedScriptValue.As<v8::Object>(); | 178 return injectedScriptValue.As<v8::Object>(); |
| 178 } | 179 } |
| 179 | 180 |
| 180 } // namespace blink | 181 } // namespace blink |
| OLD | NEW |