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, 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 "HTMLMetaElement.h" |
25 | |
26 | #include "Attribute.h" |
27 | #include "Document.h" |
28 | #include "HTMLHeadElement.h" |
29 | #include "HTMLNames.h" |
30 | #include "RuntimeEnabledFeatures.h" |
31 | #include <wtf/IsoMallocInlines.h> |
32 | |
33 | namespace WebCore { |
34 | |
35 | WTF_MAKE_ISO_ALLOCATED_IMPL(HTMLMetaElement); |
36 | |
37 | using namespace HTMLNames; |
38 | |
39 | inline HTMLMetaElement::HTMLMetaElement(const QualifiedName& tagName, Document& document) |
40 | : HTMLElement(tagName, document) |
41 | { |
42 | ASSERT(hasTagName(metaTag)); |
43 | } |
44 | |
45 | Ref<HTMLMetaElement> HTMLMetaElement::create(Document& document) |
46 | { |
47 | return adoptRef(*new HTMLMetaElement(metaTag, document)); |
48 | } |
49 | |
50 | Ref<HTMLMetaElement> HTMLMetaElement::create(const QualifiedName& tagName, Document& document) |
51 | { |
52 | return adoptRef(*new HTMLMetaElement(tagName, document)); |
53 | } |
54 | |
55 | void HTMLMetaElement::parseAttribute(const QualifiedName& name, const AtomicString& value) |
56 | { |
57 | if (name == http_equivAttr) |
58 | process(); |
59 | else if (name == contentAttr) |
60 | process(); |
61 | else if (name == nameAttr) { |
62 | // Do nothing |
63 | } else |
64 | HTMLElement::parseAttribute(name, value); |
65 | } |
66 | |
67 | Node::InsertedIntoAncestorResult HTMLMetaElement::insertedIntoAncestor(InsertionType insertionType, ContainerNode& parentOfInsertedTree) |
68 | { |
69 | HTMLElement::insertedIntoAncestor(insertionType, parentOfInsertedTree); |
70 | if (insertionType.connectedToDocument) |
71 | return InsertedIntoAncestorResult::NeedsPostInsertionCallback; |
72 | return InsertedIntoAncestorResult::Done; |
73 | } |
74 | |
75 | void HTMLMetaElement::didFinishInsertingNode() |
76 | { |
77 | process(); |
78 | } |
79 | |
80 | void HTMLMetaElement::process() |
81 | { |
82 | // Changing a meta tag while it's not in the tree shouldn't have any effect on the document. |
83 | if (!isConnected()) |
84 | return; |
85 | |
86 | const AtomicString& contentValue = attributeWithoutSynchronization(contentAttr); |
87 | if (contentValue.isNull()) |
88 | return; |
89 | |
90 | if (equalLettersIgnoringASCIICase(name(), "viewport" )) |
91 | document().processViewport(contentValue, ViewportArguments::ViewportMeta); |
92 | else if (RuntimeEnabledFeatures::sharedFeatures().disabledAdaptationsMetaTagEnabled() && equalLettersIgnoringASCIICase(name(), "disabled-adaptations" )) |
93 | document().processDisabledAdaptations(contentValue); |
94 | #if ENABLE(DARK_MODE_CSS) |
95 | else if (RuntimeEnabledFeatures::sharedFeatures().darkModeCSSEnabled() && (equalLettersIgnoringASCIICase(name(), "color-scheme" ) || equalLettersIgnoringASCIICase(name(), "supported-color-schemes" ))) |
96 | document().processColorScheme(contentValue); |
97 | #endif |
98 | #if PLATFORM(IOS_FAMILY) |
99 | else if (equalLettersIgnoringASCIICase(name(), "format-detection" )) |
100 | document().processFormatDetection(contentValue); |
101 | else if (equalLettersIgnoringASCIICase(name(), "apple-mobile-web-app-orientations" )) |
102 | document().processWebAppOrientations(); |
103 | #endif |
104 | else if (equalLettersIgnoringASCIICase(name(), "referrer" )) |
105 | document().processReferrerPolicy(contentValue, ReferrerPolicySource::MetaTag); |
106 | |
107 | const AtomicString& httpEquivValue = attributeWithoutSynchronization(http_equivAttr); |
108 | if (!httpEquivValue.isNull()) |
109 | document().processHttpEquiv(httpEquivValue, contentValue, isDescendantOf(document().head())); |
110 | } |
111 | |
112 | const AtomicString& HTMLMetaElement::content() const |
113 | { |
114 | return attributeWithoutSynchronization(contentAttr); |
115 | } |
116 | |
117 | const AtomicString& HTMLMetaElement::httpEquiv() const |
118 | { |
119 | return attributeWithoutSynchronization(http_equivAttr); |
120 | } |
121 | |
122 | const AtomicString& HTMLMetaElement::name() const |
123 | { |
124 | return getNameAttribute(); |
125 | } |
126 | |
127 | } |
128 | |