WorkerThreadableLoader.h [plain text]
#ifndef WorkerThreadableLoader_h
#define WorkerThreadableLoader_h
#if ENABLE(WORKERS)
#include "PlatformString.h"
#include "ThreadableLoader.h"
#include "ThreadableLoaderClient.h"
#include "ThreadableLoaderClientWrapper.h"
#include <wtf/PassOwnPtr.h>
#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
#include <wtf/Threading.h>
namespace WebCore {
class ResourceError;
class ResourceRequest;
class WorkerContext;
class WorkerLoaderProxy;
struct CrossThreadResourceResponseData;
struct CrossThreadResourceRequestData;
class WorkerThreadableLoader : public RefCounted<WorkerThreadableLoader>, public ThreadableLoader {
WTF_MAKE_FAST_ALLOCATED;
public:
static void loadResourceSynchronously(WorkerContext*, const ResourceRequest&, ThreadableLoaderClient&, const ThreadableLoaderOptions&);
static PassRefPtr<WorkerThreadableLoader> create(WorkerContext* workerContext, ThreadableLoaderClient* client, const String& taskMode, const ResourceRequest& request, const ThreadableLoaderOptions& options)
{
return adoptRef(new WorkerThreadableLoader(workerContext, client, taskMode, request, options));
}
~WorkerThreadableLoader();
virtual void cancel();
bool done() const { return m_workerClientWrapper->done(); }
using RefCounted<WorkerThreadableLoader>::ref;
using RefCounted<WorkerThreadableLoader>::deref;
protected:
virtual void refThreadableLoader() { ref(); }
virtual void derefThreadableLoader() { deref(); }
private:
class MainThreadBridge : public ThreadableLoaderClient {
public:
MainThreadBridge(PassRefPtr<ThreadableLoaderClientWrapper>, WorkerLoaderProxy&, const String& taskMode, const ResourceRequest&, const ThreadableLoaderOptions&, const String& outgoingReferrer);
void cancel();
void destroy();
private:
void clearClientWrapper();
static void mainThreadDestroy(ScriptExecutionContext*, MainThreadBridge*);
~MainThreadBridge();
static void mainThreadCreateLoader(ScriptExecutionContext*, MainThreadBridge*, PassOwnPtr<CrossThreadResourceRequestData>, ThreadableLoaderOptions, const String& outgoingReferrer);
static void mainThreadCancel(ScriptExecutionContext*, MainThreadBridge*);
virtual void didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent);
virtual void didReceiveResponse(const ResourceResponse&);
virtual void didReceiveData(const char*, int dataLength);
virtual void didReceiveCachedMetadata(const char*, int dataLength);
virtual void didFinishLoading(unsigned long identifier, double finishTime);
virtual void didFail(const ResourceError&);
virtual void didFailRedirectCheck();
virtual void didReceiveAuthenticationCancellation(const ResourceResponse&);
RefPtr<ThreadableLoader> m_mainThreadLoader;
RefPtr<ThreadableLoaderClientWrapper> m_workerClientWrapper;
WorkerLoaderProxy& m_loaderProxy;
String m_taskMode;
};
WorkerThreadableLoader(WorkerContext*, ThreadableLoaderClient*, const String& taskMode, const ResourceRequest&, const ThreadableLoaderOptions&);
RefPtr<WorkerContext> m_workerContext;
RefPtr<ThreadableLoaderClientWrapper> m_workerClientWrapper;
MainThreadBridge& m_bridge;
};
}
#endif // ENABLE(WORKERS)
#endif // WorkerThreadableLoader_h