1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript.host.html;
16
17 import static org.htmlunit.BrowserVersionFeatures.JS_IFRAME_ALWAYS_EXECUTE_ONLOAD;
18
19 import org.htmlunit.html.BaseFrameElement;
20 import org.htmlunit.html.FrameWindow;
21 import org.htmlunit.html.FrameWindow.PageDenied;
22 import org.htmlunit.html.HtmlInlineFrame;
23 import org.htmlunit.javascript.configuration.JsxClass;
24 import org.htmlunit.javascript.configuration.JsxConstructor;
25 import org.htmlunit.javascript.configuration.JsxGetter;
26 import org.htmlunit.javascript.configuration.JsxSetter;
27 import org.htmlunit.javascript.host.Window;
28 import org.htmlunit.javascript.host.WindowProxy;
29 import org.htmlunit.javascript.host.event.Event;
30
31
32
33
34
35
36
37
38
39 @JsxClass(domClass = HtmlInlineFrame.class)
40 public class HTMLIFrameElement extends HTMLElement {
41
42
43 private boolean isAttachedToPageDuringOnload_;
44
45
46
47
48 @Override
49 @JsxConstructor
50 public void jsConstructor() {
51 super.jsConstructor();
52 }
53
54
55
56
57
58 @JsxGetter
59 public String getSrc() {
60 return getFrame().getSrcAttribute();
61 }
62
63
64
65
66
67 @JsxSetter
68 public void setSrc(final String src) {
69 getFrame().setSrcAttribute(src);
70 isAttachedToPageDuringOnload_ = false;
71 }
72
73
74
75
76
77
78 @JsxGetter
79 public DocumentProxy getContentDocument() {
80 final FrameWindow frameWindow = getFrame().getEnclosedWindow();
81 if (PageDenied.NONE != frameWindow.getPageDenied()) {
82 return null;
83 }
84 return ((Window) frameWindow.getScriptableObject()).getDocument_js();
85 }
86
87
88
89
90
91
92
93 @JsxGetter
94 public WindowProxy getContentWindow() {
95 final FrameWindow frameWin = getFrame().getEnclosedWindow();
96 if (frameWin.isClosed()) {
97 return null;
98 }
99 return Window.getProxy(frameWin);
100 }
101
102
103
104
105
106 @JsxGetter
107 @Override
108 public String getName() {
109 return getFrame().getNameAttribute();
110 }
111
112
113
114
115
116 @JsxSetter
117 @Override
118 public void setName(final String name) {
119 getFrame().setNameAttribute(name);
120 }
121
122 private BaseFrameElement getFrame() {
123 return (BaseFrameElement) getDomNodeOrDie();
124 }
125
126
127
128
129 @Override
130 public void setOnload(final Object eventHandler) {
131 super.setOnload(eventHandler);
132 isAttachedToPageDuringOnload_ = getDomNodeOrDie().isAttachedToPage();
133 }
134
135
136
137
138
139 @JsxGetter
140 public String getAlign() {
141 return getAlign(true);
142 }
143
144
145
146
147
148 @JsxSetter
149 public void setAlign(final String align) {
150 setAlign(align, false);
151 }
152
153
154
155
156
157 @JsxGetter(propertyName = "width")
158 public String getWidth_js() {
159 return getWidthOrHeight("width", Boolean.TRUE);
160 }
161
162
163
164
165
166 @JsxSetter(propertyName = "width")
167 public void setWidth_js(final String width) {
168 setWidthOrHeight("width", width, true);
169 }
170
171
172
173
174
175 @JsxGetter(propertyName = "height")
176 public String getHeight_js() {
177 return getWidthOrHeight("height", Boolean.TRUE);
178 }
179
180
181
182
183
184 @JsxSetter(propertyName = "height")
185 public void setHeight_js(final String height) {
186 setWidthOrHeight("height", height, true);
187 }
188
189
190
191
192 @Override
193 public void executeEventLocally(final Event event) {
194 if (Event.TYPE_LOAD != event.getType()
195 || !isAttachedToPageDuringOnload_ || getBrowserVersion().hasFeature(JS_IFRAME_ALWAYS_EXECUTE_ONLOAD)) {
196 super.executeEventLocally(event);
197 }
198 }
199
200
201
202
203 public void onRefresh() {
204 isAttachedToPageDuringOnload_ = false;
205 }
206 }