Split ResourceLoadObserver into 2 classes: one for WebCore and one for the UIProcess
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Jun 2017 23:40:29 +0000 (23:40 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Jun 2017 23:40:29 +0000 (23:40 +0000)
https://bugs.webkit.org/show_bug.cgi?id=173990

Reviewed by Brent Fulgham.

Split ResourceLoadObserver into 2 classes: one for WebCore and one for the UIProcess.
They really have different API and there is therefore close to no code duplication.

Source/WebCore:

* loader/ResourceLoadObserver.cpp:
(WebCore::primaryDomain):
(WebCore::ResourceLoadObserver::setStatisticsQueue):
(WebCore::ResourceLoadObserver::shouldLog):
* loader/ResourceLoadObserver.h:
* loader/ResourceLoadStatisticsStore.cpp:
(WebCore::ResourceLoadStatisticsStore::primaryDomain):
* loader/ResourceLoadStatisticsStore.h:
* platform/URL.h:

Source/WebKit2:

* CMakeLists.txt:
* UIProcess/Cocoa/WebResourceLoadStatisticsManagerCocoa.mm:
(WebKit::WebResourceLoadStatisticsManager::registerUserDefaultsIfNeeded):
* UIProcess/WebResourceLoadObserver.cpp: Added.
(WebKit::primaryDomain):
(WebKit::WebResourceLoadObserver::sharedObserver):
(WebKit::WebResourceLoadObserver::setStatisticsStore):
(WebKit::WebResourceLoadObserver::setStatisticsQueue):
(WebKit::WebResourceLoadObserver::clearInMemoryStore):
(WebKit::WebResourceLoadObserver::clearInMemoryAndPersistentStore):
(WebKit::WebResourceLoadObserver::logUserInteraction):
(WebKit::WebResourceLoadObserver::clearUserInteraction):
(WebKit::WebResourceLoadObserver::hasHadUserInteraction):
(WebKit::WebResourceLoadObserver::setPrevalentResource):
(WebKit::WebResourceLoadObserver::isPrevalentResource):
(WebKit::WebResourceLoadObserver::clearPrevalentResource):
(WebKit::WebResourceLoadObserver::setGrandfathered):
(WebKit::WebResourceLoadObserver::isGrandfathered):
(WebKit::WebResourceLoadObserver::setSubframeUnderTopFrameOrigin):
(WebKit::WebResourceLoadObserver::setSubresourceUnderTopFrameOrigin):
(WebKit::WebResourceLoadObserver::setSubresourceUniqueRedirectTo):
(WebKit::WebResourceLoadObserver::setTimeToLiveUserInteraction):
(WebKit::WebResourceLoadObserver::setTimeToLiveCookiePartitionFree):
(WebKit::WebResourceLoadObserver::setMinimumTimeBetweeenDataRecordsRemoval):
(WebKit::WebResourceLoadObserver::setGrandfatheringTime):
(WebKit::WebResourceLoadObserver::fireDataModificationHandler):
(WebKit::WebResourceLoadObserver::fireShouldPartitionCookiesHandler):
(WebKit::WebResourceLoadObserver::fireTelemetryHandler):
* UIProcess/WebResourceLoadObserver.h: Added.
* UIProcess/WebResourceLoadStatisticsManager.cpp:
(WebKit::WebResourceLoadStatisticsManager::setPrevalentResource):
(WebKit::WebResourceLoadStatisticsManager::isPrevalentResource):
(WebKit::WebResourceLoadStatisticsManager::setHasHadUserInteraction):
(WebKit::WebResourceLoadStatisticsManager::hasHadUserInteraction):
(WebKit::WebResourceLoadStatisticsManager::setGrandfathered):
(WebKit::WebResourceLoadStatisticsManager::isGrandfathered):
(WebKit::WebResourceLoadStatisticsManager::setSubframeUnderTopFrameOrigin):
(WebKit::WebResourceLoadStatisticsManager::setSubresourceUnderTopFrameOrigin):
(WebKit::WebResourceLoadStatisticsManager::setSubresourceUniqueRedirectTo):
(WebKit::WebResourceLoadStatisticsManager::setTimeToLiveUserInteraction):
(WebKit::WebResourceLoadStatisticsManager::setTimeToLiveCookiePartitionFree):
(WebKit::WebResourceLoadStatisticsManager::setMinimumTimeBetweeenDataRecordsRemoval):
(WebKit::WebResourceLoadStatisticsManager::setGrandfatheringTime):
(WebKit::WebResourceLoadStatisticsManager::fireDataModificationHandler):
(WebKit::WebResourceLoadStatisticsManager::fireShouldPartitionCookiesHandler):
(WebKit::WebResourceLoadStatisticsManager::fireShouldPartitionCookiesHandlerForOneDomain):
(WebKit::WebResourceLoadStatisticsManager::fireTelemetryHandler):
(WebKit::WebResourceLoadStatisticsManager::clearInMemoryAndPersistentStore):
(WebKit::WebResourceLoadStatisticsManager::clearInMemoryAndPersistentStoreModifiedSinceHours):
(WebKit::WebResourceLoadStatisticsManager::resetToConsistentState):
* UIProcess/WebResourceLoadStatisticsStore.cpp:
(WebKit::WebResourceLoadStatisticsStore::registerSharedResourceLoadObserver):
* UIProcess/WebsiteData/WebsiteDataStore.cpp:
(WebKit::WebsiteDataStore::removeData):
* WebKit2.xcodeproj/project.pbxproj:

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

15 files changed:
Source/WebCore/ChangeLog
Source/WebCore/loader/ResourceLoadObserver.cpp
Source/WebCore/loader/ResourceLoadObserver.h
Source/WebCore/loader/ResourceLoadStatisticsStore.cpp
Source/WebCore/loader/ResourceLoadStatisticsStore.h
Source/WebCore/platform/URL.h
Source/WebKit2/CMakeLists.txt
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/Cocoa/WebResourceLoadStatisticsManagerCocoa.mm
Source/WebKit2/UIProcess/WebResourceLoadObserver.cpp [new file with mode: 0644]
Source/WebKit2/UIProcess/WebResourceLoadObserver.h [new file with mode: 0644]
Source/WebKit2/UIProcess/WebResourceLoadStatisticsManager.cpp
Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.cpp
Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.cpp
Source/WebKit2/WebKit2.xcodeproj/project.pbxproj

index 9637a7b..d4f7eb6 100644 (file)
@@ -1,3 +1,23 @@
+2017-06-29  Chris Dumez  <cdumez@apple.com>
+
+        Split ResourceLoadObserver into 2 classes: one for WebCore and one for the UIProcess
+        https://bugs.webkit.org/show_bug.cgi?id=173990
+
+        Reviewed by Brent Fulgham.
+
+        Split ResourceLoadObserver into 2 classes: one for WebCore and one for the UIProcess.
+        They really have different API and there is therefore close to no code duplication.
+
+        * loader/ResourceLoadObserver.cpp:
+        (WebCore::primaryDomain):
+        (WebCore::ResourceLoadObserver::setStatisticsQueue):
+        (WebCore::ResourceLoadObserver::shouldLog):
+        * loader/ResourceLoadObserver.h:
+        * loader/ResourceLoadStatisticsStore.cpp:
+        (WebCore::ResourceLoadStatisticsStore::primaryDomain):
+        * loader/ResourceLoadStatisticsStore.h:
+        * platform/URL.h:
+
 2017-06-29  Sam Weinig  <sam@webkit.org>
 
         [WebIDL] Remove custom binding for UserMessageHandlersNamespace
index dc41449..3fc6aba 100644 (file)
 #include "Frame.h"
 #include "Logging.h"
 #include "MainFrame.h"
-#include "NetworkStorageSession.h"
 #include "Page.h"
-#include "PlatformStrategies.h"
-#include "PublicSuffix.h"
-#include "ResourceLoadStatistics.h"
 #include "ResourceLoadStatisticsStore.h"
 #include "ResourceRequest.h"
 #include "ResourceResponse.h"
 #include "SecurityOrigin.h"
 #include "Settings.h"
-#include "SharedBuffer.h"
 #include "URL.h"
-#include <wtf/CrossThreadCopier.h>
 #include <wtf/NeverDestroyed.h>
 #include <wtf/WorkQueue.h>
-#include <wtf/text/StringBuilder.h>
 
 namespace WebCore {
 
+template<typename T> static inline String primaryDomain(const T& value)
+{
+    return ResourceLoadStatisticsStore::primaryDomain(value);
+}
+
 static Seconds timestampResolution { 1_h };
 
 ResourceLoadObserver& ResourceLoadObserver::sharedObserver()
@@ -69,42 +67,13 @@ void ResourceLoadObserver::setStatisticsQueue(Ref<WTF::WorkQueue>&& queue)
     ASSERT(!m_queue);
     m_queue = WTFMove(queue);
 }
-    
-void ResourceLoadObserver::clearInMemoryStore()
-{
-    if (!m_store)
-        return;
-    
-    ASSERT(m_queue);
-    m_queue->dispatch([this] {
-        m_store->clearInMemory();
-    });
-}
-    
-void ResourceLoadObserver::clearInMemoryAndPersistentStore()
-{
-    if (!m_store)
-        return;
-    
-    ASSERT(m_queue);
-    m_queue->dispatch([this] {
-        m_store->clearInMemoryAndPersistent();
-    });
-}
-
-void ResourceLoadObserver::clearInMemoryAndPersistentStore(std::chrono::system_clock::time_point modifiedSince)
-{
-    // For now, be conservative and clear everything regardless of modifiedSince
-    UNUSED_PARAM(modifiedSince);
-    clearInMemoryAndPersistentStore();
-}
 
 static inline bool is3xxRedirect(const ResourceResponse& response)
 {
     return response.httpStatusCode() >= 300 && response.httpStatusCode() <= 399;
 }
 
-bool ResourceLoadObserver::shouldLog(Page* page)
+bool ResourceLoadObserver::shouldLog(Page* page) const
 {
     // FIXME: Err on the safe side until we have sorted out what to do in worker contexts
     if (!page)
@@ -367,224 +336,9 @@ void ResourceLoadObserver::logUserInteractionWithReducedTimeResolution(const Doc
     });
 }
 
