Drop legacy WebCore::toRegistrableDomain() utility function
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Mar 2019 19:53:41 +0000 (19:53 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Mar 2019 19:53:41 +0000 (19:53 +0000)
https://bugs.webkit.org/show_bug.cgi?id=195637

Reviewed by Geoffrey Garen.

Drop legacy toRegistrableDomain() / registrableDomainAreEqual() utility functions.
Update call sites to use modern RegistrableDomain type instead.

Source/WebCore:

* loader/CrossOriginAccessControl.cpp:
(WebCore::shouldCrossOriginResourcePolicyCancelLoad):
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::setFirstPartyForCookies):
* page/DOMWindow.cpp:
(WebCore::DOMWindow::failedToRegisterDeviceMotionEventListener):
* platform/RegistrableDomain.h:
(WebCore::registrableDomainsAreEqual):
* platform/network/ResourceRequestBase.h:
* platform/network/cf/ResourceRequestCFNet.cpp:
* platform/network/cocoa/ResourceRequestCocoa.mm:

Source/WebKit:

* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::processForNavigationInternal):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@242899 268f45cc-cd09-0410-ab3c-d52691b4dbfc

13 files changed:
Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp
Source/WebCore/loader/CrossOriginAccessControl.cpp
Source/WebCore/loader/FrameLoader.cpp
Source/WebCore/page/DOMWindow.cpp
Source/WebCore/platform/RegistrableDomain.h
Source/WebCore/platform/network/ResourceRequestBase.h
Source/WebCore/platform/network/cf/ResourceRequestCFNet.cpp
Source/WebCore/platform/network/cocoa/ResourceRequestCocoa.mm
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm
Source/WebKit/UIProcess/WebProcessPool.cpp
Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp

index b1346c3..af7dc18 100644 (file)
@@ -1,3 +1,25 @@
+2019-03-13  Chris Dumez  <cdumez@apple.com>
+
+        Drop legacy WebCore::toRegistrableDomain() utility function
+        https://bugs.webkit.org/show_bug.cgi?id=195637
+
+        Reviewed by Geoffrey Garen.
+
+        Drop legacy toRegistrableDomain() / registrableDomainAreEqual() utility functions.
+        Update call sites to use modern RegistrableDomain type instead.
+
+        * loader/CrossOriginAccessControl.cpp:
+        (WebCore::shouldCrossOriginResourcePolicyCancelLoad):
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::setFirstPartyForCookies):
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::failedToRegisterDeviceMotionEventListener):
+        * platform/RegistrableDomain.h:
+        (WebCore::registrableDomainsAreEqual):
+        * platform/network/ResourceRequestBase.h:
+        * platform/network/cf/ResourceRequestCFNet.cpp:
+        * platform/network/cocoa/ResourceRequestCocoa.mm:
+
 2019-03-13  Alex Christensen  <achristensen@webkit.org>
 
         Prevent checked_cf_cast crashes in ResourceResponse::platformCertificateInfo
index e988db8..5f2909a 100644 (file)
@@ -3450,7 +3450,7 @@ bool Document::isNavigationBlockedByThirdPartyIFrameRedirectBlocking(Frame& targ
 
     // Only prevent cross-site navigations.
     auto* targetDocument = targetFrame.document();
-    if (targetDocument && (targetDocument->securityOrigin().canAccess(SecurityOrigin::create(destinationURL)) || registrableDomainsAreEqual(targetDocument->url(), destinationURL)))
+    if (targetDocument && (targetDocument->securityOrigin().canAccess(SecurityOrigin::create(destinationURL)) || areRegistrableDomainsEqual(targetDocument->url(), destinationURL)))
         return false;
 
     return true;
index 48c741a..2bb9737 100644 (file)
@@ -230,7 +230,7 @@ static inline bool shouldCrossOriginResourcePolicyCancelLoad(const SecurityOrigi
         if (origin.isUnique())
             return true;
 #if ENABLE(PUBLIC_SUFFIX_LIST)
-        if (!registrableDomainsAreEqual(response.url(), ResourceRequest::partitionName(origin.host())))
+        if (!RegistrableDomain::uncheckedCreateFromHost(origin.host()).matches(response.url()))
             return true;
 #endif
         if (origin.protocol() == "http" && response.url().protocol() == "https")
index 2c43a19..afb0ec6 100644 (file)
@@ -1107,9 +1107,9 @@ void FrameLoader::setFirstPartyForCookies(const URL& url)
     for (Frame* frame = &m_frame; frame; frame = frame->tree().traverseNext(&m_frame))
         frame->document()->setFirstPartyForCookies(url);
 
-    String registrableDomain = ResourceRequest::partitionName(url.host().toString());
+    RegistrableDomain registrableDomain(url);
     for (Frame* frame = &m_frame; frame; frame = frame->tree().traverseNext(&m_frame)) {
-        if (SecurityPolicy::shouldInheritSecurityOriginFromOwner(frame->document()->url()) || registrableDomainsAreEqual(frame->document()->url(), registrableDomain))
+        if (SecurityPolicy::shouldInheritSecurityOriginFromOwner(frame->document()->url()) || registrableDomain.matches(frame->document()->url()))
             frame->document()->setSiteForCookies(url);
     }
 }
@@ -2970,7 +2970,7 @@ void FrameLoader::addSameSiteInfoToRequestIfNeeded(ResourceRequest& request, con
         request.setIsSameSite(true);
         return;
     }
-    request.setIsSameSite(registrableDomainsAreEqual(initiator->siteForCookies(), request.url()));
+    request.setIsSameSite(areRegistrableDomainsEqual(initiator->siteForCookies(), request.url()));
 }
 
 void FrameLoader::addHTTPUpgradeInsecureRequestsIfNeeded(ResourceRequest& request)
