WorkerScriptLoader.h [plain text]
#ifndef WorkerScriptLoader_h
#define WorkerScriptLoader_h
#include "URL.h"
#include "ResourceRequest.h"
#include "ThreadableLoader.h"
#include "ThreadableLoaderClient.h"
#include <memory>
#include <wtf/FastMalloc.h>
#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
#include <wtf/text/StringBuilder.h>
namespace WebCore {
class ResourceRequest;
class ResourceResponse;
class ScriptExecutionContext;
class TextResourceDecoder;
class WorkerScriptLoaderClient;
class WorkerScriptLoader : public RefCounted<WorkerScriptLoader>, public ThreadableLoaderClient {
WTF_MAKE_FAST_ALLOCATED;
public:
static PassRefPtr<WorkerScriptLoader> create()
{
return adoptRef(new WorkerScriptLoader());
}
void loadSynchronously(ScriptExecutionContext*, const URL&, CrossOriginRequestPolicy);
void loadAsynchronously(ScriptExecutionContext*, const URL&, CrossOriginRequestPolicy, WorkerScriptLoaderClient*);
void notifyError();
String script();
const URL& url() const { return m_url; }
const URL& responseURL() const;
bool failed() const { return m_failed; }
unsigned long identifier() const { return m_identifier; }
virtual void didReceiveResponse(unsigned long , const ResourceResponse&) override;
virtual void didReceiveData(const char* data, int dataLength) override;
virtual void didFinishLoading(unsigned long identifier, double) override;
virtual void didFail(const ResourceError&) override;
virtual void didFailRedirectCheck() override;
private:
friend class WTF::RefCounted<WorkerScriptLoader>;
WorkerScriptLoader();
~WorkerScriptLoader();
std::unique_ptr<ResourceRequest> createResourceRequest();
void notifyFinished();
WorkerScriptLoaderClient* m_client;
RefPtr<ThreadableLoader> m_threadableLoader;
String m_responseEncoding;
RefPtr<TextResourceDecoder> m_decoder;
StringBuilder m_script;
URL m_url;
URL m_responseURL;
bool m_failed;
unsigned long m_identifier;
bool m_finishing;
};
}
#endif // WorkerScriptLoader_h