#ifndef WorkerThreadableLoader_h
#define WorkerThreadableLoader_h
#include "core/loader/ThreadableLoader.h"
#include "core/loader/ThreadableLoaderClient.h"
#include "core/loader/ThreadableLoaderClientWrapper.h"
#include "heap/Handle.h"
#include "wtf/PassOwnPtr.h"
#include "wtf/PassRefPtr.h"
#include "wtf/RefCounted.h"
#include "wtf/RefPtr.h"
#include "wtf/Threading.h"
#include "wtf/text/WTFString.h"
namespace WebCore {
class ResourceError;
class ResourceRequest;
class WorkerGlobalScope;
class WorkerLoaderProxy;
struct CrossThreadResourceResponseData;
struct CrossThreadResourceRequestData;
class WorkerThreadableLoader FINAL : public RefCounted<WorkerThreadableLoader>, public ThreadableLoader {
WTF_MAKE_FAST_ALLOCATED;
public:
static void loadResourceSynchronously(WorkerGlobalScope*, const ResourceRequest&, ThreadableLoaderClient&, const ThreadableLoaderOptions&);
static PassRefPtr<WorkerThreadableLoader> create(WorkerGlobalScope* workerGlobalScope, PassRefPtr<ThreadableLoaderClientWrapper> clientWrapper, PassOwnPtr<ThreadableLoaderClient> clientBridge, const ResourceRequest& request, const ThreadableLoaderOptions& options)
{
return adoptRef(new WorkerThreadableLoader(workerGlobalScope, clientWrapper, clientBridge, request, options));
}
virtual ~WorkerThreadableLoader();
virtual void cancel() OVERRIDE;
bool done() const { return m_workerClientWrapper->done(); }
using RefCounted<WorkerThreadableLoader>::ref;
using RefCounted<WorkerThreadableLoader>::deref;
protected:
virtual void refThreadableLoader() OVERRIDE { ref(); }
virtual void derefThreadableLoader() OVERRIDE { deref(); }
private:
class MainThreadBridge FINAL : public ThreadableLoaderClient {
public:
MainThreadBridge(PassRefPtr<ThreadableLoaderClientWrapper>, PassOwnPtr<ThreadableLoaderClient>, WorkerLoaderProxy&, const ResourceRequest&, const ThreadableLoaderOptions&, const String& outgoingReferrer);
void cancel();
void destroy();
private:
void clearClientWrapper();
static void mainThreadDestroy(ExecutionContext*, MainThreadBridge*);
virtual ~MainThreadBridge();
static void mainThreadCreateLoader(ExecutionContext*, MainThreadBridge*, PassOwnPtr<CrossThreadResourceRequestData>, ThreadableLoaderOptions, const String& outgoingReferrer);
static void mainThreadCancel(ExecutionContext*, MainThreadBridge*);
virtual void didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent) OVERRIDE;
virtual void didReceiveResponse(unsigned long identifier, const ResourceResponse&) OVERRIDE;
virtual void didReceiveData(const char*, int dataLength) OVERRIDE;
virtual void didDownloadData(int dataLength) OVERRIDE;
virtual void didReceiveCachedMetadata(const char*, int dataLength) OVERRIDE;
virtual void didFinishLoading(unsigned long identifier, double finishTime) OVERRIDE;
virtual void didFail(const ResourceError&) OVERRIDE;
virtual void didFailAccessControlCheck(const ResourceError&) OVERRIDE;
virtual void didFailRedirectCheck() OVERRIDE;
RefPtr<ThreadableLoader> m_mainThreadLoader;
OwnPtr<ThreadableLoaderClient> m_clientBridge;
RefPtr<ThreadableLoaderClientWrapper> m_workerClientWrapper;
WorkerLoaderProxy& m_loaderProxy;
};
WorkerThreadableLoader(WorkerGlobalScope*, PassRefPtr<ThreadableLoaderClientWrapper>, PassOwnPtr<ThreadableLoaderClient>, const ResourceRequest&, const ThreadableLoaderOptions&);
RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope;
RefPtr<ThreadableLoaderClientWrapper> m_workerClientWrapper;
MainThreadBridge& m_bridge;
};
}
#endif