index efa0e5e..8c31dbd 100644 (file)
@@ -1944,7 +1944,7 @@ void DOMWindow::failedToRegisterDeviceMotionEventListener()
         return;
 
     // FIXME: This is a quirk for chase.com on iPad (<rdar://problem/48423023>).
-    if (toRegistrableDomain(document()->url()) == "chase.com") {
+    if (RegistrableDomain::uncheckedCreateFromRegistrableDomainString("chase.com"_s).matches(document()->url())) {
         // Fire a fake DeviceMotionEvent with acceleration data to unblock the site's login flow.
         document()->postTask([](auto& context) {
             if (auto* window = downcast<Document>(context).domWindow()) {
index b386730..448af3f 100644 (file)
@@ -131,6 +131,11 @@ Optional<RegistrableDomain> RegistrableDomain::decode(Decoder& decoder)
     return registrableDomain;
 }
 
+inline bool areRegistrableDomainsEqual(const URL& a, const URL& b)
+{
+    return RegistrableDomain(a).matches(b);
+}
+
 } // namespace WebCore
 
 namespace WTF {
index 255768d..d988908 100644 (file)
@@ -31,8 +31,8 @@
 #include "FormData.h"
 #include "HTTPHeaderMap.h"
 #include "IntRect.h"
-#include <wtf/URL.h>
 #include "ResourceLoadPriority.h"
+#include <wtf/URL.h>
 
 namespace WebCore {
 
@@ -258,24 +258,6 @@ private:
 
 bool equalIgnoringHeaderFields(const ResourceRequestBase&, const ResourceRequestBase&);
 
-// FIXME: Find a better place for these functions.
-inline String toRegistrableDomain(const URL& a)
-{
-    auto host = a.host().toString();
-    auto registrableDomain = ResourceRequestBase::partitionName(host);
-    // Fall back to the host if we cannot determine the registrable domain.
-    return registrableDomain.isEmpty() ? host : registrableDomain;
-}
-
-inline bool registrableDomainsAreEqual(const URL& a, const URL& b)
-{
-    return toRegistrableDomain(a) == toRegistrableDomain(b);
-}
-inline bool registrableDomainsAreEqual(const URL& a, const String& registrableDomain)
-{
-    return toRegistrableDomain(a) == registrableDomain;
-}
-
 inline bool operator==(const ResourceRequest& a, const ResourceRequest& b) { return ResourceRequestBase::equal(a, b); }
 inline bool operator!=(ResourceRequest& a, const ResourceRequest& b) { return !(a == b); }
 
index c237904..7f4a94a 100644 (file)
@@ -27,6 +27,7 @@
 #include "ResourceRequestCFNet.h"
 
 #include "HTTPHeaderNames.h"
+#include "RegistrableDomain.h"
 #include "ResourceRequest.h"
 #include <pal/spi/cf/CFNetworkSPI.h>
 #include <wtf/cf/TypeCastsCF.h>
@@ -286,7 +287,7 @@ void ResourceRequest::doUpdateResourceRequest()
 
 #if PLATFORM(IOS_FAMILY) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000
     RetainPtr<CFURLRef> siteForCookies = adoptCF(checked_cf_cast<CFURLRef>(_CFURLRequestCopyProtocolPropertyForKey(m_cfRequest.get(), CFSTR("_kCFHTTPCookiePolicyPropertySiteForCookies"))));
-    m_sameSiteDisposition = !siteForCookies ? SameSiteDisposition::Unspecified : (registrableDomainsAreEqual(siteForCookies.get(), m_url) ? SameSiteDisposition::SameSite : SameSiteDisposition::CrossSite);
+    m_sameSiteDisposition = !siteForCookies ? SameSiteDisposition::Unspecified : (areRegistrableDomainsEqual(siteForCookies.get(), m_url) ? SameSiteDisposition::SameSite : SameSiteDisposition::CrossSite);
 
     RetainPtr<CFNumberRef> isTopSiteCF = adoptCF(checked_cf_cast<CFNumber>(_CFURLRequestCopyProtocolPropertyForKey(m_cfRequest.get(), CFSTR("_kCFHTTPCookiePolicyPropertyisTopSite"))));
     if (!isTopSiteCF)
index 2fec1f3..65fdcfa 100644 (file)
@@ -30,6 +30,7 @@
 
 #import "FormDataStreamMac.h"
 #import "HTTPHeaderNames.h"
+#import "RegistrableDomain.h"
 #import "ResourceRequestCFNet.h"
 #import "RuntimeApplicationChecks.h"
 #import <Foundation/Foundation.h>
@@ -89,7 +90,7 @@ void ResourceRequest::doUpdateResourceRequest()
 
 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || (PLATFORM(IOS_FAMILY) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000)
     URL siteForCookies { [m_nsRequest.get() _propertyForKey:@"_kCFHTTPCookiePolicyPropertySiteForCookies"] };
-    m_sameSiteDisposition = siteForCookies.isNull() ? SameSiteDisposition::Unspecified : (registrableDomainsAreEqual(siteForCookies, m_url) ? SameSiteDisposition::SameSite : SameSiteDisposition::CrossSite);
+    m_sameSiteDisposition = siteForCookies.isNull() ? SameSiteDisposition::Unspecified : (areRegistrableDomainsEqual(siteForCookies, m_url) ? SameSiteDisposition::SameSite : SameSiteDisposition::CrossSite);
 
     m_isTopSite = static_cast<NSNumber*>([m_nsRequest.get() _propertyForKey:@"_kCFHTTPCookiePolicyPropertyIsTopLevelNavigation"]).boolValue;
 #endif
index c1bfc8a..a86e116 100644 (file)
@@ -1,3 +1,16 @@
+2019-03-13  Chris Dumez  <cdumez@apple.com>
+
+        Drop legacy WebCore::toRegistrableDomain() utility function
+        https://bugs.webkit.org/show_bug.cgi?id=195637
+
+        Reviewed by Geoffrey Garen.
+
+        Drop legacy toRegistrableDomain() / registrableDomainAreEqual() utility functions.
+        Update call sites to use modern RegistrableDomain type instead.
+
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::processForNavigationInternal):
+
 2019-03-12  Brady Eidson  <beidson@apple.com>
 
         Take UnboundedNetworking assertion when a file upload is in progress.
index 28c0c65..5cdd316 100644 (file)
@@ -145,7 +145,7 @@ void NetworkDataTaskCocoa::applyCookieBlockingPolicy(bool shouldBlock)
 
 bool NetworkDataTaskCocoa::isThirdPartyRequest(const WebCore::ResourceRequest& request)
 {
-    return !WebCore::registrableDomainsAreEqual(request.url(), request.firstPartyForCookies());
+    return !WebCore::areRegistrableDomainsEqual(request.url(), request.firstPartyForCookies());
 }
 
 static void updateTaskWithFirstPartyForSameSiteCookies(NSURLSessionDataTask* task, const WebCore::ResourceRequest& request)
index 8a28536..44eea45 100644 (file)
@@ -1313,7 +1313,7 @@ DownloadProxy* WebProcessPool::download(WebPageProxy* initiatingPage, const Reso
         if (initiatingPage) {
             URL initiatingPageURL = URL { URL { }, initiatingPage->pageLoadState().url() };
             updatedRequest.setFirstPartyForCookies(initiatingPageURL);
-            updatedRequest.setIsSameSite(registrableDomainsAreEqual(initiatingPageURL, request.url()));
+            updatedRequest.setIsSameSite(areRegistrableDomainsEqual(initiatingPageURL, request.url()));
             if (!updatedRequest.hasHTTPHeaderField(HTTPHeaderName::UserAgent))
                 updatedRequest.setHTTPUserAgent(initiatingPage->userAgent());
         } else {
@@ -2212,14 +2212,14 @@ void WebProcessPool::processForNavigation(WebPageProxy& page, const API::Navigat
 void WebProcessPool::processForNavigationInternal(WebPageProxy& page, const API::Navigation& navigation, Ref<WebProcessProxy>&& sourceProcess, const URL& pageSourceURL, ProcessSwapRequestedByClient processSwapRequestedByClient, Ref<WebsiteDataStore>&& dataStore, CompletionHandler<void(Ref<WebProcessProxy>&&, SuspendedPageProxy*, const String&)>&& completionHandler)
 {
     auto& targetURL = navigation.currentRequest().url();
-    auto registrableDomain = WebCore::RegistrableDomain { targetURL };
+    auto targetRegistrableDomain = WebCore::RegistrableDomain { targetURL };
 
-    auto createNewProcess = [this, protectedThis = makeRef(*this), page = makeRef(page), targetURL, registrableDomain, dataStore = dataStore.copyRef()] () -> Ref<WebProcessProxy> {
-        if (auto process = webProcessCache().takeProcess(registrableDomain, dataStore))
+    auto createNewProcess = [this, protectedThis = makeRef(*this), page = makeRef(page), targetURL, targetRegistrableDomain, dataStore = dataStore.copyRef()] () -> Ref<WebProcessProxy> {
+        if (auto process = webProcessCache().takeProcess(targetRegistrableDomain, dataStore))
             return process.releaseNonNull();
 
         // Check if we have a suspended page for the given registrable domain and use its process if we do, for performance reasons.
-        if (auto process = findReusableSuspendedPageProcess(registrableDomain, page, dataStore)) {
+        if (auto process = findReusableSuspendedPageProcess(targetRegistrableDomain, page, dataStore)) {
             RELEASE_LOG(ProcessSwapping, "Using WebProcess %i from a SuspendedPage", process->processIdentifier());
             return process.releaseNonNull();
         }
@@ -2300,15 +2300,15 @@ void WebProcessPool::processForNavigationInternal(WebPageProxy& page, const API:
         RELEASE_LOG(ProcessSwapping, "Using related page %p's URL as source URL for process swap decision", page.configuration().relatedPage());
     }
 
-    if (!sourceURL.isValid() || !targetURL.isValid() || sourceURL.isEmpty() || sourceURL.protocolIsAbout() || registrableDomainsAreEqual(sourceURL, targetURL))
+    if (!sourceURL.isValid() || !targetURL.isValid() || sourceURL.isEmpty() || sourceURL.protocolIsAbout() || targetRegistrableDomain.matches(sourceURL))
         return completionHandler(WTFMove(sourceProcess), nullptr, "Navigation is same-site"_s);
 
     String reason = "Navigation is cross-site"_s;
     
     if (m_configuration->alwaysKeepAndReuseSwappedProcesses()) {
-        LOG(ProcessSwapping, "(ProcessSwapping) Considering re-use of a previously cached process for domain %s", registrableDomain.string().utf8().data());
+        LOG(ProcessSwapping, "(ProcessSwapping) Considering re-use of a previously cached process for domain %s", targetRegistrableDomain.string().utf8().data());
 
-        if (auto* process = m_swappedProcessesPerRegistrableDomain.get(registrableDomain)) {
+        if (auto* process = m_swappedProcessesPerRegistrableDomain.get(targetRegistrableDomain)) {
             if (&process->websiteDataStore() == dataStore.ptr()) {
                 LOG(ProcessSwapping, "(ProcessSwapping) Reusing a previously cached process with pid %i to continue navigation to URL %s", process->processIdentifier(), targetURL.string().utf8().data());
 
index 6e6ec19..2c85883 100644 (file)
@@ -395,7 +395,7 @@ void WebFrameLoaderClient::dispatchWillChangeDocument(const URL& currentUrl, con
     if (!webPage)
         return;
 
-    if (m_hasFrameSpecificStorageAccess && !WebCore::registrableDomainsAreEqual(currentUrl, newUrl)) {
+    if (m_hasFrameSpecificStorageAccess && !WebCore::areRegistrableDomainsEqual(currentUrl, newUrl)) {
         WebProcess::singleton().ensureNetworkProcessConnection().connection().send(Messages::NetworkConnectionToWebProcess::RemoveStorageAccessForFrame(sessionID(), frameID().value(), pageID().value()), 0);
         m_hasFrameSpecificStorageAccess = false;
     }