Title: [253118] trunk
Revision
253118
Author
[email protected]
Date
2019-12-04 12:06:26 -0800 (Wed, 04 Dec 2019)

Log Message

Expose basic ITP data from the database for future API/SPI use
https://bugs.webkit.org/show_bug.cgi?id=203432
<rdar://problem/56085040>

Reviewed John Wilander.

Source/WebCore:

Tests: http/tests/resourceLoadStatistics/user-interface-data-no-storage-access-database.html
       http/tests/resourceLoadStatistics/user-interface-data-no-storage-access.html
       http/tests/storageAccess/user-interface-data-with-storage-access-database.html
       http/tests/storageAccess/user-interface-data-with-storage-access.html

Updated the toString() to report only if mostRecentUserInteractionTime
was in the last 24 hours as opposed to reporting an actual time since
mostRecentUserInteractionTime changes with each test run.


* loader/ResourceLoadStatistics.cpp:
(WebCore::hasHadRecentUserInteraction):
(WebCore::ResourceLoadStatistics::toString const):

Source/WebKit:

Tests: http/tests/resourceLoadStatistics/user-interface-data-no-storage-access-database.html
       http/tests/resourceLoadStatistics/user-interface-data-no-storage-access.html
       http/tests/storageAccess/user-interface-data-with-storage-access-database.html
       http/tests/storageAccess/user-interface-data-with-storage-access.html

Adds the ability to collect sorted ITP data for displaying in a
user interface.


* NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp:
(WebKit::ResourceLoadStatisticsDatabaseStore::ResourceLoadStatisticsDatabaseStore):
(WebKit::ResourceLoadStatisticsDatabaseStore::prepareStatements):
Added new queries to the database store to check for storage access in
the database and aggregate topFrames with the same
subframe/subresource so easily create the struct for collecting data
for the UI.

(WebKit::ResourceLoadStatisticsDatabaseStore::relationshipExists const):
Fixed an incorrect function name in the error message.

(WebKit::ResourceLoadStatisticsDatabaseStore::joinSubStatisticsForSorting):
Renamed unclear SQL variable names and added a bind parameter to
specify whether resource is prevalent or not, which allows
this function to be used to collect sorted ITP data
for the UI.

(WebKit::ResourceLoadStatisticsDatabaseStore::getFirstPartyDataForDomain const):
(WebKit::ResourceLoadStatisticsDatabaseStore::gatherDataForUserInterface const):

(WebKit::buildQueryStartAndEnd):
(WebKit::getMedianOfPrevalentResourcesWithUserInteraction):
(WebKit::ResourceLoadStatisticsDatabaseStore::getTopPrevelentResourceDaysSinceUI const):
(WebKit::getMedianOfPrevalentResourceWithoutUserInteraction):
(WebKit::getNumberOfPrevalentResourcesInTopResources):
Changed sql query variable names to make them more clear and added a
new bind parameter to allow for more general use of substatistic
sorting query.

(WebKit::ResourceLoadStatisticsDatabaseStore::hasStorageAccess const):
(WebKit::ResourceLoadStatisticsDatabaseStore::dumpResourceLoadStatistics const):
Combined UI data with dumpResourceLoadStatistics() data to keep the testing aspect
of this patch simpler.

(WebKit::ResourceLoadStatisticsDatabaseStore::resourceToString const):
Since mostRecentUserInteractionTime changes with each test run, I
updated the dumping to report only if it was in the last 24 hours as
opposed to reporting an actual time.

* NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h:
* NetworkProcess/Classifier/ResourceLoadStatisticsMemoryStore.cpp:
(WebKit::ensureFirstPartyStatistic):
(WebKit::getFirstPartyDataForDomain):
(WebKit::hasBeenThirdParty):
(WebKit::ResourceLoadStatisticsMemoryStore::gatherDataForUserInterface const):
(WebKit::ResourceLoadStatisticsMemoryStore::dumpResourceLoadStatistics):
* NetworkProcess/Classifier/ResourceLoadStatisticsMemoryStore.h:
* NetworkProcess/Classifier/ResourceLoadStatisticsStore.h:
* NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:
(WebKit::WebResourceLoadStatisticsStore::gatherDataForUserInterface):
* NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h:
(WebKit::FirstPartyData::toString const):
(WebKit::FirstPartyData::operator== const):
(WebKit::ThirdPartyData::toString const):
(WebKit::ThirdPartyData::operator< const):
The toString methods allow the structs to be printed for testing
purposes. The equals methods allow the return vectors to use
appendIfNotContains.

LayoutTests:

Added new tests to check if basic ITP data is properly
collected and sorted for both the database store and the memory store.
Also edited any tests which use dumpResourceLoadStatistics() to also
expect the new aggregated data to be displayed.


* http/tests/resourceLoadStatistics/count-third-party-script-import-in-worker-database-expected.txt:
* http/tests/resourceLoadStatistics/count-third-party-script-import-in-worker-expected.txt:
* http/tests/resourceLoadStatistics/count-third-party-script-loads-database-expected.txt:
* http/tests/resourceLoadStatistics/count-third-party-script-loads-expected.txt:
* http/tests/resourceLoadStatistics/dont-count-third-party-image-as-third-party-script-database-expected.txt:
* http/tests/resourceLoadStatistics/dont-count-third-party-image-as-third-party-script-expected.txt:
* http/tests/resourceLoadStatistics/user-interface-data-no-storage-access-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/user-interface-data-no-storage-access-database.html: Added.
* http/tests/resourceLoadStatistics/user-interface-data-no-storage-access-expected.txt: Added.
* http/tests/resourceLoadStatistics/user-interface-data-no-storage-access.html: Added.
* http/tests/storageAccess/user-interface-data-with-storage-access-database-expected.txt: Added.
* http/tests/storageAccess/user-interface-data-with-storage-access-database.html: Added.
* http/tests/storageAccess/user-interface-data-with-storage-access-expected.txt: Added.
* http/tests/storageAccess/user-interface-data-with-storage-access.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (253117 => 253118)


--- trunk/LayoutTests/ChangeLog	2019-12-04 19:02:37 UTC (rev 253117)
+++ trunk/LayoutTests/ChangeLog	2019-12-04 20:06:26 UTC (rev 253118)
@@ -1,3 +1,31 @@
+2019-12-04  Kate Cheney  <[email protected]>
+
+        Expose basic ITP data from the database for future API/SPI use
+        https://bugs.webkit.org/show_bug.cgi?id=203432
+        <rdar://problem/56085040>
+
+        Reviewed John Wilander.
+
+        Added new tests to check if basic ITP data is properly
+        collected and sorted for both the database store and the memory store.
+        Also edited any tests which use dumpResourceLoadStatistics() to also
+        expect the new aggregated data to be displayed.
+
+        * http/tests/resourceLoadStatistics/count-third-party-script-import-in-worker-database-expected.txt:
+        * http/tests/resourceLoadStatistics/count-third-party-script-import-in-worker-expected.txt:
+        * http/tests/resourceLoadStatistics/count-third-party-script-loads-database-expected.txt:
+        * http/tests/resourceLoadStatistics/count-third-party-script-loads-expected.txt:
+        * http/tests/resourceLoadStatistics/dont-count-third-party-image-as-third-party-script-database-expected.txt:
+        * http/tests/resourceLoadStatistics/dont-count-third-party-image-as-third-party-script-expected.txt:
+        * http/tests/resourceLoadStatistics/user-interface-data-no-storage-access-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/user-interface-data-no-storage-access-database.html: Added.
+        * http/tests/resourceLoadStatistics/user-interface-data-no-storage-access-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/user-interface-data-no-storage-access.html: Added.
+        * http/tests/storageAccess/user-interface-data-with-storage-access-database-expected.txt: Added.
+        * http/tests/storageAccess/user-interface-data-with-storage-access-database.html: Added.
+        * http/tests/storageAccess/user-interface-data-with-storage-access-expected.txt: Added.
+        * http/tests/storageAccess/user-interface-data-with-storage-access.html: Added.
+
 2019-12-04  Antti Koivisto  <[email protected]>
 
         [LFC][Integration] Paint with TextPainter

Added: trunk/LayoutTests/http/tests/resourceLoadStatistics/aggregate-sorted-data-no-storage-access-database-expected.txt (0 => 253118)


