SIGN IN SIGN UP

[Quirks] Re-resolve site-specific quirks when the document URL changes

https://bugs.webkit.org/show_bug.cgi?id=326379
rdar://189209581

Reviewed by Brent Fulgham.

Quirks are resolved from the document's URL and the top document's URL when the
document is created, and again only when it becomes current in its frame.
Same-document URL changes (history.pushState(), history.replaceState(), and
fragment navigations) go through Document::setURL() but never touched the quirk
set, so the cached quirks go stale. This regressed when quirk resolution moved
to load time in 287966@main.  I address this problem by re-resolving quirks
wherever the URLs they depend on change.

To test this from JavaScript, I added internals.setTopDocumentHostForQuirks(), which
replaces only the host of the top document URL used for quirk matching. The
existing setTopDocumentURLForQuirks() replaces the whole URL, so pushState() has
no visible effect under it.

Tests: Tools/TestWebKitAPI/Tests/WebCore/Quirks.cpp
       Tools/TestWebKitAPI/Tests/WebKit/WKWebView/QuirksURLChange.mm
       http/tests/quirks/same-document-navigation-reresolves-quirks.html

* LayoutTests/http/tests/quirks/same-document-navigation-reresolves-quirks-expected.txt: Added.
* LayoutTests/http/tests/quirks/same-document-navigation-reresolves-quirks.html: Added.
* Source/WebCore/dom/Document.cpp:
(WebCore::Document::urlsAffectingQuirksDidChange):
(WebCore::Document::setURL):
* Source/WebCore/dom/Document.h:
* Source/WebCore/page/Page.cpp:
(WebCore::Page::setMainFrameURLAndOrigin):
(WebCore::Page::updateTopDocumentSyncData):
(WebCore::Page::setQuirksTopDocumentHostForTesting):
(WebCore::Page::topDocumentURLDidChange):
* Source/WebCore/page/Page.h:
* Source/WebCore/page/Quirks.cpp:
(WebCore::Quirks::applyFacebookFlagQuirk):
(WebCore::Quirks::topDocumentURL const):
(WebCore::Quirks::urlsDidChange):
* Source/WebCore/page/Quirks.h:
* Source/WebCore/page/QuirksData.h:
(WebCore::QuirksData::hasSameBehaviorFlags const):
* Source/WebCore/testing/Internals.cpp:
(WebCore::Internals::resetToConsistentState):
(WebCore::Internals::setTopDocumentHostForQuirks):
* Source/WebCore/testing/Internals.h:
* Source/WebCore/testing/Internals.idl:
* Tools/TestWebKitAPI/SourcesCocoa.txt:
* Tools/TestWebKitAPI/Tests/WebCore/Quirks.cpp:
(TestWebKitAPI::hasActiveQuirk):
(TestWebKitAPI::createPageWithQuirksEnabled):
(TestWebKitAPI::TEST_F(QuirksTest, SameDocumentNavigationReresolvesQuirks)):
* Tools/TestWebKitAPI/Tests/WebKit/WKWebView/QuirksURLChange.mm: Added.
(createWebViewWithInternalsAndQuirks):
(TEST(QuirksURLChange, TopDocumentPushStateReresolvesSubframeQuirks)):

Canonical link: https://commits.webkit.org/322786@main
C
Cole Carley committed
31ea7826bd9487837a696e15416e3376f5dc0fc6
Parent: 729712a