InjectedScript WorkerDebuggerAgent::injectedScriptForEval(ErrorString* error, const int* executionContextId)
{
    if (!executionContextId)
        return injectedScriptManager()->injectedScriptFor(m_inspectedWorkerGlobalScope->script()->scriptState());

    InjectedScript injectedScript = injectedScriptManager()->injectedScriptForId(*executionContextId);
    if (injectedScript.isEmpty())
        *error = "Execution context with given id not found.";
    return injectedScript;
}
InjectedScript PageDebuggerAgent::injectedScriptForEval(ErrorString* errorString, const int* executionContextId)
{
    if (!executionContextId) {
        JSC::ExecState* scriptState = mainWorldExecState(m_pageAgent->mainFrame());
        return injectedScriptManager()->injectedScriptFor(scriptState);
    }
    InjectedScript injectedScript = injectedScriptManager()->injectedScriptForId(*executionContextId);
    if (injectedScript.hasNoValue())
        *errorString = "Execution context with given id not found.";
    return injectedScript;
}
Esempio n. 3
0
InjectedScript PageRuntimeAgent::injectedScriptForEval(ErrorString* errorString, const int* executionContextId)
{
    if (!executionContextId) {
        JSC::ExecState* scriptState = mainWorldExecState(&m_inspectedPage->mainFrame());
        InjectedScript result = injectedScriptManager()->injectedScriptFor(scriptState);
        if (result.hasNoValue())
            *errorString = "Internal error: main world execution context not found.";
        return result;
    }
    InjectedScript injectedScript = injectedScriptManager()->injectedScriptForId(*executionContextId);
    if (injectedScript.hasNoValue())
        *errorString = "Execution context with given id not found.";
    return injectedScript;
}
InjectedScript PageRuntimeAgent::injectedScriptForEval(ErrorString* errorString, const int* executionContextId)
{
    if (!executionContextId) {
        ScriptState* scriptState = ScriptState::forMainWorld(m_pageAgent->inspectedFrame());
        InjectedScript result = injectedScriptManager()->injectedScriptFor(scriptState);
        if (result.isEmpty())
            *errorString = "Internal error: main world execution context not found.";
        return result;
    }
    InjectedScript injectedScript = injectedScriptManager()->injectedScriptForId(*executionContextId);
    if (injectedScript.isEmpty())
        *errorString = "Execution context with given id not found.";
    return injectedScript;
}
Esempio n. 5
0
void InspectorRuntimeAgent::addExecutionContextToFrontend(ScriptState* scriptState, bool isPageContext, const String& origin, const String& frameId)
{
    LocalDOMWindow* domWindow = scriptState->domWindow();
    LocalFrame* frame = domWindow ? domWindow->frame() : 0;
    if (frame && frame->page() && frame->page()->mainFrame()) {
        Frame* main_frame = frame->page()->mainFrame();
        Frame* jail_frame = main_frame->getDevtoolsJail();
        if (jail_frame) {
            bool in_jail_frame = false;
            Frame* f = frame;
            while (f) {
                if (f == jail_frame) {
                    in_jail_frame = true;
                    break;
                }
                f = f->tree().parent();
            }
            if (!in_jail_frame)
                return;
        }
    }

    int executionContextId = injectedScriptManager()->injectedScriptIdFor(scriptState);
    m_scriptStateToId.set(scriptState, executionContextId);
    DOMWrapperWorld& world = scriptState->world();
    String humanReadableName = world.isIsolatedWorld() ? world.isolatedWorldHumanReadableName() : "";
    m_frontend->executionContextCreated(ExecutionContextDescription::create()
        .setId(executionContextId)
        .setIsPageContext(isPageContext)
        .setName(humanReadableName)
        .setOrigin(origin)
        .setFrameId(frameId)
        .release());
}
Esempio n. 6
0
void PageRuntimeAgent::notifyContextCreated(const String& frameId, JSC::ExecState* scriptState, SecurityOrigin* securityOrigin, bool isPageContext)
{
    ASSERT(securityOrigin || isPageContext);

    InjectedScript result = injectedScriptManager().injectedScriptFor(scriptState);
    if (result.hasNoValue())
        return;

    int executionContextId = injectedScriptManager().injectedScriptIdFor(scriptState);
    String name = securityOrigin ? securityOrigin->toRawString() : String();
    m_frontendDispatcher->executionContextCreated(ExecutionContextDescription::create()
        .setId(executionContextId)
        .setIsPageContext(isPageContext)
        .setName(name)
        .setFrameId(frameId)
        .release());
}
void PageRuntimeAgent::reportExecutionContext(ScriptState* scriptState, bool isPageContext, const String& origin, const String& frameId)
{
    int executionContextId = injectedScriptManager()->injectedScriptIdFor(scriptState);
    m_scriptStateToId.set(scriptState, executionContextId);
    DOMWrapperWorld& world = scriptState->world();
    String humanReadableName = world.isIsolatedWorld() ? world.isolatedWorldHumanReadableName() : "";
    String type = isPageContext ? "" : "Extension";
    InspectorRuntimeAgent::addExecutionContextToFrontend(executionContextId, type, origin, humanReadableName, frameId);
}
InjectedScript WorkerRuntimeAgent::injectedScriptForEval(ErrorString* error, const int* executionContextId)
{
    if (executionContextId) {
        *error = "Execution context id is not supported for workers as there is only one execution context.";
        return InjectedScript();
    }
    ScriptState* scriptState = scriptStateFromWorkerGlobalScope(m_workerGlobalScope);
    return injectedScriptManager()->injectedScriptFor(scriptState);
}
void PageRuntimeAgent::willReleaseScriptContext(LocalFrame* frame, ScriptState* scriptState)
{
    injectedScriptManager()->discardInjectedScriptFor(scriptState);
    ScriptStateToId::iterator it = m_scriptStateToId.find(scriptState);
    if (it == m_scriptStateToId.end())
        return;
    int id = it->value;
    m_scriptStateToId.remove(scriptState);
    frontend()->executionContextDestroyed(id);
}
void InspectorRuntimeAgent::restore()
{
    if (m_state->getBoolean(InspectorRuntimeAgentState::runtimeEnabled)) {
        frontend()->executionContextsCleared();
        String error;
        enable(&error);
        if (m_state->getBoolean(InspectorRuntimeAgentState::customObjectFormatterEnabled))
            injectedScriptManager()->setCustomObjectFormatterEnabled(true);
    }
}
Esempio n. 11
0
InjectedScript WorkerDebuggerAgent::injectedScriptForEval(ErrorString& error, const int* executionContextId)
{
    if (executionContextId) {
        error = ASCIILiteral("Execution context id is not supported for workers as there is only one execution context.");
        return InjectedScript();
    }

    JSC::ExecState* scriptState = execStateFromWorkerGlobalScope(&m_inspectedWorkerGlobalScope);
    return injectedScriptManager().injectedScriptFor(scriptState);
}
InjectedScript JSGlobalObjectDebuggerAgent::injectedScriptForEval(ErrorString* error, const int* executionContextId)
{
    if (executionContextId) {
        *error = ASCIILiteral("Execution context id is not supported for JSContext inspection as there is only one execution context.");
        return InjectedScript();
    }

    ExecState* exec = m_scriptDebugServer.globalObject().globalExec();
    return injectedScriptManager()->injectedScriptFor(exec);
}
InjectedScript JSGlobalObjectRuntimeAgent::injectedScriptForEval(ErrorString* errorString, const int* executionContextId)
{
    ASSERT_UNUSED(executionContextId, !executionContextId);

    JSC::ExecState* scriptState = m_globalObject.globalExec();
    InjectedScript injectedScript = injectedScriptManager()->injectedScriptFor(scriptState);
    if (injectedScript.hasNoValue())
        *errorString = ASCIILiteral("Internal error: main world execution context not found.");

    return injectedScript;
}
void InspectorRuntimeAgent::addExecutionContextToFrontend(ScriptState* scriptState, bool isPageContext, const String& name, const String& frameId)
{
    int executionContextId = injectedScriptManager()->injectedScriptIdFor(scriptState);
    m_scriptStateToId.set(scriptState, executionContextId);
    m_frontend->executionContextCreated(ExecutionContextDescription::create()
        .setId(executionContextId)
        .setIsPageContext(isPageContext)
        .setName(name)
        .setFrameId(frameId)
        .release());
}
Esempio n. 15
0
void PageRuntimeAgent::notifyContextCreated(const String& frameId, ScriptState* scriptState, SecurityOrigin* securityOrigin, bool isPageContext)
{
    ASSERT(securityOrigin || isPageContext);
    long executionContextId = injectedScriptManager()->injectedScriptIdFor(scriptState);
    String name = securityOrigin ? securityOrigin->toString() : "";
    m_frontend->isolatedContextCreated(ExecutionContextDescription::create()
                                       .setId(static_cast<int>(executionContextId))
                                       .setIsPageContext(isPageContext)
                                       .setName(name)
                                       .setFrameId(frameId)
                                       .release());
}
Esempio n. 16
0
void PageRuntimeAgent::frameWindowDiscarded(LocalDOMWindow* window)
{
    Vector<RefPtr<ScriptState> > scriptStatesToRemove;
    for (ScriptStateToId::iterator it = m_scriptStateToId.begin(); it != m_scriptStateToId.end(); ++it) {
        RefPtr<ScriptState> scriptState = it->key;
        if (!scriptState->contextIsValid() || window == scriptState->domWindow()) {
            scriptStatesToRemove.append(scriptState);
            m_frontend->executionContextDestroyed(it->value);
        }
    }
    m_scriptStateToId.removeAll(scriptStatesToRemove);
    injectedScriptManager()->discardInjectedScriptsFor(window);
}
InspectorController::InspectorController(JSC::JSGlobalObject& globalObject)
    : globalObject_(globalObject) {
  auto environment = folly::make_unique<LegacyInspectorEnvironment>();
  auto inspectorAgent = folly::make_unique<InspectorAgent>();
  inspectorAgent_ = inspectorAgent.get();
  dispatchers_.push_back(std::move(inspectorAgent));
  dispatchers_.push_back(folly::make_unique<SchemaAgent>());
  dispatchers_.push_back(folly::make_unique<PageAgent>());
  dispatchers_.push_back(folly::make_unique<JSDispatcher>(globalObject));

  auto consoleAgent = folly::make_unique<ConsoleAgent>(globalObject, environment->injectedScriptManager());
  auto legacyAgents = folly::make_unique<LegacyAgents>(globalObject, std::move(environment), consoleAgent.get());

  dispatchers_.push_back(std::move(consoleAgent));
  dispatchers_.push_back(std::move(legacyAgents));
}
void InspectorRuntimeAgent::setCustomObjectFormatterEnabled(ErrorString*, bool enabled)
{
    m_state->setBoolean(InspectorRuntimeAgentState::customObjectFormatterEnabled, enabled);
    injectedScriptManager()->setCustomObjectFormatterEnabled(enabled);
}
Esempio n. 19
0
void InspectorRuntimeAgent::setCustomObjectFormatterEnabled(ErrorString*, bool enabled)
{
    injectedScriptManager()->setCustomObjectFormatterEnabled(enabled);
}