#ifndef WorkerScriptLoader_h
#define WorkerScriptLoader_h
#include "core/loader/ThreadableLoader.h"
#include "core/loader/ThreadableLoaderClient.h"
#include "platform/network/ResourceRequest.h"
#include "platform/weborigin/KURL.h"
#include "wtf/FastAllocBase.h"
#include "wtf/PassRefPtr.h"
#include "wtf/RefCounted.h"
#include "wtf/text/StringBuilder.h"
namespace WebCore {
class ResourceRequest;
class ResourceResponse;
class ExecutionContext;
class TextResourceDecoder;
class WorkerScriptLoaderClient;
class WorkerScriptLoader FINAL : public RefCounted<WorkerScriptLoader>, public ThreadableLoaderClient {
WTF_MAKE_FAST_ALLOCATED;
public:
static PassRefPtr<WorkerScriptLoader> create()
{
return adoptRef(new WorkerScriptLoader());
}
void loadSynchronously(ExecutionContext*, const KURL&, CrossOriginRequestPolicy);
void loadAsynchronously(ExecutionContext*, const KURL&, CrossOriginRequestPolicy, WorkerScriptLoaderClient*);
void notifyError();
void cancel();
void setClient(WorkerScriptLoaderClient* client) { m_client = client; }
String script();
const KURL& url() const { return m_url; }
const KURL& 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;
void setTargetType(ResourceRequest::TargetType targetType) { m_targetType = targetType; }
private:
friend class WTF::RefCounted<WorkerScriptLoader>;
WorkerScriptLoader();
virtual ~WorkerScriptLoader();
PassOwnPtr<ResourceRequest> createResourceRequest();
void notifyFinished();
WorkerScriptLoaderClient* m_client;
RefPtr<ThreadableLoader> m_threadableLoader;
String m_responseEncoding;
OwnPtr<TextResourceDecoder> m_decoder;
StringBuilder m_script;
KURL m_url;
KURL m_responseURL;
bool m_failed;
unsigned long m_identifier;
bool m_finishing;
ResourceRequest::TargetType m_targetType;
};
}
#endif