Index: Source/bindings/core/dart/DartInjectedScriptManager.cpp |
diff --git a/Source/core/inspector/InjectedScriptManager.cpp b/Source/bindings/core/dart/DartInjectedScriptManager.cpp |
similarity index 53% |
copy from Source/core/inspector/InjectedScriptManager.cpp |
copy to Source/bindings/core/dart/DartInjectedScriptManager.cpp |
index c50a7d1d5c7b7b16241ffd23ab88f2b295a559a8..6bced3471e1e9522b29e08d1aec7a75386aaa8bf 100644 |
--- a/Source/core/inspector/InjectedScriptManager.cpp |
+++ b/Source/bindings/core/dart/DartInjectedScriptManager.cpp |
@@ -29,12 +29,13 @@ |
*/ |
#include "config.h" |
-#include "core/inspector/InjectedScriptManager.h" |
+#include "bindings/core/dart/DartInjectedScriptManager.h" |
-#include "bindings/core/v8/ScriptValue.h" |
-#include "core/inspector/InjectedScript.h" |
+#include "bindings/common/ScriptValue.h" |
+#include "bindings/core/dart/DartInjectedScript.h" |
+#include "bindings/core/dart/DartScriptState.h" |
#include "core/inspector/InjectedScriptHost.h" |
-#include "core/inspector/InjectedScriptNative.h" |
+#include "core/inspector/InjectedScriptManager.h" |
#include "core/inspector/JSONParser.h" |
#include "platform/JSONValues.h" |
#include "public/platform/Platform.h" |
@@ -43,57 +44,35 @@ |
namespace blink { |
-PassOwnPtrWillBeRawPtr<InjectedScriptManager> InjectedScriptManager::createForPage() |
-{ |
- return adoptPtrWillBeNoop(new InjectedScriptManager(&InjectedScriptManager::canAccessInspectedWindow)); |
-} |
- |
-PassOwnPtrWillBeRawPtr<InjectedScriptManager> InjectedScriptManager::createForWorker() |
-{ |
- return adoptPtrWillBeNoop(new InjectedScriptManager(&InjectedScriptManager::canAccessInspectedWorkerGlobalScope)); |
-} |
- |
-InjectedScriptManager::InjectedScriptManager(InspectedStateAccessCheck accessCheck) |
- : m_nextInjectedScriptId(1) |
- , m_injectedScriptHost(InjectedScriptHost::create()) |
+DartInjectedScriptManager::DartInjectedScriptManager(InspectedStateAccessCheck accessCheck, InjectedScriptManager* javaScriptInjectedScriptManager) |
+ : m_nextInjectedScriptId(1000000000) // Elegant design so that Dart and JavaScript ids don't overlap. |
, m_inspectedStateAccessCheck(accessCheck) |
- , m_customObjectFormatterEnabled(false) |
+ , m_javaScriptInjectedScriptManager(javaScriptInjectedScriptManager) |
{ |
} |
-InjectedScriptManager::~InjectedScriptManager() |
+DartInjectedScriptManager::~DartInjectedScriptManager() |
{ |
} |
-DEFINE_TRACE(InjectedScriptManager) |
+InjectedScriptHost* DartInjectedScriptManager::injectedScriptHost() |
{ |
- visitor->trace(m_injectedScriptHost); |
+ return m_javaScriptInjectedScriptManager->injectedScriptHost(); |
} |
-void InjectedScriptManager::disconnect() |
-{ |
- m_injectedScriptHost->disconnect(); |
- m_injectedScriptHost.clear(); |
-} |
- |
-InjectedScriptHost* InjectedScriptManager::injectedScriptHost() |
-{ |
- return m_injectedScriptHost.get(); |
-} |
- |
-InjectedScript InjectedScriptManager::injectedScriptForId(int id) |
+DartInjectedScript* DartInjectedScriptManager::injectedScriptForId(int id) |
{ |
IdToInjectedScriptMap::iterator it = m_idToInjectedScript.find(id); |
if (it != m_idToInjectedScript.end()) |
return it->value; |
- for (auto& state : m_scriptStateToId) { |
- if (state.value == id) |
- return injectedScriptFor(state.key.get()); |
+ for (ScriptStateToId::iterator it = m_scriptStateToId.begin(); it != m_scriptStateToId.end(); ++it) { |
+ if (it->value == id) |
+ return injectedScriptFor(it->key.get()); |
} |
- return InjectedScript(); |
+ return 0; |
} |
-int InjectedScriptManager::injectedScriptIdFor(ScriptState* scriptState) |
+int DartInjectedScriptManager::injectedScriptIdFor(ScriptState* scriptState) |
{ |
ScriptStateToId::iterator it = m_scriptStateToId.find(scriptState); |
if (it != m_scriptStateToId.end()) |
@@ -103,68 +82,76 @@ int InjectedScriptManager::injectedScriptIdFor(ScriptState* scriptState) |
return id; |
} |
-InjectedScript InjectedScriptManager::injectedScriptForObjectId(const String& objectId) |
+DartInjectedScript* DartInjectedScriptManager::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 0; |
} |
-void InjectedScriptManager::discardInjectedScripts() |
+void DartInjectedScriptManager::discardInjectedScripts() |
{ |
m_idToInjectedScript.clear(); |
m_scriptStateToId.clear(); |
} |
-void InjectedScriptManager::discardInjectedScriptFor(ScriptState* scriptState) |
+void DartInjectedScriptManager::discardInjectedScriptsFor(LocalDOMWindow* window) |
{ |
- ScriptStateToId::iterator it = m_scriptStateToId.find(scriptState); |
- if (it == m_scriptStateToId.end()) |
+ if (m_scriptStateToId.isEmpty()) |
return; |
- m_idToInjectedScript.remove(it->value); |
- m_scriptStateToId.remove(it); |
+ Vector<long> idsToRemove; |
+ IdToInjectedScriptMap::iterator end = m_idToInjectedScript.end(); |
+ for (IdToInjectedScriptMap::iterator it = m_idToInjectedScript.begin(); it != end; ++it) { |
+ 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) { |
+ ScriptState* scriptState = it->key.get(); |
+ if (window == scriptState->domWindow()) |
+ scriptStatesToRemove.append(scriptState); |
+ } |
+ m_scriptStateToId.removeAll(scriptStatesToRemove); |
} |
-bool InjectedScriptManager::canAccessInspectedWorkerGlobalScope(ScriptState*) |
+bool DartInjectedScriptManager::canAccessInspectedWorkerGlobalScope(ScriptState*) |
{ |
return true; |
} |
-void InjectedScriptManager::releaseObjectGroup(const String& objectGroup) |
+void DartInjectedScriptManager::releaseObjectGroup(const String& objectGroup) |
{ |
Vector<int> keys; |
keys.appendRange(m_idToInjectedScript.keys().begin(), m_idToInjectedScript.keys().end()); |
- for (auto& key : keys) { |
- IdToInjectedScriptMap::iterator s = m_idToInjectedScript.find(key); |
+ 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. |
- } |
-} |
- |
-void InjectedScriptManager::setCustomObjectFormatterEnabled(bool enabled) |
-{ |
- m_customObjectFormatterEnabled = enabled; |
- IdToInjectedScriptMap::iterator end = m_idToInjectedScript.end(); |
- for (IdToInjectedScriptMap::iterator it = m_idToInjectedScript.begin(); it != end; ++it) { |
- if (!it->value.isEmpty()) |
- it->value.setCustomObjectFormatterEnabled(enabled); |
+ s->value->releaseObjectGroup(objectGroup); // m_idToInjectedScript may change here. |
} |
} |
-String InjectedScriptManager::injectedScriptSource() |
-{ |
- const WebData& injectedScriptSourceResource = Platform::current()->loadResource("InjectedScriptSource.js"); |
- return String(injectedScriptSourceResource.data(), injectedScriptSourceResource.size()); |
-} |
- |
-InjectedScript InjectedScriptManager::injectedScriptFor(ScriptState* inspectedScriptState) |
+DartInjectedScript* DartInjectedScriptManager::injectedScriptFor(ScriptState* inspectedScriptState) |
{ |
+ if (!inspectedScriptState) |
+ return 0; |
ScriptStateToId::iterator it = m_scriptStateToId.find(inspectedScriptState); |
if (it != m_scriptStateToId.end()) { |
IdToInjectedScriptMap::iterator it1 = m_idToInjectedScript.find(it->value); |
@@ -173,16 +160,16 @@ InjectedScript InjectedScriptManager::injectedScriptFor(ScriptState* inspectedSc |
} |
if (!m_inspectedStateAccessCheck(inspectedScriptState)) |
- return InjectedScript(); |
+ return 0; |
int id = injectedScriptIdFor(inspectedScriptState); |
- RefPtr<InjectedScriptNative> injectedScriptNative = adoptRef(new InjectedScriptNative(inspectedScriptState->isolate())); |
- ScriptValue injectedScriptValue = createInjectedScript(injectedScriptSource(), inspectedScriptState, id, injectedScriptNative.get()); |
- InjectedScript result(injectedScriptValue, m_inspectedStateAccessCheck, injectedScriptNative.release()); |
- if (m_customObjectFormatterEnabled) |
- result.setCustomObjectFormatterEnabled(m_customObjectFormatterEnabled); |
+ |
+ DartInjectedScript* result; |
+ ASSERT(!inspectedScriptState->isJavaScript()); |
+ result = new DartInjectedScript(static_cast<DartScriptState*>(inspectedScriptState), m_inspectedStateAccessCheck, id, injectedScriptHost(), m_javaScriptInjectedScriptManager); |
m_idToInjectedScript.set(id, result); |
return result; |
} |
} // namespace blink |
+ |