JSInjectedScriptHostCustom.cpp [plain text]
#include "config.h"
#include "JSInjectedScriptHost.h"
#if ENABLE(INSPECTOR)
#include "Console.h"
#if ENABLE(DATABASE)
#include "Database.h"
#include "JSDatabase.h"
#endif
#include "ExceptionCode.h"
#include "Frame.h"
#include "FrameLoader.h"
#include "InjectedScriptHost.h"
#include "InspectorController.h"
#include "InspectorResource.h"
#include "JSDOMWindow.h"
#include "JSNode.h"
#include "JSRange.h"
#include "Node.h"
#include "Page.h"
#if ENABLE(DOM_STORAGE)
#include "Storage.h"
#include "JSStorage.h"
#endif
#include "TextIterator.h"
#include "VisiblePosition.h"
#include <parser/SourceCode.h>
#include <runtime/JSArray.h>
#include <runtime/JSLock.h>
#include <wtf/Vector.h>
#if ENABLE(JAVASCRIPT_DEBUGGER)
#include "JavaScriptCallFrame.h"
#include "JavaScriptDebugServer.h"
#include "JSJavaScriptCallFrame.h"
#endif
using namespace JSC;
namespace WebCore {
static ScriptObject createInjectedScript(const String& source, InjectedScriptHost* injectedScriptHost, ScriptState* scriptState, long id)
{
SourceCode sourceCode = makeSource(source);
JSLock lock(SilenceAssertionsOnly);
JSDOMGlobalObject* globalObject = static_cast<JSDOMGlobalObject*>(scriptState->lexicalGlobalObject());
JSValue globalThisValue = scriptState->globalThisValue();
Completion comp = JSC::evaluate(scriptState, globalObject->globalScopeChain(), sourceCode, globalThisValue);
if (comp.complType() != JSC::Normal && comp.complType() != JSC::ReturnValue)
return ScriptObject();
JSValue functionValue = comp.value();
CallData callData;
CallType callType = functionValue.getCallData(callData);
if (callType == CallTypeNone)
return ScriptObject();
MarkedArgumentBuffer args;
args.append(toJS(scriptState, globalObject, injectedScriptHost));
args.append(globalThisValue);
args.append(jsNumber(scriptState, id));
JSValue result = JSC::call(scriptState, functionValue, callType, callData, globalThisValue, args);
if (result.isObject())
return ScriptObject(scriptState, result.getObject());
return ScriptObject();
}
#if ENABLE(DATABASE)
JSValue JSInjectedScriptHost::databaseForId(ExecState* exec, const ArgList& args)
{
if (args.size() < 1)
return jsUndefined();
InspectorController* ic = impl()->inspectorController();
if (!ic)
return jsUndefined();
Database* database = impl()->databaseForId(args.at(0).toInt32(exec));
if (!database)
return jsUndefined();
return toJS(exec, database);
}
#endif
#if ENABLE(JAVASCRIPT_DEBUGGER)
JSValue JSInjectedScriptHost::currentCallFrame(ExecState* exec, const ArgList&)
{
JavaScriptCallFrame* callFrame = impl()->currentCallFrame();
if (!callFrame || !callFrame->isValid())
return jsUndefined();
JSLock lock(SilenceAssertionsOnly);
return toJS(exec, callFrame);
}
JSValue JSInjectedScriptHost::isActivation(ExecState*, const ArgList& args)
{
JSObject* object = args.at(0).getObject();
return jsBoolean(object && object->isActivationObject());
}
#endif
JSValue JSInjectedScriptHost::nodeForId(ExecState* exec, const ArgList& args)
{
if (args.size() < 1)
return jsUndefined();
Node* node = impl()->nodeForId(args.at(0).toInt32(exec));
if (!node)
return jsUndefined();
InspectorController* ic = impl()->inspectorController();
if (!ic)
return jsUndefined();
JSLock lock(SilenceAssertionsOnly);
return toJS(exec, node);
}
JSValue JSInjectedScriptHost::pushNodePathToFrontend(ExecState* exec, const ArgList& args)
{
if (args.size() < 3)
return jsUndefined();
Node* node = toNode(args.at(0));
if (!node)
return jsUndefined();
bool withChildren = args.at(1).toBoolean(exec);
bool selectInUI = args.at(2).toBoolean(exec);
return jsNumber(exec, impl()->pushNodePathToFrontend(node, withChildren, selectInUI));
}
#if ENABLE(DATABASE)
JSValue JSInjectedScriptHost::selectDatabase(ExecState*, const ArgList& args)
{
if (args.size() < 1)
return jsUndefined();
Database* database = toDatabase(args.at(0));
if (database)
impl()->selectDatabase(database);
return jsUndefined();
}
#endif
#if ENABLE(DOM_STORAGE)
JSValue JSInjectedScriptHost::selectDOMStorage(ExecState*, const ArgList& args)
{
if (args.size() < 1)
return jsUndefined();
InspectorController* ic = impl()->inspectorController();
if (!ic)
return jsUndefined();
Storage* storage = toStorage(args.at(0));
if (storage)
impl()->selectDOMStorage(storage);
return jsUndefined();
}
#endif
ScriptObject InjectedScriptHost::injectedScriptFor(ScriptState* scriptState)
{
JSLock lock(SilenceAssertionsOnly);
JSDOMGlobalObject* globalObject = static_cast<JSDOMGlobalObject*>(scriptState->lexicalGlobalObject());
JSObject* injectedScript = globalObject->injectedScript();
if (injectedScript)
return ScriptObject(scriptState, injectedScript);
ASSERT(!m_injectedScriptSource.isEmpty());
ScriptObject injectedScriptObject = createInjectedScript(m_injectedScriptSource, this, scriptState, m_nextInjectedScriptId);
globalObject->setInjectedScript(injectedScriptObject.jsObject());
m_idToInjectedScript.set(m_nextInjectedScriptId, injectedScriptObject);
m_nextInjectedScriptId++;
return injectedScriptObject;
}
}
#endif // ENABLE(INSPECTOR)