WebInjectedScriptManager.cpp [plain text]
#include "config.h"
#include "WebInjectedScriptManager.h"
#include "CommandLineAPIModule.h"
#include "ScriptState.h"
namespace WebCore {
using namespace Inspector;
WebInjectedScriptManager::WebInjectedScriptManager(InspectorEnvironment& environment, Ref<InjectedScriptHost>&& host)
: InjectedScriptManager(environment, WTFMove(host))
{
}
void WebInjectedScriptManager::connect()
{
InjectedScriptManager::connect();
m_commandLineAPIHost = CommandLineAPIHost::create();
}
void WebInjectedScriptManager::disconnect()
{
InjectedScriptManager::disconnect();
if (m_commandLineAPIHost) {
m_commandLineAPIHost->disconnect();
m_commandLineAPIHost = nullptr;
}
}
void WebInjectedScriptManager::discardInjectedScripts()
{
InjectedScriptManager::discardInjectedScripts();
if (m_commandLineAPIHost)
m_commandLineAPIHost->clearAllWrappers();
}
void WebInjectedScriptManager::didCreateInjectedScript(const Inspector::InjectedScript& injectedScript)
{
CommandLineAPIModule::injectIfNeeded(this, injectedScript);
}
void WebInjectedScriptManager::discardInjectedScriptsFor(DOMWindow* window)
{
if (m_scriptStateToId.isEmpty())
return;
Vector<long> idsToRemove;
for (const auto& it : m_idToInjectedScript) {
JSC::JSGlobalObject* lexicalGlobalObject = it.value.globalObject();
if (window != domWindowFromExecState(lexicalGlobalObject))
continue;
m_scriptStateToId.remove(lexicalGlobalObject);
idsToRemove.append(it.key);
}
for (auto& id : idsToRemove)
m_idToInjectedScript.remove(id);
Vector<JSC::JSGlobalObject*> scriptStatesToRemove;
for (const auto& it : m_scriptStateToId) {
JSC::JSGlobalObject* lexicalGlobalObject = it.key;
if (window == domWindowFromExecState(lexicalGlobalObject))
scriptStatesToRemove.append(lexicalGlobalObject);
}
for (auto& lexicalGlobalObject : scriptStatesToRemove)
m_scriptStateToId.remove(lexicalGlobalObject);
}
}