InjectedScript InjectedScriptManager::injectedScriptFor(ScriptState* inspectedScriptState)
{
    v8::HandleScope handleScope;
    v8::Local<v8::Context> context = inspectedScriptState->context();
    v8::Context::Scope contextScope(context);

    v8::Local<v8::Object> global = context->Global();
    // Skip proxy object. The proxy object will survive page navigation while we need
    // an object whose lifetime consides with that of the inspected context.
    global = v8::Local<v8::Object>::Cast(global->GetPrototype());

    v8::Handle<v8::String> key = V8HiddenPropertyName::devtoolsInjectedScript();
    v8::Local<v8::Value> val = global->GetHiddenValue(key);
    if (!val.IsEmpty() && val->IsObject())
        return InjectedScript(ScriptObject(inspectedScriptState, v8::Local<v8::Object>::Cast(val)), m_inspectedStateAccessCheck);

    if (!m_inspectedStateAccessCheck(inspectedScriptState))
        return InjectedScript();

    pair<long, ScriptObject> injectedScript = injectScript(injectedScriptSource(), inspectedScriptState);
    InjectedScript result(injectedScript.second, m_inspectedStateAccessCheck);
    m_idToInjectedScript.set(injectedScript.first, result);
    global->SetHiddenValue(key, injectedScript.second.v8Object());
    return result;
}
Ejemplo n.º 2
0
InjectedScript InjectedScriptManager::injectedScriptFor(JSC::ExecState* inspectedExecState)
{
    ExecStateToId::iterator it = m_scriptStateToId.find(inspectedExecState);
    if (it != m_scriptStateToId.end()) {
        IdToInjectedScriptMap::iterator it1 = m_idToInjectedScript.find(it->value);
        if (it1 != m_idToInjectedScript.end())
            return it1->value;
    }

    if (!m_inspectedStateAccessCheck(inspectedExecState))
        return InjectedScript();

    int id = injectedScriptIdFor(inspectedExecState);
    ScriptObject injectedScriptObject = createInjectedScript(injectedScriptSource(), inspectedExecState, id);
    InjectedScript result(injectedScriptObject, m_inspectedStateAccessCheck);
    m_idToInjectedScript.set(id, result);
    return result;
}
Ejemplo n.º 3
0
bool InjectedScriptBase::canAccessInspectedWindow() const
{
    return m_inspectedStateAccessCheck(m_injectedScriptObject.scriptState());
}
bool InjectedScript::canAccessInspectedWindow() const
{
    ASSERT(!isEmpty());
    return m_inspectedStateAccessCheck(m_injectedScriptObject.scriptState());
}