1/* 2 * Copyright (C) 2000 Harri Porten (porten@kde.org) 3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reseved. 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public 16 * License along with this library; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 */ 19 20#ifndef JSDOMWindowBase_h 21#define JSDOMWindowBase_h 22 23#include "PlatformString.h" 24#include "JSDOMBinding.h" 25#include <heap/Strong.h> 26#include <wtf/Forward.h> 27#include <wtf/HashMap.h> 28#include <wtf/OwnPtr.h> 29 30namespace WebCore { 31 32 class DOMWindow; 33 class Event; 34 class Frame; 35 class DOMWrapperWorld; 36 class JSDOMWindow; 37 class JSDOMWindowShell; 38 class JSLocation; 39 class JSEventListener; 40 class SecurityOrigin; 41 42 class JSDOMWindowBasePrivate; 43 44 class JSDOMWindowBase : public JSDOMGlobalObject { 45 typedef JSDOMGlobalObject Base; 46 protected: 47 JSDOMWindowBase(JSC::JSGlobalData&, JSC::Structure*, PassRefPtr<DOMWindow>, JSDOMWindowShell*); 48 49 public: 50 void updateDocument(); 51 52 DOMWindow* impl() const { return m_impl.get(); } 53 virtual ScriptExecutionContext* scriptExecutionContext() const; 54 55 // Called just before removing this window from the JSDOMWindowShell. 56 void willRemoveFromWindowShell(); 57 58 static const JSC::ClassInfo s_info; 59 60 static JSC::Structure* createStructure(JSC::JSGlobalData& globalData, JSC::JSValue prototype) 61 { 62 return JSC::Structure::create(globalData, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), AnonymousSlotCount, &s_info); 63 } 64 65 virtual JSC::ExecState* globalExec(); 66 virtual bool supportsProfiling() const; 67 virtual bool supportsRichSourceInfo() const; 68 virtual bool shouldInterruptScript() const; 69 70 bool allowsAccessFrom(JSC::ExecState*) const; 71 bool allowsAccessFromNoErrorMessage(JSC::ExecState*) const; 72 bool allowsAccessFrom(JSC::ExecState*, String& message) const; 73 void printErrorMessage(const String&) const; 74 75 // Don't call this version of allowsAccessFrom -- it's a slightly incorrect implementation used only by WebScriptObject 76 virtual bool allowsAccessFrom(const JSC::JSGlobalObject*) const; 77 78 virtual JSC::JSObject* toThisObject(JSC::ExecState*) const; 79 virtual JSC::JSValue toStrictThisObject(JSC::ExecState*) const; 80 JSDOMWindowShell* shell() const; 81 82 static JSC::JSGlobalData* commonJSGlobalData(); 83 84 private: 85 RefPtr<DOMWindow> m_impl; 86 JSDOMWindowShell* m_shell; 87 88 bool allowsAccessFromPrivate(const JSC::JSGlobalObject*) const; 89 String crossDomainAccessErrorMessage(const JSC::JSGlobalObject*) const; 90 }; 91 92 // Returns a JSDOMWindow or jsNull() 93 // JSDOMGlobalObject* is ignored, accessing a window in any context will 94 // use that DOMWindow's prototype chain. 95 JSC::JSValue toJS(JSC::ExecState*, JSDOMGlobalObject*, DOMWindow*); 96 JSC::JSValue toJS(JSC::ExecState*, DOMWindow*); 97 98 // Returns JSDOMWindow or 0 99 JSDOMWindow* toJSDOMWindow(Frame*, DOMWrapperWorld*); 100 JSDOMWindow* toJSDOMWindow(JSC::JSValue); 101 102} // namespace WebCore 103 104#endif // JSDOMWindowBase_h 105