| Index: Source/core/inspector/InjectedScriptManager.cpp
|
| diff --git a/Source/core/inspector/InjectedScriptManager.cpp b/Source/core/inspector/InjectedScriptManager.cpp
|
| index 03d76176584a059972ac4057c1858ed49f572568..4f291613a29dee223c638364e24022be272d4646 100644
|
| --- a/Source/core/inspector/InjectedScriptManager.cpp
|
| +++ b/Source/core/inspector/InjectedScriptManager.cpp
|
| @@ -32,6 +32,8 @@
|
| #include "core/inspector/InjectedScriptManager.h"
|
|
|
| #include "InjectedScriptSource.h"
|
| +#include "bindings/dart/DartInjectedScript.h"
|
| +#include "bindings/dart/DartScriptState.h"
|
| #include "bindings/v8/ScriptObject.h"
|
| #include "core/inspector/InjectedScript.h"
|
| #include "core/inspector/InjectedScriptHost.h"
|
| @@ -55,11 +57,13 @@ InjectedScriptManager::InjectedScriptManager(InspectedStateAccessCheck accessChe
|
| : m_nextInjectedScriptId(1)
|
| , m_injectedScriptHost(InjectedScriptHost::create())
|
| , m_inspectedStateAccessCheck(accessCheck)
|
| + , m_placeholderInjectedScript(0)
|
| {
|
| }
|
|
|
| InjectedScriptManager::~InjectedScriptManager()
|
| {
|
| + delete m_placeholderInjectedScript;
|
| }
|
|
|
| void InjectedScriptManager::disconnect()
|
| @@ -68,21 +72,28 @@ void InjectedScriptManager::disconnect()
|
| m_injectedScriptHost.clear();
|
| }
|
|
|
| +InjectedScript& InjectedScriptManager::placeholderInjectedScript()
|
| +{
|
| + if (!m_placeholderInjectedScript)
|
| + m_placeholderInjectedScript = new V8InjectedScript();
|
| + return *m_placeholderInjectedScript;
|
| +}
|
| +
|
| InjectedScriptHost* InjectedScriptManager::injectedScriptHost()
|
| {
|
| return m_injectedScriptHost.get();
|
| }
|
|
|
| -InjectedScript InjectedScriptManager::injectedScriptForId(int id)
|
| +InjectedScript& InjectedScriptManager::injectedScriptForId(int id)
|
| {
|
| IdToInjectedScriptMap::iterator it = m_idToInjectedScript.find(id);
|
| if (it != m_idToInjectedScript.end())
|
| - return it->value;
|
| + return *(it->value);
|
| for (ScriptStateToId::iterator it = m_scriptStateToId.begin(); it != m_scriptStateToId.end(); ++it) {
|
| if (it->value == id)
|
| return injectedScriptFor(it->key.get());
|
| }
|
| - return InjectedScript();
|
| + return placeholderInjectedScript();
|
| }
|
|
|
| int InjectedScriptManager::injectedScriptIdFor(ScriptState* scriptState)
|
| @@ -95,16 +106,19 @@ int InjectedScriptManager::injectedScriptIdFor(ScriptState* scriptState)
|
| return id;
|
| }
|
|
|
| -InjectedScript InjectedScriptManager::injectedScriptForObjectId(const String& objectId)
|
| +InjectedScript& InjectedScriptManager::injectedScriptForObjectId(const String& objectId)
|
| {
|
| RefPtr<JSONValue> parsedObjectId = parseJSON(objectId);
|
| if (parsedObjectId && parsedObjectId->type() == JSONValue::TypeObject) {
|
| long injectedScriptId = 0;
|
| bool success = parsedObjectId->asObject()->getNumber("injectedScriptId", &injectedScriptId);
|
| - if (success)
|
| - return m_idToInjectedScript.get(injectedScriptId);
|
| + if (success) {
|
| + IdToInjectedScriptMap::iterator s = m_idToInjectedScript.find(injectedScriptId);
|
| + if (s != m_idToInjectedScript.end())
|
| + return *(s->value);
|
| + }
|
| }
|
| - return InjectedScript();
|
| + return placeholderInjectedScript();
|
| }
|
|
|
| void InjectedScriptManager::discardInjectedScripts()
|
| @@ -121,14 +135,17 @@ void InjectedScriptManager::discardInjectedScriptsFor(DOMWindow* window)
|
| Vector<long> idsToRemove;
|
| IdToInjectedScriptMap::iterator end = m_idToInjectedScript.end();
|
| for (IdToInjectedScriptMap::iterator it = m_idToInjectedScript.begin(); it != end; ++it) {
|
| - ScriptState* scriptState = it->value.scriptState();
|
| + ScriptState* scriptState = it->value->scriptState();
|
| if (window != scriptState->domWindow())
|
| continue;
|
| m_scriptStateToId.remove(scriptState);
|
| idsToRemove.append(it->key);
|
| }
|
| + for (size_t i = 0; i < idsToRemove.size(); i++)
|
| + delete m_idToInjectedScript.get(idsToRemove[i]);
|
| m_idToInjectedScript.removeAll(idsToRemove);
|
|
|
| +
|
| // Now remove script states that have id but no injected script.
|
| Vector<ScriptState*> scriptStatesToRemove;
|
| for (ScriptStateToId::iterator it = m_scriptStateToId.begin(); it != m_scriptStateToId.end(); ++it) {
|
| @@ -151,7 +168,7 @@ void InjectedScriptManager::releaseObjectGroup(const String& objectGroup)
|
| for (Vector<int>::iterator k = keys.begin(); k != keys.end(); ++k) {
|
| IdToInjectedScriptMap::iterator s = m_idToInjectedScript.find(*k);
|
| if (s != m_idToInjectedScript.end())
|
| - s->value.releaseObjectGroup(objectGroup); // m_idToInjectedScript may change here.
|
| + s->value->releaseObjectGroup(objectGroup); // m_idToInjectedScript may change here.
|
| }
|
| }
|
|
|
| @@ -160,23 +177,29 @@ String InjectedScriptManager::injectedScriptSource()
|
| return String(reinterpret_cast<const char*>(InjectedScriptSource_js), sizeof(InjectedScriptSource_js));
|
| }
|
|
|
| -InjectedScript InjectedScriptManager::injectedScriptFor(ScriptState* inspectedScriptState)
|
| +InjectedScript& InjectedScriptManager::injectedScriptFor(ScriptState* inspectedScriptState)
|
| {
|
| ScriptStateToId::iterator it = m_scriptStateToId.find(inspectedScriptState);
|
| if (it != m_scriptStateToId.end()) {
|
| IdToInjectedScriptMap::iterator it1 = m_idToInjectedScript.find(it->value);
|
| if (it1 != m_idToInjectedScript.end())
|
| - return it1->value;
|
| + return *(it1->value);
|
| }
|
|
|
| if (!m_inspectedStateAccessCheck(inspectedScriptState))
|
| - return InjectedScript();
|
| + return placeholderInjectedScript();
|
|
|
| int id = injectedScriptIdFor(inspectedScriptState);
|
| - ScriptObject injectedScriptObject = createInjectedScript(injectedScriptSource(), inspectedScriptState, id);
|
| - InjectedScript result(injectedScriptObject, m_inspectedStateAccessCheck);
|
| +
|
| + InjectedScript* result;
|
| + if (inspectedScriptState->isJavaScript()) {
|
| + ScriptObject injectedScriptObject = createInjectedScript(injectedScriptSource(), inspectedScriptState, id);
|
| + result = new V8InjectedScript(injectedScriptObject, m_inspectedStateAccessCheck);
|
| + } else {
|
| + result = new DartInjectedScript(static_cast<DartScriptState*>(inspectedScriptState), m_inspectedStateAccessCheck, id, injectedScriptHost());
|
| + }
|
| m_idToInjectedScript.set(id, result);
|
| - return result;
|
| + return *result;
|
| }
|
|
|
| } // namespace WebCore
|
|
|