Replace ResourceLoadStatisticsStore C API with Cocoa SPI
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 1 Jul 2017 16:10:07 +0000 (16:10 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 1 Jul 2017 16:10:07 +0000 (16:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=174060

Reviewed by Brent Fulgham.

Source/WebKit2:

Replace ResourceLoadStatisticsStore C API by Cocoa SPI. The new Cocoa SPI is on
WKWebsiteDataStore, which allows us to get rid of the WebResourceLoadStatisticsManager
singleton as the SPI can now interact directly with the WebResourceLoadStatisticsStore.

* UIProcess/API/C/WKResourceLoadStatisticsManager.cpp: Removed.
* UIProcess/API/C/WKResourceLoadStatisticsManager.h: Removed.
Drop old C API.

* UIProcess/WebResourceLoadStatisticsManager.cpp: Removed.
* UIProcess/WebResourceLoadStatisticsManager.h: Removed.
Drop WebResourceLoadStatisticsManager singleton which was only required by the
C API. This is because the C API was global, rather than working on a specific
store.

* UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
* UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
Add new Cocoa SPI on WKWebsiteDataStore. This is only used for testing.

* UIProcess/WebResourceLoadStatisticsStore.cpp:
(WebKit::WebResourceLoadStatisticsStore::registerSharedResourceLoadObserver):
Stop registering the store with the WebResourceLoadStatisticsManager singleton,
as this singleton is gone.

* UIProcess/WebsiteData/WebsiteDataStore.h:
(WebKit::WebsiteDataStore::resourceLoadStatistics):
Add new getter to retrieve the WebResourceLoadStatisticsStore from the
WebsiteDataStore. This is needed by the new Cocoa SPI.

* WebKit2.xcodeproj/project.pbxproj:
Drop some files.

Tools:

Port WebKitTestRunner over to the new Cocoa SPI.

* WebKitTestRunner/InjectedBundle/TestRunner.cpp:
(WTR::TestRunner::setStatisticsNotifyPagesWhenDataRecordsWereScanned):
(WTR::TestRunner::setStatisticsNotifyPagesWhenTelemetryWasCaptured):
Drop calls to the WKResourceLoadStatisticsStore C API here. Those were
no-ops since this code runs in the WebContent process, not the
UIProcess.

* WebKitTestRunner/TestController.cpp:
* WebKitTestRunner/cocoa/TestControllerCocoa.mm:

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

18 files changed:
Source/WebKit2/CMakeLists.txt
Source/WebKit2/ChangeLog
Source/WebKit2/PlatformGTK.cmake
Source/WebKit2/PlatformMac.cmake
Source/WebKit2/PlatformWPE.cmake
Source/WebKit2/UIProcess/API/C/WKResourceLoadStatisticsManager.cpp [deleted file]
Source/WebKit2/UIProcess/API/C/WKResourceLoadStatisticsManager.h [deleted file]
Source/WebKit2/UIProcess/API/Cocoa/WKWebsiteDataStore.mm
Source/WebKit2/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h
Source/WebKit2/UIProcess/WebResourceLoadStatisticsManager.cpp [deleted file]
Source/WebKit2/UIProcess/WebResourceLoadStatisticsManager.h [deleted file]
Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.cpp
Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.h
Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
Tools/ChangeLog
Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp
Tools/WebKitTestRunner/TestController.cpp
Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm

index 3c12797..9df376e 100644 (file)
@@ -328,7 +328,6 @@ set(WebKit2_SOURCES
     UIProcess/WebProcessLifetimeTracker.cpp
     UIProcess/WebProcessPool.cpp
     UIProcess/WebProcessProxy.cpp
-    UIProcess/WebResourceLoadStatisticsManager.cpp
     UIProcess/WebURLSchemeHandler.cpp
     UIProcess/WebURLSchemeTask.cpp
     UIProcess/WebViewportAttributes.cpp
index 6508101..cfee27d 100644 (file)
@@ -1,3 +1,41 @@
+2017-07-01  Chris Dumez  <cdumez@apple.com>
+
+        Replace ResourceLoadStatisticsStore C API with Cocoa SPI
+        https://bugs.webkit.org/show_bug.cgi?id=174060
+
+        Reviewed by Brent Fulgham.
+
+        Replace ResourceLoadStatisticsStore C API by Cocoa SPI. The new Cocoa SPI is on
+        WKWebsiteDataStore, which allows us to get rid of the WebResourceLoadStatisticsManager
+        singleton as the SPI can now interact directly with the WebResourceLoadStatisticsStore.
+
+        * UIProcess/API/C/WKResourceLoadStatisticsManager.cpp: Removed.
+        * UIProcess/API/C/WKResourceLoadStatisticsManager.h: Removed.
+        Drop old C API.
+
+        * UIProcess/WebResourceLoadStatisticsManager.cpp: Removed.
+        * UIProcess/WebResourceLoadStatisticsManager.h: Removed.
+        Drop WebResourceLoadStatisticsManager singleton which was only required by the
+        C API. This is because the C API was global, rather than working on a specific
+        store.
+
+        * UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
+        * UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
+        Add new Cocoa SPI on WKWebsiteDataStore. This is only used for testing.
+
+        * UIProcess/WebResourceLoadStatisticsStore.cpp:
+        (WebKit::WebResourceLoadStatisticsStore::registerSharedResourceLoadObserver):
+        Stop registering the store with the WebResourceLoadStatisticsManager singleton,
+        as this singleton is gone.
+
+        * UIProcess/WebsiteData/WebsiteDataStore.h:
+        (WebKit::WebsiteDataStore::resourceLoadStatistics):
+        Add new getter to retrieve the WebResourceLoadStatisticsStore from the
+        WebsiteDataStore. This is needed by the new Cocoa SPI.
+
+        * WebKit2.xcodeproj/project.pbxproj:
+        Drop some files.
+
 2017-06-30  Megan Gardner  <megan_gardner@apple.com>
 
         Unreviewed mac build fix.
index 363777d..3423d3f 100644 (file)
@@ -107,14 +107,12 @@ list(APPEND WebKit2_SOURCES
     UIProcess/DefaultUndoController.cpp
     UIProcess/DrawingAreaProxyImpl.cpp
     UIProcess/LegacySessionStateCodingNone.cpp
-    UIProcess/WebResourceLoadStatisticsManager.cpp
     UIProcess/WebResourceLoadStatisticsStore.cpp
     UIProcess/WebResourceLoadStatisticsTelemetry.cpp
     UIProcess/WebTextChecker.cpp
     UIProcess/WebTextCheckerClient.cpp
 
     UIProcess/API/C/WKGrammarDetail.cpp
-    UIProcess/API/C/WKResourceLoadStatisticsManager.cpp
 
     UIProcess/API/C/cairo/WKIconDatabaseCairo.cpp
 
index 857c4e6..52c6d54 100644 (file)
@@ -165,7 +165,6 @@ list(APPEND WebKit2_SOURCES
     UIProcess/HighPerformanceGraphicsUsageSampler.cpp
     UIProcess/PerActivityStateCPUUsageSampler.cpp
     UIProcess/WebContextMenuListenerProxy.cpp
-    UIProcess/WebResourceLoadStatisticsManager.cpp
     UIProcess/WebResourceLoadStatisticsStore.cpp
     UIProcess/WebResourceLoadStatisticsTelemetry.cpp
 
@@ -179,8 +178,6 @@ list(APPEND WebKit2_SOURCES
     UIProcess/API/APIUserStyleSheet.cpp
     UIProcess/API/APIWebsiteDataRecord.cpp
 
-    UIProcess/API/C/WKResourceLoadStatisticsManager.cpp
-
     UIProcess/API/C/mac/WKContextPrivateMac.mm
     UIProcess/API/C/mac/WKPagePrivateMac.mm
 
index 92550fc..3f7c00f 100644 (file)
@@ -125,12 +125,10 @@ list(APPEND WebKit2_SOURCES
     UIProcess/BackingStore.cpp
     UIProcess/DefaultUndoController.cpp
     UIProcess/LegacySessionStateCodingNone.cpp
-    UIProcess/WebResourceLoadStatisticsManager.cpp
     UIProcess/WebResourceLoadStatisticsStore.cpp
     UIProcess/WebResourceLoadStatisticsTelemetry.cpp
 
     UIProcess/API/C/WKGrammarDetail.cpp
-    UIProcess/API/C/WKResourceLoadStatisticsManager.cpp
 
     UIProcess/API/C/cairo/WKIconDatabaseCairo.cpp
 
diff --git a/Source/WebKit2/UIProcess/API/C/WKResourceLoadStatisticsManager.cpp b/Source/WebKit2/UIProcess/API/C/WKResourceLoadStatisticsManager.cpp
deleted file mode 100644 (file)
index 696abc8..0000000
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * 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 "WKResourceLoadStatisticsManager.h"
-
-#include "WKAPICast.h"
-#include "WebResourceLoadStatisticsManager.h"
-#include "WebResourceLoadStatisticsStore.h"
-#include <wtf/Seconds.h>
-
-using namespace WebCore;
-using namespace WebKit;
-
-void WKResourceLoadStatisticsManagerSetPrevalentResource(WKStringRef hostName, bool value)
-{
-    if (value)
-        WebResourceLoadStatisticsManager::shared().setPrevalentResource(URL(URL(), toWTFString(hostName)));
-    else
-        WebResourceLoadStatisticsManager::shared().clearPrevalentResource(URL(URL(), toWTFString(hostName)));
-}
-
-bool WKResourceLoadStatisticsManagerIsPrevalentResource(WKStringRef hostName)
-{
-    return WebResourceLoadStatisticsManager::shared().isPrevalentResource(URL(URL(), toWTFString(hostName)));
-}
-
-void WKResourceLoadStatisticsManagerSetHasHadUserInteraction(WKStringRef hostName, bool value)
-{
-    if (value)
-        WebResourceLoadStatisticsManager::shared().logUserInteraction(URL(URL(), toWTFString(hostName)));
-    else
-        WebResourceLoadStatisticsManager::shared().clearUserInteraction(URL(URL(), toWTFString(hostName)));
-}
-
-// FIXME: This API name is wrong.
-bool WKResourceLoadStatisticsManagerIsHasHadUserInteraction(WKStringRef hostName)
-{
-    return WebResourceLoadStatisticsManager::shared().hasHadUserInteraction(URL(URL(), toWTFString(hostName)));
-}
-
-void WKResourceLoadStatisticsManagerSetGrandfathered(WKStringRef hostName, bool value)
-{
-    WebResourceLoadStatisticsManager::shared().setGrandfathered(URL(URL(), toWTFString(hostName)), value);
-}
-
-bool WKResourceLoadStatisticsManagerIsGrandfathered(WKStringRef hostName)
-{
-    return WebResourceLoadStatisticsManager::shared().isGrandfathered(URL(URL(), toWTFString(hostName)));
-}
-
-void WKResourceLoadStatisticsManagerSetSubframeUnderTopFrameOrigin(WKStringRef hostName, WKStringRef topFrameHostName)
-{
-    WebResourceLoadStatisticsManager::shared().setSubframeUnderTopFrameOrigin(URL(URL(), toWTFString(hostName)), URL(URL(), toWTFString(topFrameHostName)));
-}
-
-void WKResourceLoadStatisticsManagerSetSubresourceUnderTopFrameOrigin(WKStringRef hostName, WKStringRef topFrameHostName)
-{
-    WebResourceLoadStatisticsManager::shared().setSubresourceUnderTopFrameOrigin(URL(URL(), toWTFString(hostName)), URL(URL(), toWTFString(topFrameHostName)));
-}
-
-void WKResourceLoadStatisticsManagerSetSubresourceUniqueRedirectTo(WKStringRef hostName, WKStringRef hostNameRedirectedTo)
-{
-    WebResourceLoadStatisticsManager::shared().setSubresourceUniqueRedirectTo(URL(URL(), toWTFString(hostName)), URL(URL(), toWTFString(hostNameRedirectedTo)));
-}
-
-void WKResourceLoadStatisticsManagerSetTimeToLiveUserInteraction(double seconds)
-{
-    WebResourceLoadStatisticsManager::shared().setTimeToLiveUserInteraction(Seconds { seconds });
-}
-
-void WKResourceLoadStatisticsManagerSetTimeToLiveCookiePartitionFree(double seconds)
-{
-    WebResourceLoadStatisticsManager::shared().setTimeToLiveCookiePartitionFree(Seconds { seconds });
-}
-
-void WKResourceLoadStatisticsManagerSetMinimumTimeBetweenDataRecordsRemoval(double seconds)
-{
-    WebResourceLoadStatisticsManager::shared().setMinimumTimeBetweenDataRecordsRemoval(Seconds { seconds });
-}
-
-void WKResourceLoadStatisticsManagerSetGrandfatheringTime(double seconds)
-{
-    WebResourceLoadStatisticsManager::shared().setGrandfatheringTime(Seconds { seconds });
-}
-
-void WKResourceLoadStatisticsManagerFireDataModificationHandler()
-{
-    WebResourceLoadStatisticsManager::shared().fireDataModificationHandler();
-}
-
-void WKResourceLoadStatisticsManagerFireShouldPartitionCookiesHandler()
-{
-    WebResourceLoadStatisticsManager::shared().fireShouldPartitionCookiesHandler();
-}
-
-void WKResourceLoadStatisticsManagerFireShouldPartitionCookiesHandlerForOneDomain(WKStringRef hostName, bool value)
-{
-    if (value)
-        WebResourceLoadStatisticsManager::shared().fireShouldPartitionCookiesHandler({ }, { toWTFString(hostName) }, false);
-    else
-        WebResourceLoadStatisticsManager::shared().fireShouldPartitionCookiesHandler({ toWTFString(hostName) }, { }, false);
-}
-
-void WKResourceLoadStatisticsManagerFireTelemetryHandler()
-{
-    WebResourceLoadStatisticsManager::shared().fireTelemetryHandler();
-}
-
-void WKResourceLoadStatisticsManagerSetNotifyPagesWhenDataRecordsWereScanned(bool value)
-{
-    WebResourceLoadStatisticsStore::setNotifyPagesWhenDataRecordsWereScanned(value);
-}
-
-void WKResourceLoadStatisticsManagerSetShouldClassifyResourcesBeforeDataRecordsRemoval(bool value)
-{
-    WebResourceLoadStatisticsStore::setShouldClassifyResourcesBeforeDataRecordsRemoval(value);
-}
-
-void WKResourceLoadStatisticsManagerSetNotifyPagesWhenTelemetryWasCaptured(bool value)
-{
-    WebResourceLoadStatisticsTelemetry::setNotifyPagesWhenTelemetryWasCaptured(value);
-}
-
-void WKResourceLoadStatisticsManagerSetShouldSubmitTelemetry(bool value)
-{
-    WebResourceLoadStatisticsStore::setShouldSubmitTelemetry(value);
-}
-
-void WKResourceLoadStatisticsManagerClearInMemoryAndPersistentStore()
-{
-    WebResourceLoadStatisticsManager::shared().clearInMemoryAndPersistentStore();
-}
-
-void WKResourceLoadStatisticsManagerClearInMemoryAndPersistentStoreModifiedSinceHours(unsigned hours)
-{
-    WebResourceLoadStatisticsManager::shared().clearInMemoryAndPersistentStore(std::chrono::system_clock::now() - std::chrono::hours(hours));
-}
-
-void WKResourceLoadStatisticsManagerResetToConsistentState()
-{
-    WebResourceLoadStatisticsManager::shared().setTimeToLiveUserInteraction(24_h * 30.);
-    WebResourceLoadStatisticsManager::shared().setTimeToLiveCookiePartitionFree(24_h);
-    WebResourceLoadStatisticsManager::shared().setMinimumTimeBetweenDataRecordsRemoval(1_h);
-    WebResourceLoadStatisticsManager::shared().setGrandfatheringTime(1_h);
-    WebResourceLoadStatisticsStore::setNotifyPagesWhenDataRecordsWereScanned(false);
-    WebResourceLoadStatisticsTelemetry::setNotifyPagesWhenTelemetryWasCaptured(false);
-    WebResourceLoadStatisticsStore::setShouldClassifyResourcesBeforeDataRecordsRemoval(true);
-    WebResourceLoadStatisticsManager::shared().clearInMemoryStore();
-}
diff --git a/Source/WebKit2/UIProcess/API/C/WKResourceLoadStatisticsManager.h b/Source/WebKit2/UIProcess/API/C/WKResourceLoadStatisticsManager.h
deleted file mode 100644 (file)
index 81fe244..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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 <WebKit/WKBase.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-    
-    WK_EXPORT void WKResourceLoadStatisticsManagerSetPrevalentResource(WKStringRef hostName, bool value);
-    WK_EXPORT bool WKResourceLoadStatisticsManagerIsPrevalentResource(WKStringRef hostName);
-    WK_EXPORT void WKResourceLoadStatisticsManagerSetHasHadUserInteraction(WKStringRef hostName, bool value);
-    WK_EXPORT bool WKResourceLoadStatisticsManagerIsHasHadUserInteraction(WKStringRef hostName);
-    WK_EXPORT void WKResourceLoadStatisticsManagerSetGrandfathered(WKStringRef hostName, bool value);
-    WK_EXPORT bool WKResourceLoadStatisticsManagerIsGrandfathered(WKStringRef hostName);
-    WK_EXPORT void WKResourceLoadStatisticsManagerSetSubframeUnderTopFrameOrigin(WKStringRef hostName, WKStringRef topFrameHostName);
-    WK_EXPORT void WKResourceLoadStatisticsManagerSetSubresourceUnderTopFrameOrigin(WKStringRef hostName, WKStringRef topFrameHostName);
-    WK_EXPORT void WKResourceLoadStatisticsManagerSetSubresourceUniqueRedirectTo(WKStringRef hostName, WKStringRef hostNameRedirectedTo);
-    WK_EXPORT void WKResourceLoadStatisticsManagerSetTimeToLiveUserInteraction(double seconds);
-    WK_EXPORT void WKResourceLoadStatisticsManagerSetTimeToLiveCookiePartitionFree(double seconds);
-    WK_EXPORT void WKResourceLoadStatisticsManagerSetMinimumTimeBetweenDataRecordsRemoval(double seconds);
-    WK_EXPORT void WKResourceLoadStatisticsManagerSetGrandfatheringTime(double seconds);
-    WK_EXPORT void WKResourceLoadStatisticsManagerFireDataModificationHandler();
-    WK_EXPORT void WKResourceLoadStatisticsManagerFireShouldPartitionCookiesHandler();
-    WK_EXPORT void WKResourceLoadStatisticsManagerFireShouldPartitionCookiesHandlerForOneDomain(WKStringRef hostName, bool value);
-    WK_EXPORT void WKResourceLoadStatisticsManagerFireTelemetryHandler();
-    WK_EXPORT void WKResourceLoadStatisticsManagerSetNotifyPagesWhenDataRecordsWereScanned(bool value);
-    WK_EXPORT void WKResourceLoadStatisticsManagerSetShouldClassifyResourcesBeforeDataRecordsRemoval(bool value);
-    WK_EXPORT void WKResourceLoadStatisticsManagerSetNotifyPagesWhenTelemetryWasCaptured(bool value);
-    WK_EXPORT void WKResourceLoadStatisticsManagerSetShouldSubmitTelemetry(bool value);
-    WK_EXPORT void WKResourceLoadStatisticsManagerClearInMemoryAndPersistentStore();
-    WK_EXPORT void WKResourceLoadStatisticsManagerClearInMemoryAndPersistentStoreModifiedSinceHours(unsigned);
-    WK_EXPORT void WKResourceLoadStatisticsManagerResetToConsistentState();
-
-#ifdef __cplusplus
-}
-#endif
index 9571059..36d6422 100644 (file)
 #import "WKHTTPCookieStoreInternal.h"
 #import "WKNSArray.h"
 #import "WKWebsiteDataRecordInternal.h"
+#import "WebResourceLoadStatisticsStore.h"
+#import "WebResourceLoadStatisticsTelemetry.h"
 #import "WebsiteDataFetchOption.h"
 #import "_WKWebsiteDataStoreConfiguration.h"
+#import <WebCore/URL.h>
 #import <wtf/BlockPtr.h>
 
+using namespace WebCore;
+
 @implementation WKWebsiteDataStore
 
 + (WKWebsiteDataStore *)defaultDataStore
@@ -202,6 +207,234 @@ static Vector<WebKit::WebsiteDataRecord> toWebsiteDataRecords(NSArray *dataRecor
     _websiteDataStore->websiteDataStore().setResourceLoadStatisticsEnabled(enabled);
 }
 
+- (void)_resourceLoadStatisticsSetIsPrevalentResource:(BOOL)value forHost:(NSString *)host
+{
+    auto* store = _websiteDataStore->websiteDataStore().resourceLoadStatistics();
+    if (!store)
+        return;
+
+    if (value)
+        store->setPrevalentResource(URL(URL(), host));
+    else
+        store->clearPrevalentResource(URL(URL(), host));
+}
+
+- (BOOL)_resourceLoadStatisticsIsPrevalentResource:(NSString *)host
+{
+    auto* store = _websiteDataStore->websiteDataStore().resourceLoadStatistics();
+    if (!store)
+        return NO;
+
+    return store->isPrevalentResource(URL(URL(), host));
+}
+
+- (void)_resourceLoadStatisticsSetHadUserInteraction:(BOOL)value forHost:(NSString *)host
+{
+    auto* store = _websiteDataStore->websiteDataStore().resourceLoadStatistics();
+    if (!store)
+        return;
+
+    if (value)
+        store->logUserInteraction(URL(URL(), host));
+    else
+        store->clearUserInteraction(URL(URL(), host));
+}
+
+- (BOOL)_resourceLoadStatisticsHadUserInteraction:(NSString *)host
+{
+    auto* store = _websiteDataStore->websiteDataStore().resourceLoadStatistics();
+    if (!store)
+        return NO;
+
+    return store->hasHadUserInteraction(URL(URL(), host));
+}
+
+- (void)_resourceLoadStatisticsSetIsGrandfathered:(BOOL)value forHost:(NSString *)host
+{
+    auto* store = _websiteDataStore->websiteDataStore().resourceLoadStatistics();
+    if (!store)
+        return;
+
+    store->setGrandfathered(URL(URL(), host), value);
+}
+
+- (BOOL)_resourceLoadStatisticsIsGrandfathered:(NSString *)host
+{
+    auto* store = _websiteDataStore->websiteDataStore().resourceLoadStatistics();
+    if (!store)
+        return NO;
+
+    return store->isGrandfathered(URL(URL(), host));
+}
+
+- (void)_resourceLoadStatisticsSetSubframeUnderTopFrameOrigin:(NSString *)topFrameHostName forHost:(NSString *)host
+{
+    auto* store = _websiteDataStore->websiteDataStore().resourceLoadStatistics();
+    if (!store)
+        return;
+
+    store->setSubframeUnderTopFrameOrigin(URL(URL(), host), URL(URL(), topFrameHostName));
+}
+
+- (void)_resourceLoadStatisticsSetSubresourceUnderTopFrameOrigin:(NSString *)topFrameHostName forHost:(NSString *)host
+{
+    auto* store = _websiteDataStore->websiteDataStore().resourceLoadStatistics();
+    if (!store)
+        return;
+
+    store->setSubresourceUnderTopFrameOrigin(URL(URL(), host), URL(URL(), topFrameHostName));
+}
+
+- (void)_resourceLoadStatisticsSetSubresourceUniqueRedirectTo:(NSString *)hostNameRedirectedTo forHost:(NSString *)host
+{
+    auto* store = _websiteDataStore->websiteDataStore().resourceLoadStatistics();
+    if (!store)
+        return;
+
+    store->setSubresourceUniqueRedirectTo(URL(URL(), host), URL(URL(), hostNameRedirectedTo));
+}
+
+- (void)_resourceLoadStatisticsSetTimeToLiveUserInteraction:(double)seconds
+{
+    auto* store = _websiteDataStore->websiteDataStore().resourceLoadStatistics();
+    if (!store)
+        return;
+
+    store->setTimeToLiveUserInteraction(Seconds { seconds });
+}
+
+- (void)_resourceLoadStatisticsSetTimeToLiveCookiePartitionFree:(double)seconds
+{
+    auto* store = _websiteDataStore->websiteDataStore().resourceLoadStatistics();
+    if (!store)
+        return;
+
+    store->setTimeToLiveCookiePartitionFree(Seconds { seconds });
+}
+
+- (void)_resourceLoadStatisticsSetMinimumTimeBetweenDataRecordsRemoval:(double)seconds
+{
+    auto* store = _websiteDataStore->websiteDataStore().resourceLoadStatistics();
+    if (!store)
+        return;
+
+    store->setMinimumTimeBetweenDataRecordsRemoval(Seconds { seconds });
+}
+
+- (void)_resourceLoadStatisticsSetGrandfatheringTime:(double)seconds
+{
+    auto* store = _websiteDataStore->websiteDataStore().resourceLoadStatistics();
+    if (!store)
+        return;
+
+    store->setGrandfatheringTime(Seconds {seconds });
+}
+
+- (void)_resourceLoadStatisticsFireDataModificationHandler
+{
+    auto* store = _websiteDataStore->websiteDataStore().resourceLoadStatistics();
+    if (!store)
+        return;
+
+    store->fireDataModificationHandler();
+}
+
+- (void)_resourceLoadStatisticsFireShouldPartitionCookiesHandler
+{
+    auto* store = _websiteDataStore->websiteDataStore().resourceLoadStatistics();
+    if (!store)
+        return;
+
+    store->fireShouldPartitionCookiesHandler();
+}
+
+- (void)_resourceLoadStatisticsFireShouldPartitionCookiesHandlerForOneDomain:(BOOL)value forHost:(NSString *)host
+{
+    auto* store = _websiteDataStore->websiteDataStore().resourceLoadStatistics();
+    if (!store)
+        return;
+
+    if (value)
+        store->fireShouldPartitionCookiesHandler({ }, { host }, false);
+    else
+        store->fireShouldPartitionCookiesHandler({ host }, { }, false);
+}
+
+- (void)_resourceLoadStatisticsFireTelemetryHandler
+{
+    auto* store = _websiteDataStore->websiteDataStore().resourceLoadStatistics();
+    if (!store)
+        return;
+
+    store->fireTelemetryHandler();
+}
+
+- (void)_resourceLoadStatisticsSetNotifyPagesWhenDataRecordsWereScanned:(BOOL)value
+{
+    auto* store = _websiteDataStore->websiteDataStore().resourceLoadStatistics();
+    if (!store)
+        return;
+
+    store->setNotifyPagesWhenDataRecordsWereScanned(value);
+}
+
+- (void)_resourceLoadStatisticsSetShouldClassifyResourcesBeforeDataRecordsRemoval:(BOOL)value
+{
+    auto* store = _websiteDataStore->websiteDataStore().resourceLoadStatistics();
+    if (!store)
+        return;
+
+    store->setShouldClassifyResourcesBeforeDataRecordsRemoval(value);
+}
+
+- (void)_resourceLoadStatisticsSetNotifyPagesWhenTelemetryWasCaptured:(BOOL)value
+{
+    WebKit::WebResourceLoadStatisticsTelemetry::setNotifyPagesWhenTelemetryWasCaptured(value);
+}
+
+- (void)_resourceLoadStatisticsSetShouldSubmitTelemetry:(BOOL)value
+{
+    auto* store = _websiteDataStore->websiteDataStore().resourceLoadStatistics();
+    if (!store)
+        return;
+
+    store->setShouldSubmitTelemetry(value);
+}
+
+- (void)_resourceLoadStatisticsClearInMemoryAndPersistentStore
+{
+    auto* store = _websiteDataStore->websiteDataStore().resourceLoadStatistics();
+    if (!store)
+        return;
+
+    store->clearInMemoryAndPersistent();
+}
+
+- (void)_resourceLoadStatisticsClearInMemoryAndPersistentStoreModifiedSinceHours:(unsigned)hours
+{
+    auto* store = _websiteDataStore->websiteDataStore().resourceLoadStatistics();
+    if (!store)
+        return;
+
+    store->clearInMemoryAndPersistent(std::chrono::system_clock::now() - std::chrono::hours(hours));
+}
+
+- (void)_resourceLoadStatisticsResetToConsistentState
+{
+    auto* store = _websiteDataStore->websiteDataStore().resourceLoadStatistics();
+    if (!store)
+        return;
+
+    store->setTimeToLiveUserInteraction(24_h * 30.);
+    store->setTimeToLiveCookiePartitionFree(24_h);
+    store->setMinimumTimeBetweenDataRecordsRemoval(1_h);
+    store->setGrandfatheringTime(1_h);
+    store->setNotifyPagesWhenDataRecordsWereScanned(false);
+    WebKit::WebResourceLoadStatisticsTelemetry::setNotifyPagesWhenTelemetryWasCaptured(false);
+    store->setShouldClassifyResourcesBeforeDataRecordsRemoval(true);
+    store->clearInMemory();
+}
+
 @end
 
 #endif // WK_API_ENABLED
index 91e463e..b89a26c 100644 (file)
@@ -43,6 +43,32 @@ typedef NS_OPTIONS(NSUInteger, _WKWebsiteDataStoreFetchOptions) {
 
 @property (nonatomic, setter=_setResourceLoadStatisticsEnabled:) BOOL _resourceLoadStatisticsEnabled WK_API_AVAILABLE(macosx(10.12), ios(10.0));
 
+// ResourceLoadStatistics SPI for testing.
+- (void)_resourceLoadStatisticsSetIsPrevalentResource:(BOOL)value forHost:(NSString *)host WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (BOOL)_resourceLoadStatisticsIsPrevalentResource:(NSString *)host WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_resourceLoadStatisticsSetHadUserInteraction:(BOOL)value forHost:(NSString *)host WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (BOOL)_resourceLoadStatisticsHadUserInteraction:(NSString *)host WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_resourceLoadStatisticsSetIsGrandfathered:(BOOL)value forHost:(NSString *)host WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (BOOL)_resourceLoadStatisticsIsGrandfathered:(NSString *)host WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_resourceLoadStatisticsSetSubframeUnderTopFrameOrigin:(NSString *)topFrameHostName forHost:(NSString *)host WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_resourceLoadStatisticsSetSubresourceUnderTopFrameOrigin:(NSString *)topFrameHostName forHost:(NSString *)host WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_resourceLoadStatisticsSetSubresourceUniqueRedirectTo:(NSString *)hostNameRedirectedTo forHost:(NSString *)host WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_resourceLoadStatisticsSetTimeToLiveUserInteraction:(double)seconds WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_resourceLoadStatisticsSetTimeToLiveCookiePartitionFree:(double)seconds WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_resourceLoadStatisticsSetMinimumTimeBetweenDataRecordsRemoval:(double)seconds WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_resourceLoadStatisticsSetGrandfatheringTime:(double)seconds WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_resourceLoadStatisticsFireDataModificationHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_resourceLoadStatisticsFireShouldPartitionCookiesHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_resourceLoadStatisticsFireShouldPartitionCookiesHandlerForOneDomain:(BOOL)value forHost:(NSString *)host WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_resourceLoadStatisticsFireTelemetryHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_resourceLoadStatisticsSetNotifyPagesWhenDataRecordsWereScanned:(BOOL)value WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_resourceLoadStatisticsSetShouldClassifyResourcesBeforeDataRecordsRemoval:(BOOL)value WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_resourceLoadStatisticsSetNotifyPagesWhenTelemetryWasCaptured:(BOOL)value WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_resourceLoadStatisticsSetShouldSubmitTelemetry:(BOOL)value WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_resourceLoadStatisticsClearInMemoryAndPersistentStore WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_resourceLoadStatisticsClearInMemoryAndPersistentStoreModifiedSinceHours:(unsigned)hours WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_resourceLoadStatisticsResetToConsistentState WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+
 @end
 
 NS_ASSUME_NONNULL_END
diff --git a/Source/WebKit2/UIProcess/WebResourceLoadStatisticsManager.cpp b/Source/WebKit2/UIProcess/WebResourceLoadStatisticsManager.cpp
deleted file mode 100644 (file)
index bc5fde7..0000000
+++ /dev/null
@@ -1,232 +0,0 @@
-/*
- * 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 "WebResourceLoadStatisticsManager.h"
-
-#include "WebResourceLoadStatisticsStore.h"
-#include <WebCore/URL.h>
-#include <wtf/NeverDestroyed.h>
-
-namespace WebKit {
-
-using namespace WebCore;
-
-WebResourceLoadStatisticsManager& WebResourceLoadStatisticsManager::shared()
-{
-    static NeverDestroyed<WebResourceLoadStatisticsManager> webResourceLoadStatisticsManager;
-    return webResourceLoadStatisticsManager;
-}
-
-WebResourceLoadStatisticsManager::WebResourceLoadStatisticsManager()
-{
-}
-
-WebResourceLoadStatisticsManager::~WebResourceLoadStatisticsManager()
-{
-}
-
-void WebResourceLoadStatisticsManager::setStatisticsStore(Ref<WebResourceLoadStatisticsStore>&& store)
-{
-    m_store = WTFMove(store);
-}
-
-void WebResourceLoadStatisticsManager::clearInMemoryStore()
-{
-    if (!m_store)
-        return;
-
-    m_store->clearInMemory();
-}
-
-void WebResourceLoadStatisticsManager::clearInMemoryAndPersistentStore()
-{
-    if (!m_store)
-        return;
-
-    m_store->clearInMemoryAndPersistent();
-}
-
-void WebResourceLoadStatisticsManager::clearInMemoryAndPersistentStore(std::chrono::system_clock::time_point modifiedSince)
-{
-    if (!m_store)
-        return;
-
-    m_store->clearInMemoryAndPersistent(modifiedSince);
-}
-
-void WebResourceLoadStatisticsManager::logUserInteraction(const URL& url)
-{
-    if (!m_store)
-        return;
-
-    m_store->logUserInteraction(url);
-}
-
-void WebResourceLoadStatisticsManager::clearUserInteraction(const URL& url)
-{
-    if (!m_store)
-        return;
-
-    m_store->clearUserInteraction(url);
-}
-
-bool WebResourceLoadStatisticsManager::hasHadUserInteraction(const URL& url)
-{
-    if (!m_store)
-        return false;
-
-    return m_store->hasHadUserInteraction(url);
-}
-
-void WebResourceLoadStatisticsManager::setPrevalentResource(const URL& url)
-{
-    if (!m_store)
-        return;
-
-    m_store->setPrevalentResource(url);
-}
-
-bool WebResourceLoadStatisticsManager::isPrevalentResource(const URL& url)
-{
-    if (!m_store)
-        return false;
-
-    return m_store->isPrevalentResource(url);
-}
-
-void WebResourceLoadStatisticsManager::clearPrevalentResource(const URL& url)
-{
-    if (!m_store)
-        return;
-
-    m_store->clearPrevalentResource(url);
-}
-
-void WebResourceLoadStatisticsManager::setGrandfathered(const URL& url, bool value)
-{
-    if (!m_store)
-        return;
-
-    m_store->setGrandfathered(url, value);
-}
-
-bool WebResourceLoadStatisticsManager::isGrandfathered(const URL& url)
-{
-    if (!m_store)
-        return false;
-
-    return m_store->isGrandfathered(url);
-}
-
-void WebResourceLoadStatisticsManager::setSubframeUnderTopFrameOrigin(const URL& subframe, const URL& topFrame)
-{
-    if (!m_store)
-        return;
-
-    m_store->setSubframeUnderTopFrameOrigin(subframe, topFrame);
-}
-
-void WebResourceLoadStatisticsManager::setSubresourceUnderTopFrameOrigin(const URL& subresource, const URL& topFrame)
-{
-    if (!m_store)
-        return;
-
-    m_store->setSubresourceUnderTopFrameOrigin(subresource, topFrame);
-}
-
-void WebResourceLoadStatisticsManager::setSubresourceUniqueRedirectTo(const URL& subresource, const URL& hostNameRedirectedTo)
-{
-    if (!m_store)
-        return;
-
-    m_store->setSubresourceUniqueRedirectTo(subresource, hostNameRedirectedTo);
-}
-
-void WebResourceLoadStatisticsManager::setTimeToLiveUserInteraction(Seconds seconds)
-{
-    if (!m_store)
-        return;
-
-    m_store->setTimeToLiveUserInteraction(seconds);
-}
-
-void WebResourceLoadStatisticsManager::setTimeToLiveCookiePartitionFree(Seconds seconds)
-{
-    if (!m_store)
-        return;
-
-    m_store->setTimeToLiveCookiePartitionFree(seconds);
-}
-
-void WebResourceLoadStatisticsManager::setMinimumTimeBetweenDataRecordsRemoval(Seconds seconds)
-{
-    if (!m_store)
-        return;
-
-    m_store->setMinimumTimeBetweenDataRecordsRemoval(seconds);
-}
-
-void WebResourceLoadStatisticsManager::setGrandfatheringTime(Seconds seconds)
-{
-    if (!m_store)
-        return;
-
-    m_store->setGrandfatheringTime(seconds);
-}
-
-void WebResourceLoadStatisticsManager::fireDataModificationHandler()
-{
-    if (!m_store)
-        return;
-
-    m_store->fireDataModificationHandler();
-}
-
-void WebResourceLoadStatisticsManager::fireShouldPartitionCookiesHandler()
-{
-    if (!m_store)
-        return;
-
-    m_store->fireShouldPartitionCookiesHandler();
-}
-
-void WebResourceLoadStatisticsManager::fireShouldPartitionCookiesHandler(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool clearFirst)
-{
-    if (!m_store)
-        return;
-
-    m_store->fireShouldPartitionCookiesHandler(domainsToRemove, domainsToAdd, clearFirst);
-}
-
-void WebResourceLoadStatisticsManager::fireTelemetryHandler()
-{
-    if (!m_store)
-        return;
-
-    m_store->fireTelemetryHandler();
-}
-
-} // namespace WebKit
diff --git a/Source/WebKit2/UIProcess/WebResourceLoadStatisticsManager.h b/Source/WebKit2/UIProcess/WebResourceLoadStatisticsManager.h
deleted file mode 100644 (file)
index 22bb208..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * 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 <chrono>
-#include <wtf/Seconds.h>
-#include <wtf/text/WTFString.h>
-
-namespace WebCore {
-class URL;
-}
-
-namespace WebKit {
-
-class WebResourceLoadStatisticsStore;
-
-// FIXME: This should probably become an APIObject for the WebResourceLoadStatisticsStore.
-class WebResourceLoadStatisticsManager {
-    friend class NeverDestroyed<WebResourceLoadStatisticsManager>;
-public:
-    // FIXME: This should not be a singleton.
-    static WebResourceLoadStatisticsManager& shared();
-    void setStatisticsStore(Ref<WebResourceLoadStatisticsStore>&&);
-
-    ~WebResourceLoadStatisticsManager();
-
-    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 setMinimumTimeBetweenDataRecordsRemoval(Seconds);
-    void setGrandfatheringTime(Seconds);
-
-    void fireDataModificationHandler();
-    void fireShouldPartitionCookiesHandler();
-    void fireShouldPartitionCookiesHandler(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool clearFirst);
-    void fireTelemetryHandler();
-
-    void clearInMemoryStore();
-    void clearInMemoryAndPersistentStore();
-    void clearInMemoryAndPersistentStore(std::chrono::system_clock::time_point modifiedSince);
-
-private:
-    WebResourceLoadStatisticsManager();
-
-    RefPtr<WebResourceLoadStatisticsStore> m_store;
-};
-
-} // namespace WebKit
index 6c3d00e..6849210 100644 (file)
@@ -30,7 +30,6 @@
 #include "WebProcessMessages.h"
 #include "WebProcessPool.h"
 #include "WebProcessProxy.h"
-#include "WebResourceLoadStatisticsManager.h"
 #include "WebResourceLoadStatisticsStoreMessages.h"
 #include "WebsiteDataFetchOption.h"
 #include "WebsiteDataType.h"
@@ -214,7 +213,6 @@ void WebResourceLoadStatisticsStore::registerSharedResourceLoadObserver()
 {
     ASSERT(RunLoop::isMain());
     
-    WebResourceLoadStatisticsManager::shared().setStatisticsStore(*this);
     m_resourceLoadStatisticsStore->setNotificationCallback([this, protectedThis = makeRef(*this)] {
         if (m_resourceLoadStatisticsStore->isEmpty())
             return;
index 7ca26de..e763960 100644 (file)
@@ -89,6 +89,7 @@ public:
 
     bool resourceLoadStatisticsEnabled() const;
     void setResourceLoadStatisticsEnabled(bool);
+    WebResourceLoadStatisticsStore* resourceLoadStatistics() const { return m_resourceLoadStatistics.get(); }
     void registerSharedResourceLoadObserver();
 
     static void cloneSessionData(WebPageProxy& sourcePage, WebPageProxy& newPage);
index 2a53e64..c8fcb8c 100644 (file)
                65B86F1E12F11DE300B7DD8A /* WKBundleInspector.h in Headers */ = {isa = PBXBuildFile; fileRef = 65B86F1812F11D7B00B7DD8A /* WKBundleInspector.h */; settings = {ATTRIBUTES = (Private, ); }; };
                6B821DDC1EEF05DD00D7AF4A /* WebResourceLoadStatisticsTelemetry.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B821DDA1EEF05DD00D7AF4A /* WebResourceLoadStatisticsTelemetry.h */; };
                6B821DDD1EEF05DD00D7AF4A /* WebResourceLoadStatisticsTelemetry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B821DDB1EEF05DD00D7AF4A /* WebResourceLoadStatisticsTelemetry.cpp */; };
-               6BE9699C1E43B3FF008B7483 /* WKResourceLoadStatisticsManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 6BE9699B1E43B3FF008B7483 /* WKResourceLoadStatisticsManager.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               6BE9699E1E43B41D008B7483 /* WKResourceLoadStatisticsManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BE9699D1E43B41D008B7483 /* WKResourceLoadStatisticsManager.cpp */; };
-               6BE969A01E43B86E008B7483 /* WebResourceLoadStatisticsManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 6BE9699F1E43B86E008B7483 /* WebResourceLoadStatisticsManager.h */; };
-               6BE969A21E43B8A4008B7483 /* WebResourceLoadStatisticsManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BE969A11E43B8A4008B7483 /* WebResourceLoadStatisticsManager.cpp */; };
                6BE969C11E54D452008B7483 /* corePrediction_model in Resources */ = {isa = PBXBuildFile; fileRef = 6BE969C01E54D452008B7483 /* corePrediction_model */; };
                6BE969C71E54D4B6008B7483 /* ResourceLoadStatisticsClassifier.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BE969C61E54D4B6008B7483 /* ResourceLoadStatisticsClassifier.cpp */; };
                6BE969CA1E54D4CF008B7483 /* ResourceLoadStatisticsClassifierCocoa.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BE969C81E54D4CF008B7483 /* ResourceLoadStatisticsClassifierCocoa.cpp */; };
                65B86F1812F11D7B00B7DD8A /* WKBundleInspector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKBundleInspector.h; sourceTree = "<group>"; };
                6B821DDA1EEF05DD00D7AF4A /* WebResourceLoadStatisticsTelemetry.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebResourceLoadStatisticsTelemetry.h; sourceTree = "<group>"; };
                6B821DDB1EEF05DD00D7AF4A /* WebResourceLoadStatisticsTelemetry.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebResourceLoadStatisticsTelemetry.cpp; sourceTree = "<group>"; };
-               6BE9699B1E43B3FF008B7483 /* WKResourceLoadStatisticsManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKResourceLoadStatisticsManager.h; sourceTree = "<group>"; };
-               6BE9699D1E43B41D008B7483 /* WKResourceLoadStatisticsManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKResourceLoadStatisticsManager.cpp; sourceTree = "<group>"; };
-               6BE9699F1E43B86E008B7483 /* WebResourceLoadStatisticsManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebResourceLoadStatisticsManager.h; sourceTree = "<group>"; };
-               6BE969A11E43B8A4008B7483 /* WebResourceLoadStatisticsManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebResourceLoadStatisticsManager.cpp; sourceTree = "<group>"; };
                6BE969C01E54D452008B7483 /* corePrediction_model */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = corePrediction_model; sourceTree = "<group>"; };
                6BE969C61E54D4B6008B7483 /* ResourceLoadStatisticsClassifier.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ResourceLoadStatisticsClassifier.cpp; sourceTree = "<group>"; };
                6BE969C81E54D4CF008B7483 /* ResourceLoadStatisticsClassifierCocoa.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ResourceLoadStatisticsClassifierCocoa.cpp; sourceTree = "<group>"; };
                                BC111B0D112F5E4F00337BAB /* WebProcessProxy.cpp */,
                                BC032DCF10F4389F0058C15A /* WebProcessProxy.h */,
                                BCEE7AB312817095009827DA /* WebProcessProxy.messages.in */,