-void ResourceLoadObserver::logUserInteraction(const URL& url)
-{
-    if (url.isBlankURL() || url.isEmpty())
-        return;
-
-    ASSERT(m_queue);
-    m_queue->dispatch([this, primaryDomainString = primaryDomain(url).isolatedCopy()] {
-        {
-        auto locker = holdLock(m_store->statisticsLock());
-        auto& statistics = m_store->ensureResourceStatisticsForPrimaryDomain(primaryDomainString);
-        statistics.hadUserInteraction = true;
-        statistics.mostRecentUserInteractionTime = WallTime::now();
-        }
-        
-        m_store->fireShouldPartitionCookiesHandler({ primaryDomainString }, { }, false);
-    });
-}
-
-void ResourceLoadObserver::clearUserInteraction(const URL& url)
-{
-    if (url.isBlankURL() || url.isEmpty())
-        return;
-
-    auto locker = holdLock(m_store->statisticsLock());
-    auto& statistics = m_store->ensureResourceStatisticsForPrimaryDomain(primaryDomain(url));
-    
-    statistics.hadUserInteraction = false;
-    statistics.mostRecentUserInteractionTime = { };
-}
-
-bool ResourceLoadObserver::hasHadUserInteraction(const URL& url)
-{
-    if (url.isBlankURL() || url.isEmpty())
-        return false;
-
-    auto locker = holdLock(m_store->statisticsLock());
-    auto& statistics = m_store->ensureResourceStatisticsForPrimaryDomain(primaryDomain(url));
-    
-    return m_store->hasHadRecentUserInteraction(statistics);
-}
-
-void ResourceLoadObserver::setPrevalentResource(const URL& url)
-{
-    if (url.isBlankURL() || url.isEmpty())
-        return;
-
-    auto locker = holdLock(m_store->statisticsLock());
-    auto& statistics = m_store->ensureResourceStatisticsForPrimaryDomain(primaryDomain(url));
-    
-    statistics.isPrevalentResource = true;
-}
-
-bool ResourceLoadObserver::isPrevalentResource(const URL& url)
-{
-    if (url.isBlankURL() || url.isEmpty())
-        return false;
-
-    auto locker = holdLock(m_store->statisticsLock());
-    auto& statistics = m_store->ensureResourceStatisticsForPrimaryDomain(primaryDomain(url));
-    
-    return statistics.isPrevalentResource;
-}
-    
-void ResourceLoadObserver::clearPrevalentResource(const URL& url)
-{
-    if (url.isBlankURL() || url.isEmpty())
-        return;
-
-    auto locker = holdLock(m_store->statisticsLock());
-    auto& statistics = m_store->ensureResourceStatisticsForPrimaryDomain(primaryDomain(url));
-    
-    statistics.isPrevalentResource = false;
-}
-    
-void ResourceLoadObserver::setGrandfathered(const URL& url, bool value)
-{
-    if (url.isBlankURL() || url.isEmpty())
-        return;
-    
-    auto locker = holdLock(m_store->statisticsLock());
-    auto& statistics = m_store->ensureResourceStatisticsForPrimaryDomain(primaryDomain(url));
-    
-    statistics.grandfathered = value;
-}
-    
-bool ResourceLoadObserver::isGrandfathered(const URL& url)
-{
-    if (url.isBlankURL() || url.isEmpty())
-        return false;
-    
-    auto locker = holdLock(m_store->statisticsLock());
-    auto& statistics = m_store->ensureResourceStatisticsForPrimaryDomain(primaryDomain(url));
-    
-    return statistics.grandfathered;
-}
-
-void ResourceLoadObserver::setSubframeUnderTopFrameOrigin(const URL& subframe, const URL& topFrame)
-{
-    if (subframe.isBlankURL() || subframe.isEmpty() || topFrame.isBlankURL() || topFrame.isEmpty())
-        return;
-    
-    ASSERT(m_queue);
-    m_queue->dispatch([this, primaryTopFrameDomainString = primaryDomain(topFrame).isolatedCopy(), primarySubFrameDomainString = primaryDomain(subframe).isolatedCopy()] {
-        auto locker = holdLock(m_store->statisticsLock());
-        auto& statistics = m_store->ensureResourceStatisticsForPrimaryDomain(primarySubFrameDomainString);
-        statistics.subframeUnderTopFrameOrigins.add(primaryTopFrameDomainString);
-    });
-}
-
-void ResourceLoadObserver::setSubresourceUnderTopFrameOrigin(const URL& subresource, const URL& topFrame)
-{
-    if (subresource.isBlankURL() || subresource.isEmpty() || topFrame.isBlankURL() || topFrame.isEmpty())
-        return;
-    
-    ASSERT(m_queue);
-    m_queue->dispatch([this, primaryTopFrameDomainString = primaryDomain(topFrame).isolatedCopy(), primarySubresourceDomainString = primaryDomain(subresource).isolatedCopy()] {
-        auto locker = holdLock(m_store->statisticsLock());
-        auto& statistics = m_store->ensureResourceStatisticsForPrimaryDomain(primarySubresourceDomainString);
-        statistics.subresourceUnderTopFrameOrigins.add(primaryTopFrameDomainString);
-    });
-}
-
-void ResourceLoadObserver::setSubresourceUniqueRedirectTo(const URL& subresource, const URL& hostNameRedirectedTo)
-{
-    if (subresource.isBlankURL() || subresource.isEmpty() || hostNameRedirectedTo.isBlankURL() || hostNameRedirectedTo.isEmpty())
-        return;
-    
-    ASSERT(m_queue);
-    m_queue->dispatch([this, primaryRedirectDomainString = primaryDomain(hostNameRedirectedTo).isolatedCopy(), primarySubresourceDomainString = primaryDomain(subresource).isolatedCopy()] {
-        auto locker = holdLock(m_store->statisticsLock());
-        auto& statistics = m_store->ensureResourceStatisticsForPrimaryDomain(primarySubresourceDomainString);
-        statistics.subresourceUniqueRedirectsTo.add(primaryRedirectDomainString);
-    });
-}
-
-void ResourceLoadObserver::setTimeToLiveUserInteraction(Seconds seconds)
-{
-    m_store->setTimeToLiveUserInteraction(seconds);
-}
-
-void ResourceLoadObserver::setTimeToLiveCookiePartitionFree(Seconds seconds)
-{
-    m_store->setTimeToLiveCookiePartitionFree(seconds);
-}
-
-void ResourceLoadObserver::setMinimumTimeBetweeenDataRecordsRemoval(Seconds seconds)
-{
-    m_store->setMinimumTimeBetweeenDataRecordsRemoval(seconds);
-}
-    
-void ResourceLoadObserver::setReducedTimestampResolution(Seconds seconds)
-{
-    if (seconds > 0_s)
-        timestampResolution = seconds;
-}
-
-void ResourceLoadObserver::setGrandfatheringTime(Seconds seconds)
-{
-    m_store->setMinimumTimeBetweeenDataRecordsRemoval(seconds);
-}
-    
-void ResourceLoadObserver::fireDataModificationHandler()
-{
-    // Helper function used by testing system. Should only be called from the main thread.
-    ASSERT(isMainThread());
-    m_queue->dispatch([this] {
-        m_store->fireDataModificationHandler();
-    });
-}
-
-void ResourceLoadObserver::fireShouldPartitionCookiesHandler()
-{
-    // Helper function used by testing system. Should only be called from the main thread.
-    ASSERT(isMainThread());
-    m_queue->dispatch([this] {
-        m_store->fireShouldPartitionCookiesHandler();
-    });
-}
-
-void ResourceLoadObserver::fireShouldPartitionCookiesHandler(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool clearFirst)
-{
-    // Helper function used by testing system. Should only be called from the main thread.
-    ASSERT(isMainThread());
-    m_queue->dispatch([this, domainsToRemove = CrossThreadCopier<Vector<String>>::copy(domainsToRemove), domainsToAdd = CrossThreadCopier<Vector<String>>::copy(domainsToAdd), clearFirst] {
-        m_store->fireShouldPartitionCookiesHandler(domainsToRemove, domainsToAdd, clearFirst);
-    });
-}
-
-void ResourceLoadObserver::fireTelemetryHandler()
-{
-    // Helper function used by testing system. Should only be called from the main thread.
-    ASSERT(isMainThread());
-    m_store->fireTelemetryHandler();
-}
-    
-String ResourceLoadObserver::primaryDomain(const URL& url)
-{
-    return primaryDomain(url.host());
-}
-
-String ResourceLoadObserver::primaryDomain(const String& host)
-{
-    if (host.isNull() || host.isEmpty())
-        return ASCIILiteral("nullOrigin");
-
-#if ENABLE(PUBLIC_SUFFIX_LIST)
-    String primaryDomain = topPrivatelyControlledDomain(host);
-    // We will have an empty string here if there is no TLD. Use the host as a fallback.
-    if (!primaryDomain.isEmpty())
-        return primaryDomain;
-#endif
-
-    return host;
-}
-
 String ResourceLoadObserver::statisticsForOrigin(const String& origin)
 {
     return m_store ? m_store->statisticsForOrigin(origin) : emptyString();
 }
 
