<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>260938</bug_id>
          
          <creation_ts>2023-08-30 19:11:24 -0700</creation_ts>
          <short_desc>Create a helper for targeting domain names in Quirks.cpp</short_desc>
          <delta_ts>2024-07-17 01:15:25 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebCore Misc.</component>
          <version>Safari 17</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=267623</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=276709</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>258603</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Karl Dubost">karlcow</reporter>
          <assigned_to name="Karl Dubost">karlcow</assigned_to>
          <cc>webkit-bug-importer</cc>
    
    <cc>zalan</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1974604</commentid>
    <comment_count>0</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2023-08-30 19:11:24 -0700</bug_when>
    <thetext>Currently the Quirks.cpp is targeting domain names in a lot of different ways, around 16 ways more or less equivalent. 
Probably not everything would benefit from a helper function but probably a big chunk of them. 
The goal being able to pass domain name string and return true, when the Document is matching this string.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1974605</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2023-08-30 19:12:03 -0700</bug_when>
    <thetext>&lt;rdar://problem/114737751&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1974606</commentid>
    <comment_count>2</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2023-08-30 19:12:59 -0700</bug_when>
    <thetext>some of the current patterns

// 1
// match example.com OR finish by .example.com
auto host = m_document-&gt;url().host();
return equalLettersIgnoringASCIICase(host, &quot;example.com&quot;_s) || host.endsWithIgnoringASCIICase(&quot;.example.com&quot;_s);


// 2
// match example.com only but with a topDocument()?
auto&amp; url = m_document-&gt;topDocument().url();
auto host = url.host();
if (equalLettersIgnoringASCIICase(host, &quot;example.com&quot;_s))
    return true;


// 3
// same as above, just organizing differently
auto&amp; url = m_document-&gt;topDocument().url();
return equalLettersIgnoringASCIICase(url.host(), &quot;example.com&quot;_s);


// 4
// same, different wrapping
return equalLettersIgnoringASCIICase(m_document-&gt;topDocument().url().host(), &quot;example.com&quot;_s


// 5
// testing only for *.example.com
auto host = m_document-&gt;topDocument().url().host();
return host.endsWithIgnoringASCIICase(&quot;.example.com&quot;_s);


// 6
// not using comparison function, but just strict equality with strings
// so I guess fails if different case, such as ExAmple.com
auto&amp; topDocument = m_document-&gt;topDocument();
auto host = topDocument.url().host();
auto isExample = host.endsWith(&quot;.example.com&quot;_s) || host == &quot;example.com&quot;_s;


// 7
// converted to lowercase, then string comparison AND a path
auto&amp; url = m_document-&gt;topDocument().url();
auto host = url.host().convertToASCIILowercase();
if (host == &quot;example.com&quot;_s || host.endsWith(&quot;.example.com&quot;_s)) {
    return startsWithLettersIgnoringASCIICase(url.path(), &quot;/somewhere/&quot;_s)
}

// 8
// using the quirk function name 
// and a domain function to match on something.example.*
if (!m_quirkName)
    m_quirkName = isDomain(*m_document);
return m_quirkName.value();
// with  isDomain()
static inline bool isDomain(Document&amp; document)
{
    auto host = document.topDocument().url().host();
    return startsWithLettersIgnoringASCIICase(host, &quot;something.&quot;_s) &amp;&amp; topPrivatelyControlledDomain(host.toString()).startsWith(&quot;example.&quot;_s);
}

// 9 
// another case of matching a domain function
static bool isExampleDomain(const URL&amp; url)
{
    static NeverDestroyed exampleDomain = RegistrableDomain { URL { &quot;https://example.com&quot;_s } };
    return exampleDomain-&gt;matches(url);
}


// 10
// RegistrableDomain and using the function name
if (m_quirkName)
    return m_quirkName.value();
auto domain = RegistrableDomain(m_document-&gt;url()).string();
m_quirkName = domain == &quot;example.com&quot;_s;
return m_quirkName.value();

// 11
// Same, just another variation
auto topURL = m_document-&gt;topDocument().url();
auto host = topURL.host();
RegistrableDomain registrableDomain { topURL };
if (registrableDomain == &quot;example.com&quot;_s) {}


// 12
// using topPrivatelyControlledDomain and then simple function
// https://searchfox.org/wubkat/source/Source/WebCore/platform/soup/PublicSuffixSoup.cpp#63-103
topPrivatelyControlledDomain(m_document-&gt;topDocument().url().host().toString()).startsWith(&quot;example.&quot;_s)


// 13
// using topPrivatelyControlledDomain AND a path
auto&amp; url = m_document-&gt;topDocument().url();
return topPrivatelyControlledDomain(url.host().toString()).startsWith(&quot;example.&quot;_s) &amp;&amp; startsWithLettersIgnoringASCIICase(url.path(), &quot;/somewhere/&quot;_s);

// 14
// another variation on 11. with paranthesis around the domain matching
auto domain = RegistrableDomain { m_document-&gt;topDocument().url() };
m_quirkName = (domain == &quot;example.com&quot;_s);


// 15
// using securityOrigin()
auto host = m_document-&gt;securityOrigin().host();
m_quirkName = host == &quot;www.example.com&quot;_s 

// 16 
// variation on 15
auto domain = m_document-&gt;securityOrigin().domain().convertToASCIILowercase();
m_quirkName = domain == &quot;example.com&quot;_s || domain.endsWith(&quot;.example.com&quot;_s);</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1974607</commentid>
    <comment_count>3</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2023-08-30 19:18:44 -0700</bug_when>
    <thetext>We probably need to be extra-careful on why some Quirks chose to use

* m_document-&gt;topDocument().url().host()
* m_document-&gt;url().host()
* m_document-&gt;securityOrigin().host()
* m_document-&gt;securityOrigin().domain()
* RegistrableDomain(m_document-&gt;url()).string()
* topPrivatelyControlledDomain(url.host().toString())</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1974643</commentid>
    <comment_count>4</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2023-08-30 22:08:47 -0700</bug_when>
    <thetext>Testing for WebCore::RegistrableDomain
https://searchfox.org/wubkat/source/Tools/TestWebKitAPI/Tests/WebCore/RegistrableDomain.cpp
https://searchfox.org/wubkat/source/Source/WebCore/platform/RegistrableDomain.h</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1974929</commentid>
    <comment_count>5</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2023-08-31 23:05:36 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/17329</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1977087</commentid>
    <comment_count>6</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2023-09-12 10:25:30 -0700</bug_when>
    <thetext>Committed 267907@main (2d5d6f169a10): &lt;https://commits.webkit.org/267907@main&gt;

Reviewed commits have been landed. Closing PR #17329 and removing active labels.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1994588</commentid>
    <comment_count>7</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2023-11-23 14:39:59 -0800</bug_when>
    <thetext>*** Bug 211607 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>