WebInjectedScriptManager.cpp [plain text]
#include "config.h"
#include "WebInjectedScriptManager.h"
#include "CommandLineAPIModule.h"
#include "ScriptState.h"
using namespace Inspector;
namespace WebCore {
WebInjectedScriptManager::WebInjectedScriptManager(InspectorEnvironment& environment, RefPtr<InjectedScriptHost>&& host)
: InjectedScriptManager(environment, WTFMove(host))
, m_commandLineAPIHost(CommandLineAPIHost::create())
{
}
void WebInjectedScriptManager::disconnect()
{
InjectedScriptManager::disconnect();
m_commandLineAPIHost->disconnect();
m_commandLineAPIHost = nullptr;
}
void WebInjectedScriptManager::discardInjectedScripts()
{
InjectedScriptManager::discardInjectedScripts();
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::ExecState* scriptState = it.value.scriptState();
if (window != domWindowFromExecState(scriptState))
continue;
m_scriptStateToId.remove(scriptState);
idsToRemove.append(it.key);
}
for (auto& id : idsToRemove)
m_idToInjectedScript.remove(id);
Vector<JSC::ExecState*> scriptStatesToRemove;
for (const auto& it : m_scriptStateToId) {
JSC::ExecState* scriptState = it.key;
if (window == domWindowFromExecState(scriptState))
scriptStatesToRemove.append(scriptState);
}
for (auto& scriptState : scriptStatesToRemove)
m_scriptStateToId.remove(scriptState);
}
}