#ifndef ScriptController_h
#define ScriptController_h
#include "bindings/v8/ScriptValue.h"
#include "bindings/v8/SharedPersistent.h"
#include "core/fetch/CrossOriginAccessControl.h"
#include "wtf/Forward.h"
#include "wtf/HashMap.h"
#include "wtf/RefCounted.h"
#include "wtf/Vector.h"
#include "wtf/text/TextPosition.h"
#include <v8.h>
struct NPObject;
namespace WebCore {
class DOMWrapperWorld;
class ExecutionContext;
class Event;
class LocalFrame;
class HTMLDocument;
class HTMLPlugInElement;
class KURL;
class ScriptSourceCode;
class ScriptState;
class SecurityOrigin;
class V8WindowShell;
class Widget;
typedef WTF::Vector<v8::Extension*> V8Extensions;
enum ReasonForCallingCanExecuteScripts {
AboutToExecuteScript,
NotAboutToExecuteScript
};
class ScriptController {
public:
enum ExecuteScriptPolicy {
ExecuteScriptWhenScriptsDisabled,
DoNotExecuteScriptWhenScriptsDisabled
};
ScriptController(LocalFrame*);
~ScriptController();
bool initializeMainWorld();
V8WindowShell* windowShell(DOMWrapperWorld&);
V8WindowShell* existingWindowShell(DOMWrapperWorld&);
void executeScriptInMainWorld(const String&, ExecuteScriptPolicy = DoNotExecuteScriptWhenScriptsDisabled);
void executeScriptInMainWorld(const ScriptSourceCode&, AccessControlStatus = NotSharableCrossOrigin);
ScriptValue executeScriptInMainWorldAndReturnValue(const ScriptSourceCode&);
v8::Local<v8::Value> executeScriptAndReturnValue(v8::Handle<v8::Context>, const ScriptSourceCode&, AccessControlStatus = NotSharableCrossOrigin);
void executeScriptInIsolatedWorld(int worldID, const Vector<ScriptSourceCode>& sources, int extensionGroup, Vector<ScriptValue>* results);
bool executeScriptIfJavaScriptURL(const KURL&);
v8::Local<v8::Value> callFunction(v8::Handle<v8::Function>, v8::Handle<v8::Value>, int argc, v8::Handle<v8::Value> argv[]);
static v8::Local<v8::Value> callFunction(ExecutionContext*, v8::Handle<v8::Function>, v8::Handle<v8::Value> receiver, int argc, v8::Handle<v8::Value> info[], v8::Isolate*);
bool shouldBypassMainWorldContentSecurityPolicy();
void bindToWindowObject(LocalFrame*, const String& key, NPObject*);
PassRefPtr<SharedPersistent<v8::Object> > createPluginWrapper(Widget*);
void enableEval();
void disableEval(const String& errorMessage);
static bool canAccessFromCurrentOrigin(LocalFrame*);
static void setCaptureCallStackForUncaughtExceptions(bool);
void collectIsolatedContexts(Vector<std::pair<ScriptState*, SecurityOrigin*> >&);
bool canExecuteScripts(ReasonForCallingCanExecuteScripts);
TextPosition eventHandlerPosition() const;
void clearWindowShell();
void updateDocument();
void namedItemAdded(HTMLDocument*, const AtomicString&);
void namedItemRemoved(HTMLDocument*, const AtomicString&);
void updateSecurityOrigin(SecurityOrigin*);
void clearScriptObjects();
void cleanupScriptObjectsForPlugin(Widget*);
void clearForClose();
NPObject* createScriptObjectForPluginElement(HTMLPlugInElement*);
NPObject* windowScriptNPObject();
static void registerExtensionIfNeeded(v8::Extension*);
static V8Extensions& registeredExtensions();
bool setContextDebugId(int);
static int contextDebugId(v8::Handle<v8::Context>);
v8::Isolate* isolate() const { return m_isolate; }
private:
typedef HashMap<int, OwnPtr<V8WindowShell> > IsolatedWorldMap;
typedef HashMap<Widget*, NPObject*> PluginObjectMap;
ScriptValue evaluateScriptInMainWorld(const ScriptSourceCode&, AccessControlStatus, ExecuteScriptPolicy);
LocalFrame* m_frame;
const String* m_sourceURL;
v8::Isolate* m_isolate;
OwnPtr<V8WindowShell> m_windowShell;
IsolatedWorldMap m_isolatedWorlds;
PluginObjectMap m_pluginObjects;
NPObject* m_windowScriptNPObject;
};
}
#endif