#ifndef WebSocketDeflateFramer_h
#define WebSocketDeflateFramer_h
#include "modules/websockets/WebSocketDeflater.h"
#include "modules/websockets/WebSocketExtensionProcessor.h"
#include "modules/websockets/WebSocketFrame.h"
#include "wtf/OwnPtr.h"
#include "wtf/PassOwnPtr.h"
namespace WebCore {
class WebSocketDeflateFramer;
class DeflateResultHolder {
WTF_MAKE_FAST_ALLOCATED;
public:
static PassOwnPtr<DeflateResultHolder> create(WebSocketDeflateFramer* framer)
{
return adoptPtr(new DeflateResultHolder(framer));
}
~DeflateResultHolder();
bool succeeded() const { return m_succeeded; }
String failureReason() const { return m_failureReason; }
void fail(const String& failureReason);
private:
explicit DeflateResultHolder(WebSocketDeflateFramer*);
WebSocketDeflateFramer* m_framer;
bool m_succeeded;
String m_failureReason;
};
class InflateResultHolder {
WTF_MAKE_FAST_ALLOCATED;
public:
static PassOwnPtr<InflateResultHolder> create(WebSocketDeflateFramer* framer)
{
return adoptPtr(new InflateResultHolder(framer));
}
~InflateResultHolder();
bool succeeded() const { return m_succeeded; }
String failureReason() const { return m_failureReason; }
void fail(const String& failureReason);
private:
explicit InflateResultHolder(WebSocketDeflateFramer*);
WebSocketDeflateFramer* m_framer;
bool m_succeeded;
String m_failureReason;
};
class WebSocketDeflateFramer {
public:
WebSocketDeflateFramer();
PassOwnPtr<WebSocketExtensionProcessor> createExtensionProcessor();
bool enabled() const { return m_enabled; }
PassOwnPtr<DeflateResultHolder> deflate(WebSocketFrame&);
void resetDeflateContext();
PassOwnPtr<InflateResultHolder> inflate(WebSocketFrame&);
void resetInflateContext();
void didFail();
void enableDeflate(int windowBits, WebSocketDeflater::ContextTakeOverMode);
private:
bool m_enabled;
OwnPtr<WebSocketDeflater> m_deflater;
OwnPtr<WebSocketInflater> m_inflater;
};
}
#endif