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 <wtf/Forward.h>
31 class ScriptController;
33 typedef HashMap<void*, JSC::Weak<JSC::JSObject>> DOMObjectWrapperMap;
35 class DOMWrapperWorld : public RefCounted<DOMWrapperWorld> {
37 static Ref<DOMWrapperWorld> create(JSC::VM& vm, bool isNormal = false)
39 return adoptRef(*new DOMWrapperWorld(vm, isNormal));
41 WEBCORE_EXPORT ~DOMWrapperWorld();
43 // Free as much memory held onto by this world as possible.
44 WEBCORE_EXPORT void clearWrappers();
46 void didCreateWindowShell(ScriptController* scriptController) { m_scriptControllersWithWindowShells.add(scriptController); }
47 void didDestroyWindowShell(ScriptController* scriptController) { m_scriptControllersWithWindowShells.remove(scriptController); }
49 void setShadowRootIsAlwaysOpen() { m_shadowRootIsAlwaysOpen = true; }
50 bool shadowRootIsAlwaysOpen() const { return m_shadowRootIsAlwaysOpen; }
52 // FIXME: can we make this private?
53 DOMObjectWrapperMap m_wrappers;
54 HashMap<CSSValue*, void*> m_cssValueRoots;
56 bool isNormal() const { return m_isNormal; }
58 JSC::VM& vm() const { return m_vm; }
61 DOMWrapperWorld(JSC::VM&, bool isNormal);
65 HashSet<ScriptController*> m_scriptControllersWithWindowShells;
67 bool m_shadowRootIsAlwaysOpen { false };
70 DOMWrapperWorld& normalWorld(JSC::VM&);
71 WEBCORE_EXPORT DOMWrapperWorld& mainThreadNormalWorld();
72 inline DOMWrapperWorld& debuggerWorld() { return mainThreadNormalWorld(); }
73 inline DOMWrapperWorld& pluginWorld() { return mainThreadNormalWorld(); }
75 inline DOMWrapperWorld& currentWorld(JSC::ExecState* exec)
77 return JSC::jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->world();
80 inline DOMWrapperWorld& worldForDOMObject(JSC::JSObject* object)
82 return JSC::jsCast<JSDOMGlobalObject*>(object->globalObject())->world();
85 } // namespace WebCore
87 #endif // DOMWrapperWorld_h