-                               6BE969A11E43B8A4008B7483 /* WebResourceLoadStatisticsManager.cpp */,
-                               6BE9699F1E43B86E008B7483 /* WebResourceLoadStatisticsManager.h */,
                                7A9CD8C01C77984900D9F6C7 /* WebResourceLoadStatisticsStore.cpp */,
                                7A9CD8C11C77984900D9F6C7 /* WebResourceLoadStatisticsStore.h */,
                                7A9CD8C21C779AD600D9F6C7 /* WebResourceLoadStatisticsStore.messages.in */,
                                518ACAE912AEE6BB00B04B83 /* WKProtectionSpaceTypes.h */,
                                33367638130C99DC006C9DE2 /* WKResourceCacheManager.cpp */,
                                33367639130C99DC006C9DE2 /* WKResourceCacheManager.h */,
-                               6BE9699D1E43B41D008B7483 /* WKResourceLoadStatisticsManager.cpp */,
-                               6BE9699B1E43B3FF008B7483 /* WKResourceLoadStatisticsManager.h */,
                                1ADE46B01954EC61000F7985 /* WKSessionStateRef.cpp */,
                                1ADE46B11954EC61000F7985 /* WKSessionStateRef.h */,
                                314888FE1D91B11D00377042 /* WKTextChecker.cpp */,
                                3760881F150413E900FC82C7 /* WebRenderObject.h in Headers */,
                                510AFFBA16542048001BA05E /* WebResourceLoader.h in Headers */,
                                51F060E01654317F00F3281B /* WebResourceLoaderMessages.h in Headers */,
