#ifndef InspectorState_h
#define InspectorState_h
#include "platform/JSONValues.h"
#include "wtf/HashMap.h"
#include "wtf/text/WTFString.h"
namespace WebCore {
class InspectorStateClient;
class InspectorStateUpdateListener {
public:
virtual ~InspectorStateUpdateListener() { }
virtual void inspectorStateUpdated() = 0;
};
class InspectorState FINAL {
WTF_MAKE_FAST_ALLOCATED;
public:
InspectorState(InspectorStateUpdateListener*, PassRefPtr<JSONObject>);
void loadFromCookie(const String& inspectorStateCookie);
void mute();
void unmute();
bool getBoolean(const String& propertyName);
String getString(const String& propertyName);
long getLong(const String& propertyName);
long getLong(const String& propertyName, long defaultValue);
double getDouble(const String& propertyName);
double getDouble(const String& propertyName, double defaultValue);
PassRefPtr<JSONObject> getObject(const String& propertyName);
void setBoolean(const String& propertyName, bool value) { setValue(propertyName, JSONBasicValue::create(value)); }
void setString(const String& propertyName, const String& value) { setValue(propertyName, JSONString::create(value)); }
void setLong(const String& propertyName, long value) { setValue(propertyName, JSONBasicValue::create((double)value)); }
void setDouble(const String& propertyName, double value) { setValue(propertyName, JSONBasicValue::create(value)); }
void setObject(const String& propertyName, PassRefPtr<JSONObject> value) { setValue(propertyName, value); }
void remove(const String&);
private:
void updateCookie();
void setValue(const String& propertyName, PassRefPtr<JSONValue>);
void setFromCookie(PassRefPtr<JSONObject>);
friend class InspectorCompositeState;
InspectorStateUpdateListener* m_listener;
RefPtr<JSONObject> m_properties;
};
class InspectorCompositeState FINAL : public InspectorStateUpdateListener {
public:
InspectorCompositeState(InspectorStateClient* inspectorClient)
: m_client(inspectorClient)
, m_stateObject(JSONObject::create())
, m_isMuted(false)
{
}
virtual ~InspectorCompositeState() { }
void mute();
void unmute();
InspectorState* createAgentState(const String&);
void loadFromCookie(const String&);
private:
typedef HashMap<String, OwnPtr<InspectorState> > InspectorStateMap;
virtual void inspectorStateUpdated() OVERRIDE;
InspectorStateClient* m_client;
RefPtr<JSONObject> m_stateObject;
bool m_isMuted;
InspectorStateMap m_inspectorStateMap;
};
}
#endif