E59A Change code order in HTMLMetaElement::process() · WebKit/WebKit@b66d5e5 · GitHub
[go: up one dir, main page]

Skip to content

Commit b66d5e5

Browse files
Ahmad-S792Ahmad Saleem
authored andcommitted
Change code order in HTMLMetaElement::process()
Change code order in HTMLMetaElement::process() https://bugs.webkit.org/show_bug.cgi?id=251046 Reviewed by Tim Nguyen. Merge - https://chromium.googlesource.com/chromium/blink/+/d905ef4a93adf27fc8f72cc333e28acf0e912cf6 This patch is to refactor 'process' function to check 'name' attribute earlier and avoid any unnecessary comparisons. * Source/WebCore/html/HTMLMetaElement.cpp: (HTMLMetaElement::process): Refactoring Canonical link: https://commits.webkit.org/259413@main
1 parent 0ff58f0 commit b66d5e5

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

Source/WebCore/html/HTMLMetaElement.cpp

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
* Copyright (C) 1999 Lars Knoll (knoll@kde.org)
33
* (C) 1999 Antti Koivisto (koivisto@kde.org)
44
* (C) 2001 Dirk Mueller (mueller@kde.org)
5-
* Copyright (C) 2003, 2010 Apple Inc. All rights reserved.
5+
* Copyright (C) 2003-2023 Apple Inc. All rights reserved.
6+
* Copyright (C) 2013 Google Inc. All rights reserved.
67
*
78
* This library is free software; you can redistribute it and/or
89
* modify it under the terms of the GNU Library General Public
@@ -160,32 +161,41 @@ void HTMLMetaElement::process()
160161
if (!isInDocumentTree())
161162
return;
162163

164+
// https://html.spec.whatwg.org/multipage/semantics.html#the-meta-element
165+
// All below situations require a content attribute (which can be the empty string).
163166
const AtomString& contentValue = attributeWithoutSynchronization(contentAttr);
164167
if (contentValue.isNull())
165168
return;
169+
170+
const AtomString& httpEquivValue = attributeWithoutSynchronization(http_equivAttr);
171+
// Get the document to process the tag, but only if we're actually part of DOM
172+
// tree (changing a meta tag while it's not in the tree shouldn't have any effect
173+
// on the document)
174+
if (!httpEquivValue.isNull())
175+
document().processMetaHttpEquiv(httpEquivValue, contentValue, isDescendantOf(document().head()));
176+
177+
const AtomString& nameValue = attributeWithoutSynchronization(nameAttr);
178+
if (nameValue.isNull())
179+
return;
166180

167-
if (equalLettersIgnoringASCIICase(name(), "viewport"_s))
181+
if (equalLettersIgnoringASCIICase(nameValue, "viewport"_s))
168182
document().processViewport(contentValue, ViewportArguments::ViewportMeta);
169-
else if (document().settings().disabledAdaptationsMetaTagEnabled() && equalLettersIgnoringASCIICase(name(), "disabled-adaptations"_s))
183+
else if (document().settings().disabledAdaptationsMetaTagEnabled() && equalLettersIgnoringASCIICase(nameValue, "disabled-adaptations"_s))
170184
document().processDisabledAdaptations(contentValue);
171185
#if ENABLE(DARK_MODE_CSS)
172-
else if (equalLettersIgnoringASCIICase(name(), "color-scheme"_s) || equalLettersIgnoringASCIICase(name(), "supported-color-schemes"_s))
186+
else if (equalLettersIgnoringASCIICase(nameValue, "color-scheme"_s) || equalLettersIgnoringASCIICase(nameValue, "supported-color-schemes"_s))
173187
document().processColorScheme(contentValue);
174188
#endif
175-
else if (equalLettersIgnoringASCIICase(name(), "theme-color"_s))
189+
else if (equalLettersIgnoringASCIICase(nameValue, "theme-color"_s))
176190
document().metaElementThemeColorChanged(*this);
177191
#if PLATFORM(IOS_FAMILY)
178-
else if (equalLettersIgnoringASCIICase(name(), "format-detection"_s))
192+
else if (equalLettersIgnoringASCIICase(nameValue, "format-detection"_s))
179193
document().processFormatDetection(contentValue);
180-
else if (equalLettersIgnoringASCIICase(name(), "apple-mobile-web-app-orientations"_s))
194+
else if (equalLettersIgnoringASCIICase(nameValue, "apple-mobile-web-app-orientations"_s))
181195
document().processWebAppOrientations();
182196
#endif
183-
else if (equalLettersIgnoringASCIICase(name(), "referrer"_s))
197+
else if (equalLettersIgnoringASCIICase(nameValue, "referrer"_s))
184198
document().processReferrerPolicy(contentValue, ReferrerPolicySource::MetaTag);
185-
186-
const AtomString& httpEquivValue = attributeWithoutSynchronization(http_equivAttr);
187-
if (!httpEquivValue.isNull())
188-
document().processMetaHttpEquiv(httpEquivValue, contentValue, isDescendantOf(document().head()));
189199
}
190200

191201
const AtomString& HTMLMetaElement::content() const

0 commit comments

Comments
 (0)
0