WorkerThreadableLoader.h [plain text]
#ifndef WorkerThreadableLoader_h
#define WorkerThreadableLoader_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>
#include <wtf/text/WTFString.h>
namespace WebCore {
class ResourceError;
class ResourceRequest;
class WorkerGlobalScope;
class WorkerLoaderProxy;
struct CrossThreadResourceResponseData;
struct CrossThreadResourceRequestData;
class WorkerThreadableLoader : 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, ThreadableLoaderClient* client, const String& taskMode, const ResourceRequest& request, const ThreadableLoaderOptions& options)
{
return adoptRef(new WorkerThreadableLoader(workerGlobalScope, client, taskMode, request, options));
}
~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 : 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) override;
virtual void didReceiveResponse(unsigned long identifier, const ResourceResponse&) override;
virtual void didReceiveData(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;
RefPtr<ThreadableLoaderClientWrapper> m_workerClientWrapper;
WorkerLoaderProxy& m_loaderProxy;
String m_taskMode;
};
WorkerThreadableLoader(WorkerGlobalScope*, ThreadableLoaderClient*, const String& taskMode, const ResourceRequest&, const ThreadableLoaderOptions&);
RefPtr<WorkerGlobalScope> m_workerGlobalScope;
RefPtr<ThreadableLoaderClientWrapper> m_workerClientWrapper;
MainThreadBridge& m_bridge;
};
}
#endif // WorkerThreadableLoader_h