⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 242712 in webkit


Ignore:
Timestamp:
Mar 11, 2019, 10:01:27 AM (7 years ago)
Author:
wilander@apple.com
Message:

Resource Load Statistics: Make it possible exclude localhost from classification
https://bugs.webkit.org/show_bug.cgi?id=195474
<rdar://problem/47520577>

Reviewed by Brent Fulgham.

Source/WebKit:

This patch allows for localhost to be excluded from classification and
treatment as a prevalent resource.

  • NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp:

(WebKit::ResourceLoadStatisticsDatabaseStore::ResourceLoadStatisticsDatabaseStore):
(WebKit::ResourceLoadStatisticsDatabaseStore::reclassifyResources):

Makes use of the new ResourceLoadStatisticsMemoryStore::shouldSkip().

(WebKit::ResourceLoadStatisticsDatabaseStore::setPrevalentResource):

Makes use of the new ResourceLoadStatisticsMemoryStore::shouldSkip().

(WebKit::ResourceLoadStatisticsDatabaseStore::isPrevalentResource const):

Makes use of the new ResourceLoadStatisticsMemoryStore::shouldSkip().

(WebKit::ResourceLoadStatisticsDatabaseStore::isVeryPrevalentResource const):

Makes use of the new ResourceLoadStatisticsMemoryStore::shouldSkip().

(WebKit::ResourceLoadStatisticsDatabaseStore::setVeryPrevalentResource):

Makes use of the new ResourceLoadStatisticsMemoryStore::shouldSkip().

  • NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h:
  • NetworkProcess/Classifier/ResourceLoadStatisticsMemoryStore.cpp:

(WebKit::ResourceLoadStatisticsMemoryStore::ResourceLoadStatisticsMemoryStore):
(WebKit::ResourceLoadStatisticsMemoryStore::classifyPrevalentResources):

Makes use of the new ResourceLoadStatisticsMemoryStore::shouldSkip().

(WebKit::ResourceLoadStatisticsMemoryStore::setPrevalentResource):

Makes use of the new ResourceLoadStatisticsMemoryStore::shouldSkip().

(WebKit::ResourceLoadStatisticsMemoryStore::isPrevalentResource const):

Makes use of the new ResourceLoadStatisticsMemoryStore::shouldSkip().

(WebKit::ResourceLoadStatisticsMemoryStore::isVeryPrevalentResource const):

Makes use of the new ResourceLoadStatisticsMemoryStore::shouldSkip().

(WebKit::ResourceLoadStatisticsMemoryStore::setVeryPrevalentResource):

Makes use of the new ResourceLoadStatisticsMemoryStore::shouldSkip().

  • NetworkProcess/Classifier/ResourceLoadStatisticsMemoryStore.h:
  • NetworkProcess/Classifier/ResourceLoadStatisticsStore.cpp:

(WebKit::ResourceLoadStatisticsStore::ResourceLoadStatisticsStore):

Now takes a ShouldIncludeLocalhost parameter.

(WebKit::ResourceLoadStatisticsStore::shouldSkip const):

Convenience function, currently supporting the localhost exclusion.

(WebKit::ResourceLoadStatisticsStore::setIsRunningTest):

Test infrastructure.

  • NetworkProcess/Classifier/ResourceLoadStatisticsStore.h:
  • NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:

(WebKit::WebResourceLoadStatisticsStore::setIsRunningTest):

Test infrastructure.

(WebKit::WebResourceLoadStatisticsStore::WebResourceLoadStatisticsStore):

Now takes a ShouldIncludeLocalhost parameter.

  • NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h:

Defines the new ShouldIncludeLocalhost boolean enum.

  • NetworkProcess/NetworkProcess.cpp:

(WebKit::NetworkProcess::setIsRunningResourceLoadStatisticsTest):

Test infrastructure.

  • NetworkProcess/NetworkProcess.h:
  • NetworkProcess/NetworkProcess.messages.in:
  • NetworkProcess/NetworkSession.cpp:

(WebKit::NetworkSession::setResourceLoadStatisticsEnabled):

Forwards the localhost setting to the create function.

  • NetworkProcess/NetworkSession.h:
  • NetworkProcess/NetworkSessionCreationParameters.cpp:

(WebKit::NetworkSessionCreationParameters::encode const):
(WebKit::NetworkSessionCreationParameters::decode):

  • NetworkProcess/NetworkSessionCreationParameters.h:

New parameter called shouldIncludeLocalhostInResourceLoadStatistics.

  • NetworkProcess/cocoa/NetworkSessionCocoa.mm:

(WebKit::NetworkSessionCocoa::NetworkSessionCocoa):

Picks up the localhost setting from the parameters.

  • UIProcess/API/C/WKWebsiteDataStoreRef.cpp:

(WKWebsiteDataStoreSetStatisticsIsRunningTest):

Test infrastructure.

  • UIProcess/API/C/WKWebsiteDataStoreRef.h:
  • UIProcess/Network/NetworkProcessProxy.cpp:

(WebKit::NetworkProcessProxy::setIsRunningResourceLoadStatisticsTest):

Test infrastructure.

  • UIProcess/Network/NetworkProcessProxy.h:
  • UIProcess/WebProcessPool.cpp:

(WebKit::WebProcessPool::ensureNetworkProcess):

Picks up the localhost setting from the WebsiteDataStore parameters.

  • UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:

(WebKit::WebsiteDataStore::parameters):

Makes sure Safari does not exclude localhost.

  • UIProcess/WebsiteData/WebsiteDataStore.cpp:

(WebKit::WebsiteDataStore::setIsRunningResourceLoadStatisticsTest):

Test infrastructure.

  • UIProcess/WebsiteData/WebsiteDataStore.h:

Tools:

This patch allows for localhost to be excluded from classification and
treatment as a prevalent resource.

The WebKit Tools change adds a new function called
testRunner.setStatisticsIsRunningTest() which can be used to control this
behavior.

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

(WTR::TestRunner::setStatisticsIsRunningTest):

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

(WTR::TestController::setStatisticsIsRunningTest):

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

(WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):

LayoutTests:

This patch makes sure that all test cases that need to, call the enableFeature()
function in http/tests/resourceLoadStatistics/resources/util.js.

The enableFeature() now calls the new function testRunner.setStatisticsIsRunningTest().

  • http/tests/resourceLoadStatistics/do-not-block-top-level-navigation-redirect.html:
  • http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html:
  • http/tests/resourceLoadStatistics/prevalent-resource-with-user-interaction.html:
  • http/tests/resourceLoadStatistics/resources/set-cookie-on-redirect.php:
  • http/tests/resourceLoadStatistics/resources/util.js:

(setEnableFeature):

  • http/tests/storageAccess/has-storage-access-from-prevalent-domain-with-user-interaction.html:
  • http/tests/storageAccess/request-and-grant-access-cross-origin-sandboxed-iframe-from-prevalent-domain-with-user-interaction.html:
  • http/tests/storageAccess/request-and-grant-access-cross-origin-sandboxed-iframe-from-prevalent-domain-without-user-interaction.html:
  • http/tests/storageAccess/request-and-grant-access-cross-origin-sandboxed-iframe.html:
  • http/tests/storageAccess/request-storage-access-cross-origin-sandboxed-iframe-with-unique-origin.html:
  • http/tests/storageAccess/request-storage-access-same-origin-iframe.html:
  • http/tests/storageAccess/request-storage-access-same-origin-sandboxed-iframe.html:
  • http/tests/storageAccess/request-storage-access-top-frame.html:
Location:
trunk
Files:
46 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r242704 r242712  
     12019-03-11  John Wilander  <wilander@apple.com>
     2
     3        Resource Load Statistics: Make it possible exclude localhost from classification
     4        https://bugs.webkit.org/show_bug.cgi?id=195474
     5        <rdar://problem/47520577>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        This patch makes sure that all test cases that need to, call the enableFeature()
     10        function in http/tests/resourceLoadStatistics/resources/util.js.
     11
     12        The enableFeature() now calls the new function testRunner.setStatisticsIsRunningTest().
     13
     14        * http/tests/resourceLoadStatistics/do-not-block-top-level-navigation-redirect.html:
     15        * http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html:
     16        * http/tests/resourceLoadStatistics/prevalent-resource-with-user-interaction.html:
     17        * http/tests/resourceLoadStatistics/resources/set-cookie-on-redirect.php:
     18        * http/tests/resourceLoadStatistics/resources/util.js:
     19        (setEnableFeature):
     20        * http/tests/storageAccess/has-storage-access-from-prevalent-domain-with-user-interaction.html:
     21        * http/tests/storageAccess/request-and-grant-access-cross-origin-sandboxed-iframe-from-prevalent-domain-with-user-interaction.html:
     22        * http/tests/storageAccess/request-and-grant-access-cross-origin-sandboxed-iframe-from-prevalent-domain-without-user-interaction.html:
     23        * http/tests/storageAccess/request-and-grant-access-cross-origin-sandboxed-iframe.html:
     24        * http/tests/storageAccess/request-storage-access-cross-origin-sandboxed-iframe-with-unique-origin.html:
     25        * http/tests/storageAccess/request-storage-access-same-origin-iframe.html:
     26        * http/tests/storageAccess/request-storage-access-same-origin-sandboxed-iframe.html:
     27        * http/tests/storageAccess/request-storage-access-top-frame.html:
     28
    1292019-03-11  Javier Fernandez  <jfernandez@igalia.com>
    230
  • trunk/LayoutTests/http/tests/resourceLoadStatistics/do-not-block-top-level-navigation-redirect.html

    r234440 r242712  
    44    <meta charset="UTF-8">
    55    <script src="/js-test-resources/js-test.js"></script>
     6    <script src="resources/util.js"></script>
    67<script>
    78    description("Tests that blocking is not applied to top-level navigation redirects.");
     
    1213    function doRedirect()
    1314    {
    14         testRunner.setStatisticsPrevalentResource("http://localhost", true, function() {
    15             if (!testRunner.isStatisticsPrevalentResource("http://localhost")) {
    16                 testFailed("Host did not get set as prevalent resource.");
    17                 finishJSTest();
    18             }
    19             else
    20                 document.location.href = "http://localhost:8000/resourceLoadStatistics/resources/set-cookie-on-redirect.php?step=1";
     15        setEnableFeature(true, function () {
     16            testRunner.setStatisticsPrevalentResource("http://localhost", true, function () {
     17                if (!testRunner.isStatisticsPrevalentResource("http://localhost")) {
     18                    testFailed("Host did not get set as prevalent resource.");
     19                    setEnableFeature(false, finishJSTest);
     20                } else
     21                    document.location.href = "http://localhost:8000/resourceLoadStatistics/resources/set-cookie-on-redirect.php?step=1";
     22            });
    2123        });
    2224    }
    2325</script>
    2426</head>
    25 <body onload="doRedirect()">
     27<body onload="setTimeout('doRedirect()', 0)">
    2628</body>
    2729</html>
  • trunk/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html

    r234440 r242712  
    4242        if (testRunner) {
    4343            setEnableFeature(true, function() {
    44                 testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
    4544                testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
    4645            });
  • trunk/LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-with-user-interaction.html

    r233888 r242712  
    55    <title>Tests for Prevalent Resource With User Interaction</title>
    66    <script src="/js-test-resources/js-test.js"></script>
     7    <script src="resources/util.js"></script>
    78</head>
    8 <body>
     9<body onload="setTimeout('setUpAndRun()', 0)">
    910<script>
     11    if (testRunner)
     12        testRunner.waitUntilDone();
     13
    1014    const hostUnderTest = "127.0.0.1:8000";
    1115    const statisticsUrl = "http://" + hostUnderTest + "/temp";
     
    3842                        else
    3943                            testFailed("Cookie deleted or document.cookie contains other cookies: " + document.cookie);
    40                         internals.setResourceLoadStatisticsEnabled(false);
    41                         testRunner.statisticsResetToConsistentState(function() {
     44                        setEnableFeature(false, function() {
    4245                            testRunner.notifyDone();
    4346                        });
     
    5154    }
    5255
    53     if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
    54         testRunner.waitUntilDone();
    55         internals.setResourceLoadStatisticsEnabled(true);
    56         testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
    57         runTestRunnerTest();
     56    function setUpAndRun() {
     57        if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
     58            setEnableFeature(true, function () {
     59                runTestRunnerTest();
     60            });
     61        } else {
     62            testFailed("Wrong host, no testRunner, or no internals.");
     63            testRunner.notifyDone();
     64        }
    5865    }
    5966</script>
  • trunk/LayoutTests/http/tests/resourceLoadStatistics/resources/set-cookie-on-redirect.php

    r234440 r242712  
    1717    echo "FAILED: Cookie not set\n";
    1818  }
    19   echo "<script>if (window.testRunner && window.internals) testRunner.statisticsResetToConsistentState(function() { internals.setResourceLoadStatisticsEnabled(false); testRunner.notifyDone(); });</script>";
     19  echo "<script src='util.js'></script>";
     20  echo "<script>if (window.testRunner && window.internals) setEnableFeature(false, finishJSTest);</script>";
    2021}
    2122?>
  • trunk/LayoutTests/http/tests/resourceLoadStatistics/resources/util.js

    r234440 r242712  
    55    if (enable) {
    66        internals.setResourceLoadStatisticsEnabled(true);
     7        testRunner.setStatisticsIsRunningTest(true);
    78        completionHandler();
    89    } else {
    910        testRunner.statisticsResetToConsistentState(function() {
     11            testRunner.setStatisticsIsRunningTest(false);
    1012            internals.setResourceLoadStatisticsEnabled(false);
    1113            completionHandler();
  • trunk/LayoutTests/http/tests/storageAccess/has-storage-access-from-prevalent-domain-with-user-interaction.html

    r234440 r242712  
    44    <script src="/js-test-resources/js-test.js"></script>
    55    <script src="/js-test-resources/ui-helper.js"></script>
     6    <script src="/resourceLoadStatistics/resources/util.js"></script>
    67    <script>
    78        description("Tests that a cross-origin iframe from a prevalent domain with user interaction does not have storage access.");
     
    1819            } else
    1920                testFailed("Received a message from an unexpected origin: " + event.origin);
    20             finishJSTest();
     21            setEnableFeature(false, finishJSTest);
    2122        }
    2223
    2324        const hostUnderTest = "localhost:8000";
    2425        const statisticsUrl = "http://" + hostUnderTest + "/temp";
    25         testRunner.setStatisticsPrevalentResource(statisticsUrl, true, function() {
    26             if (!testRunner.isStatisticsPrevalentResource(statisticsUrl))
    27                 testFailed("Host did not get set as prevalent resource.");
    28             testRunner.setStatisticsHasHadUserInteraction(statisticsUrl, true, function() {
    29                 if (!testRunner.isStatisticsHasHadUserInteraction(statisticsUrl))
    30                     testFailed("Host did not get logged for user interaction.");
    31                 let iframeElement = document.createElement("iframe");
    32                 iframeElement.setAttribute("sandbox", "allow-storage-access-by-user-activation allow-scripts allow-same-origin allow-modals");
    33                 iframeElement.id = "TheIframeThatRequestsStorageAccess";
    34                 iframeElement.src = "http://localhost:8000/storageAccess/resources/has-storage-access-iframe.html#policyShouldNotGrantAccess";
    35                 document.body.appendChild(iframeElement);
     26        function runTest() {
     27            setEnableFeature(true, function() {
     28                testRunner.setStatisticsPrevalentResource(statisticsUrl, true, function() {
     29                    if (!testRunner.isStatisticsPrevalentResource(statisticsUrl))
     30                        testFailed("Host did not get set as prevalent resource.");
     31                    testRunner.setStatisticsHasHadUserInteraction(statisticsUrl, true, function() {
     32                        if (!testRunner.isStatisticsHasHadUserInteraction(statisticsUrl))
     33                            testFailed("Host did not get logged for user interaction.");
     34                        let iframeElement = document.createElement("iframe");
     35                        iframeElement.setAttribute("sandbox", "allow-storage-access-by-user-activation allow-scripts allow-same-origin allow-modals");
     36                        iframeElement.id = "TheIframeThatRequestsStorageAccess";
     37                        iframeElement.src = "http://localhost:8000/storageAccess/resources/has-storage-access-iframe.html#policyShouldNotGrantAccess";
     38                        document.body.appendChild(iframeElement);
     39                    });
     40                });
     41
    3642            });
    37         });
     43        }
    3844    </script>
    3945</head>
    40 <body>
     46<body onload="runTest()">
    4147</body>
    4248</html>
  • trunk/LayoutTests/http/tests/storageAccess/request-and-grant-access-cross-origin-sandboxed-iframe-from-prevalent-domain-with-user-interaction.html

    r234440 r242712  
    44    <script src="/js-test-resources/js-test.js"></script>
    55    <script src="/js-test-resources/ui-helper.js"></script>
     6    <script src="/resourceLoadStatistics/resources/util.js"></script>
    67    <script>
    78        description("Tests that cross-origin iframe storage access is granted if the iframe is sandboxed, has the allow token, the iframe origin is a prevalent resource, the iframe origin has had recent user interaction, and the user opts in.");
     
    1819            } else
    1920                testFailed("Received a message from an unexpected origin: " + event.origin);
    20             finishJSTest();
     21            setEnableFeature(false, finishJSTest);
    2122        }
    2223
     
    3132                    else {
    3233                        testFailed("No eventSender.");
    33                         finishJSTest();
     34                        setEnableFeature(false, finishJSTest);
    3435                    }
    3536                },
    3637                function () {
    3738                    testFailed("Promise rejected.");
    38                     finishJSTest();
     39                    setEnableFeature(false, finishJSTest);
    3940                }
    4041            );
     
    4748        const hostUnderTest = "localhost:8000";
    4849        const statisticsUrl = "http://" + hostUnderTest + "/temp";
    49         testRunner.setStatisticsPrevalentResource(statisticsUrl, true, function() {
    50             if (!testRunner.isStatisticsPrevalentResource(statisticsUrl))
    51                 testFailed("Host did not get set as prevalent resource.");
    52             testRunner.setStatisticsHasHadUserInteraction(statisticsUrl, true, function() {
    53                 if (!testRunner.isStatisticsHasHadUserInteraction(statisticsUrl))
    54                     testFailed("Host did not get logged for user interaction.");
    55                 let iframeElement = document.createElement("iframe");
    56                 iframeElement.setAttribute("sandbox", "allow-storage-access-by-user-activation allow-scripts allow-same-origin allow-modals");
    57                 iframeElement.onload = runTest;
    58                 iframeElement.id = "TheIframeThatRequestsStorageAccess";
    59                 iframeElement.src = "http://localhost:8000/storageAccess/resources/request-storage-access-iframe.html#userShouldGrantAccess,userShouldBeConsulted,policyShouldGrantAccess,isNotSameOriginIframe";
    60                 document.body.appendChild(iframeElement);
     50        setEnableFeature(true, function() {
     51            testRunner.setStatisticsPrevalentResource(statisticsUrl, true, function() {
     52                if (!testRunner.isStatisticsPrevalentResource(statisticsUrl))
     53                    testFailed("Host did not get set as prevalent resource.");
     54                testRunner.setStatisticsHasHadUserInteraction(statisticsUrl, true, function() {
     55                    if (!testRunner.isStatisticsHasHadUserInteraction(statisticsUrl))
     56                        testFailed("Host did not get logged for user interaction.");
     57                    let iframeElement = document.createElement("iframe");
     58                    iframeElement.setAttribute("sandbox", "allow-storage-access-by-user-activation allow-scripts allow-same-origin allow-modals");
     59                    iframeElement.onload = runTest;
     60                    iframeElement.id = "TheIframeThatRequestsStorageAccess";
     61                    iframeElement.src = "http://localhost:8000/storageAccess/resources/request-storage-access-iframe.html#userShouldGrantAccess,userShouldBeConsulted,policyShouldGrantAccess,isNotSameOriginIframe";
     62                    document.body.appendChild(iframeElement);
     63                });
    6164            });
    6265        });
  • trunk/LayoutTests/http/tests/storageAccess/request-and-grant-access-cross-origin-sandboxed-iframe-from-prevalent-domain-without-user-interaction.html

    r234440 r242712  
    44    <script src="/js-test-resources/js-test.js"></script>
    55    <script src="/js-test-resources/ui-helper.js"></script>
     6    <script src="/resourceLoadStatistics/resources/util.js"></script>
    67    <script>
    78        description("Tests that cross-origin iframe storage access is denied if the iframe is sandboxed, has the allow token, the iframe origin is a prevalent resource, the iframe origin has not had user interaction, and the user opts in.");
     
    1819            } else
    1920                testFailed("Received a message from an unexpected origin: " + event.origin);
    20             finishJSTest();
     21            setEnableFeature(false, finishJSTest);
    2122        }
    2223
     
    3132                    else {
    3233                        testFailed("No eventSender.");
    33                         finishJSTest();
     34                        setEnableFeature(false, finishJSTest);
    3435                    }
    3536                },
    3637                function () {
    3738                    testFailed("Promise rejected.");
    38                     finishJSTest();
     39                    setEnableFeature(false, finishJSTest);
    3940                }
    4041            );
     
    4748        const hostUnderTest = "localhost:8000";
    4849        const statisticsUrl = "http://" + hostUnderTest + "/temp";
    49         testRunner.setStatisticsPrevalentResource(statisticsUrl, true, function() {
    50             if (!testRunner.isStatisticsPrevalentResource(statisticsUrl))
    51                 testFailed("Host did not get set as prevalent resource.");
    52             let iframeElement = document.createElement("iframe");
    53             iframeElement.setAttribute("sandbox", "allow-storage-access-by-user-activation allow-scripts allow-same-origin allow-modals");
    54             iframeElement.onload = runTest;
    55             iframeElement.id = "TheIframeThatRequestsStorageAccess";
    56             iframeElement.src = "http://localhost:8000/storageAccess/resources/request-storage-access-iframe.html#userShouldGrantAccess,userShouldBeConsulted,policyShouldNotGrantAccess,isNotSameOriginIframe";
    57             document.body.appendChild(iframeElement);
     50
     51        setEnableFeature(true, function() {
     52            testRunner.setStatisticsPrevalentResource(statisticsUrl, true, function() {
     53                if (!testRunner.isStatisticsPrevalentResource(statisticsUrl))
     54                    testFailed("Host did not get set as prevalent resource.");
     55                let iframeElement = document.createElement("iframe");
     56                iframeElement.setAttribute("sandbox", "allow-storage-access-by-user-activation allow-scripts allow-same-origin allow-modals");
     57                iframeElement.onload = runTest;
     58                iframeElement.id = "TheIframeThatRequestsStorageAccess";
     59                iframeElement.src = "http://localhost:8000/storageAccess/resources/request-storage-access-iframe.html#userShouldGrantAccess,userShouldBeConsulted,policyShouldNotGrantAccess,isNotSameOriginIframe";
     60                document.body.appendChild(iframeElement);
     61            });
    5862        });
    5963    </script>
  • trunk/LayoutTests/http/tests/storageAccess/request-and-grant-access-cross-origin-sandboxed-iframe.html

    r234440 r242712  
    44    <script src="/js-test-resources/js-test.js"></script>
    55    <script src="/js-test-resources/ui-helper.js"></script>
     6    <script src="/resourceLoadStatistics/resources/util.js"></script>
    67    <script>
    78        description("Tests that cross-origin iframe storage access is granted if the iframe is sandboxed, has the allow token, and the user opts in.");
     
    1819            } else
    1920                testFailed("Received a message from an unexpected origin: " + event.origin);
    20             finishJSTest();
     21            setEnableFeature(false, finishJSTest);
    2122        }
    2223
     
    3132                    else {
    3233                        testFailed("No eventSender.");
    33                         finishJSTest();
     34                        setEnableFeature(false, finishJSTest);
    3435                    }
    3536                },
    3637                function () {
    3738                    testFailed("Promise rejected.");
    38                     finishJSTest();
     39                    setEnableFeature(false, finishJSTest);
    3940                }
    4041            );
     
    4243
    4344        function runTest() {
    44             activateElement("TheIframeThatRequestsStorageAccess");
     45            setEnableFeature(true, function() {
     46                activateElement("TheIframeThatRequestsStorageAccess");
     47            });
    4548        }
    4649    </script>
  • trunk/LayoutTests/http/tests/storageAccess/request-storage-access-cross-origin-sandboxed-iframe-with-unique-origin.html

    r234440 r242712  
    44    <script src="/js-test-resources/js-test.js"></script>
    55    <script src="/js-test-resources/ui-helper.js"></script>
     6    <script src="/resourceLoadStatistics/resources/util.js"></script>
    67    <script>
    78        description("Tests that cross-origin iframe storage access is denied if the iframe is sandboxed and has the unique origin because it lacks the allow-same-origin token.");
     
    1819            } else
    1920                testFailed("Received a message from an unexpected origin: " + event.origin);
    20             finishJSTest();
     21            setEnableFeature(false, finishJSTest);
    2122        }
    2223
     
    3132                    else {
    3233                        testFailed("No eventSender.");
    33                         finishJSTest();
     34                        setEnableFeature(false, finishJSTest);
    3435                    }
    3536                },
    3637                function () {
    3738                    testFailed("Promise rejected.");
    38                     finishJSTest();
     39                    setEnableFeature(false, finishJSTest);
    3940                }
    4041            );
     
    4243
    4344        function runTest() {
    44             activateElement("TheIframeThatRequestsStorageAccess");
     45            setEnableFeature(true, function() {
     46                activateElement("TheIframeThatRequestsStorageAccess");
     47            });
    4548        }
    4649    </script>
  • trunk/LayoutTests/http/tests/storageAccess/request-storage-access-same-origin-iframe.html

    r234440 r242712  
    44    <script src="/js-test-resources/js-test.js"></script>
    55    <script src="/js-test-resources/ui-helper.js"></script>
     6    <script src="/resourceLoadStatistics/resources/util.js"></script>
    67    <script>
    78        description("Tests that same-origin iframe storage access is granted if the iframe is not sandboxed.");
     
    1819            } else
    1920                testFailed("Received a message from an unexpected origin: " + event.origin);
    20             finishJSTest();
     21            setEnableFeature(false, finishJSTest);
    2122        }
    2223
     
    3132                    else {
    3233                        testFailed("No eventSender.");
    33                         finishJSTest();
     34                        setEnableFeature(false, finishJSTest);
    3435                    }
    3536                },
    3637                function () {
    3738                    testFailed("Promise rejected.");
    38                     finishJSTest();
     39                    setEnableFeature(false, finishJSTest);
    3940                }
    4041            );
     
    4243
    4344        function runTest() {
    44             activateElement("TheIframeThatRequestsStorageAccess");
     45            setEnableFeature(true, function() {
     46                activateElement("TheIframeThatRequestsStorageAccess");
     47            });
    4548        }
    4649    </script>
  • trunk/LayoutTests/http/tests/storageAccess/request-storage-access-same-origin-sandboxed-iframe.html

    r234440 r242712  
    44    <script src="/js-test-resources/js-test.js"></script>
    55    <script src="/js-test-resources/ui-helper.js"></script>
     6    <script src="/resourceLoadStatistics/resources/util.js"></script>
    67    <script>
    78        description("Tests that same-origin iframe storage access is granted if the iframe is sandboxed and has the allow token.");
     
    1819            } else
    1920                testFailed("Received a message from an unexpected origin: " + event.origin);
    20             finishJSTest();
     21            setEnableFeature(false, finishJSTest);
    2122        }
    2223
     
    3132                    else {
    3233                        testFailed("No eventSender.");
    33                         finishJSTest();
     34                        setEnableFeature(false, finishJSTest);
    3435                    }
    3536                },
    3637                function () {
    3738                    testFailed("Promise rejected.");
    38                     finishJSTest();
     39                    setEnableFeature(false, finishJSTest);
    3940                }
    4041            );
     
    4243
    4344        function runTest() {
    44             activateElement("TheIframeThatRequestsStorageAccess");
     45            setEnableFeature(true, function() {
     46                activateElement("TheIframeThatRequestsStorageAccess");
     47            });
    4548        }
    4649    </script>
  • trunk/LayoutTests/http/tests/storageAccess/request-storage-access-top-frame.html

    r234440 r242712  
    2727
    2828    function makeRequestWithUserGesture() {
    29         var promise = document.requestStorageAccess();
    30         promise.then(
    31             function () {
    32                 requestStorageAccessResolved = true;
    33                 continueAfterRequestWithUserGesture();
    34             },
    35             function () {
    36                 requestStorageAccessResolved = false;
    37                 continueAfterRequestWithUserGesture();
    38             }
    39         );
     29        setEnableFeature(true, function() {
     30            var promise = document.requestStorageAccess();
     31            promise.then(
     32                function () {
     33                    requestStorageAccessResolved = true;
     34                    continueAfterRequestWithUserGesture();
     35                },
     36                function () {
     37                    requestStorageAccessResolved = false;
     38                    continueAfterRequestWithUserGesture();
     39                }
     40            );
     41        });
    4042    }
    4143
  • trunk/Source/WebKit/ChangeLog

    r242710 r242712  
     12019-03-11  John Wilander  <wilander@apple.com>
     2
     3        Resource Load Statistics: Make it possible exclude localhost from classification
     4        https://bugs.webkit.org/show_bug.cgi?id=195474
     5        <rdar://problem/47520577>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        This patch allows for localhost to be excluded from classification and
     10        treatment as a prevalent resource.
     11
     12        * NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp:
     13        (WebKit::ResourceLoadStatisticsDatabaseStore::ResourceLoadStatisticsDatabaseStore):
     14        (WebKit::ResourceLoadStatisticsDatabaseStore::reclassifyResources):
     15            Makes use of the new ResourceLoadStatisticsMemoryStore::shouldSkip().
     16        (WebKit::ResourceLoadStatisticsDatabaseStore::setPrevalentResource):
     17            Makes use of the new ResourceLoadStatisticsMemoryStore::shouldSkip().
     18        (WebKit::ResourceLoadStatisticsDatabaseStore::isPrevalentResource const):
     19            Makes use of the new ResourceLoadStatisticsMemoryStore::shouldSkip().
     20        (WebKit::ResourceLoadStatisticsDatabaseStore::isVeryPrevalentResource const):
     21            Makes use of the new ResourceLoadStatisticsMemoryStore::shouldSkip().
     22        (WebKit::ResourceLoadStatisticsDatabaseStore::setVeryPrevalentResource):
     23            Makes use of the new ResourceLoadStatisticsMemoryStore::shouldSkip().
     24        * NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h:
     25        * NetworkProcess/Classifier/ResourceLoadStatisticsMemoryStore.cpp:
     26        (WebKit::ResourceLoadStatisticsMemoryStore::ResourceLoadStatisticsMemoryStore):
     27        (WebKit::ResourceLoadStatisticsMemoryStore::classifyPrevalentResources):
     28            Makes use of the new ResourceLoadStatisticsMemoryStore::shouldSkip().
     29        (WebKit::ResourceLoadStatisticsMemoryStore::setPrevalentResource):
     30            Makes use of the new ResourceLoadStatisticsMemoryStore::shouldSkip().
     31        (WebKit::ResourceLoadStatisticsMemoryStore::isPrevalentResource const):
     32            Makes use of the new ResourceLoadStatisticsMemoryStore::shouldSkip().
     33        (WebKit::ResourceLoadStatisticsMemoryStore::isVeryPrevalentResource const):
     34            Makes use of the new ResourceLoadStatisticsMemoryStore::shouldSkip().
     35        (WebKit::ResourceLoadStatisticsMemoryStore::setVeryPrevalentResource):
     36            Makes use of the new ResourceLoadStatisticsMemoryStore::shouldSkip().
     37        * NetworkProcess/Classifier/ResourceLoadStatisticsMemoryStore.h:
     38        * NetworkProcess/Classifier/ResourceLoadStatisticsStore.cpp:
     39        (WebKit::ResourceLoadStatisticsStore::ResourceLoadStatisticsStore):
     40            Now takes a ShouldIncludeLocalhost parameter.
     41        (WebKit::ResourceLoadStatisticsStore::shouldSkip const):
     42            Convenience function, currently supporting the localhost exclusion.
     43        (WebKit::ResourceLoadStatisticsStore::setIsRunningTest):
     44            Test infrastructure.
     45        * NetworkProcess/Classifier/ResourceLoadStatisticsStore.h:
     46        * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:
     47        (WebKit::WebResourceLoadStatisticsStore::setIsRunningTest):
     48            Test infrastructure.
     49        (WebKit::WebResourceLoadStatisticsStore::WebResourceLoadStatisticsStore):
     50            Now takes a ShouldIncludeLocalhost parameter.
     51        * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h:
     52            Defines the new ShouldIncludeLocalhost boolean enum.
     53        * NetworkProcess/NetworkProcess.cpp:
     54        (WebKit::NetworkProcess::setIsRunningResourceLoadStatisticsTest):
     55            Test infrastructure.
     56        * NetworkProcess/NetworkProcess.h:
     57        * NetworkProcess/NetworkProcess.messages.in:
     58        * NetworkProcess/NetworkSession.cpp:
     59        (WebKit::NetworkSession::setResourceLoadStatisticsEnabled):
     60            Forwards the localhost setting to the create function.
     61        * NetworkProcess/NetworkSession.h:
     62        * NetworkProcess/NetworkSessionCreationParameters.cpp:
     63        (WebKit::NetworkSessionCreationParameters::encode const):
     64        (WebKit::NetworkSessionCreationParameters::decode):
     65        * NetworkProcess/NetworkSessionCreationParameters.h:
     66            New parameter called shouldIncludeLocalhostInResourceLoadStatistics.
     67        * NetworkProcess/cocoa/NetworkSessionCocoa.mm:
     68        (WebKit::NetworkSessionCocoa::NetworkSessionCocoa):
     69            Picks up the localhost setting from the parameters.
     70        * UIProcess/API/C/WKWebsiteDataStoreRef.cpp:
     71        (WKWebsiteDataStoreSetStatisticsIsRunningTest):
     72            Test infrastructure.
     73        * UIProcess/API/C/WKWebsiteDataStoreRef.h:
     74        * UIProcess/Network/NetworkProcessProxy.cpp:
     75        (WebKit::NetworkProcessProxy::setIsRunningResourceLoadStatisticsTest):
     76            Test infrastructure.
     77        * UIProcess/Network/NetworkProcessProxy.h:
     78        * UIProcess/WebProcessPool.cpp:
     79        (WebKit::WebProcessPool::ensureNetworkProcess):
     80            Picks up the localhost setting from the WebsiteDataStore parameters.
     81        * UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
     82        (WebKit::WebsiteDataStore::parameters):
     83            Makes sure Safari does not exclude localhost.
     84        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
     85        (WebKit::WebsiteDataStore::setIsRunningResourceLoadStatisticsTest):
     86            Test infrastructure.
     87        * UIProcess/WebsiteData/WebsiteDataStore.h:
     88
    1892019-03-11  Alex Christensen  <achristensen@webkit.org>
    290
  • trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp

    r242603 r242712  
    159159    "FOREIGN KEY(fromDomainID) REFERENCES ObservedDomains(domainID) ON DELETE CASCADE);"_s;
    160160   
    161 ResourceLoadStatisticsDatabaseStore::ResourceLoadStatisticsDatabaseStore(WebResourceLoadStatisticsStore& store, WorkQueue& workQueue, const String& storageDirectoryPath)
    162     : ResourceLoadStatisticsStore(store, workQueue)
     161ResourceLoadStatisticsDatabaseStore::ResourceLoadStatisticsDatabaseStore(WebResourceLoadStatisticsStore& store, WorkQueue& workQueue, ShouldIncludeLocalhost shouldIncludeLocalhost, const String& storageDirectoryPath)
     162    : ResourceLoadStatisticsStore(store, workQueue, shouldIncludeLocalhost)
    163163    , m_storageDirectoryPath(storageDirectoryPath + "/observations.db")
    164164    , m_observedDomainCount(m_database, observedDomainCountQuery)
     
    690690
    691691    for (auto& resourceStatistic : notVeryPrevalentResources.values()) {
     692        if (shouldSkip(resourceStatistic.registerableDomain))
     693            continue;
     694
    692695        auto newPrevalence = classifier().calculateResourcePrevalence(resourceStatistic.subresourceUnderTopFrameDomainsCount, resourceStatistic.subresourceUniqueRedirectsToCount, resourceStatistic.subframeUnderTopFrameDomainsCount, resourceStatistic.topFrameUniqueRedirectsToCount, resourceStatistic.prevalence);
    693696        if (newPrevalence != resourceStatistic.prevalence)
     
    10671070{
    10681071    ASSERT(!RunLoop::isMain());
     1072    if (shouldSkip(domain))
     1073        return;
    10691074
    10701075    if (m_updatePrevalentResourceStatement.bindInt(1, 1) != SQLITE_OK
     
    11401145    ASSERT(!RunLoop::isMain());
    11411146
     1147    if (shouldSkip(domain))
     1148        return false;
     1149
    11421150    return predicateValueForDomain(m_isPrevalentResourceStatement, domain);
    11431151}
     
    11461154{
    11471155    ASSERT(!RunLoop::isMain());
     1156
     1157    if (shouldSkip(domain))
     1158        return false;
    11481159
    11491160    return predicateValueForDomain(m_isVeryPrevalentResourceStatement, domain);
     
    15851596    ASSERT(!RunLoop::isMain());
    15861597
     1598    if (shouldSkip(domain))
     1599        return;
     1600
    15871601    ensureResourceStatisticsForRegistrableDomain(domain);
    15881602    setPrevalentResource(domain, ResourceLoadPrevalence::High);
     
    15931607    ASSERT(!RunLoop::isMain());
    15941608
     1609    if (shouldSkip(domain))
     1610        return;
     1611   
    15951612    ensureResourceStatisticsForRegistrableDomain(domain);
    15961613    setPrevalentResource(domain, ResourceLoadPrevalence::VeryHigh);
  • trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h

    r242603 r242712  
    5151class ResourceLoadStatisticsDatabaseStore final : public ResourceLoadStatisticsStore {
    5252public:
    53     ResourceLoadStatisticsDatabaseStore(WebResourceLoadStatisticsStore&, WorkQueue&, const String& storageDirectoryPath);
     53    ResourceLoadStatisticsDatabaseStore(WebResourceLoadStatisticsStore&, WorkQueue&, ShouldIncludeLocalhost, const String& storageDirectoryPath);
    5454
    5555    void populateFromMemoryStore(const ResourceLoadStatisticsMemoryStore&);
  • trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsMemoryStore.cpp

    r242603 r242712  
    6868}
    6969
    70 ResourceLoadStatisticsMemoryStore::ResourceLoadStatisticsMemoryStore(WebResourceLoadStatisticsStore& store, WorkQueue& workQueue)
    71     : ResourceLoadStatisticsStore(store, workQueue)
     70ResourceLoadStatisticsMemoryStore::ResourceLoadStatisticsMemoryStore(WebResourceLoadStatisticsStore& store, WorkQueue& workQueue, ShouldIncludeLocalhost shouldIncludeLocalhost)
     71    : ResourceLoadStatisticsStore(store, workQueue, shouldIncludeLocalhost)
    7272{
    7373    ASSERT(!RunLoop::isMain());
     
    176176{
    177177    for (auto& resourceStatistic : m_resourceStatisticsMap.values()) {
     178        if (shouldSkip(resourceStatistic.registrableDomain))
     179            continue;
    178180        if (isPrevalentDueToDebugMode(resourceStatistic))
    179181            setPrevalentResource(resourceStatistic, ResourceLoadPrevalence::High);
     
    459461    ASSERT(!RunLoop::isMain());
    460462
     463    if (shouldSkip(resourceStatistic.registrableDomain))
     464        return;
     465
    461466    resourceStatistic.isPrevalentResource = true;
    462467    resourceStatistic.isVeryPrevalentResource = newPrevalence == ResourceLoadPrevalence::VeryHigh;
     
    487492    ASSERT(!RunLoop::isMain());
    488493
     494    if (shouldSkip(domain))
     495        return false;
     496
    489497    auto mapEntry = m_resourceStatisticsMap.find(domain);
    490498    return mapEntry == m_resourceStatisticsMap.end() ? false : mapEntry->value.isPrevalentResource;
     
    495503    ASSERT(!RunLoop::isMain());
    496504
     505    if (shouldSkip(domain))
     506        return false;
     507   
    497508    auto mapEntry = m_resourceStatisticsMap.find(domain);
    498509    return mapEntry == m_resourceStatisticsMap.end() ? false : mapEntry->value.isPrevalentResource && mapEntry->value.isVeryPrevalentResource;
     
    851862    ASSERT(!RunLoop::isMain());
    852863
     864    if (shouldSkip(domain))
     865        return;
     866   
    853867    auto& resourceStatistic = ensureResourceStatisticsForRegistrableDomain(domain);
    854868    setPrevalentResource(resourceStatistic, ResourceLoadPrevalence::High);
     
    859873    ASSERT(!RunLoop::isMain());
    860874
     875    if (shouldSkip(domain))
     876        return;
     877   
    861878    auto& resourceStatistic = ensureResourceStatisticsForRegistrableDomain(domain);
    862879    setPrevalentResource(resourceStatistic, ResourceLoadPrevalence::VeryHigh);
  • trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsMemoryStore.h

    r242603 r242712  
    4848class ResourceLoadStatisticsMemoryStore final : public ResourceLoadStatisticsStore {
    4949public:
    50     ResourceLoadStatisticsMemoryStore(WebResourceLoadStatisticsStore&, WorkQueue&);
     50    ResourceLoadStatisticsMemoryStore(WebResourceLoadStatisticsStore&, WorkQueue&, ShouldIncludeLocalhost);
    5151
    5252    void setPersistentStorage(ResourceLoadStatisticsPersistentStorage&);
  • trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsStore.cpp

    r242598 r242712  
    102102}
    103103
    104 ResourceLoadStatisticsStore::ResourceLoadStatisticsStore(WebResourceLoadStatisticsStore& store, WorkQueue& workQueue)
     104ResourceLoadStatisticsStore::ResourceLoadStatisticsStore(WebResourceLoadStatisticsStore& store, WorkQueue& workQueue, ShouldIncludeLocalhost shouldIncludeLocalhost)
    105105    : m_store(store)
    106106    , m_workQueue(workQueue)
     107    , m_shouldIncludeLocalhost(shouldIncludeLocalhost)
    107108{
    108109    ASSERT(!RunLoop::isMain());
     
    130131    ASSERT(!RunLoop::isMain());
    131132    m_parameters.shouldNotifyPagesWhenDataRecordsWereScanned = value;
     133}
     134
     135bool ResourceLoadStatisticsStore::shouldSkip(const RegistrableDomain& domain) const
     136{
     137    ASSERT(!RunLoop::isMain());
     138    return !(parameters().isRunningTest)
     139    && m_shouldIncludeLocalhost == ShouldIncludeLocalhost::No && domain.string() == "localhost";
     140}
     141
     142void ResourceLoadStatisticsStore::setIsRunningTest(bool value)
     143{
     144    ASSERT(!RunLoop::isMain());
     145    m_parameters.isRunningTest = value;
    132146}
    133147
  • trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsStore.h

    r242603 r242712  
    147147
    148148    void setNotifyPagesWhenDataRecordsWereScanned(bool);
     149    void setIsRunningTest(bool);
     150    bool shouldSkip(const RegistrableDomain&) const;
    149151    void setShouldClassifyResourcesBeforeDataRecordsRemoval(bool);
    150152    void setShouldSubmitTelemetry(bool);
     
    185187    static void debugLogDomainsInBatches(const char* action, const Vector<RegistrableDomain>& domains);
    186188
    187     ResourceLoadStatisticsStore(WebResourceLoadStatisticsStore&, WorkQueue&);
     189    ResourceLoadStatisticsStore(WebResourceLoadStatisticsStore&, WorkQueue&, ShouldIncludeLocalhost);
    188190
    189191    bool hasStatisticsExpired(const ResourceLoadStatistics&) const;
     
    217219        bool shouldClassifyResourcesBeforeDataRecordsRemoval { true };
    218220        bool shouldSubmitTelemetry { true };
     221        bool isRunningTest { false };
    219222    };
    220223    const Parameters& parameters() const { return m_parameters; }
     
    266269    bool m_storageAccessPromptsEnabled { false };
    267270    bool m_dataRecordsBeingRemoved { false };
     271    ShouldIncludeLocalhost m_shouldIncludeLocalhost { ShouldIncludeLocalhost::Yes };
    268272};
    269273
  • trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp

    r242603 r242712  
    109109}
    110110
     111void WebResourceLoadStatisticsStore::setIsRunningTest(bool value, CompletionHandler<void()>&& completionHandler)
     112{
     113    ASSERT(RunLoop::isMain());
     114   
     115    postTask([this, value, completionHandler = WTFMove(completionHandler)]() mutable {
     116        if (m_statisticsStore)
     117            m_statisticsStore->setIsRunningTest(value);
     118       
     119        postTaskReply(WTFMove(completionHandler));
     120    });
     121}
     122
    111123void WebResourceLoadStatisticsStore::setShouldClassifyResourcesBeforeDataRecordsRemoval(bool value, CompletionHandler<void()>&& completionHandler)
    112124{
     
    139151}
    140152
    141 WebResourceLoadStatisticsStore::WebResourceLoadStatisticsStore(NetworkSession& networkSession, const String& resourceLoadStatisticsDirectory)
     153WebResourceLoadStatisticsStore::WebResourceLoadStatisticsStore(NetworkSession& networkSession, const String& resourceLoadStatisticsDirectory, ShouldIncludeLocalhost shouldIncludeLocalhost)
    142154    : m_networkSession(makeWeakPtr(networkSession))
    143155    , m_statisticsQueue(WorkQueue::create("WebResourceLoadStatisticsStore Process Data Queue", WorkQueue::Type::Serial, WorkQueue::QOS::Utility))
     
    146158    ASSERT(RunLoop::isMain());
    147159   
    148     postTask([this, resourceLoadStatisticsDirectory = resourceLoadStatisticsDirectory.isolatedCopy()] {
     160    postTask([this, resourceLoadStatisticsDirectory = resourceLoadStatisticsDirectory.isolatedCopy(), shouldIncludeLocalhost] {
    149161        if (RuntimeEnabledFeatures::sharedFeatures().isITPDatabaseEnabled()) {
    150             m_statisticsStore = std::make_unique<ResourceLoadStatisticsDatabaseStore>(*this, m_statisticsQueue, resourceLoadStatisticsDirectory);
    151 
    152             auto memoryStore = std::make_unique<ResourceLoadStatisticsMemoryStore>(*this, m_statisticsQueue);
     162            m_statisticsStore = std::make_unique<ResourceLoadStatisticsDatabaseStore>(*this, m_statisticsQueue, shouldIncludeLocalhost, resourceLoadStatisticsDirectory);
     163
     164            auto memoryStore = std::make_unique<ResourceLoadStatisticsMemoryStore>(*this, m_statisticsQueue, shouldIncludeLocalhost);
    153165            auto persistentStore = std::make_unique<ResourceLoadStatisticsPersistentStorage>(*memoryStore, m_statisticsQueue, resourceLoadStatisticsDirectory);
    154166
    155167            downcast<ResourceLoadStatisticsDatabaseStore>(*m_statisticsStore.get()).populateFromMemoryStore(*memoryStore);
    156168        } else {
    157             m_statisticsStore = std::make_unique<ResourceLoadStatisticsMemoryStore>(*this, m_statisticsQueue);
     169            m_statisticsStore = std::make_unique<ResourceLoadStatisticsMemoryStore>(*this, m_statisticsQueue, shouldIncludeLocalhost);
    158170            m_persistentStorage = std::make_unique<ResourceLoadStatisticsPersistentStorage>(downcast<ResourceLoadStatisticsMemoryStore>(*m_statisticsStore), m_statisticsQueue, resourceLoadStatisticsDirectory);
    159171        }
  • trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h

    r242603 r242712  
    5959class WebProcessProxy;
    6060enum class ShouldGrandfatherStatistics : bool;
     61enum class ShouldIncludeLocalhost : bool { No, Yes };
    6162
    6263class WebResourceLoadStatisticsStore final : public ThreadSafeRefCounted<WebResourceLoadStatisticsStore, WTF::DestructionThread::Main>, public IPC::MessageReceiver {
     
    7879    using FrameID = uint64_t;
    7980
    80     static Ref<WebResourceLoadStatisticsStore> create(NetworkSession& networkSession, const String& resourceLoadStatisticsDirectory)
     81    static Ref<WebResourceLoadStatisticsStore> create(NetworkSession& networkSession, const String& resourceLoadStatisticsDirectory, ShouldIncludeLocalhost shouldIncludeLocalhost)
    8182    {
    82         return adoptRef(*new WebResourceLoadStatisticsStore(networkSession, resourceLoadStatisticsDirectory));
     83        return adoptRef(*new WebResourceLoadStatisticsStore(networkSession, resourceLoadStatisticsDirectory, shouldIncludeLocalhost));
    8384    }
    8485
     
    129130    void removePrevalentDomains(const Vector<RegistrableDomain>&);
    130131    void setNotifyPagesWhenDataRecordsWereScanned(bool, CompletionHandler<void()>&&);
     132    void setIsRunningTest(bool, CompletionHandler<void()>&&);
    131133    void setSubframeUnderTopFrameDomain(const SubFrameDomain&, const TopFrameDomain&, CompletionHandler<void()>&&);
    132134    void setSubresourceUnderTopFrameDomain(const SubResourceDomain&, const TopFrameDomain&, CompletionHandler<void()>&&);
     
    172174
    173175private:
    174     explicit WebResourceLoadStatisticsStore(NetworkSession&, const String&);
     176    explicit WebResourceLoadStatisticsStore(NetworkSession&, const String&, ShouldIncludeLocalhost);
    175177
    176178    void postTask(WTF::Function<void()>&&);
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp

    r242603 r242712  
    787787}
    788788
     789void NetworkProcess::setIsRunningResourceLoadStatisticsTest(PAL::SessionID sessionID, bool value, CompletionHandler<void()>&& completionHandler)
     790{
     791    if (auto* networkSession = this->networkSession(sessionID)) {
     792        if (auto* resourceLoadStatistics = networkSession->resourceLoadStatistics())
     793            resourceLoadStatistics->setIsRunningTest(value, WTFMove(completionHandler));
     794        else
     795            completionHandler();
     796    } else {
     797        ASSERT_NOT_REACHED();
     798        completionHandler();
     799    }
     800}
     801
    789802void NetworkProcess::setNotifyPagesWhenTelemetryWasCaptured(PAL::SessionID sessionID, bool value, CompletionHandler<void()>&& completionHandler)
    790803{
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.h

    r242603 r242712  
    245245    void setMinimumTimeBetweenDataRecordsRemoval(PAL::SessionID, Seconds, CompletionHandler<void()>&&);
    246246    void setNotifyPagesWhenDataRecordsWereScanned(PAL::SessionID, bool value, CompletionHandler<void()>&&);
     247    void setIsRunningResourceLoadStatisticsTest(PAL::SessionID, bool value, CompletionHandler<void()>&&);
    247248    void setNotifyPagesWhenTelemetryWasCaptured(PAL::SessionID, bool value, CompletionHandler<void()>&&);
    248249    void setResourceLoadStatisticsEnabled(bool);
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.messages.in

    r242603 r242712  
    122122    SetShouldClassifyResourcesBeforeDataRecordsRemoval(PAL::SessionID sessionID, bool value) -> () Async
    123123    SetNotifyPagesWhenDataRecordsWereScanned(PAL::SessionID sessionID, bool value) -> () Async
     124    SetIsRunningResourceLoadStatisticsTest(PAL::SessionID sessionID, bool value) -> () Async
    124125    SetNotifyPagesWhenTelemetryWasCaptured(PAL::SessionID sessionID, bool value) -> () Async
    125126    SetResourceLoadStatisticsDebugMode(PAL::SessionID sessionID, bool debugMode) -> () Async
  • trunk/Source/WebKit/NetworkProcess/NetworkSession.cpp

    r242598 r242712  
    3131#include "NetworkProcessProxyMessages.h"
    3232#include "WebProcessProxy.h"
    33 #include "WebResourceLoadStatisticsStore.h"
    3433#include <WebCore/AdClickAttribution.h>
    3534#include <WebCore/CookieJar.h>
     
    10099    if (m_sessionID.isEphemeral())
    101100        return;
    102    
    103     m_resourceLoadStatistics = WebResourceLoadStatisticsStore::create(*this, m_resourceLoadStatisticsDirectory);
     101
     102    m_resourceLoadStatistics = WebResourceLoadStatisticsStore::create(*this, m_resourceLoadStatisticsDirectory, m_shouldIncludeLocalhostInResourceLoadStatistics);
    104103}
    105104
  • trunk/Source/WebKit/NetworkProcess/NetworkSession.h

    r242598 r242712  
    2626#pragma once
    2727
     28#include "WebResourceLoadStatisticsStore.h"
    2829#include <WebCore/RegistrableDomain.h>
    2930#include <pal/SessionID.h>
     
    9293#if ENABLE(RESOURCE_LOAD_STATISTICS)
    9394    RefPtr<WebResourceLoadStatisticsStore> m_resourceLoadStatistics;
     95    ShouldIncludeLocalhost m_shouldIncludeLocalhostInResourceLoadStatistics { ShouldIncludeLocalhost::Yes };
    9496#endif
    9597    UniqueRef<NetworkAdClickAttribution> m_adClickAttribution;
  • trunk/Source/WebKit/NetworkProcess/NetworkSessionCreationParameters.cpp

    r240858 r242712  
    8080    encoder << resourceLoadStatisticsDirectoryExtensionHandle;
    8181    encoder << enableResourceLoadStatistics;
     82    encoder << shouldIncludeLocalhostInResourceLoadStatistics;
    8283}
    8384
     
    171172    decoder >> enableResourceLoadStatistics;
    172173    if (!enableResourceLoadStatistics)
     174        return WTF::nullopt;
     175
     176    Optional<bool> shouldIncludeLocalhostInResourceLoadStatistics;
     177    decoder >> shouldIncludeLocalhostInResourceLoadStatistics;
     178    if (!shouldIncludeLocalhostInResourceLoadStatistics)
    173179        return WTF::nullopt;
    174180
     
    197203        , WTFMove(*resourceLoadStatisticsDirectoryExtensionHandle)
    198204        , WTFMove(*enableResourceLoadStatistics)
     205        , WTFMove(*shouldIncludeLocalhostInResourceLoadStatistics)
    199206    }};
    200207}
  • trunk/Source/WebKit/NetworkProcess/NetworkSessionCreationParameters.h

    r240858 r242712  
    8282    SandboxExtension::Handle resourceLoadStatisticsDirectoryExtensionHandle;
    8383    bool enableResourceLoadStatistics { false };
     84    bool shouldIncludeLocalhostInResourceLoadStatistics { true };
    8485};
    8586
  • trunk/Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm

    r242367 r242712  
    949949#if ENABLE(RESOURCE_LOAD_STATISTICS)
    950950    m_resourceLoadStatisticsDirectory = parameters.resourceLoadStatisticsDirectory;
     951    m_shouldIncludeLocalhostInResourceLoadStatistics = parameters.shouldIncludeLocalhostInResourceLoadStatistics ? ShouldIncludeLocalhost::Yes : ShouldIncludeLocalhost::No;
    951952    setResourceLoadStatisticsEnabled(parameters.enableResourceLoadStatistics);
    952953#endif
  • trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp

    r242598 r242712  
    337337}
    338338
     339void WKWebsiteDataStoreSetStatisticsIsRunningTest(WKWebsiteDataStoreRef dataStoreRef, bool value, void* context, WKWebsiteDataStoreSetStatisticsIsRunningTestFunction callback)
     340{
     341#if ENABLE(RESOURCE_LOAD_STATISTICS)
     342    WebKit::toImpl(dataStoreRef)->websiteDataStore().setIsRunningResourceLoadStatisticsTest(value, [context, callback] {
     343        callback(context);
     344    });
     345#else
     346    callback(context);
     347#endif
     348}
     349
    339350void WKWebsiteDataStoreSetStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(WKWebsiteDataStoreRef dataStoreRef, bool value)
    340351{
  • trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h

    r242598 r242712  
    8080WK_EXPORT void WKWebsiteDataStoreStatisticsSubmitTelemetry(WKWebsiteDataStoreRef dataStoreRef);
    8181WK_EXPORT void WKWebsiteDataStoreSetStatisticsNotifyPagesWhenDataRecordsWereScanned(WKWebsiteDataStoreRef dataStoreRef, bool value);
     82typedef void (*WKWebsiteDataStoreSetStatisticsIsRunningTestFunction)(void* functionContext);
     83WK_EXPORT void WKWebsiteDataStoreSetStatisticsIsRunningTest(WKWebsiteDataStoreRef dataStoreRef, bool value, void* context, WKWebsiteDataStoreSetStatisticsIsRunningTestFunction callback);
    8284WK_EXPORT void WKWebsiteDataStoreSetStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(WKWebsiteDataStoreRef dataStoreRef, bool value);
    8385WK_EXPORT void WKWebsiteDataStoreSetStatisticsNotifyPagesWhenTelemetryWasCaptured(WKWebsiteDataStoreRef dataStoreRef, bool value);
  • trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp

    r242603 r242712  
    595595}
    596596
     597void NetworkProcessProxy::setIsRunningResourceLoadStatisticsTest(PAL::SessionID sessionID, bool value, CompletionHandler<void()>&& completionHandler)
     598{
     599    if (!canSendMessage()) {
     600        completionHandler();
     601        return;
     602    }
     603   
     604    sendWithAsyncReply(Messages::NetworkProcess::SetIsRunningResourceLoadStatisticsTest(sessionID, value), WTFMove(completionHandler));
     605}
     606
    597607void NetworkProcessProxy::setSubframeUnderTopFrameDomain(PAL::SessionID sessionID, const RegistrableDomain& subFrameDomain, const RegistrableDomain& topFrameDomain, CompletionHandler<void()>&& completionHandler)
    598608{
  • trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h

    r242603 r242712  
    114114    void setGrandfathered(PAL::SessionID, const RegistrableDomain&, bool isGrandfathered, CompletionHandler<void()>&&);
    115115    void setNotifyPagesWhenDataRecordsWereScanned(PAL::SessionID, bool, CompletionHandler<void()>&&);
     116    void setIsRunningResourceLoadStatisticsTest(PAL::SessionID, bool, CompletionHandler<void()>&&);
    116117    void setNotifyPagesWhenTelemetryWasCaptured(PAL::SessionID, bool, CompletionHandler<void()>&&);
    117118    void setSubframeUnderTopFrameDomain(PAL::SessionID, const SubFrameDomain&, const TopFrameDomain&, CompletionHandler<void()>&&);
  • trunk/Source/WebKit/UIProcess/WebProcessPool.cpp

    r242603 r242712  
    575575
    576576    bool enableResourceLoadStatistics = false;
    577     if (withWebsiteDataStore)
     577    bool shouldIncludeLocalhost = true;
     578    if (withWebsiteDataStore) {
    578579        enableResourceLoadStatistics = withWebsiteDataStore->resourceLoadStatisticsEnabled();
    579     else if (m_websiteDataStore)
     580        shouldIncludeLocalhost = withWebsiteDataStore->parameters().networkSessionParameters.shouldIncludeLocalhostInResourceLoadStatistics;
     581    } else if (m_websiteDataStore) {
    580582        enableResourceLoadStatistics = m_websiteDataStore->resourceLoadStatisticsEnabled();
     583        shouldIncludeLocalhost = m_websiteDataStore->websiteDataStore().parameters().networkSessionParameters.shouldIncludeLocalhostInResourceLoadStatistics;
     584    }
    581585
    582586    parameters.defaultDataStoreParameters.networkSessionParameters.enableResourceLoadStatistics = enableResourceLoadStatistics;
     587    parameters.defaultDataStoreParameters.networkSessionParameters.shouldIncludeLocalhostInResourceLoadStatistics = shouldIncludeLocalhost;
    583588
    584589    // Add any platform specific parameters
  • trunk/Source/WebKit/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm

    r242302 r242712  
    103103        WTFMove(resourceLoadStatisticsDirectory),
    104104        WTFMove(resourceLoadStatisticsDirectoryHandle),
    105         false
     105        false,
     106        isSafari
    106107    };
    107108    finalizeApplicationIdentifiers();
  • trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp

    r242598 r242712  
    16091609}
    16101610
     1611void WebsiteDataStore::setIsRunningResourceLoadStatisticsTest(bool value, CompletionHandler<void()>&& completionHandler)
     1612{
     1613    auto callbackAggregator = CallbackAggregator::create(WTFMove(completionHandler));
     1614   
     1615    for (auto& processPool : processPools())
     1616        processPool->ensureNetworkProcess().setIsRunningResourceLoadStatisticsTest(m_sessionID, value, [processPool, callbackAggregator = callbackAggregator.copyRef()] { });
     1617}
     1618
    16111619void WebsiteDataStore::setNotifyPagesWhenTelemetryWasCaptured(bool value, CompletionHandler<void()>&& completionHandler)
    16121620{
  • trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h

    r242598 r242712  
    148148    void setLastSeen(const URL&, Seconds, CompletionHandler<void()>&&);
    149149    void setNotifyPagesWhenDataRecordsWereScanned(bool, CompletionHandler<void()>&&);
     150    void setIsRunningResourceLoadStatisticsTest(bool, CompletionHandler<void()>&&);
    150151    void setPruneEntriesDownTo(size_t, CompletionHandler<void()>&&);
    151152    void setSubframeUnderTopFrameDomain(const URL& subframe, const URL& topFrame, CompletionHandler<void()>&&);
  • trunk/Tools/ChangeLog

    r242711 r242712  
     12019-03-11  John Wilander  <wilander@apple.com>
     2
     3        Resource Load Statistics: Make it possible exclude localhost from classification
     4        https://bugs.webkit.org/show_bug.cgi?id=195474
     5        <rdar://problem/47520577>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        This patch allows for localhost to be excluded from classification and
     10        treatment as a prevalent resource.
     11
     12        The WebKit Tools change adds a new function called
     13        testRunner.setStatisticsIsRunningTest() which can be used to control this
     14        behavior.
     15
     16        * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
     17        * WebKitTestRunner/InjectedBundle/TestRunner.cpp:
     18        (WTR::TestRunner::setStatisticsIsRunningTest):
     19        * WebKitTestRunner/InjectedBundle/TestRunner.h:
     20        * WebKitTestRunner/TestController.cpp:
     21        (WTR::TestController::setStatisticsIsRunningTest):
     22        * WebKitTestRunner/TestController.h:
     23        * WebKitTestRunner/TestInvocation.cpp:
     24        (WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):
     25
    1262019-03-11  Aakash Jain  <aakash_jain@apple.com>
    227
  • trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl

    r242664 r242712  
    310310    void statisticsSubmitTelemetry();
    311311    void setStatisticsNotifyPagesWhenDataRecordsWereScanned(boolean value);
     312    void setStatisticsIsRunningTest(boolean value);
    312313    void setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(boolean value);
    313314    void setStatisticsNotifyPagesWhenTelemetryWasCaptured(boolean value);
  • trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp

    r242664 r242712  
    19481948}
    19491949
     1950void TestRunner::setStatisticsIsRunningTest(bool value)
     1951{
     1952    WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("StatisticsSetIsRunningTest"));
     1953    WKRetainPtr<WKBooleanRef> messageBody(AdoptWK, WKBooleanCreate(value));
     1954    WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr);
     1955}
     1956
    19501957void TestRunner::setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(bool value)
    19511958{
  • trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h

    r242664 r242712  
    419419    void setStatisticsTimeToLiveUserInteraction(double seconds);
    420420    void setStatisticsNotifyPagesWhenDataRecordsWereScanned(bool);
     421    void setStatisticsIsRunningTest(bool);
    421422    void setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(bool);
    422423    void setStatisticsNotifyPagesWhenTelemetryWasCaptured(bool value);
  • trunk/Tools/WebKitTestRunner/TestController.cpp

    r242664 r242712  
    32893289}
    32903290
     3291void TestController::setStatisticsIsRunningTest(bool value)
     3292{
     3293    auto* dataStore = WKContextGetWebsiteDataStore(platformContext());
     3294    ResourceStatisticsCallbackContext context(*this);
     3295    WKWebsiteDataStoreSetStatisticsIsRunningTest(dataStore, value, &context, resourceStatisticsVoidResultCallback);
     3296    runUntil(context.done, noTimeout);
     3297}
     3298
    32913299void TestController::setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(bool value)
    32923300{
  • trunk/Tools/WebKitTestRunner/TestController.h

    r242664 r242712  
    231231    void statisticsSubmitTelemetry();
    232232    void setStatisticsNotifyPagesWhenDataRecordsWereScanned(bool);
     233    void setStatisticsIsRunningTest(bool);
    233234    void setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(bool);
    234235    void setStatisticsNotifyPagesWhenTelemetryWasCaptured(bool value);
  • trunk/Tools/WebKitTestRunner/TestInvocation.cpp

    r242664 r242712  
    13341334    }
    13351335
     1336    if (WKStringIsEqualToUTF8CString(messageName, "StatisticsSetIsRunningTest")) {
     1337        ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
     1338        WKBooleanRef value = static_cast<WKBooleanRef>(messageBody);
     1339        TestController::singleton().setStatisticsIsRunningTest(WKBooleanGetValue(value));
     1340        return nullptr;
     1341    }
     1342   
    13361343    if (WKStringIsEqualToUTF8CString(messageName, "StatisticsNotifyPagesWhenTelemetryWasCaptured")) {
    13371344        ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
Note: See TracChangeset for help on using the changeset viewer.