-                               6BE969A01E43B86E008B7483 /* WebResourceLoadStatisticsManager.h in Headers */,
                                7A791EFB1C7CFD0100C4C52B /* WebResourceLoadStatisticsStoreMessages.h in Headers */,
                                6B821DDC1EEF05DD00D7AF4A /* WebResourceLoadStatisticsTelemetry.h in Headers */,
                                413075B01DE85F580039EC69 /* WebRTCMonitor.h in Headers */,
                                37948409150C4B9700E52CE9 /* WKRenderLayer.h in Headers */,
                                37608823150414F700FC82C7 /* WKRenderObject.h in Headers */,
                                3336763B130C99DC006C9DE2 /* WKResourceCacheManager.h in Headers */,
-                               6BE9699C1E43B3FF008B7483 /* WKResourceLoadStatisticsManager.h in Headers */,
                                BC8A501511765F5600757573 /* WKRetainPtr.h in Headers */,
                                1A7E377918E4A4FE003D0FFF /* WKScriptMessage.h in Headers */,
                                1A7E377518E4A33A003D0FFF /* WKScriptMessageHandler.h in Headers */,
                                3760881E150413E900FC82C7 /* WebRenderObject.cpp in Sources */,
                                510AFFB916542048001BA05E /* WebResourceLoader.cpp in Sources */,
                                51F060E11654318500F3281B /* WebResourceLoaderMessageReceiver.cpp in Sources */,