-}
+} // namespace WebCore
index bd7590b..9a0545c 100644 (file)
@@ -55,43 +55,13 @@ public:
     void logWebSocketLoading(const Frame*, const URL&);
     void logUserInteractionWithReducedTimeResolution(const Document&);
 
-    WEBCORE_EXPORT void logUserInteraction(const URL&);
-    WEBCORE_EXPORT bool hasHadUserInteraction(const URL&);
-    WEBCORE_EXPORT void clearUserInteraction(const URL&);
-
-    WEBCORE_EXPORT void setPrevalentResource(const URL&);
-    WEBCORE_EXPORT bool isPrevalentResource(const URL&);
-    WEBCORE_EXPORT void clearPrevalentResource(const URL&);
-    WEBCORE_EXPORT void setGrandfathered(const URL&, bool value);
-    WEBCORE_EXPORT bool isGrandfathered(const URL&);
-    
-    WEBCORE_EXPORT void setSubframeUnderTopFrameOrigin(const URL& subframe, const URL& topFrame);
-    WEBCORE_EXPORT void setSubresourceUnderTopFrameOrigin(const URL& subresource, const URL& topFrame);
-    WEBCORE_EXPORT void setSubresourceUniqueRedirectTo(const URL& subresource, const URL& hostNameRedirectedTo);
-
-    WEBCORE_EXPORT void setTimeToLiveUserInteraction(Seconds);
-    WEBCORE_EXPORT void setTimeToLiveCookiePartitionFree(Seconds);
-    WEBCORE_EXPORT void setMinimumTimeBetweeenDataRecordsRemoval(Seconds);
-    WEBCORE_EXPORT void setReducedTimestampResolution(Seconds);
-    WEBCORE_EXPORT void setGrandfatheringTime(Seconds);
-    
-    WEBCORE_EXPORT void fireDataModificationHandler();
-    WEBCORE_EXPORT void fireShouldPartitionCookiesHandler();
-    WEBCORE_EXPORT void fireShouldPartitionCookiesHandler(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool clearFirst);
-    WEBCORE_EXPORT void fireTelemetryHandler();
-
     WEBCORE_EXPORT void setStatisticsStore(Ref<ResourceLoadStatisticsStore>&&);
     WEBCORE_EXPORT void setStatisticsQueue(Ref<WTF::WorkQueue>&&);
-    WEBCORE_EXPORT void clearInMemoryStore();
-    WEBCORE_EXPORT void clearInMemoryAndPersistentStore();
-    WEBCORE_EXPORT void clearInMemoryAndPersistentStore(std::chrono::system_clock::time_point modifiedSince);
 
     WEBCORE_EXPORT String statisticsForOrigin(const String&);
 
 private:
-    bool shouldLog(Page*);
-    static String primaryDomain(const URL&);
-    static String primaryDomain(const String& host);
+    bool shouldLog(Page*) const;
 
     RefPtr<ResourceLoadStatisticsStore> m_store;
     RefPtr<WTF::WorkQueue> m_queue;
index 437803e..c0ce171 100644 (file)
@@ -30,6 +30,7 @@
 #include "Logging.h"
 #include "NetworkStorageSession.h"
 #include "PlatformStrategies.h"
+#include "PublicSuffix.h"
 #include "ResourceLoadStatistics.h"
 #include "SharedBuffer.h"
 #include "URL.h"
@@ -465,5 +466,25 @@ WTF::RecursiveLockAdapter<Lock>& ResourceLoadStatisticsStore::statisticsLock()
 {
     return m_statisticsLock;
 }
+
+String ResourceLoadStatisticsStore::primaryDomain(const URL& url)
+{
+    return primaryDomain(url.host());
+}
+
+String ResourceLoadStatisticsStore::primaryDomain(const String& host)
+{
+    if (host.isNull() || host.isEmpty())
+        return ASCIILiteral("nullOrigin");
+
+#if ENABLE(PUBLIC_SUFFIX_LIST)
+    String primaryDomain = topPrivatelyControlledDomain(host);
+    // We will have an empty string here if there is no TLD. Use the host as a fallback.
+    if (!primaryDomain.isEmpty())
+        return primaryDomain;
+#endif
+
+    return host;
+}
     
 }
index 65a4eab..c50c3a5 100644 (file)
@@ -63,10 +63,10 @@ public:
     bool isEmpty() const { return m_resourceStatisticsMap.isEmpty(); }
     size_t size() const { return m_resourceStatisticsMap.size(); }
     WEBCORE_EXPORT void clearInMemory();
-    void clearInMemoryAndPersistent();
+    WEBCORE_EXPORT void clearInMemoryAndPersistent();
 
-    ResourceLoadStatistics& ensureResourceStatisticsForPrimaryDomain(const String&);
-    ResourceLoadStatistics takeResourceStatisticsForPrimaryDomain(const String&);
+    WEBCORE_EXPORT ResourceLoadStatistics& ensureResourceStatisticsForPrimaryDomain(const String&);
+    WEBCORE_EXPORT ResourceLoadStatistics takeResourceStatisticsForPrimaryDomain(const String&);
     void setResourceStatisticsForPrimaryDomain(const String&, ResourceLoadStatistics&&);
 
     bool isPrevalentResource(const String&) const;
@@ -81,14 +81,14 @@ public:
     WEBCORE_EXPORT void setGrandfatherExistingWebsiteDataCallback(WTF::Function<void()>&&);
     WEBCORE_EXPORT void setFireTelemetryCallback(WTF::Function<void()>&& handler);
 
