1 /* 2 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 14 * its contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #include "config.h" 30 #include "JSDOMWindowShell.h" 31 32 #include "Frame.h" 33 #include "JSDOMWindow.h" 34 #include "DOMWindow.h" 35 #include "ScriptController.h" 36 #include <runtime/JSObject.h> 37 38 using namespace JSC; 39 40 namespace WebCore { 41 42 ASSERT_CLASS_FITS_IN_CELL(JSDOMWindowShell); 43 44 const ClassInfo JSDOMWindowShell::s_info = { "JSDOMWindowShell", 0, 0, 0 }; 45 46 JSDOMWindowShell::JSDOMWindowShell(PassRefPtr<DOMWindow> window, DOMWrapperWorld* world) 47 : Base(JSDOMWindowShell::createStructure(jsNull())) 48 , m_window(0) 49 , m_world(world) 50 { 51 setWindow(window); 52 } 53 54 JSDOMWindowShell::~JSDOMWindowShell() 55 { 56 } 57 58 void JSDOMWindowShell::setWindow(PassRefPtr<DOMWindow> domWindow) 59 { 60 // Explicitly protect the global object's prototype so it isn't collected 61 // when we allocate the global object. (Once the global object is fully 62 // constructed, it can mark its own prototype.) 63 RefPtr<Structure> prototypeStructure = JSDOMWindowPrototype::createStructure(jsNull()); 64 ProtectedPtr<JSDOMWindowPrototype> prototype = new JSDOMWindowPrototype(prototypeStructure.release()); 65 66 RefPtr<Structure> structure = JSDOMWindow::createStructure(prototype); 67 JSDOMWindow* jsDOMWindow = new (JSDOMWindow::commonJSGlobalData()) JSDOMWindow(structure.release(), domWindow, this); 68 setWindow(jsDOMWindow); 69 } 70 71 // ---- 72 // JSObject methods 73 // ---- 74 75 void JSDOMWindowShell::markChildren(MarkStack& markStack) 76 { 77 Base::markChildren(markStack); 78 if (m_window) 79 markStack.append(m_window); 80 } 81 82 UString JSDOMWindowShell::className() const 83 { 84 return m_window->className(); 85 } 86 87 bool JSDOMWindowShell::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) 88 { 89 return m_window->getOwnPropertySlot(exec, propertyName, slot); 90 } 91 92 bool JSDOMWindowShell::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor) 93 { 94 return m_window->getOwnPropertyDescriptor(exec, propertyName, descriptor); 95 } 96 97 void JSDOMWindowShell::put(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot) 98 { 99 m_window->put(exec, propertyName, value, slot); 100 } 101 102 void JSDOMWindowShell::putWithAttributes(ExecState* exec, const Identifier& propertyName, JSValue value, unsigned attributes) 103 { 104 m_window->putWithAttributes(exec, propertyName, value, attributes); 105 } 106 107 bool JSDOMWindowShell::defineOwnProperty(JSC::ExecState* exec, const JSC::Identifier& propertyName, JSC::PropertyDescriptor& descriptor, bool shouldThrow) 108 { 109 return m_window->defineOwnProperty(exec, propertyName, descriptor, shouldThrow); 110 } 111 112 bool JSDOMWindowShell::deleteProperty(ExecState* exec, const Identifier& propertyName) 113 { 114 return m_window->deleteProperty(exec, propertyName); 115 } 116 117 void JSDOMWindowShell::getPropertyNames(ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode) 118 { 119 m_window->getPropertyNames(exec, propertyNames, mode); 120 } 121 122 void JSDOMWindowShell::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode) 123 { 124 m_window->getOwnPropertyNames(exec, propertyNames, mode); 125 } 126 127 void JSDOMWindowShell::defineGetter(ExecState* exec, const Identifier& propertyName, JSObject* getterFunction, unsigned attributes) 128 { 129 m_window->defineGetter(exec, propertyName, getterFunction, attributes); 130 } 131 132 void JSDOMWindowShell::defineSetter(ExecState* exec, const Identifier& propertyName, JSObject* setterFunction, unsigned attributes) 133 { 134 m_window->defineSetter(exec, propertyName, setterFunction, attributes); 135 } 136 137 JSValue JSDOMWindowShell::lookupGetter(ExecState* exec, const Identifier& propertyName) 138 { 139 return m_window->lookupGetter(exec, propertyName); 140 } 141 142 JSValue JSDOMWindowShell::lookupSetter(ExecState* exec, const Identifier& propertyName) 143 { 144 return m_window->lookupSetter(exec, propertyName); 145 } 146 147 JSObject* JSDOMWindowShell::unwrappedObject() 148 { 149 return m_window; 150 } 151 152 // ---- 153 // JSDOMWindow methods 154 // ---- 155 156 DOMWindow* JSDOMWindowShell::impl() const 157 { 158 return m_window->impl(); 159 } 160 161 void* JSDOMWindowShell::operator new(size_t size) 162 { 163 return JSDOMWindow::commonJSGlobalData()->heap.allocate(size); 164 } 165 166 // ---- 167 // Conversion methods 168 // ---- 169 170 JSValue toJS(ExecState* exec, Frame* frame) 171 { 172 if (!frame) 173 return jsNull(); 174 return frame->script()->windowShell(currentWorld(exec)); 175 } 176 177 JSDOMWindowShell* toJSDOMWindowShell(Frame* frame, DOMWrapperWorld* isolatedWorld) 178 { 179 if (!frame) 180 return 0; 181 return frame->script()->windowShell(isolatedWorld); 182 } 183 184 } // namespace WebCore 185