Log Message
Implement dumpResourceLoadStatistics in SQLite ITP Database https://bugs.webkit.org/show_bug.cgi?id=203224 <rdar://problem/56482165>
Patch by Kate Cheney <[email protected]> on 2019-10-23 Reviewed by John Wilander. Source/WebKit: This patch implements dumpResourceLoadStatistics() in the ITP database store. This function required a boolean flag isScheduledForWebsiteDataRemoval that now must be stored in the database, resulting in a small schema change. Because of the schema change, this patch also compares any existing database file against the new schema, and deletes the existing file if the schema is not current. * NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp: The logic for topFrameLinkDecorationsFromQuery was the opposite of all other "xyzFrom" queries. When merging data from the memory store, the load statistic being inserted holds a list of topFrames which it has been redirected to from. I think it makes more sense to also organize the table this way. (WebKit::ObservedDomainsTableSchemaV1): (WebKit::ObservedDomainsTableSchemaV1Alternate): For support on both iOS and MacOS, there are two CREATE TABLE queries to compare to, depending on whether the query result contains quotes around the table name. (WebKit::ResourceLoadStatisticsDatabaseStore::ResourceLoadStatisticsDatabaseStore): (WebKit::ResourceLoadStatisticsDatabaseStore::openITPDatabase): (WebKit::ResourceLoadStatisticsDatabaseStore::openAndDropOldDatabaseIfNecessary): The code to check for the current schema was adapted from SQLiteIDBBackingStore.cpp (WebKit::ResourceLoadStatisticsDatabaseStore::prepareStatements): (WebKit::ResourceLoadStatisticsDatabaseStore::insertObservedDomain): (WebKit::ResourceLoadStatisticsDatabaseStore::ensureAndMakeDomainList): The previous naming of the list parameter in this function was confusing because it is used by many different relationships not just subframes under top frames. (WebKit::ResourceLoadStatisticsDatabaseStore::insertDomainRelationshipList): topFrameLinkDecorationsFrom were never inserted into the database. (WebKit::ResourceLoadStatisticsDatabaseStore::insertDomainRelationships): (WebKit::ResourceLoadStatisticsDatabaseStore::merge): (WebKit::ResourceLoadStatisticsDatabaseStore::mergeStatistic): Since the statement to get all data for a given domain is now used in multiple places, I stored the query as a constexpr auto. (WebKit::ResourceLoadStatisticsDatabaseStore::logCrossSiteLoadWithLinkDecoration): Matched the memory store functionality, which calls the boolean "gotLinkDecorationFromPrevalentResource." I thought isScheduledForWebsiteDataRemoval would be more clear of a name, because this flag gets cleared even when prevalent top frame link decorations for this domain still exist in the table. (WebKit::ResourceLoadStatisticsDatabaseStore::dumpResourceLoadStatistics): (WebKit::ResourceLoadStatisticsDatabaseStore::setIsScheduledForWebsiteDataRemoval): (WebKit::ResourceLoadStatisticsDatabaseStore::prevalentDomains): Deleted. (WebKit::ResourceLoadStatisticsDatabaseStore::domains): To match memory store functionality, the check for website data to delete should check all domains, not just prevalent ones. (WebKit::ResourceLoadStatisticsDatabaseStore::hasHadUnexpiredRecentUserInteraction): (WebKit::ResourceLoadStatisticsDatabaseStore::shouldRemoveAllWebsiteDataFor): This now needs to check if the resource is prevalent, because it is no longer guaranteed. (WebKit::ResourceLoadStatisticsDatabaseStore::shouldRemoveAllButCookiesFor): (WebKit::ResourceLoadStatisticsDatabaseStore::registrableDomainsToRemoveWebsiteDataFor): (WebKit::ResourceLoadStatisticsDatabaseStore::getDomainStringFromDomainID): (WebKit::ResourceLoadStatisticsDatabaseStore::getSubStatisticStatement): (WebKit::ResourceLoadStatisticsDatabaseStore::appendSubStatisticList): (WebKit::ResourceLoadStatisticsDatabaseStore::resourceToString): This functionality matches the toString function in ResourceLoadStatistics.cpp. (WebKit::CompletionHandler<void): * NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h: LayoutTests: Migrated tests from the memory store to be used to test dumping for database store. Both tests are almost identical to the memory store tests except they set the useITPDatabase flag to true and log-cross-site-load-with-link-decoration-database.html tests one additional domain to be sure that listing multiple domains in a category works in the database store. * http/tests/resourceLoadStatistics/log-cross-site-load-with-link-decoration-database-expected.txt: Added. * http/tests/resourceLoadStatistics/log-cross-site-load-with-link-decoration-database.html: Added. * http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-link-decoration-database-expected.txt: Added. * http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-link-decoration-database.html: Added.
Modified Paths
- trunk/LayoutTests/ChangeLog
- trunk/Source/WebKit/ChangeLog
- trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp
- trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h
Added Paths
- trunk/LayoutTests/http/tests/resourceLoadStatistics/log-cross-site-load-with-link-decoration-database-expected.txt
- trunk/LayoutTests/http/tests/resourceLoadStatistics/log-cross-site-load-with-link-decoration-database.html
- trunk/LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-link-decoration-database-expected.txt
- trunk/LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-link-decoration-database.html
Diff
Modified: trunk/LayoutTests/ChangeLog (251500 => 251501)
--- trunk/LayoutTests/ChangeLog 2019-10-23 21:58:17 UTC (rev 251500)
+++ trunk/LayoutTests/ChangeLog 2019-10-23 22:06:46 UTC (rev 251501)
@@ -1,3 +1,22 @@
+2019-10-23 Kate Cheney <[email protected]>
+
+ Implement dumpResourceLoadStatistics in SQLite ITP Database
+ https://bugs.webkit.org/show_bug.cgi?id=203224
+ <rdar://problem/56482165>
+
+ Reviewed by John Wilander.
+
+ Migrated tests from the memory store to be used to test dumping
+ for database store. Both tests are almost identical to the memory
+ store tests except they set the useITPDatabase flag to true and
+ log-cross-site-load-with-link-decoration-database.html tests one additional domain
+ to be sure that listing multiple domains in a category works in the database store.
+
+ * http/tests/resourceLoadStatistics/log-cross-site-load-with-link-decoration-database-expected.txt: Added.
+ * http/tests/resourceLoadStatistics/log-cross-site-load-with-link-decoration-database.html: Added.
+ * http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-link-decoration-database-expected.txt: Added.
+ * http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-link-decoration-database.html: Added.
+
2019-10-21 Jiewen Tan <[email protected]>
[WebAuthn] Warn users when multiple NFC tags present
Added: trunk/LayoutTests/http/tests/resourceLoadStatistics/log-cross-site-load-with-link-decoration-database-expected.txt (0 => 251501)
--- trunk/LayoutTests/http/tests/resourceLoadStatistics/log-cross-site-load-with-link-decoration-database-expected.txt (rev 0)
+++ trunk/LayoutTests/http/tests/resourceLoadStatistics/log-cross-site-load-with-link-decoration-database-expected.txt 2019-10-23 22:06:46 UTC (rev 251501)
@@ -0,0 +1,31 @@
+Test logging of link decorated cross-site navigations from a prevalent resource.
+
+Resource load statistics:
+
+Registrable domain: 127.0.0.1
+ lastSeen: 0
+ hadUserInteraction: No
+ mostRecentUserInteraction: -1
+ grandfathered: No
+ IsScheduledForAllButCookieDataRemoval: No isPrevalentResource: Yes
+ isVeryPrevalentResource: No
+ dataRecordsRemoved: 0
+Registrable domain: 127.0.0.2
+ lastSeen: 0
+ hadUserInteraction: No
+ mostRecentUserInteraction: -1
+ grandfathered: No
+ IsScheduledForAllButCookieDataRemoval: No isPrevalentResource: No
+ isVeryPrevalentResource: No
+ dataRecordsRemoved: 0
+Registrable domain: localhost
+ lastSeen: 0
+ hadUserInteraction: No
+ mostRecentUserInteraction: -1
+ grandfathered: No
+ TopFrameLinkDecorationsFrom:
+ 127.0.0.1
+ 127.0.0.2
+ IsScheduledForAllButCookieDataRemoval: Yes isPrevalentResource: No
+ isVeryPrevalentResource: No
+ dataRecordsRemoved: 0
Added: trunk/LayoutTests/http/tests/resourceLoadStatistics/log-cross-site-load-with-link-decoration-database.html (0 => 251501)
--- trunk/LayoutTests/http/tests/resourceLoadStatistics/log-cross-site-load-with-link-decoration-database.html (rev 0)
+++ trunk/LayoutTests/http/tests/resourceLoadStatistics/log-cross-site-load-with-link-decoration-database.html 2019-10-23 22:06:46 UTC (rev 251501)
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src=""
+</head>
+<body _onload_="setTimeout('runTest()', 0)">
+<div id="description">Test logging of link decorated cross-site navigations from a prevalent resource.</div>
+<div id="output"></div>
+<script>
+ if (window.testRunner) {
+ testRunner.setUseITPDatabase(true);
+ testRunner.waitUntilDone();
+ testRunner.dumpAsText();
+ }
+
+ function navigateCrossOrigin() {
+ document.location.href = "" + "/resourceLoadStatistics/log-cross-site-load-with-link-decoration-database.html?link=decoration";
+ }
+
+ const destinationOrigin = "http://localhost:8000";
+ const prevalentResourceOrigin = "http://127.0.0.1:8000";
+ const testOrigin = "http://127.0.0.2:8000";
+ function runTest() {
+ if (document.location.origin === prevalentResourceOrigin) {
+ setEnableFeature(true, function () {
+ testRunner.setStatisticsPrevalentResource(prevalentResourceOrigin, true, function() {
+ if (!testRunner.isStatisticsPrevalentResource(prevalentResourceOrigin))
+ testFailed("Host did not get set as prevalent resource.");
+ testRunner.setStatisticsCrossSiteLoadWithLinkDecoration(testOrigin, destinationOrigin);
+ testRunner.statisticsUpdateCookieBlocking(navigateCrossOrigin);
+ });
+
+ });
+ } else {
+ testRunner.dumpResourceLoadStatistics();
+ setEnableFeature(false, function () {
+ testRunner.notifyDone();
+ });
+ }
+ }
+</script>
+</body>
+</html>
Added: trunk/LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-link-decoration-database-expected.txt (0 => 251501)
--- trunk/LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-link-decoration-database-expected.txt (rev 0)
+++ trunk/LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-link-decoration-database-expected.txt 2019-10-23 22:06:46 UTC (rev 251501)
@@ -0,0 +1,35 @@
+Check that non-cookie website data gets removed after a navigation with link decoration from a prevalent resource.
+
+Before deletion: Client-side cookie exists.
+Before deletion: HttpOnly cookie exists.
+Before deletion: Regular server-side cookie exists.
+Before deletion: LocalStorage entry does exist.
+Before deletion: IDB entry does exist.
+
+After deletion: HttpOnly cookie exists.
+After deletion: Client-side cookie exists.
+After deletion: Regular server-side cookie exists.
+After deletion: LocalStorage entry does not exist.
+After deletion: IDB entry does not exist.
+
+
+Resource load statistics:
+
+Registrable domain: 127.0.0.1
+ lastSeen: 0
+ hadUserInteraction: No
+ mostRecentUserInteraction: -1
+ grandfathered: No
+ TopFrameLinkDecorationsFrom:
+ localhost
+ IsScheduledForAllButCookieDataRemoval: No isPrevalentResource: No
+ isVeryPrevalentResource: No
+ dataRecordsRemoved: 1
+Registrable domain: localhost
+ lastSeen: 0
+ hadUserInteraction: No
+ mostRecentUserInteraction: -1
+ grandfathered: No
+ IsScheduledForAllButCookieDataRemoval: No isPrevalentResource: Yes
+ isVeryPrevalentResource: No
+ dataRecordsRemoved: 0
Added: trunk/LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-link-decoration-database.html (0 => 251501)
--- trunk/LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-link-decoration-database.html (rev 0)
+++ trunk/LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-link-decoration-database.html 2019-10-23 22:06:46 UTC (rev 251501)
@@ -0,0 +1,247 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src=""
+ <script src=""
+</head>
+<body _onload_="setTimeout('runTest()', 0)">
+<div id="description">Check that non-cookie website data gets removed after a navigation with link decoration from a prevalent resource.</div>
+<br>
+<div id="output"></div>
+<br>
+<script>
+ testRunner.setUseITPDatabase(true);
+ testRunner.waitUntilDone();
+ testRunner.dumpAsText();
+
+ const httpOnlyCookieName = "http-only-cookie";
+ const serverSideCookieName = "server-side-cookie";
+ const clientSideCookieName = "client-side-cookie";
+
+ function sortStringArray(a, b) {
+ a = a.toLowerCase();
+ b = b.toLowerCase();
+
+ return a > b ? 1 : b > a ? -1 : 0;
+ }
+
+ function addLinebreakToOutput() {
+ let element = document.createElement("br");
+ output.appendChild(element);
+ }
+
+ function addOutput(message) {
+ let element = document.createElement("div");
+ element.innerText = message;
+ output.appendChild(element);
+ }
+
+ function checkCookies(isAfterDeletion) {
+ let unsortedTestPassedMessages = [];
+ let cookies = internals.getCookies();
+ if (!cookies.length)
+ testFailed((isAfterDeletion ? "After" : "Before") + " script-accessible deletion: No cookies found.");
+ for (let cookie of cookies) {
+ switch (cookie.name) {
+ case httpOnlyCookieName:
+ unsortedTestPassedMessages.push((isAfterDeletion ? "After" : "Before") + " deletion: " + (isAfterDeletion ? " " : "") + "HttpOnly cookie exists.");
+ break;
+ case serverSideCookieName:
+ unsortedTestPassedMessages.push((isAfterDeletion ? "After" : "Before") + " deletion: Regular server-side cookie exists.");
+ break;
+ case clientSideCookieName:
+ unsortedTestPassedMessages.push((isAfterDeletion ? "After" : "Before") + " deletion: Client-side cookie exists.");
+ break;
+ }
+ }
+ let sortedTestPassedMessages = unsortedTestPassedMessages.sort(sortStringArray);
+ for (let testPassedMessage of sortedTestPassedMessages) {
+ addOutput(testPassedMessage);
+ }
+ }
+
+ const dbName = "TestDatabase";
+
+ function createIDBDataStore(callback) {
+ let request = indexedDB.open(dbName);
+ request._onerror_ = function() {
+ addOutput("Couldn't create indexedDB.");
+ finishTest();
+ };
+ request._onupgradeneeded_ = function(event) {
+ let db = event.target.result;
+ let objStore = db.createObjectStore("test", {autoIncrement: true});
+ objStore.add("value");
+ callback();
+ }
+ }
+
+ const maxIntervals = 20;
+
+ let intervalCounterIDB;
+ let checkIDBCallback;
+ let checkIDBIntervalID;
+ let semaphoreIDBCheck = false;
+ function checkIDBDataStoreExists(isAfterDeletion, callback) {
+ let request;
+ intervalCounterIDB = 0;
+ checkIDBCallback = callback;
+ if (!isAfterDeletion) {
+ // Check until there is a IDB.
+ checkIDBIntervalID = setInterval(function() {
+ if (semaphoreIDBCheck)
+ return;
+ semaphoreIDBCheck = true;
+
+ if (++intervalCounterIDB >= maxIntervals) {
+ clearInterval(checkIDBIntervalID);
+ addOutput("Before deletion: IDB entry does not exist.");
+ semaphoreIDBCheck = false;
+ checkIDBCallback();
+ } else {
+ request = indexedDB.open(dbName);
+ request._onerror_ = function () {
+ clearInterval(checkIDBIntervalID);
+ addOutput("Couldn't open indexedDB.");
+ semaphoreIDBCheck = false;
+ finishTest();
+ };
+ request._onupgradeneeded_ = function () {
+ // Let the next interval check again.
+ semaphoreIDBCheck = false;
+ };
+ request._onsuccess_ = function () {
+ clearInterval(checkIDBIntervalID);
+ addOutput("Before deletion: IDB entry does exist.");
+ semaphoreIDBCheck = false;
+ checkIDBCallback();
+ };
+ }
+ }, 200);
+ } else {
+ // Check until there is no IDB.
+ checkIDBIntervalID = setInterval(function () {
+ if (semaphoreIDBCheck)
+ return;
+ semaphoreIDBCheck = true;
+
+ if (++intervalCounterIDB >= maxIntervals) {
+ clearInterval(checkIDBIntervalID);
+ addOutput("Before deletion: IDB entry does not exist.");
+ semaphoreIDBCheck = false;
+ checkIDBCallback();
+ } else {
+ request = indexedDB.open(dbName);
+ request._onerror_ = function () {
+ clearInterval(checkIDBIntervalID);
+ addOutput("Couldn't open indexedDB.");
+ semaphoreIDBCheck = false;
+ finishTest();
+ };
+ request._onupgradeneeded_ = function () {
+ clearInterval(checkIDBIntervalID);
+ addOutput("After deletion: IDB entry does not exist.");
+ semaphoreIDBCheck = false;
+ checkIDBCallback();
+ };
+ request._onsuccess_ = function () {
+ // Let the next interval check again.
+ semaphoreIDBCheck = false;
+ };
+ }
+ }, 200);
+ }
+ }
+
+ let intervalCounterLocalStorage;
+ let checkLocalStorageCallback;
+ let checkLocalStorageIntervalID;
+ const localStorageName = "test";
+ const localStorageValue = "value";
+ function checkLocalStorageExists(isAfterDeletion, callback) {
+ intervalCounterLocalStorage = 0;
+ checkLocalStorageCallback = callback;
+ if (!isAfterDeletion) {
+ // Check until there is LocalStorage.
+ checkLocalStorageIntervalID = setInterval(function() {
+ if (++intervalCounterLocalStorage >= maxIntervals) {
+ clearInterval(checkLocalStorageIntervalID);
+ checkLocalStorageCallback();
+ } else if (testRunner.isStatisticsHasLocalStorage(destinationOrigin)) {
+ clearInterval(checkLocalStorageIntervalID);
+ let value = localStorage.getItem(localStorageName);
+ addOutput("Before deletion: LocalStorage entry " + (value === localStorageValue ? "does" : "does not") + " exist.");
+ checkLocalStorageCallback();
+ }
+ }, 100);
+ } else {
+ // Check until there is no LocalStorage.
+ checkLocalStorageIntervalID = setInterval(function() {
+ if (++intervalCounterLocalStorage >= maxIntervals) {
+ clearInterval(checkLocalStorageIntervalID);
+ checkLocalStorageCallback();
+ } else if (!testRunner.isStatisticsHasLocalStorage(destinationOrigin)) {
+ clearInterval(checkLocalStorageIntervalID);
+ let value = localStorage.getItem(localStorageName);
+ addOutput("After deletion: LocalStorage entry " + (value === localStorageValue ? "does" : "does not") + " exist.");
+ checkLocalStorageCallback();
+ }
+ }, 100);
+ }
+ }
+
+ async function writeWebsiteDataAndContinue() {
+ // Write cookies.
+ await fetch("/cookies/resources/set-http-only-cookie.php?cookieName=" + httpOnlyCookieName, { credentials: "same-origin" });
+ await fetch("/cookies/resources/setCookies.cgi", { headers: { "Set-Cookie": serverSideCookieName + "=1; path=/;" }, credentials: "same-origin" });
+ document.cookie = clientSideCookieName + "=1";
+
+ checkCookies(false);
+
+ // Write LocalStorage
+ localStorage.setItem(localStorageName, localStorageValue);
+ checkLocalStorageExists(false, function() {
+
+ // Write IndexedDB.
+ createIDBDataStore(function () {
+ checkIDBDataStoreExists(false, function() {
+ addLinebreakToOutput();
+ processWebsiteDataAndContinue();
+ });
+ });
+ });
+ }
+
+ function processWebsiteDataAndContinue() {
+ testRunner.installStatisticsDidScanDataRecordsCallback(checkWebsiteDataAndContinue);
+ testRunner.statisticsProcessStatisticsAndDataRecords();
+ }
+
+ function checkWebsiteDataAndContinue() {
+ checkCookies(true);
+ checkLocalStorageExists(true, function () {
+ checkIDBDataStoreExists(true, finishTest);
+ });
+ }
+
+ function finishTest() {
+ resetCookies();
+ testRunner.dumpResourceLoadStatistics();
+ setEnableFeature(false, function() {
+ testRunner.notifyDone();
+ });
+ }
+
+ const prevalentResourceOrigin = "http://localhost:8000";
+ const destinationOrigin = "http://127.0.0.1:8000";
+ function runTest() {
+ setEnableFeature(true, function () {
+ testRunner.setStatisticsPrevalentResource(prevalentResourceOrigin, true, function() {
+ testRunner.setStatisticsCrossSiteLoadWithLinkDecoration(prevalentResourceOrigin, destinationOrigin);
+ writeWebsiteDataAndContinue();
+ });
+ });
+ }
+</script>
+</body>
+</html>
Modified: trunk/Source/WebKit/ChangeLog (251500 => 251501)
--- trunk/Source/WebKit/ChangeLog 2019-10-23 21:58:17 UTC (rev 251500)
+++ trunk/Source/WebKit/ChangeLog 2019-10-23 22:06:46 UTC (rev 251501)
@@ -1,3 +1,83 @@
+2019-10-23 Kate Cheney <[email protected]>
+
+ Implement dumpResourceLoadStatistics in SQLite ITP Database
+ https://bugs.webkit.org/show_bug.cgi?id=203224
+ <rdar://problem/56482165>
+
+ Reviewed by John Wilander.
+
+ This patch implements dumpResourceLoadStatistics() in the ITP database
+ store. This function required a boolean flag isScheduledForWebsiteDataRemoval that
+ now must be stored in the database, resulting in a small schema change.
+
+ Because of the schema change, this patch also compares any existing
+ database file against the new schema, and deletes the existing file if the schema is
+ not current.
+
+ * NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp:
+ The logic for topFrameLinkDecorationsFromQuery was the opposite
+ of all other "xyzFrom" queries. When merging data from the memory
+ store, the load statistic being inserted holds a list of topFrames
+ which it has been redirected to from. I think it makes more sense
+ to also organize the table this way.
+
+ (WebKit::ObservedDomainsTableSchemaV1):
+ (WebKit::ObservedDomainsTableSchemaV1Alternate):
+ For support on both iOS and MacOS, there are two CREATE TABLE queries
+ to compare to, depending on whether the query result contains quotes
+ around the table name.
+
+ (WebKit::ResourceLoadStatisticsDatabaseStore::ResourceLoadStatisticsDatabaseStore):
+ (WebKit::ResourceLoadStatisticsDatabaseStore::openITPDatabase):
+ (WebKit::ResourceLoadStatisticsDatabaseStore::openAndDropOldDatabaseIfNecessary):
+ The code to check for the current schema was adapted from SQLiteIDBBackingStore.cpp
+
+ (WebKit::ResourceLoadStatisticsDatabaseStore::prepareStatements):
+ (WebKit::ResourceLoadStatisticsDatabaseStore::insertObservedDomain):
+ (WebKit::ResourceLoadStatisticsDatabaseStore::ensureAndMakeDomainList):
+ The previous naming of the list parameter in this function was
+ confusing because it is used by many different relationships not just
+ subframes under top frames.
+
+ (WebKit::ResourceLoadStatisticsDatabaseStore::insertDomainRelationshipList):
+ topFrameLinkDecorationsFrom were never inserted into the database.
+
+ (WebKit::ResourceLoadStatisticsDatabaseStore::insertDomainRelationships):
+ (WebKit::ResourceLoadStatisticsDatabaseStore::merge):
+ (WebKit::ResourceLoadStatisticsDatabaseStore::mergeStatistic):
+ Since the statement to get all data for a given domain is now used in
+ multiple places, I stored the query as a constexpr auto.
+
+ (WebKit::ResourceLoadStatisticsDatabaseStore::logCrossSiteLoadWithLinkDecoration):
+ Matched the memory store functionality, which calls the boolean
+ "gotLinkDecorationFromPrevalentResource." I thought isScheduledForWebsiteDataRemoval
+ would be more clear of a name, because this flag gets cleared even when
+ prevalent top frame link decorations for this domain still exist in the table.
+
+ (WebKit::ResourceLoadStatisticsDatabaseStore::dumpResourceLoadStatistics):
+ (WebKit::ResourceLoadStatisticsDatabaseStore::setIsScheduledForWebsiteDataRemoval):
+ (WebKit::ResourceLoadStatisticsDatabaseStore::prevalentDomains): Deleted.
+ (WebKit::ResourceLoadStatisticsDatabaseStore::domains):
+ To match memory store functionality, the check for website data to
+ delete should check all domains, not just prevalent ones.
+
+ (WebKit::ResourceLoadStatisticsDatabaseStore::hasHadUnexpiredRecentUserInteraction):
+ (WebKit::ResourceLoadStatisticsDatabaseStore::shouldRemoveAllWebsiteDataFor):
+ This now needs to check if the resource is prevalent, because it is
+ no longer guaranteed.
+
+ (WebKit::ResourceLoadStatisticsDatabaseStore::shouldRemoveAllButCookiesFor):
+ (WebKit::ResourceLoadStatisticsDatabaseStore::registrableDomainsToRemoveWebsiteDataFor):
+ (WebKit::ResourceLoadStatisticsDatabaseStore::getDomainStringFromDomainID):
+ (WebKit::ResourceLoadStatisticsDatabaseStore::getSubStatisticStatement):
+ (WebKit::ResourceLoadStatisticsDatabaseStore::appendSubStatisticList):
+ (WebKit::ResourceLoadStatisticsDatabaseStore::resourceToString):
+ This functionality matches the toString function in
+ ResourceLoadStatistics.cpp.
+
+ (WebKit::CompletionHandler<void):
+ * NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h:
+
2019-10-21 Jiewen Tan <[email protected]>
[WebAuthn] Warn users when multiple NFC tags present
Modified: trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp (251500 => 251501)
--- trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp 2019-10-23 21:58:17 UTC (rev 251500)
+++ trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp 2019-10-23 22:06:46 UTC (rev 251501)
@@ -75,13 +75,13 @@
// INSERT Queries
constexpr auto insertObservedDomainQuery = "INSERT INTO ObservedDomains (registrableDomain, lastSeen, hadUserInteraction,"
"mostRecentUserInteractionTime, grandfathered, isPrevalent, isVeryPrevalent, dataRecordsRemoved, timesAccessedAsFirstPartyDueToUserInteraction,"
- "timesAccessedAsFirstPartyDueToStorageAccessAPI) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"_s;
+ "timesAccessedAsFirstPartyDueToStorageAccessAPI, isScheduledForAllButCookieDataRemoval) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"_s;
constexpr auto insertTopLevelDomainQuery = "INSERT INTO TopLevelDomains VALUES (?)"_s;
constexpr auto storageAccessUnderTopFrameDomainsQuery = "INSERT OR IGNORE INTO StorageAccessUnderTopFrameDomains (domainID, topLevelDomainID) SELECT ?, domainID FROM ObservedDomains WHERE registrableDomain in ( "_s;
constexpr auto topFrameUniqueRedirectsToQuery = "INSERT OR IGNORE into TopFrameUniqueRedirectsTo (sourceDomainID, toDomainID) SELECT ?, domainID FROM ObservedDomains where registrableDomain in ( "_s;
constexpr auto subframeUnderTopFrameDomainsQuery = "INSERT OR IGNORE into SubframeUnderTopFrameDomains (subFrameDomainID, topFrameDomainID) SELECT ?, domainID FROM ObservedDomains where registrableDomain in ( "_s;
constexpr auto topFrameUniqueRedirectsFromQuery = "INSERT OR IGNORE INTO TopFrameUniqueRedirectsFrom (targetDomainID, fromDomainID) SELECT ?, domainID FROM ObservedDomains WHERE registrableDomain in ( "_s;
-constexpr auto topFrameLinkDecorationsFromQuery = "INSERT OR IGNORE INTO TopFrameLinkDecorationsFrom (fromDomainID, toDomainID) SELECT ?, domainID FROM ObservedDomains WHERE registrableDomain in ( "_s;
+constexpr auto topFrameLinkDecorationsFromQuery = "INSERT OR IGNORE INTO TopFrameLinkDecorationsFrom (toDomainID, fromDomainID) SELECT ?, domainID FROM ObservedDomains WHERE registrableDomain in ( "_s;
constexpr auto subresourceUnderTopFrameDomainsQuery = "INSERT OR IGNORE INTO SubresourceUnderTopFrameDomains (subresourceDomainID, topFrameDomainID) SELECT ?, domainID FROM ObservedDomains WHERE registrableDomain in ( "_s;
constexpr auto subresourceUniqueRedirectsToQuery = "INSERT OR IGNORE INTO SubresourceUniqueRedirectsTo (subresourceDomainID, toDomainID) SELECT ?, domainID FROM ObservedDomains WHERE registrableDomain in ( "_s;
constexpr auto subresourceUniqueRedirectsFromQuery = "INSERT OR IGNORE INTO SubresourceUniqueRedirectsFrom (subresourceDomainID, fromDomainID) SELECT ?, domainID FROM ObservedDomains WHERE registrableDomain in ( "_s;
@@ -93,8 +93,8 @@
"WHERE subresourceDomainID = ? AND topFrameDomainID = (SELECT domainID FROM ObservedDomains WHERE registrableDomain = ?))"_s;
constexpr auto subresourceUniqueRedirectsToExistsQuery = "SELECT EXISTS (SELECT 1 FROM SubresourceUniqueRedirectsTo WHERE subresourceDomainID = ? "
"AND toDomainID = (SELECT domainID FROM ObservedDomains WHERE registrableDomain = ?))"_s;
-constexpr auto topFrameLinkDecorationsFromExistsQuery = "SELECT EXISTS (SELECT 1 FROM TopFrameLinkDecorationsFrom WHERE fromDomainID = ? "
-"AND toDomainID = (SELECT domainID FROM ObservedDomains WHERE registrableDomain = ?))"_s;
+constexpr auto topFrameLinkDecorationsFromExistsQuery = "SELECT EXISTS (SELECT 1 FROM TopFrameLinkDecorationsFrom WHERE toDomainID = ? "
+"AND fromDomainID = (SELECT domainID FROM ObservedDomains WHERE registrableDomain = ?))"_s;
// UPDATE Queries
constexpr auto mostRecentUserInteractionQuery = "UPDATE ObservedDomains SET hadUserInteraction = ?, mostRecentUserInteractionTime = ? "
@@ -105,15 +105,18 @@
constexpr auto updateVeryPrevalentResourceQuery = "UPDATE ObservedDomains SET isVeryPrevalent = ? WHERE registrableDomain = ?"_s;
constexpr auto clearPrevalentResourceQuery = "UPDATE ObservedDomains SET isPrevalent = 0, isVeryPrevalent = 0 WHERE registrableDomain = ?"_s;
constexpr auto updateGrandfatheredQuery = "UPDATE ObservedDomains SET grandfathered = ? WHERE registrableDomain = ?"_s;
+constexpr auto updateIsScheduledForAllButCookieDataRemovalQuery = "UPDATE ObservedDomains SET isScheduledForAllButCookieDataRemoval = ? WHERE registrableDomain = ?"_s;
-
// SELECT Queries
constexpr auto domainIDFromStringQuery = "SELECT domainID FROM ObservedDomains WHERE registrableDomain = ?"_s;
+constexpr auto domainStringFromDomainIDQuery = "SELECT registrableDomain FROM ObservedDomains WHERE domainID = ?"_s;
constexpr auto isPrevalentResourceQuery = "SELECT isPrevalent FROM ObservedDomains WHERE registrableDomain = ?"_s;
constexpr auto isVeryPrevalentResourceQuery = "SELECT isVeryPrevalent FROM ObservedDomains WHERE registrableDomain = ?"_s;
constexpr auto hadUserInteractionQuery = "SELECT hadUserInteraction, mostRecentUserInteractionTime FROM ObservedDomains WHERE registrableDomain = ?"_s;
constexpr auto isGrandfatheredQuery = "SELECT grandfathered FROM ObservedDomains WHERE registrableDomain = ?"_s;
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;
// CREATE TABLE Queries
constexpr auto createObservedDomain = "CREATE TABLE ObservedDomains ("
@@ -120,7 +123,8 @@
"domainID INTEGER PRIMARY KEY, registrableDomain TEXT NOT NULL UNIQUE ON CONFLICT FAIL, lastSeen REAL NOT NULL, "
"hadUserInteraction INTEGER NOT NULL, mostRecentUserInteractionTime REAL NOT NULL, grandfathered INTEGER NOT NULL, "
"isPrevalent INTEGER NOT NULL, isVeryPrevalent INTEGER NOT NULL, dataRecordsRemoved INTEGER NOT NULL,"
- "timesAccessedAsFirstPartyDueToUserInteraction INTEGER NOT NULL, timesAccessedAsFirstPartyDueToStorageAccessAPI INTEGER NOT NULL);"_s;
+ "timesAccessedAsFirstPartyDueToUserInteraction INTEGER NOT NULL, timesAccessedAsFirstPartyDueToStorageAccessAPI INTEGER NOT NULL,"
+ "isScheduledForAllButCookieDataRemoval INTEGER NOT NULL)"_s;
enum {
DomainIDIndex,
@@ -133,7 +137,8 @@
IsVeryPrevalentIndex,
DataRecordsRemovedIndex,
TimesAccessedAsFirstPartyDueToUserInteractionIndex,
- TimesAccessedAsFirstPartyDueToStorageAccessAPIIndex
+ TimesAccessedAsFirstPartyDueToStorageAccessAPIIndex,
+ IsScheduledForAllButCookieDataRemovalIndex
};
constexpr auto createTopLevelDomains = "CREATE TABLE TopLevelDomains ("
@@ -156,9 +161,9 @@
"FOREIGN KEY(fromDomainID) REFERENCES TopLevelDomains(topLevelDomainID) ON DELETE CASCADE);"_s;
constexpr auto createTopFrameLinkDecorationsFrom = "CREATE TABLE TopFrameLinkDecorationsFrom ("
- "fromDomainID INTEGER NOT NULL, toDomainID INTEGER NOT NULL, "
- "FOREIGN KEY(fromDomainID) REFERENCES TopLevelDomains(topLevelDomainID) ON DELETE CASCADE, "
- "FOREIGN KEY(toDomainID) REFERENCES TopLevelDomains(topLevelDomainID) ON DELETE CASCADE);"_s;
+ "toDomainID INTEGER NOT NULL, fromDomainID INTEGER NOT NULL, "
+ "FOREIGN KEY(toDomainID) REFERENCES TopLevelDomains(topLevelDomainID) ON DELETE CASCADE, "
+ "FOREIGN KEY(fromDomainID) REFERENCES TopLevelDomains(topLevelDomainID) ON DELETE CASCADE);"_s;
constexpr auto createSubframeUnderTopFrameDomains = "CREATE TABLE SubframeUnderTopFrameDomains ("
"subFrameDomainID INTEGER NOT NULL, topFrameDomainID INTEGER NOT NULL, "
@@ -184,7 +189,7 @@
constexpr auto createUniqueIndexStorageAccessUnderTopFrameDomains = "CREATE UNIQUE INDEX IF NOT EXISTS StorageAccessUnderTopFrameDomains_domainID_topLevelDomainID on StorageAccessUnderTopFrameDomains ( domainID, topLevelDomainID );"_s;
constexpr auto createUniqueIndexTopFrameUniqueRedirectsTo = "CREATE UNIQUE INDEX IF NOT EXISTS TopFrameUniqueRedirectsTo_sourceDomainID_toDomainID on TopFrameUniqueRedirectsTo ( sourceDomainID, toDomainID );"_s;
constexpr auto createUniqueIndexTopFrameUniqueRedirectsFrom = "CREATE UNIQUE INDEX IF NOT EXISTS TopFrameUniqueRedirectsFrom_targetDomainID_fromDomainID on TopFrameUniqueRedirectsFrom ( targetDomainID, fromDomainID );"_s;
-constexpr auto createUniqueIndexTopFrameLinkDecorationsFrom = "CREATE UNIQUE INDEX IF NOT EXISTS TopFrameLinkDecorationsFrom_fromDomainID_toDomainID on TopFrameLinkDecorationsFrom ( fromDomainID, toDomainID );"_s;
+constexpr auto createUniqueIndexTopFrameLinkDecorationsFrom = "CREATE UNIQUE INDEX IF NOT EXISTS TopFrameLinkDecorationsFrom_toDomainID_fromDomainID on TopFrameLinkDecorationsFrom ( toDomainID, fromDomainID );"_s;
constexpr auto createUniqueIndexSubframeUnderTopFrameDomains = "CREATE UNIQUE INDEX IF NOT EXISTS SubframeUnderTopFrameDomains_subFrameDomainID_topFrameDomainID on SubframeUnderTopFrameDomains ( subFrameDomainID, topFrameDomainID );"_s;
constexpr auto createUniqueIndexSubresourceUnderTopFrameDomains = "CREATE UNIQUE INDEX IF NOT EXISTS SubresourceUnderTopFrameDomains_subresourceDomainID_topFrameDomainID on SubresourceUnderTopFrameDomains ( subresourceDomainID, topFrameDomainID );"_s;
constexpr auto createUniqueIndexSubresourceUniqueRedirectsTo = "CREATE UNIQUE INDEX IF NOT EXISTS SubresourceUniqueRedirectsTo_subresourceDomainID_toDomainID on SubresourceUniqueRedirectsTo ( subresourceDomainID, toDomainID );"_s;
@@ -192,6 +197,16 @@
const unsigned minimumPrevalentResourcesForTelemetry = 3;
+static const String ObservedDomainsTableSchemaV1()
+{
+ return createObservedDomain;
+}
+
+static const String ObservedDomainsTableSchemaV1Alternate()
+{
+ return "CREATE TABLE \"ObservedDomains\" (domainID INTEGER PRIMARY KEY, registrableDomain TEXT NOT NULL UNIQUE ON CONFLICT FAIL, lastSeen REAL NOT NULL, hadUserInteraction INTEGER NOT NULL, mostRecentUserInteractionTime REAL NOT NULL, grandfathered INTEGER NOT NULL, isPrevalent INTEGER NOT NULL, isVeryPrevalent INTEGER NOT NULL, dataRecordsRemoved INTEGER NOT NULL,timesAccessedAsFirstPartyDueToUserInteraction INTEGER NOT NULL, timesAccessedAsFirstPartyDueToStorageAccessAPI INTEGER NOT NULL,isScheduledForAllButCookieDataRemoval INTEGER NOT NULL)";
+}
+
ResourceLoadStatisticsDatabaseStore::ResourceLoadStatisticsDatabaseStore(WebResourceLoadStatisticsStore& store, WorkQueue& workQueue, ShouldIncludeLocalhost shouldIncludeLocalhost, const String& storageDirectoryPath, PAL::SessionID sessionID)
: ResourceLoadStatisticsStore(store, workQueue, shouldIncludeLocalhost)
, m_storageDirectoryPath(storageDirectoryPath + "/observations.db")
@@ -213,20 +228,20 @@
, m_clearPrevalentResourceStatement(m_database, clearPrevalentResourceQuery)
, m_hadUserInteractionStatement(m_database, hadUserInteractionQuery)
, m_updateGrandfatheredStatement(m_database, updateGrandfatheredQuery)
+ , m_updateIsScheduledForAllButCookieDataRemovalStatement(m_database, updateIsScheduledForAllButCookieDataRemovalQuery)
, m_isGrandfatheredStatement(m_database, isGrandfatheredQuery)
, m_findExpiredUserInteractionStatement(m_database, findExpiredUserInteractionQuery)
, m_countPrevalentResourcesStatement(m_database, countPrevalentResourcesQuery)
, m_countPrevalentResourcesWithUserInteractionStatement(m_database, countPrevalentResourcesWithUserInteractionQuery)
, m_countPrevalentResourcesWithoutUserInteractionStatement(m_database, countPrevalentResourcesWithoutUserInteractionQuery)
+ , m_getResourceDataByDomainNameStatement(m_database, getResourceDataByDomainNameQuery)
+ , m_getAllDomainsStatement(m_database, getAllDomainsQuery)
+ , m_domainStringFromDomainIDStatement(m_database, domainStringFromDomainIDQuery)
, m_sessionID(sessionID)
{
ASSERT(!RunLoop::isMain());
- if (!m_database.open(m_storageDirectoryPath)) {
- RELEASE_LOG_ERROR(Network, "%p - ResourceLoadStatisticsDatabaseStore::open failed, error message: %{public}s, database path: %{public}s", this, m_database.lastErrorMsg(), m_storageDirectoryPath.utf8().data());
- ASSERT_NOT_REACHED();
- return;
- }
+ openAndDropOldDatabaseIfNecessary();
// Since we are using a workerQueue, the sequential dispatch blocks may be called by different threads.
m_database.disableThreadingChecks();
@@ -254,6 +269,50 @@
});
}
+void ResourceLoadStatisticsDatabaseStore::openITPDatabase()
+{
+ if (!m_database.open(m_storageDirectoryPath)) {
+ RELEASE_LOG_ERROR(Network, "%p - ResourceLoadStatisticsDatabaseStore::open failed, error message: %{public}s, database path: %{public}s", this, m_database.lastErrorMsg(), m_storageDirectoryPath.utf8().data());
+ ASSERT_NOT_REACHED();
+ }
+}
+
+void ResourceLoadStatisticsDatabaseStore::openAndDropOldDatabaseIfNecessary()
+{
+ openITPDatabase();
+
+ String currentSchema;
+ {
+ // Fetch the schema for an existing Observed Domains table.
+ SQLiteStatement statement(m_database, "SELECT type, sql FROM sqlite_master WHERE tbl_name='ObservedDomains'");
+ if (statement.prepare() != SQLITE_OK) {
+ LOG_ERROR("Unable to prepare statement to fetch schema for the ObservedDomains table.");
+ ASSERT_NOT_REACHED();
+ return;
+ }
+
+ // If there is no ObservedDomains table at all, or there is an error executing the fetch, delete the file.
+ if (statement.step() != SQLITE_ROW) {
+ LOG_ERROR("Error executing statement to fetch schema for the Observed Domains table.");
+ m_database.close();
+ FileSystem::deleteFile(m_storageDirectoryPath);
+ openITPDatabase();
+ return;
+ }
+
+ currentSchema = statement.getColumnText(1);
+ }
+
+ ASSERT(!currentSchema.isEmpty());
+
+ // If the schema in the ResourceLoadStatistics directory is not the current schema, delete the database file.
+ if (currentSchema != ObservedDomainsTableSchemaV1() && currentSchema != ObservedDomainsTableSchemaV1Alternate()) {
+ m_database.close();
+ FileSystem::deleteFile(m_storageDirectoryPath);
+ openITPDatabase();
+ }
+}
+
static void resetStatement(SQLiteStatement& statement)
{
int resetResult = statement.reset();
@@ -371,6 +430,7 @@
|| m_clearPrevalentResourceStatement.prepare() != SQLITE_OK
|| m_hadUserInteractionStatement.prepare() != SQLITE_OK
|| m_updateGrandfatheredStatement.prepare() != SQLITE_OK
+ || m_updateIsScheduledForAllButCookieDataRemovalStatement.prepare() != SQLITE_OK
|| m_isGrandfatheredStatement.prepare() != SQLITE_OK
|| m_findExpiredUserInteractionStatement.prepare() != SQLITE_OK
|| m_topFrameLinkDecorationsFromExists.prepare() != SQLITE_OK
@@ -377,6 +437,9 @@
|| m_countPrevalentResourcesStatement.prepare() != SQLITE_OK
|| m_countPrevalentResourcesWithUserInteractionStatement.prepare() != SQLITE_OK
|| m_countPrevalentResourcesWithoutUserInteractionStatement.prepare() != SQLITE_OK
+ || m_getResourceDataByDomainNameStatement.prepare() != SQLITE_OK
+ || m_getAllDomainsStatement.prepare() != SQLITE_OK
+ || m_domainStringFromDomainIDStatement.prepare() != SQLITE_OK
) {
RELEASE_LOG_ERROR(Network, "%p - ResourceLoadStatisticsDatabaseStore::prepareStatements failed to prepare, error message: %{public}s", this, m_database.lastErrorMsg());
ASSERT_NOT_REACHED();
@@ -405,7 +468,8 @@
|| m_insertObservedDomainStatement.bindInt(IsVeryPrevalentIndex, loadStatistics.isVeryPrevalentResource) != SQLITE_OK
|| m_insertObservedDomainStatement.bindInt(DataRecordsRemovedIndex, loadStatistics.dataRecordsRemoved) != SQLITE_OK
|| m_insertObservedDomainStatement.bindInt(TimesAccessedAsFirstPartyDueToUserInteractionIndex, loadStatistics.timesAccessedAsFirstPartyDueToUserInteraction) != SQLITE_OK
- || m_insertObservedDomainStatement.bindInt(TimesAccessedAsFirstPartyDueToStorageAccessAPIIndex, loadStatistics.timesAccessedAsFirstPartyDueToStorageAccessAPI) != SQLITE_OK) {
+ || m_insertObservedDomainStatement.bindInt(TimesAccessedAsFirstPartyDueToStorageAccessAPIIndex, loadStatistics.timesAccessedAsFirstPartyDueToStorageAccessAPI) != SQLITE_OK
+ || m_insertObservedDomainStatement.bindInt(IsScheduledForAllButCookieDataRemovalIndex, loadStatistics.gotLinkDecorationFromPrevalentResource) != SQLITE_OK) {
RELEASE_LOG_ERROR_IF_ALLOWED(m_sessionID, "%p - ResourceLoadStatisticsDatabaseStore::insertObservedDomain failed to bind, error message: %{private}s", this, m_database.lastErrorMsg());
ASSERT_NOT_REACHED();
return false;
@@ -488,11 +552,11 @@
return domainID;
}
-String ResourceLoadStatisticsDatabaseStore::ensureAndMakeDomainList(const HashSet<RegistrableDomain>& subframeUnderTopFrameDomains)
+String ResourceLoadStatisticsDatabaseStore::ensureAndMakeDomainList(const HashSet<RegistrableDomain>& domainList)
{
StringBuilder builder;
- for (auto& topFrameResource : subframeUnderTopFrameDomains) {
+ for (auto& topFrameResource : domainList) {
// Insert query will fail if top frame domain is not already in the database
ensureResourceStatisticsForRegistrableDomain(topFrameResource);
@@ -507,9 +571,9 @@
return builder.toString();
}
-void ResourceLoadStatisticsDatabaseStore::insertDomainRelationshipList(const String& statement, const HashSet<RegistrableDomain>& subframeUnderTopFrameDomains, unsigned domainID)
+void ResourceLoadStatisticsDatabaseStore::insertDomainRelationshipList(const String& statement, const HashSet<RegistrableDomain>& domainList, unsigned domainID)
{
- SQLiteStatement insertRelationshipStatement(m_database, makeString(statement, ensureAndMakeDomainList(subframeUnderTopFrameDomains), " );"));
+ SQLiteStatement insertRelationshipStatement(m_database, makeString(statement, ensureAndMakeDomainList(domainList), " );"));
if (insertRelationshipStatement.prepare() != SQLITE_OK
|| insertRelationshipStatement.bindInt(1, domainID) != SQLITE_OK
@@ -534,6 +598,7 @@
insertDomainRelationshipList(subresourceUnderTopFrameDomainsQuery, loadStatistics.subresourceUnderTopFrameDomains, registrableDomainID.value());
insertDomainRelationshipList(subresourceUniqueRedirectsToQuery, loadStatistics.subresourceUniqueRedirectsTo, registrableDomainID.value());
insertDomainRelationshipList(subresourceUniqueRedirectsFromQuery, loadStatistics.subresourceUniqueRedirectsFrom, registrableDomainID.value());
+ insertDomainRelationshipList(topFrameLinkDecorationsFromQuery, loadStatistics.topFrameLinkDecorationsFrom, registrableDomainID.value());
}
void ResourceLoadStatisticsDatabaseStore::populateFromMemoryStore(const ResourceLoadStatisticsMemoryStore& memoryStore)
@@ -564,6 +629,7 @@
bool currentIsPrevalent = current.getColumnInt(IsPrevalentIndex);
bool currentIsVeryPrevalent = current.getColumnInt(IsVeryPrevalentIndex);
unsigned currentDataRecordsRemoved = current.getColumnInt(DataRecordsRemovedIndex);
+ bool currentIsScheduledForAllButCookieDataRemoval = current.getColumnInt(IsScheduledForAllButCookieDataRemovalIndex);
ASSERT(currentRegistrableDomain == other.registrableDomain.string());
@@ -585,6 +651,8 @@
setVeryPrevalentResource(other.registrableDomain);
if (other.dataRecordsRemoved > currentDataRecordsRemoved)
updateDataRecordsRemoved(other.registrableDomain, other.dataRecordsRemoved);
+ if (other.gotLinkDecorationFromPrevalentResource && !currentIsScheduledForAllButCookieDataRemoval)
+ setIsScheduledForAllButCookieDataRemoval(other.registrableDomain, true);
}
void ResourceLoadStatisticsDatabaseStore::mergeStatistic(const ResourceLoadStatistics& statistic)
@@ -591,16 +659,15 @@
{
ASSERT(!RunLoop::isMain());
- SQLiteStatement fetchOldStatisticData(m_database, "SELECT * FROM ObservedDomains where registrableDomain = ?");
- if (fetchOldStatisticData.prepare() != SQLITE_OK
- || fetchOldStatisticData.bindText(1, statistic.registrableDomain.string()) != SQLITE_OK
- || fetchOldStatisticData.step() != SQLITE_ROW) {
+ if (m_getResourceDataByDomainNameStatement.bindText(1, statistic.registrableDomain.string()) != SQLITE_OK
+ || m_getResourceDataByDomainNameStatement.step() != SQLITE_ROW) {
RELEASE_LOG_ERROR_IF_ALLOWED(m_sessionID, "%p - ResourceLoadStatisticsDatabaseStore::mergeStatistic. Statement failed to bind or domain was not found, error message: %{private}s", this, m_database.lastErrorMsg());
ASSERT_NOT_REACHED();
return;
}
- merge(fetchOldStatisticData, statistic);
+ merge(m_getResourceDataByDomainNameStatement, statistic);
+ resetStatement(m_getResourceDataByDomainNameStatement);
}
void ResourceLoadStatisticsDatabaseStore::mergeStatistics(Vector<ResourceLoadStatistics>&& statistics)
@@ -1328,8 +1395,12 @@
ASSERT(!RunLoop::isMain());
ASSERT(fromDomain != toDomain);
- auto fromDomainResult = ensureResourceStatisticsForRegistrableDomain(fromDomain);
- insertDomainRelationshipList(topFrameLinkDecorationsFromQuery, HashSet<RegistrableDomain>({ toDomain }), fromDomainResult.second);
+ auto toDomainResult = ensureResourceStatisticsForRegistrableDomain(toDomain);
+ insertDomainRelationshipList(topFrameLinkDecorationsFromQuery, HashSet<RegistrableDomain>({ fromDomain }), toDomainResult.second);
+
+ if (isPrevalentResource(fromDomain))
+ setIsScheduledForAllButCookieDataRemoval(toDomain, true);
+
scheduleStatisticsProcessingRequestIfNecessary();
}
@@ -1467,10 +1538,20 @@
void ResourceLoadStatisticsDatabaseStore::dumpResourceLoadStatistics(CompletionHandler<void(const String&)>&& completionHandler)
{
ASSERT(!RunLoop::isMain());
+ if (dataRecordsBeingRemoved()) {
+ m_dataRecordRemovalCompletionHandlers.append([this, completionHandler = WTFMove(completionHandler)]() mutable {
+ dumpResourceLoadStatistics(WTFMove(completionHandler));
+ });
+ return;
+ }
- // FIXME(195088): Implement SQLite-based dumping routines.
- ASSERT_NOT_REACHED();
- completionHandler({ });
+ StringBuilder result;
+ result.appendLiteral("Resource load statistics:\n\n");
+ while (m_getAllDomainsStatement.step() == SQLITE_ROW)
+ resourceToString(result, m_getAllDomainsStatement.getColumnText(0));
+
+ resetStatement(m_getAllDomainsStatement);
+ completionHandler(result.toString());
}
bool ResourceLoadStatisticsDatabaseStore::predicateValueForDomain(WebCore::SQLiteStatement& predicateStatement, const RegistrableDomain& domain) const
@@ -1569,6 +1650,23 @@
ASSERT_UNUSED(resetResult, resetResult == SQLITE_OK);
}
+void ResourceLoadStatisticsDatabaseStore::setIsScheduledForAllButCookieDataRemoval(const RegistrableDomain& domain, bool value)
+{
+ ASSERT(!RunLoop::isMain());
+
+ ensureResourceStatisticsForRegistrableDomain(domain);
+
+ if (m_updateIsScheduledForAllButCookieDataRemovalStatement.bindInt(1, value) != SQLITE_OK
+ || m_updateIsScheduledForAllButCookieDataRemovalStatement.bindText(2, domain.string()) != SQLITE_OK
+ || m_updateIsScheduledForAllButCookieDataRemovalStatement.step() != SQLITE_DONE) {
+ RELEASE_LOG_ERROR_IF_ALLOWED(m_sessionID, "%p - ResourceLoadStatisticsDatabaseStore::setIsScheduledForAllButCookieDataRemoval failed to bind, error message: %{private}s", this, m_database.lastErrorMsg());
+ ASSERT_NOT_REACHED();
+ return;
+ }
+
+ resetStatement(m_updateIsScheduledForAllButCookieDataRemovalStatement);
+}
+
bool ResourceLoadStatisticsDatabaseStore::isGrandfathered(const RegistrableDomain& domain) const
{
ASSERT(!RunLoop::isMain());
@@ -1803,12 +1901,12 @@
});
}
-Vector<ResourceLoadStatisticsDatabaseStore::PrevalentDomainData> ResourceLoadStatisticsDatabaseStore::prevalentDomains() const
+Vector<ResourceLoadStatisticsDatabaseStore::DomainData> ResourceLoadStatisticsDatabaseStore::domains() const
{
ASSERT(!RunLoop::isMain());
- Vector<PrevalentDomainData> results;
- SQLiteStatement statement(m_database, "SELECT domainID, registrableDomain, mostRecentUserInteractionTime, hadUserInteraction, grandfathered FROM ObservedDomains WHERE isPrevalent = 1"_s);
+ Vector<DomainData> results;
+ SQLiteStatement statement(m_database, "SELECT domainID, registrableDomain, mostRecentUserInteractionTime, hadUserInteraction, grandfathered, isScheduledForAllButCookieDataRemoval FROM ObservedDomains"_s);
if (statement.prepare() != SQLITE_OK)
return results;
@@ -1818,6 +1916,7 @@
, WallTime::fromRawSeconds(statement.getColumnDouble(2))
, statement.getColumnInt(3) ? true : false
, statement.getColumnInt(4) ? true : false
+ , statement.getColumnInt(5) ? true : false
});
}
@@ -1889,7 +1988,7 @@
}
}
-bool ResourceLoadStatisticsDatabaseStore::hasHadUnexpiredRecentUserInteraction(const PrevalentDomainData& resourceStatistic, OperatingDatesWindow operatingDatesWindow)
+bool ResourceLoadStatisticsDatabaseStore::hasHadUnexpiredRecentUserInteraction(const DomainData& resourceStatistic, OperatingDatesWindow operatingDatesWindow)
{
if (resourceStatistic.hadUserInteraction && hasStatisticsExpired(resourceStatistic.mostRecentUserInteractionTime, operatingDatesWindow)) {
clearUserInteraction(resourceStatistic.registrableDomain);
@@ -1899,16 +1998,14 @@
return resourceStatistic.hadUserInteraction;
}
-bool ResourceLoadStatisticsDatabaseStore::shouldRemoveAllWebsiteDataFor(const PrevalentDomainData& resourceStatistic, bool shouldCheckForGrandfathering)
+bool ResourceLoadStatisticsDatabaseStore::shouldRemoveAllWebsiteDataFor(const DomainData& resourceStatistic, bool shouldCheckForGrandfathering)
{
- return !hasHadUnexpiredRecentUserInteraction(resourceStatistic, OperatingDatesWindow::Long) && (!shouldCheckForGrandfathering || !resourceStatistic.grandfathered);
+ return isPrevalentResource(resourceStatistic.registrableDomain) && !hasHadUnexpiredRecentUserInteraction(resourceStatistic, OperatingDatesWindow::Long) && (!shouldCheckForGrandfathering || !resourceStatistic.grandfathered);
}
-bool ResourceLoadStatisticsDatabaseStore::shouldRemoveAllButCookiesFor(const PrevalentDomainData& resourceStatistic, bool shouldCheckForGrandfathering) const
+bool ResourceLoadStatisticsDatabaseStore::shouldRemoveAllButCookiesFor(const DomainData& resourceStatistic, bool shouldCheckForGrandfathering)
{
- UNUSED_PARAM(resourceStatistic);
- UNUSED_PARAM(shouldCheckForGrandfathering);
- return false;
+ return resourceStatistic.isScheduledForAllButCookieDataRemoval && !hasHadUnexpiredRecentUserInteraction(resourceStatistic, OperatingDatesWindow::Short) && (!shouldCheckForGrandfathering || !resourceStatistic.grandfathered);
}
Vector<std::pair<RegistrableDomain, WebsiteDataToRemove>> ResourceLoadStatisticsDatabaseStore::registrableDomainsToRemoveWebsiteDataFor()
@@ -1925,14 +2022,15 @@
Vector<std::pair<RegistrableDomain, WebsiteDataToRemove>> domainsToRemoveWebsiteDataFor;
- Vector<PrevalentDomainData> prevalentDomains = this->prevalentDomains();
+ Vector<DomainData> domains = this->domains();
Vector<unsigned> domainIDsToClearGrandfathering;
- for (auto& statistic : prevalentDomains) {
+ for (auto& statistic : domains) {
if (shouldRemoveAllWebsiteDataFor(statistic, shouldCheckForGrandfathering))
domainsToRemoveWebsiteDataFor.append(std::make_pair(statistic.registrableDomain, WebsiteDataToRemove::All));
- else if (shouldRemoveAllButCookiesFor(statistic, shouldCheckForGrandfathering))
+ else if (shouldRemoveAllButCookiesFor(statistic, shouldCheckForGrandfathering)) {
domainsToRemoveWebsiteDataFor.append(std::make_pair(statistic.registrableDomain, WebsiteDataToRemove::AllButCookies));
-
+ setIsScheduledForAllButCookieDataRemoval(statistic.registrableDomain, false);
+ }
if (shouldClearGrandfathering && statistic.grandfathered)
domainIDsToClearGrandfathering.append(statistic.domainID);
}
@@ -2079,7 +2177,148 @@
return (subFrameUnderTopFrameCount.getColumnInt(0) == 1 && subresourceUnderTopFrameCount.getColumnInt(0) == 1 && subresourceUniqueRedirectsTo.getColumnInt(0) == 1);
}
+static void appendBoolean(StringBuilder& builder, const String& label, bool flag)
+{
+ builder.appendLiteral(" ");
+ builder.append(label);
+ builder.appendLiteral(": ");
+ builder.append(flag ? "Yes" : "No");
+}
+static void appendNextEntry(StringBuilder& builder, String entry)
+{
+ builder.appendLiteral(" ");
+ builder.append(entry);
+ builder.append('\n');
+}
+
+String ResourceLoadStatisticsDatabaseStore::getDomainStringFromDomainID(unsigned domainID) const
+{
+ auto result = emptyString();
+
+ if (m_domainStringFromDomainIDStatement.bindInt(1, domainID) != SQLITE_OK) {
+ RELEASE_LOG_ERROR_IF_ALLOWED(m_sessionID, "%p - ResourceLoadStatisticsDatabaseStore::getDomainStringFromDomainID. Statement failed to prepare or bind, error message: %{private}s", this, m_database.lastErrorMsg());
+ ASSERT_NOT_REACHED();
+ return result;
+ }
+
+ if (m_domainStringFromDomainIDStatement.step() == SQLITE_ROW)
+ result = m_domainStringFromDomainIDStatement.getColumnText(0);
+
+ resetStatement(m_domainStringFromDomainIDStatement);
+ return result;
+}
+
+String ResourceLoadStatisticsDatabaseStore::getSubStatisticStatement(const String& tableName) const
+{
+ if (tableName == "StorageAccessUnderTopFrameDomains")
+ return "SELECT topLevelDomainID from StorageAccessUnderTopFrameDomains WHERE domainID = ?";
+ if (tableName == "TopFrameUniqueRedirectsTo")
+ return "SELECT toDomainID from TopFrameUniqueRedirectsTo WHERE sourceDomainID = ?";
+ if (tableName == "TopFrameUniqueRedirectsFrom")
+ return "SELECT fromDomainID from TopFrameUniqueRedirectsFrom WHERE targetDomainID = ?";
+ if (tableName == "TopFrameLinkDecorationsFrom")
+ return "SELECT fromDomainID from TopFrameLinkDecorationsFrom WHERE toDomainID = ?";
+ if (tableName == "SubframeUnderTopFrameDomains")
+ return "SELECT topFrameDomainID from SubframeUnderTopFrameDomains WHERE subFrameDomainID = ?";
+ if (tableName == "SubresourceUnderTopFrameDomains")
+ return "SELECT topFrameDomainID from SubresourceUnderTopFrameDomains WHERE subresourceDomainID = ?";
+ if (tableName == "SubresourceUniqueRedirectsTo")
+ return "SELECT toDomainID from SubresourceUniqueRedirectsTo WHERE subresourceDomainID = ?";
+ if (tableName == "SubresourceUniqueRedirectsFrom")
+ return "SELECT fromDomainID from SubresourceUniqueRedirectsFrom WHERE subresourceDomainID = ?";
+
+ return emptyString();
+}
+
+void ResourceLoadStatisticsDatabaseStore::appendSubStatisticList(StringBuilder& builder, const String& tableName, const String& domain) const
+{
+ auto query = getSubStatisticStatement(tableName);
+
+ if (query.isEmpty())
+ return;
+
+ SQLiteStatement data(m_database, query);
+
+ if (data.prepare() != SQLITE_OK
+ || data.bindInt(1, domainID(RegistrableDomain::uncheckedCreateFromHost(domain)).value()) != SQLITE_OK) {
+ RELEASE_LOG_ERROR_IF_ALLOWED(m_sessionID, "%p - ResourceLoadStatisticsDatabaseStore::appendSubStatisticList. Statement failed to prepare or bind, error message: %{private}s", this, m_database.lastErrorMsg());
+ ASSERT_NOT_REACHED();
+ return;
+ }
+
+ if (data.step() != SQLITE_ROW)
+ return;
+
+ builder.appendLiteral(" ");
+ builder.append(tableName);
+ builder.appendLiteral(":\n");
+
+ auto result = getDomainStringFromDomainID(data.getColumnInt(0));
+ appendNextEntry(builder, result);
+
+ while (data.step() == SQLITE_ROW) {
+ result = getDomainStringFromDomainID(data.getColumnInt(0));
+ appendNextEntry(builder, result);
+ }
+}
+
+void ResourceLoadStatisticsDatabaseStore::resourceToString(StringBuilder& builder, const String& domain) const
+{
+ if (m_getResourceDataByDomainNameStatement.bindText(1, domain) != SQLITE_OK
+ || m_getResourceDataByDomainNameStatement.step() != SQLITE_ROW) {
+ RELEASE_LOG_ERROR_IF_ALLOWED(m_sessionID, "%p - ResourceLoadStatisticsDatabaseStore::resourceToString. Statement failed to bind or domain was not found, error message: %{private}s", this, m_database.lastErrorMsg());
+ ASSERT_NOT_REACHED();
+ return;
+ }
+
+ builder.appendLiteral("Registrable domain: ");
+ builder.append(domain);
+ builder.append('\n');
+ builder.appendLiteral(" lastSeen: ");
+ builder.appendFixedPrecisionNumber(m_getResourceDataByDomainNameStatement.getColumnDouble(LastSeenIndex));
+ builder.append('\n');
+
+ // User interaction
+ appendBoolean(builder, "hadUserInteraction", m_getResourceDataByDomainNameStatement.getColumnInt(HadUserInteractionIndex));
+ builder.append('\n');
+ builder.appendLiteral(" mostRecentUserInteraction: ");
+ builder.appendFixedPrecisionNumber(m_getResourceDataByDomainNameStatement.getColumnDouble(MostRecentUserInteractionTimeIndex));
+ builder.append('\n');
+ appendBoolean(builder, "grandfathered", m_getResourceDataByDomainNameStatement.getColumnInt(GrandfatheredIndex));
+ builder.append('\n');
+
+ // Storage access
+ appendSubStatisticList(builder, "StorageAccessUnderTopFrameDomains", domain);
+
+ // Top frame stats
+ appendSubStatisticList(builder, "TopFrameUniqueRedirectsTo", domain);
+ appendSubStatisticList(builder, "TopFrameUniqueRedirectsFrom", domain);
+ appendSubStatisticList(builder, "TopFrameLinkDecorationsFrom", domain);
+
+ appendBoolean(builder, "IsScheduledForAllButCookieDataRemoval", m_getResourceDataByDomainNameStatement.getColumnInt(IsScheduledForAllButCookieDataRemovalIndex));
+
+ // Subframe stats
+ appendSubStatisticList(builder, "SubframeUnderTopFrameDomains", domain);
+
+ // Subresource stats
+ appendSubStatisticList(builder, "SubresourceUnderTopFrameDomains", domain);
+ appendSubStatisticList(builder, "SubresourceUniqueRedirectsTo", domain);
+ appendSubStatisticList(builder, "SubresourceUniqueRedirectsFrom", domain);
+
+ // Prevalent Resource
+ appendBoolean(builder, "isPrevalentResource", m_getResourceDataByDomainNameStatement.getColumnInt(IsPrevalentIndex));
+ builder.append('\n');
+ appendBoolean(builder, "isVeryPrevalentResource", m_getResourceDataByDomainNameStatement.getColumnInt(IsVeryPrevalentIndex));
+ builder.append('\n');
+ builder.appendLiteral(" dataRecordsRemoved: ");
+ builder.appendNumber(m_getResourceDataByDomainNameStatement.getColumnInt(DataRecordsRemovedIndex));
+ builder.append('\n');
+
+ resetStatement(m_getResourceDataByDomainNameStatement);
+}
+
+
} // namespace WebKit
#endif
Modified: trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h (251500 => 251501)
--- trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h 2019-10-23 21:58:17 UTC (rev 251500)
+++ trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h 2019-10-23 22:06:46 UTC (rev 251501)
@@ -109,6 +109,7 @@
void setGrandfathered(const RegistrableDomain&, bool value) override;
bool isGrandfathered(const RegistrableDomain&) const override;
+ void setIsScheduledForAllButCookieDataRemoval(const RegistrableDomain&, bool value);
void setSubframeUnderTopFrameDomain(const SubFrameDomain&, const TopFrameDomain&) override;
void setSubresourceUnderTopFrameDomain(const SubResourceDomain&, const TopFrameDomain&) override;
void setSubresourceUniqueRedirectTo(const SubResourceDomain&, const RedirectDomain&) override;
@@ -131,8 +132,14 @@
void setLastSeen(const RegistrableDomain&, Seconds) override;
bool isCorrectSubStatisticsCount(const RegistrableDomain&, const TopFrameDomain&);
+ void resourceToString(StringBuilder&, const String&) const;
private:
+ void openITPDatabase();
+ void openAndDropOldDatabaseIfNecessary();
+ String getDomainStringFromDomainID(unsigned) const;
+ String getSubStatisticStatement(const String&) const;
+ void appendSubStatisticList(StringBuilder&, const String& tableName, const String& domain) const;
void mergeStatistic(const ResourceLoadStatistics&);
void merge(WebCore::SQLiteStatement&, const ResourceLoadStatistics&);
void clearDatabaseContents();
@@ -157,15 +164,16 @@
Vector<RegistrableDomain> domainsToBlockButKeepCookiesFor() const;
Vector<RegistrableDomain> domainsWithUserInteractionAsFirstParty() const;
- struct PrevalentDomainData {
+ struct DomainData {
unsigned domainID;
RegistrableDomain registrableDomain;
WallTime mostRecentUserInteractionTime;
bool hadUserInteraction;
bool grandfathered;
+ bool isScheduledForAllButCookieDataRemoval;
};
- Vector<PrevalentDomainData> prevalentDomains() const;
- bool hasHadUnexpiredRecentUserInteraction(const PrevalentDomainData&, OperatingDatesWindow);
+ Vector<DomainData> domains() const;
+ bool hasHadUnexpiredRecentUserInteraction(const DomainData&, OperatingDatesWindow);
Vector<unsigned> findExpiredUserInteractions() const;
void clearExpiredUserInteractions();
void clearGrandfathering(Vector<unsigned>&&);
@@ -198,8 +206,8 @@
void pruneStatisticsIfNeeded() override;
enum class AddedRecord { No, Yes };
std::pair<AddedRecord, unsigned> ensureResourceStatisticsForRegistrableDomain(const RegistrableDomain&);
- bool shouldRemoveAllWebsiteDataFor(const PrevalentDomainData&, bool shouldCheckForGrandfathering);
- bool shouldRemoveAllButCookiesFor(const PrevalentDomainData&, bool shouldCheckForGrandfathering) const;
+ bool shouldRemoveAllWebsiteDataFor(const DomainData&, bool shouldCheckForGrandfathering);
+ bool shouldRemoveAllButCookiesFor(const DomainData&, bool shouldCheckForGrandfathering);
Vector<std::pair<RegistrableDomain, WebsiteDataToRemove>> registrableDomainsToRemoveWebsiteDataFor() override;
bool isDatabaseStore() const final { return true; }
@@ -229,11 +237,15 @@
WebCore::SQLiteStatement m_clearPrevalentResourceStatement;
mutable WebCore::SQLiteStatement m_hadUserInteractionStatement;
WebCore::SQLiteStatement m_updateGrandfatheredStatement;
+ mutable WebCore::SQLiteStatement m_updateIsScheduledForAllButCookieDataRemovalStatement;
mutable WebCore::SQLiteStatement m_isGrandfatheredStatement;
mutable WebCore::SQLiteStatement m_findExpiredUserInteractionStatement;
mutable WebCore::SQLiteStatement m_countPrevalentResourcesStatement;
mutable WebCore::SQLiteStatement m_countPrevalentResourcesWithUserInteractionStatement;
mutable WebCore::SQLiteStatement m_countPrevalentResourcesWithoutUserInteractionStatement;
+ mutable WebCore::SQLiteStatement m_getResourceDataByDomainNameStatement;
+ mutable WebCore::SQLiteStatement m_getAllDomainsStatement;
+ mutable WebCore::SQLiteStatement m_domainStringFromDomainIDStatement;
PAL::SessionID m_sessionID;
};
_______________________________________________ webkit-changes mailing list [email protected] https://lists.webkit.org/mailman/listinfo/webkit-changes