-    void fireDataModificationHandler();
-    void fireTelemetryHandler();
-    void setTimeToLiveUserInteraction(Seconds);
-    void setTimeToLiveCookiePartitionFree(Seconds);
-    void setMinimumTimeBetweeenDataRecordsRemoval(Seconds);
-    void setGrandfatheringTime(Seconds);
+    WEBCORE_EXPORT void fireDataModificationHandler();
+    WEBCORE_EXPORT void fireTelemetryHandler();
+    WEBCORE_EXPORT void setTimeToLiveUserInteraction(Seconds);
+    WEBCORE_EXPORT void setTimeToLiveCookiePartitionFree(Seconds);
+    WEBCORE_EXPORT void setMinimumTimeBetweeenDataRecordsRemoval(Seconds);
+    WEBCORE_EXPORT void setGrandfatheringTime(Seconds);
     WEBCORE_EXPORT void fireShouldPartitionCookiesHandler();
-    void fireShouldPartitionCookiesHandler(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool clearFirst);
+    WEBCORE_EXPORT void fireShouldPartitionCookiesHandler(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool clearFirst);
 
     WEBCORE_EXPORT void processStatistics(WTF::Function<void(ResourceLoadStatistics&)>&&);
 
@@ -103,6 +103,10 @@ public:
     WEBCORE_EXPORT void dataRecordsWereRemoved();
     
     WEBCORE_EXPORT WTF::RecursiveLockAdapter<Lock>& statisticsLock();
+
+    WEBCORE_EXPORT static String primaryDomain(const URL&);
+    WEBCORE_EXPORT static String primaryDomain(const String& host);
+
 private:
     ResourceLoadStatisticsStore() = default;
 
index dacd84c..68d6285 100644 (file)
@@ -135,7 +135,7 @@ public:
     bool protocolIsData() const { return protocolIs("data"); }
     bool protocolIsInHTTPFamily() const;
     WEBCORE_EXPORT bool isLocalFile() const;
-    bool isBlankURL() const;
+    WEBCORE_EXPORT bool isBlankURL() const;
     bool cannotBeABaseURL() const { return m_cannotBeABaseURL; }
 
     WEBCORE_EXPORT bool setProtocol(const String&);
index 15e71f1..67d4477 100644 (file)
@@ -328,6 +328,7 @@ set(WebKit2_SOURCES
     UIProcess/WebProcessLifetimeTracker.cpp
     UIProcess/WebProcessPool.cpp
     UIProcess/WebProcessProxy.cpp
+    UIProcess/WebResourceLoadObserver.cpp
     UIProcess/WebURLSchemeHandler.cpp
     UIProcess/WebURLSchemeTask.cpp
     UIProcess/WebViewportAttributes.cpp
index 949275e..ae7eba0 100644 (file)
@@ -1,3 +1,69 @@
+2017-06-29  Chris Dumez  <cdumez@apple.com>
+
+        Split ResourceLoadObserver into 2 classes: one for WebCore and one for the UIProcess
+        https://bugs.webkit.org/show_bug.cgi?id=173990
+
+        Reviewed by Brent Fulgham.
+
+        Split ResourceLoadObserver into 2 classes: one for WebCore and one for the UIProcess.
+        They really have different API and there is therefore close to no code duplication.
+
+        * CMakeLists.txt:
+        * UIProcess/Cocoa/WebResourceLoadStatisticsManagerCocoa.mm:
+        (WebKit::WebResourceLoadStatisticsManager::registerUserDefaultsIfNeeded):
+        * UIProcess/WebResourceLoadObserver.cpp: Added.
+        (WebKit::primaryDomain):
+        (WebKit::WebResourceLoadObserver::sharedObserver):
+        (WebKit::WebResourceLoadObserver::setStatisticsStore):
+        (WebKit::WebResourceLoadObserver::setStatisticsQueue):
+        (WebKit::WebResourceLoadObserver::clearInMemoryStore):
+        (WebKit::WebResourceLoadObserver::clearInMemoryAndPersistentStore):
+        (WebKit::WebResourceLoadObserver::logUserInteraction):
+        (WebKit::WebResourceLoadObserver::clearUserInteraction):
+        (WebKit::WebResourceLoadObserver::hasHadUserInteraction):
+        (WebKit::WebResourceLoadObserver::setPrevalentResource):
+        (WebKit::WebResourceLoadObserver::isPrevalentResource):
+        (WebKit::WebResourceLoadObserver::clearPrevalentResource):
+        (WebKit::WebResourceLoadObserver::setGrandfathered):
+        (WebKit::WebResourceLoadObserver::isGrandfathered):
+        (WebKit::WebResourceLoadObserver::setSubframeUnderTopFrameOrigin):
+        (WebKit::WebResourceLoadObserver::setSubresourceUnderTopFrameOrigin):
+        (WebKit::WebResourceLoadObserver::setSubresourceUniqueRedirectTo):
+        (WebKit::WebResourceLoadObserver::setTimeToLiveUserInteraction):
+        (WebKit::WebResourceLoadObserver::setTimeToLiveCookiePartitionFree):
+        (WebKit::WebResourceLoadObserver::setMinimumTimeBetweeenDataRecordsRemoval):
+        (WebKit::WebResourceLoadObserver::setGrandfatheringTime):
+        (WebKit::WebResourceLoadObserver::fireDataModificationHandler):
+        (WebKit::WebResourceLoadObserver::fireShouldPartitionCookiesHandler):
+        (WebKit::WebResourceLoadObserver::fireTelemetryHandler):
+        * UIProcess/WebResourceLoadObserver.h: Added.
+        * UIProcess/WebResourceLoadStatisticsManager.cpp:
+        (WebKit::WebResourceLoadStatisticsManager::setPrevalentResource):
+        (WebKit::WebResourceLoadStatisticsManager::isPrevalentResource):
+        (WebKit::WebResourceLoadStatisticsManager::setHasHadUserInteraction):
+        (WebKit::WebResourceLoadStatisticsManager::hasHadUserInteraction):
+        (WebKit::WebResourceLoadStatisticsManager::setGrandfathered):
+        (WebKit::WebResourceLoadStatisticsManager::isGrandfathered):
+        (WebKit::WebResourceLoadStatisticsManager::setSubframeUnderTopFrameOrigin):
+        (WebKit::WebResourceLoadStatisticsManager::setSubresourceUnderTopFrameOrigin):
+        (WebKit::WebResourceLoadStatisticsManager::setSubresourceUniqueRedirectTo):
+        (WebKit::WebResourceLoadStatisticsManager::setTimeToLiveUserInteraction):
+        (WebKit::WebResourceLoadStatisticsManager::setTimeToLiveCookiePartitionFree):
+        (WebKit::WebResourceLoadStatisticsManager::setMinimumTimeBetweeenDataRecordsRemoval):
+        (WebKit::WebResourceLoadStatisticsManager::setGrandfatheringTime):
+        (WebKit::WebResourceLoadStatisticsManager::fireDataModificationHandler):
+        (WebKit::WebResourceLoadStatisticsManager::fireShouldPartitionCookiesHandler):
+        (WebKit::WebResourceLoadStatisticsManager::fireShouldPartitionCookiesHandlerForOneDomain):
+        (WebKit::WebResourceLoadStatisticsManager::fireTelemetryHandler):
+        (WebKit::WebResourceLoadStatisticsManager::clearInMemoryAndPersistentStore):
+        (WebKit::WebResourceLoadStatisticsManager::clearInMemoryAndPersistentStoreModifiedSinceHours):
+        (WebKit::WebResourceLoadStatisticsManager::resetToConsistentState):
+        * UIProcess/WebResourceLoadStatisticsStore.cpp:
+        (WebKit::WebResourceLoadStatisticsStore::registerSharedResourceLoadObserver):
+        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
+        (WebKit::WebsiteDataStore::removeData):
+        * WebKit2.xcodeproj/project.pbxproj:
+
 2017-06-29  Sam Weinig  <sam@webkit.org>
 
         [WebIDL] Remove custom binding for UserMessageHandlersNamespace
index be1d954..351e7b1 100644 (file)
@@ -27,7 +27,7 @@
 #import "WebResourceLoadStatisticsManager.h"
 
 #import "WebPreferencesKeys.h"
-#import <WebCore/ResourceLoadObserver.h>
+#import "WebResourceLoadObserver.h"
 
 using namespace WebCore;
 
@@ -43,19 +43,15 @@ void WebResourceLoadStatisticsManager::registerUserDefaultsIfNeeded()
         
         double timeToLiveUserInteraction = [[NSUserDefaults standardUserDefaults] doubleForKey: WebPreferencesKey::resourceLoadStatisticsTimeToLiveUserInteractionKey()];
         if (timeToLiveUserInteraction > 0 && timeToLiveUserInteraction <= 30 * dayInSeconds)
-            ResourceLoadObserver::sharedObserver().setTimeToLiveUserInteraction(Seconds { timeToLiveUserInteraction });
+            WebResourceLoadObserver::sharedObserver().setTimeToLiveUserInteraction(Seconds { timeToLiveUserInteraction });
         
         double timeToLiveCookiePartitionFree = [[NSUserDefaults standardUserDefaults] doubleForKey: WebPreferencesKey::resourceLoadStatisticsTimeToLiveCookiePartitionFreeKey()];
         if (timeToLiveCookiePartitionFree > 0 && timeToLiveCookiePartitionFree <= dayInSeconds)
-            ResourceLoadObserver::sharedObserver().setTimeToLiveCookiePartitionFree(Seconds { timeToLiveCookiePartitionFree });
-        
-        double reducedTimestampResolution = [[NSUserDefaults standardUserDefaults] doubleForKey: WebPreferencesKey::resourceLoadStatisticsReducedTimestampResolutionKey()];
-        if (reducedTimestampResolution > 0 && reducedTimestampResolution <= hourInSeconds)
-            ResourceLoadObserver::sharedObserver().setReducedTimestampResolution(Seconds { reducedTimestampResolution });
+            WebResourceLoadObserver::sharedObserver().setTimeToLiveCookiePartitionFree(Seconds { timeToLiveCookiePartitionFree });
 
         double grandfatheringTime = [[NSUserDefaults standardUserDefaults] doubleForKey: WebPreferencesKey::resourceLoadStatisticsGrandfatheringTimeKey()];
         if (grandfatheringTime > 0 && grandfatheringTime <= 7 * dayInSeconds)
-            ResourceLoadObserver::sharedObserver().setGrandfatheringTime(Seconds { grandfatheringTime });
+            WebResourceLoadObserver::sharedObserver().setGrandfatheringTime(Seconds { grandfatheringTime });
     });
 }
 
