#ifndef HTMLScriptRunner_h
#define HTMLScriptRunner_h
#include "core/dom/PendingScript.h"
#include "wtf/Deque.h"
#include "wtf/PassRefPtr.h"
#include "wtf/text/TextPosition.h"
namespace WebCore {
class Resource;
class ScriptResource;
class Document;
class Element;
class LocalFrame;
class HTMLScriptRunnerHost;
class ScriptSourceCode;
class HTMLScriptRunner {
WTF_MAKE_NONCOPYABLE(HTMLScriptRunner); WTF_MAKE_FAST_ALLOCATED;
public:
static PassOwnPtr<HTMLScriptRunner> create(Document* document, HTMLScriptRunnerHost* host)
{
return adoptPtr(new HTMLScriptRunner(document, host));
}
~HTMLScriptRunner();
void detach();
void execute(PassRefPtr<Element> scriptToProcess, const TextPosition& scriptStartPosition);
void executeScriptsWaitingForLoad(Resource*);
bool hasScriptsWaitingForResources() const { return m_hasScriptsWaitingForResources; }
void executeScriptsWaitingForResources();
bool executeScriptsWaitingForParsing();
bool hasParserBlockingScript() const;
bool isExecutingScript() const { return !!m_scriptNestingLevel; }
private:
HTMLScriptRunner(Document*, HTMLScriptRunnerHost*);
LocalFrame* frame() const;
enum PendingScriptType {
PendingScriptBlockingParser,
PendingScriptDeferred
};
void executeParsingBlockingScript();
void executePendingScriptAndDispatchEvent(PendingScript&, PendingScriptType);
void executeParsingBlockingScripts();
void requestParsingBlockingScript(Element*);
void requestDeferredScript(Element*);
bool requestPendingScript(PendingScript&, Element*) const;
void runScript(Element*, const TextPosition& scriptStartPosition);
void watchForLoad(PendingScript&);
void stopWatchingForLoad(PendingScript&);
bool isPendingScriptReady(const PendingScript&);
ScriptSourceCode sourceFromPendingScript(const PendingScript&, bool& errorOccurred) const;
Document* m_document;
HTMLScriptRunnerHost* m_host;
PendingScript m_parserBlockingScript;
Deque<PendingScript> m_scriptsToExecuteAfterParsing;
unsigned m_scriptNestingLevel;
bool m_hasScriptsWaitingForResources;
};
}
#endif