-                               6BE969A21E43B8A4008B7483 /* WebResourceLoadStatisticsManager.cpp in Sources */,
                                7A791EFC1C7D08C500C4C52B /* WebResourceLoadStatisticsStore.cpp in Sources */,
                                7AAD175F1EA6AF99003B0894 /* WebResourceLoadStatisticsStoreCocoa.mm in Sources */,
                                7A791EFA1C7CFCF100C4C52B /* WebResourceLoadStatisticsStoreMessageReceiver.cpp in Sources */,
                                37948408150C4B9700E52CE9 /* WKRenderLayer.cpp in Sources */,
                                37608822150414F700FC82C7 /* WKRenderObject.cpp in Sources */,
                                3336763A130C99DC006C9DE2 /* WKResourceCacheManager.cpp in Sources */,
-                               6BE9699E1E43B41D008B7483 /* WKResourceLoadStatisticsManager.cpp in Sources */,
                                1A7E377818E4A4FE003D0FFF /* WKScriptMessage.mm in Sources */,
                                0FCB4E5518BBE044000FCFC9 /* WKScrollView.mm in Sources */,
                                51CD1C661B34B9DC00142CA5 /* WKSecurityOrigin.mm in Sources */,
index 3d55a74..10f346c 100644 (file)
@@ -1,3 +1,22 @@
+2017-07-01  Chris Dumez  <cdumez@apple.com>
+
+        Replace ResourceLoadStatisticsStore C API with Cocoa SPI
+        https://bugs.webkit.org/show_bug.cgi?id=174060
+
+        Reviewed by Brent Fulgham.
+
+        Port WebKitTestRunner over to the new Cocoa SPI.
+
+        * WebKitTestRunner/InjectedBundle/TestRunner.cpp:
+        (WTR::TestRunner::setStatisticsNotifyPagesWhenDataRecordsWereScanned):
+        (WTR::TestRunner::setStatisticsNotifyPagesWhenTelemetryWasCaptured):
+        Drop calls to the WKResourceLoadStatisticsStore C API here. Those were
+        no-ops since this code runs in the WebContent process, not the
+        UIProcess.
+
+        * WebKitTestRunner/TestController.cpp:
+        * WebKitTestRunner/cocoa/TestControllerCocoa.mm:
+
 2017-06-30  Megan Gardner  <megan_gardner@apple.com>
 
         Unreviewed mac build fix.