--- trunk/LayoutTests/http/tests/resourceLoadStatistics/aggregate-sorted-data-no-storage-access-database-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/resourceLoadStatistics/aggregate-sorted-data-no-storage-access-database-expected.txt	2019-12-04 20:06:26 UTC (rev 253118)
@@ -0,0 +1,83 @@
+Check correct UI data gets reported with no storage access.
+
+
+
+Resource load statistics:
+
+Registrable domain: subframe1
+    hadUserInteraction: No
+    mostRecentUserInteraction: -1
+    grandfathered: No
+    IsScheduledForAllButCookieDataRemoval: No
+    SubframeUnderTopFrameDomains:
+        topframe1
+    SubresourceUniqueRedirectsTo:
+        topframe2
+    isPrevalentResource: No
+    isVeryPrevalentResource: No
+    dataRecordsRemoved: 0
+Registrable domain: subframe2
+    hadUserInteraction: No
+    mostRecentUserInteraction: -1
+    grandfathered: No
+    IsScheduledForAllButCookieDataRemoval: No
+    SubframeUnderTopFrameDomains:
+        topframe1
+    isPrevalentResource: No
+    isVeryPrevalentResource: No
+    dataRecordsRemoved: 0
+Registrable domain: subframe3
+    hadUserInteraction: No
+    mostRecentUserInteraction: -1
+    grandfathered: No
+    IsScheduledForAllButCookieDataRemoval: No
+    SubframeUnderTopFrameDomains:
+        topframe1
+        topframe4
+    SubresourceUnderTopFrameDomains:
+        topframe3
+    SubresourceUniqueRedirectsTo:
+        topframe2
+    isPrevalentResource: No
+    isVeryPrevalentResource: No
+    dataRecordsRemoved: 0
+Registrable domain: topframe1
+    hadUserInteraction: No
+    mostRecentUserInteraction: -1
+    grandfathered: No
+    IsScheduledForAllButCookieDataRemoval: No
+    isPrevalentResource: No
+    isVeryPrevalentResource: No
+    dataRecordsRemoved: 0
+Registrable domain: topframe2
+    hadUserInteraction: No
+    mostRecentUserInteraction: -1
+    grandfathered: No
+    IsScheduledForAllButCookieDataRemoval: No
+    isPrevalentResource: No
+    isVeryPrevalentResource: No
+    dataRecordsRemoved: 0
+Registrable domain: topframe3
+    hadUserInteraction: No
+    mostRecentUserInteraction: -1
+    grandfathered: No
+    IsScheduledForAllButCookieDataRemoval: No
+    isPrevalentResource: No
+    isVeryPrevalentResource: No
+    dataRecordsRemoved: 0
+Registrable domain: topframe4
+    hadUserInteraction: No
+    mostRecentUserInteraction: -1
+    grandfathered: No
+    IsScheduledForAllButCookieDataRemoval: No
+    isPrevalentResource: No
+    isVeryPrevalentResource: No
+    dataRecordsRemoved: 0
+
+ITP Data:
+Third Party Registrable Domain: subframe3
+    {{ Has been granted storage access under topframe1: 0 },{ Has been granted storage access under topframe4: 0 },{ Has been granted storage access under topframe3: 0 },{ Has been granted storage access under topframe2: 0 },}
+Third Party Registrable Domain: subframe1
+    {{ Has been granted storage access under topframe1: 0 },{ Has been granted storage access under topframe2: 0 },}
+Third Party Registrable Domain: subframe2
+    {{ Has been granted storage access under topframe1: 0 },}

Added: trunk/LayoutTests/http/tests/resourceLoadStatistics/aggregate-sorted-data-no-storage-access-database.html (0 => 253118)


--- trunk/LayoutTests/http/tests/resourceLoadStatistics/aggregate-sorted-data-no-storage-access-database.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/resourceLoadStatistics/aggregate-sorted-data-no-storage-access-database.html	2019-12-04 20:06:26 UTC (rev 253118)
@@ -0,0 +1,54 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src=""
+    <script src=""
+</head>
+<body _onload_="setTimeout('runTest()', 0)">
+<div id="description">Check correct UI data gets reported with no storage access.</div>
+<br>
+<div id="output"></div>
+<br>
+<script>
+    testRunner.waitUntilDone();
+    testRunner.dumpAsText();
+
+    function finishTest() {
+        testRunner.dumpResourceLoadStatistics();
+        setEnableFeature(false, function() {
+            testRunner.notifyDone();
+        });
+    }
+
+    const subOrigin1 = "http://subframe1:8000";
+    const subOrigin2  = "http://subframe2:8000";
+    const subOrigin3  = "http://subframe3:8000";
+
+    const topFrameOrigin1 = "http://topframe1:8000";
+    const topFrameOrigin2 = "http://topframe2:8000";
+    const topFrameOrigin3 = "http://topframe3:8000";
+    const topFrameOrigin4 = "http://topframe4:8000";
+
+    function runTest() {
+        testRunner.setUseITPDatabase(true);
+        setEnableFeature(true, function () {
+
+            // subOrigin1 will be logged under 2 top frames. Should appear second
+            testRunner.setStatisticsSubframeUnderTopFrameOrigin(subOrigin1, topFrameOrigin1);
+            testRunner.setStatisticsSubresourceUniqueRedirectTo(subOrigin1, topFrameOrigin2);
+
+            // subOrigin2 will be logged under 1 top frames. Should appear third
+            testRunner.setStatisticsSubframeUnderTopFrameOrigin(subOrigin2, topFrameOrigin1);
+
+            // subOrigin3 will be logged under 4 top frames. Should appear first
+            testRunner.setStatisticsSubframeUnderTopFrameOrigin(subOrigin3, topFrameOrigin1);
+            testRunner.setStatisticsSubresourceUniqueRedirectTo(subOrigin3, topFrameOrigin2);
+            testRunner.setStatisticsSubresourceUnderTopFrameOrigin(subOrigin3, topFrameOrigin3);
+            testRunner.setStatisticsSubframeUnderTopFrameOrigin(subOrigin3, topFrameOrigin4);
+
+            setTimeout(function () { finishTest() }, 500);
+        });
+    }
+</script>
+</body>
+</html>

Added: trunk/LayoutTests/http/tests/resourceLoadStatistics/aggregate-sorted-data-no-storage-access-expected.txt (0 => 253118)


--- trunk/LayoutTests/http/tests/resourceLoadStatistics/aggregate-sorted-data-no-storage-access-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/resourceLoadStatistics/aggregate-sorted-data-no-storage-access-expected.txt	2019-12-04 20:06:26 UTC (rev 253118)
@@ -0,0 +1,83 @@
+Check correct UI data gets reported with no storage access granted.
+
+
+
+Resource load statistics:
+
+Registrable domain: topframe2
+    hadUserInteraction: No
+    mostRecentUserInteraction: -1
+    grandfathered: No
+    gotLinkDecorationFromPrevalentResource: No
+    isPrevalentResource: No
+    isVeryPrevalentResource: No
+    dataRecordsRemoved: 0
+Registrable domain: topframe3
+    hadUserInteraction: No
+    mostRecentUserInteraction: -1
+    grandfathered: No
+    gotLinkDecorationFromPrevalentResource: No
+    isPrevalentResource: No
+    isVeryPrevalentResource: No
+    dataRecordsRemoved: 0
+Registrable domain: topframe1
+    hadUserInteraction: No
+    mostRecentUserInteraction: -1
+    grandfathered: No
+    gotLinkDecorationFromPrevalentResource: No
+    isPrevalentResource: No
+    isVeryPrevalentResource: No
+    dataRecordsRemoved: 0
+Registrable domain: topframe4
+    hadUserInteraction: No
+    mostRecentUserInteraction: -1
+    grandfathered: No
+    gotLinkDecorationFromPrevalentResource: No
+    isPrevalentResource: No
+    isVeryPrevalentResource: No
+    dataRecordsRemoved: 0
+Registrable domain: subframe1
+    hadUserInteraction: No
+    mostRecentUserInteraction: -1
+    grandfathered: No
+    gotLinkDecorationFromPrevalentResource: No
+    subframeUnderTopFrameDomains:
+        topframe1
+    subresourceUniqueRedirectsTo:
+        topframe2
+    isPrevalentResource: No
+    isVeryPrevalentResource: No
+    dataRecordsRemoved: 0
+Registrable domain: subframe2
+    hadUserInteraction: No
+    mostRecentUserInteraction: -1
+    grandfathered: No
+    gotLinkDecorationFromPrevalentResource: No
+    subframeUnderTopFrameDomains:
+        topframe1
+    isPrevalentResource: No
+    isVeryPrevalentResource: No
+    dataRecordsRemoved: 0
+Registrable domain: subframe3
+    hadUserInteraction: No
+    mostRecentUserInteraction: -1
+    grandfathered: No
+    gotLinkDecorationFromPrevalentResource: No
+    subframeUnderTopFrameDomains:
+        topframe1
+        topframe4
+    subresourceUnderTopFrameDomains:
+        topframe3
+    subresourceUniqueRedirectsTo:
+        topframe2
+    isPrevalentResource: No
+    isVeryPrevalentResource: No
+    dataRecordsRemoved: 0
+
+ITP Data:
+Third Party Registrable Domain: subframe3
+    {{ Has been granted storage access under topframe1: 0 },{ Has been granted storage access under topframe4: 0 },{ Has been granted storage access under topframe3: 0 },{ Has been granted storage access under topframe2: 0 },}
+Third Party Registrable Domain: subframe1
+    {{ Has been granted storage access under topframe1: 0 },{ Has been granted storage access under topframe2: 0 },}
+Third Party Registrable Domain: subframe2
+    {{ Has been granted storage access under topframe1: 0 },}

Added: trunk/LayoutTests/http/tests/resourceLoadStatistics/aggregate-sorted-data-no-storage-access.html (0 => 253118)


