Title: [287497] trunk
- Revision
- 287497
- Author
- [email protected]
- Date
- 2021-12-31 16:22:38 -0800 (Fri, 31 Dec 2021)
Log Message
Include a few more tag names to search when running modal container detection
https://bugs.webkit.org/show_bug.cgi?id=234652
Reviewed by Darin Adler.
Source/WebCore:
Broaden the list of tag names that we heuristically scan for the search term. This particular modal container
detection failure was due to the search term appearing inside a `b` element, though I'm adding a few additional
types just to be safe. Since we're checking more than just few tag names, we also take this opportunity to
convert this into a compact AtomString hashtable of tag names that we should scan in the process of detecting
modal containers.
Test: ModalContainerObservation.DetectSearchTermInBoldTag
* page/ModalContainerObserver.cpp:
(WebCore::matchesSearchTerm):
Tools:
Add an API test that's representative of the website where modal container observation failed (due to the search
term being inside a `b` element).
* TestWebKitAPI/Tests/WebKitCocoa/ModalContainerObservation.mm:
(TestWebKitAPI::TEST):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (287496 => 287497)
--- trunk/Source/WebCore/ChangeLog 2021-12-31 23:33:52 UTC (rev 287496)
+++ trunk/Source/WebCore/ChangeLog 2022-01-01 00:22:38 UTC (rev 287497)
@@ -1,5 +1,23 @@
2021-12-31 Wenson Hsieh <[email protected]>
+ Include a few more tag names to search when running modal container detection
+ https://bugs.webkit.org/show_bug.cgi?id=234652
+
+ Reviewed by Darin Adler.
+
+ Broaden the list of tag names that we heuristically scan for the search term. This particular modal container
+ detection failure was due to the search term appearing inside a `b` element, though I'm adding a few additional
+ types just to be safe. Since we're checking more than just few tag names, we also take this opportunity to
+ convert this into a compact AtomString hashtable of tag names that we should scan in the process of detecting
+ modal containers.
+
+ Test: ModalContainerObservation.DetectSearchTermInBoldTag
+
+ * page/ModalContainerObserver.cpp:
+ (WebCore::matchesSearchTerm):
+
+2021-12-31 Wenson Hsieh <[email protected]>
+
Refactor some Cocoa-specific code in WebCore::FontAttributes to be platform-agnostic
https://bugs.webkit.org/show_bug.cgi?id=234757
Modified: trunk/Source/WebCore/page/ModalContainerObserver.cpp (287496 => 287497)
--- trunk/Source/WebCore/page/ModalContainerObserver.cpp 2021-12-31 23:33:52 UTC (rev 287496)
+++ trunk/Source/WebCore/page/ModalContainerObserver.cpp 2022-01-01 00:22:38 UTC (rev 287497)
@@ -49,6 +49,7 @@
#include "RenderView.h"
#include "SimulatedClickOptions.h"
#include "Text.h"
+#include <wtf/RobinHoodHashSet.h>
#include <wtf/Scope.h>
#include <wtf/URL.h>
@@ -94,14 +95,33 @@
static bool matchesSearchTerm(const Text& textNode, const AtomString& searchTerm)
{
RefPtr parent = textNode.parentElementInComposedTree();
- bool shouldSearchNode = ([&] {
- if (!is<HTMLElement>(parent.get()))
- return false;
- return parent->hasTagName(HTMLNames::aTag) || parent->hasTagName(HTMLNames::divTag) || parent->hasTagName(HTMLNames::pTag) || parent->hasTagName(HTMLNames::spanTag) || parent->hasTagName(HTMLNames::sectionTag);
- })();
+ static NeverDestroyed tagNamesToSearch = [] {
+ static constexpr std::array tags {
+ &HTMLNames::aTag,
+ &HTMLNames::divTag,
+ &HTMLNames::pTag,
+ &HTMLNames::spanTag,
+ &HTMLNames::sectionTag,
+ &HTMLNames::bTag,
+ &HTMLNames::iTag,
+ &HTMLNames::uTag,
+ &HTMLNames::liTag,
+ &HTMLNames::h1Tag,
+ &HTMLNames::h2Tag,
+ &HTMLNames::h3Tag,
+ &HTMLNames::h4Tag,
+ &HTMLNames::h5Tag,
+ &HTMLNames::h6Tag,
+ };
+ MemoryCompactLookupOnlyRobinHoodHashSet<AtomString> set;
+ set.reserveInitialCapacity(std::size(tags));
+ for (auto& tag : tags)
+ set.add(tag->get().localName());
+ return set;
+ }();
- if (!shouldSearchNode)
+ if (!is<HTMLElement>(parent.get()) || !tagNamesToSearch.get().contains(downcast<HTMLElement>(*parent).localName()))
return false;
if (LIKELY(!textNode.data().containsIgnoringASCIICase(searchTerm)))
Modified: trunk/Tools/ChangeLog (287496 => 287497)
--- trunk/Tools/ChangeLog 2021-12-31 23:33:52 UTC (rev 287496)
+++ trunk/Tools/ChangeLog 2022-01-01 00:22:38 UTC (rev 287497)
@@ -1,5 +1,18 @@
2021-12-31 Wenson Hsieh <[email protected]>
+ Include a few more tag names to search when running modal container detection
+ https://bugs.webkit.org/show_bug.cgi?id=234652
+
+ Reviewed by Darin Adler.
+
+ Add an API test that's representative of the website where modal container observation failed (due to the search
+ term being inside a `b` element).
+
+ * TestWebKitAPI/Tests/WebKitCocoa/ModalContainerObservation.mm:
+ (TestWebKitAPI::TEST):
+
+2021-12-31 Wenson Hsieh <[email protected]>
+
Updating the file name of attachment-backed images should automatically set the `alt` attribute
https://bugs.webkit.org/show_bug.cgi?id=234747
rdar://85899879
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ModalContainerObservation.mm (287496 => 287497)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ModalContainerObservation.mm 2021-12-31 23:33:52 UTC (rev 287496)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ModalContainerObservation.mm 2022-01-01 00:22:38 UTC (rev 287497)
@@ -222,4 +222,14 @@
EXPECT_EQ([webView lastModalContainerInfo].availableTypes, _WKModalContainerControlTypeNeutral);
}
+TEST(ModalContainerObservation, DetectSearchTermInBoldTag)
+{
+ auto webView = createModalContainerWebView();
+ [webView loadBundlePage:@"modal-container-custom"];
+ [webView evaluate:@"show(`<b>Hello world</b><a href=''>Yes</a><a href=''>No</a>`)" andDecidePolicy:_WKModalContainerDecisionHideAndIgnore];
+
+ EXPECT_FALSE([[webView contentsAsString] containsString:@"Hello world"]);
+ EXPECT_EQ([webView lastModalContainerInfo].availableTypes, _WKModalContainerControlTypePositive | _WKModalContainerControlTypeNegative);
+}
+
} // namespace TestWebKitAPI
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes