JSDOMWindowBase.h revision 5f1ab04193ad0130ca8204aadaceae083aca9881
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 <runtime/Protect.h> 26#include <wtf/HashMap.h> 27#include <wtf/OwnPtr.h> 28 29namespace WebCore { 30 31 class AtomicString; 32 class DOMWindow; 33 class Event; 34 class Frame; 35 class JSDOMWindow; 36 class JSDOMWindowShell; 37 class JSLocation; 38 class JSEventListener; 39 class SecurityOrigin; 40 41 class JSDOMWindowBasePrivate; 42 43 // This is the only WebCore JS binding which does not inherit from DOMObject 44 class JSDOMWindowBase : public JSDOMGlobalObject { 45 typedef JSDOMGlobalObject Base; 46 protected: 47 JSDOMWindowBase(PassRefPtr<JSC::Structure>, PassRefPtr<DOMWindow>, JSDOMWindowShell*); 48 49 public: 50 void updateDocument(); 51 52 DOMWindow* impl() const { return d()->impl.get(); } 53 virtual ScriptExecutionContext* scriptExecutionContext() const; 54 55 virtual bool getOwnPropertySlot(JSC::ExecState*, const JSC::Identifier&, JSC::PropertySlot&); 56 virtual void put(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::JSValue, JSC::PutPropertySlot&); 57 58 // Called just before removing this window from the JSDOMWindowShell. 59 void willRemoveFromWindowShell(); 60 61 virtual const JSC::ClassInfo* classInfo() const { return &s_info; } 62 static const JSC::ClassInfo s_info; 63 64 virtual JSC::ExecState* globalExec(); 65 66 virtual bool supportsProfiling() const; 67 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 74 void printErrorMessage(const String&) const; 75 76 // Don't call this version of allowsAccessFrom -- it's a slightly incorrect implementation used only by WebScriptObject 77 virtual bool allowsAccessFrom(const JSC::JSGlobalObject*) const; 78 79 virtual JSC::JSObject* toThisObject(JSC::ExecState*) const; 80 JSDOMWindowShell* shell() const; 81 82 static JSC::JSGlobalData* commonJSGlobalData(); 83 84 private: 85 struct JSDOMWindowBaseData : public JSDOMGlobalObjectData { 86 JSDOMWindowBaseData(PassRefPtr<DOMWindow>, JSDOMWindowShell*); 87 88 RefPtr<DOMWindow> impl; 89 JSDOMWindowShell* shell; 90 }; 91 92 static JSC::JSValue childFrameGetter(JSC::ExecState*, const JSC::Identifier&, const JSC::PropertySlot&); 93 static JSC::JSValue indexGetter(JSC::ExecState*, const JSC::Identifier&, const JSC::PropertySlot&); 94 static JSC::JSValue namedItemGetter(JSC::ExecState*, const JSC::Identifier&, const JSC::PropertySlot&); 95 96 bool allowsAccessFromPrivate(const JSC::JSGlobalObject*) const; 97 String crossDomainAccessErrorMessage(const JSC::JSGlobalObject*) const; 98 99 JSDOMWindowBaseData* d() const { return static_cast<JSDOMWindowBaseData*>(JSC::JSVariableObject::d); } 100 }; 101 102 // Returns a JSDOMWindow or jsNull() 103 JSC::JSValue toJS(JSC::ExecState*, DOMWindow*); 104 105 // Returns JSDOMWindow or 0 106 JSDOMWindow* toJSDOMWindow(Frame*); 107 JSDOMWindow* toJSDOMWindow(JSC::JSValue); 108 109} // namespace WebCore 110 111#endif // JSDOMWindowBase_h 112