2 * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
3 * Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009 Apple Inc. All rights reserved.
4 * Copyright (C) 2007 Samuel Weinig <sam@webkit.org>
5 * Copyright (C) 2009 Google, Inc. All rights reserved.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #ifndef DOMWrapperWorld_h
23 #define DOMWrapperWorld_h
25 #include "JSDOMGlobalObject.h"
26 #include <heap/Weak.h>
27 #include <runtime/WeakGCMap.h>
28 #include <wtf/Forward.h>
34 class ScriptController;
36 typedef HashMap<void*, JSC::Weak<JSDOMWrapper> > DOMObjectWrapperMap;
37 typedef HashMap<StringImpl*, JSC::Weak<JSC::JSString> > JSStringCache;
39 class JSDOMWrapperOwner : public JSC::WeakHandleOwner {
41 JSDOMWrapperOwner(DOMWrapperWorld*);
42 virtual void finalize(JSC::Handle<JSC::Unknown>, void* context);
45 DOMWrapperWorld* m_world;
48 inline JSDOMWrapperOwner::JSDOMWrapperOwner(DOMWrapperWorld* world)
53 class JSStringOwner : public JSC::WeakHandleOwner {
55 JSStringOwner(DOMWrapperWorld*);
56 virtual void finalize(JSC::Handle<JSC::Unknown>, void* context);
59 DOMWrapperWorld* m_world;
62 inline JSStringOwner::JSStringOwner(DOMWrapperWorld* world)
67 class DOMWrapperWorld : public RefCounted<DOMWrapperWorld> {
69 static PassRefPtr<DOMWrapperWorld> create(JSC::JSGlobalData* globalData, bool isNormal = false)
71 return adoptRef(new DOMWrapperWorld(globalData, isNormal));
75 // Free as much memory held onto by this world as possible.
78 void didCreateWindowShell(ScriptController* scriptController) { m_scriptControllersWithWindowShells.add(scriptController); }
79 void didDestroyWindowShell(ScriptController* scriptController) { m_scriptControllersWithWindowShells.remove(scriptController); }
81 // FIXME: can we make this private?
82 DOMObjectWrapperMap m_wrappers;
83 JSStringCache m_stringCache;
84 HashMap<CSSValue*, void*> m_cssValueRoots;
86 bool isNormal() const { return m_isNormal; }
88 JSC::JSGlobalData* globalData() const { return m_globalData; }
89 JSDOMWrapperOwner* defaultWrapperOwner() { return &m_defaultWrapperOwner; }
90 JSStringOwner* stringWrapperOwner() { return &m_stringWrapperOwner; }
93 DOMWrapperWorld(JSC::JSGlobalData*, bool isNormal);
96 JSC::JSGlobalData* m_globalData;
97 HashSet<ScriptController*> m_scriptControllersWithWindowShells;
99 JSDOMWrapperOwner m_defaultWrapperOwner;
100 JSStringOwner m_stringWrapperOwner;
103 DOMWrapperWorld* normalWorld(JSC::JSGlobalData&);
104 DOMWrapperWorld* mainThreadNormalWorld();
105 inline DOMWrapperWorld* debuggerWorld() { return mainThreadNormalWorld(); }
106 inline DOMWrapperWorld* pluginWorld() { return mainThreadNormalWorld(); }
108 inline DOMWrapperWorld* currentWorld(JSC::ExecState* exec)
110 return static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->world();
113 } // namespace WebCore
115 #endif // DOMWrapperWorld_h