1 /* 2 * Copyright (C) 1999-2001 Harri Porten (porten (at) kde.org) 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 4 * Copyright (C) 2007 Samuel Weinig <sam (at) webkit.org> 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 */ 20 21 #include "config.h" 22 #include "DOMWrapperWorld.h" 23 24 #include "JSDOMWindow.h" 25 #include "ScriptController.h" 26 #include "WebCoreJSClientData.h" 27 28 using namespace JSC; 29 30 namespace WebCore { 31 32 void JSDOMWrapperOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) 33 { 34 JSDOMWrapper* wrapper = static_cast<JSDOMWrapper*>(handle.get().asCell()); 35 void* domObject = context; 36 uncacheWrapper(m_world, domObject, wrapper); 37 } 38 39 DOMWrapperWorld::DOMWrapperWorld(JSC::JSGlobalData* globalData, bool isNormal) 40 : m_globalData(globalData) 41 , m_isNormal(isNormal) 42 , m_defaultWrapperOwner(this) 43 { 44 JSGlobalData::ClientData* clientData = m_globalData->clientData; 45 ASSERT(clientData); 46 static_cast<WebCoreJSClientData*>(clientData)->rememberWorld(this); 47 } 48 49 DOMWrapperWorld::~DOMWrapperWorld() 50 { 51 JSGlobalData::ClientData* clientData = m_globalData->clientData; 52 ASSERT(clientData); 53 static_cast<WebCoreJSClientData*>(clientData)->forgetWorld(this); 54 55 // These items are created lazily. 56 while (!m_scriptControllersWithWindowShells.isEmpty()) 57 (*m_scriptControllersWithWindowShells.begin())->destroyWindowShell(this); 58 } 59 60 void DOMWrapperWorld::clearWrappers() 61 { 62 m_wrappers.clear(); 63 m_stringCache.clear(); 64 65 // These items are created lazily. 66 while (!m_scriptControllersWithWindowShells.isEmpty()) 67 (*m_scriptControllersWithWindowShells.begin())->destroyWindowShell(this); 68 } 69 70 DOMWrapperWorld* normalWorld(JSC::JSGlobalData& globalData) 71 { 72 JSGlobalData::ClientData* clientData = globalData.clientData; 73 ASSERT(clientData); 74 return static_cast<WebCoreJSClientData*>(clientData)->normalWorld(); 75 } 76 77 DOMWrapperWorld* mainThreadNormalWorld() 78 { 79 ASSERT(isMainThread()); 80 static DOMWrapperWorld* cachedNormalWorld = normalWorld(*JSDOMWindow::commonJSGlobalData()); 81 return cachedNormalWorld; 82 } 83 84 } // namespace WebCore 85