diff --git a/Source/WebKit2/UIProcess/WebResourceLoadObserver.cpp b/Source/WebKit2/UIProcess/WebResourceLoadObserver.cpp
new file mode 100644 (file)
index 0000000..926f01c
--- /dev/null
@@ -0,0 +1,282 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebResourceLoadObserver.h"
+
+#include <WebCore/ResourceLoadStatisticsStore.h>
+#include <WebCore/URL.h>
+#include <wtf/CrossThreadCopier.h>
+#include <wtf/NeverDestroyed.h>
+#include <wtf/RunLoop.h>
+#include <wtf/WorkQueue.h>
+
+namespace WebKit {
+
+using namespace WebCore;
+
+template<typename T> static inline String primaryDomain(const T& value)
+{
+    return ResourceLoadStatisticsStore::primaryDomain(value);
+}
+
+WebResourceLoadObserver& WebResourceLoadObserver::sharedObserver()
+{
+    static NeverDestroyed<WebResourceLoadObserver> WebResourceLoadObserver;
+    return WebResourceLoadObserver;
+}
+
+void WebResourceLoadObserver::setStatisticsStore(Ref<ResourceLoadStatisticsStore>&& store)
+{
+    if (m_store && m_queue)
+        m_queue = nullptr;
+    m_store = WTFMove(store);
+}
+
+void WebResourceLoadObserver::setStatisticsQueue(Ref<WTF::WorkQueue>&& queue)
+{
+    ASSERT(!m_queue);
+    m_queue = WTFMove(queue);
+}
+
+void WebResourceLoadObserver::clearInMemoryStore()
+{
+    if (!m_store)
+        return;
+
+    ASSERT(m_queue);
+    m_queue->dispatch([this] {
+        m_store->clearInMemory();
+    });
+}
+
+void WebResourceLoadObserver::clearInMemoryAndPersistentStore()
+{
+    if (!m_store)
+        return;
+
+    ASSERT(m_queue);
+    m_queue->dispatch([this] {
+        m_store->clearInMemoryAndPersistent();
+    });
+}
+
+void WebResourceLoadObserver::clearInMemoryAndPersistentStore(std::chrono::system_clock::time_point modifiedSince)
+{
+    // For now, be conservative and clear everything regardless of modifiedSince
+    UNUSED_PARAM(modifiedSince);
+    clearInMemoryAndPersistentStore();
+}
+
+void WebResourceLoadObserver::logUserInteraction(const URL& url)
+{
+    if (url.isBlankURL() || url.isEmpty())
+        return;
+
+    ASSERT(m_queue);
+    m_queue->dispatch([this, primaryDomainString = primaryDomain(url).isolatedCopy()] {
+        {
+            auto locker = holdLock(m_store->statisticsLock());
+            auto& statistics = m_store->ensureResourceStatisticsForPrimaryDomain(primaryDomainString);
+            statistics.hadUserInteraction = true;
+            statistics.mostRecentUserInteractionTime = WallTime::now();
+        }
+
+        m_store->fireShouldPartitionCookiesHandler({ primaryDomainString }, { }, false);
+    });
+}
+
+void WebResourceLoadObserver::clearUserInteraction(const URL& url)
+{
+    if (url.isBlankURL() || url.isEmpty())
+        return;
+
+    auto locker = holdLock(m_store->statisticsLock());
+    auto& statistics = m_store->ensureResourceStatisticsForPrimaryDomain(primaryDomain(url));
+
+    statistics.hadUserInteraction = false;
+    statistics.mostRecentUserInteractionTime = { };
+}
+
+bool WebResourceLoadObserver::hasHadUserInteraction(const URL& url)
+{
+    if (url.isBlankURL() || url.isEmpty())
+        return false;
+
+    auto locker = holdLock(m_store->statisticsLock());
+    auto& statistics = m_store->ensureResourceStatisticsForPrimaryDomain(primaryDomain(url));
+
+    return m_store->hasHadRecentUserInteraction(statistics);
+}
+
+void WebResourceLoadObserver::setPrevalentResource(const URL& url)
+{
+    if (url.isBlankURL() || url.isEmpty())
+        return;
+
+    auto locker = holdLock(m_store->statisticsLock());
+    auto& statistics = m_store->ensureResourceStatisticsForPrimaryDomain(primaryDomain(url));
+
+    statistics.isPrevalentResource = true;
+}
+
+bool WebResourceLoadObserver::isPrevalentResource(const URL& url)
+{
+    if (url.isBlankURL() || url.isEmpty())
+        return false;
+
+    auto locker = holdLock(m_store->statisticsLock());
+    auto& statistics = m_store->ensureResourceStatisticsForPrimaryDomain(primaryDomain(url));
+
+    return statistics.isPrevalentResource;
+}
+
+void WebResourceLoadObserver::clearPrevalentResource(const URL& url)
+{
+    if (url.isBlankURL() || url.isEmpty())
+        return;
+
+    auto locker = holdLock(m_store->statisticsLock());
+    auto& statistics = m_store->ensureResourceStatisticsForPrimaryDomain(primaryDomain(url));
+
+    statistics.isPrevalentResource = false;
+}
+
+void WebResourceLoadObserver::setGrandfathered(const URL& url, bool value)
+{
+    if (url.isBlankURL() || url.isEmpty())
+        return;
+
+    auto locker = holdLock(m_store->statisticsLock());
+    auto& statistics = m_store->ensureResourceStatisticsForPrimaryDomain(primaryDomain(url));
+
+    statistics.grandfathered = value;
+}
+
+bool WebResourceLoadObserver::isGrandfathered(const URL& url)
+{
+    if (url.isBlankURL() || url.isEmpty())
+        return false;
+
+    auto locker = holdLock(m_store->statisticsLock());
+    auto& statistics = m_store->ensureResourceStatisticsForPrimaryDomain(primaryDomain(url));
+
+    return statistics.grandfathered;
+}
+
+void WebResourceLoadObserver::setSubframeUnderTopFrameOrigin(const URL& subframe, const URL& topFrame)
+{
+    if (subframe.isBlankURL() || subframe.isEmpty() || topFrame.isBlankURL() || topFrame.isEmpty())
+        return;
+
+    ASSERT(m_queue);
+    m_queue->dispatch([this, primaryTopFrameDomainString = primaryDomain(topFrame).isolatedCopy(), primarySubFrameDomainString = primaryDomain(subframe).isolatedCopy()] {
+        auto locker = holdLock(m_store->statisticsLock());
+        auto& statistics = m_store->ensureResourceStatisticsForPrimaryDomain(primarySubFrameDomainString);
+        statistics.subframeUnderTopFrameOrigins.add(primaryTopFrameDomainString);
+    });
+}
+
+void WebResourceLoadObserver::setSubresourceUnderTopFrameOrigin(const URL& subresource, const URL& topFrame)
+{
+    if (subresource.isBlankURL() || subresource.isEmpty() || topFrame.isBlankURL() || topFrame.isEmpty())
+        return;
+
+    ASSERT(m_queue);
+    m_queue->dispatch([this, primaryTopFrameDomainString = primaryDomain(topFrame).isolatedCopy(), primarySubresourceDomainString = primaryDomain(subresource).isolatedCopy()] {
+        auto locker = holdLock(m_store->statisticsLock());
+        auto& statistics = m_store->ensureResourceStatisticsForPrimaryDomain(primarySubresourceDomainString);
+        statistics.subresourceUnderTopFrameOrigins.add(primaryTopFrameDomainString);
+    });
+}
+
+void WebResourceLoadObserver::setSubresourceUniqueRedirectTo(const URL& subresource, const URL& hostNameRedirectedTo)
+{
+    if (subresource.isBlankURL() || subresource.isEmpty() || hostNameRedirectedTo.isBlankURL() || hostNameRedirectedTo.isEmpty())
+        return;
+
+    ASSERT(m_queue);
+    m_queue->dispatch([this, primaryRedirectDomainString = primaryDomain(hostNameRedirectedTo).isolatedCopy(), primarySubresourceDomainString = primaryDomain(subresource).isolatedCopy()] {
+        auto locker = holdLock(m_store->statisticsLock());
+        auto& statistics = m_store->ensureResourceStatisticsForPrimaryDomain(primarySubresourceDomainString);
+        statistics.subresourceUniqueRedirectsTo.add(primaryRedirectDomainString);
+    });
+}
+
+void WebResourceLoadObserver::setTimeToLiveUserInteraction(Seconds seconds)
+{
+    m_store->setTimeToLiveUserInteraction(seconds);
+}
+
+void WebResourceLoadObserver::setTimeToLiveCookiePartitionFree(Seconds seconds)
+{
+    m_store->setTimeToLiveCookiePartitionFree(seconds);
+}
+
+void WebResourceLoadObserver::setMinimumTimeBetweeenDataRecordsRemoval(Seconds seconds)
+{
+    m_store->setMinimumTimeBetweeenDataRecordsRemoval(seconds);
+}
+
+void WebResourceLoadObserver::setGrandfatheringTime(Seconds seconds)
+{
+    m_store->setMinimumTimeBetweeenDataRecordsRemoval(seconds);
+}
+
+void WebResourceLoadObserver::fireDataModificationHandler()
+{
+    // Helper function used by testing system. Should only be called from the main thread.
+    ASSERT(RunLoop::isMain());
+    m_queue->dispatch([this] {
+        m_store->fireDataModificationHandler();
+    });
+}
+
+void WebResourceLoadObserver::fireShouldPartitionCookiesHandler()
+{
+    // Helper function used by testing system. Should only be called from the main thread.
+    ASSERT(RunLoop::isMain());
+    m_queue->dispatch([this] {
+        m_store->fireShouldPartitionCookiesHandler();
+    });
+}
+
+void WebResourceLoadObserver::fireShouldPartitionCookiesHandler(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool clearFirst)
+{
+    // Helper function used by testing system. Should only be called from the main thread.
+    ASSERT(RunLoop::isMain());
+    m_queue->dispatch([this, domainsToRemove = CrossThreadCopier<Vector<String>>::copy(domainsToRemove), domainsToAdd = CrossThreadCopier<Vector<String>>::copy(domainsToAdd), clearFirst] {
+        m_store->fireShouldPartitionCookiesHandler(domainsToRemove, domainsToAdd, clearFirst);
+    });
+}
+
+void WebResourceLoadObserver::fireTelemetryHandler()
+{
+    // Helper function used by testing system. Should only be called from the main thread.
+    ASSERT(RunLoop::isMain());
+    m_store->fireTelemetryHandler();
+}
+
+} // namespace WebKit
diff --git a/Source/WebKit2/UIProcess/WebResourceLoadObserver.h b/Source/WebKit2/UIProcess/WebResourceLoadObserver.h
new file mode 100644 (file)
index 0000000..ec107b2
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <WebCore/ResourceLoadStatisticsStore.h>
+#include <wtf/text/WTFString.h>
+
+namespace WTF {
+class WorkQueue;
+}
+
+namespace WebCore {
+class URL;
+}
+
+namespace WebKit {
+
+class WebResourceLoadObserver {
+    friend class NeverDestroyed<WebResourceLoadObserver>;
+public:
+    static WebResourceLoadObserver& sharedObserver();
+
+    void logUserInteraction(const WebCore::URL&);
+    bool hasHadUserInteraction(const WebCore::URL&);
+    void clearUserInteraction(const WebCore::URL&);
+
+    void setPrevalentResource(const WebCore::URL&);
+    bool isPrevalentResource(const WebCore::URL&);
+    void clearPrevalentResource(const WebCore::URL&);
+    void setGrandfathered(const WebCore::URL&, bool value);
+    bool isGrandfathered(const WebCore::URL&);
+
+    void setSubframeUnderTopFrameOrigin(const WebCore::URL& subframe, const WebCore::URL& topFrame);
+    void setSubresourceUnderTopFrameOrigin(const WebCore::URL& subresource, const WebCore::URL& topFrame);
+    void setSubresourceUniqueRedirectTo(const WebCore::URL& subresource, const WebCore::URL& hostNameRedirectedTo);
+
+    void setTimeToLiveUserInteraction(Seconds);
+    void setTimeToLiveCookiePartitionFree(Seconds);
+    void setMinimumTimeBetweeenDataRecordsRemoval(Seconds);
+    void setGrandfatheringTime(Seconds);
+
+    void fireDataModificationHandler();
+    void fireShouldPartitionCookiesHandler();
+    void fireShouldPartitionCookiesHandler(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool clearFirst);
+    void fireTelemetryHandler();
+
+    void setStatisticsStore(Ref<WebCore::ResourceLoadStatisticsStore>&&);
+    void setStatisticsQueue(Ref<WTF::WorkQueue>&&);
+    void clearInMemoryStore();
+    void clearInMemoryAndPersistentStore();
+    void clearInMemoryAndPersistentStore(std::chrono::system_clock::time_point modifiedSince);
+
+private:
+    RefPtr<WebCore::ResourceLoadStatisticsStore> m_store;
+    RefPtr<WTF::WorkQueue> m_queue;
+};
+
+} // namespace WebKit
index 975f311..871738f 100644 (file)
@@ -27,8 +27,8 @@
 #include "WebResourceLoadStatisticsManager.h"
 
 #include "Logging.h"
