Changeset 252840 in webkit


Ignore:
Timestamp:
Nov 23, 2019 7:05:49 PM (4 years ago)
Author:
wilander@apple.com
Message:

Resource Load Statistics: Allow multiple third-party cookie blocking settings
https://bugs.webkit.org/show_bug.cgi?id=204389
<rdar://problem/57344054>

Reviewed by Brent Fulgham.

Source/WebCore:

This change introduces an enum ThirdPartyCookieBlockingMode for how third-party
cookie blocking should be carried out. It then uses the set mode in
NetworkStorageSession::shouldBlockCookies().

The reason for supporting three different modes is that what is now named
OnlyAccordingToPerDomainPolicy is shipping, AllOnSitesWithoutUserInteraction is
in beta, and All is behind an experimental flag.

Tests: http/tests/resourceLoadStatistics/third-party-cookie-blocking-on-sites-without-user-interaction-database.html

http/tests/resourceLoadStatistics/third-party-cookie-blocking-on-sites-without-user-interaction.html

  • page/Settings.yaml:

Flipped the isThirdPartyCookieBlockingEnabled flag to on by default.

  • platform/network/NetworkStorageSession.cpp:

(WebCore::NetworkStorageSession::shouldBlockCookies const):
(WebCore::NetworkStorageSession::setThirdPartyCookieBlockingMode):

  • platform/network/NetworkStorageSession.h:

(WebCore::NetworkStorageSession::setIsThirdPartyCookieBlockingEnabled): Deleted.

Source/WebKit:

This change make the third-party cookie blocking setting go from a boolean to
the new enum WebCore::ThirdPartyCookieBlockingMode with three different settings.
Functions and member variables are renamed accordingly.

The reason for supporting three different modes is that what is now named
OnlyAccordingToPerDomainPolicy is shipping, AllOnSitesWithoutUserInteraction is
in beta, and All is behind an experimental flag.

The change also updates the test API to map the TestRunner call to the enum.

  • NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp:

(WebKit::ResourceLoadStatisticsDatabaseStore::hasStorageAccess):
(WebKit::ResourceLoadStatisticsDatabaseStore::requestStorageAccess):
(WebKit::ResourceLoadStatisticsDatabaseStore::clearUserInteraction):

Now makes use of a completion handler and updates the cookie blocking state.

(WebKit::ResourceLoadStatisticsDatabaseStore::hasHadUserInteraction):
(WebKit::ResourceLoadStatisticsDatabaseStore::areAllThirdPartyCookiesBlockedUnder):

New convenience function to check the cookie blocking status per first-party domain.

(WebKit::ResourceLoadStatisticsDatabaseStore::cookieAccess):

Restructured the code to make it very clear that the logic is the same as the
corresponding function in ResourceLoadStatisticsMemoryStore.
Can no longer be const since it calls areAllThirdPartyCookiesBlockedUnder() which
in turn calls hasHadUserInteraction() and that function may clear user interaction data.

(WebKit::ResourceLoadStatisticsDatabaseStore::hasHadUnexpiredRecentUserInteraction):
(WebKit::ResourceLoadStatisticsDatabaseStore::cookieAccess const): Deleted.

See comment above on the non-const version of this function.

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

(WebKit::ResourceLoadStatisticsMemoryStore::areAllThirdPartyCookiesBlockedUnder):

New convenience function to check the cookie blocking status per first-party domain.

(WebKit::ResourceLoadStatisticsMemoryStore::cookieAccess):

Restructured the code to make it very clear that the logic is the same as the
corresponding function in ResourceLoadStatisticsDatabaseStore.
Can no longer be const since it calls areAllThirdPartyCookiesBlockedUnder() which
in turn calls hasHadUserInteraction() and that function may clear user interaction data.

(WebKit::ResourceLoadStatisticsMemoryStore::hasStorageAccess):
(WebKit::ResourceLoadStatisticsMemoryStore::requestStorageAccess):
(WebKit::ResourceLoadStatisticsMemoryStore::clearUserInteraction):

Now makes use of a completion handler and updates the cookie blocking state.

(WebKit::ResourceLoadStatisticsMemoryStore::cookieAccess const): Deleted.

See comment above on the non-const version of this function.

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

(WebKit::ResourceLoadStatisticsStore::setThirdPartyCookieBlockingMode):
(WebKit::ResourceLoadStatisticsStore::thirdPartyCookieBlockingMode const):
(WebKit::ResourceLoadStatisticsStore::setIsThirdPartyCookieBlockingEnabled): Deleted.
(WebKit::ResourceLoadStatisticsStore::isThirdPartyCookieBlockingEnabled const): Deleted.

  • NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:

(WebKit::WebResourceLoadStatisticsStore::setThirdPartyCookieBlockingMode):
(WebKit::WebResourceLoadStatisticsStore::clearUserInteraction):

Now forwards the completion handler.

(WebKit::WebResourceLoadStatisticsStore::setIsThirdPartyCookieBlockingEnabled): Deleted.

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

(WebKit::NetworkProcess::setShouldBlockThirdPartyCookiesForTesting):

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

The SetShouldBlockThirdPartyCookiesForTesting message now uses an enum instead of a
boolean.

  • NetworkProcess/NetworkSession.cpp:

(WebKit::NetworkSession::setResourceLoadStatisticsEnabled):

Now forwards the enum value instead of a boolean.

(WebKit::NetworkSession::recreateResourceLoadStatisticStore):

Now makes sure the cookie blocking setting is forwarded to the recreated store.

(WebKit::NetworkSession::setThirdPartyCookieBlockingMode):
(WebKit::NetworkSession::setIsThirdPartyCookieBlockingEnabled): Deleted.

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

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

Support for the new enum.

  • NetworkProcess/NetworkSessionCreationParameters.h:
  • NetworkProcess/cocoa/NetworkSessionCocoa.mm:

(WebKit::NetworkSessionCocoa::NetworkSessionCocoa):

  • Scripts/webkit/messages.py:

Tells the IPC code generator where to find WebCore::ThirdPartyCookieBlockingMode.

  • Shared/WebPreferences.yaml:

Flipped the IsThirdPartyCookieBlockingEnabled flag to on by default.

  • UIProcess/API/C/WKWebsiteDataStoreRef.cpp:

(WKWebsiteDataStoreSetResourceLoadStatisticsShouldBlockThirdPartyCookiesForTesting):
(WKWebsiteDataStoreStatisticsResetToConsistentState):

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

(WebKit::NetworkProcessProxy::setShouldBlockThirdPartyCookiesForTesting):

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

(WebKit::WebProcessPool::ensureNetworkProcess):

Makes use of the enum in the NetworkSessionCreationParameters.

  • UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:

(WebKit::WebsiteDataStore::parameters):

  • UIProcess/WebsiteData/WebsiteDataStore.cpp:

(WebKit::WebsiteDataStore::setResourceLoadStatisticsShouldBlockThirdPartyCookiesForTesting):

  • UIProcess/WebsiteData/WebsiteDataStore.h:

Tools:

This change allows the existing TestRunner function
setStatisticsShouldBlockThirdPartyCookies() to set an optional boolean
parameter onlyOnSitesWithoutUserInteraction to opt in to that behavior.

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

(WTR::TestRunner::setStatisticsShouldBlockThirdPartyCookies):

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

(WTR::TestController::setStatisticsShouldBlockThirdPartyCookies):

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

(WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):

LayoutTests:

The added tests existed before and are not re-introduced to test their dedicated setting.

The changed tests have been expanded to cover the new code paths.

  • http/tests/resourceLoadStatistics/third-party-cookie-blocking-on-sites-without-user-interaction-database-expected.txt: Added.
  • http/tests/resourceLoadStatistics/third-party-cookie-blocking-on-sites-without-user-interaction-database.html: Added.
  • http/tests/resourceLoadStatistics/third-party-cookie-blocking-on-sites-without-user-interaction-expected.txt: Added.
  • http/tests/resourceLoadStatistics/third-party-cookie-blocking-on-sites-without-user-interaction.html: Added.
  • http/tests/storageAccess/grant-with-prompt-under-general-third-party-cookie-blocking-database-expected.txt:
  • http/tests/storageAccess/grant-with-prompt-under-general-third-party-cookie-blocking-database.html:
  • http/tests/storageAccess/grant-with-prompt-under-general-third-party-cookie-blocking-expected.txt:
  • http/tests/storageAccess/grant-with-prompt-under-general-third-party-cookie-blocking.html:
  • http/tests/storageAccess/has-storage-access-under-general-third-party-cookie-blocking-with-cookie-database-expected.txt:
  • http/tests/storageAccess/has-storage-access-under-general-third-party-cookie-blocking-with-cookie-database.html:
  • http/tests/storageAccess/has-storage-access-under-general-third-party-cookie-blocking-with-cookie-expected.txt:
  • http/tests/storageAccess/has-storage-access-under-general-third-party-cookie-blocking-with-cookie.html:
Location:
trunk
Files:
4 added
46 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r252838 r252840  
     12019-11-23  John Wilander  <wilander@apple.com>
     2
     3        Resource Load Statistics: Allow multiple third-party cookie blocking settings
     4        https://bugs.webkit.org/show_bug.cgi?id=204389
     5        <rdar://problem/57344054>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        The added tests existed before and are not re-introduced to test their dedicated setting.
     10
     11        The changed tests have been expanded to cover the new code paths.
     12
     13        * http/tests/resourceLoadStatistics/third-party-cookie-blocking-on-sites-without-user-interaction-database-expected.txt: Added.
     14        * http/tests/resourceLoadStatistics/third-party-cookie-blocking-on-sites-without-user-interaction-database.html: Added.
     15        * http/tests/resourceLoadStatistics/third-party-cookie-blocking-on-sites-without-user-interaction-expected.txt: Added.
     16        * http/tests/resourceLoadStatistics/third-party-cookie-blocking-on-sites-without-user-interaction.html: Added.
     17        * http/tests/storageAccess/grant-with-prompt-under-general-third-party-cookie-blocking-database-expected.txt:
     18        * http/tests/storageAccess/grant-with-prompt-under-general-third-party-cookie-blocking-database.html:
     19        * http/tests/storageAccess/grant-with-prompt-under-general-third-party-cookie-blocking-expected.txt:
     20        * http/tests/storageAccess/grant-with-prompt-under-general-third-party-cookie-blocking.html:
     21        * http/tests/storageAccess/has-storage-access-under-general-third-party-cookie-blocking-with-cookie-database-expected.txt:
     22        * http/tests/storageAccess/has-storage-access-under-general-third-party-cookie-blocking-with-cookie-database.html:
     23        * http/tests/storageAccess/has-storage-access-under-general-third-party-cookie-blocking-with-cookie-expected.txt:
     24        * http/tests/storageAccess/has-storage-access-under-general-third-party-cookie-blocking-with-cookie.html:
     25
    1262019-11-23  Jonathan Bedard  <jbedard@apple.com>
    227
  • trunk/LayoutTests/http/tests/storageAccess/grant-with-prompt-under-general-third-party-cookie-blocking-database-expected.txt

    r251663 r252840  
    55
    66PASS Storage access was granted. document.cookie == firstPartyCookie=value, cookies seen server-side == {"firstPartyCookie":"value"}
     7PASS Storage access was granted. document.cookie == firstPartyCookie=value, cookies seen server-side == {"firstPartyCookie":"value"}
    78PASS successfullyParsed is true
    89
  • trunk/LayoutTests/http/tests/storageAccess/grant-with-prompt-under-general-third-party-cookie-blocking-database.html

    r252210 r252840  
    2121            } else
    2222                testFailed("Received a message from an unexpected origin: " + event.origin);
    23             testRunner.setStatisticsShouldBlockThirdPartyCookies(false, function() {
    24                 setEnableFeature(false, finishJSTest);
    25             });
     23
     24            switch (document.location.hash) {
     25                case "#firstTest":
     26                    document.location.hash = "secondTest";
     27                    // Clear all data so that the previous grant doesn't count toward the next test.
     28                    testRunner.statisticsClearInMemoryAndPersistentStore(runTest);
     29                    break;
     30                case "#secondTest":
     31                    testRunner.setStatisticsShouldBlockThirdPartyCookies(false, function() {
     32                        setEnableFeature(false, finishJSTest);
     33                    });
     34                    break;
     35                default:
     36                    testFailed("Message handler called under unknown circumstances.");
     37                    testRunner.setStatisticsShouldBlockThirdPartyCookies(false, function() {
     38                        setEnableFeature(false, finishJSTest);
     39                    });
     40            }
    2641        }
    2742
     
    5368
    5469        function runTest() {
    55             if (document.location.hash !== "#cookieSet") {
    56                 setEnableFeature(true, function() {
    57                     document.location.href = thirdPartyUrl + "/storageAccess/resources/set-cookie.php?name=firstPartyCookie&value=value#" + firstPartyUrl + "/storageAccess/grant-with-prompt-under-general-third-party-cookie-blocking-database.html#cookieSet";
    58                 });
    59             } else {
    60                 testRunner.setStatisticsShouldBlockThirdPartyCookies(true, function() {
    61                     if (testRunner.isStatisticsPrevalentResource(thirdPartyUrl))
    62                         testFailed("Third-party set as prevalent resource.");
    63                     testRunner.setStatisticsHasHadUserInteraction(firstPartyUrl, true, function() {
    64                         if (!testRunner.isStatisticsHasHadUserInteraction(firstPartyUrl))
    65                             testFailed("First-party did not get logged for user interaction.");
     70            switch (document.location.hash) {
     71                case "":
     72                    setEnableFeature(true, function() {
     73                        document.location.href = thirdPartyUrl + "/storageAccess/resources/set-cookie.php?dummy=" + Math.random() + "&name=firstPartyCookie&value=value#" + firstPartyUrl + "/storageAccess/grant-with-prompt-under-general-third-party-cookie-blocking-database.html#firstTest";
     74                    });
     75                    break;
     76                case "#firstTest":
     77                    // Test that the request is granted if third-party cookies are blocked under first-parties without
     78                    // user interaction.
     79                    testRunner.setStatisticsShouldBlockThirdPartyCookies(true, function() {
     80                        if (testRunner.isStatisticsPrevalentResource(thirdPartyUrl))
     81                            testFailed("Third-party set as prevalent resource.");
     82                        if (testRunner.isStatisticsHasHadUserInteraction(firstPartyUrl))
     83                            testFailed("First-party was logged for user interaction.");
    6684                        testRunner.setStatisticsHasHadUserInteraction(thirdPartyUrl, true, function() {
    6785                            if (!testRunner.isStatisticsHasHadUserInteraction(thirdPartyUrl))
     
    6987                            let iframeElement = document.createElement("iframe");
    7088                            iframeElement.onload = function() {
    71                                 activateElement("TheIframeThatRequestsStorageAccess");
     89                                activateElement("TheFirstIframeThatRequestsStorageAccess");
    7290                            };
    73                             iframeElement.id = "TheIframeThatRequestsStorageAccess";
    74                             iframeElement.src = "http://localhost:8000/storageAccess/resources/request-storage-access-iframe.html#userShouldGrantAccess,userShouldBeConsulted,policyShouldGrantAccess,isNotSameOriginIframe";
     91                            iframeElement.id = "TheFirstIframeThatRequestsStorageAccess";
     92                            iframeElement.src = "http://localhost:8000/storageAccess/resources/request-storage-access-iframe.html?dummy=" + Math.random() + "#userShouldGrantAccess,userShouldBeConsulted,policyShouldGrantAccess,isNotSameOriginIframe";
    7593                            document.body.appendChild(iframeElement);
    7694                        });
    77                     });
    78                 });
     95                    }, true);
     96                    break;
     97                case "#secondTest":
     98                    // Test that the request is granted if third-party cookies are blocked unconditionally.
     99                    testRunner.setStatisticsShouldBlockThirdPartyCookies(true, function() {
     100                        if (testRunner.isStatisticsPrevalentResource(thirdPartyUrl))
     101                            testFailed("Third-party set as prevalent resource.");
     102                        testRunner.setStatisticsHasHadUserInteraction(thirdPartyUrl, true, function() {
     103                            if (!testRunner.isStatisticsHasHadUserInteraction(thirdPartyUrl))
     104                                testFailed("Third-party did not get logged for user interaction.");
     105                            let iframeElement = document.createElement("iframe");
     106                            iframeElement.onload = function() {
     107                                activateElement("TheSecondIframeThatRequestsStorageAccess");
     108                            };
     109                            iframeElement.id = "TheSecondIframeThatRequestsStorageAccess";
     110                            iframeElement.src = "http://localhost:8000/storageAccess/resources/request-storage-access-iframe.html?dummy=" + Math.random() + "#userShouldGrantAccess,userShouldBeConsulted,policyShouldGrantAccess,isNotSameOriginIframe";
     111                            document.body.appendChild(iframeElement);
     112                        });
     113                    }, false);
     114                    break;
    79115            }
    80116        }
  • trunk/LayoutTests/http/tests/storageAccess/grant-with-prompt-under-general-third-party-cookie-blocking-expected.txt

    r251663 r252840  
    55
    66PASS Storage access was granted. document.cookie == firstPartyCookie=value, cookies seen server-side == {"firstPartyCookie":"value"}
     7PASS Storage access was granted. document.cookie == firstPartyCookie=value, cookies seen server-side == {"firstPartyCookie":"value"}
    78PASS successfullyParsed is true
    89
  • trunk/LayoutTests/http/tests/storageAccess/grant-with-prompt-under-general-third-party-cookie-blocking.html

    r251663 r252840  
    2020            } else
    2121                testFailed("Received a message from an unexpected origin: " + event.origin);
    22             testRunner.setStatisticsShouldBlockThirdPartyCookies(false, function() {
    23                 setEnableFeature(false, finishJSTest);
    24             });
     22
     23            switch (document.location.hash) {
     24                case "#firstTest":
     25                    document.location.hash = "secondTest";
     26                    // Clear all data so that the previous grant doesn't count toward the next test.
     27                    testRunner.statisticsClearInMemoryAndPersistentStore(runTest);
     28                    break;
     29                case "#secondTest":
     30                    testRunner.setStatisticsShouldBlockThirdPartyCookies(false, function() {
     31                        setEnableFeature(false, finishJSTest);
     32                    });
     33                    break;
     34                default:
     35                    testFailed("Message handler called under unknown circumstances.");
     36                    testRunner.setStatisticsShouldBlockThirdPartyCookies(false, function() {
     37                        setEnableFeature(false, finishJSTest);
     38                    });
     39            }
    2540        }
    2641
     
    5267
    5368        function runTest() {
    54             if (document.location.hash !== "#cookieSet") {
    55                 setEnableFeature(true, function() {
    56                     document.location.href = thirdPartyUrl + "/storageAccess/resources/set-cookie.php?name=firstPartyCookie&value=value#" + firstPartyUrl + "/storageAccess/grant-with-prompt-under-general-third-party-cookie-blocking.html#cookieSet";
    57                 });
    58             } else {
    59                 testRunner.setStatisticsShouldBlockThirdPartyCookies(true, function() {
    60                     if (testRunner.isStatisticsPrevalentResource(thirdPartyUrl))
    61                         testFailed("Third-party set as prevalent resource.");
    62                     testRunner.setStatisticsHasHadUserInteraction(firstPartyUrl, true, function() {
    63                         if (!testRunner.isStatisticsHasHadUserInteraction(firstPartyUrl))
    64                             testFailed("First-party did not get logged for user interaction.");
     69            switch (document.location.hash) {
     70                case "":
     71                    setEnableFeature(true, function() {
     72                        document.location.href = thirdPartyUrl + "/storageAccess/resources/set-cookie.php?dummy=" + Math.random() + "&name=firstPartyCookie&value=value#" + firstPartyUrl + "/storageAccess/grant-with-prompt-under-general-third-party-cookie-blocking.html#firstTest";
     73                    });
     74                    break;
     75                case "#firstTest":
     76                    // Test that the request is granted if third-party cookies are blocked under first-parties without
     77                    // user interaction.
     78                    testRunner.setStatisticsShouldBlockThirdPartyCookies(true, function() {
     79                        if (testRunner.isStatisticsPrevalentResource(thirdPartyUrl))
     80                            testFailed("Third-party set as prevalent resource.");
     81                            if (testRunner.isStatisticsHasHadUserInteraction(firstPartyUrl))
     82                                testFailed("First-party was logged for user interaction.");
     83                            testRunner.setStatisticsHasHadUserInteraction(thirdPartyUrl, true, function() {
     84                                if (!testRunner.isStatisticsHasHadUserInteraction(thirdPartyUrl))
     85                                    testFailed("Third-party did not get logged for user interaction.");
     86                                let iframeElement = document.createElement("iframe");
     87                                iframeElement.onload = function() {
     88                                    activateElement("TheFirstIframeThatRequestsStorageAccess");
     89                                };
     90                                iframeElement.id = "TheFirstIframeThatRequestsStorageAccess";
     91                                iframeElement.src = "http://localhost:8000/storageAccess/resources/request-storage-access-iframe.html?dummy=" + Math.random() + "#userShouldGrantAccess,userShouldBeConsulted,policyShouldGrantAccess,isNotSameOriginIframe";
     92                                document.body.appendChild(iframeElement);
     93                            });
     94                    }, true);
     95                    break;
     96                case "#secondTest":
     97                    // Test that the request is granted if third-party cookies are blocked unconditionally.
     98                    testRunner.setStatisticsShouldBlockThirdPartyCookies(true, function() {
     99                        if (testRunner.isStatisticsPrevalentResource(thirdPartyUrl))
     100                            testFailed("Third-party set as prevalent resource.");
    65101                        testRunner.setStatisticsHasHadUserInteraction(thirdPartyUrl, true, function() {
    66102                            if (!testRunner.isStatisticsHasHadUserInteraction(thirdPartyUrl))
     
    68104                            let iframeElement = document.createElement("iframe");
    69105                            iframeElement.onload = function() {
    70                                 activateElement("TheIframeThatRequestsStorageAccess");
     106                                activateElement("TheSecondIframeThatRequestsStorageAccess");
    71107                            };
    72                             iframeElement.id = "TheIframeThatRequestsStorageAccess";
    73                             iframeElement.src = "http://localhost:8000/storageAccess/resources/request-storage-access-iframe.html#userShouldGrantAccess,userShouldBeConsulted,policyShouldGrantAccess,isNotSameOriginIframe";
     108                            iframeElement.id = "TheSecondIframeThatRequestsStorageAccess";
     109                            iframeElement.src = "http://localhost:8000/storageAccess/resources/request-storage-access-iframe.html?dummy=" + Math.random() + "#userShouldGrantAccess,userShouldBeConsulted,policyShouldGrantAccess,isNotSameOriginIframe";
    74110                            document.body.appendChild(iframeElement);
    75111                        });
    76                     });
    77                 });
     112                    }, false);
     113                    break;
    78114            }
    79115        }
  • trunk/LayoutTests/http/tests/storageAccess/has-storage-access-under-general-third-party-cookie-blocking-with-cookie-database-expected.txt

    r251663 r252840  
    99PASS No storage access. document.cookie == , cookies seen server-side == "No cookies"
    1010PASS No storage access. document.cookie == , cookies seen server-side == "No cookies"
     11PASS No storage access. document.cookie == , cookies seen server-side == "No cookies"
    1112PASS successfullyParsed is true
    1213
  • trunk/LayoutTests/http/tests/storageAccess/has-storage-access-under-general-third-party-cookie-blocking-with-cookie-database.html

    r252210 r252840  
    2222            } else
    2323                testFailed("Received a message from an unexpected origin: " + event.origin);
     24
    2425            if (document.location.hash === "#lastStep") {
    2526                testRunner.setStatisticsShouldBlockThirdPartyCookies(false, function() {
     
    5152                    // No general third-party cookie blocking, no user interaction, not prevalent.
    5253                    let iframeElement = document.createElement("iframe");
    53                     iframeElement.src = thirdPartyUrl + "/storageAccess/resources/has-storage-access-iframe.html#policyShouldGrantAccess";
     54                    iframeElement.src = thirdPartyUrl + "/storageAccess/resources/has-storage-access-iframe.html?dummy=" + Math.random() + "#policyShouldGrantAccess";
    5455                    document.body.appendChild(iframeElement);
    5556                    break;
     
    6162                            testFailed("Third-party did not get logged for user interaction.");
    6263                        let iframeElement = document.createElement("iframe");
    63                         iframeElement.src = thirdPartyUrl + "/storageAccess/resources/has-storage-access-iframe.html#policyShouldGrantAccess";
     64                        iframeElement.src = thirdPartyUrl + "/storageAccess/resources/has-storage-access-iframe.html?dummy=" + Math.random() + "#policyShouldGrantAccess";
    6465                        document.body.appendChild(iframeElement);
    6566                    });
     
    7273                            testFailed("First-party did not get logged for user interaction.");
    7374                        let iframeElement = document.createElement("iframe");
    74                         iframeElement.src = thirdPartyUrl + "/storageAccess/resources/has-storage-access-iframe.html#policyShouldGrantAccess";
     75                        iframeElement.src = thirdPartyUrl + "/storageAccess/resources/has-storage-access-iframe.html?dummy=" + Math.random() + "#policyShouldGrantAccess";
    7576                        document.body.appendChild(iframeElement);
    7677                    });
     
    7879                case "#step4":
    7980                    document.location.hash = "step5";
     81                    // Third-party cookie blocking under first-parties without user interaction, only third-party user interaction, not prevalent.
     82                    testRunner.setStatisticsShouldBlockThirdPartyCookies(true, function() {
     83                        testRunner.setStatisticsHasHadUserInteraction(firstPartyUrl, false, function() {
     84                            if (testRunner.isStatisticsHasHadUserInteraction(firstPartyUrl))
     85                                testFailed("First-party got logged for user interaction.");
     86                            let iframeElement = document.createElement("iframe");
     87                            iframeElement.src = thirdPartyUrl + "/storageAccess/resources/has-storage-access-iframe.html?dummy=" + Math.random() + "#policyShouldNotGrantAccess";
     88                            document.body.appendChild(iframeElement);
     89                        });
     90                    }, true);
     91                    break;
     92                case "#step5":
     93                    document.location.hash = "step6";
    8094                    // General third-party cookie blocking, first- and third-party user interaction, not prevalent.
    8195                    testRunner.setStatisticsShouldBlockThirdPartyCookies(true, function() {
    82                         let iframeElement = document.createElement("iframe");
    83                         iframeElement.src = thirdPartyUrl + "/storageAccess/resources/has-storage-access-iframe.html#policyShouldNotGrantAccess";
    84                         document.body.appendChild(iframeElement);
    85                     });
     96                        testRunner.setStatisticsHasHadUserInteraction(firstPartyUrl, true, function() {
     97                            if (!testRunner.isStatisticsHasHadUserInteraction(firstPartyUrl))
     98                                testFailed("First-party did not get logged for user interaction.");
     99                            let iframeElement = document.createElement("iframe");
     100                            iframeElement.src = thirdPartyUrl + "/storageAccess/resources/has-storage-access-iframe.html?dummy=" + Math.random() + "#policyShouldNotGrantAccess";
     101                            document.body.appendChild(iframeElement);
     102                        });
     103                    }, false);
    86104                    break;
    87                 case "#step5":
     105                case "#step6":
    88106                    document.location.hash = "lastStep";
    89107                    // General third-party cookie blocking, first- and third-party user interaction, prevalent.
     
    93111                        testRunner.statisticsUpdateCookieBlocking(function() {
    94112                            let iframeElement = document.createElement("iframe");
    95                             iframeElement.src = thirdPartyUrl + "/storageAccess/resources/has-storage-access-iframe.html#policyShouldNotGrantAccess";
     113                            iframeElement.src = thirdPartyUrl + "/storageAccess/resources/has-storage-access-iframe.html?dummy=" + Math.random() + "#policyShouldNotGrantAccess";
    96114                            document.body.appendChild(iframeElement);
    97115                        });
  • trunk/LayoutTests/http/tests/storageAccess/has-storage-access-under-general-third-party-cookie-blocking-with-cookie-expected.txt

    r251663 r252840  
    99PASS No storage access. document.cookie == , cookies seen server-side == "No cookies"
    1010PASS No storage access. document.cookie == , cookies seen server-side == "No cookies"
     11PASS No storage access. document.cookie == , cookies seen server-side == "No cookies"
    1112PASS successfullyParsed is true
    1213
  • trunk/LayoutTests/http/tests/storageAccess/has-storage-access-under-general-third-party-cookie-blocking-with-cookie.html

    r251663 r252840  
    2121            } else
    2222                testFailed("Received a message from an unexpected origin: " + event.origin);
     23
    2324            if (document.location.hash === "#lastStep") {
    2425                testRunner.setStatisticsShouldBlockThirdPartyCookies(false, function() {
     
    5051                    // No general third-party cookie blocking, no user interaction, not prevalent.
    5152                    let iframeElement = document.createElement("iframe");
    52                     iframeElement.src = thirdPartyUrl + "/storageAccess/resources/has-storage-access-iframe.html#policyShouldGrantAccess";
     53                    iframeElement.src = thirdPartyUrl + "/storageAccess/resources/has-storage-access-iframe.html?dummy=" + Math.random() + "#policyShouldGrantAccess";
    5354                    document.body.appendChild(iframeElement);
    5455                    break;
     
    6061                            testFailed("Third-party did not get logged for user interaction.");
    6162                        let iframeElement = document.createElement("iframe");
    62                         iframeElement.src = thirdPartyUrl + "/storageAccess/resources/has-storage-access-iframe.html#policyShouldGrantAccess";
     63                        iframeElement.src = thirdPartyUrl + "/storageAccess/resources/has-storage-access-iframe.html?dummy=" + Math.random() + "#policyShouldGrantAccess";
    6364                        document.body.appendChild(iframeElement);
    6465                    });
     
    7172                            testFailed("First-party did not get logged for user interaction.");
    7273                        let iframeElement = document.createElement("iframe");
    73                         iframeElement.src = thirdPartyUrl + "/storageAccess/resources/has-storage-access-iframe.html#policyShouldGrantAccess";
     74                        iframeElement.src = thirdPartyUrl + "/storageAccess/resources/has-storage-access-iframe.html?dummy=" + Math.random() + "#policyShouldGrantAccess";
    7475                        document.body.appendChild(iframeElement);
    7576                    });
     
    7778                case "#step4":
    7879                    document.location.hash = "step5";
     80                    // Third-party cookie blocking under first-parties without user interaction, only third-party user interaction, not prevalent.
     81                    testRunner.setStatisticsShouldBlockThirdPartyCookies(true, function() {
     82                        testRunner.setStatisticsHasHadUserInteraction(firstPartyUrl, false, function() {
     83                            if (testRunner.isStatisticsHasHadUserInteraction(firstPartyUrl))
     84                                testFailed("First-party got logged for user interaction.");
     85                            let iframeElement = document.createElement("iframe");
     86                            iframeElement.src = thirdPartyUrl + "/storageAccess/resources/has-storage-access-iframe.html?dummy=" + Math.random() + "#policyShouldNotGrantAccess";
     87                            document.body.appendChild(iframeElement);
     88                        });
     89                    }, true);
     90                    break;
     91                case "#step5":
     92                    document.location.hash = "step6";
    7993                    // General third-party cookie blocking, first- and third-party user interaction, not prevalent.
    8094                    testRunner.setStatisticsShouldBlockThirdPartyCookies(true, function() {
     95                        testRunner.setStatisticsHasHadUserInteraction(firstPartyUrl, true, function() {
     96                            if (!testRunner.isStatisticsHasHadUserInteraction(firstPartyUrl))
     97                                testFailed("First-party did not get logged for user interaction.");
    8198                        let iframeElement = document.createElement("iframe");
    82                         iframeElement.src = thirdPartyUrl + "/storageAccess/resources/has-storage-access-iframe.html#policyShouldNotGrantAccess";
     99                        iframeElement.src = thirdPartyUrl + "/storageAccess/resources/has-storage-access-iframe.html?dummy=" + Math.random() + "#policyShouldNotGrantAccess";
    83100                        document.body.appendChild(iframeElement);
    84                     });
     101                        });
     102                    }, false);
    85103                    break;
    86                 case "#step5":
     104                case "#step6":
    87105                    document.location.hash = "lastStep";
    88106                    // General third-party cookie blocking, first- and third-party user interaction, prevalent.
     
    92110                        testRunner.statisticsUpdateCookieBlocking(function() {
    93111                            let iframeElement = document.createElement("iframe");
    94                             iframeElement.src = thirdPartyUrl + "/storageAccess/resources/has-storage-access-iframe.html#policyShouldNotGrantAccess";
     112                            iframeElement.src = thirdPartyUrl + "/storageAccess/resources/has-storage-access-iframe.html?dummy=" + Math.random() + "#policyShouldNotGrantAccess";
    95113                            document.body.appendChild(iframeElement);
    96114                        });
  • trunk/Source/WebCore/ChangeLog

    r252839 r252840  
     12019-11-23  John Wilander  <wilander@apple.com>
     2
     3        Resource Load Statistics: Allow multiple third-party cookie blocking settings
     4        https://bugs.webkit.org/show_bug.cgi?id=204389
     5        <rdar://problem/57344054>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        This change introduces an enum ThirdPartyCookieBlockingMode for how third-party
     10        cookie blocking should be carried out. It then uses the set mode in
     11        NetworkStorageSession::shouldBlockCookies().
     12
     13        The reason for supporting three different modes is that what is now named
     14        OnlyAccordingToPerDomainPolicy is shipping, AllOnSitesWithoutUserInteraction is
     15        in beta, and All is behind an experimental flag.
     16
     17        Tests: http/tests/resourceLoadStatistics/third-party-cookie-blocking-on-sites-without-user-interaction-database.html
     18               http/tests/resourceLoadStatistics/third-party-cookie-blocking-on-sites-without-user-interaction.html
     19
     20        * page/Settings.yaml:
     21            Flipped the isThirdPartyCookieBlockingEnabled flag to on by default.
     22        * platform/network/NetworkStorageSession.cpp:
     23        (WebCore::NetworkStorageSession::shouldBlockCookies const):
     24        (WebCore::NetworkStorageSession::setThirdPartyCookieBlockingMode):
     25        * platform/network/NetworkStorageSession.h:
     26        (WebCore::NetworkStorageSession::setIsThirdPartyCookieBlockingEnabled): Deleted.
     27
    1282019-11-23  Commit Queue  <commit-queue@webkit.org>
    229
  • trunk/Source/WebCore/page/Settings.yaml

    r252762 r252840  
    882882
    883883isThirdPartyCookieBlockingEnabled:
    884   initial: false
     884  initial: true
    885885
    886886isLoggedInAPIEnabled:
  • trunk/Source/WebCore/platform/network/NetworkStorageSession.cpp

    r252623 r252840  
    114114        return false;
    115115
    116     if (m_isThirdPartyCookieBlockingEnabled)
     116    switch (m_thirdPartyCookieBlockingMode) {
     117    case ThirdPartyCookieBlockingMode::All:
    117118        return true;
    118 
    119     return shouldBlockThirdPartyCookies(resourceDomain);
     119    case ThirdPartyCookieBlockingMode::AllOnSitesWithoutUserInteraction:
     120        if (!hasHadUserInteractionAsFirstParty(firstPartyDomain))
     121            return true;
     122        FALLTHROUGH;
     123    case ThirdPartyCookieBlockingMode::OnlyAccordingToPerDomainPolicy:
     124        return shouldBlockThirdPartyCookies(resourceDomain);
     125    }
    120126}
    121127
     
    270276}
    271277
     278void NetworkStorageSession::setThirdPartyCookieBlockingMode(ThirdPartyCookieBlockingMode blockingMode)
     279{
     280    m_thirdPartyCookieBlockingMode = blockingMode;
     281}
     282
    272283Optional<Seconds> NetworkStorageSession::clientSideCookieCap(const RegistrableDomain& firstParty, Optional<PageIdentifier> pageID) const
    273284{
  • trunk/Source/WebCore/platform/network/NetworkStorageSession.h

    r252623 r252840  
    7575enum class IncludeSecureCookies : bool;
    7676enum class IncludeHttpOnlyCookies : bool;
     77enum class ThirdPartyCookieBlockingMode : uint8_t { All, AllOnSitesWithoutUserInteraction, OnlyAccordingToPerDomainPolicy };
    7778
    7879class NetworkStorageSession {
     
    166167    WEBCORE_EXPORT void didCommitCrossSiteLoadWithDataTransferFromPrevalentResource(const RegistrableDomain& toDomain, PageIdentifier);
    167168    WEBCORE_EXPORT void resetCrossSiteLoadsWithLinkDecorationForTesting();
    168     void setIsThirdPartyCookieBlockingEnabled(bool enabled) { m_isThirdPartyCookieBlockingEnabled = enabled; }
     169    WEBCORE_EXPORT void setThirdPartyCookieBlockingMode(ThirdPartyCookieBlockingMode);
    169170#endif
    170171
     
    202203    HashMap<WebCore::PageIdentifier, RegistrableDomain> m_navigatedToWithLinkDecorationByPrevalentResource;
    203204    bool m_navigationWithLinkDecorationTestMode = false;
    204     bool m_isThirdPartyCookieBlockingEnabled = false;
     205    ThirdPartyCookieBlockingMode m_thirdPartyCookieBlockingMode { ThirdPartyCookieBlockingMode::AllOnSitesWithoutUserInteraction };
    205206#endif
    206207
     
    220221
    221222}
     223
     224namespace WTF {
     225
     226template<> struct EnumTraits<WebCore::ThirdPartyCookieBlockingMode> {
     227    using values = EnumValues<
     228        WebCore::ThirdPartyCookieBlockingMode,
     229        WebCore::ThirdPartyCookieBlockingMode::All,
     230        WebCore::ThirdPartyCookieBlockingMode::AllOnSitesWithoutUserInteraction,
     231        WebCore::ThirdPartyCookieBlockingMode::OnlyAccordingToPerDomainPolicy
     232    >;
     233};
     234
     235}
  • trunk/Source/WebKit/ChangeLog

    r252839 r252840  
     12019-11-23  John Wilander  <wilander@apple.com>
     2
     3        Resource Load Statistics: Allow multiple third-party cookie blocking settings
     4        https://bugs.webkit.org/show_bug.cgi?id=204389
     5        <rdar://problem/57344054>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        This change make the third-party cookie blocking setting go from a boolean to
     10        the new enum WebCore::ThirdPartyCookieBlockingMode with three different settings.
     11        Functions and member variables are renamed accordingly.
     12
     13        The reason for supporting three different modes is that what is now named
     14        OnlyAccordingToPerDomainPolicy is shipping, AllOnSitesWithoutUserInteraction is
     15        in beta, and All is behind an experimental flag.
     16
     17        The change also updates the test API to map the TestRunner call to the enum.
     18
     19        * NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp:
     20        (WebKit::ResourceLoadStatisticsDatabaseStore::hasStorageAccess):
     21        (WebKit::ResourceLoadStatisticsDatabaseStore::requestStorageAccess):
     22        (WebKit::ResourceLoadStatisticsDatabaseStore::clearUserInteraction):
     23            Now makes use of a completion handler and updates the cookie blocking state.
     24        (WebKit::ResourceLoadStatisticsDatabaseStore::hasHadUserInteraction):
     25        (WebKit::ResourceLoadStatisticsDatabaseStore::areAllThirdPartyCookiesBlockedUnder):
     26            New convenience function to check the cookie blocking status per first-party domain.
     27        (WebKit::ResourceLoadStatisticsDatabaseStore::cookieAccess):
     28            Restructured the code to make it very clear that the logic is the same as the
     29            corresponding function in ResourceLoadStatisticsMemoryStore.
     30            Can no longer be const since it calls areAllThirdPartyCookiesBlockedUnder() which
     31            in turn calls hasHadUserInteraction() and that function may clear user interaction data.
     32        (WebKit::ResourceLoadStatisticsDatabaseStore::hasHadUnexpiredRecentUserInteraction):
     33        (WebKit::ResourceLoadStatisticsDatabaseStore::cookieAccess const): Deleted.
     34            See comment above on the non-const version of this function.
     35        * NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h:
     36        * NetworkProcess/Classifier/ResourceLoadStatisticsMemoryStore.cpp:
     37        (WebKit::ResourceLoadStatisticsMemoryStore::areAllThirdPartyCookiesBlockedUnder):
     38            New convenience function to check the cookie blocking status per first-party domain.
     39        (WebKit::ResourceLoadStatisticsMemoryStore::cookieAccess):
     40            Restructured the code to make it very clear that the logic is the same as the
     41            corresponding function in ResourceLoadStatisticsDatabaseStore.
     42            Can no longer be const since it calls areAllThirdPartyCookiesBlockedUnder() which
     43            in turn calls hasHadUserInteraction() and that function may clear user interaction data.
     44        (WebKit::ResourceLoadStatisticsMemoryStore::hasStorageAccess):
     45        (WebKit::ResourceLoadStatisticsMemoryStore::requestStorageAccess):
     46        (WebKit::ResourceLoadStatisticsMemoryStore::clearUserInteraction):
     47            Now makes use of a completion handler and updates the cookie blocking state.
     48        (WebKit::ResourceLoadStatisticsMemoryStore::cookieAccess const): Deleted.
     49            See comment above on the non-const version of this function.
     50        * NetworkProcess/Classifier/ResourceLoadStatisticsMemoryStore.h:
     51        * NetworkProcess/Classifier/ResourceLoadStatisticsStore.h:
     52        (WebKit::ResourceLoadStatisticsStore::setThirdPartyCookieBlockingMode):
     53        (WebKit::ResourceLoadStatisticsStore::thirdPartyCookieBlockingMode const):
     54        (WebKit::ResourceLoadStatisticsStore::setIsThirdPartyCookieBlockingEnabled): Deleted.
     55        (WebKit::ResourceLoadStatisticsStore::isThirdPartyCookieBlockingEnabled const): Deleted.
     56        * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:
     57        (WebKit::WebResourceLoadStatisticsStore::setThirdPartyCookieBlockingMode):
     58        (WebKit::WebResourceLoadStatisticsStore::clearUserInteraction):
     59            Now forwards the completion handler.
     60        (WebKit::WebResourceLoadStatisticsStore::setIsThirdPartyCookieBlockingEnabled): Deleted.
     61        * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h:
     62        * NetworkProcess/NetworkProcess.cpp:
     63        (WebKit::NetworkProcess::setShouldBlockThirdPartyCookiesForTesting):
     64        * NetworkProcess/NetworkProcess.h:
     65        * NetworkProcess/NetworkProcess.messages.in:
     66            The SetShouldBlockThirdPartyCookiesForTesting message now uses an enum instead of a
     67            boolean.
     68        * NetworkProcess/NetworkSession.cpp:
     69        (WebKit::NetworkSession::setResourceLoadStatisticsEnabled):
     70            Now forwards the enum value instead of a boolean.
     71        (WebKit::NetworkSession::recreateResourceLoadStatisticStore):
     72            Now makes sure the cookie blocking setting is forwarded to the recreated store.
     73        (WebKit::NetworkSession::setThirdPartyCookieBlockingMode):
     74        (WebKit::NetworkSession::setIsThirdPartyCookieBlockingEnabled): Deleted.
     75        * NetworkProcess/NetworkSession.h:
     76        * NetworkProcess/NetworkSessionCreationParameters.cpp:
     77        (WebKit::NetworkSessionCreationParameters::encode const):
     78        (WebKit::NetworkSessionCreationParameters::decode):
     79            Support for the new enum.
     80        * NetworkProcess/NetworkSessionCreationParameters.h:
     81        * NetworkProcess/cocoa/NetworkSessionCocoa.mm:
     82        (WebKit::NetworkSessionCocoa::NetworkSessionCocoa):
     83        * Scripts/webkit/messages.py:
     84            Tells the IPC code generator where to find WebCore::ThirdPartyCookieBlockingMode.
     85        * Shared/WebPreferences.yaml:
     86            Flipped the IsThirdPartyCookieBlockingEnabled flag to on by default.
     87        * UIProcess/API/C/WKWebsiteDataStoreRef.cpp:
     88        (WKWebsiteDataStoreSetResourceLoadStatisticsShouldBlockThirdPartyCookiesForTesting):
     89        (WKWebsiteDataStoreStatisticsResetToConsistentState):
     90        * UIProcess/API/C/WKWebsiteDataStoreRef.h:
     91        * UIProcess/Network/NetworkProcessProxy.cpp:
     92        (WebKit::NetworkProcessProxy::setShouldBlockThirdPartyCookiesForTesting):
     93        * UIProcess/Network/NetworkProcessProxy.h:
     94        * UIProcess/WebProcessPool.cpp:
     95        (WebKit::WebProcessPool::ensureNetworkProcess):
     96            Makes use of the enum in the NetworkSessionCreationParameters.
     97        * UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
     98        (WebKit::WebsiteDataStore::parameters):
     99        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
     100        (WebKit::WebsiteDataStore::setResourceLoadStatisticsShouldBlockThirdPartyCookiesForTesting):
     101        * UIProcess/WebsiteData/WebsiteDataStore.h:
     102
    11032019-11-23  Commit Queue  <commit-queue@webkit.org>
    2104
  • trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp

    r252817 r252840  
    12581258    ensureResourceStatisticsForRegistrableDomain(subFrameDomain);
    12591259
    1260     switch (cookieAccess(subFrameDomain)) {
     1260    switch (cookieAccess(subFrameDomain, topFrameDomain)) {
    12611261    case CookieAccess::CannotRequest:
    12621262        completionHandler(false);
     
    12911291    auto subFrameStatus = ensureResourceStatisticsForRegistrableDomain(subFrameDomain);
    12921292   
    1293     switch (cookieAccess(subFrameDomain)) {
     1293    switch (cookieAccess(subFrameDomain, topFrameDomain)) {
    12941294    case CookieAccess::CannotRequest:
    12951295        RELEASE_LOG_INFO_IF(debugLoggingEnabled(), ITPDebug, "Cannot grant storage access to %{private}s since its cookies are blocked in third-party contexts and it has not received user interaction as first-party.", subFrameDomain.string().utf8().data());
     
    15001500}
    15011501
    1502 void ResourceLoadStatisticsDatabaseStore::clearUserInteraction(const RegistrableDomain& domain)
     1502void ResourceLoadStatisticsDatabaseStore::clearUserInteraction(const RegistrableDomain& domain, CompletionHandler<void()>&& completionHandler)
    15031503{
    15041504    ASSERT(!RunLoop::isMain());
     
    15141514        ASSERT_NOT_REACHED();
    15151515    }
     1516
     1517    // Update cookie blocking unconditionally since a call to hasHadUserInteraction()
     1518    // to check the previous user interaction status could call clearUserInteraction(),
     1519    // blowing the call stack.
     1520    updateCookieBlocking(WTFMove(completionHandler));
    15161521}
    15171522
     
    15421547        // Set timestamp to 0 so that statistics merge will know
    15431548        // it has been reset as opposed to its default -1.
    1544         clearUserInteraction(domain);
     1549        clearUserInteraction(domain, [] { });
    15451550        hadUserInteraction = false;
    15461551    }
     
    18531858}
    18541859
    1855 CookieAccess ResourceLoadStatisticsDatabaseStore::cookieAccess(const RegistrableDomain& domain) const
     1860bool ResourceLoadStatisticsDatabaseStore::areAllThirdPartyCookiesBlockedUnder(const TopFrameDomain& topFrameDomain)
     1861{
     1862    if (thirdPartyCookieBlockingMode() == ThirdPartyCookieBlockingMode::All)
     1863        return true;
     1864
     1865    if (thirdPartyCookieBlockingMode() == ThirdPartyCookieBlockingMode::AllOnSitesWithoutUserInteraction && !hasHadUserInteraction(topFrameDomain, OperatingDatesWindow::Long))
     1866        return true;
     1867
     1868    return false;
     1869}
     1870
     1871CookieAccess ResourceLoadStatisticsDatabaseStore::cookieAccess(const SubResourceDomain& subresourceDomain, const TopFrameDomain& topFrameDomain)
    18561872{
    18571873    ASSERT(!RunLoop::isMain());
     
    18591875    SQLiteStatement statement(m_database, "SELECT isPrevalent, hadUserInteraction FROM ObservedDomains WHERE registrableDomain = ?");
    18601876    if (statement.prepare() != SQLITE_OK
    1861         || statement.bindText(1, domain.string()) != SQLITE_OK) {
     1877        || statement.bindText(1, subresourceDomain.string()) != SQLITE_OK) {
    18621878        RELEASE_LOG_ERROR_IF_ALLOWED(m_sessionID, "%p - ResourceLoadStatisticsDatabaseStore::cookieAccess failed to bind, error message: %{private}s", this, m_database.lastErrorMsg());
    18631879        ASSERT_NOT_REACHED();
    18641880    }
    1865    
     1881
    18661882    bool hasNoEntry = statement.step() != SQLITE_ROW;
    1867     if (hasNoEntry) {
    1868         if (isThirdPartyCookieBlockingEnabled())
    1869             return CookieAccess::OnlyIfGranted;
     1883    bool isPrevalent = !hasNoEntry && !!statement.getColumnInt(0);
     1884    bool hadUserInteraction = !hasNoEntry && statement.getColumnInt(1) ? true : false;
     1885
     1886    if (!areAllThirdPartyCookiesBlockedUnder(topFrameDomain) && !isPrevalent)
    18701887        return CookieAccess::BasedOnCookiePolicy;
    1871     }
    1872 
    1873     bool isPrevalent = !!statement.getColumnInt(0);
    1874     if (!isPrevalent && !isThirdPartyCookieBlockingEnabled())
    1875         return CookieAccess::BasedOnCookiePolicy;
    1876 
    1877     bool hadUserInteraction = statement.getColumnInt(1) ? true : false;
     1888
    18781889    if (!hadUserInteraction)
    18791890        return CookieAccess::CannotRequest;
     
    20632074{
    20642075    if (resourceStatistic.hadUserInteraction && hasStatisticsExpired(resourceStatistic.mostRecentUserInteractionTime, operatingDatesWindow)) {
    2065         clearUserInteraction(resourceStatistic.registrableDomain);
     2076        clearUserInteraction(resourceStatistic.registrableDomain, [] { });
    20662077        return false;
    20672078    }
  • trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h

    r252817 r252840  
    128128    void logCrossSiteLoadWithLinkDecoration(const NavigatedFromDomain&, const NavigatedToDomain&) override;
    129129
    130     void clearUserInteraction(const RegistrableDomain&) override;
     130    void clearUserInteraction(const RegistrableDomain&, CompletionHandler<void()>&&) override;
    131131    bool hasHadUserInteraction(const RegistrableDomain&, OperatingDatesWindow) override;
    132132
     
    195195    bool predicateValueForDomain(WebCore::SQLiteStatement&, const RegistrableDomain&) const;
    196196
    197     CookieAccess cookieAccess(const RegistrableDomain&) const;
    198    
     197    bool areAllThirdPartyCookiesBlockedUnder(const TopFrameDomain&) override;
     198    CookieAccess cookieAccess(const SubResourceDomain&, const TopFrameDomain&);
     199
    199200    void setPrevalentResource(const RegistrableDomain&, ResourceLoadPrevalence);
    200201    unsigned recursivelyFindNonPrevalentDomainsThatRedirectedToThisDomain(unsigned primaryDomainID, StdSet<unsigned>& nonPrevalentRedirectionSources, unsigned numberOfRecursiveCalls);
  • trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsMemoryStore.cpp

    r252641 r252840  
    213213}
    214214
    215 CookieAccess ResourceLoadStatisticsMemoryStore::cookieAccess(const ResourceLoadStatistics& resourceStatistic) const
    216 {
    217     if (!isThirdPartyCookieBlockingEnabled() && !resourceStatistic.isPrevalentResource)
     215bool ResourceLoadStatisticsMemoryStore::areAllThirdPartyCookiesBlockedUnder(const TopFrameDomain& topFrameDomain)
     216{
     217    if (thirdPartyCookieBlockingMode() == ThirdPartyCookieBlockingMode::All)
     218        return true;
     219
     220    if (thirdPartyCookieBlockingMode() == ThirdPartyCookieBlockingMode::AllOnSitesWithoutUserInteraction && !hasHadUserInteraction(topFrameDomain, OperatingDatesWindow::Long))
     221        return true;
     222
     223    return false;
     224}
     225
     226CookieAccess ResourceLoadStatisticsMemoryStore::cookieAccess(const ResourceLoadStatistics& resourceStatistic, const TopFrameDomain& topFrameDomain)
     227{
     228    bool isPrevalent = resourceStatistic.isPrevalentResource;
     229    bool hadUserInteraction = resourceStatistic.hadUserInteraction;
     230
     231    if (!areAllThirdPartyCookiesBlockedUnder(topFrameDomain) && !isPrevalent)
    218232        return CookieAccess::BasedOnCookiePolicy;
    219233
    220     if (!resourceStatistic.hadUserInteraction)
     234    if (!hadUserInteraction)
    221235        return CookieAccess::CannotRequest;
    222236   
     
    229243
    230244    auto& subFrameStatistic = ensureResourceStatisticsForRegistrableDomain(subFrameDomain);
    231     switch (cookieAccess(subFrameStatistic)) {
     245    switch (cookieAccess(subFrameStatistic, topFrameDomain)) {
    232246    case CookieAccess::CannotRequest:
    233247        completionHandler(false);
     
    261275
    262276    auto& subFrameStatistic = ensureResourceStatisticsForRegistrableDomain(subFrameDomain);
    263     switch (cookieAccess(subFrameStatistic)) {
     277    switch (cookieAccess(subFrameStatistic, topFrameDomain)) {
    264278    case CookieAccess::CannotRequest:
    265279        RELEASE_LOG_INFO_IF(debugLoggingEnabled(), ITPDebug, "Cannot grant storage access to %{public}s since its cookies are blocked in third-party contexts and it has not received user interaction as first-party.", subFrameDomain.string().utf8().data());
     
    440454}
    441455
    442 void ResourceLoadStatisticsMemoryStore::clearUserInteraction(const RegistrableDomain& domain)
     456void ResourceLoadStatisticsMemoryStore::clearUserInteraction(const RegistrableDomain& domain, CompletionHandler<void()>&& completionHandler)
    443457{
    444458    ASSERT(!RunLoop::isMain());
    445459
    446460    auto& statistics = ensureResourceStatisticsForRegistrableDomain(domain);
     461    bool didHavePreviousUserInteraction = statistics.hadUserInteraction;
    447462    statistics.hadUserInteraction = false;
    448463    statistics.mostRecentUserInteractionTime = { };
     464    if (!didHavePreviousUserInteraction) {
     465        completionHandler();
     466        return;
     467    }
     468    updateCookieBlocking(WTFMove(completionHandler));
    449469}
    450470
  • trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsMemoryStore.h

    r251663 r252840  
    9898    void calculateAndSubmitTelemetry() const override;
    9999
    100     CookieAccess cookieAccess(const ResourceLoadStatistics&) const;
     100    bool areAllThirdPartyCookiesBlockedUnder(const TopFrameDomain&) override;
     101    CookieAccess cookieAccess(const ResourceLoadStatistics&, const TopFrameDomain&);
    101102    void hasStorageAccess(const SubFrameDomain&, const TopFrameDomain&, Optional<WebCore::FrameIdentifier>, WebCore::PageIdentifier, CompletionHandler<void(bool)>&&) override;
    102103    void requestStorageAccess(SubFrameDomain&&, TopFrameDomain&&, WebCore::FrameIdentifier, WebCore::PageIdentifier, CompletionHandler<void(StorageAccessStatus)>&&) override;
     
    107108    void logCrossSiteLoadWithLinkDecoration(const NavigatedFromDomain&, const NavigatedToDomain&) override;
    108109
    109     void clearUserInteraction(const RegistrableDomain&) override;
     110    void clearUserInteraction(const RegistrableDomain&, CompletionHandler<void()>&&) override;
    110111    bool hasHadUserInteraction(const RegistrableDomain&, OperatingDatesWindow) override;
    111112
  • trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsStore.h

    r251663 r252840  
    3131#include "WebResourceLoadStatisticsStore.h"
    3232#include <WebCore/FrameIdentifier.h>
     33#include <WebCore/NetworkStorageSession.h>
    3334#include <wtf/CompletionHandler.h>
    3435#include <wtf/Vector.h>
     
    162163    bool isDebugModeEnabled() const { return m_debugModeEnabled; };
    163164    void setPrevalentResourceForDebugMode(const RegistrableDomain&);
    164     void setIsThirdPartyCookieBlockingEnabled(bool enabled) { m_thirdPartyCookieBlockingEnabled = enabled; };
    165     bool isThirdPartyCookieBlockingEnabled() const { return m_thirdPartyCookieBlockingEnabled; };
    166 
     165    void setThirdPartyCookieBlockingMode(WebCore::ThirdPartyCookieBlockingMode mode) { m_thirdPartyCookieBlockingMode = mode; };
     166    WebCore::ThirdPartyCookieBlockingMode thirdPartyCookieBlockingMode() const { return m_thirdPartyCookieBlockingMode; };
     167
     168    virtual bool areAllThirdPartyCookiesBlockedUnder(const TopFrameDomain&) = 0;
    167169    virtual void hasStorageAccess(const SubFrameDomain&, const TopFrameDomain&, Optional<WebCore::FrameIdentifier>, WebCore::PageIdentifier, CompletionHandler<void(bool)>&&) = 0;
    168170    virtual void requestStorageAccess(SubFrameDomain&&, TopFrameDomain&&, WebCore::FrameIdentifier, WebCore::PageIdentifier, CompletionHandler<void(StorageAccessStatus)>&&) = 0;
     
    173175    virtual void logCrossSiteLoadWithLinkDecoration(const NavigatedFromDomain&, const NavigatedToDomain&) = 0;
    174176
    175     virtual void clearUserInteraction(const RegistrableDomain&) = 0;
     177    virtual void clearUserInteraction(const RegistrableDomain&, CompletionHandler<void()>&&) = 0;
    176178    virtual bool hasHadUserInteraction(const RegistrableDomain&, OperatingDatesWindow) = 0;
    177179
     
    271273    bool m_debugLoggingEnabled { false };
    272274    bool m_debugModeEnabled { false };
    273     bool m_thirdPartyCookieBlockingEnabled { false };
     275    WebCore::ThirdPartyCookieBlockingMode m_thirdPartyCookieBlockingMode { WebCore::ThirdPartyCookieBlockingMode::AllOnSitesWithoutUserInteraction };
    274276    bool m_dataRecordsBeingRemoved { false };
    275277    ShouldIncludeLocalhost m_shouldIncludeLocalhost { ShouldIncludeLocalhost::Yes };
  • trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp

    r252123 r252840  
    463463}
    464464
    465 void WebResourceLoadStatisticsStore::setIsThirdPartyCookieBlockingEnabled(bool enabled)
     465void WebResourceLoadStatisticsStore::setThirdPartyCookieBlockingMode(ThirdPartyCookieBlockingMode blockingMode)
    466466{
    467467    ASSERT(RunLoop::isMain());
     
    469469    if (m_networkSession) {
    470470        if (auto* storageSession = m_networkSession->networkStorageSession())
    471             storageSession->setIsThirdPartyCookieBlockingEnabled(enabled);
     471            storageSession->setThirdPartyCookieBlockingMode(blockingMode);
    472472        else
    473473            ASSERT_NOT_REACHED();
    474474    }
    475475
    476     postTask([this, enabled]() {
     476    postTask([this, blockingMode]() {
    477477        if (!m_statisticsStore)
    478478            return;
    479479
    480         m_statisticsStore->setIsThirdPartyCookieBlockingEnabled(enabled);
     480        m_statisticsStore->setThirdPartyCookieBlockingMode(blockingMode);
    481481    });
    482482}
     
    612612   
    613613    postTask([this, domain = domain.isolatedCopy(), completionHandler = WTFMove(completionHandler)]() mutable {
    614         if (m_statisticsStore)
    615             m_statisticsStore->clearUserInteraction(domain);
    616         postTaskReply(WTFMove(completionHandler));
     614        auto innerCompletionHandler = [completionHandler = WTFMove(completionHandler)]() mutable {
     615            postTaskReply(WTFMove(completionHandler));
     616        };
     617        if (m_statisticsStore) {
     618            m_statisticsStore->clearUserInteraction(domain, WTFMove(innerCompletionHandler));
     619            return;
     620        }
     621        innerCompletionHandler();
    617622    });
    618623}
  • trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h

    r251672 r252840  
    5353enum class StorageAccessPromptWasShown : bool;
    5454enum class StorageAccessWasGranted : bool;
     55enum class ThirdPartyCookieBlockingMode : uint8_t;
    5556}
    5657
     
    180181
    181182    void hasCookies(const RegistrableDomain&, CompletionHandler<void(bool)>&&);
    182     void setIsThirdPartyCookieBlockingEnabled(bool);
     183    void setThirdPartyCookieBlockingMode(WebCore::ThirdPartyCookieBlockingMode);
    183184    void didCreateNetworkProcess();
    184185
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp

    r252839 r252840  
    12541254}
    12551255
    1256 void NetworkProcess::setShouldBlockThirdPartyCookiesForTesting(PAL::SessionID sessionID, bool enabled, CompletionHandler<void()>&& completionHandler)
     1256void NetworkProcess::setShouldBlockThirdPartyCookiesForTesting(PAL::SessionID sessionID, WebCore::ThirdPartyCookieBlockingMode blockingMode, CompletionHandler<void()>&& completionHandler)
    12571257{
    12581258    if (auto* networkSession = this->networkSession(sessionID))
    1259         networkSession->setIsThirdPartyCookieBlockingEnabled(enabled);
     1259        networkSession->setThirdPartyCookieBlockingMode(blockingMode);
    12601260    else
    12611261        ASSERT_NOT_REACHED();
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.h

    r252839 r252840  
    261261    bool isITPDatabaseEnabled() const { return m_isITPDatabaseEnabled; }
    262262    void setShouldDowngradeReferrerForTesting(bool, CompletionHandler<void()>&&);
    263     void setShouldBlockThirdPartyCookiesForTesting(PAL::SessionID, bool, CompletionHandler<void()>&&);
     263    void setShouldBlockThirdPartyCookiesForTesting(PAL::SessionID, WebCore::ThirdPartyCookieBlockingMode, CompletionHandler<void()>&&);
    264264#endif
    265265
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.messages.in

    r252839 r252840  
    137137    HasIsolatedSession(PAL::SessionID sessionID, WebCore::RegistrableDomain domain) -> (bool hasIsolatedSession) Async
    138138    SetShouldDowngradeReferrerForTesting(bool enabled) -> () Async
    139     SetShouldBlockThirdPartyCookiesForTesting(PAL::SessionID sessionID, bool enabled) -> () Async
     139    SetShouldBlockThirdPartyCookiesForTesting(PAL::SessionID sessionID, enum:uint8_t WebCore::ThirdPartyCookieBlockingMode blockingMode) -> () Async
    140140#endif
    141141
  • trunk/Source/WebKit/NetworkProcess/NetworkSession.cpp

    r252623 r252840  
    4040#include <WebCore/AdClickAttribution.h>
    4141#include <WebCore/CookieJar.h>
    42 #include <WebCore/NetworkStorageSession.h>
    4342#include <WebCore/ResourceRequest.h>
    4443
     
    176175    if (!m_resourceLoadStatisticsManualPrevalentResource.isEmpty())
    177176        m_resourceLoadStatistics->setPrevalentResourceForDebugMode(m_resourceLoadStatisticsManualPrevalentResource, [] { });
    178     m_resourceLoadStatistics->setIsThirdPartyCookieBlockingEnabled(m_thirdPartyCookieBlockingEnabled);
     177    m_resourceLoadStatistics->setThirdPartyCookieBlockingMode(m_thirdPartyCookieBlockingMode);
    179178}
    180179
     
    184183    m_resourceLoadStatistics = WebResourceLoadStatisticsStore::create(*this, m_resourceLoadStatisticsDirectory, m_shouldIncludeLocalhostInResourceLoadStatistics);
    185184    m_resourceLoadStatistics->populateMemoryStoreFromDisk(WTFMove(completionHandler));
     185    m_resourceLoadStatistics->setThirdPartyCookieBlockingMode(m_thirdPartyCookieBlockingMode);
    186186}
    187187
     
    226226}
    227227
    228 void NetworkSession::setIsThirdPartyCookieBlockingEnabled(bool enabled)
     228void NetworkSession::setThirdPartyCookieBlockingMode(ThirdPartyCookieBlockingMode blockingMode)
    229229{
    230230    ASSERT(m_resourceLoadStatistics);
    231     m_thirdPartyCookieBlockingEnabled = enabled;
     231    m_thirdPartyCookieBlockingMode = blockingMode;
    232232    if (m_resourceLoadStatistics)
    233         m_resourceLoadStatistics->setIsThirdPartyCookieBlockingEnabled(m_thirdPartyCookieBlockingEnabled);
     233        m_resourceLoadStatistics->setThirdPartyCookieBlockingMode(blockingMode);
    234234}
    235235#endif // ENABLE(RESOURCE_LOAD_STATISTICS)
  • trunk/Source/WebKit/NetworkProcess/NetworkSession.h

    r252397 r252840  
    3131#include <WebCore/AdClickAttribution.h>
    3232#include <WebCore/BlobRegistryImpl.h>
     33#include <WebCore/NetworkStorageSession.h>
    3334#include <WebCore/RegistrableDomain.h>
    3435#include <pal/SessionID.h>
     
    9899    void setShouldDowngradeReferrerForTesting(bool);
    99100    bool shouldDowngradeReferrer() const;
    100     void setIsThirdPartyCookieBlockingEnabled(bool);
     101    void setThirdPartyCookieBlockingMode(WebCore::ThirdPartyCookieBlockingMode);
    101102#endif
    102103    void storeAdClickAttribution(WebCore::AdClickAttribution&&);
     
    145146    bool m_enableResourceLoadStatisticsLogTestingEvent;
    146147    bool m_downgradeReferrer { true };
    147     bool m_thirdPartyCookieBlockingEnabled { false };
     148    WebCore::ThirdPartyCookieBlockingMode m_thirdPartyCookieBlockingMode { WebCore::ThirdPartyCookieBlockingMode::AllOnSitesWithoutUserInteraction };
    148149#endif
    149150    bool m_isStaleWhileRevalidateEnabled { false };
  • trunk/Source/WebKit/NetworkProcess/NetworkSessionCreationParameters.cpp

    r252397 r252840  
    6969    encoder << enableResourceLoadStatisticsDebugMode;
    7070    encoder << resourceLoadStatisticsManualPrevalentResource;
    71     encoder << enableThirdPartyCookieBlocking;
     71    encoder << thirdPartyCookieBlockingMode;
    7272
    7373    encoder << networkCacheDirectory << networkCacheDirectoryExtensionHandle;
     
    201201        return WTF::nullopt;
    202202
    203     Optional<bool> enableThirdPartyCookieBlocking;
    204     decoder >> enableThirdPartyCookieBlocking;
    205     if (!enableThirdPartyCookieBlocking)
     203    Optional<WebCore::ThirdPartyCookieBlockingMode> thirdPartyCookieBlockingMode;
     204    decoder >> thirdPartyCookieBlockingMode;
     205    if (!thirdPartyCookieBlockingMode)
    206206        return WTF::nullopt;
    207207
     
    289289        , WTFMove(*shouldIncludeLocalhostInResourceLoadStatistics)
    290290        , WTFMove(*enableResourceLoadStatisticsDebugMode)
    291         , WTFMove(*enableThirdPartyCookieBlocking)
     291        , WTFMove(*thirdPartyCookieBlockingMode)
    292292        , WTFMove(*deviceManagementRestrictionsEnabled)
    293293        , WTFMove(*allLoadsBlockedByDeviceManagementRestrictionsForTesting)
  • trunk/Source/WebKit/NetworkProcess/NetworkSessionCreationParameters.h

    r252397 r252840  
    2727
    2828#include "SandboxExtension.h"
     29#include <WebCore/NetworkStorageSession.h>
    2930#include <WebCore/RegistrableDomain.h>
    3031#include <pal/SessionID.h>
     
    8687    bool shouldIncludeLocalhostInResourceLoadStatistics { true };
    8788    bool enableResourceLoadStatisticsDebugMode { false };
    88     bool enableThirdPartyCookieBlocking { false };
     89    WebCore::ThirdPartyCookieBlockingMode thirdPartyCookieBlockingMode { WebCore::ThirdPartyCookieBlockingMode::AllOnSitesWithoutUserInteraction };
    8990    bool deviceManagementRestrictionsEnabled { false };
    9091    bool allLoadsBlockedByDeviceManagementRestrictionsForTesting { false };
  • trunk/Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm

    r252819 r252840  
    11361136    m_enableResourceLoadStatisticsDebugMode = parameters.enableResourceLoadStatisticsDebugMode ? EnableResourceLoadStatisticsDebugMode::Yes : EnableResourceLoadStatisticsDebugMode::No;
    11371137    m_resourceLoadStatisticsManualPrevalentResource = parameters.resourceLoadStatisticsManualPrevalentResource;
    1138     m_thirdPartyCookieBlockingEnabled = parameters.enableThirdPartyCookieBlocking;
     1138    m_thirdPartyCookieBlockingMode = parameters.thirdPartyCookieBlockingMode;
    11391139    setResourceLoadStatisticsEnabled(parameters.enableResourceLoadStatistics);
    11401140#endif
  • trunk/Source/WebKit/Scripts/webkit/messages.py

    r252655 r252840  
    589589        'WebCore::TextCheckingType': ['<WebCore/TextChecking.h>'],
    590590        'WebCore::TextIndicatorData': ['<WebCore/TextIndicator.h>'],
     591        'WebCore::ThirdPartyCookieBlockingMode': ['<WebCore/NetworkStorageSession.h>'],
    591592        'WebCore::ViewportAttributes': ['<WebCore/ViewportArguments.h>'],
    592593        'WebCore::WillContinueLoading': ['<WebCore/FrameLoaderTypes.h>'],
  • trunk/Source/WebKit/Shared/WebPreferences.yaml

    r252361 r252840  
    17961796IsThirdPartyCookieBlockingEnabled:
    17971797  type: bool
    1798   defaultValue: false
     1798  defaultValue: true
    17991799  humanReadableName: "Block All 3rd-Party Cookies (ITP)"
    18001800  humanReadableDescription: "Block all third-party cookies when Intelligent Tracking Prevention is enabled"
  • trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp

    r252839 r252840  
    539539}
    540540
    541 void WKWebsiteDataStoreSetResourceLoadStatisticsShouldBlockThirdPartyCookiesForTesting(WKWebsiteDataStoreRef dataStoreRef, bool enabled, void* context, WKWebsiteDataStoreSetResourceLoadStatisticsShouldBlockThirdPartyCookiesForTestingFunction completionHandler)
    542 {
    543 #if ENABLE(RESOURCE_LOAD_STATISTICS)
    544     WebKit::toImpl(dataStoreRef)->setResourceLoadStatisticsShouldBlockThirdPartyCookiesForTesting(enabled, [context, completionHandler] {
     541void WKWebsiteDataStoreSetResourceLoadStatisticsShouldBlockThirdPartyCookiesForTesting(WKWebsiteDataStoreRef dataStoreRef, bool enabled, bool onlyOnSitesWithoutUserInteraction, void* context, WKWebsiteDataStoreSetResourceLoadStatisticsShouldBlockThirdPartyCookiesForTestingFunction completionHandler)
     542{
     543#if ENABLE(RESOURCE_LOAD_STATISTICS)
     544    WebKit::toImpl(dataStoreRef)->setResourceLoadStatisticsShouldBlockThirdPartyCookiesForTesting(enabled, onlyOnSitesWithoutUserInteraction, [context, completionHandler] {
    545545        completionHandler(context);
    546546    });
     
    562562    store.resetCrossSiteLoadsWithLinkDecorationForTesting([callbackAggregator = callbackAggregator.copyRef()] { });
    563563    store.setResourceLoadStatisticsShouldDowngradeReferrerForTesting(true, [callbackAggregator = callbackAggregator.copyRef()] { });
    564     store.setResourceLoadStatisticsShouldBlockThirdPartyCookiesForTesting(false, [callbackAggregator = callbackAggregator.copyRef()] { });
     564    store.setResourceLoadStatisticsShouldBlockThirdPartyCookiesForTesting(false, false, [callbackAggregator = callbackAggregator.copyRef()] { });
    565565    store.resetParametersToDefaultValues([callbackAggregator = callbackAggregator.copyRef()] { });
    566566    store.scheduleClearInMemoryAndPersistent(WebKit::ShouldGrandfatherStatistics::No, [callbackAggregator = callbackAggregator.copyRef()] { });
  • trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h

    r252839 r252840  
    121121WK_EXPORT void WKWebsiteDataStoreSetResourceLoadStatisticsShouldDowngradeReferrerForTesting(WKWebsiteDataStoreRef dataStoreRef, bool enabled, void* context, WKWebsiteDataStoreSetResourceLoadStatisticsShouldDowngradeReferrerForTestingFunction completionHandler);
    122122typedef void (*WKWebsiteDataStoreSetResourceLoadStatisticsShouldBlockThirdPartyCookiesForTestingFunction)(void* functionContext);
    123 WK_EXPORT void WKWebsiteDataStoreSetResourceLoadStatisticsShouldBlockThirdPartyCookiesForTesting(WKWebsiteDataStoreRef dataStoreRef, bool enabled, void* context, WKWebsiteDataStoreSetResourceLoadStatisticsShouldBlockThirdPartyCookiesForTestingFunction completionHandler);
     123WK_EXPORT void WKWebsiteDataStoreSetResourceLoadStatisticsShouldBlockThirdPartyCookiesForTesting(WKWebsiteDataStoreRef dataStoreRef, bool enabled, bool onlyOnSitesWithoutUserInteraction, void* context, WKWebsiteDataStoreSetResourceLoadStatisticsShouldBlockThirdPartyCookiesForTestingFunction completionHandler);
    124124typedef void (*WKWebsiteDataStoreStatisticsResetToConsistentStateFunction)(void* functionContext);
    125125WK_EXPORT void WKWebsiteDataStoreStatisticsResetToConsistentState(WKWebsiteDataStoreRef dataStoreRef, void* context, WKWebsiteDataStoreStatisticsResetToConsistentStateFunction completionHandler);
  • trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp

    r252839 r252840  
    10581058}
    10591059
    1060 void NetworkProcessProxy::setShouldBlockThirdPartyCookiesForTesting(PAL::SessionID sessionID, bool enabled, CompletionHandler<void()>&& completionHandler)
    1061 {
    1062     if (!canSendMessage()) {
    1063         completionHandler();
    1064         return;
    1065     }
    1066    
    1067     sendWithAsyncReply(Messages::NetworkProcess::SetShouldBlockThirdPartyCookiesForTesting(sessionID, enabled), WTFMove(completionHandler));
     1060void NetworkProcessProxy::setShouldBlockThirdPartyCookiesForTesting(PAL::SessionID sessionID, ThirdPartyCookieBlockingMode blockingMode, CompletionHandler<void()>&& completionHandler)
     1061{
     1062    if (!canSendMessage()) {
     1063        completionHandler();
     1064        return;
     1065    }
     1066   
     1067    sendWithAsyncReply(Messages::NetworkProcess::SetShouldBlockThirdPartyCookiesForTesting(sessionID, blockingMode), WTFMove(completionHandler));
    10681068}
    10691069#endif // ENABLE(RESOURCE_LOAD_STATISTICS)
  • trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h

    r252839 r252840  
    158158    void hasIsolatedSession(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void(bool)>&&);
    159159    void setShouldDowngradeReferrerForTesting(bool, CompletionHandler<void()>&&);
    160     void setShouldBlockThirdPartyCookiesForTesting(PAL::SessionID, bool, CompletionHandler<void()>&&);
     160    void setShouldBlockThirdPartyCookiesForTesting(PAL::SessionID, WebCore::ThirdPartyCookieBlockingMode, CompletionHandler<void()>&&);
    161161#endif
    162162   
  • trunk/Source/WebKit/UIProcess/WebProcessPool.cpp

    r252839 r252840  
    563563    bool shouldIncludeLocalhost = true;
    564564    bool enableResourceLoadStatisticsDebugMode = false;
    565     bool enableThirdPartyCookieBlocking = false;
     565    WebCore::ThirdPartyCookieBlockingMode thirdPartyCookieBlockingMode = WebCore::ThirdPartyCookieBlockingMode::AllOnSitesWithoutUserInteraction;
    566566    WebCore::RegistrableDomain manualPrevalentResource { };
    567567    if (withWebsiteDataStore) {
     
    574574            shouldIncludeLocalhost = networkSessionParameters.shouldIncludeLocalhostInResourceLoadStatistics;
    575575            enableResourceLoadStatisticsDebugMode = networkSessionParameters.enableResourceLoadStatisticsDebugMode;
    576             enableThirdPartyCookieBlocking = networkSessionParameters.enableThirdPartyCookieBlocking;
     576            thirdPartyCookieBlockingMode = networkSessionParameters.thirdPartyCookieBlockingMode;
    577577            manualPrevalentResource = networkSessionParameters.resourceLoadStatisticsManualPrevalentResource;
    578578        }
     
    595595            shouldIncludeLocalhost = networkSessionParameters.shouldIncludeLocalhostInResourceLoadStatistics;
    596596            enableResourceLoadStatisticsDebugMode = networkSessionParameters.enableResourceLoadStatisticsDebugMode;
    597             enableThirdPartyCookieBlocking = networkSessionParameters.enableThirdPartyCookieBlocking;
     597            thirdPartyCookieBlockingMode = networkSessionParameters.thirdPartyCookieBlockingMode;
    598598            manualPrevalentResource = networkSessionParameters.resourceLoadStatisticsManualPrevalentResource;
    599599        }
     
    619619    parameters.defaultDataStoreParameters.networkSessionParameters.shouldIncludeLocalhostInResourceLoadStatistics = shouldIncludeLocalhost;
    620620    parameters.defaultDataStoreParameters.networkSessionParameters.enableResourceLoadStatisticsDebugMode = enableResourceLoadStatisticsDebugMode;
    621     parameters.defaultDataStoreParameters.networkSessionParameters.enableThirdPartyCookieBlocking = enableThirdPartyCookieBlocking;
     621    parameters.defaultDataStoreParameters.networkSessionParameters.thirdPartyCookieBlockingMode = thirdPartyCookieBlockingMode;
    622622    parameters.defaultDataStoreParameters.networkSessionParameters.resourceLoadStatisticsManualPrevalentResource = manualPrevalentResource;
    623623
  • trunk/Source/WebKit/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm

    r252839 r252840  
    3333#import "WebResourceLoadStatisticsStore.h"
    3434#import "WebsiteDataStoreParameters.h"
     35#import <WebCore/NetworkStorageSession.h>
    3536#import <WebCore/RegistrableDomain.h>
    3637#import <WebCore/RuntimeApplicationChecks.h>
     
    7071    bool shouldLogCookieInformation = false;
    7172    bool enableResourceLoadStatisticsDebugMode = false;
    72     bool enableThirdPartyCookieBlocking = false;
     73    auto thirdPartyCookieBlockingMode = WebCore::ThirdPartyCookieBlockingMode::OnlyAccordingToPerDomainPolicy;
    7374    bool enableLegacyTLS = true;
    7475    if (id value = [defaults objectForKey:@"WebKitEnableLegacyTLS"])
     
    7778#if ENABLE(RESOURCE_LOAD_STATISTICS)
    7879    enableResourceLoadStatisticsDebugMode = [defaults boolForKey:@"ITPDebugMode"];
    79     enableThirdPartyCookieBlocking = [defaults boolForKey:[NSString stringWithFormat:@"Experimental%@", WebPreferencesKey::isThirdPartyCookieBlockingEnabledKey().createCFString().get()]];
     80    if ([defaults boolForKey:[NSString stringWithFormat:@"Experimental%@", WebPreferencesKey::isThirdPartyCookieBlockingEnabledKey().createCFString().get()]])
     81        thirdPartyCookieBlockingMode = WebCore::ThirdPartyCookieBlockingMode::All;
     82    else
     83        thirdPartyCookieBlockingMode = WebCore::ThirdPartyCookieBlockingMode::AllOnSitesWithoutUserInteraction;
    8084    auto* manualPrevalentResource = [defaults stringForKey:@"ITPManualPrevalentResource"];
    8185    if (manualPrevalentResource) {
     
    141145        shouldIncludeLocalhostInResourceLoadStatistics,
    142146        enableResourceLoadStatisticsDebugMode,
    143         enableThirdPartyCookieBlocking,
     147        thirdPartyCookieBlockingMode,
    144148        m_configuration->deviceManagementRestrictionsEnabled(),
    145149        m_configuration->allLoadsBlockedByDeviceManagementRestrictionsForTesting(),
  • trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp

    r252839 r252840  
    5050#include <WebCore/DatabaseTracker.h>
    5151#include <WebCore/HTMLMediaElement.h>
     52#include <WebCore/NetworkStorageSession.h>
    5253#include <WebCore/OriginLock.h>
    5354#include <WebCore/RegistrableDomain.h>
     
    17881789}
    17891790
    1790 void WebsiteDataStore::setResourceLoadStatisticsShouldBlockThirdPartyCookiesForTesting(bool enabled, CompletionHandler<void()>&& completionHandler)
    1791 {
    1792     auto callbackAggregator = CallbackAggregator::create(WTFMove(completionHandler));
    1793    
     1791void WebsiteDataStore::setResourceLoadStatisticsShouldBlockThirdPartyCookiesForTesting(bool enabled, bool onlyOnSitesWithoutUserInteraction, CompletionHandler<void()>&& completionHandler)
     1792{
     1793    auto callbackAggregator = CallbackAggregator::create(WTFMove(completionHandler));
     1794    WebCore::ThirdPartyCookieBlockingMode blockingMode = WebCore::ThirdPartyCookieBlockingMode::OnlyAccordingToPerDomainPolicy;
     1795    if (enabled)
     1796        blockingMode = onlyOnSitesWithoutUserInteraction ? WebCore::ThirdPartyCookieBlockingMode::AllOnSitesWithoutUserInteraction : WebCore::ThirdPartyCookieBlockingMode::All;
     1797
    17941798    for (auto& processPool : processPools()) {
    17951799        if (auto* networkProcess = processPool->networkProcess()) {
    1796             networkProcess->setShouldBlockThirdPartyCookiesForTesting(m_sessionID, enabled, [callbackAggregator = callbackAggregator.copyRef()] { });
     1800            networkProcess->setShouldBlockThirdPartyCookiesForTesting(m_sessionID, blockingMode, [callbackAggregator = callbackAggregator.copyRef()] { });
    17971801            ASSERT(processPools().size() == 1);
    17981802            break;
  • trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h

    r252839 r252840  
    195195    void hasIsolatedSessionForTesting(const URL&, CompletionHandler<void(bool)>&&) const;
    196196    void setResourceLoadStatisticsShouldDowngradeReferrerForTesting(bool, CompletionHandler<void()>&&);
    197     void setResourceLoadStatisticsShouldBlockThirdPartyCookiesForTesting(bool, CompletionHandler<void()>&&);
     197    void setResourceLoadStatisticsShouldBlockThirdPartyCookiesForTesting(bool enabled, bool onlyOnSitesWithoutUserInteraction, CompletionHandler<void()>&&);
    198198#endif
    199199    void setCacheMaxAgeCapForPrevalentResources(Seconds, CompletionHandler<void()>&&);
  • trunk/Tools/ChangeLog

    r252839 r252840  
     12019-11-23  John Wilander  <wilander@apple.com>
     2
     3        Resource Load Statistics: Allow multiple third-party cookie blocking settings
     4        https://bugs.webkit.org/show_bug.cgi?id=204389
     5        <rdar://problem/57344054>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        This change allows the existing TestRunner function
     10        setStatisticsShouldBlockThirdPartyCookies() to set an optional boolean
     11        parameter onlyOnSitesWithoutUserInteraction to opt in to that behavior.
     12
     13        * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
     14        * WebKitTestRunner/InjectedBundle/TestRunner.cpp:
     15        (WTR::TestRunner::setStatisticsShouldBlockThirdPartyCookies):
     16        * WebKitTestRunner/InjectedBundle/TestRunner.h:
     17        * WebKitTestRunner/TestController.cpp:
     18        (WTR::TestController::setStatisticsShouldBlockThirdPartyCookies):
     19        * WebKitTestRunner/TestController.h:
     20        * WebKitTestRunner/TestInvocation.cpp:
     21        (WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):
     22
    1232019-11-23  Commit Queue  <commit-queue@webkit.org>
    224
  • trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl

    r252623 r252840  
    343343    boolean hasStatisticsIsolatedSession(DOMString hostName);
    344344    void setStatisticsShouldDowngradeReferrer(boolean value, object callback);
    345     void setStatisticsShouldBlockThirdPartyCookies(boolean value, object callback);
     345    void setStatisticsShouldBlockThirdPartyCookies(boolean value, object callback, optional boolean onlyOnSitesWithoutUserInteraction);
    346346
    347347    // Injected bundle form client.
  • trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp

    r252623 r252840  
    3434#include "TestController.h"
    3535#include <JavaScriptCore/JSCTestRunnerUtils.h>
     36#include <WebCore/NetworkStorageSession.h>
    3637#include <WebCore/ResourceLoadObserver.h>
    3738#include <WebKit/WKBundle.h>
     
    22242225}
    22252226
    2226 void TestRunner::setStatisticsShouldBlockThirdPartyCookies(bool value, JSValueRef completionHandler)
     2227void TestRunner::setStatisticsShouldBlockThirdPartyCookies(bool value, JSValueRef completionHandler, bool onlyOnSitesWithoutUserInteraction)
    22272228{
    22282229    if (m_hasSetBlockThirdPartyCookiesCallback)
    22292230        return;
    2230    
     2231
    22312232    cacheTestRunnerCallback(StatisticsDidSetShouldBlockThirdPartyCookiesCallbackID, completionHandler);
    22322233    WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetStatisticsShouldBlockThirdPartyCookies"));
     2234    if (onlyOnSitesWithoutUserInteraction)
     2235        messageName = adoptWK(WKStringCreateWithUTF8CString("SetStatisticsShouldBlockThirdPartyCookiesOnSitesWithoutUserInteraction"));
    22332236    WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(value));
    22342237    WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr);
  • trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h

    r252623 r252840  
    443443    void setStatisticsShouldDowngradeReferrer(bool, JSValueRef callback);
    444444    void statisticsCallDidSetShouldDowngradeReferrerCallback();
    445     void setStatisticsShouldBlockThirdPartyCookies(bool, JSValueRef callback);
     445    void setStatisticsShouldBlockThirdPartyCookies(bool value, JSValueRef callback, bool onlyOnSitesWithoutUserInteraction);
    446446    void statisticsCallDidSetShouldBlockThirdPartyCookiesCallback();
    447447    void statisticsResetToConsistentState(JSValueRef completionHandler);
  • trunk/Tools/WebKitTestRunner/TestController.cpp

    r252839 r252840  
    35683568}
    35693569
    3570 void TestController::setStatisticsShouldBlockThirdPartyCookies(bool value)
     3570void TestController::setStatisticsShouldBlockThirdPartyCookies(bool value, bool onlyOnSitesWithoutUserInteraction)
    35713571{
    35723572    ResourceStatisticsCallbackContext context(*this);
    3573     WKWebsiteDataStoreSetResourceLoadStatisticsShouldBlockThirdPartyCookiesForTesting(TestController::websiteDataStore(), value, &context, resourceStatisticsVoidResultCallback);
     3573    WKWebsiteDataStoreSetResourceLoadStatisticsShouldBlockThirdPartyCookiesForTesting(TestController::websiteDataStore(), value, onlyOnSitesWithoutUserInteraction, &context, resourceStatisticsVoidResultCallback);
    35743574    runUntil(context.done, noTimeout);
    35753575    m_currentInvocation->didSetShouldBlockThirdPartyCookies();
  • trunk/Tools/WebKitTestRunner/TestController.h

    r252839 r252840  
    254254    bool hasStatisticsIsolatedSession(WKStringRef hostName);
    255255    void setStatisticsShouldDowngradeReferrer(bool value);
    256     void setStatisticsShouldBlockThirdPartyCookies(bool value);
     256    void setStatisticsShouldBlockThirdPartyCookies(bool value, bool onlyOnSitesWithoutUserInteraction);
    257257    void statisticsResetToConsistentState();
    258258
  • trunk/Tools/WebKitTestRunner/TestInvocation.cpp

    r252623 r252840  
    15501550    }
    15511551   
     1552    if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsShouldBlockThirdPartyCookiesOnSitesWithoutUserInteraction")) {
     1553        ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
     1554        WKBooleanRef value = static_cast<WKBooleanRef>(messageBody);
     1555        TestController::singleton().setStatisticsShouldBlockThirdPartyCookies(WKBooleanGetValue(value), true);
     1556        return nullptr;
     1557    }
     1558   
    15521559    if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsShouldBlockThirdPartyCookies")) {
    15531560        ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
    15541561        WKBooleanRef value = static_cast<WKBooleanRef>(messageBody);
    1555         TestController::singleton().setStatisticsShouldBlockThirdPartyCookies(WKBooleanGetValue(value));
     1562        TestController::singleton().setStatisticsShouldBlockThirdPartyCookies(WKBooleanGetValue(value), false);
    15561563        return nullptr;
    15571564    }
Note: See TracChangeset for help on using the changeset viewer.