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 WebCoreJSClientData_h 23#define WebCoreJSClientData_h 24 25#include "DOMWrapperWorld.h" 26#include "DOMObjectHashTableMap.h" 27#include <wtf/HashSet.h> 28#include <wtf/RefPtr.h> 29 30namespace WebCore { 31 32class WebCoreJSClientData : public JSC::VM::ClientData { 33 WTF_MAKE_NONCOPYABLE(WebCoreJSClientData); WTF_MAKE_FAST_ALLOCATED; 34 friend class VMWorldIterator; 35 friend void initNormalWorldClientData(JSC::VM*); 36 37public: 38 WebCoreJSClientData() { } 39 virtual ~WebCoreJSClientData() 40 { 41 ASSERT(m_worldSet.contains(m_normalWorld.get())); 42 ASSERT(m_worldSet.size() == 1); 43 ASSERT(m_normalWorld->hasOneRef()); 44 m_normalWorld.clear(); 45 ASSERT(m_worldSet.isEmpty()); 46 } 47 48 DOMWrapperWorld* normalWorld() { return m_normalWorld.get(); } 49 50 void getAllWorlds(Vector<RefPtr<DOMWrapperWorld> >& worlds) 51 { 52 copyToVector(m_worldSet, worlds); 53 } 54 55 void rememberWorld(DOMWrapperWorld* world) 56 { 57 ASSERT(!m_worldSet.contains(world)); 58 m_worldSet.add(world); 59 } 60 void forgetWorld(DOMWrapperWorld* world) 61 { 62 ASSERT(m_worldSet.contains(world)); 63 m_worldSet.remove(world); 64 } 65 66 DOMObjectHashTableMap hashTableMap; 67 68private: 69 HashSet<DOMWrapperWorld*> m_worldSet; 70 RefPtr<DOMWrapperWorld> m_normalWorld; 71}; 72 73inline void initNormalWorldClientData(JSC::VM* vm) 74{ 75 WebCoreJSClientData* webCoreJSClientData = new WebCoreJSClientData; 76 vm->clientData = webCoreJSClientData; // ~VM deletes this pointer. 77 webCoreJSClientData->m_normalWorld = DOMWrapperWorld::create(vm, true); 78} 79 80} // namespace WebCore 81 82#endif // WebCoreJSClientData_h 83