index 1aa0e5d..150a34b 100644 (file)
@@ -46,7 +46,6 @@
 #include <WebKit/WKBundleScriptWorld.h>
 #include <WebKit/WKData.h>
 #include <WebKit/WKPagePrivate.h>
-#include <WebKit/WKResourceLoadStatisticsManager.h>
 #include <WebKit/WKRetainPtr.h>
 #include <WebKit/WKSerializedScriptValue.h>
 #include <WebKit/WebKit2_C.h>
@@ -1456,13 +1455,12 @@ void TestRunner::statisticsFireTelemetryHandler()
     WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("StatisticsFireTelemetryHandler"));
     WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), 0, nullptr);
 }
-    
+
 void TestRunner::setStatisticsNotifyPagesWhenDataRecordsWereScanned(bool value)
 {
     WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("StatisticsNotifyPagesWhenDataRecordsWereScanned"));
     WKRetainPtr<WKBooleanRef> messageBody(AdoptWK, WKBooleanCreate(value));
     WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr);
-    WKResourceLoadStatisticsManagerSetNotifyPagesWhenDataRecordsWereScanned(value);
 }
 
 void TestRunner::setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(bool value)
@@ -1471,13 +1469,12 @@ void TestRunner::setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(bo
     WKRetainPtr<WKBooleanRef> messageBody(AdoptWK, WKBooleanCreate(value));
     WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr);
 }
