From 290968e36d41b424e268d39e9a2774c64cc6bd87 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Thu, 7 Mar 2024 01:45:39 -0800 Subject: [PATCH] Quirk getElementsByName() on older iPadOS apps https://bugs.webkit.org/show_bug.cgi?id=270229 rdar://122548304 Reviewed by Ryosuke Niwa. 272530@main aligned us with the HTML Standard for getElementsByName() by making it only work for HTML elements. There is at least one iPadOS app that is impacted by that change. This change should give them a bit of time to catch up by making getElementsByName() look at all elements again for older iPadOS apps. * Source/WTF/wtf/cocoa/RuntimeApplicationChecksCocoa.h: * Source/WebCore/dom/NameNodeList.cpp: (WebCore::NameNodeList::NameNodeList): (WebCore::NameNodeList::elementMatches const): * Source/WebCore/dom/NameNodeList.h: * Source/WebCore/page/Quirks.cpp: (WebCore::Quirks::needsGetElementsByNameQuirk const): * Source/WebCore/page/Quirks.h: Canonical link: https://commits.webkit.org/275779@main --- Source/WTF/wtf/cocoa/RuntimeApplicationChecksCocoa.h | 1 + Source/WebCore/dom/NameNodeList.cpp | 4 +++- Source/WebCore/dom/NameNodeList.h | 1 + Source/WebCore/page/Quirks.cpp | 11 +++++++++++ Source/WebCore/page/Quirks.h | 2 ++ 5 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Source/WTF/wtf/cocoa/RuntimeApplicationChecksCocoa.h b/Source/WTF/wtf/cocoa/RuntimeApplicationChecksCocoa.h index 96a6d856e488..9585794a4cdf 100644 --- a/Source/WTF/wtf/cocoa/RuntimeApplicationChecksCocoa.h +++ b/Source/WTF/wtf/cocoa/RuntimeApplicationChecksCocoa.h @@ -67,6 +67,7 @@ enum class SDKAlignedBehavior { ModernCompabilityModeByDefault, NoClientCertificateLookup, NoExpandoIndexedPropertiesOnWindow, + NoGetElementsByNameQuirk, NoIMDbCSSOMViewScrollingQuirk, NoLaBanquePostaleQuirks, NoMoviStarPlusCORSPreflightQuirk, diff --git a/Source/WebCore/dom/NameNodeList.cpp b/Source/WebCore/dom/NameNodeList.cpp index 68bd796e80e8..13830f2f133d 100644 --- a/Source/WebCore/dom/NameNodeList.cpp +++ b/Source/WebCore/dom/NameNodeList.cpp @@ -26,6 +26,7 @@ #include "ElementInlines.h" #include "LiveNodeListInlines.h" #include "NodeRareData.h" +#include "Quirks.h" #include namespace WebCore { @@ -37,6 +38,7 @@ WTF_MAKE_ISO_ALLOCATED_IMPL(NameNodeList); NameNodeList::NameNodeList(ContainerNode& rootNode, const AtomString& name) : CachedLiveNodeList(rootNode, NodeListInvalidationType::InvalidateOnNameAttrChange) , m_name(name) + , m_needsGetElementsByNameQuirk(rootNode.document().quirks().needsGetElementsByNameQuirk()) { } @@ -52,7 +54,7 @@ NameNodeList::~NameNodeList() bool NameNodeList::elementMatches(Element& element) const { - return element.isHTMLElement() && element.getNameAttribute() == m_name; + return (is(element) || m_needsGetElementsByNameQuirk) && element.getNameAttribute() == m_name; } } // namespace WebCore diff --git a/Source/WebCore/dom/NameNodeList.h b/Source/WebCore/dom/NameNodeList.h index f8d8c2bff8b9..7f55fd200359 100644 --- a/Source/WebCore/dom/NameNodeList.h +++ b/Source/WebCore/dom/NameNodeList.h @@ -40,6 +40,7 @@ class NameNodeList final : public CachedLiveNodeList { NameNodeList(ContainerNode& rootNode, const AtomString& name); AtomString m_name; + bool m_needsGetElementsByNameQuirk; }; } // namespace WebCore diff --git a/Source/WebCore/page/Quirks.cpp b/Source/WebCore/page/Quirks.cpp index 3310109b0a92..4005e10a9b8a 100644 --- a/Source/WebCore/page/Quirks.cpp +++ b/Source/WebCore/page/Quirks.cpp @@ -1853,4 +1853,15 @@ bool Quirks::shouldUseEphemeralPartitionedStorageForDOMCookies(const URL& url) c return false; } +// This quirk has intentionally limited exposure to increase the odds of being able to remove it +// again within a reasonable timeframe as the impacted apps are being updated. +bool Quirks::needsGetElementsByNameQuirk() const +{ +#if PLATFORM(IOS) + return needsQuirks() && !PAL::currentUserInterfaceIdiomIsSmallScreen() && !linkedOnOrAfterSDKWithBehavior(SDKAlignedBehavior::NoGetElementsByNameQuirk); +#else + return false; +#endif +} + } diff --git a/Source/WebCore/page/Quirks.h b/Source/WebCore/page/Quirks.h index 990370007bba..c7070a31160c 100644 --- a/Source/WebCore/page/Quirks.h +++ b/Source/WebCore/page/Quirks.h @@ -189,6 +189,8 @@ class Quirks { bool shouldIgnorePlaysInlineRequirementQuirk() const; WEBCORE_EXPORT bool shouldUseEphemeralPartitionedStorageForDOMCookies(const URL&) const; + bool needsGetElementsByNameQuirk() const; + private: bool needsQuirks() const; bool isDomain(const String&) const;