// -*- c-basic-offset: 2 -*- /* * This file is part of the KDE libraries * Copyright (C) 1999-2003 Harri Porten (porten@kde.org) * Copyright (C) 2001-2003 David Faure (faure@kde.org) * Copyright (C) 2003 Apple Computer, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "kjs_binding.h" #include #if defined(HAVE_VALGRIND_MEMCHECK_H) #include #define VALGRIND_SUPPORT #endif #include "kjs_dom.h" #include "kjs_range.h" #include #include #include #include #include #include #include #include #include #include "debugger/debugwindow.h" #include #include #include using namespace KJSDebugger; namespace KJS { UString DOMObject::toString(ExecState *) const { return "[object " + className() + "]"; } HashMap* ScriptInterpreter::s_allDomObjects; typedef QList InterpreterList; static InterpreterList *interpreterList; ScriptInterpreter::ScriptInterpreter( JSGlobalObject *global, khtml::ChildFrame* frame ) : Interpreter( global ), m_frame( frame ), m_evt( 0L ), m_inlineCode(false), m_timerCallback(false) { #ifdef KJS_VERBOSE kDebug(6070) << "ScriptInterpreter::ScriptInterpreter " << this << " for part=" << m_frame; #endif if ( !interpreterList ) interpreterList = new InterpreterList; interpreterList->append( this ); } ScriptInterpreter::~ScriptInterpreter() { #ifdef KJS_VERBOSE kDebug(6070) << "ScriptInterpreter::~ScriptInterpreter " << this << " for part=" << m_frame; #endif assert( interpreterList && interpreterList->contains( this ) ); interpreterList->removeAll( this ); if ( interpreterList->isEmpty() ) { delete interpreterList; interpreterList = 0; } } void ScriptInterpreter::forgetDOMObject( void* objectHandle ) { if( !interpreterList ) return; for (int i = 0; i < interpreterList->size(); ++i) interpreterList->at(i)->m_domObjects.remove( objectHandle ); allDomObjects()->remove( objectHandle ); } void ScriptInterpreter::mark(bool isMain) { Interpreter::mark(isMain); #ifdef KJS_VERBOSE kDebug(6070) << "ScriptInterpreter::mark " << this << " marking " << m_domObjects.size() << " DOM objects"; #endif HashMap::iterator it = m_domObjects.begin(); while (it != m_domObjects.end()) { DOMObject* obj = it->second; if (obj->shouldMark()) obj->mark(); ++it; } } KParts::ReadOnlyPart* ScriptInterpreter::part() const { return m_frame->m_part.data(); } bool ScriptInterpreter::isWindowOpenAllowed() const { if ( m_evt ) { int id = m_evt->handle()->id(); bool eventOk = ( // mouse events id == DOM::EventImpl::CLICK_EVENT || id == DOM::EventImpl::MOUSEUP_EVENT || id == DOM::EventImpl::MOUSEDOWN_EVENT || id == DOM::EventImpl::KHTML_ECMA_CLICK_EVENT || id == DOM::EventImpl::KHTML_ECMA_DBLCLICK_EVENT || // keyboard events id == DOM::EventImpl::KEYDOWN_EVENT || id == DOM::EventImpl::KEYPRESS_EVENT || id == DOM::EventImpl::KEYUP_EVENT || // other accepted events id == DOM::EventImpl::SELECT_EVENT || id == DOM::EventImpl::CHANGE_EVENT || id == DOM::EventImpl::SUBMIT_EVENT ); kDebug(6070) << "Window.open, smart policy: id=" << id << " eventOk=" << eventOk; if (eventOk) return true; } else // no event { if ( m_inlineCode && !m_timerCallback ) { // This is the ok"; } else // This is the case or a timer callback -> block it kDebug(6070) << "Window.open, smart policy, no event,