JSInjectedScriptManager.cpp [plain text]
#include "config.h"
#if ENABLE(INSPECTOR)
#include "InjectedScriptManager.h"
#include "BindingSecurity.h"
#include "ExceptionCode.h"
#include "JSDOMWindow.h"
#include "JSDOMWindowCustom.h"
#include "JSInjectedScriptHost.h"
#include "JSMainThreadExecState.h"
#include "ScriptObject.h"
#include <parser/SourceCode.h>
#include <runtime/JSLock.h>
using namespace JSC;
namespace WebCore {
ScriptObject InjectedScriptManager::createInjectedScript(const String& source, ScriptState* scriptState, int id)
{
JSLockHolder lock(scriptState);
SourceCode sourceCode = makeSource(source);
JSDOMGlobalObject* globalObject = jsCast<JSDOMGlobalObject*>(scriptState->lexicalGlobalObject());
JSValue globalThisValue = scriptState->globalThisValue();
JSValue evaluationException;
JSValue evaluationReturnValue;
if (isMainThread())
evaluationReturnValue = JSMainThreadExecState::evaluate(scriptState, sourceCode, globalThisValue, &evaluationException);
else {
JSC::JSLockHolder lock(scriptState);
evaluationReturnValue = JSC::evaluate(scriptState, sourceCode, globalThisValue, &evaluationException);
}
if (evaluationException)
return ScriptObject();
JSValue functionValue = evaluationReturnValue;
CallData callData;
CallType callType = getCallData(functionValue, callData);
if (callType == CallTypeNone)
return ScriptObject();
MarkedArgumentBuffer args;
args.append(toJS(scriptState, globalObject, m_injectedScriptHost.get()));
args.append(globalThisValue);
args.append(jsNumber(id));
JSValue result = JSC::call(scriptState, functionValue, callType, callData, globalThisValue, args);
if (result.isObject())
return ScriptObject(scriptState, result.getObject());
return ScriptObject();
}
bool InjectedScriptManager::canAccessInspectedWindow(ScriptState* scriptState)
{
JSLockHolder lock(scriptState);
JSDOMWindow* inspectedWindow = toJSDOMWindow(scriptState->lexicalGlobalObject());
if (!inspectedWindow)
return false;
return BindingSecurity::shouldAllowAccessToDOMWindow(scriptState, inspectedWindow->impl(), DoNotReportSecurityError);
}
}
#endif // ENABLE(INSPECTOR)