+#include "WebResourceLoadObserver.h"
 #include "WebResourceLoadStatisticsStore.h"
-#include <WebCore/ResourceLoadObserver.h>
 #include <WebCore/URL.h>
 
 using namespace WebCore;
@@ -38,95 +38,95 @@ namespace WebKit {
 void WebResourceLoadStatisticsManager::setPrevalentResource(const String& hostName, bool value)
 {
     if (value)
-        WebCore::ResourceLoadObserver::sharedObserver().setPrevalentResource(URL(URL(), hostName));
+        WebResourceLoadObserver::sharedObserver().setPrevalentResource(URL(URL(), hostName));
     else
-        WebCore::ResourceLoadObserver::sharedObserver().clearPrevalentResource(URL(URL(), hostName));
+        WebResourceLoadObserver::sharedObserver().clearPrevalentResource(URL(URL(), hostName));
 }
 
 bool WebResourceLoadStatisticsManager::isPrevalentResource(const String& hostName)
 {
-    return WebCore::ResourceLoadObserver::sharedObserver().isPrevalentResource(URL(URL(), hostName));
+    return WebResourceLoadObserver::sharedObserver().isPrevalentResource(URL(URL(), hostName));
 }
     
 void WebResourceLoadStatisticsManager::setHasHadUserInteraction(const String& hostName, bool value)
 {
     if (value)
-        WebCore::ResourceLoadObserver::sharedObserver().logUserInteraction(URL(URL(), hostName));
+        WebResourceLoadObserver::sharedObserver().logUserInteraction(URL(URL(), hostName));
     else
-        WebCore::ResourceLoadObserver::sharedObserver().clearUserInteraction(URL(URL(), hostName));
+        WebResourceLoadObserver::sharedObserver().clearUserInteraction(URL(URL(), hostName));
 }
 
 bool WebResourceLoadStatisticsManager::hasHadUserInteraction(const String& hostName)
 {
-    return WebCore::ResourceLoadObserver::sharedObserver().hasHadUserInteraction(URL(URL(), hostName));
+    return WebResourceLoadObserver::sharedObserver().hasHadUserInteraction(URL(URL(), hostName));
 }
 
 void WebResourceLoadStatisticsManager::setGrandfathered(const String& hostName, bool value)
 {
-    WebCore::ResourceLoadObserver::sharedObserver().setGrandfathered(URL(URL(), hostName), value);
+    WebResourceLoadObserver::sharedObserver().setGrandfathered(URL(URL(), hostName), value);
 }
 
 bool WebResourceLoadStatisticsManager::isGrandfathered(const String& hostName)
 {
-    return WebCore::ResourceLoadObserver::sharedObserver().isGrandfathered(URL(URL(), hostName));
+    return WebResourceLoadObserver::sharedObserver().isGrandfathered(URL(URL(), hostName));
 }
 
 void WebResourceLoadStatisticsManager::setSubframeUnderTopFrameOrigin(const String& hostName, const String& topFrameHostName)
 {
-    WebCore::ResourceLoadObserver::sharedObserver().setSubframeUnderTopFrameOrigin(URL(URL(), hostName), URL(URL(), topFrameHostName));
+    WebResourceLoadObserver::sharedObserver().setSubframeUnderTopFrameOrigin(URL(URL(), hostName), URL(URL(), topFrameHostName));
 }
 
 void WebResourceLoadStatisticsManager::setSubresourceUnderTopFrameOrigin(const String& hostName, const String& topFrameHostName)
 {
-    WebCore::ResourceLoadObserver::sharedObserver().setSubresourceUnderTopFrameOrigin(URL(URL(), hostName), URL(URL(), topFrameHostName));
+    WebResourceLoadObserver::sharedObserver().setSubresourceUnderTopFrameOrigin(URL(URL(), hostName), URL(URL(), topFrameHostName));
 }
 
 void WebResourceLoadStatisticsManager::setSubresourceUniqueRedirectTo(const String& hostName, const String& hostNameRedirectedTo)
 {
-    WebCore::ResourceLoadObserver::sharedObserver().setSubresourceUniqueRedirectTo(URL(URL(), hostName), URL(URL(), hostNameRedirectedTo));
+    WebResourceLoadObserver::sharedObserver().setSubresourceUniqueRedirectTo(URL(URL(), hostName), URL(URL(), hostNameRedirectedTo));
 }
 
 void WebResourceLoadStatisticsManager::setTimeToLiveUserInteraction(Seconds seconds)
 {
-    WebCore::ResourceLoadObserver::sharedObserver().setTimeToLiveUserInteraction(seconds);
+    WebResourceLoadObserver::sharedObserver().setTimeToLiveUserInteraction(seconds);
 }
 
 void WebResourceLoadStatisticsManager::setTimeToLiveCookiePartitionFree(Seconds seconds)
 {
-    WebCore::ResourceLoadObserver::sharedObserver().setTimeToLiveCookiePartitionFree(seconds);
+    WebResourceLoadObserver::sharedObserver().setTimeToLiveCookiePartitionFree(seconds);
 }
 
 void WebResourceLoadStatisticsManager::setMinimumTimeBetweeenDataRecordsRemoval(Seconds seconds)
 {
-    WebCore::ResourceLoadObserver::sharedObserver().setMinimumTimeBetweeenDataRecordsRemoval(seconds);
+    WebResourceLoadObserver::sharedObserver().setMinimumTimeBetweeenDataRecordsRemoval(seconds);
 }
 
 void WebResourceLoadStatisticsManager::setGrandfatheringTime(Seconds seconds)
 {
-    WebCore::ResourceLoadObserver::sharedObserver().setGrandfatheringTime(seconds);
+    WebResourceLoadObserver::sharedObserver().setGrandfatheringTime(seconds);
 }
 
 void WebResourceLoadStatisticsManager::fireDataModificationHandler()
 {
-    WebCore::ResourceLoadObserver::sharedObserver().fireDataModificationHandler();
+    WebResourceLoadObserver::sharedObserver().fireDataModificationHandler();
 }
 
 void WebResourceLoadStatisticsManager::fireShouldPartitionCookiesHandler()
 {
-    WebCore::ResourceLoadObserver::sharedObserver().fireShouldPartitionCookiesHandler();
+    WebResourceLoadObserver::sharedObserver().fireShouldPartitionCookiesHandler();
 }
 
 void WebResourceLoadStatisticsManager::fireShouldPartitionCookiesHandlerForOneDomain(const String& hostName, bool value)
 {
     if (value)
-        WebCore::ResourceLoadObserver::sharedObserver().fireShouldPartitionCookiesHandler({ }, {hostName}, false);
+        WebResourceLoadObserver::sharedObserver().fireShouldPartitionCookiesHandler({ }, {hostName}, false);
     else
-        WebCore::ResourceLoadObserver::sharedObserver().fireShouldPartitionCookiesHandler({hostName}, { }, false);
+        WebResourceLoadObserver::sharedObserver().fireShouldPartitionCookiesHandler({hostName}, { }, false);
 }
 
 void WebResourceLoadStatisticsManager::fireTelemetryHandler()
 {
-    WebCore::ResourceLoadObserver::sharedObserver().fireTelemetryHandler();
+    WebResourceLoadObserver::sharedObserver().fireTelemetryHandler();
 }
     
 void WebResourceLoadStatisticsManager::setNotifyPagesWhenDataRecordsWereScanned(bool value)
@@ -151,24 +151,24 @@ void WebResourceLoadStatisticsManager::setShouldClassifyResourcesBeforeDataRecor
 
 void WebResourceLoadStatisticsManager::clearInMemoryAndPersistentStore()
 {
-    WebCore::ResourceLoadObserver::sharedObserver().clearInMemoryAndPersistentStore();
+    WebResourceLoadObserver::sharedObserver().clearInMemoryAndPersistentStore();
 }
 
 void WebResourceLoadStatisticsManager::clearInMemoryAndPersistentStoreModifiedSinceHours(unsigned hours)
 {
-    WebCore::ResourceLoadObserver::sharedObserver().clearInMemoryAndPersistentStore(std::chrono::system_clock::now() - std::chrono::hours(hours));
+    WebResourceLoadObserver::sharedObserver().clearInMemoryAndPersistentStore(std::chrono::system_clock::now() - std::chrono::hours(hours));
 }
     
 void WebResourceLoadStatisticsManager::resetToConsistentState()
 {
-    WebCore::ResourceLoadObserver::sharedObserver().setTimeToLiveUserInteraction(24_h * 30.);
-    WebCore::ResourceLoadObserver::sharedObserver().setTimeToLiveCookiePartitionFree(24_h);
-    WebCore::ResourceLoadObserver::sharedObserver().setMinimumTimeBetweeenDataRecordsRemoval(1_h);
-    WebCore::ResourceLoadObserver::sharedObserver().setGrandfatheringTime(1_h);
+    WebResourceLoadObserver::sharedObserver().setTimeToLiveUserInteraction(24_h * 30.);
+    WebResourceLoadObserver::sharedObserver().setTimeToLiveCookiePartitionFree(24_h);
+    WebResourceLoadObserver::sharedObserver().setMinimumTimeBetweeenDataRecordsRemoval(1_h);
+    WebResourceLoadObserver::sharedObserver().setGrandfatheringTime(1_h);
     WebResourceLoadStatisticsStore::setNotifyPagesWhenDataRecordsWereScanned(false);
     WebResourceLoadStatisticsTelemetry::setNotifyPagesWhenTelemetryWasCaptured(false);
     WebResourceLoadStatisticsStore::setShouldClassifyResourcesBeforeDataRecordsRemoval(true);
-    WebCore::ResourceLoadObserver::sharedObserver().clearInMemoryStore();
+    WebResourceLoadObserver::sharedObserver().clearInMemoryStore();
 }
     
 } // namespace WebKit
