| 1 | /* |
| 2 | * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) |
| 3 | * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. |
| 4 | * Copyright (C) 2007 Samuel Weinig <sam@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 "CommonVM.h" |
| 25 | #include "JSDOMWindow.h" |
| 26 | #include "WebCoreJSClientData.h" |
| 27 | #include "WindowProxy.h" |
| 28 | #include <wtf/MainThread.h> |
| 29 | |
| 30 | |
| 31 | namespace WebCore { |
| 32 | using namespace JSC; |
| 33 | |
| 34 | DOMWrapperWorld::DOMWrapperWorld(JSC::VM& vm, bool isNormal) |
| 35 | : m_vm(vm) |
| 36 | , m_isNormal(isNormal) |
| 37 | { |
| 38 | VM::ClientData* clientData = m_vm.clientData; |
| 39 | ASSERT(clientData); |
| 40 | static_cast<JSVMClientData*>(clientData)->rememberWorld(*this); |
| 41 | } |
| 42 | |
| 43 | DOMWrapperWorld::~DOMWrapperWorld() |
| 44 | { |
| 45 | VM::ClientData* clientData = m_vm.clientData; |
| 46 | ASSERT(clientData); |
| 47 | static_cast<JSVMClientData*>(clientData)->forgetWorld(*this); |
| 48 | |
| 49 | // These items are created lazily. |
| 50 | while (!m_jsWindowProxies.isEmpty()) |
| 51 | (*m_jsWindowProxies.begin())->destroyJSWindowProxy(*this); |
| 52 | } |
| 53 | |
| 54 | void DOMWrapperWorld::clearWrappers() |
| 55 | { |
| 56 | m_wrappers.clear(); |
| 57 | |
| 58 | // These items are created lazily. |
| 59 | while (!m_jsWindowProxies.isEmpty()) |
| 60 | (*m_jsWindowProxies.begin())->destroyJSWindowProxy(*this); |
| 61 | } |
| 62 | |
| 63 | DOMWrapperWorld& normalWorld(JSC::VM& vm) |
| 64 | { |
| 65 | VM::ClientData* clientData = vm.clientData; |
| 66 | ASSERT(clientData); |
| 67 | return static_cast<JSVMClientData*>(clientData)->normalWorld(); |
| 68 | } |
| 69 | |
| 70 | DOMWrapperWorld& mainThreadNormalWorld() |
| 71 | { |
| 72 | ASSERT(isMainThread()); |
| 73 | static DOMWrapperWorld& cachedNormalWorld = normalWorld(commonVM()); |
| 74 | return cachedNormalWorld; |
| 75 | } |
| 76 | |
| 77 | } // namespace WebCore |
| 78 | |