Use new RegistrableDomain type in PSON code
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Mar 2019 17:48:47 +0000 (17:48 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Mar 2019 17:48:47 +0000 (17:48 +0000)
https://bugs.webkit.org/show_bug.cgi?id=195634

Reviewed by Youenn Fablet.

Use new RegistrableDomain type in PSON code instead of more error-prone String type.

* UIProcess/SuspendedPageProxy.cpp:
(WebKit::SuspendedPageProxy::SuspendedPageProxy):
* UIProcess/SuspendedPageProxy.h:
* UIProcess/WebProcessCache.cpp:
(WebKit::WebProcessCache::canCacheProcess const):
(WebKit::WebProcessCache::addProcessIfPossible):
(WebKit::WebProcessCache::takeProcess):
(WebKit::WebProcessCache::clearAllProcessesForSession):
* UIProcess/WebProcessCache.h:
* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::addProcessToOriginCacheSet):
(WebKit::WebProcessPool::removeProcessFromOriginCacheSet):
(WebKit::WebProcessPool::processForNavigationInternal):
(WebKit::WebProcessPool::findReusableSuspendedPageProcess):
(WebKit::WebProcessPool::didCollectPrewarmInformation):
(WebKit::WebProcessPool::tryPrewarmWithDomainInformation):
* UIProcess/WebProcessPool.h:
* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::canBeAddedToWebProcessCache const):
(WebKit::WebProcessProxy::maybeShutDown):
(WebKit::WebProcessProxy::didCollectPrewarmInformation):
(WebKit::WebProcessProxy::didStartProvisionalLoadForMainFrame):
* UIProcess/WebProcessProxy.h:
(WebKit::WebProcessProxy::registrableDomain const):
* UIProcess/WebProcessProxy.messages.in:
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::sendPrewarmInformation):

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/SuspendedPageProxy.cpp
Source/WebKit/UIProcess/SuspendedPageProxy.h
Source/WebKit/UIProcess/WebProcessCache.cpp
Source/WebKit/UIProcess/WebProcessCache.h
Source/WebKit/UIProcess/WebProcessPool.cpp
Source/WebKit/UIProcess/WebProcessPool.h
Source/WebKit/UIProcess/WebProcessProxy.cpp
Source/WebKit/UIProcess/WebProcessProxy.h
Source/WebKit/UIProcess/WebProcessProxy.messages.in
Source/WebKit/WebProcess/WebProcess.cpp

index 3e4927a..6c7197e 100644 (file)
@@ -1,3 +1,40 @@
+2019-03-13  Chris Dumez  <cdumez@apple.com>
+
+        Use new RegistrableDomain type in PSON code
+        https://bugs.webkit.org/show_bug.cgi?id=195634
+
+        Reviewed by Youenn Fablet.
+
+        Use new RegistrableDomain type in PSON code instead of more error-prone String type.
+
+        * UIProcess/SuspendedPageProxy.cpp:
+        (WebKit::SuspendedPageProxy::SuspendedPageProxy):
+        * UIProcess/SuspendedPageProxy.h:
+        * UIProcess/WebProcessCache.cpp:
+        (WebKit::WebProcessCache::canCacheProcess const):
+        (WebKit::WebProcessCache::addProcessIfPossible):
+        (WebKit::WebProcessCache::takeProcess):
+        (WebKit::WebProcessCache::clearAllProcessesForSession):
+        * UIProcess/WebProcessCache.h:
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::addProcessToOriginCacheSet):
+        (WebKit::WebProcessPool::removeProcessFromOriginCacheSet):
+        (WebKit::WebProcessPool::processForNavigationInternal):
+        (WebKit::WebProcessPool::findReusableSuspendedPageProcess):
+        (WebKit::WebProcessPool::didCollectPrewarmInformation):
+        (WebKit::WebProcessPool::tryPrewarmWithDomainInformation):
+        * UIProcess/WebProcessPool.h:
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::canBeAddedToWebProcessCache const):
+        (WebKit::WebProcessProxy::maybeShutDown):
+        (WebKit::WebProcessProxy::didCollectPrewarmInformation):
+        (WebKit::WebProcessProxy::didStartProvisionalLoadForMainFrame):
+        * UIProcess/WebProcessProxy.h:
+        (WebKit::WebProcessProxy::registrableDomain const):
+        * UIProcess/WebProcessProxy.messages.in:
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::sendPrewarmInformation):
+
 2019-03-13  Fujii Hironori  <Hironori.Fujii@sony.com>
 
         [Win][PlayStation] Remove WebCore::standardUserAgentForURL