-    
+
 void TestRunner::setStatisticsNotifyPagesWhenTelemetryWasCaptured(bool value)
 {
     WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("StatisticsNotifyPagesWhenTelemetryWasCaptured"));
     WKRetainPtr<WKBooleanRef> messageBody(AdoptWK, WKBooleanCreate(value));
     WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr);
-    WKResourceLoadStatisticsManagerSetNotifyPagesWhenTelemetryWasCaptured(value);
 }
 
 void TestRunner::setStatisticsMinimumTimeBetweenDataRecordsRemoval(double seconds)
index 8aa6a68..0bec2d9 100644 (file)
@@ -54,7 +54,6 @@
 #include <WebKit/WKPluginInformation.h>
 #include <WebKit/WKPreferencesRefPrivate.h>
 #include <WebKit/WKProtectionSpace.h>
-#include <WebKit/WKResourceLoadStatisticsManager.h>
 #include <WebKit/WKRetainPtr.h>
 #include <WebKit/WKSecurityOriginRef.h>
 #include <WebKit/WKTextChecker.h>
@@ -388,8 +387,6 @@ void TestController::initialize(int argc, const char* argv[])
 #if PLATFORM(MAC)
     WebCoreTestSupport::installMockGamepadProvider();
 #endif
-    
-    WKResourceLoadStatisticsManagerSetShouldSubmitTelemetry(false);
 
     WKRetainPtr<WKStringRef> pageGroupIdentifier(AdoptWK, WKStringCreateWithUTF8CString("WebKitTestRunnerPageGroup"));
     m_pageGroup.adopt(WKPageGroupCreateWithIdentifier(pageGroupIdentifier.get()));