--- trunk/LayoutTests/http/tests/resourceLoadStatistics/aggregate-sorted-data-no-storage-access.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/resourceLoadStatistics/aggregate-sorted-data-no-storage-access.html	2019-12-04 20:06:26 UTC (rev 253118)
@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src=""
+    <script src=""
+</head>
+<body _onload_="setTimeout('runTest()', 0)">
+<div id="description">Check correct UI data gets reported with no storage access granted.</div>
+<br>
+<div id="output"></div>
+<br>
+<script>
+    testRunner.waitUntilDone();
+    testRunner.dumpAsText();
+
+    function finishTest() {
+        testRunner.dumpResourceLoadStatistics();
+        setEnableFeature(false, function() {
+            testRunner.notifyDone();
+        });
+    }
+
+    const subOrigin1 = "http://subframe1:8000";
+    const subOrigin2  = "http://subframe2:8000";
+    const subOrigin3  = "http://subframe3:8000";
+    
+    const topFrameOrigin1 = "http://topframe1:8000";
+    const topFrameOrigin2 = "http://topframe2:8000";
+    const topFrameOrigin3 = "http://topframe3:8000";
+    const topFrameOrigin4 = "http://topframe4:8000";
+
+    function runTest() {
+        setEnableFeature(true, function () {
+
+            // subOrigin1 will be logged under 2 top frames. Should appear second
+            testRunner.setStatisticsSubframeUnderTopFrameOrigin(subOrigin1, topFrameOrigin1);
+            testRunner.setStatisticsSubresourceUniqueRedirectTo(subOrigin1, topFrameOrigin2);
+
+            // subOrigin2 will be logged under 1 top frames. Should appear third
+            testRunner.setStatisticsSubframeUnderTopFrameOrigin(subOrigin2, topFrameOrigin1);
+
+            // subOrigin3 will be logged under 4 top frames. Should appear first
+            testRunner.setStatisticsSubframeUnderTopFrameOrigin(subOrigin3, topFrameOrigin1);
+            testRunner.setStatisticsSubresourceUniqueRedirectTo(subOrigin3, topFrameOrigin2);
+            testRunner.setStatisticsSubresourceUnderTopFrameOrigin(subOrigin3, topFrameOrigin3);
+            testRunner.setStatisticsSubframeUnderTopFrameOrigin(subOrigin3, topFrameOrigin4);
+
+            setTimeout(function () { finishTest() }, 500);
+        });
+    }
+</script>
+</body>
+</html>

Modified: trunk/LayoutTests/http/tests/resourceLoadStatistics/count-third-party-script-import-in-worker-database-expected.txt (253117 => 253118)


--- trunk/LayoutTests/http/tests/resourceLoadStatistics/count-third-party-script-import-in-worker-database-expected.txt	2019-12-04 19:02:37 UTC (rev 253117)
+++ trunk/LayoutTests/http/tests/resourceLoadStatistics/count-third-party-script-import-in-worker-database-expected.txt	2019-12-04 20:06:26 UTC (rev 253118)
@@ -24,3 +24,7 @@
     isPrevalentResource: No
     isVeryPrevalentResource: No
     dataRecordsRemoved: 0
+
+ITP Data:
+Third Party Registrable Domain: localhost
+    {{ Has been granted storage access under 127.0.0.1: 0 },}

Modified: trunk/LayoutTests/http/tests/resourceLoadStatistics/count-third-party-script-import-in-worker-expected.txt (253117 => 253118)


--- trunk/LayoutTests/http/tests/resourceLoadStatistics/count-third-party-script-import-in-worker-expected.txt	2019-12-04 19:02:37 UTC (rev 253117)
+++ trunk/LayoutTests/http/tests/resourceLoadStatistics/count-third-party-script-import-in-worker-expected.txt	2019-12-04 20:06:26 UTC (rev 253118)
@@ -24,3 +24,7 @@
     isPrevalentResource: No
     isVeryPrevalentResource: No
     dataRecordsRemoved: 0
+
+ITP Data:
+Third Party Registrable Domain: localhost
+    {{ Has been granted storage access under 127.0.0.1: 0 },}

Modified: trunk/LayoutTests/http/tests/resourceLoadStatistics/count-third-party-script-loads-database-expected.txt (253117 => 253118)


--- trunk/LayoutTests/http/tests/resourceLoadStatistics/count-third-party-script-loads-database-expected.txt	2019-12-04 19:02:37 UTC (rev 253117)
+++ trunk/LayoutTests/http/tests/resourceLoadStatistics/count-third-party-script-loads-database-expected.txt	2019-12-04 20:06:26 UTC (rev 253118)
@@ -24,3 +24,7 @@
     isPrevalentResource: No
     isVeryPrevalentResource: No
     dataRecordsRemoved: 0
+
+ITP Data:
+Third Party Registrable Domain: localhost
+    {{ Has been granted storage access under 127.0.0.1: 0 },}

Modified: trunk/LayoutTests/http/tests/resourceLoadStatistics/count-third-party-script-loads-expected.txt (253117 => 253118)


--- trunk/LayoutTests/http/tests/resourceLoadStatistics/count-third-party-script-loads-expected.txt	2019-12-04 19:02:37 UTC (rev 253117)
+++ trunk/LayoutTests/http/tests/resourceLoadStatistics/count-third-party-script-loads-expected.txt	2019-12-04 20:06:26 UTC (rev 253118)
@@ -24,3 +24,7 @@
     isPrevalentResource: No
     isVeryPrevalentResource: No
     dataRecordsRemoved: 0
+
+ITP Data:
+Third Party Registrable Domain: localhost
+    {{ Has been granted storage access under 127.0.0.1: 0 },}

Modified: trunk/LayoutTests/http/tests/resourceLoadStatistics/dont-count-third-party-image-as-third-party-script-database-expected.txt (253117 => 253118)


--- trunk/LayoutTests/http/tests/resourceLoadStatistics/dont-count-third-party-image-as-third-party-script-database-expected.txt	2019-12-04 19:02:37 UTC (rev 253117)
+++ trunk/LayoutTests/http/tests/resourceLoadStatistics/dont-count-third-party-image-as-third-party-script-database-expected.txt	2019-12-04 20:06:26 UTC (rev 253118)
@@ -22,3 +22,7 @@
     isPrevalentResource: No
     isVeryPrevalentResource: No
     dataRecordsRemoved: 0
+
+ITP Data:
+Third Party Registrable Domain: localhost
+    {{ Has been granted storage access under 127.0.0.1: 0 },}

Modified: trunk/LayoutTests/http/tests/resourceLoadStatistics/dont-count-third-party-image-as-third-party-script-expected.txt (253117 => 253118)


--- trunk/LayoutTests/http/tests/resourceLoadStatistics/dont-count-third-party-image-as-third-party-script-expected.txt	2019-12-04 19:02:37 UTC (rev 253117)
+++ trunk/LayoutTests/http/tests/resourceLoadStatistics/dont-count-third-party-image-as-third-party-script-expected.txt	2019-12-04 20:06:26 UTC (rev 253118)
@@ -14,3 +14,7 @@
     isPrevalentResource: No
     isVeryPrevalentResource: No
     dataRecordsRemoved: 0
+
+ITP Data:
+Third Party Registrable Domain: localhost
+    {{ Has been granted storage access under 127.0.0.1: 0 },}

Added: trunk/LayoutTests/http/tests/storageAccess/aggregate-sorted-data-with-storage-access-database-expected.txt (0 => 253118)


--- trunk/LayoutTests/http/tests/storageAccess/aggregate-sorted-data-with-storage-access-database-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/storageAccess/aggregate-sorted-data-with-storage-access-database-expected.txt	2019-12-04 20:06:26 UTC (rev 253118)
@@ -0,0 +1,36 @@
+Check correct UI data gets reported with storage access granted.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS Storage access was granted. document.cookie == firstPartyCookie=value, cookies seen server-side == {"firstPartyCookie":"value"}
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
+Resource load statistics:
+
+Registrable domain: 127.0.0.1
+    hadUserInteraction: Yes
+    mostRecentUserInteraction: within 24 hours
+    grandfathered: No
+    IsScheduledForAllButCookieDataRemoval: No
+    isPrevalentResource: No
+    isVeryPrevalentResource: No
+    dataRecordsRemoved: 0
+Registrable domain: localhost
+    hadUserInteraction: Yes
+    mostRecentUserInteraction: within 24 hours
+    grandfathered: No
+    StorageAccessUnderTopFrameDomains:
+        127.0.0.1
+    IsScheduledForAllButCookieDataRemoval: No
+    SubframeUnderTopFrameDomains:
+        127.0.0.1
+    isPrevalentResource: No
+    isVeryPrevalentResource: No
+    dataRecordsRemoved: 0
+
+ITP Data:
+Third Party Registrable Domain: localhost
+    {{ Has been granted storage access under 127.0.0.1: 1 },}

Added: trunk/LayoutTests/http/tests/storageAccess/aggregate-sorted-data-with-storage-access-database.html (0 => 253118)


