• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
JSDOMWindowShell(PassRefPtr<DOMWindow> window)46 JSDOMWindowShell::JSDOMWindowShell(PassRefPtr<DOMWindow> window)
47     : Base(JSDOMWindowShell::createStructure(jsNull()))
48     , m_window(0)
49 {
50     setWindow(window);
51 }
52 
~JSDOMWindowShell()53 JSDOMWindowShell::~JSDOMWindowShell()
54 {
55 }
56 
setWindow(PassRefPtr<DOMWindow> domWindow)57 void JSDOMWindowShell::setWindow(PassRefPtr<DOMWindow> domWindow)
58 {
59     // Explicitly protect the global object's prototype so it isn't collected
60     // when we allocate the global object. (Once the global object is fully
61     // constructed, it can mark its own prototype.)
62     RefPtr<Structure> prototypeStructure = JSDOMWindowPrototype::createStructure(jsNull());
63     ProtectedPtr<JSDOMWindowPrototype> prototype = new JSDOMWindowPrototype(prototypeStructure.release());
64 
65     RefPtr<Structure> structure = JSDOMWindow::createStructure(prototype);
66     JSDOMWindow* jsDOMWindow = new (JSDOMWindow::commonJSGlobalData()) JSDOMWindow(structure.release(), domWindow, this);
67     setWindow(jsDOMWindow);
68 }
69 
70 // ----
71 // JSObject methods
72 // ----
73 
markChildren(MarkStack & markStack)74 void JSDOMWindowShell::markChildren(MarkStack& markStack)
75 {
76     Base::markChildren(markStack);
77     if (m_window)
78         markStack.append(m_window);
79 }
80 
className() const81 UString JSDOMWindowShell::className() const
82 {
83     return m_window->className();
84 }
85 
getOwnPropertySlot(ExecState * exec,const Identifier & propertyName,PropertySlot & slot)86 bool JSDOMWindowShell::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
87 {
88     return m_window->getOwnPropertySlot(exec, propertyName, slot);
89 }
90 
put(ExecState * exec,const Identifier & propertyName,JSValue value,PutPropertySlot & slot)91 void JSDOMWindowShell::put(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)
92 {
93     m_window->put(exec, propertyName, value, slot);
94 }
95 
putWithAttributes(ExecState * exec,const Identifier & propertyName,JSValue value,unsigned attributes)96 void JSDOMWindowShell::putWithAttributes(ExecState* exec, const Identifier& propertyName, JSValue value, unsigned attributes)
97 {
98     m_window->putWithAttributes(exec, propertyName, value, attributes);
99 }
100 
deleteProperty(ExecState * exec,const Identifier & propertyName)101 bool JSDOMWindowShell::deleteProperty(ExecState* exec, const Identifier& propertyName)
102 {
103     return m_window->deleteProperty(exec, propertyName);
104 }
105 
getPropertyNames(ExecState * exec,PropertyNameArray & propertyNames)106 void JSDOMWindowShell::getPropertyNames(ExecState* exec, PropertyNameArray& propertyNames)
107 {
108     m_window->getPropertyNames(exec, propertyNames);
109 }
110 
getPropertyAttributes(JSC::ExecState * exec,const Identifier & propertyName,unsigned & attributes) const111 bool JSDOMWindowShell::getPropertyAttributes(JSC::ExecState* exec, const Identifier& propertyName, unsigned& attributes) const
112 {
113     return m_window->getPropertyAttributes(exec, propertyName, attributes);
114 }
115 
defineGetter(ExecState * exec,const Identifier & propertyName,JSObject * getterFunction)116 void JSDOMWindowShell::defineGetter(ExecState* exec, const Identifier& propertyName, JSObject* getterFunction)
117 {
118     m_window->defineGetter(exec, propertyName, getterFunction);
119 }
120 
defineSetter(ExecState * exec,const Identifier & propertyName,JSObject * setterFunction)121 void JSDOMWindowShell::defineSetter(ExecState* exec, const Identifier& propertyName, JSObject* setterFunction)
122 {
123     m_window->defineSetter(exec, propertyName, setterFunction);
124 }
125 
lookupGetter(ExecState * exec,const Identifier & propertyName)126 JSValue JSDOMWindowShell::lookupGetter(ExecState* exec, const Identifier& propertyName)
127 {
128     return m_window->lookupGetter(exec, propertyName);
129 }
130 
lookupSetter(ExecState * exec,const Identifier & propertyName)131 JSValue JSDOMWindowShell::lookupSetter(ExecState* exec, const Identifier& propertyName)
132 {
133     return m_window->lookupSetter(exec, propertyName);
134 }
135 
unwrappedObject()136 JSObject* JSDOMWindowShell::unwrappedObject()
137 {
138     return m_window;
139 }
140 
141 // ----
142 // JSDOMWindow methods
143 // ----
144 
impl() const145 DOMWindow* JSDOMWindowShell::impl() const
146 {
147     return m_window->impl();
148 }
149 
operator new(size_t size)150 void* JSDOMWindowShell::operator new(size_t size)
151 {
152     return JSDOMWindow::commonJSGlobalData()->heap.allocate(size);
153 }
154 
155 // ----
156 // Conversion methods
157 // ----
158 
toJS(ExecState *,Frame * frame)159 JSValue toJS(ExecState*, Frame* frame)
160 {
161     if (!frame)
162         return jsNull();
163     return frame->script()->windowShell();
164 }
165 
toJSDOMWindowShell(Frame * frame)166 JSDOMWindowShell* toJSDOMWindowShell(Frame* frame)
167 {
168     if (!frame)
169         return 0;
170     return frame->script()->windowShell();
171 }
172 
173 } // namespace WebCore
174