@@ -2209,157 +2206,141 @@ void TestController::setIgnoresViewportScaleLimits(bool ignoresViewportScaleLimi
     WKPageSetIgnoresViewportScaleLimits(m_mainWebView->page(), ignoresViewportScaleLimits);
 }
 
-void TestController::setStatisticsPrevalentResource(WKStringRef hostName, bool value)
+void TestController::terminateNetworkProcess()
 {
-    WKResourceLoadStatisticsManagerSetPrevalentResource(hostName, value);
+    WKContextTerminateNetworkProcess(platformContext());
 }
 
-bool TestController::isStatisticsPrevalentResource(WKStringRef hostName)
+#if !PLATFORM(COCOA)
+void TestController::platformWillRunTest(const TestInvocation&)
 {
-    return WKResourceLoadStatisticsManagerIsPrevalentResource(hostName);
 }
 
-void TestController::setStatisticsHasHadUserInteraction(WKStringRef hostName, bool value)
+void TestController::platformCreateWebView(WKPageConfigurationRef configuration, const TestOptions& options)
 {
-    WKResourceLoadStatisticsManagerSetHasHadUserInteraction(hostName, value);
+    m_mainWebView = std::make_unique<PlatformWebView>(configuration, options);
 }
 
-bool TestController::isStatisticsHasHadUserInteraction(WKStringRef hostName)
+PlatformWebView* TestController::platformCreateOtherPage(PlatformWebView* parentView, WKPageConfigurationRef configuration, const TestOptions& options)
 {
-    return WKResourceLoadStatisticsManagerIsHasHadUserInteraction(hostName);
+    return new PlatformWebView(configuration, options);
 }
 
-void TestController::setStatisticsGrandfathered(WKStringRef hostName, bool value)
+WKContextRef TestController::platformAdjustContext(WKContextRef context, WKContextConfigurationRef contextConfiguration)
 {
-    WKResourceLoadStatisticsManagerSetGrandfathered(hostName, value);
+    return context;
 }
 
-bool TestController::isStatisticsGrandfathered(WKStringRef hostName)
+void TestController::platformResetStateToConsistentValues()
 {
-    return WKResourceLoadStatisticsManagerIsGrandfathered(hostName);
+
 }
 
-void TestController::setStatisticsSubframeUnderTopFrameOrigin(WKStringRef hostName, WKStringRef topFrameHostName)
+unsigned TestController::imageCountInGeneralPasteboard() const
 {
-    WKResourceLoadStatisticsManagerSetSubframeUnderTopFrameOrigin(hostName, topFrameHostName);
+    return 0;
 }
 
-void TestController::setStatisticsSubresourceUnderTopFrameOrigin(WKStringRef hostName, WKStringRef topFrameHostName)
+void TestController::removeAllSessionCredentials()
 {
-    WKResourceLoadStatisticsManagerSetSubresourceUnderTopFrameOrigin(hostName, topFrameHostName);
 }
-    
-void TestController::setStatisticsSubresourceUniqueRedirectTo(WKStringRef hostName, WKStringRef hostNameRedirectedTo)
+
+#endif
+
+#if !PLATFORM(COCOA) || !WK_API_ENABLED
+
+void TestController::setStatisticsPrevalentResource(WKStringRef, bool)
 {
-    WKResourceLoadStatisticsManagerSetSubresourceUniqueRedirectTo(hostName, hostNameRedirectedTo);
 }
 
-void TestController::setStatisticsTimeToLiveUserInteraction(double seconds)
+bool TestController::isStatisticsPrevalentResource(WKStringRef)
 {
-    WKResourceLoadStatisticsManagerSetTimeToLiveUserInteraction(seconds);
+    return false;
 }
 
-void TestController::setStatisticsTimeToLiveCookiePartitionFree(double seconds)
+void TestController::setStatisticsHasHadUserInteraction(WKStringRef, bool)
 {
-    WKResourceLoadStatisticsManagerSetTimeToLiveCookiePartitionFree(seconds);
 }
 
-void TestController::statisticsFireDataModificationHandler()
+bool TestController::isStatisticsHasHadUserInteraction(WKStringRef)
 {
-    WKResourceLoadStatisticsManagerFireDataModificationHandler();
+    return false;
 }
-    
-void TestController::statisticsFireShouldPartitionCookiesHandler()
+
+void TestController::setStatisticsGrandfathered(WKStringRef, bool)
 {
-    WKResourceLoadStatisticsManagerFireShouldPartitionCookiesHandler();
 }
 
-void TestController::statisticsFireShouldPartitionCookiesHandlerForOneDomain(WKStringRef hostName, bool value)
+bool TestController::isStatisticsGrandfathered(WKStringRef)
 {
-    WKResourceLoadStatisticsManagerFireShouldPartitionCookiesHandlerForOneDomain(hostName, value);
+    return false;
 }
 
-void TestController::statisticsFireTelemetryHandler()
+void TestController::setStatisticsSubframeUnderTopFrameOrigin(WKStringRef, WKStringRef)
 {
-    WKResourceLoadStatisticsManagerFireTelemetryHandler();
 }
-    
-void TestController::setStatisticsNotifyPagesWhenDataRecordsWereScanned(bool value)
+
+void TestController::setStatisticsSubresourceUnderTopFrameOrigin(WKStringRef, WKStringRef)
 {
-    WKResourceLoadStatisticsManagerSetNotifyPagesWhenDataRecordsWereScanned(value);
 }
-    
-void TestController::setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(bool value)
+
+void TestController::setStatisticsSubresourceUniqueRedirectTo(WKStringRef, WKStringRef)
 {
-    WKResourceLoadStatisticsManagerSetShouldClassifyResourcesBeforeDataRecordsRemoval(value);
 }
 
-void TestController::setStatisticsNotifyPagesWhenTelemetryWasCaptured(bool value)
+void TestController::setStatisticsTimeToLiveUserInteraction(double)
 {
-    WKResourceLoadStatisticsManagerSetNotifyPagesWhenTelemetryWasCaptured(value);
 }
-    
-void TestController::setStatisticsMinimumTimeBetweenDataRecordsRemoval(double seconds)
+
+void TestController::setStatisticsTimeToLiveCookiePartitionFree(double)
 {
-    WKResourceLoadStatisticsManagerSetMinimumTimeBetweenDataRecordsRemoval(seconds);
 }
 
-void TestController::setStatisticsGrandfatheringTime(double seconds)
+void TestController::statisticsFireDataModificationHandler()
 {
-    WKResourceLoadStatisticsManagerSetGrandfatheringTime(seconds);
 }
 
-void TestController::statisticsClearInMemoryAndPersistentStore()
+void TestController::statisticsFireShouldPartitionCookiesHandler()
 {
-    WKResourceLoadStatisticsManagerClearInMemoryAndPersistentStore();
 }
 