index 64e6070..91e6d04 100644 (file)
@@ -30,6 +30,7 @@
 #include "WebProcessMessages.h"
 #include "WebProcessPool.h"
 #include "WebProcessProxy.h"
+#include "WebResourceLoadObserver.h"
 #include "WebResourceLoadStatisticsManager.h"
 #include "WebResourceLoadStatisticsStoreMessages.h"
 #include "WebsiteDataFetchOption.h"
@@ -37,7 +38,6 @@
 #include <WebCore/FileMonitor.h>
 #include <WebCore/FileSystem.h>
 #include <WebCore/KeyedCoding.h>
-#include <WebCore/ResourceLoadObserver.h>
 #include <WebCore/ResourceLoadStatistics.h>
 #include <wtf/CrossThreadCopier.h>
 #include <wtf/MainThread.h>
@@ -210,8 +210,8 @@ void WebResourceLoadStatisticsStore::registerSharedResourceLoadObserver()
 {
     ASSERT(RunLoop::isMain());
     
-    ResourceLoadObserver::sharedObserver().setStatisticsStore(m_resourceLoadStatisticsStore.copyRef());
-    ResourceLoadObserver::sharedObserver().setStatisticsQueue(m_statisticsQueue.copyRef());
+    WebResourceLoadObserver::sharedObserver().setStatisticsStore(m_resourceLoadStatisticsStore.copyRef());
+    WebResourceLoadObserver::sharedObserver().setStatisticsQueue(m_statisticsQueue.copyRef());
     m_resourceLoadStatisticsStore->setNotificationCallback([this, protectedThis = makeRef(*this)] {
         if (m_resourceLoadStatisticsStore->isEmpty())
             return;
index e6bacbf..083c74f 100644 (file)
@@ -34,6 +34,7 @@
 #include "WebCookieManagerProxy.h"
 #include "WebProcessMessages.h"
 #include "WebProcessPool.h"
+#include "WebResourceLoadObserver.h"
 #include "WebResourceLoadStatisticsStore.h"
 #include "WebResourceLoadStatisticsStoreMessages.h"
 #include "WebsiteData.h"
@@ -43,7 +44,6 @@
 #include <WebCore/FileSystem.h>
 #include <WebCore/HTMLMediaElement.h>
 #include <WebCore/OriginLock.h>
-#include <WebCore/ResourceLoadObserver.h>
 #include <WebCore/SecurityOrigin.h>
 #include <WebCore/SecurityOriginData.h>
 #include <wtf/CrossThreadCopier.h>
@@ -816,7 +816,7 @@ void WebsiteDataStore::removeData(OptionSet<WebsiteDataType> dataTypes, std::chr
 #endif
 
     if (dataTypes.contains(WebsiteDataType::ResourceLoadStatistics))
-        WebCore::ResourceLoadObserver::sharedObserver().clearInMemoryAndPersistentStore(modifiedSince);
+        WebResourceLoadObserver::sharedObserver().clearInMemoryAndPersistentStore(modifiedSince);
 
     // There's a chance that we don't have any pending callbacks. If so, we want to dispatch the completion handler right away.
     callbackAggregator->callIfNeeded();
@@ -1085,7 +1085,7 @@ void WebsiteDataStore::removeData(OptionSet<WebsiteDataType> dataTypes, const Ve
 #endif
 
     if (dataTypes.contains(WebsiteDataType::ResourceLoadStatistics))
-        WebCore::ResourceLoadObserver::sharedObserver().clearInMemoryAndPersistentStore();
+        WebResourceLoadObserver::sharedObserver().clearInMemoryAndPersistentStore();
 
     // There's a chance that we don't have any pending callbacks. If so, we want to dispatch the completion handler right away.
     callbackAggregator->callIfNeeded();
index c75dc78..cbf2e28 100644 (file)
                41FAF5F81E3C1021001AE678 /* LibWebRTCResolver.h in Headers */ = {isa = PBXBuildFile; fileRef = 41FAF5F61E3C0B47001AE678 /* LibWebRTCResolver.h */; };
                41FAF5F91E3C1025001AE678 /* LibWebRTCResolver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41FAF5F71E3C0B47001AE678 /* LibWebRTCResolver.cpp */; };
                4450AEC01DC3FAE5009943F2 /* SharedMemoryCocoa.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4450AEBF1DC3FAE5009943F2 /* SharedMemoryCocoa.cpp */; };
+               46343B3A1F0599230003F309 /* WebResourceLoadObserver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4646AB321F0598D4009D07FC /* WebResourceLoadObserver.cpp */; };
+               46343B3B1F0599260003F309 /* WebResourceLoadObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = 4646AB331F0598D4009D07FC /* WebResourceLoadObserver.h */; };
                463FD4801EB9459600A2982C /* WKProcessTerminationReason.h in Headers */ = {isa = PBXBuildFile; fileRef = 463FD47F1EB9458400A2982C /* WKProcessTerminationReason.h */; settings = {ATTRIBUTES = (Private, ); }; };
                463FD4821EB94EC000A2982C /* ProcessTerminationReason.h in Headers */ = {isa = PBXBuildFile; fileRef = 463FD4811EB94EAD00A2982C /* ProcessTerminationReason.h */; };
                465250E61ECF52DC002025CB /* WebKit2InitializeCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 465250E51ECF52CD002025CB /* WebKit2InitializeCocoa.mm */; };
                4450AEBF1DC3FAE5009943F2 /* SharedMemoryCocoa.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SharedMemoryCocoa.cpp; path = cocoa/SharedMemoryCocoa.cpp; sourceTree = "<group>"; };
                463FD47F1EB9458400A2982C /* WKProcessTerminationReason.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKProcessTerminationReason.h; sourceTree = "<group>"; };
                463FD4811EB94EAD00A2982C /* ProcessTerminationReason.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProcessTerminationReason.h; sourceTree = "<group>"; };
+               4646AB321F0598D4009D07FC /* WebResourceLoadObserver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebResourceLoadObserver.cpp; sourceTree = "<group>"; };
+               4646AB331F0598D4009D07FC /* WebResourceLoadObserver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebResourceLoadObserver.h; sourceTree = "<group>"; };
                465250E51ECF52CD002025CB /* WebKit2InitializeCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebKit2InitializeCocoa.mm; sourceTree = "<group>"; };
                46A2B6061E5675A200C3DEDA /* BackgroundProcessResponsivenessTimer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BackgroundProcessResponsivenessTimer.cpp; sourceTree = "<group>"; };
                46A2B6071E5675A200C3DEDA /* BackgroundProcessResponsivenessTimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BackgroundProcessResponsivenessTimer.h; sourceTree = "<group>"; };
                                BC111B0D112F5E4F00337BAB /* WebProcessProxy.cpp */,
                                BC032DCF10F4389F0058C15A /* WebProcessProxy.h */,
                                BCEE7AB312817095009827DA /* WebProcessProxy.messages.in */,
