|
1 /* |
|
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
|
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
|
4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
|
5 * Copyright (C) 2003, 2008, 2009, 2010 Apple Inc. All rights reserved. |
|
6 * |
|
7 * This library is free software; you can redistribute it and/or |
|
8 * modify it under the terms of the GNU Library General Public |
|
9 * License as published by the Free Software Foundation; either |
|
10 * version 2 of the License, or (at your option) any later version. |
|
11 * |
|
12 * This library is distributed in the hope that it will be useful, |
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
15 * Library General Public License for more details. |
|
16 * |
|
17 * You should have received a copy of the GNU Library General Public License |
|
18 * along with this library; see the file COPYING.LIB. If not, write to |
|
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
20 * Boston, MA 02110-1301, USA. |
|
21 */ |
|
22 |
|
23 #include "config.h" |
|
24 #include "HTMLBaseElement.h" |
|
25 |
|
26 #include "Attribute.h" |
|
27 #include "CSSHelper.h" |
|
28 #include "Document.h" |
|
29 #include "Frame.h" |
|
30 #include "HTMLNames.h" |
|
31 #include "XSSAuditor.h" |
|
32 |
|
33 namespace WebCore { |
|
34 |
|
35 using namespace HTMLNames; |
|
36 |
|
37 inline HTMLBaseElement::HTMLBaseElement(const QualifiedName& tagName, Document* document) |
|
38 : HTMLElement(tagName, document) |
|
39 { |
|
40 ASSERT(hasTagName(baseTag)); |
|
41 } |
|
42 |
|
43 PassRefPtr<HTMLBaseElement> HTMLBaseElement::create(const QualifiedName& tagName, Document* document) |
|
44 { |
|
45 return adoptRef(new HTMLBaseElement(tagName, document)); |
|
46 } |
|
47 |
|
48 void HTMLBaseElement::parseMappedAttribute(Attribute* attr) |
|
49 { |
|
50 if (attr->name() == hrefAttr) { |
|
51 m_hrefAttrValue = attr->value(); |
|
52 m_href = deprecatedParseURL(attr->value()); |
|
53 process(); |
|
54 } else if (attr->name() == targetAttr) { |
|
55 m_target = attr->value(); |
|
56 process(); |
|
57 } else |
|
58 HTMLElement::parseMappedAttribute(attr); |
|
59 } |
|
60 |
|
61 void HTMLBaseElement::insertedIntoDocument() |
|
62 { |
|
63 HTMLElement::insertedIntoDocument(); |
|
64 process(); |
|
65 } |
|
66 |
|
67 void HTMLBaseElement::removedFromDocument() |
|
68 { |
|
69 HTMLElement::removedFromDocument(); |
|
70 |
|
71 // Since the document doesn't have a base element, clear the base URL and target. |
|
72 // FIXME: This does not handle the case of multiple base elements correctly. |
|
73 document()->setBaseElementURL(KURL()); |
|
74 document()->setBaseElementTarget(String()); |
|
75 } |
|
76 |
|
77 void HTMLBaseElement::process() |
|
78 { |
|
79 if (!inDocument()) |
|
80 return; |
|
81 |
|
82 if (!m_href.isEmpty() && (!document()->frame() || document()->frame()->script()->xssAuditor()->canSetBaseElementURL(m_hrefAttrValue))) |
|
83 document()->setBaseElementURL(KURL(document()->url(), m_href)); |
|
84 |
|
85 if (!m_target.isEmpty()) |
|
86 document()->setBaseElementTarget(m_target); |
|
87 |
|
88 // FIXME: Changing a document's base URL should probably automatically update the resolved relative URLs of all images, stylesheets, etc. |
|
89 } |
|
90 |
|
91 } |