Resource Load Statistics: Non-redirected top frame navigation should not get captured...
authorwilander@apple.com <wilander@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 28 Sep 2018 00:23:37 +0000 (00:23 +0000)
committerwilander@apple.com <wilander@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 28 Sep 2018 00:23:37 +0000 (00:23 +0000)
https://bugs.webkit.org/show_bug.cgi?id=190055
<rdar://problem/44843460>

Reviewed by Chris Dumez.

Source/WebCore:

Test: http/tests/resourceLoadStatistics/do-not-capture-statistics-for-simple-top-navigations.html

* loader/ResourceLoadStatistics.cpp:
(WebCore::ResourceLoadStatistics::decode):
    Corrects legacy statistics for frames and triggers a re-classification.

Source/WebKit:

* UIProcess/ResourceLoadStatisticsMemoryStore.cpp:
    Bumped the statisticsModelVersion to 14 to be able to
    correct legacy statistics.
(WebKit::ResourceLoadStatisticsMemoryStore::logFrameNavigation):
    Now skips capture if it's the main frame.

LayoutTests:

* http/tests/resourceLoadStatistics/do-not-capture-statistics-for-simple-top-navigations-expected.txt: Added.
* http/tests/resourceLoadStatistics/do-not-capture-statistics-for-simple-top-navigations.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@236578 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/http/tests/resourceLoadStatistics/do-not-capture-statistics-for-simple-top-navigations-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/do-not-capture-statistics-for-simple-top-navigations.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/loader/ResourceLoadStatistics.cpp
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/ResourceLoadStatisticsMemoryStore.cpp