index 5345ba1..82ddf19 100644 (file)
@@ -82,7 +82,7 @@ SuspendedPageProxy::SuspendedPageProxy(WebPageProxy& page, Ref<WebProcessProxy>&
     : m_page(page)
     , m_process(WTFMove(process))
     , m_mainFrameID(mainFrameID)
-    , m_registrableDomain(toRegistrableDomain(URL(URL(), item.url())))
+    , m_registrableDomain(URL(URL(), item.url()))
     , m_suspensionTimeoutTimer(RunLoop::main(), this, &SuspendedPageProxy::suspensionTimedOut)
 #if PLATFORM(IOS_FAMILY)
     , m_suspensionToken(m_process->throttler().backgroundActivityToken())
index 640bf21..5c24c34 100644 (file)
@@ -29,7 +29,7 @@
 #include "ProcessThrottler.h"
 #include "WebBackForwardListItem.h"
 #include "WebPageProxyMessages.h"
-#include <WebCore/SecurityOriginData.h>
+#include <WebCore/RegistrableDomain.h>
 #include <wtf/RefCounted.h>
 #include <wtf/WeakPtr.h>
 
@@ -47,7 +47,7 @@ public:
     WebPageProxy& page() const { return m_page; }
     WebProcessProxy& process() { return m_process.get(); }
     uint64_t mainFrameID() const { return m_mainFrameID; }
-    const String& registrableDomain() const { return m_registrableDomain; }
+    const WebCore::RegistrableDomain& registrableDomain() const { return m_registrableDomain; }
 
     bool failedToSuspend() const { return m_suspensionState == SuspensionState::FailedToSuspend; }
 
@@ -71,7 +71,7 @@ private:
     WebPageProxy& m_page;
     Ref<WebProcessProxy> m_process;
     uint64_t m_mainFrameID;
-    String m_registrableDomain;
+    WebCore::RegistrableDomain m_registrableDomain;
     bool m_isClosed { false };
 
     SuspensionState m_suspensionState { SuspensionState::Suspending };
index 72ed3e0..fff7bc6 100644 (file)
@@ -55,6 +55,11 @@ bool WebProcessCache::canCacheProcess(WebProcessProxy& process) const
     if (!capacity())
         return false;
 
+    if (process.registrableDomain().isEmpty()) {
+        RELEASE_LOG(ProcessSwapping, "%p - WebProcessCache::canCacheProcess(): Not caching process %i because it does not have an associated registrable domain", this, process.processIdentifier());
+        return false;
+    }
+
     if (MemoryPressureHandler::singleton().isUnderMemoryPressure()) {
         RELEASE_LOG(ProcessSwapping, "%p - WebProcessCache::canCacheProcess(): Not caching process %i because we are under memory pressure", this, process.processIdentifier());
         return false;
@@ -69,9 +74,8 @@ bool WebProcessCache::canCacheProcess(WebProcessProxy& process) const
     return true;
 }
 
-bool WebProcessCache::addProcessIfPossible(const String& registrableDomain, Ref<WebProcessProxy>&& process)
+bool WebProcessCache::addProcessIfPossible(Ref<WebProcessProxy>&& process)
 {
-    ASSERT(!registrableDomain.isEmpty());
     ASSERT(!process->pageCount());
     ASSERT(!process->provisionalPageCount());
     ASSERT(!process->suspendedPageCount());
@@ -124,7 +128,7 @@ bool WebProcessCache::addProcess(std::unique_ptr<CachedProcess>&& cachedProcess)
     return true;
 }
 
-RefPtr<WebProcessProxy> WebProcessCache::takeProcess(const String& registrableDomain, WebsiteDataStore& dataStore)
+RefPtr<WebProcessProxy> WebProcessCache::takeProcess(const WebCore::RegistrableDomain& registrableDomain, WebsiteDataStore& dataStore)
 {
     auto it = m_processesPerRegistrableDomain.find(registrableDomain);
     if (it == m_processesPerRegistrableDomain.end())
@@ -180,7 +184,7 @@ void WebProcessCache::clear()
 
 void WebProcessCache::clearAllProcessesForSession(PAL::SessionID sessionID)
 {
-    Vector<String> keysToRemove;
+    Vector<WebCore::RegistrableDomain> keysToRemove;
     for (auto& pair : m_processesPerRegistrableDomain) {
         if (pair.value->process().websiteDataStore().sessionID() == sessionID) {
             RELEASE_LOG(ProcessSwapping, "%p - WebProcessCache::clearAllProcessesForSession() evicting process %i because its session was destroyed", this, pair.value->process().processIdentifier());
index 0a30d53..6688866 100644 (file)
@@ -26,6 +26,7 @@
 
 #pragma once
 
+#include <WebCore/RegistrableDomain.h>
 #include <pal/SessionID.h>
 #include <wtf/HashMap.h>
 #include <wtf/RunLoop.h>
@@ -42,8 +43,8 @@ class WebProcessCache {
 public:
     explicit WebProcessCache(WebProcessPool&);
 
-    bool addProcessIfPossible(const String& registrableDomain, Ref<WebProcessProxy>&&);
-    RefPtr<WebProcessProxy> takeProcess(const String& registrableDomain, WebsiteDataStore&);
+    bool addProcessIfPossible(Ref<WebProcessProxy>&&);
+    RefPtr<WebProcessProxy> takeProcess(const WebCore::RegistrableDomain&, WebsiteDataStore&);
 
     void updateCapacity(WebProcessPool&);
     unsigned capacity() const { return m_capacity; }
@@ -85,7 +86,7 @@ private:
     unsigned m_capacity { 0 };
 
     HashMap<uint64_t, std::unique_ptr<CachedProcess>> m_pendingAddRequests;
-    HashMap<String, std::unique_ptr<CachedProcess>> m_processesPerRegistrableDomain;
+    HashMap<WebCore::RegistrableDomain, std::unique_ptr<CachedProcess>> m_processesPerRegistrableDomain;
     RunLoop::Timer<WebProcessCache> m_evictionTimer;
 };
 
index aac52aa..4b27830 100644 (file)
@@ -2159,12 +2159,12 @@ ServiceWorkerProcessProxy* WebProcessPool::serviceWorkerProcessProxyFromPageID(u
 
 void WebProcessPool::addProcessToOriginCacheSet(WebProcessProxy& process, const URL& url)
 {
-    auto registrableDomain = toRegistrableDomain(url);
+    auto registrableDomain = WebCore::RegistrableDomain { url };
     auto result = m_swappedProcessesPerRegistrableDomain.add(registrableDomain, &process);
     if (!result.isNewEntry)
         result.iterator->value = &process;
 
-    LOG(ProcessSwapping, "(ProcessSwapping) Registrable domain %s just saved a cached process with pid %i", registrableDomain.utf8().data(), process.processIdentifier());
+    LOG(ProcessSwapping, "(ProcessSwapping) Registrable domain %s just saved a cached process with pid %i", registrableDomain.string().utf8().data(), process.processIdentifier());
     if (!result.isNewEntry)
         LOG(ProcessSwapping, "(ProcessSwapping) Note: It already had one saved");
 }
@@ -2174,7 +2174,7 @@ void WebProcessPool::removeProcessFromOriginCacheSet(WebProcessProxy& process)
     LOG(ProcessSwapping, "(ProcessSwapping) Removing process with pid %i from the origin cache set", process.processIdentifier());
 
     // FIXME: This can be very inefficient as the number of remembered origins and processes grows
-    Vector<String> registrableDomainsToRemove;
+    Vector<WebCore::RegistrableDomain> registrableDomainsToRemove;
     for (auto entry : m_swappedProcessesPerRegistrableDomain) {
         if (entry.value == &process)
             registrableDomainsToRemove.append(entry.key);
@@ -2212,7 +2212,7 @@ 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 = toRegistrableDomain(targetURL);
+    auto registrableDomain = 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))
@@ -2306,7 +2306,7 @@ void WebProcessPool::processForNavigationInternal(WebPageProxy& page, const API:
     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.utf8().data());
+        LOG(ProcessSwapping, "(ProcessSwapping) Considering re-use of a previously cached process for domain %s", registrableDomain.string().utf8().data());
 
         if (auto* process = m_swappedProcessesPerRegistrableDomain.get(registrableDomain)) {
             if (&process->websiteDataStore() == dataStore.ptr()) {
@@ -2326,7 +2326,7 @@ void WebProcessPool::processForNavigationInternal(WebPageProxy& page, const API:
     return completionHandler(createNewProcess(), nullptr, reason);
 }
 
-RefPtr<WebProcessProxy> WebProcessPool::findReusableSuspendedPageProcess(const String& registrableDomain, WebPageProxy& page, WebsiteDataStore& dataStore)
+RefPtr<WebProcessProxy> WebProcessPool::findReusableSuspendedPageProcess(const WebCore::RegistrableDomain& registrableDomain, WebPageProxy& page, WebsiteDataStore& dataStore)
 {
     auto it = m_suspendedPages.findIf([&](auto& suspendedPage) {
         return suspendedPage->registrableDomain() == registrableDomain && &suspendedPage->process().websiteDataStore() == &dataStore;
@@ -2450,7 +2450,7 @@ void WebProcessPool::sendDisplayConfigurationChangedMessageForTesting()
 #endif
 }
 
-void WebProcessPool::didCollectPrewarmInformation(const String& registrableDomain, const WebCore::PrewarmInformation& prewarmInformation)
+void WebProcessPool::didCollectPrewarmInformation(const WebCore::RegistrableDomain& registrableDomain, const WebCore::PrewarmInformation& prewarmInformation)
 {
     static const size_t maximumSizeToPreventUnlimitedGrowth = 100;
     if (m_prewarmInformationPerRegistrableDomain.size() == maximumSizeToPreventUnlimitedGrowth)
@@ -2465,7 +2465,7 @@ void WebProcessPool::didCollectPrewarmInformation(const String& registrableDomai
 
 void WebProcessPool::tryPrewarmWithDomainInformation(WebProcessProxy& process, const URL& url)
 {
-    auto* prewarmInformation = m_prewarmInformationPerRegistrableDomain.get(toRegistrableDomain(url));
+    auto* prewarmInformation = m_prewarmInformationPerRegistrableDomain.get(RegistrableDomain { url });
     if (!prewarmInformation)
         return;
     process.send(Messages::WebProcess::PrewarmWithDomainInformation(*prewarmInformation), 0);
index 3d2b598..f109c2c 100644 (file)
@@ -467,13 +467,13 @@ public:
     void removeSuspendedPage(SuspendedPageProxy&);
     bool hasSuspendedPageFor(WebProcessProxy&, WebPageProxy&) const;
     unsigned maxSuspendedPageCount() const { return m_maxSuspendedPageCount; }
-    RefPtr<WebProcessProxy> findReusableSuspendedPageProcess(const String&, WebPageProxy&, WebsiteDataStore&);
+    RefPtr<WebProcessProxy> findReusableSuspendedPageProcess(const WebCore::RegistrableDomain&, WebPageProxy&, WebsiteDataStore&);
 
     void clearSuspendedPages(AllowProcessCaching);
 
     void didReachGoodTimeToPrewarm(WebsiteDataStore&);
 
-    void didCollectPrewarmInformation(const String& registrableDomain, const WebCore::PrewarmInformation&);
+    void didCollectPrewarmInformation(const WebCore::RegistrableDomain&, const WebCore::PrewarmInformation&);
 
     void screenPropertiesStateChanged();
 
@@ -756,9 +756,9 @@ private:
     unsigned m_maxSuspendedPageCount { 0 };
 
     UniqueRef<WebProcessCache> m_webProcessCache;
-    HashMap<String, RefPtr<WebProcessProxy>> m_swappedProcessesPerRegistrableDomain;
+    HashMap<WebCore::RegistrableDomain, RefPtr<WebProcessProxy>> m_swappedProcessesPerRegistrableDomain;
 
-    HashMap<String, std::unique_ptr<WebCore::PrewarmInformation>> m_prewarmInformationPerRegistrableDomain;
+    HashMap<WebCore::RegistrableDomain, std::unique_ptr<WebCore::PrewarmInformation>> m_prewarmInformationPerRegistrableDomain;
 
 #if PLATFORM(MAC) && ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING)
     Vector<std::unique_ptr<DisplayLink>> m_displayLinks;
index 50de216..9030df2 100644 (file)
@@ -834,9 +834,6 @@ void WebProcessProxy::didDestroyUserGestureToken(uint64_t identifier)
 
 bool WebProcessProxy::canBeAddedToWebProcessCache() const
 {
-    if (registrableDomain().isEmpty())
-        return false;
-
     if (isServiceWorkerProcess())
         return false;
 
@@ -851,7 +848,7 @@ void WebProcessProxy::maybeShutDown(AllowProcessCaching allowProcessCaching)
     if (state() == State::Terminated || !canTerminateAuxiliaryProcess())
         return;
 
-    if (allowProcessCaching == AllowProcessCaching::Yes && canBeAddedToWebProcessCache() && processPool().webProcessCache().addProcessIfPossible(registrableDomain(), *this))
+    if (allowProcessCaching == AllowProcessCaching::Yes && canBeAddedToWebProcessCache() && processPool().webProcessCache().addProcessIfPossible(*this))
         return;
 
     shutDown();
@@ -1415,7 +1412,7 @@ void WebProcessProxy::didCheckProcessLocalPortForActivity(uint64_t callbackIdent
     callback(isLocallyReachable ? MessagePortChannelProvider::HasActivity::Yes : MessagePortChannelProvider::HasActivity::No);
 }
 
-void WebProcessProxy::didCollectPrewarmInformation(const String& domain, const WebCore::PrewarmInformation& prewarmInformation)
+void WebProcessProxy::didCollectPrewarmInformation(const WebCore::RegistrableDomain& domain, const WebCore::PrewarmInformation& prewarmInformation)
 {
     processPool().didCollectPrewarmInformation(domain, prewarmInformation);
 }
@@ -1430,13 +1427,13 @@ void WebProcessProxy::didStartProvisionalLoadForMainFrame(const URL& url)
     RELEASE_ASSERT(!isInProcessCache());
 
     // This process has been used for several registrable domains already.
-    if (m_registrableDomain && m_registrableDomain->isNull())
+    if (m_registrableDomain && m_registrableDomain->isEmpty())
         return;
 
-    auto registrableDomain = toRegistrableDomain(url);
+    auto registrableDomain = WebCore::RegistrableDomain { url };
     if (m_registrableDomain && *m_registrableDomain != registrableDomain) {
         // Null out registrable domain since this process has now been used for several domains.
-        m_registrableDomain = String();
+        m_registrableDomain = WebCore::RegistrableDomain { };
         return;
     }
 
index e3d8f8f..258102b 100644 (file)
@@ -41,6 +41,7 @@
 #include <WebCore/MessagePortChannelProvider.h>
 #include <WebCore/MessagePortIdentifier.h>
 #include <WebCore/ProcessIdentifier.h>
+#include <WebCore/RegistrableDomain.h>
 #include <WebCore/SharedStringHash.h>
 #include <memory>
 #include <pal/SessionID.h>
@@ -114,7 +115,7 @@ public:
 
     WebProcessPool& processPool() const { ASSERT(m_processPool); return *m_processPool.get(); }
 
-    String registrableDomain() const { return m_registrableDomain.valueOr(String()); }
+    WebCore::RegistrableDomain registrableDomain() const { return m_registrableDomain.valueOr(WebCore::RegistrableDomain { }); }
     void setIsInProcessCache(bool);
     bool isInProcessCache() const { return m_isInProcessCache; }
 
@@ -371,7 +372,7 @@ private:
 
     bool canTerminateAuxiliaryProcess();
 
-    void didCollectPrewarmInformation(const String& domain, const WebCore::PrewarmInformation&);
+    void didCollectPrewarmInformation(const WebCore::RegistrableDomain&, const WebCore::PrewarmInformation&);
 
     void logDiagnosticMessageForResourceLimitTermination(const String& limitKey);
 
@@ -434,7 +435,7 @@ private:
 
     HashMap<String, uint64_t> m_pageURLRetainCountMap;
 
-    Optional<String> m_registrableDomain;
+    Optional<WebCore::RegistrableDomain> m_registrableDomain;
     bool m_isInProcessCache { false };
 
     enum class NoOrMaybe { No, Maybe } m_isResponsive;
index 78b9618..2c82ee6 100644 (file)
@@ -64,7 +64,7 @@ messages -> WebProcessProxy LegacyReceiver {
     DidDeliverMessagePortMessages(uint64_t messageBatchIdentifier)
     DidCheckProcessLocalPortForActivity(uint64_t callbackIdentifier, bool isLocallyReachable)
 
-    DidCollectPrewarmInformation(String domain, struct WebCore::PrewarmInformation prewarmInformation)
+    DidCollectPrewarmInformation(WebCore::RegistrableDomain domain, struct WebCore::PrewarmInformation prewarmInformation)
 
 #if PLATFORM(COCOA)
     CacheMediaMIMETypes(Vector<String> types)
index c1e44f1..69cb9e4 100644 (file)
@@ -1575,7 +1575,7 @@ void WebProcess::processDidResume()
 
 void WebProcess::sendPrewarmInformation(const URL& url)
 {
-    auto registrableDomain = toRegistrableDomain(url);
+    auto registrableDomain = WebCore::RegistrableDomain { url };
     if (registrableDomain.isEmpty())
         return;
     parentProcessConnection()->send(Messages::WebProcessProxy::DidCollectPrewarmInformation(registrableDomain, WebCore::ProcessWarming::collectPrewarmInformation()), 0);