--- trunk/LayoutTests/http/tests/storageAccess/aggregate-sorted-data-with-storage-access-database.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/storageAccess/aggregate-sorted-data-with-storage-access-database.html	2019-12-04 20:06:26 UTC (rev 253118)
@@ -0,0 +1,86 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src=""
+    <script src=""
+    <script src=""
+    <script>
+        description("Check correct UI data gets reported with storage access granted.");
+        jsTestIsAsync = true;
+        testRunner.setUseITPDatabase(true);
+
+        const firstPartyUrl = "http://127.0.0.1:8000";
+        const thirdPartyUrl = "http://localhost:8000";
+
+        function receiveMessage(event) {
+            if (event.origin === "http://localhost:8000") {
+                if (event.data.indexOf("PASS ") !== -1) {
+                    testRunner.dumpResourceLoadStatistics();
+                    testPassed(event.data.replace("PASS ", ""));
+                } else
+                    testFailed(event.data.replace("FAIL ", ""));
+            } else
+                testFailed("Received a message from an unexpected origin: " + event.origin);
+            testRunner.setStatisticsShouldBlockThirdPartyCookies(false, function() {
+                setEnableFeature(false, finishJSTest);
+            });
+        }
+
+        window.addEventListener("message", receiveMessage, false);
+
+        function activateElement(elementId) {
+            var element = document.getElementById(elementId);
+            var centerX = element.offsetLeft + element.offsetWidth / 2;
+            var centerY = element.offsetTop + element.offsetHeight / 2;
+            UIHelper.activateAt(centerX, centerY).then(
+                function () {
+                    if (window.eventSender)
+                        eventSender.keyDown("escape");
+                    else {
+                        testFailed("No eventSender.");
+                        testRunner.setStatisticsShouldBlockThirdPartyCookies(false, function() {
+                            setEnableFeature(false, finishJSTest);
+                        });
+                    }
+                },
+                function () {
+                    testFailed("Promise rejected.");
+                    testRunner.setStatisticsShouldBlockThirdPartyCookies(false, function() {
+                        setEnableFeature(false, finishJSTest);
+                    });
+                }
+            );
+        }
+
+        function runTest() {
+            if (document.location.hash !== "#cookieSet") {
+                setEnableFeature(true, function() {
+                    document.location.href = "" + "/storageAccess/resources/set-cookie.php?name=firstPartyCookie&value=value#" + firstPartyUrl + "/storageAccess/aggregate-sorted-data-with-storage-access-database.html#cookieSet";
+                });
+            } else {
+                testRunner.setStatisticsShouldBlockThirdPartyCookies(true, function() {
+                    if (testRunner.isStatisticsPrevalentResource(thirdPartyUrl))
+                        testFailed("Third-party set as prevalent resource.");
+                    testRunner.setStatisticsHasHadUserInteraction(firstPartyUrl, true, function() {
+                        if (!testRunner.isStatisticsHasHadUserInteraction(firstPartyUrl))
+                            testFailed("First-party did not get logged for user interaction.");
+                        testRunner.setStatisticsHasHadUserInteraction(thirdPartyUrl, true, function() {
+                            if (!testRunner.isStatisticsHasHadUserInteraction(thirdPartyUrl))
+                                testFailed("Third-party did not get logged for user interaction.");
+                            let iframeElement = document.createElement("iframe");
+                            iframeElement._onload_ = function() {
+                                activateElement("TheIframeThatRequestsStorageAccess");
+                            };
+                            iframeElement.id = "TheIframeThatRequestsStorageAccess";
+                            iframeElement.src = ""
+                            document.body.appendChild(iframeElement);
+                        });
+                    });
+                });
+            }
+        }
+    </script>
+</head>
+<body _onload_="runTest()">
+</body>
+</html>

Added: trunk/LayoutTests/http/tests/storageAccess/aggregate-sorted-data-with-storage-access-expected.txt (0 => 253118)


--- trunk/LayoutTests/http/tests/storageAccess/aggregate-sorted-data-with-storage-access-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/storageAccess/aggregate-sorted-data-with-storage-access-expected.txt	2019-12-04 20:06:26 UTC (rev 253118)
@@ -0,0 +1,36 @@
+Check correct UI data gets reported with storage access granted.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS Storage access was granted. document.cookie == firstPartyCookie=value, cookies seen server-side == {"firstPartyCookie":"value"}
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
+Resource load statistics:
+
+Registrable domain: localhost
+    hadUserInteraction: Yes
+    mostRecentUserInteraction: within 24 hours
+    grandfathered: No
+    storageAccessUnderTopFrameDomains:
+        127.0.0.1
+    gotLinkDecorationFromPrevalentResource: No
+    subframeUnderTopFrameDomains:
+        127.0.0.1
+    isPrevalentResource: No
+    isVeryPrevalentResource: No
+    dataRecordsRemoved: 0
+Registrable domain: 127.0.0.1
+    hadUserInteraction: Yes
+    mostRecentUserInteraction: within 24 hours
+    grandfathered: No
+    gotLinkDecorationFromPrevalentResource: No
+    isPrevalentResource: No
+    isVeryPrevalentResource: No
+    dataRecordsRemoved: 0
+
+ITP Data:
+Third Party Registrable Domain: localhost
+    {{ Has been granted storage access under 127.0.0.1: 1 },}

Added: trunk/LayoutTests/http/tests/storageAccess/aggregate-sorted-data-with-storage-access.html (0 => 253118)


--- trunk/LayoutTests/http/tests/storageAccess/aggregate-sorted-data-with-storage-access.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/storageAccess/aggregate-sorted-data-with-storage-access.html	2019-12-04 20:06:26 UTC (rev 253118)
@@ -0,0 +1,85 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src=""
+    <script src=""
+    <script src=""
+    <script>
+        description("Check correct UI data gets reported with storage access granted.");
+        jsTestIsAsync = true;
+
+        const firstPartyUrl = "http://127.0.0.1:8000";
+        const thirdPartyUrl = "http://localhost:8000";
+
+        function receiveMessage(event) {
+            if (event.origin === "http://localhost:8000") {
+                if (event.data.indexOf("PASS ") !== -1) {
+                    testRunner.dumpResourceLoadStatistics();
+                    testPassed(event.data.replace("PASS ", ""));
+                } else
+                    testFailed(event.data.replace("FAIL ", ""));
+            } else
+                testFailed("Received a message from an unexpected origin: " + event.origin);
+            testRunner.setStatisticsShouldBlockThirdPartyCookies(false, function() {
+                setEnableFeature(false, finishJSTest);
+            });
+        }
+
+        window.addEventListener("message", receiveMessage, false);
+
+        function activateElement(elementId) {
+            var element = document.getElementById(elementId);
+            var centerX = element.offsetLeft + element.offsetWidth / 2;
+            var centerY = element.offsetTop + element.offsetHeight / 2;
+            UIHelper.activateAt(centerX, centerY).then(
+                function () {
+                    if (window.eventSender)
+                        eventSender.keyDown("escape");
+                    else {
+                        testFailed("No eventSender.");
+                        testRunner.setStatisticsShouldBlockThirdPartyCookies(false, function() {
+                            setEnableFeature(false, finishJSTest);
+                        });
+                    }
+                },
+                function () {
+                    testFailed("Promise rejected.");
+                    testRunner.setStatisticsShouldBlockThirdPartyCookies(false, function() {
+                        setEnableFeature(false, finishJSTest);
+                    });
+                }
+            );
+        }
+
+        function runTest() {
+            if (document.location.hash !== "#cookieSet") {
+                setEnableFeature(true, function() {
+                    document.location.href = "" + "/storageAccess/resources/set-cookie.php?name=firstPartyCookie&value=value#" + firstPartyUrl + "/storageAccess/aggregate-sorted-data-with-storage-access.html#cookieSet";
+                });
+            } else {
+                testRunner.setStatisticsShouldBlockThirdPartyCookies(true, function() {
+                    if (testRunner.isStatisticsPrevalentResource(thirdPartyUrl))
+                        testFailed("Third-party set as prevalent resource.");
+                    testRunner.setStatisticsHasHadUserInteraction(firstPartyUrl, true, function() {
+                        if (!testRunner.isStatisticsHasHadUserInteraction(firstPartyUrl))
+                            testFailed("First-party did not get logged for user interaction.");
+                        testRunner.setStatisticsHasHadUserInteraction(thirdPartyUrl, true, function() {
+                            if (!testRunner.isStatisticsHasHadUserInteraction(thirdPartyUrl))
+                                testFailed("Third-party did not get logged for user interaction.");
+                            let iframeElement = document.createElement("iframe");
+                            iframeElement._onload_ = function() {
+                                activateElement("TheIframeThatRequestsStorageAccess");
+                            };
+                            iframeElement.id = "TheIframeThatRequestsStorageAccess";
+                            iframeElement.src = ""
+                            document.body.appendChild(iframeElement);
+                        });
+                    });
+                });
+            }
+        }
+    </script>
+</head>
+<body _onload_="runTest()">
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (253117 => 253118)


--- trunk/Source/WebCore/ChangeLog	2019-12-04 19:02:37 UTC (rev 253117)
+++ trunk/Source/WebCore/ChangeLog	2019-12-04 20:06:26 UTC (rev 253118)
@@ -1,3 +1,24 @@
+2019-12-04  Kate Cheney  <[email protected]>
+
+        Expose basic ITP data from the database for future API/SPI use
+        https://bugs.webkit.org/show_bug.cgi?id=203432
+        <rdar://problem/56085040>
+
+        Reviewed John Wilander.
+
+        Tests: http/tests/resourceLoadStatistics/user-interface-data-no-storage-access-database.html
+               http/tests/resourceLoadStatistics/user-interface-data-no-storage-access.html
+               http/tests/storageAccess/user-interface-data-with-storage-access-database.html
+               http/tests/storageAccess/user-interface-data-with-storage-access.html
+
+        Updated the toString() to report only if mostRecentUserInteractionTime
+        was in the last 24 hours as opposed to reporting an actual time since 
+        mostRecentUserInteractionTime changes with each test run.
+
+        * loader/ResourceLoadStatistics.cpp:
+        (WebCore::hasHadRecentUserInteraction):
+        (WebCore::ResourceLoadStatistics::toString const):
+
 2019-12-04  Louie Livon-Bemel  <[email protected]>
 
         Add exclusion rule for text manipulation SPI to exclude based on element class