index 6c17863..0f3ba1b 100644 (file)
@@ -1,3 +1,14 @@
+2018-09-27  John Wilander  <wilander@apple.com>
+
+        Resource Load Statistics: Non-redirected top frame navigation should not get captured in statistics
+        https://bugs.webkit.org/show_bug.cgi?id=190055
+        <rdar://problem/44843460>
+
+        Reviewed by Chris Dumez.
+
+        * http/tests/resourceLoadStatistics/do-not-capture-statistics-for-simple-top-navigations-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/do-not-capture-statistics-for-simple-top-navigations.html: Added.
+
 2018-09-27  Chris Dumez  <cdumez@apple.com>
 
         Regression(r236512): fast/scrolling/scroll-animator-overlay-scrollbars-clicked.html and editing/pasteboard/emacs-ctrl-a-k-y.html are flaky
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/do-not-capture-statistics-for-simple-top-navigations-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/do-not-capture-statistics-for-simple-top-navigations-expected.txt
new file mode 100644 (file)
index 0000000..069c91c
--- /dev/null
@@ -0,0 +1,11 @@
+Test that a non-redirected top frame navigation doesn't get captured in statistics.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1") is false
+PASS testRunner.isStatisticsRegisteredAsSubFrameUnder("http://127.0.0.1", "http://localhost") is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/do-not-capture-statistics-for-simple-top-navigations.html b/LayoutTests/http/tests/resourceLoadStatistics/do-not-capture-statistics-for-simple-top-navigations.html
new file mode 100644 (file)
index 0000000..c889343
--- /dev/null
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <script src="/js-test-resources/js-test.js"></script>
+    <script src="resources/util.js"></script>
+</head>
+<body>
+<script>
+    description("Test that a non-redirected top frame navigation doesn't get captured in statistics.");
+    jsTestIsAsync = true;
+
+    function finishTest() {
+        shouldBeFalse('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
+        shouldBeFalse('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://127.0.0.1", "http://localhost")');
+        setEnableFeature(false, finishJSTest);
+    }
+
+    function runTest() {
+        switch (document.location.host) {
+            case "127.0.0.1:8000":
+                setEnableFeature(true, function() {
+                    if (testRunner.isStatisticsPrevalentResource("http://localhost:8000"))
+                        testFailed("Localhost was classified as prevalent resource before the test starts.");
+                    document.location.href = "http://localhost:8000/resourceLoadStatistics/do-not-capture-statistics-for-simple-top-navigations.html";
+                });
+                break;
+            case "localhost:8000":
+                testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+                testRunner.installStatisticsDidScanDataRecordsCallback(finishTest);
+                testRunner.statisticsNotifyObserver();
+                break;
+            default:
+                testFailed("Unknown host: " + document.location.host);
+                finishTest();
+        }
+    }
+
+    if (window.testRunner && window.internals)
+        runTest();
+</script>
+</body>
+</html>
index a8d1f2c..653b43b 100644 (file)
@@ -1,3 +1,17 @@
+2018-09-27  John Wilander  <wilander@apple.com>
+
+        Resource Load Statistics: Non-redirected top frame navigation should not get captured in statistics
+        https://bugs.webkit.org/show_bug.cgi?id=190055
+        <rdar://problem/44843460>
+
+        Reviewed by Chris Dumez.
+
+        Test: http/tests/resourceLoadStatistics/do-not-capture-statistics-for-simple-top-navigations.html
+
+        * loader/ResourceLoadStatistics.cpp:
+        (WebCore::ResourceLoadStatistics::decode):
+            Corrects legacy statistics for frames and triggers a re-classification.
+
 2018-09-27  Jer Noble  <jer.noble@apple.com>
 
         Unreviewed watchOS build fix; Fix declaration for ports which USE(ENCRYPTED_MEDIA) but don't
index 32596d1..27a45a7 100644 (file)
@@ -213,8 +213,9 @@ bool ResourceLoadStatistics::decode(KeyedDecoder& decoder, unsigned modelVersion
     }
 
     // Subframe stats
-    decodeHashCountedSet(decoder, "subframeUnderTopFrameOrigins", subframeUnderTopFrameOrigins);
-    
+    if (modelVersion >= 14)
+        decodeHashCountedSet(decoder, "subframeUnderTopFrameOrigins", subframeUnderTopFrameOrigins);
+
     // Subresource stats
     decodeHashCountedSet(decoder, "subresourceUnderTopFrameOrigins", subresourceUnderTopFrameOrigins);
     decodeHashCountedSet(decoder, "subresourceUniqueRedirectsTo", subresourceUniqueRedirectsTo);
@@ -230,6 +231,12 @@ bool ResourceLoadStatistics::decode(KeyedDecoder& decoder, unsigned modelVersion
             return false;
     }
 
+    // Trigger re-classification based on model 14.
+    if (modelVersion < 14) {
+        isPrevalentResource = false;
+        isVeryPrevalentResource = false;
+    }
+
     if (!decoder.decodeUInt32("dataRecordsRemoved", dataRecordsRemoved))
         return false;
 
index 27fc40e..267ad70 100644 (file)
@@ -1,3 +1,17 @@
+2018-09-27  John Wilander  <wilander@apple.com>
+
+        Resource Load Statistics: Non-redirected top frame navigation should not get captured in statistics
+        https://bugs.webkit.org/show_bug.cgi?id=190055
+        <rdar://problem/44843460>
+
+        Reviewed by Chris Dumez.
+
+        * UIProcess/ResourceLoadStatisticsMemoryStore.cpp:
+            Bumped the statisticsModelVersion to 14 to be able to
+            correct legacy statistics.
+        (WebKit::ResourceLoadStatisticsMemoryStore::logFrameNavigation):
+            Now skips capture if it's the main frame.
+
 2018-09-27  Brent Fulgham  <bfulgham@apple.com>
 
         [iOS] Allow access to VoiceServices features needed for accessibility
index 63877d3..39c2e41 100644 (file)
@@ -46,7 +46,7 @@
 namespace WebKit {
 using namespace WebCore;
 
-constexpr unsigned statisticsModelVersion { 13 };
+constexpr unsigned statisticsModelVersion { 14 };
 constexpr unsigned maxNumberOfRecursiveCallsInRedirectTraceBack { 50 };
 constexpr Seconds minimumStatisticsProcessingInterval { 5_s };
 constexpr unsigned operatingDatesWindow { 30 };
@@ -596,7 +596,7 @@ void ResourceLoadStatisticsMemoryStore::logFrameNavigation(const String& targetP
     bool areTargetAndSourceDomainsAssociated = targetPrimaryDomain == sourcePrimaryDomain;
 
     bool statisticsWereUpdated = false;
-    if (targetHost != mainFrameHost && !(areTargetAndMainFrameDomainsAssociated || areTargetAndSourceDomainsAssociated)) {
+    if (!isMainFrame && targetHost != mainFrameHost && !(areTargetAndMainFrameDomainsAssociated || areTargetAndSourceDomainsAssociated)) {
         auto& targetStatistics = ensureResourceStatisticsForPrimaryDomain(targetPrimaryDomain);
         targetStatistics.lastSeen = ResourceLoadStatistics::reduceTimeResolution(WallTime::now());
         if (targetStatistics.subframeUnderTopFrameOrigins.add(mainFramePrimaryDomain).isNewEntry)