WebInjectedScriptManager.cpp [plain text]
#include "config.h"
#include "WebInjectedScriptManager.h"
#if ENABLE(INSPECTOR)
#include "CommandLineAPIModule.h"
#include "ScriptState.h"
using namespace Inspector;
namespace WebCore {
WebInjectedScriptManager::WebInjectedScriptManager(InspectorEnvironment& environment, PassRefPtr<InjectedScriptHost> host)
: InjectedScriptManager(environment, host)
, m_commandLineAPIHost(CommandLineAPIHost::create())
{
}
void WebInjectedScriptManager::disconnect()
{
InjectedScriptManager::disconnect();
m_commandLineAPIHost->disconnect();
m_commandLineAPIHost.clear();
}
void WebInjectedScriptManager::didCreateInjectedScript(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::ExecState* scriptState = it.value.scriptState();
if (window != domWindowFromExecState(scriptState))
continue;
m_scriptStateToId.remove(scriptState);
idsToRemove.append(it.key);
}
for (size_t i = 0; i < idsToRemove.size(); i++)
m_idToInjectedScript.remove(idsToRemove[i]);
Vector<JSC::ExecState*> scriptStatesToRemove;
for (const auto& it : m_scriptStateToId) {
JSC::ExecState* scriptState = it.key;
if (window == domWindowFromExecState(scriptState))
scriptStatesToRemove.append(scriptState);
}
for (size_t i = 0; i < scriptStatesToRemove.size(); i++)
m_scriptStateToId.remove(scriptStatesToRemove[i]);
}
}
#endif // ENABLE(INSPECTOR)