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 "JSDOMBinding.h" 24 #include "JSDOMGlobalObject.h" 25 #include <wtf/Forward.h> 26 27 namespace WebCore { 28 29 class DOMWindow; 30 class Frame; 31 class DOMWrapperWorld; 32 class JSDOMWindow; 33 class JSDOMWindowShell; 34 35 class JSDOMWindowBasePrivate; 36 37 class JSDOMWindowBase : public JSDOMGlobalObject { 38 typedef JSDOMGlobalObject Base; 39 protected: 40 JSDOMWindowBase(JSC::JSGlobalData&, JSC::Structure*, PassRefPtr<DOMWindow>, JSDOMWindowShell*); 41 42 public: 43 void updateDocument(); 44 impl()45 DOMWindow* impl() const { return m_impl.get(); } 46 virtual ScriptExecutionContext* scriptExecutionContext() const; 47 48 // Called just before removing this window from the JSDOMWindowShell. 49 void willRemoveFromWindowShell(); 50 51 static const JSC::ClassInfo s_info; 52 createStructure(JSC::JSGlobalData & globalData,JSC::JSValue prototype)53 static JSC::Structure* createStructure(JSC::JSGlobalData& globalData, JSC::JSValue prototype) 54 { 55 return JSC::Structure::create(globalData, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), AnonymousSlotCount, &s_info); 56 } 57 58 virtual JSC::ExecState* globalExec(); 59 virtual bool supportsProfiling() const; 60 virtual bool supportsRichSourceInfo() const; 61 virtual bool shouldInterruptScript() const; 62 63 bool allowsAccessFrom(JSC::ExecState*) const; 64 bool allowsAccessFromNoErrorMessage(JSC::ExecState*) const; 65 bool allowsAccessFrom(JSC::ExecState*, String& message) const; 66 void printErrorMessage(const String&) const; 67 68 // Don't call this version of allowsAccessFrom -- it's a slightly incorrect implementation used only by WebScriptObject 69 virtual bool allowsAccessFrom(const JSC::JSGlobalObject*) const; 70 71 virtual JSC::JSObject* toThisObject(JSC::ExecState*) const; 72 virtual JSC::JSValue toStrictThisObject(JSC::ExecState*) const; 73 JSDOMWindowShell* shell() const; 74 75 static JSC::JSGlobalData* commonJSGlobalData(); 76 77 private: 78 RefPtr<DOMWindow> m_impl; 79 JSDOMWindowShell* m_shell; 80 81 bool allowsAccessFromPrivate(const JSC::JSGlobalObject*) const; 82 String crossDomainAccessErrorMessage(const JSC::JSGlobalObject*) const; 83 }; 84 85 // Returns a JSDOMWindow or jsNull() 86 // JSDOMGlobalObject* is ignored, accessing a window in any context will 87 // use that DOMWindow's prototype chain. 88 JSC::JSValue toJS(JSC::ExecState*, JSDOMGlobalObject*, DOMWindow*); 89 JSC::JSValue toJS(JSC::ExecState*, DOMWindow*); 90 91 // Returns JSDOMWindow or 0 92 JSDOMWindow* toJSDOMWindow(Frame*, DOMWrapperWorld*); 93 JSDOMWindow* toJSDOMWindow(JSC::JSValue); 94 95 } // namespace WebCore 96 97 #endif // JSDOMWindowBase_h 98