#ifndef ExecutionContext_h
#define ExecutionContext_h
#include "core/dom/ActiveDOMObject.h"
#include "core/dom/ExecutionContextClient.h"
#include "core/dom/SandboxFlags.h"
#include "core/dom/SecurityContext.h"
#include "core/events/ErrorEvent.h"
#include "core/fetch/CrossOriginAccessControl.h"
#include "core/frame/ConsoleTypes.h"
#include "core/frame/DOMTimer.h"
#include "platform/LifecycleContext.h"
#include "platform/weborigin/KURL.h"
#include "wtf/Functional.h"
#include "wtf/OwnPtr.h"
#include "wtf/PassOwnPtr.h"
namespace WTF {
class OrdinalNumber;
}
namespace WebCore {
class ContextLifecycleNotifier;
class DOMWindow;
class EventListener;
class EventQueue;
class EventTarget;
class ExecutionContextTask;
class PublicURLManager;
class SecurityOrigin;
class ScriptCallStack;
class ScriptState;
class ExecutionContext : public LifecycleContext<ExecutionContext> {
public:
ExecutionContext();
virtual ~ExecutionContext();
void setClient(ExecutionContextClient* client) { m_client = client; }
bool isDocument() const { return m_client && m_client->isDocument(); }
bool isWorkerGlobalScope() const { return m_client && m_client->isWorkerGlobalScope(); }
bool isJSExecutionForbidden() { return m_client && m_client->isJSExecutionForbidden(); }
SecurityOrigin* securityOrigin() const;
ContentSecurityPolicy* contentSecurityPolicy() const;
const KURL& url() const;
KURL completeURL(const String& url) const;
void disableEval(const String& errorMessage);
DOMWindow* executingWindow() const;
String userAgent(const KURL&) const;
void postTask(PassOwnPtr<ExecutionContextTask>);
void postTask(const Closure&);
double timerAlignmentInterval() const;
bool shouldSanitizeScriptError(const String& sourceURL, AccessControlStatus);
void reportException(PassRefPtrWillBeRawPtr<ErrorEvent>, PassRefPtr<ScriptCallStack>, AccessControlStatus);
void addConsoleMessage(MessageSource, MessageLevel, const String& message, const String& sourceURL, unsigned lineNumber);
void addConsoleMessage(MessageSource, MessageLevel, const String& message, ScriptState* = 0);
PublicURLManager& publicURLManager();
bool hasPendingActivity();
void suspendActiveDOMObjects();
void resumeActiveDOMObjects();
void stopActiveDOMObjects();
unsigned activeDOMObjectCount();
virtual void suspendScheduledTasks();
virtual void resumeScheduledTasks();
virtual bool tasksNeedSuspension() { return false; }
bool activeDOMObjectsAreSuspended() const { return m_activeDOMObjectsAreSuspended; }
bool activeDOMObjectsAreStopped() const { return m_activeDOMObjectsAreStopped; }
bool isIteratingOverObservers() const;
void suspendActiveDOMObjectIfNeeded(ActiveDOMObject*);
void ref() { refExecutionContext(); }
void deref() { derefExecutionContext(); }
int circularSequentialID();
void didChangeTimerAlignmentInterval();
SandboxFlags sandboxFlags() const { return m_sandboxFlags; }
bool isSandboxed(SandboxFlags mask) const { return m_sandboxFlags & mask; }
void enforceSandboxFlags(SandboxFlags mask);
PassOwnPtr<LifecycleNotifier<ExecutionContext> > createLifecycleNotifier();
virtual EventQueue* eventQueue() const = 0;
protected:
ContextLifecycleNotifier& lifecycleNotifier();
private:
friend class DOMTimer;
bool dispatchErrorEvent(PassRefPtrWillBeRawPtr<ErrorEvent>, AccessControlStatus);
virtual void refExecutionContext() = 0;
virtual void derefExecutionContext() = 0;
int installNewTimeout(PassOwnPtr<ScheduledAction>, int timeout, bool singleShot);
void removeTimeoutByID(int timeoutID);
ExecutionContextClient* m_client;
SandboxFlags m_sandboxFlags;
int m_circularSequentialID;
typedef HashMap<int, OwnPtr<DOMTimer> > TimeoutMap;
TimeoutMap m_timeouts;
bool m_inDispatchErrorEvent;
class PendingException;
OwnPtr<Vector<OwnPtr<PendingException> > > m_pendingExceptions;
bool m_activeDOMObjectsAreSuspended;
bool m_activeDOMObjectsAreStopped;
OwnPtr<PublicURLManager> m_publicURLManager;
OwnPtr<ContextLifecycleNotifier> m_lifecycleNotifier;
};
}
#endif