#ifndef DOMWrapperWorld_h
#define DOMWrapperWorld_h
#include "JSDOMGlobalObject.h"
#include <heap/Weak.h>
#include <runtime/WeakGCMap.h>
#include <wtf/Forward.h>
namespace WebCore {
class CSSValue;
class JSDOMWrapper;
class ScriptController;
typedef HashMap<void*, JSC::Weak<JSDOMWrapper> > DOMObjectWrapperMap;
typedef HashMap<StringImpl*, JSC::Weak<JSC::JSString> > JSStringCache;
class JSDOMWrapperOwner : public JSC::WeakHandleOwner {
public:
JSDOMWrapperOwner(DOMWrapperWorld*);
virtual void finalize(JSC::Handle<JSC::Unknown>, void* context);
private:
DOMWrapperWorld* m_world;
};
inline JSDOMWrapperOwner::JSDOMWrapperOwner(DOMWrapperWorld* world)
: m_world(world)
{
}
class JSStringOwner : public JSC::WeakHandleOwner {
public:
JSStringOwner(DOMWrapperWorld*);
virtual void finalize(JSC::Handle<JSC::Unknown>, void* context);
private:
DOMWrapperWorld* m_world;
};
inline JSStringOwner::JSStringOwner(DOMWrapperWorld* world)
: m_world(world)
{
}
class DOMWrapperWorld : public RefCounted<DOMWrapperWorld> {
public:
static PassRefPtr<DOMWrapperWorld> create(JSC::JSGlobalData* globalData, bool isNormal = false)
{
return adoptRef(new DOMWrapperWorld(globalData, isNormal));
}
~DOMWrapperWorld();
void clearWrappers();
void didCreateWindowShell(ScriptController* scriptController) { m_scriptControllersWithWindowShells.add(scriptController); }
void didDestroyWindowShell(ScriptController* scriptController) { m_scriptControllersWithWindowShells.remove(scriptController); }
DOMObjectWrapperMap m_wrappers;
JSStringCache m_stringCache;
HashMap<CSSValue*, void*> m_cssValueRoots;
bool isNormal() const { return m_isNormal; }
JSC::JSGlobalData* globalData() const { return m_globalData; }
JSDOMWrapperOwner* defaultWrapperOwner() { return &m_defaultWrapperOwner; }
JSStringOwner* stringWrapperOwner() { return &m_stringWrapperOwner; }
protected:
DOMWrapperWorld(JSC::JSGlobalData*, bool isNormal);
private:
JSC::JSGlobalData* m_globalData;
HashSet<ScriptController*> m_scriptControllersWithWindowShells;
bool m_isNormal;
JSDOMWrapperOwner m_defaultWrapperOwner;
JSStringOwner m_stringWrapperOwner;
};
DOMWrapperWorld* normalWorld(JSC::JSGlobalData&);
DOMWrapperWorld* mainThreadNormalWorld();
inline DOMWrapperWorld* debuggerWorld() { return mainThreadNormalWorld(); }
inline DOMWrapperWorld* pluginWorld() { return mainThreadNormalWorld(); }
inline DOMWrapperWorld* currentWorld(JSC::ExecState* exec)
{
return static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->world();
}
}
#endif // DOMWrapperWorld_h