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