1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
/*
* Copyright (C) 1999 Lars Knoll (knoll@kde.org)
* (C) 1999 Antti Koivisto (koivisto@kde.org)
* (C) 2000 Simon Hausmann (hausmann@kde.org)
* (C) 2001 Dirk Mueller (mueller@kde.org)
* Copyright (C) 2004, 2006, 2008, 2009 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "HTMLFrameElementBase.h"
#include "CSSHelper.h"
#include "Document.h"
#include "EventNames.h"
#include "FocusController.h"
#include "Frame.h"
#include "FrameLoader.h"
#include "FrameTree.h"
#include "FrameView.h"
#include "HTMLFrameSetElement.h"
#include "HTMLNames.h"
#include "ScriptEventListener.h"
#include "KURL.h"
#include "MappedAttribute.h"
#include "Page.h"
#include "RenderFrame.h"
#include "Settings.h"
namespace WebCore {
using namespace HTMLNames;
HTMLFrameElementBase::HTMLFrameElementBase(const QualifiedName& tagName, Document* document)
: HTMLFrameOwnerElement(tagName, document)
, m_scrolling(ScrollbarAuto)
, m_marginWidth(-1)
, m_marginHeight(-1)
, m_viewSource(false)
, m_shouldOpenURLAfterAttach(false)
{
}
bool HTMLFrameElementBase::isURLAllowed() const
{
if (m_URL.isEmpty())
return true;
const KURL& completeURL = document()->completeURL(m_URL);
// Don't allow more than 200 total frames in a set. This seems
// like a reasonable upper bound, and otherwise mutually recursive
// frameset pages can quickly bring the program to its knees with
// exponential growth in the number of frames.
// FIXME: This limit could be higher, but because WebKit has some
// algorithms that happen while loading which appear to be N^2 or
// worse in the number of frames, we'll keep it at 200 for now.
if (Frame* parentFrame = document()->frame()) {
if (parentFrame->page()->frameCount() > 200)
return false;
}
// We allow one level of self-reference because some sites depend on that.
// But we don't allow more than one.
bool foundSelfReference = false;
for (Frame* frame = document()->frame(); frame; frame = frame->tree()->parent()) {
if (equalIgnoringFragmentIdentifier(frame->loader()->url(), completeURL)) {
if (foundSelfReference)
return false;
foundSelfReference = true;
}
}
return true;
}
void HTMLFrameElementBase::openURL()
{
ASSERT(!m_frameName.isEmpty());
if (!isURLAllowed())
return;
if (m_URL.isEmpty())
m_URL = blankURL().string();
Frame* parentFrame = document()->frame();
if (!parentFrame)
return;
parentFrame->loader()->requestFrame(this, m_URL, m_frameName);
if (contentFrame())
contentFrame()->setInViewSourceMode(viewSourceMode());
}
void HTMLFrameElementBase::parseMappedAttribute(MappedAttribute *attr)
{
if (attr->name() == srcAttr)
setLocation(deprecatedParseURL(attr->value()));
else if (attr->name() == idAttr) {
// Important to call through to base for the id attribute so the hasID bit gets set.
HTMLFrameOwnerElement::parseMappedAttribute(attr);
m_frameName = attr->value();
} else if (attr->name() == nameAttr) {
m_frameName = attr->value();
// FIXME: If we are already attached, this doesn't actually change the frame's name.
// FIXME: If we are already attached, this doesn't check for frame name
// conflicts and generate a unique frame name.
} else if (attr->name() == marginwidthAttr) {
m_marginWidth = attr->value().toInt();
// FIXME: If we are already attached, this has no effect.
} else if (attr->name() == marginheightAttr) {
m_marginHeight = attr->value().toInt();
// FIXME: If we are already attached, this has no effect.
} else if (attr->name() == scrollingAttr) {
// Auto and yes both simply mean "allow scrolling." No means "don't allow scrolling."
if (equalIgnoringCase(attr->value(), "auto") || equalIgnoringCase(attr->value(), "yes"))
m_scrolling = document()->frameElementsShouldIgnoreScrolling() ? ScrollbarAlwaysOff : ScrollbarAuto;
else if (equalIgnoringCase(attr->value(), "no"))
m_scrolling = ScrollbarAlwaysOff;
// FIXME: If we are already attached, this has no effect.
} else if (attr->name() == viewsourceAttr) {
m_viewSource = !attr->isNull();
if (contentFrame())
contentFrame()->setInViewSourceMode(viewSourceMode());
} else if (attr->name() == onloadAttr)
setAttributeEventListener(eventNames().loadEvent, createAttributeEventListener(this, attr));
else if (attr->name() == onbeforeloadAttr)
setAttributeEventListener(eventNames().beforeloadEvent, createAttributeEventListener(this, attr));
else if (attr->name() == onbeforeunloadAttr) {
// FIXME: should <frame> elements have beforeunload handlers?
setAttributeEventListener(eventNames().beforeunloadEvent, createAttributeEventListener(this, attr));
} else
HTMLFrameOwnerElement::parseMappedAttribute(attr);
}
void HTMLFrameElementBase::setNameAndOpenURL()
{
m_frameName = getAttribute(nameAttr);
if (m_frameName.isNull())
m_frameName = getAttribute(idAttr);
if (Frame* parentFrame = document()->frame())
m_frameName = parentFrame->tree()->uniqueChildName(m_frameName);
openURL();
}
void HTMLFrameElementBase::setNameAndOpenURLCallback(Node* n)
{
static_cast<HTMLFrameElementBase*>(n)->setNameAndOpenURL();
}
void HTMLFrameElementBase::insertedIntoDocument()
{
HTMLFrameOwnerElement::insertedIntoDocument();
// We delay frame loading until after the render tree is fully constructed.
// Othewise, a synchronous load that executed JavaScript would see incorrect
// (0) values for the frame's renderer-dependent properties, like width.
m_shouldOpenURLAfterAttach = true;
}
void HTMLFrameElementBase::removedFromDocument()
{
m_shouldOpenURLAfterAttach = false;
HTMLFrameOwnerElement::removedFromDocument();
}
void HTMLFrameElementBase::attach()
{
if (m_shouldOpenURLAfterAttach) {
m_shouldOpenURLAfterAttach = false;
queuePostAttachCallback(&HTMLFrameElementBase::setNameAndOpenURLCallback, this);
}
HTMLFrameOwnerElement::attach();
if (RenderPart* renderPart = toRenderPart(renderer())) {
if (Frame* frame = contentFrame())
renderPart->setWidget(frame->view());
}
}
KURL HTMLFrameElementBase::location() const
{
return document()->completeURL(getAttribute(srcAttr));
}
void HTMLFrameElementBase::setLocation(const String& str)
{
Settings* settings = document()->settings();
if (settings && settings->needsAcrobatFrameReloadingQuirk() && m_URL == str)
return;
m_URL = AtomicString(str);
if (inDocument())
openURL();
}
bool HTMLFrameElementBase::supportsFocus() const
{
return true;
}
void HTMLFrameElementBase::setFocus(bool received)
{
HTMLFrameOwnerElement::setFocus(received);
if (Page* page = document()->page())
page->focusController()->setFocusedFrame(received ? contentFrame() : 0);
}
bool HTMLFrameElementBase::isURLAttribute(Attribute *attr) const
{
return attr->name() == srcAttr;
}
int HTMLFrameElementBase::width() const
{
if (!renderer())
return 0;
document()->updateLayoutIgnorePendingStylesheets();
return toRenderBox(renderer())->width();
}
int HTMLFrameElementBase::height() const
{
if (!renderer())
return 0;
document()->updateLayoutIgnorePendingStylesheets();
return toRenderBox(renderer())->height();
}
} // namespace WebCore
|