void InspectorBackend::removeNode(long callId, long nodeId)
{
    InspectorFrontend* frontend = inspectorFrontend();
    if (!frontend)
        return;

    Node* node = nodeForId(nodeId);
    if (!node) {
        // Use -1 to denote an error condition.
        frontend->didRemoveNode(callId, -1);
        return;
    }

    Node* parentNode = node->parentNode();
    if (!parentNode) {
        frontend->didRemoveNode(callId, -1);
        return;
    }

    ExceptionCode code;
    parentNode->removeChild(node, code);
    if (code) {
        frontend->didRemoveNode(callId, -1);
        return;
    }

    frontend->didRemoveNode(callId, nodeId);
}
void InspectorBackend::dispatchOnInjectedScript(long callId, long injectedScriptId, const String& methodName, const String& arguments, bool async)
{
    InspectorFrontend* frontend = inspectorFrontend();
    if (!frontend)
        return;

    // FIXME: explicitly pass injectedScriptId along with node id to the frontend.
    bool injectedScriptIdIsNodeId = injectedScriptId <= 0;

    InjectedScript injectedScript;
    if (injectedScriptIdIsNodeId)
        injectedScript = m_inspectorController->injectedScriptForNodeId(-injectedScriptId);
    else
        injectedScript = m_inspectorController->injectedScriptHost()->injectedScriptForId(injectedScriptId);

    if (injectedScript.hasNoValue())
        return;

    RefPtr<SerializedScriptValue> result;
    bool hadException = false;
    injectedScript.dispatch(callId, methodName, arguments, async, &result, &hadException);
    if (async)
        return;  // InjectedScript will return result asynchronously by means of ::reportDidDispatchOnInjectedScript.
    frontend->didDispatchOnInjectedScript(callId, result.get(), hadException);
}
long InspectorBackend::pushNodePathToFrontend(Node* node, bool selectInUI)
{
    InspectorFrontend* frontend = inspectorFrontend();
    InspectorDOMAgent* domAgent = inspectorDOMAgent();
    if (!domAgent || !frontend)
        return 0;
    long id = domAgent->pushNodePathToFrontend(node);
    if (selectInUI)
        frontend->updateFocusedNode(id);
    return id;
}
void InspectorBackend::getResourceContent(long callId, unsigned long identifier)
{
    InspectorFrontend* frontend = inspectorFrontend();
    if (!frontend)
        return;

    RefPtr<InspectorResource> resource = m_inspectorController->resources().get(identifier);
    if (resource)
        frontend->didGetResourceContent(callId, resource->sourceString());
    else
        frontend->didGetResourceContent(callId, "");
}
Пример #5
0
void InspectorBackend::dispatchOnInjectedScript(long callId, const String& methodName, const String& arguments)
{
    InspectorFrontend* frontend = inspectorFrontend();
    if (!frontend)
        return;

    ScriptFunctionCall function(m_inspectorController->m_scriptState, m_inspectorController->m_injectedScriptObj, "dispatch");
    function.appendArgument(methodName);
    function.appendArgument(arguments);
    bool hadException = false;
    ScriptValue result = function.call(hadException);
    if (hadException)
        frontend->didDispatchOnInjectedScript(callId, "", true);
    else
        frontend->didDispatchOnInjectedScript(callId, result.toString(m_inspectorController->m_scriptState), false);
}
void InspectorBackend::dispatchOnInjectedScript(long callId, const String& methodName, const String& arguments, bool async)
{
    InspectorFrontend* frontend = inspectorFrontend();
    if (!frontend)
        return;

    ScriptFunctionCall function(m_inspectorController->m_scriptState, m_inspectorController->m_injectedScriptObj, "dispatch");
    function.appendArgument(methodName);
    function.appendArgument(arguments);
    if (async)
        function.appendArgument(static_cast<int>(callId));
    bool hadException = false;
    ScriptValue result = function.call(hadException);
    if (async)
        return;  // InjectedScript will return result asynchronously by means of ::reportDidDispatchOnInjectedScript.
    if (hadException)
        frontend->didDispatchOnInjectedScript(callId, "", true);
    else
        frontend->didDispatchOnInjectedScript(callId, result.toString(m_inspectorController->m_scriptState), false);
}