Changeset 234080 in webkit


Ignore:
Timestamp:
Jul 20, 2018 8:10:53 PM (6 years ago)
Author:
wilander@apple.com
Message:

Resource Load Statistics: Enable basic functionality in experimental debug mode
https://bugs.webkit.org/show_bug.cgi?id=187835
<rdar://problem/42408590>

Reviewed by Chris Dumez.

This patch makes the experimental ITP Debug Mode feature work, at least
Source/WebKit:

to a basic level. This means:

  • Debug logging on the INFO level.
  • Permanently treat 3rdpartytestwebkit.org as a prevalent resource.
  • Support manual setting of a custom permanently prevalent resource through user defaults on Cocoa platforms.
  • UIProcess/API/C/WKWebsiteDataStoreRef.cpp:

(WKWebsiteDataStoreSetResourceLoadStatisticsDebugModeWithCompletionHandler):
(WKWebsiteDataStoreSetResourceLoadStatisticsPrevalentResourceForDebugMode):

Test infrastructure.

  • UIProcess/API/C/WKWebsiteDataStoreRef.h:
  • UIProcess/Cocoa/ResourceLoadStatisticsMemoryStoreCocoa.mm:

(WebKit::ResourceLoadStatisticsMemoryStore::registerUserDefaultsIfNeeded):

Used to pick up custom set prevalent resource on Cocoa platforms (for debug mode).

  • UIProcess/ResourceLoadStatisticsMemoryStore.cpp:

(WebKit::ResourceLoadStatisticsMemoryStore::isPrevalentDueToDebugMode):
(WebKit::ResourceLoadStatisticsMemoryStore::processStatisticsAndDataRecords):

Now skips processing of debug mode prevalent resources so that they
stay prevalent.

(WebKit::ResourceLoadStatisticsMemoryStore::ensurePrevalentResourcesForDebugMode):

Convenience function to make 3rdpartytestwebkit.org and any custom domain
set through ResourceLoadStatisticsMemoryStore::setPrevalentResourceForDebugMode()
be prevalent resources.

(WebKit::ResourceLoadStatisticsMemoryStore::setResourceLoadStatisticsDebugMode):
(WebKit::ResourceLoadStatisticsMemoryStore::setPrevalentResourceForDebugMode):

Sets a custom domain to always be treated as prevalent in debug mode.

(WebKit::ResourceLoadStatisticsMemoryStore::clear):

Now makes sure 3rdpartytestwebkit.org and any custom domain set through
ResourceLoadStatisticsMemoryStore::setPrevalentResourceForDebugMode()
are prevalent resources even after a clear of the store.

(WebKit::debugLogDomainsInBatches):

We may have too many domain names to fit in a single log statement.
This function logs them in batches of 50, if we have more than 50.

(WebKit::ResourceLoadStatisticsMemoryStore::updateCookiePartitioning):

Now makes use of debugLogDomainsInBatches() in debug mode.

  • UIProcess/ResourceLoadStatisticsMemoryStore.h:

(WebKit::ResourceLoadStatisticsMemoryStore::isDebugModeEnabled const):

  • UIProcess/ResourceLoadStatisticsPersistentStorage.cpp:

(WebKit::ResourceLoadStatisticsPersistentStorage::populateMemoryStoreFromDisk):

Now accepts a non-empty memory store in debug mode. This is to support a
pre-populated store with 3rdpartytestwebkit.org and any custom domain already
set as prevalent.

(WebKit::ResourceLoadStatisticsPersistentStorage::setResourceLoadStatisticsDebugMode):

  • UIProcess/WebResourceLoadStatisticsStore.cpp:

(WebKit::WebResourceLoadStatisticsStore::setResourceLoadStatisticsDebugMode):
(WebKit::WebResourceLoadStatisticsStore::setPrevalentResourceForDebugMode):

  • UIProcess/WebResourceLoadStatisticsStore.h:
  • UIProcess/WebsiteData/WebsiteDataStore.cpp:

(WebKit::WebsiteDataStore::setResourceLoadStatisticsDebugMode):

  • UIProcess/WebsiteData/WebsiteDataStore.h:

Tools:

to a basic level. All of the changes to TestRunner are to support the
layout tests for the functionality.

  • WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
  • WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:

(WTR::InjectedBundle::didReceiveMessageToPage):

  • WebKitTestRunner/InjectedBundle/TestRunner.cpp:

(WTR::TestRunner::setStatisticsDebugMode):
(WTR::TestRunner::statisticsCallDidSetDebugModeCallback):
(WTR::TestRunner::setStatisticsPrevalentResourceForDebugMode):
(WTR::TestRunner::statisticsCallDidSetPrevalentResourceForDebugModeCallback):

  • WebKitTestRunner/InjectedBundle/TestRunner.h:
  • WebKitTestRunner/TestController.cpp:

(WTR::TestController::setStatisticsDebugMode):
(WTR::TestController::setStatisticsPrevalentResourceForDebugMode):

  • WebKitTestRunner/TestController.h:
  • WebKitTestRunner/TestInvocation.cpp:

(WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):
(WTR::TestInvocation::didSetStatisticsDebugMode):
(WTR::TestInvocation::didSetPrevalentResourceForDebugMode):

  • WebKitTestRunner/TestInvocation.h:

LayoutTests:

to a basic level.

  • http/tests/resourceLoadStatistics/enable-debug-mode-expected.txt: Added.
  • http/tests/resourceLoadStatistics/enable-debug-mode.html: Added.
  • http/tests/resourceLoadStatistics/set-custom-prevalent-resource-in-debug-mode-expected.txt: Added.
  • http/tests/resourceLoadStatistics/set-custom-prevalent-resource-in-debug-mode.html: Added.
Location:
trunk
Files:
4 added
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r234077 r234080  
     12018-07-20  John Wilander  <wilander@apple.com>
     2
     3        Resource Load Statistics: Enable basic functionality in experimental debug mode
     4        https://bugs.webkit.org/show_bug.cgi?id=187835
     5        <rdar://problem/42408590>
     6
     7        Reviewed by Chris Dumez.
     8
     9        This patch makes the experimental ITP Debug Mode feature work, at least
     10        to a basic level.
     11
     12        * http/tests/resourceLoadStatistics/enable-debug-mode-expected.txt: Added.
     13        * http/tests/resourceLoadStatistics/enable-debug-mode.html: Added.
     14        * http/tests/resourceLoadStatistics/set-custom-prevalent-resource-in-debug-mode-expected.txt: Added.
     15        * http/tests/resourceLoadStatistics/set-custom-prevalent-resource-in-debug-mode.html: Added.
     16
    1172018-07-20  Sihui Liu  <sihui_liu@apple.com>
    218
  • trunk/Source/WebKit/ChangeLog

    r234067 r234080  
     12018-07-20  John Wilander  <wilander@apple.com>
     2
     3        Resource Load Statistics: Enable basic functionality in experimental debug mode
     4        https://bugs.webkit.org/show_bug.cgi?id=187835
     5        <rdar://problem/42408590>
     6
     7        Reviewed by Chris Dumez.
     8
     9        This patch makes the experimental ITP Debug Mode feature work, at least
     10        to a basic level. This means:
     11        - Debug logging on the INFO level.
     12        - Permanently treat 3rdpartytestwebkit.org as a prevalent resource.
     13        - Support manual setting of a custom permanently prevalent resource through user
     14          defaults on Cocoa platforms.
     15
     16        * UIProcess/API/C/WKWebsiteDataStoreRef.cpp:
     17        (WKWebsiteDataStoreSetResourceLoadStatisticsDebugModeWithCompletionHandler):
     18        (WKWebsiteDataStoreSetResourceLoadStatisticsPrevalentResourceForDebugMode):
     19            Test infrastructure.
     20        * UIProcess/API/C/WKWebsiteDataStoreRef.h:
     21        * UIProcess/Cocoa/ResourceLoadStatisticsMemoryStoreCocoa.mm:
     22        (WebKit::ResourceLoadStatisticsMemoryStore::registerUserDefaultsIfNeeded):
     23            Used to pick up custom set prevalent resource on Cocoa platforms (for debug mode).
     24        * UIProcess/ResourceLoadStatisticsMemoryStore.cpp:
     25        (WebKit::ResourceLoadStatisticsMemoryStore::isPrevalentDueToDebugMode):
     26        (WebKit::ResourceLoadStatisticsMemoryStore::processStatisticsAndDataRecords):
     27            Now skips processing of debug mode prevalent resources so that they
     28            stay prevalent.
     29        (WebKit::ResourceLoadStatisticsMemoryStore::ensurePrevalentResourcesForDebugMode):
     30            Convenience function to make 3rdpartytestwebkit.org and any custom domain
     31            set through ResourceLoadStatisticsMemoryStore::setPrevalentResourceForDebugMode()
     32            be prevalent resources.
     33        (WebKit::ResourceLoadStatisticsMemoryStore::setResourceLoadStatisticsDebugMode):
     34        (WebKit::ResourceLoadStatisticsMemoryStore::setPrevalentResourceForDebugMode):
     35            Sets a custom domain to always be treated as prevalent in debug mode.
     36        (WebKit::ResourceLoadStatisticsMemoryStore::clear):
     37            Now makes sure 3rdpartytestwebkit.org and any custom domain set through
     38            ResourceLoadStatisticsMemoryStore::setPrevalentResourceForDebugMode()
     39            are prevalent resources even after a clear of the store.
     40        (WebKit::debugLogDomainsInBatches):
     41            We may have too many domain names to fit in a single log statement.
     42            This function logs them in batches of 50, if we have more than 50.
     43        (WebKit::ResourceLoadStatisticsMemoryStore::updateCookiePartitioning):
     44            Now makes use of debugLogDomainsInBatches() in debug mode.
     45        * UIProcess/ResourceLoadStatisticsMemoryStore.h:
     46        (WebKit::ResourceLoadStatisticsMemoryStore::isDebugModeEnabled const):
     47        * UIProcess/ResourceLoadStatisticsPersistentStorage.cpp:
     48        (WebKit::ResourceLoadStatisticsPersistentStorage::populateMemoryStoreFromDisk):
     49            Now accepts a non-empty memory store in debug mode. This is to support a
     50            pre-populated store with 3rdpartytestwebkit.org and any custom domain already
     51            set as prevalent.
     52        (WebKit::ResourceLoadStatisticsPersistentStorage::setResourceLoadStatisticsDebugMode):
     53        * UIProcess/WebResourceLoadStatisticsStore.cpp:
     54        (WebKit::WebResourceLoadStatisticsStore::setResourceLoadStatisticsDebugMode):
     55        (WebKit::WebResourceLoadStatisticsStore::setPrevalentResourceForDebugMode):
     56        * UIProcess/WebResourceLoadStatisticsStore.h:
     57        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
     58        (WebKit::WebsiteDataStore::setResourceLoadStatisticsDebugMode):
     59        * UIProcess/WebsiteData/WebsiteDataStore.h:
     60
    1612018-07-20  Tim Horton  <timothy_horton@apple.com>
    262
  • trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp

    r233888 r234080  
    7070}
    7171
     72void WKWebsiteDataStoreSetResourceLoadStatisticsDebugModeWithCompletionHandler(WKWebsiteDataStoreRef dataStoreRef, bool enable, void* context, WKWebsiteDataStoreStatisticsDebugModeFunction completionHandler)
     73{
     74    auto* store = WebKit::toImpl(dataStoreRef)->websiteDataStore().resourceLoadStatistics();
     75    if (!store) {
     76        completionHandler(context);
     77        return;
     78    }
     79   
     80    store->setResourceLoadStatisticsDebugMode(enable, [context, completionHandler] {
     81        completionHandler(context);
     82    });
     83}
     84
     85void WKWebsiteDataStoreSetResourceLoadStatisticsPrevalentResourceForDebugMode(WKWebsiteDataStoreRef dataStoreRef, WKStringRef host, void* context, WKWebsiteDataStoreStatisticsDebugModeFunction completionHandler)
     86{
     87    auto* store = WebKit::toImpl(dataStoreRef)->websiteDataStore().resourceLoadStatistics();
     88    if (!store) {
     89        completionHandler(context);
     90        return;
     91    }
     92   
     93    store->setPrevalentResourceForDebugMode(WebCore::URL(WebCore::URL(), WebKit::toImpl(host)->string()), [context, completionHandler] {
     94        completionHandler(context);
     95    });
     96}
    7297void WKWebsiteDataStoreSetStatisticsLastSeen(WKWebsiteDataStoreRef dataStoreRef, WKStringRef host, double seconds, void* context, WKWebsiteDataStoreStatisticsLastSeenFunction completionHandler)
    7398{
  • trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h

    r233888 r234080  
    4141WK_EXPORT void WKWebsiteDataStoreSetResourceLoadStatisticsEnabled(WKWebsiteDataStoreRef dataStoreRef, bool enable);
    4242WK_EXPORT void WKWebsiteDataStoreSetResourceLoadStatisticsDebugMode(WKWebsiteDataStoreRef dataStoreRef, bool enable);
     43typedef void (*WKWebsiteDataStoreStatisticsDebugModeFunction)(void* functionContext);
     44WK_EXPORT void WKWebsiteDataStoreSetResourceLoadStatisticsDebugModeWithCompletionHandler(WKWebsiteDataStoreRef dataStoreRef, bool enable, void* context, WKWebsiteDataStoreStatisticsDebugModeFunction completionHandler);
     45WK_EXPORT void WKWebsiteDataStoreSetResourceLoadStatisticsPrevalentResourceForDebugMode(WKWebsiteDataStoreRef dataStoreRef, WKStringRef host, void* context, WKWebsiteDataStoreStatisticsDebugModeFunction completionHandler);   
    4346typedef void (*WKWebsiteDataStoreStatisticsLastSeenFunction)(void* functionContext);
    4447WK_EXPORT void WKWebsiteDataStoreSetStatisticsLastSeen(WKWebsiteDataStoreRef dataStoreRef, WKStringRef host, double seconds, void* context, WKWebsiteDataStoreStatisticsLastSeenFunction completionHandler);
  • trunk/Source/WebKit/UIProcess/Cocoa/ResourceLoadStatisticsMemoryStoreCocoa.mm

    r233310 r234080  
    2626#import "config.h"
    2727#import "ResourceLoadStatisticsMemoryStore.h"
     28#import <wtf/text/WTFString.h>
    2829
    2930namespace WebKit {
     
    5253        setDebugLogggingEnabled([[NSUserDefaults standardUserDefaults] boolForKey:@"ResourceLoadStatisticsDebugLoggingEnabled"]);
    5354        setResourceLoadStatisticsDebugMode([[NSUserDefaults standardUserDefaults] boolForKey:@"ExperimentalResourceLoadStatisticsDebugMode"]);
     55        auto* debugManualPrevalentResource = [[NSUserDefaults standardUserDefaults] stringForKey:@"ResourceLoadStatisticsManualPrevalentResource"];
     56        if (debugManualPrevalentResource)
     57            setPrevalentResourceForDebugMode(debugManualPrevalentResource);
    5458        setStorageAccessPromptsEnabled([[NSUserDefaults standardUserDefaults] boolForKey:@"ExperimentalStorageAccessPromptsEnabled"]);
    5559    });
  • trunk/Source/WebKit/UIProcess/ResourceLoadStatisticsMemoryStore.cpp

    r234020 r234080  
    5252constexpr unsigned operatingDatesWindow { 30 };
    5353constexpr unsigned maxImportance { 3 };
     54static const char* debugStaticPrevalentResource { "3rdpartytestwebkit.org" };
    5455
    5556#if !RELEASE_LOG_DISABLED
     
    320321}
    321322
     323bool ResourceLoadStatisticsMemoryStore::isPrevalentDueToDebugMode(ResourceLoadStatistics& resourceStatistic)
     324{
     325    if (!m_debugModeEnabled)
     326        return false;
     327
     328    return resourceStatistic.highLevelDomain == debugStaticPrevalentResource || resourceStatistic.highLevelDomain == m_debugManualPrevalentResource;
     329}
     330
    322331void ResourceLoadStatisticsMemoryStore::processStatisticsAndDataRecords()
    323332{
     
    326335    if (m_parameters.shouldClassifyResourcesBeforeDataRecordsRemoval) {
    327336        for (auto& resourceStatistic : m_resourceStatisticsMap.values()) {
    328             if (!resourceStatistic.isVeryPrevalentResource) {
     337            if (isPrevalentDueToDebugMode(resourceStatistic))
     338                setPrevalentResource(resourceStatistic, ResourceLoadPrevalence::High);
     339            else if (!resourceStatistic.isVeryPrevalentResource) {
    329340                markAsPrevalentIfHasRedirectedToPrevalent(resourceStatistic);
    330341                auto currentPrevalence = resourceStatistic.isPrevalentResource ? ResourceLoadPrevalence::High : ResourceLoadPrevalence::Low;
     
    508519}
    509520
     521Vector<String> ResourceLoadStatisticsMemoryStore::ensurePrevalentResourcesForDebugMode()
     522{
     523    if (!m_debugModeEnabled)
     524        return { };
     525
     526    Vector<String> primaryDomainsToBlock;
     527    primaryDomainsToBlock.reserveInitialCapacity(2);
     528
     529    auto& staticSesourceStatistic = ensureResourceStatisticsForPrimaryDomain(debugStaticPrevalentResource);
     530    setPrevalentResource(staticSesourceStatistic, ResourceLoadPrevalence::High);
     531    primaryDomainsToBlock.uncheckedAppend(debugStaticPrevalentResource);
     532
     533    if (!m_debugManualPrevalentResource.isEmpty()) {
     534        auto& manualResourceStatistic = ensureResourceStatisticsForPrimaryDomain(m_debugManualPrevalentResource);
     535        setPrevalentResource(manualResourceStatistic, ResourceLoadPrevalence::High);
     536        primaryDomainsToBlock.uncheckedAppend(m_debugManualPrevalentResource);
     537    }
     538   
     539    return primaryDomainsToBlock;
     540}
     541
    510542void ResourceLoadStatisticsMemoryStore::setResourceLoadStatisticsDebugMode(bool enable)
    511543{
     
    513545
    514546    m_debugModeEnabled = enable;
     547    m_debugLoggingEnabled = enable;
     548
     549    ensurePrevalentResourcesForDebugMode();
     550}
     551
     552void ResourceLoadStatisticsMemoryStore::setPrevalentResourceForDebugMode(const String& domain)
     553{
     554    if (!m_debugModeEnabled)
     555        return;
     556
     557    m_debugManualPrevalentResource = domain;
     558    auto& resourceStatistic = ensureResourceStatisticsForPrimaryDomain(domain);
     559    setPrevalentResource(resourceStatistic, ResourceLoadPrevalence::High);
     560
    515561#if !RELEASE_LOG_DISABLED
    516     RELEASE_LOG_INFO_IF(m_debugLoggingEnabled, ResourceLoadStatisticsDebug, "ITP Debug Mode %{public}s.", (m_debugModeEnabled ? "enabled" : "disabled"));
     562    RELEASE_LOG_INFO(ResourceLoadStatisticsDebug, "Did set %{public}s as prevalent resource for the purposes of ITP Debug Mode.", domain.utf8().data());
    517563#endif
    518564}
     
    892938
    893939    removeAllStorageAccess();
    894     updateCookiePartitioningForDomains({ }, { }, { }, ShouldClearFirst::Yes, []() { });
     940
     941    auto primaryDomainsToBlock = ensurePrevalentResourcesForDebugMode();
     942    updateCookiePartitioningForDomains({ }, primaryDomainsToBlock, { }, ShouldClearFirst::Yes, []() { });
    895943}
    896944
     
    934982{
    935983    return statistic.storageAccessUnderTopFrameOrigins.contains(firstPartyPrimaryDomain);
     984}
     985
     986static void debugLogDomainsInBatches(const char* action, const Vector<String>& domains)
     987{
     988#if !RELEASE_LOG_DISABLED
     989    static const auto maxNumberOfDomainsInOneLogStatement = 50;
     990    if (domains.isEmpty())
     991        return;
     992
     993    if (domains.size() <= maxNumberOfDomainsInOneLogStatement) {
     994        RELEASE_LOG_INFO(ResourceLoadStatisticsDebug, "About to %{public}s cookies in third-party contexts for: %{public}s.", action, domainsToString(domains).utf8().data());
     995        return;
     996    }
     997   
     998    Vector<String> batch;
     999    batch.reserveInitialCapacity(maxNumberOfDomainsInOneLogStatement);
     1000    auto batchNumber = 1;
     1001    unsigned numberOfBatches = std::ceil(domains.size() / static_cast<float>(maxNumberOfDomainsInOneLogStatement));
     1002
     1003    for (auto& domain : domains) {
     1004        if (batch.size() == maxNumberOfDomainsInOneLogStatement) {
     1005            RELEASE_LOG_INFO(ResourceLoadStatisticsDebug, "About to %{public}s cookies in third-party contexts for (%{public}d of %u): %{public}s.", action, batchNumber, numberOfBatches, domainsToString(batch).utf8().data());
     1006            batch.shrink(0);
     1007            ++batchNumber;
     1008        }
     1009        batch.append(domain);
     1010    }
     1011    if (!batch.isEmpty())
     1012        RELEASE_LOG_INFO(ResourceLoadStatisticsDebug, "About to %{public}s cookies in third-party contexts for (%{public}d of %u): %{public}s.", action, batchNumber, numberOfBatches, domainsToString(batch).utf8().data());
     1013#else
     1014    UNUSED_PARAM(action);
     1015    UNUSED_PARAM(domains);
     1016#endif
    9361017}
    9371018
     
    9661047    }
    9671048
    968 #if !RELEASE_LOG_DISABLED
    9691049    if (m_debugLoggingEnabled) {
    9701050        if (!domainsToPartition.isEmpty())
    971             RELEASE_LOG_INFO(ResourceLoadStatisticsDebug, "About to partition cookies in third-party contexts for %{public}s.", domainsToString(domainsToPartition).utf8().data());
     1051            debugLogDomainsInBatches("partition", domainsToPartition);
    9721052        if (!domainsToBlock.isEmpty())
    973             RELEASE_LOG_INFO(ResourceLoadStatisticsDebug, "About to block cookies in third-party contexts for %{public}s.", domainsToString(domainsToBlock).utf8().data());
     1053            debugLogDomainsInBatches("block", domainsToBlock);
    9741054        if (!domainsToNeitherPartitionNorBlock.isEmpty())
    975             RELEASE_LOG_INFO(ResourceLoadStatisticsDebug, "About to neither partition nor block cookies in third-party contexts for %{public}s.", domainsToString(domainsToNeitherPartitionNorBlock).utf8().data());
    976     }
    977 #endif
     1055            debugLogDomainsInBatches("neither partition nor block", domainsToNeitherPartitionNorBlock);
     1056    }
    9781057
    9791058    RunLoop::main().dispatch([this, store = makeRef(m_store), domainsToPartition = crossThreadCopy(domainsToPartition), domainsToBlock = crossThreadCopy(domainsToBlock), domainsToNeitherPartitionNorBlock = crossThreadCopy(domainsToNeitherPartitionNorBlock), completionHandler = WTFMove(completionHandler)] () mutable {
  • trunk/Source/WebKit/UIProcess/ResourceLoadStatisticsMemoryStore.h

    r233310 r234080  
    114114    void setGrandfatheringTime(Seconds);
    115115    void setResourceLoadStatisticsDebugMode(bool);
     116    bool isDebugModeEnabled() const { return m_debugModeEnabled; };
     117    void setPrevalentResourceForDebugMode(const String& domain);
    116118
    117119    void hasStorageAccess(const String& subFramePrimaryDomain, const String& topFramePrimaryDomain, uint64_t frameID, uint64_t pageID, CompletionHandler<void(bool)>&&);
     
    144146    void grantStorageAccessInternal(String&& subFrameHost, String&& topFrameHost, std::optional<uint64_t> frameID, uint64_t pageID, bool userWasPromptedNowOrEarlier, CompletionHandler<void(bool)>&&);
    145147    void markAsPrevalentIfHasRedirectedToPrevalent(WebCore::ResourceLoadStatistics&);
     148    bool isPrevalentDueToDebugMode(WebCore::ResourceLoadStatistics&);
     149    Vector<String> ensurePrevalentResourcesForDebugMode();
    146150    void removeDataRecords(CompletionHandler<void()>&&);
    147151    void pruneStatisticsIfNeeded();
     
    182186    bool m_debugLoggingEnabled { false };
    183187    bool m_debugModeEnabled { false };
     188    String m_debugManualPrevalentResource;
    184189    bool m_storageAccessPromptsEnabled { false };
    185190    bool m_dataRecordsBeingRemoved { false };
  • trunk/Source/WebKit/UIProcess/ResourceLoadStatisticsPersistentStorage.cpp

    r233367 r234080  
    236236    }
    237237
    238     ASSERT_WITH_MESSAGE(m_memoryStore.isEmpty(), "This is the initial import so the store should be empty");
     238    // Debug mode has a prepoulated memory store.
     239    ASSERT_WITH_MESSAGE(m_memoryStore.isEmpty() || m_memoryStore.isDebugModeEnabled(), "This is the initial import so the store should be empty");
    239240    m_memoryStore.mergeWithDataFromDecoder(*decoder);
    240241
  • trunk/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.cpp

    r233888 r234080  
    170170}
    171171
    172 void WebResourceLoadStatisticsStore::setResourceLoadStatisticsDebugMode(bool value)
    173 {
    174     ASSERT(RunLoop::isMain());
    175 
    176     postTask([this, value] {
     172void WebResourceLoadStatisticsStore::setResourceLoadStatisticsDebugMode(bool value, CompletionHandler<void()>&& completionHandler)
     173{
     174    ASSERT(RunLoop::isMain());
     175
     176    postTask([this, value, completionHandler = WTFMove(completionHandler)]() mutable {
    177177        if (m_memoryStore)
    178178            m_memoryStore->setResourceLoadStatisticsDebugMode(value);
     179        postTaskReply([completionHandler = WTFMove(completionHandler)] {
     180            completionHandler();
     181        });
     182    });
     183}
     184
     185void WebResourceLoadStatisticsStore::setPrevalentResourceForDebugMode(const WebCore::URL& url, CompletionHandler<void()>&& completionHandler)
     186{
     187    ASSERT(RunLoop::isMain());
     188
     189    postTask([this, primaryDomain = isolatedPrimaryDomain(url), completionHandler = WTFMove(completionHandler)]() mutable {
     190        if (m_memoryStore)
     191            m_memoryStore->setPrevalentResourceForDebugMode(primaryDomain);
     192        postTaskReply([completionHandler = WTFMove(completionHandler)] {
     193            completionHandler();
     194        });
    179195    });
    180196}
  • trunk/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.h

    r233888 r234080  
    133133    void resetParametersToDefaultValues(CompletionHandler<void()>&&);
    134134
    135     void setResourceLoadStatisticsDebugMode(bool);
    136 
     135    void setResourceLoadStatisticsDebugMode(bool, CompletionHandler<void()>&&);
     136    void setPrevalentResourceForDebugMode(const WebCore::URL&, CompletionHandler<void()>&&);
     137   
    137138    void setStatisticsTestingCallback(WTF::Function<void(const String&)>&& callback) { m_statisticsTestingCallback = WTFMove(callback); }
    138139    void logTestingEvent(const String&);
  • trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp

    r233538 r234080  
    15091509void WebsiteDataStore::setResourceLoadStatisticsDebugMode(bool enabled)
    15101510{
     1511    setResourceLoadStatisticsDebugMode(enabled, []() { });
     1512}
     1513
     1514void WebsiteDataStore::setResourceLoadStatisticsDebugMode(bool enabled, CompletionHandler<void()>&& completionHandler)
     1515{
    15111516    m_resourceLoadStatisticsDebugMode = enabled;
    15121517    if (m_resourceLoadStatistics)
    1513         m_resourceLoadStatistics->setResourceLoadStatisticsDebugMode(enabled);
     1518        m_resourceLoadStatistics->setResourceLoadStatisticsDebugMode(enabled, WTFMove(completionHandler));
     1519    else
     1520        completionHandler();
    15141521}
    15151522
  • trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h

    r233468 r234080  
    110110    bool resourceLoadStatisticsDebugMode() const;
    111111    void setResourceLoadStatisticsDebugMode(bool);
     112    void setResourceLoadStatisticsDebugMode(bool, CompletionHandler<void()>&&);
    112113
    113114    uint64_t cacheStoragePerOriginQuota() const { return m_resolvedConfiguration.cacheStoragePerOriginQuota; }
  • trunk/Tools/ChangeLog

    r234064 r234080  
     12018-07-20  John Wilander  <wilander@apple.com>
     2
     3        Resource Load Statistics: Enable basic functionality in experimental debug mode
     4        https://bugs.webkit.org/show_bug.cgi?id=187835
     5        <rdar://problem/42408590>
     6
     7        Reviewed by Chris Dumez.
     8
     9        This patch makes the experimental ITP Debug Mode feature work, at least
     10        to a basic level. All of the changes to TestRunner are to support the
     11        layout tests for the functionality.
     12
     13        * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
     14        * WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
     15        (WTR::InjectedBundle::didReceiveMessageToPage):
     16        * WebKitTestRunner/InjectedBundle/TestRunner.cpp:
     17        (WTR::TestRunner::setStatisticsDebugMode):
     18        (WTR::TestRunner::statisticsCallDidSetDebugModeCallback):
     19        (WTR::TestRunner::setStatisticsPrevalentResourceForDebugMode):
     20        (WTR::TestRunner::statisticsCallDidSetPrevalentResourceForDebugModeCallback):
     21        * WebKitTestRunner/InjectedBundle/TestRunner.h:
     22        * WebKitTestRunner/TestController.cpp:
     23        (WTR::TestController::setStatisticsDebugMode):
     24        (WTR::TestController::setStatisticsPrevalentResourceForDebugMode):
     25        * WebKitTestRunner/TestController.h:
     26        * WebKitTestRunner/TestInvocation.cpp:
     27        (WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):
     28        (WTR::TestInvocation::didSetStatisticsDebugMode):
     29        (WTR::TestInvocation::didSetPrevalentResourceForDebugMode):
     30        * WebKitTestRunner/TestInvocation.h:
     31
    1322018-07-20  Ryosuke Niwa  <rniwa@apple.com>
    233
  • trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl

    r234064 r234080  
    273273    void installStatisticsDidScanDataRecordsCallback(object callback);
    274274    void installStatisticsDidRunTelemetryCallback(object callback);
     275    void setStatisticsDebugMode(boolean value, object completionHandler);
     276    void setStatisticsPrevalentResourceForDebugMode(DOMString hostName, object completionHandler);
    275277    void setStatisticsLastSeen(DOMString hostName, double seconds, object completionHandler);
    276278    void setStatisticsPrevalentResource(DOMString hostName, boolean value, object completionHandler);
  • trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp

    r233941 r234080  
    316316    }
    317317
     318    if (WKStringIsEqualToUTF8CString(messageName, "CallDidSetStatisticsDebugMode")) {
     319        m_testRunner->statisticsCallDidSetDebugModeCallback();
     320        return;
     321    }
     322   
     323    if (WKStringIsEqualToUTF8CString(messageName, "CallDidSetPrevalentResourceForDebugMode")) {
     324        m_testRunner->statisticsCallDidSetPrevalentResourceForDebugModeCallback();
     325        return;
     326    }
     327   
    318328    if (WKStringIsEqualToUTF8CString(messageName, "CallDidSetLastSeen")) {
    319329        m_testRunner->statisticsCallDidSetLastSeenCallback();
  • trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp

    r234064 r234080  
    737737    DidEndSwipeCallbackID,
    738738    DidRemoveSwipeSnapshotCallbackID,
     739    SetStatisticsDebugModeCallbackID,
     740    SetStatisticsPrevalentResourceForDebugModeCallbackID,
    739741    SetStatisticsLastSeenCallbackID,
    740742    SetStatisticsPrevalentResourceCallbackID,
     
    13321334}
    13331335
     1336void TestRunner::setStatisticsDebugMode(bool value, JSValueRef completionHandler)
     1337{
     1338    cacheTestRunnerCallback(SetStatisticsDebugModeCallbackID, completionHandler);
     1339
     1340    WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetStatisticsDebugMode"));
     1341    WKRetainPtr<WKBooleanRef> messageBody(AdoptWK, WKBooleanCreate(value));
     1342    WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr);
     1343
     1344}
     1345
     1346void TestRunner::statisticsCallDidSetDebugModeCallback()
     1347{
     1348    callTestRunnerCallback(SetStatisticsDebugModeCallbackID);
     1349}
     1350
     1351void TestRunner::setStatisticsPrevalentResourceForDebugMode(JSStringRef hostName, JSValueRef completionHandler)
     1352{
     1353    cacheTestRunnerCallback(SetStatisticsPrevalentResourceForDebugModeCallbackID, completionHandler);
     1354   
     1355    WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetStatisticsPrevalentResourceForDebugMode"));
     1356    WKRetainPtr<WKStringRef> messageBody(AdoptWK, WKStringCreateWithJSString(hostName));
     1357    WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr);
     1358}
     1359
     1360void TestRunner::statisticsCallDidSetPrevalentResourceForDebugModeCallback()
     1361{
     1362    callTestRunnerCallback(SetStatisticsPrevalentResourceForDebugModeCallbackID);
     1363}
     1364
    13341365void TestRunner::setStatisticsLastSeen(JSStringRef hostName, double seconds, JSValueRef completionHandler)
    13351366{
     
    13631394    callTestRunnerCallback(SetStatisticsLastSeenCallbackID);
    13641395}
    1365 
    13661396
    13671397void TestRunner::setStatisticsPrevalentResource(JSStringRef hostName, bool value, JSValueRef completionHandler)
  • trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h

    r234064 r234080  
    383383    void statisticsCallDidSetPartitionOrBlockCookiesForHostCallback();
    384384    void statisticsSubmitTelemetry();
     385    void setStatisticsDebugMode(bool value, JSValueRef completionHandler);
     386    void statisticsCallDidSetDebugModeCallback();
     387    void setStatisticsPrevalentResourceForDebugMode(JSStringRef hostName, JSValueRef completionHandler);
     388    void statisticsCallDidSetPrevalentResourceForDebugModeCallback();
    385389    void setStatisticsLastSeen(JSStringRef hostName, double seconds, JSValueRef completionHandler);
    386390    void statisticsCallDidSetLastSeenCallback();
  • trunk/Tools/WebKitTestRunner/TestController.cpp

    r233888 r234080  
    26462646    context->testController.notifyDone();
    26472647}
    2648    
     2648
     2649void TestController::setStatisticsDebugMode(bool value)
     2650{
     2651    auto* dataStore = WKContextGetWebsiteDataStore(platformContext());
     2652    ResourceStatisticsCallbackContext context(*this);
     2653    WKWebsiteDataStoreSetResourceLoadStatisticsDebugModeWithCompletionHandler(dataStore, value, &context, resourceStatisticsVoidResultCallback);
     2654    runUntil(context.done, noTimeout);
     2655    m_currentInvocation->didSetStatisticsDebugMode();
     2656}
     2657
     2658void TestController::setStatisticsPrevalentResourceForDebugMode(WKStringRef hostName)
     2659{
     2660    auto* dataStore = WKContextGetWebsiteDataStore(platformContext());
     2661    ResourceStatisticsCallbackContext context(*this);
     2662    WKWebsiteDataStoreSetResourceLoadStatisticsPrevalentResourceForDebugMode(dataStore, hostName, &context, resourceStatisticsVoidResultCallback);
     2663    runUntil(context.done, noTimeout);
     2664    m_currentInvocation->didSetPrevalentResourceForDebugMode();
     2665}
     2666
    26492667void TestController::setStatisticsLastSeen(WKStringRef host, double seconds)
    26502668{
  • trunk/Tools/WebKitTestRunner/TestController.h

    r233782 r234080  
    157157    void setShouldDownloadUndisplayableMIMETypes(bool value) { m_shouldDownloadUndisplayableMIMETypes = value; }
    158158
     159    void setStatisticsDebugMode(bool value);
     160    void setStatisticsPrevalentResourceForDebugMode(WKStringRef hostName);
    159161    void setStatisticsLastSeen(WKStringRef hostName, double seconds);
    160162    void setStatisticsPrevalentResource(WKStringRef hostName, bool value);
  • trunk/Tools/WebKitTestRunner/TestInvocation.cpp

    r233888 r234080  
    10371037    }
    10381038
     1039    if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsDebugMode")) {
     1040        ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
     1041        WKBooleanRef value = static_cast<WKBooleanRef>(messageBody);
     1042        TestController::singleton().setStatisticsDebugMode(WKBooleanGetValue(value));
     1043        return nullptr;
     1044    }
     1045   
     1046    if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsPrevalentResourceForDebugMode")) {
     1047        ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
     1048        WKStringRef hostName = static_cast<WKStringRef>(messageBody);
     1049        TestController::singleton().setStatisticsPrevalentResourceForDebugMode(hostName);
     1050        return nullptr;
     1051    }
     1052   
    10391053    if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsLastSeen")) {
    10401054        ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
     
    15281542}
    15291543
     1544void TestInvocation::didSetStatisticsDebugMode()
     1545{
     1546    WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetStatisticsDebugMode"));
     1547    WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
     1548}
     1549
     1550void TestInvocation::didSetPrevalentResourceForDebugMode()
     1551{
     1552    WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetPrevalentResourceForDebugMode"));
     1553    WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
     1554}
     1555
    15301556void TestInvocation::didSetLastSeen()
    15311557{
  • trunk/Tools/WebKitTestRunner/TestInvocation.h

    r233888 r234080  
    7575    void didResetStatisticsToConsistentState();
    7676    void didSetPartitionOrBlockCookiesForHost();
     77    void didSetStatisticsDebugMode();
     78    void didSetPrevalentResourceForDebugMode();
    7779    void didSetLastSeen();
    7880    void didSetPrevalentResource();
Note: See TracChangeset for help on using the changeset viewer.