1/* 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. 6 * 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. 11 * 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. 16 * 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 20 */ 21 22#ifndef DOMWrapperWorld_h 23#define DOMWrapperWorld_h 24 25#include "JSDOMGlobalObject.h" 26#include <runtime/WeakGCMap.h> 27#include <wtf/Forward.h> 28 29namespace WebCore { 30 31class CSSValue; 32class JSDOMWrapper; 33class ScriptController; 34 35typedef HashMap<void*, JSC::Weak<JSDOMWrapper> > DOMObjectWrapperMap; 36typedef JSC::WeakGCMap<StringImpl*, JSC::JSString, PtrHash<StringImpl*> > JSStringCache; 37 38class DOMWrapperWorld : public RefCounted<DOMWrapperWorld> { 39public: 40 static PassRefPtr<DOMWrapperWorld> create(JSC::VM* vm, bool isNormal = false) 41 { 42 return adoptRef(new DOMWrapperWorld(vm, isNormal)); 43 } 44 ~DOMWrapperWorld(); 45 46 // Free as much memory held onto by this world as possible. 47 void clearWrappers(); 48 49 void didCreateWindowShell(ScriptController* scriptController) { m_scriptControllersWithWindowShells.add(scriptController); } 50 void didDestroyWindowShell(ScriptController* scriptController) { m_scriptControllersWithWindowShells.remove(scriptController); } 51 52 // FIXME: can we make this private? 53 DOMObjectWrapperMap m_wrappers; 54 JSStringCache m_stringCache; 55 HashMap<CSSValue*, void*> m_cssValueRoots; 56 57 bool isNormal() const { return m_isNormal; } 58 59 JSC::VM* vm() const { return m_vm; } 60 61protected: 62 DOMWrapperWorld(JSC::VM*, bool isNormal); 63 64private: 65 JSC::VM* m_vm; 66 HashSet<ScriptController*> m_scriptControllersWithWindowShells; 67 bool m_isNormal; 68}; 69 70DOMWrapperWorld* normalWorld(JSC::VM&); 71DOMWrapperWorld* mainThreadNormalWorld(); 72inline DOMWrapperWorld* debuggerWorld() { return mainThreadNormalWorld(); } 73inline DOMWrapperWorld* pluginWorld() { return mainThreadNormalWorld(); } 74 75inline DOMWrapperWorld* currentWorld(JSC::ExecState* exec) 76{ 77 return JSC::jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->world(); 78} 79 80} // namespace WebCore 81 82#endif // DOMWrapperWorld_h 83