-void TestController::statisticsClearInMemoryAndPersistentStoreModifiedSinceHours(unsigned hours)
+void TestController::statisticsFireShouldPartitionCookiesHandlerForOneDomain(WKStringRef, bool)
 {
-    WKResourceLoadStatisticsManagerClearInMemoryAndPersistentStoreModifiedSinceHours(hours);
 }
-    
-void TestController::statisticsResetToConsistentState()
+
+void TestController::statisticsFireTelemetryHandler()
 {
-    WKResourceLoadStatisticsManagerResetToConsistentState();
 }
 
-void TestController::terminateNetworkProcess()
+void TestController::setStatisticsNotifyPagesWhenDataRecordsWereScanned(bool)
 {
-    WKContextTerminateNetworkProcess(platformContext());
 }
 
-#if !PLATFORM(COCOA)
-void TestController::platformWillRunTest(const TestInvocation&)
+void TestController::setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(bool)
 {
 }
 
-void TestController::platformCreateWebView(WKPageConfigurationRef configuration, const TestOptions& options)
+void TestController::setStatisticsNotifyPagesWhenTelemetryWasCaptured(bool)
 {
-    m_mainWebView = std::make_unique<PlatformWebView>(configuration, options);
 }
 
-PlatformWebView* TestController::platformCreateOtherPage(PlatformWebView* parentView, WKPageConfigurationRef configuration, const TestOptions& options)
+void TestController::setStatisticsMinimumTimeBetweenDataRecordsRemoval(double)
 {
-    return new PlatformWebView(configuration, options);
 }
 
-WKContextRef TestController::platformAdjustContext(WKContextRef context, WKContextConfigurationRef contextConfiguration)
+void TestController::setStatisticsGrandfatheringTime(double)
 {
-    return context;
 }
 
-void TestController::platformResetStateToConsistentValues()
+void TestController::statisticsClearInMemoryAndPersistentStore()
 {
-
 }
 
-unsigned TestController::imageCountInGeneralPasteboard() const
+void TestController::statisticsClearInMemoryAndPersistentStoreModifiedSinceHours(unsigned)
 {
-    return 0;
 }
 
-void TestController::removeAllSessionCredentials()
+void TestController::statisticsResetToConsistentState()
 {
 }
 
index 4241e4c..783111c 100644 (file)
@@ -28,6 +28,7 @@
 
 #import "CrashReporterInfo.h"
 #import "PlatformWebView.h"
+#import "StringFunctions.h"
 #import "TestInvocation.h"
 #import "TestRunnerWKWebView.h"
 #import <Foundation/Foundation.h>
@@ -42,6 +43,7 @@
 #import <WebKit/WKWebViewConfigurationPrivate.h>
 #import <WebKit/WKWebViewPrivate.h>
 #import <WebKit/WKWebsiteDataRecordPrivate.h>
+#import <WebKit/WKWebsiteDataStorePrivate.h>
 #import <WebKit/WKWebsiteDataStoreRef.h>
 #import <WebKit/_WKProcessPoolConfiguration.h>
 #import <WebKit/_WKUserContentExtensionStore.h>
 
 namespace WTR {
 
+#if WK_API_ENABLED
+static NSString* toNSString(WKStringRef string)
+{
+    return [NSString stringWithCString:toWTFString(string).utf8().data()];
+}
+#endif
+
 static WKWebViewConfiguration *globalWebViewConfiguration;
 
 void initializeWebViewConfiguration(const char* libraryPath, WKStringRef injectedBundlePath, WKContextRef context, WKContextConfigurationRef contextConfiguration)
@@ -70,7 +79,8 @@ void initializeWebViewConfiguration(const char* libraryPath, WKStringRef injecte
     WKCookieManagerSetCookieStoragePartitioningEnabled(WKContextGetCookieManager(context), true);
 #endif
 
-    WKWebsiteDataStoreSetResourceLoadStatisticsEnabled(WKContextGetWebsiteDataStore(context), true);
+    [globalWebViewConfiguration.websiteDataStore _setResourceLoadStatisticsEnabled:YES];
+    [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsSetShouldSubmitTelemetry:NO];
 
 #if PLATFORM(IOS)
     globalWebViewConfiguration.allowsInlineMediaPlayback = YES;
@@ -211,4 +221,121 @@ void TestController::removeAllSessionCredentials()
 #endif
 }
 
+#if WK_API_ENABLED
+void TestController::setStatisticsPrevalentResource(WKStringRef hostName, bool value)
+{
+    [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsSetIsPrevalentResource:value forHost:toNSString(hostName)];
+}
+
+bool TestController::isStatisticsPrevalentResource(WKStringRef hostName)
+{
+    return [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsIsPrevalentResource:toNSString(hostName)];
+}
+
+void TestController::setStatisticsHasHadUserInteraction(WKStringRef hostName, bool value)
+{
+    [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsSetHadUserInteraction:value forHost:toNSString(hostName)];
+}
+
+bool TestController::isStatisticsHasHadUserInteraction(WKStringRef hostName)
+{
+    return [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsHadUserInteraction:toNSString(hostName)];
+}
+
+void TestController::setStatisticsGrandfathered(WKStringRef hostName, bool value)
+{
+    [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsSetIsGrandfathered:value forHost:toNSString(hostName)];
+}
+
+bool TestController::isStatisticsGrandfathered(WKStringRef hostName)
+{
+    return [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsIsGrandfathered:toNSString(hostName)];
+}
+
+void TestController::setStatisticsSubframeUnderTopFrameOrigin(WKStringRef hostName, WKStringRef topFrameHostName)
+{
+    [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsSetSubframeUnderTopFrameOrigin:toNSString(topFrameHostName) forHost:toNSString(hostName)];
+}
+
+void TestController::setStatisticsSubresourceUnderTopFrameOrigin(WKStringRef hostName, WKStringRef topFrameHostName)
+{
+    [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsSetSubresourceUnderTopFrameOrigin:toNSString(topFrameHostName) forHost:toNSString(hostName)];
+}
+
+void TestController::setStatisticsSubresourceUniqueRedirectTo(WKStringRef hostName, WKStringRef hostNameRedirectedTo)
+{
+    [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsSetSubresourceUniqueRedirectTo:toNSString(hostNameRedirectedTo) forHost:toNSString(hostName)];
+}
+
+void TestController::setStatisticsTimeToLiveUserInteraction(double seconds)
+{
+    [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsSetTimeToLiveUserInteraction:seconds];
+}
+
+void TestController::setStatisticsTimeToLiveCookiePartitionFree(double seconds)
+{
+    [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsSetTimeToLiveCookiePartitionFree:seconds];
+}
+
+void TestController::statisticsFireDataModificationHandler()
+{
+    [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsFireDataModificationHandler];
+}
+
+void TestController::statisticsFireShouldPartitionCookiesHandler()
+{
+    [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsFireShouldPartitionCookiesHandler];
+}
+
+void TestController::statisticsFireShouldPartitionCookiesHandlerForOneDomain(WKStringRef hostName, bool value)
+{
+    [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsFireShouldPartitionCookiesHandlerForOneDomain:value forHost:toNSString(hostName)];
+}
+
+void TestController::statisticsFireTelemetryHandler()
+{
+    [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsFireTelemetryHandler];
+}
+
+void TestController::setStatisticsNotifyPagesWhenDataRecordsWereScanned(bool value)
+{
+    [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsSetNotifyPagesWhenDataRecordsWereScanned:value];
+}
+
+void TestController::setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(bool value)
+{
+    [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsSetShouldClassifyResourcesBeforeDataRecordsRemoval:value];
+}
+
+void TestController::setStatisticsNotifyPagesWhenTelemetryWasCaptured(bool value)
+{
+    [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsSetNotifyPagesWhenTelemetryWasCaptured:value];
+}
+
+void TestController::setStatisticsMinimumTimeBetweenDataRecordsRemoval(double seconds)
+{
+    [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsSetMinimumTimeBetweenDataRecordsRemoval:seconds];
+}
+
+void TestController::setStatisticsGrandfatheringTime(double seconds)
+{
+    [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsSetGrandfatheringTime:seconds];
+}
+
+void TestController::statisticsClearInMemoryAndPersistentStore()
+{
+    [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsClearInMemoryAndPersistentStore];
+}
+
+void TestController::statisticsClearInMemoryAndPersistentStoreModifiedSinceHours(unsigned hours)
+{
+    [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsClearInMemoryAndPersistentStoreModifiedSinceHours:hours];
+}
+
+void TestController::statisticsResetToConsistentState()
+{
+    [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsResetToConsistentState];
+}
+#endif // WK_API_ENABLED
+
 } // namespace WTR