void InjectedScriptManager::discardInjectedScriptsFor(DOMWindow* window)
{
    if (m_scriptStateToId.isEmpty())
        return;

    Vector<long> idsToRemove;
    IdToInjectedScriptMap::iterator end = m_idToInjectedScript.end();
    for (IdToInjectedScriptMap::iterator it = m_idToInjectedScript.begin(); it != end; ++it) {
        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]);

    // Now remove script states that have id but no injected script.
    Vector<JSC::ExecState*> scriptStatesToRemove;
    for (ExecStateToId::iterator it = m_scriptStateToId.begin(); it != m_scriptStateToId.end(); ++it) {
        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]);
}
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]);

    // Now remove script states that have id but no injected script.
    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]);
}
void ConsoleMessage::windowCleared(DOMWindow* window)
{
    if (!m_arguments)
        return;
    if (domWindowFromExecState(m_arguments->globalState()) != window)
        return;
    if (!m_message)
        m_message = "<message collected>";
    m_arguments.clear();
}
Exemple #4
0
void WebConsoleAgent::frameWindowDiscarded(DOMWindow* window)
{
    for (auto& message : m_consoleMessages) {
        JSC::ExecState* exec = message->scriptState();
        if (!exec)
            continue;
        if (domWindowFromExecState(exec) != window)
            continue;
        message->clear();
    }

    static_cast<WebInjectedScriptManager&>(m_injectedScriptManager).discardInjectedScriptsFor(window);
}