JSInjectedScriptManager.cpp [plain text]
#include "config.h"
#include "InjectedScriptManager.h"
#if ENABLE(INSPECTOR)
#include "ExceptionCode.h"
#include "InjectedScript.h"
#include "JSDOMWindow.h"
#include "JSDOMWindowCustom.h"
#include "JSInjectedScriptHost.h"
#include "JSMainThreadExecState.h"
#include <parser/SourceCode.h>
#include <runtime/JSLock.h>
using namespace JSC;
namespace WebCore {
ScriptObject InjectedScriptManager::createInjectedScript(const String& source, ScriptState* scriptState, long id)
{
JSLock lock(SilenceAssertionsOnly);
SourceCode sourceCode = makeSource(stringToUString(source));
JSDOMGlobalObject* globalObject = static_cast<JSDOMGlobalObject*>(scriptState->lexicalGlobalObject());
JSValue globalThisValue = scriptState->globalThisValue();
JSValue evaluationException;
JSValue evaluationReturnValue = JSMainThreadExecState::evaluate(scriptState, globalObject->globalScopeChain(), 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();
}
void InjectedScriptManager::discardInjectedScript(ScriptState* scriptState)
{
JSDOMGlobalObject* globalObject = static_cast<JSDOMGlobalObject*>(scriptState->lexicalGlobalObject());
globalObject->setInjectedScript(0);
}
InjectedScript InjectedScriptManager::injectedScriptFor(ScriptState* scriptState)
{
JSLock lock(SilenceAssertionsOnly);
JSDOMGlobalObject* globalObject = static_cast<JSDOMGlobalObject*>(scriptState->lexicalGlobalObject());
JSObject* injectedScript = globalObject->injectedScript();
if (injectedScript)
return InjectedScript(ScriptObject(scriptState, injectedScript), m_inspectedStateAccessCheck);
if (!m_inspectedStateAccessCheck(scriptState))
return InjectedScript();
pair<long, ScriptObject> injectedScriptObject = injectScript(injectedScriptSource(), scriptState);
globalObject->setInjectedScript(injectedScriptObject.second.jsObject());
InjectedScript result(injectedScriptObject.second, m_inspectedStateAccessCheck);
m_idToInjectedScript.set(injectedScriptObject.first, result);
return result;
}
bool InjectedScriptManager::canAccessInspectedWindow(ScriptState* scriptState)
{
JSLock lock(SilenceAssertionsOnly);
JSDOMWindow* inspectedWindow = toJSDOMWindow(scriptState->lexicalGlobalObject());
if (!inspectedWindow)
return false;
return inspectedWindow->allowsAccessFromNoErrorMessage(scriptState);
}
}
#endif // ENABLE(INSPECTOR)