+                               4646AB321F0598D4009D07FC /* WebResourceLoadObserver.cpp */,
+                               4646AB331F0598D4009D07FC /* WebResourceLoadObserver.h */,
                                6BE969A11E43B8A4008B7483 /* WebResourceLoadStatisticsManager.cpp */,
                                6BE9699F1E43B86E008B7483 /* WebResourceLoadStatisticsManager.h */,
                                7A9CD8C01C77984900D9F6C7 /* WebResourceLoadStatisticsStore.cpp */,
                                0F5947A8187B517600437857 /* RemoteScrollingCoordinatorMessages.h in Headers */,
                                0F59479B187B3B6000437857 /* RemoteScrollingCoordinatorProxy.h in Headers */,
                                0F5947A4187B3B7D00437857 /* RemoteScrollingCoordinatorTransaction.h in Headers */,
+                               46343B3B1F0599260003F309 /* WebResourceLoadObserver.h in Headers */,
                                0F59479D187B3B6000437857 /* RemoteScrollingTree.h in Headers */,
                                A55BA81F1BA25B27007CD33D /* RemoteWebInspectorProxy.h in Headers */,
                                A55BA8251BA25CFB007CD33D /* RemoteWebInspectorProxyMessages.h in Headers */,
                                C0337DAE127A24FE008FF4F4 /* WebEvent.cpp in Sources */,
                                BC032DBA10F4380F0058C15A /* WebEventConversion.cpp in Sources */,
                                BC111B5E112F629800337BAB /* WebEventFactory.mm in Sources */,
+                               46343B3A1F0599230003F309 /* WebResourceLoadObserver.cpp in Sources */,
                                BCE469531214E6CB000B98EB /* WebFormClient.cpp in Sources */,
                                BCE469551214E6CB000B98EB /* WebFormSubmissionListenerProxy.cpp in Sources */,
                                BC111ADD112F5B9300337BAB /* WebFrame.cpp in Sources */,