Modified: trunk/Source/WebCore/loader/ResourceLoadStatistics.cpp (253117 => 253118)


--- trunk/Source/WebCore/loader/ResourceLoadStatistics.cpp	2019-12-04 19:02:37 UTC (rev 253117)
+++ trunk/Source/WebCore/loader/ResourceLoadStatistics.cpp	2019-12-04 20:06:26 UTC (rev 253118)
@@ -413,6 +413,11 @@
 }
 #endif
 
+static bool hasHadRecentUserInteraction(WTF::Seconds interactionTimeSeconds)
+{
+    return interactionTimeSeconds > Seconds(0) && WallTime::now().secondsSinceEpoch() - interactionTimeSeconds < 24_h;
+}
+
 String ResourceLoadStatistics::toString() const
 {
     StringBuilder builder;
@@ -424,7 +429,10 @@
     appendBoolean(builder, "hadUserInteraction", hadUserInteraction);
     builder.append('\n');
     builder.appendLiteral("    mostRecentUserInteraction: ");
-    builder.appendFixedPrecisionNumber(mostRecentUserInteractionTime.secondsSinceEpoch().value());
+    if (hasHadRecentUserInteraction(mostRecentUserInteractionTime.secondsSinceEpoch()))
+        builder.appendLiteral("within 24 hours");
+    else
+        builder.appendLiteral("-1");
     builder.append('\n');
     appendBoolean(builder, "grandfathered", grandfathered);
     builder.append('\n');

Modified: trunk/Source/WebKit/ChangeLog (253117 => 253118)


--- trunk/Source/WebKit/ChangeLog	2019-12-04 19:02:37 UTC (rev 253117)
+++ trunk/Source/WebKit/ChangeLog	2019-12-04 20:06:26 UTC (rev 253118)
@@ -1,3 +1,78 @@
+2019-12-04  Kate Cheney  <[email protected]>
+
+        Expose basic ITP data from the database for future API/SPI use
+        https://bugs.webkit.org/show_bug.cgi?id=203432
+        <rdar://problem/56085040>
+
+        Reviewed John Wilander.
+
+        Tests: http/tests/resourceLoadStatistics/user-interface-data-no-storage-access-database.html
+               http/tests/resourceLoadStatistics/user-interface-data-no-storage-access.html
+               http/tests/storageAccess/user-interface-data-with-storage-access-database.html
+               http/tests/storageAccess/user-interface-data-with-storage-access.html
+
+        Adds the ability to collect sorted ITP data for displaying in a
+        user interface. 
+
+        * NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp:
+        (WebKit::ResourceLoadStatisticsDatabaseStore::ResourceLoadStatisticsDatabaseStore):
+        (WebKit::ResourceLoadStatisticsDatabaseStore::prepareStatements):
+        Added new queries to the database store to check for storage access in
+        the database and aggregate topFrames with the same
+        subframe/subresource so easily create the struct for collecting data
+        for the UI.
+
+        (WebKit::ResourceLoadStatisticsDatabaseStore::relationshipExists const):
+        Fixed an incorrect function name in the error message.
+
+        (WebKit::ResourceLoadStatisticsDatabaseStore::joinSubStatisticsForSorting):
+        Renamed unclear SQL variable names and added a bind parameter to
+        specify whether resource is prevalent or not, which allows
+        this function to be used to collect sorted ITP data
+        for the UI.
+
+        (WebKit::ResourceLoadStatisticsDatabaseStore::getFirstPartyDataForDomain const):
+        (WebKit::ResourceLoadStatisticsDatabaseStore::gatherDataForUserInterface const):
+
+        (WebKit::buildQueryStartAndEnd):
+        (WebKit::getMedianOfPrevalentResourcesWithUserInteraction):
+        (WebKit::ResourceLoadStatisticsDatabaseStore::getTopPrevelentResourceDaysSinceUI const):
+        (WebKit::getMedianOfPrevalentResourceWithoutUserInteraction):
+        (WebKit::getNumberOfPrevalentResourcesInTopResources):
+        Changed sql query variable names to make them more clear and added a
+        new bind parameter to allow for more general use of substatistic
+        sorting query.
+
+        (WebKit::ResourceLoadStatisticsDatabaseStore::hasStorageAccess const):
+        (WebKit::ResourceLoadStatisticsDatabaseStore::dumpResourceLoadStatistics const):
+        Combined UI data with dumpResourceLoadStatistics() data to keep the testing aspect
+        of this patch simpler.
+
+        (WebKit::ResourceLoadStatisticsDatabaseStore::resourceToString const):
+        Since mostRecentUserInteractionTime changes with each test run, I
+        updated the dumping to report only if it was in the last 24 hours as
+        opposed to reporting an actual time.
+
+        * NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h:
+        * NetworkProcess/Classifier/ResourceLoadStatisticsMemoryStore.cpp:
+        (WebKit::ensureFirstPartyStatistic):
+        (WebKit::getFirstPartyDataForDomain):
+        (WebKit::hasBeenThirdParty):
+        (WebKit::ResourceLoadStatisticsMemoryStore::gatherDataForUserInterface const):
+        (WebKit::ResourceLoadStatisticsMemoryStore::dumpResourceLoadStatistics):
+        * NetworkProcess/Classifier/ResourceLoadStatisticsMemoryStore.h:
+        * NetworkProcess/Classifier/ResourceLoadStatisticsStore.h:
+        * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:
+        (WebKit::WebResourceLoadStatisticsStore::gatherDataForUserInterface):
+        * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h:
+        (WebKit::FirstPartyData::toString const):
+        (WebKit::FirstPartyData::operator== const):
+        (WebKit::ThirdPartyData::toString const):
+        (WebKit::ThirdPartyData::operator< const):
+        The toString methods allow the structs to be printed for testing
+        purposes. The equals methods allow the return vectors to use
+        appendIfNotContains.
+
 2019-12-04  Louie Livon-Bemel  <[email protected]>
 
         Add exclusion rule for text manipulation SPI to exclude based on element class

Modified: trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp (253117 => 253118)


--- trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp	2019-12-04 19:02:37 UTC (rev 253117)
+++ trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp	2019-12-04 20:06:26 UTC (rev 253118)
@@ -99,6 +99,7 @@
     "AND fromDomainID = (SELECT domainID FROM ObservedDomains WHERE registrableDomain = ?))"_s;
 constexpr auto topFrameLoadedThirdPartyScriptsExistsQuery = "SELECT EXISTS (SELECT 1 FROM TopFrameLoadedThirdPartyScripts WHERE topFrameDomainID = ? "
     "AND subresourceDomainID = (SELECT domainID FROM ObservedDomains WHERE registrableDomain = ?))"_s;
+constexpr auto storageAccessExistsQuery = "SELECT EXISTS (SELECT 1 FROM StorageAccessUnderTopFrameDomains WHERE domainID = ? AND topLevelDomainID = (SELECT domainID FROM ObservedDomains WHERE registrableDomain = ?))"_s;
 
 // UPDATE Queries
 constexpr auto mostRecentUserInteractionQuery = "UPDATE ObservedDomains SET hadUserInteraction = ?, mostRecentUserInteractionTime = ? "
@@ -121,6 +122,9 @@
 constexpr auto findExpiredUserInteractionQuery = "SELECT domainID FROM ObservedDomains WHERE hadUserInteraction = 1 AND mostRecentUserInteractionTime < ?"_s;
 constexpr auto getResourceDataByDomainNameQuery = "SELECT * FROM ObservedDomains WHERE registrableDomain = ?";
 constexpr auto getAllDomainsQuery = "SELECT registrableDomain FROM ObservedDomains"_s;
+constexpr auto getAllSubStatisticsUnderDomainQuery = "SELECT topFrameDomainID FROM SubframeUnderTopFrameDomains WHERE subFrameDomainID = ?"
+    "UNION ALL SELECT topFrameDomainID FROM SubresourceUnderTopFrameDomains WHERE subresourceDomainID = ?"
+    "UNION ALL SELECT toDomainID FROM SubresourceUniqueRedirectsTo WHERE subresourceDomainID = ?"_s;
 
 const char* tables[] = {
     "ObservedDomains",
@@ -262,6 +266,8 @@
     , m_getResourceDataByDomainNameStatement(m_database, getResourceDataByDomainNameQuery)
     , m_getAllDomainsStatement(m_database, getAllDomainsQuery)
     , m_domainStringFromDomainIDStatement(m_database, domainStringFromDomainIDQuery)
+    , m_getAllSubStatisticsStatement(m_database, getAllSubStatisticsUnderDomainQuery)
+    , m_storageAccessExistsStatement(m_database, storageAccessExistsQuery)
     , m_sessionID(sessionID)
 {
     ASSERT(!RunLoop::isMain());
@@ -503,6 +509,8 @@
         || m_getResourceDataByDomainNameStatement.prepare() != SQLITE_OK
         || m_getAllDomainsStatement.prepare() != SQLITE_OK
         || m_domainStringFromDomainIDStatement.prepare() != SQLITE_OK
+        || m_getAllSubStatisticsStatement.prepare() != SQLITE_OK
+        || m_storageAccessExistsStatement.prepare() != SQLITE_OK
         ) {
         RELEASE_LOG_ERROR(Network, "%p - ResourceLoadStatisticsDatabaseStore::prepareStatements failed to prepare, error message: %{public}s", this, m_database.lastErrorMsg());
         ASSERT_NOT_REACHED();
@@ -560,7 +568,7 @@
     if (statement.bindInt(1, *firstDomainID) != SQLITE_OK
         || statement.bindText(2, secondDomain.string()) != SQLITE_OK
         || statement.step() != SQLITE_ROW) {
-        RELEASE_LOG_ERROR_IF_ALLOWED(m_sessionID, "%p - ResourceLoadStatisticsDatabaseStore::m_insertDomainRelationshipStatement failed to bind, error message: %{private}s", this, m_database.lastErrorMsg());
+        RELEASE_LOG_ERROR_IF_ALLOWED(m_sessionID, "%p - ResourceLoadStatisticsDatabaseStore::relationshipExists failed to bind, error message: %{private}s", this, m_database.lastErrorMsg());
         ASSERT_NOT_REACHED();
         return false;
     }
@@ -755,19 +763,19 @@
 {
     return R"query(
         domainID,
-        (cnt1 + cnt2 + cnt3) as sum
+        (countSubFrameUnderTopFrame + countSubResourceUnderTopFrame + countUniqueRedirectTo) as sum
         FROM (
         SELECT
             domainID,
-            COUNT(DISTINCT f.topFrameDomainID) as cnt1,
-            COUNT(DISTINCT r.topFrameDomainID) as cnt2,
-            COUNT(DISTINCT toDomainID) as cnt3
+            COUNT(DISTINCT f.topFrameDomainID) as countSubFrameUnderTopFrame,
+            COUNT(DISTINCT r.topFrameDomainID) as countSubResourceUnderTopFrame,
+            COUNT(DISTINCT toDomainID) as countUniqueRedirectTo
         FROM
         ObservedDomains o
         LEFT JOIN SubframeUnderTopFrameDomains f ON o.domainID = f.subFrameDomainID
         LEFT JOIN SubresourceUnderTopFrameDomains r ON o.domainID = r.subresourceDomainID
         LEFT JOIN SubresourceUniqueRedirectsTo u ON o.domainID = u.subresourceDomainID
-        WHERE isPrevalent = 1
+        WHERE isPrevalent LIKE ?
         and hadUserInteraction LIKE ?
         GROUP BY domainID) ORDER BY sum DESC
         )query";
@@ -778,15 +786,60 @@
     return SQLiteStatement(database, makeString("SELECT mostRecentUserInteractionTime FROM ObservedDomains INNER JOIN (SELECT ", joinSubStatisticsForSorting(), ") as q ON ObservedDomains.domainID = q.domainID LIMIT 1 OFFSET ?"));
 }
 
+Vector<ThirdPartyDataForSpecificFirstParty> ResourceLoadStatisticsDatabaseStore::getThirdPartyDataForSpecificFirstPartyDomains(unsigned thirdPartyDomainID, const RegistrableDomain& thirdPartyDomain) const
+{
+    if (m_getAllSubStatisticsStatement.bindInt(1, thirdPartyDomainID) != SQLITE_OK
+        || m_getAllSubStatisticsStatement.bindInt(2, thirdPartyDomainID) != SQLITE_OK
+        || m_getAllSubStatisticsStatement.bindInt(3, thirdPartyDomainID) != SQLITE_OK) {
+        RELEASE_LOG_ERROR(Network, "ResourceLoadStatisticsDatabaseStore::getThirdPartyDataForSpecificFirstPartyDomain, error message: %{public}s", m_database.lastErrorMsg());
+        ASSERT_NOT_REACHED();
+    }
+    Vector<ThirdPartyDataForSpecificFirstParty> thirdPartyDataForSpecificFirstPartyDomains;
+    while (m_getAllSubStatisticsStatement.step() == SQLITE_ROW) {
+        RegistrableDomain firstPartyDomain = RegistrableDomain::uncheckedCreateFromRegistrableDomainString(getDomainStringFromDomainID(m_getAllSubStatisticsStatement.getColumnInt(0)));
+        thirdPartyDataForSpecificFirstPartyDomains.appendIfNotContains(ThirdPartyDataForSpecificFirstParty { firstPartyDomain, hasStorageAccess(firstPartyDomain, thirdPartyDomain) });
+    }
+    resetStatement(m_getAllSubStatisticsStatement);
+    return thirdPartyDataForSpecificFirstPartyDomains;
+}
+
+static bool hasBeenThirdParty(unsigned timesUnderFirstParty)
+{
+    return timesUnderFirstParty > 0;
+}
+
+Vector<ThirdPartyData> ResourceLoadStatisticsDatabaseStore::aggregatedThirdPartyData() const
+{
+    ASSERT(!RunLoop::isMain());
+
+    Vector<ThirdPartyData> thirdPartyDataList;
+    SQLiteStatement sortedStatistics(m_database, makeString("SELECT ", joinSubStatisticsForSorting()));
+    if (sortedStatistics.prepare() != SQLITE_OK
+        || sortedStatistics.bindText(1, "%")
+        || sortedStatistics.bindText(2, "%") != SQLITE_OK) {
+        RELEASE_LOG_ERROR(Network, "ResourceLoadStatisticsDatabaseStore::aggregatedThirdPartyData, error message: %{public}s", m_database.lastErrorMsg());
+        ASSERT_NOT_REACHED();
+        return thirdPartyDataList;
+    }
+    while (sortedStatistics.step() == SQLITE_ROW) {
+        if (hasBeenThirdParty(sortedStatistics.getColumnInt(1))) {
+            auto thirdPartyDomainID = sortedStatistics.getColumnInt(0);
+            auto thirdPartyDomain = RegistrableDomain::uncheckedCreateFromRegistrableDomainString(getDomainStringFromDomainID(thirdPartyDomainID));
+            thirdPartyDataList.append(ThirdPartyData { thirdPartyDomain, getThirdPartyDataForSpecificFirstPartyDomains(thirdPartyDomainID, thirdPartyDomain) });
+        }
+    }
+    return thirdPartyDataList;
+}
+
 static std::pair<StringView, StringView> buildQueryStartAndEnd(PrevalentResourceDatabaseTelemetry::Statistic statistic)
 {
     switch (statistic) {
     case PrevalentResourceDatabaseTelemetry::Statistic::MedianSubFrameWithoutUI:
-        return std::make_pair("SELECT cnt1 FROM ObservedDomains o INNER JOIN(SELECT cnt1, ", ") as q ON o.domainID = q.domainID LIMIT 1 OFFSET ?");
+        return std::make_pair("SELECT countSubFrameUnderTopFrame FROM ObservedDomains o INNER JOIN(SELECT countSubFrameUnderTopFrame, ", ") as q ON o.domainID = q.domainID LIMIT 1 OFFSET ?");
     case PrevalentResourceDatabaseTelemetry::Statistic::MedianSubResourceWithoutUI:
-        return std::make_pair("SELECT cnt2 FROM ObservedDomains o INNER JOIN(SELECT cnt2, ", ") as q ON o.domainID = q.domainID LIMIT 1 OFFSET ?");
+        return std::make_pair("SELECT countSubResourceUnderTopFrame FROM ObservedDomains o INNER JOIN(SELECT countSubResourceUnderTopFrame, ", ") as q ON o.domainID = q.domainID LIMIT 1 OFFSET ?");
     case PrevalentResourceDatabaseTelemetry::Statistic::MedianUniqueRedirectsWithoutUI:
-        return std::make_pair("SELECT cnt3 FROM ObservedDomains o INNER JOIN(SELECT cnt3, ", ") as q ON o.domainID = q.domainID LIMIT 1 OFFSET ?");
+        return std::make_pair("SELECT countUniqueRedirectTo FROM ObservedDomains o INNER JOIN(SELECT countUniqueRedirectTo, ", ") as q ON o.domainID = q.domainID LIMIT 1 OFFSET ?");
     case PrevalentResourceDatabaseTelemetry::Statistic::MedianDataRecordsRemovedWithoutUI:
         return std::make_pair("SELECT dataRecordsRemoved FROM (SELECT * FROM ObservedDomains o INNER JOIN(SELECT ", ") as q ON o.domainID = q.domainID) LIMIT 1 OFFSET ?");
     case PrevalentResourceDatabaseTelemetry::Statistic::MedianTimesAccessedDueToUserInteractionWithoutUI:
@@ -818,7 +871,7 @@
     }
 
     // Bind
-    if (medianDaysSinceUIStatement.bindInt(1, 1) != SQLITE_OK || medianDaysSinceUIStatement.bindInt(2, (prevalentResourcesWithUserInteractionCount / 2) != SQLITE_OK)) {
+    if (medianDaysSinceUIStatement.bindInt(1, 1) != SQLITE_OK || medianDaysSinceUIStatement.bindInt(2, 1) != SQLITE_OK || medianDaysSinceUIStatement.bindInt(3, (prevalentResourcesWithUserInteractionCount / 2) != SQLITE_OK)) {
         RELEASE_LOG_ERROR(Network, "ResourceLoadStatisticsDatabaseStore::getMedianOfPrevalentResourcesWithUserInteraction, error message: %{public}s", database.lastErrorMsg());
         ASSERT_NOT_REACHED();
         return 0;
@@ -847,7 +900,7 @@
     }
 
     // Bind
-    if (lowerMedianDaysSinceUIStatement.bindInt(1, 1) != SQLITE_OK || lowerMedianDaysSinceUIStatement.bindInt(2, ((prevalentResourcesWithUserInteractionCount - 1) / 2)) != SQLITE_OK) {
+    if (lowerMedianDaysSinceUIStatement.bindInt(1, 1) != SQLITE_OK || lowerMedianDaysSinceUIStatement.bindInt(2, 1) != SQLITE_OK || lowerMedianDaysSinceUIStatement.bindInt(3, ((prevalentResourcesWithUserInteractionCount - 1) / 2)) != SQLITE_OK) {
         RELEASE_LOG_ERROR(Network, "ResourceLoadStatisticsDatabaseStore::getMedianOfPrevalentResourcesWithUserInteraction, error message: %{public}s", database.lastErrorMsg());
         ASSERT_NOT_REACHED();
         return 0;
@@ -900,7 +953,8 @@
     }
     
     // Bind
-    if (topPrevalentResourceWithUserInteractionDaysSinceUserInteractionStatement.bindInt(1, 1) != SQLITE_OK) {
+    if (topPrevalentResourceWithUserInteractionDaysSinceUserInteractionStatement.bindInt(1, 1) != SQLITE_OK
+        || topPrevalentResourceWithUserInteractionDaysSinceUserInteractionStatement.bindInt(2, 1) != SQLITE_OK) {
         RELEASE_LOG_ERROR(Network, "ResourceLoadStatisticsDatabaseStore::topPrevalentResourceWithUserInteractionDaysSinceUserInteractionStatement query failed to bind, error message: %{public}s", m_database.lastErrorMsg());
         ASSERT_NOT_REACHED();
         return 0;
@@ -927,8 +981,9 @@
     SQLiteStatement getMedianStatistic = makeMedianWithoutUIQuery(database, statistic);
 
     if (getMedianStatistic.prepare() == SQLITE_OK) {
-        if (getMedianStatistic.bindInt(1, 0) != SQLITE_OK
-            || getMedianStatistic.bindInt(2, (bucketSize / 2)) != SQLITE_OK) {
+        if (getMedianStatistic.bindInt(1, 1) != SQLITE_OK
+            || getMedianStatistic.bindInt(2, 0) != SQLITE_OK
+            || getMedianStatistic.bindInt(3, (bucketSize / 2)) != SQLITE_OK) {
             RELEASE_LOG_ERROR(Network, "ResourceLoadStatisticsDatabaseStore::makeMedianWithoutUIQuery, error message: %{public}s", database.lastErrorMsg());
             ASSERT_NOT_REACHED();
             return 0;
@@ -943,7 +998,8 @@
     SQLiteStatement getLowerMedianStatistic = makeMedianWithoutUIQuery(database, statistic);
 
     if (getLowerMedianStatistic.prepare() == SQLITE_OK) {
-        if (getLowerMedianStatistic.bindInt(1, 0) != SQLITE_OK
+        if (getLowerMedianStatistic.bindInt(1, 1) != SQLITE_OK
+            || getLowerMedianStatistic.bindInt(2, 0) != SQLITE_OK
             || getLowerMedianStatistic.bindInt(2, ((bucketSize-1) / 2)) != SQLITE_OK) {
             RELEASE_LOG_ERROR(Network, "ResourceLoadStatisticsDatabaseStore::makeMedianWithoutUIQuery, error message: %{public}s", database.lastErrorMsg());
             ASSERT_NOT_REACHED();
@@ -961,8 +1017,9 @@
     SQLiteStatement prevalentResourceCountInTop(database, makeString("SELECT COUNT(*) FROM (SELECT * FROM ObservedDomains o INNER JOIN(SELECT ", joinSubStatisticsForSorting(), ") as q on q.domainID = o.domainID LIMIT ?) as p WHERE p.hadUserInteraction = 1;"));
 
     if (prevalentResourceCountInTop.prepare() == SQLITE_OK) {
-        if (prevalentResourceCountInTop.bindText(1, "%") != SQLITE_OK
-            || prevalentResourceCountInTop.bindInt(2, bucketSize) != SQLITE_OK) {
+        if (prevalentResourceCountInTop.bindInt(1, 1) != SQLITE_OK
+            || prevalentResourceCountInTop.bindText(2, "%") != SQLITE_OK
+            || prevalentResourceCountInTop.bindInt(3, bucketSize) != SQLITE_OK) {
             RELEASE_LOG_ERROR(Network, "ResourceLoadStatisticsDatabaseStore::getNumberOfPrevalentResourcesInTopResources, error message: %{public}s", database.lastErrorMsg());
             ASSERT_NOT_REACHED();
             return 0;
@@ -1251,6 +1308,11 @@
     m_database.runVacuumCommand();
 }
 
+bool ResourceLoadStatisticsDatabaseStore::hasStorageAccess(const TopFrameDomain& topFrameDomain, const SubFrameDomain& subFrameDomain) const
+{
+    return relationshipExists(m_storageAccessExistsStatement, domainID(subFrameDomain), topFrameDomain);
+}
+
 void ResourceLoadStatisticsDatabaseStore::hasStorageAccess(const SubFrameDomain& subFrameDomain, const TopFrameDomain& topFrameDomain, Optional<FrameIdentifier> frameID, PageIdentifier pageID, CompletionHandler<void(bool)>&& completionHandler)
 {
     ASSERT(!RunLoop::isMain());
@@ -1618,7 +1680,15 @@
     result.appendLiteral("Resource load statistics:\n\n");
     while (m_getAllDomainsStatement.step() == SQLITE_ROW)
         resourceToString(result, m_getAllDomainsStatement.getColumnText(0));
-    
+
+    auto thirdPartyData = aggregatedThirdPartyData();
+    if (!thirdPartyData.isEmpty()) {
+        result.append("\nITP Data:\n");
+        for (auto thirdParty : thirdPartyData) {
+            result.append(thirdParty.toString());
+            result.append('\n');
+        }
+    }
     resetStatement(m_getAllDomainsStatement);
     completionHandler(result.toString());
 }
@@ -2350,6 +2420,11 @@
     }
 }
 
+static bool hasHadRecentUserInteraction(WTF::Seconds interactionTimeSeconds)
+{
+    return interactionTimeSeconds > Seconds(0) && WallTime::now().secondsSinceEpoch() - interactionTimeSeconds < 24_h;
+}
+
 void ResourceLoadStatisticsDatabaseStore::resourceToString(StringBuilder& builder, const String& domain) const
 {
     if (m_getResourceDataByDomainNameStatement.bindText(1, domain) != SQLITE_OK
@@ -2367,7 +2442,10 @@
     appendBoolean(builder, "hadUserInteraction", m_getResourceDataByDomainNameStatement.getColumnInt(HadUserInteractionIndex));
     builder.append('\n');
     builder.appendLiteral("    mostRecentUserInteraction: ");
-    builder.appendFixedPrecisionNumber(m_getResourceDataByDomainNameStatement.getColumnDouble(MostRecentUserInteractionTimeIndex));
+    if (hasHadRecentUserInteraction(Seconds(m_getResourceDataByDomainNameStatement.getColumnDouble(MostRecentUserInteractionTimeIndex))))
+        builder.appendLiteral("within 24 hours");
+    else
+        builder.appendLiteral("-1");
     builder.append('\n');
     appendBoolean(builder, "grandfathered", m_getResourceDataByDomainNameStatement.getColumnInt(GrandfatheredIndex));
     builder.append('\n');

Modified: trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h (253117 => 253118)


--- trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h	2019-12-04 19:02:37 UTC (rev 253117)
+++ trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h	2019-12-04 20:06:26 UTC (rev 253118)
@@ -85,6 +85,7 @@
     void clear(CompletionHandler<void()>&&) override;
     bool isEmpty() const override;
 
+    Vector<ThirdPartyData> aggregatedThirdPartyData() const override;
     void updateCookieBlocking(CompletionHandler<void()>&&) override;
 
     void classifyPrevalentResources() override;
@@ -137,6 +138,8 @@
 private:
     void openITPDatabase();
     bool isCorrectTableSchema();
+    bool hasStorageAccess(const TopFrameDomain&, const SubFrameDomain&) const;
+    Vector<ThirdPartyDataForSpecificFirstParty> getThirdPartyDataForSpecificFirstPartyDomains(unsigned, const RegistrableDomain&) const;
     void openAndDropOldDatabaseIfNecessary();
     String getDomainStringFromDomainID(unsigned) const;
     String getSubStatisticStatement(const String&) const;
@@ -248,6 +251,8 @@
     mutable WebCore::SQLiteStatement m_getResourceDataByDomainNameStatement;
     mutable WebCore::SQLiteStatement m_getAllDomainsStatement;
     mutable WebCore::SQLiteStatement m_domainStringFromDomainIDStatement;
+    mutable WebCore::SQLiteStatement m_getAllSubStatisticsStatement;
+    mutable WebCore::SQLiteStatement m_storageAccessExistsStatement;
     PAL::SessionID m_sessionID;
 };
 

Modified: trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsMemoryStore.cpp (253117 => 253118)


--- trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsMemoryStore.cpp	2019-12-04 19:02:37 UTC (rev 253117)
+++ trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsMemoryStore.cpp	2019-12-04 20:06:26 UTC (rev 253118)
@@ -103,6 +103,46 @@
         WebResourceLoadStatisticsTelemetry::calculateAndSubmit(*this);
 }
 
+static void ensureThirdPartyDataForSpecificFirstPartyDomain(Vector<ThirdPartyDataForSpecificFirstParty>& thirdPartyDataForSpecificFirstPartyDomain, const RegistrableDomain& firstPartyDomain, bool thirdPartyHasStorageAccess)
+{
+    ThirdPartyDataForSpecificFirstParty thirdPartyDataForSpecificFirstParty { firstPartyDomain, thirdPartyHasStorageAccess };
+    thirdPartyDataForSpecificFirstPartyDomain.appendIfNotContains(thirdPartyDataForSpecificFirstParty);
+}
+
+static Vector<ThirdPartyDataForSpecificFirstParty> getThirdPartyDataForSpecificFirstPartyDomains(const ResourceLoadStatistics& thirdPartyStatistic)
+{
+    Vector<ThirdPartyDataForSpecificFirstParty> thirdPartyDataForSpecificFirstPartyDomains;
+
+    for (auto firstPartyDomain : thirdPartyStatistic.subframeUnderTopFrameDomains)
+        ensureThirdPartyDataForSpecificFirstPartyDomain(thirdPartyDataForSpecificFirstPartyDomains, firstPartyDomain, thirdPartyStatistic.storageAccessUnderTopFrameDomains.contains(firstPartyDomain));
+    for (auto firstPartyDomain : thirdPartyStatistic.subresourceUnderTopFrameDomains)
+        ensureThirdPartyDataForSpecificFirstPartyDomain(thirdPartyDataForSpecificFirstPartyDomains, firstPartyDomain, thirdPartyStatistic.storageAccessUnderTopFrameDomains.contains(firstPartyDomain));
+    for (auto firstPartyDomain : thirdPartyStatistic.subresourceUniqueRedirectsTo)
+        ensureThirdPartyDataForSpecificFirstPartyDomain(thirdPartyDataForSpecificFirstPartyDomains, firstPartyDomain, thirdPartyStatistic.storageAccessUnderTopFrameDomains.contains(firstPartyDomain));
+
+    return thirdPartyDataForSpecificFirstPartyDomains;
+}
+
+static bool hasBeenThirdParty(const ResourceLoadStatistics& statistic)
+{
+    return !statistic.subframeUnderTopFrameDomains.isEmpty()
+        || !statistic.subresourceUnderTopFrameDomains.isEmpty()
+        || !statistic.subresourceUniqueRedirectsTo.isEmpty();
+}
+
+Vector<ThirdPartyData> ResourceLoadStatisticsMemoryStore::aggregatedThirdPartyData() const
+{
+    ASSERT(!RunLoop::isMain());
+
+    Vector<ThirdPartyData> thirdPartyDataList;
+    for (auto& statistic : m_resourceStatisticsMap.values()) {
+        if (hasBeenThirdParty(statistic))
+            thirdPartyDataList.append(ThirdPartyData { statistic.registrableDomain, getThirdPartyDataForSpecificFirstPartyDomains(statistic) });
+    }
+    std::sort(thirdPartyDataList.rbegin(), thirdPartyDataList.rend());
+    return thirdPartyDataList;
+}
+
 void ResourceLoadStatisticsMemoryStore::incrementRecordsDeletedCountForDomains(HashSet<RegistrableDomain>&& domainsWithDeletedWebsiteData)
 {
     ASSERT(!RunLoop::isMain());
@@ -510,6 +550,15 @@
     result.appendLiteral("Resource load statistics:\n\n");
     for (auto& mapEntry : m_resourceStatisticsMap.values())
         result.append(mapEntry.toString());
+
+    auto thirdPartyData = aggregatedThirdPartyData();
+    if (!thirdPartyData.isEmpty()) {
+        result.append("\nITP Data:\n");
+        for (auto thirdParty : thirdPartyData) {
+            result.append(thirdParty.toString());
+            result.append('\n');
+        }
+    }
     completionHandler(result.toString());
 }
 

Modified: trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsMemoryStore.h (253117 => 253118)


--- trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsMemoryStore.h	2019-12-04 19:02:37 UTC (rev 253117)
+++ trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsMemoryStore.h	2019-12-04 20:06:26 UTC (rev 253118)
@@ -56,6 +56,7 @@
     void clear(CompletionHandler<void()>&&) override;
     bool isEmpty() const override;
 
+    Vector<ThirdPartyData> aggregatedThirdPartyData() const override;
     const HashMap<RegistrableDomain, WebCore::ResourceLoadStatistics>& data() const { return m_resourceStatisticsMap; }
 
     std::unique_ptr<WebCore::KeyedEncoder> createEncoderFromData() const;

Modified: trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsStore.h (253117 => 253118)


--- trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsStore.h	2019-12-04 19:02:37 UTC (rev 253117)
+++ trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsStore.h	2019-12-04 20:06:26 UTC (rev 253118)
@@ -98,6 +98,7 @@
 
     virtual void clear(CompletionHandler<void()>&&) = 0;
     virtual bool isEmpty() const = 0;
+    virtual Vector<ThirdPartyData> aggregatedThirdPartyData() const = 0;
 
     virtual void updateCookieBlocking(CompletionHandler<void()>&&) = 0;
     void updateCookieBlockingForDomains(const RegistrableDomainsToBlockCookiesFor&, CompletionHandler<void()>&&);

Modified: trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp (253117 => 253118)


--- trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp	2019-12-04 19:02:37 UTC (rev 253117)
+++ trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp	2019-12-04 20:06:26 UTC (rev 253118)
@@ -1149,6 +1149,11 @@
         const_cast<WebResourceLoadStatisticsStore*>(this)->networkSession()->notifyPageStatisticsTelemetryFinished(numberOfPrevalentResources, numberOfPrevalentResourcesWithUserInteraction, numberOfPrevalentResourcesWithoutUserInteraction, topPrevalentResourceWithUserInteractionDaysSinceUserInteraction, medianDaysSinceUserInteractionPrevalentResourceWithUserInteraction, top3NumberOfPrevalentResourcesWithUI, top3MedianSubFrameWithoutUI, top3MedianSubResourceWithoutUI, top3MedianUniqueRedirectsWithoutUI, top3MedianDataRecordsRemovedWithoutUI);
 }
 
+Vector<ThirdPartyData> WebResourceLoadStatisticsStore::aggregatedThirdPartyData()
+{
+    return m_statisticsStore->aggregatedThirdPartyData();
+}
+
 } // namespace WebKit
 
 #endif

Modified: trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h (253117 => 253118)


--- trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h	2019-12-04 19:02:37 UTC (rev 253117)
+++ trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h	2019-12-04 20:06:26 UTC (rev 253118)
@@ -78,6 +78,46 @@
     RegistrableDomainsToBlockCookiesFor isolatedCopy() const { return { domainsToBlockAndDeleteCookiesFor.isolatedCopy(), domainsToBlockButKeepCookiesFor.isolatedCopy(), domainsWithUserInteractionAsFirstParty.isolatedCopy() }; }
 };
 
+struct ThirdPartyDataForSpecificFirstParty {
+    WebCore::RegistrableDomain firstPartyDomain;
+    bool storageAccessGranted;
+
+    String toString() const
+    {
+        return makeString("Has been granted storage access under ", firstPartyDomain.string(), ": ", storageAccessGranted);
+    }
+
+    bool operator==(ThirdPartyDataForSpecificFirstParty const other) const
+    {
+        return firstPartyDomain == other.firstPartyDomain && storageAccessGranted == other.storageAccessGranted;
+    }
+};
+
+struct ThirdPartyData {
+    WebCore::RegistrableDomain thirdPartyDomain;
+    Vector<ThirdPartyDataForSpecificFirstParty> underFirstParties;
+
+    String toString() const
+    {
+        StringBuilder stringBuilder;
+        stringBuilder.append("Third Party Registrable Domain: ", thirdPartyDomain.string(), "\n");
+        stringBuilder.appendLiteral("    {");
+
+        for (auto firstParty : underFirstParties) {
+            stringBuilder.appendLiteral("{ ");
+            stringBuilder.append(firstParty.toString());
+            stringBuilder.appendLiteral(" },");
+        }
+        stringBuilder.appendLiteral("}");
+        return stringBuilder.toString();
+    }
+
+    bool operator<(const ThirdPartyData &other) const
+    {
+        return underFirstParties.size() < other.underFirstParties.size();
+    }
+};
+
 class WebResourceLoadStatisticsStore final : public ThreadSafeRefCounted<WebResourceLoadStatisticsStore, WTF::DestructionThread::Main> {
 public:
     using ResourceLoadStatistics = WebCore::ResourceLoadStatistics;
@@ -195,6 +235,7 @@
 
     void resourceLoadStatisticsUpdated(Vector<WebCore::ResourceLoadStatistics>&&);
     void requestStorageAccessUnderOpener(DomainInNeedOfStorageAccess&&, WebCore::PageIdentifier openerID, OpenerDomain&&);
+    Vector<ThirdPartyData> aggregatedThirdPartyData();
 
 private:
     explicit WebResourceLoadStatisticsStore(NetworkSession&, const String&, ShouldIncludeLocalhost);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to