Title: [294297] branches/safari-613-branch
Revision
294297
Author
alanc...@apple.com
Date
2022-05-16 23:10:43 -0700 (Mon, 16 May 2022)

Log Message

Cherry-pick r293264. rdar://problem/92130849

    Web Inspector: Regression(r287684) Resources from the memory cache show empty content in Network, Sources, and Search tabs
    https://bugs.webkit.org/show_bug.cgi?id=239667

    Reviewed by Devin Rousso.

    Source/WebCore:

    Updated tests:
    - http/tests/inspector/network/resource-response-source-disk-cache.html
    - http/tests/inspector/network/resource-response-source-memory-cache.html

    r287684 introduced a subtle bug when calling InspectorInstrumentation::didReceiveData. We rely
    on there being a difference between real, but empty, data buffer and not having a data buffer,
    but after r287684 an empty SharedBuffer would be passed in the later case. Instead, we should
    continue to pass nullptr if there is no buffer so that InspectorNetworkAgent::didReceiveData
    can distiguish between the two.

    The bug is the result of having a non-nullptr `data` in `InspectorNetworkAgent::didReceiveData`,
    which causes us to call `maybeAddResourceData`, which means by the time
    `InspectorNetworkAgent::getResponseBody` is called, the ResourceData for the request will have
    an empty, not non-existant, `content()`, which means we will return the empty content instead,
    since we believe the response had actual content.

    * inspector/InspectorInstrumentation.cpp:
    (WebCore::InspectorInstrumentation::didReceiveDataImpl):
    * inspector/InspectorInstrumentation.h:
    (WebCore::InspectorInstrumentation::didReceiveData):
    * loader/ResourceLoadNotifier.cpp:
    (WebCore::ResourceLoadNotifier::dispatchDidReceiveData):

    LayoutTests:

    Add test steps to ensure that the resource has content, and that the base64Encoded value matches our
    expectations. While only the memory cache was affected by this regression, add the test steps to both
    the memory and disk caches to defend this functionality.

    * http/tests/inspector/network/resource-response-source-memory-cache-expected.txt:
    * http/tests/inspector/network/resource-response-source-memory-cache.html:
    * http/tests/inspector/network/resource-response-source-disk-cache-expected.txt:
    * http/tests/inspector/network/resource-response-source-disk-cache.html:

    Canonical link: https://commits.webkit.org/249905@main
    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@293264 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Diff

Modified: branches/safari-613-branch/LayoutTests/ChangeLog (294296 => 294297)


--- branches/safari-613-branch/LayoutTests/ChangeLog	2022-05-17 06:10:38 UTC (rev 294296)
+++ branches/safari-613-branch/LayoutTests/ChangeLog	2022-05-17 06:10:43 UTC (rev 294297)
@@ -1,5 +1,69 @@
 2022-05-16  Alan Coon  <alanc...@apple.com>
 
+        Cherry-pick r293264. rdar://problem/92130849
+
+    Web Inspector: Regression(r287684) Resources from the memory cache show empty content in Network, Sources, and Search tabs
+    https://bugs.webkit.org/show_bug.cgi?id=239667
+    
+    Reviewed by Devin Rousso.
+    
+    Source/WebCore:
+    
+    Updated tests:
+    - http/tests/inspector/network/resource-response-source-disk-cache.html
+    - http/tests/inspector/network/resource-response-source-memory-cache.html
+    
+    r287684 introduced a subtle bug when calling InspectorInstrumentation::didReceiveData. We rely
+    on there being a difference between real, but empty, data buffer and not having a data buffer,
+    but after r287684 an empty SharedBuffer would be passed in the later case. Instead, we should
+    continue to pass nullptr if there is no buffer so that InspectorNetworkAgent::didReceiveData
+    can distiguish between the two.
+    
+    The bug is the result of having a non-nullptr `data` in `InspectorNetworkAgent::didReceiveData`,
+    which causes us to call `maybeAddResourceData`, which means by the time
+    `InspectorNetworkAgent::getResponseBody` is called, the ResourceData for the request will have
+    an empty, not non-existant, `content()`, which means we will return the empty content instead,
+    since we believe the response had actual content.
+    
+    * inspector/InspectorInstrumentation.cpp:
+    (WebCore::InspectorInstrumentation::didReceiveDataImpl):
+    * inspector/InspectorInstrumentation.h:
+    (WebCore::InspectorInstrumentation::didReceiveData):
+    * loader/ResourceLoadNotifier.cpp:
+    (WebCore::ResourceLoadNotifier::dispatchDidReceiveData):
+    
+    LayoutTests:
+    
+    Add test steps to ensure that the resource has content, and that the base64Encoded value matches our
+    expectations. While only the memory cache was affected by this regression, add the test steps to both
+    the memory and disk caches to defend this functionality.
+    
+    * http/tests/inspector/network/resource-response-source-memory-cache-expected.txt:
+    * http/tests/inspector/network/resource-response-source-memory-cache.html:
+    * http/tests/inspector/network/resource-response-source-disk-cache-expected.txt:
+    * http/tests/inspector/network/resource-response-source-disk-cache.html:
+    
+    Canonical link: https://commits.webkit.org/249905@main
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@293264 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2022-04-22  Patrick Angle  <pan...@apple.com>
+
+            Web Inspector: Regression(r287684) Resources from the memory cache show empty content in Network, Sources, and Search tabs
+            https://bugs.webkit.org/show_bug.cgi?id=239667
+
+            Reviewed by Devin Rousso.
+
+            Add test steps to ensure that the resource has content, and that the base64Encoded value matches our
+            expectations. While only the memory cache was affected by this regression, add the test steps to both
+            the memory and disk caches to defend this functionality.
+
+            * http/tests/inspector/network/resource-response-source-memory-cache-expected.txt:
+            * http/tests/inspector/network/resource-response-source-memory-cache.html:
+            * http/tests/inspector/network/resource-response-source-disk-cache-expected.txt:
+            * http/tests/inspector/network/resource-response-source-disk-cache.html:
+
+2022-05-16  Alan Coon  <alanc...@apple.com>
+
         Cherry-pick r293170. rdar://problem/91117803
 
     AVSampleBufferRenderSynchronizer timeline sometimes goes backwards when playback begins

Modified: branches/safari-613-branch/LayoutTests/http/tests/inspector/network/resource-response-source-disk-cache-expected.txt (294296 => 294297)


--- branches/safari-613-branch/LayoutTests/http/tests/inspector/network/resource-response-source-disk-cache-expected.txt	2022-05-17 06:10:38 UTC (rev 294296)
+++ branches/safari-613-branch/LayoutTests/http/tests/inspector/network/resource-response-source-disk-cache-expected.txt	2022-05-17 06:10:43 UTC (rev 294297)
@@ -6,6 +6,8 @@
 -- Running test case: PossibleNetworkLoad
 PASS: Resource should be created.
 PASS: Resource should receive a Response.
+PASS: Response `body` should not be empty.
+PASS: Response should be base64 encoded.
 
 -- Running test case: Resource.ResponseSource.DiskCache
 PASS: Resource should be created.
@@ -12,4 +14,6 @@
 PASS: Resource should receive a Response.
 PASS: statusCode should be 200
 PASS: responseSource should be Symbol(disk-cache)
+PASS: Response `body` should not be empty.
+PASS: Response should be base64 encoded.
 

Modified: branches/safari-613-branch/LayoutTests/http/tests/inspector/network/resource-response-source-disk-cache.html (294296 => 294297)


--- branches/safari-613-branch/LayoutTests/http/tests/inspector/network/resource-response-source-disk-cache.html	2022-05-17 06:10:38 UTC (rev 294296)
+++ branches/safari-613-branch/LayoutTests/http/tests/inspector/network/resource-response-source-disk-cache.html	2022-05-17 06:10:43 UTC (rev 294297)
@@ -40,6 +40,10 @@
                         InspectorTest.expectEqual(resource.statusCode, statusCode, `statusCode should be ${statusCode}`);
                     if (responseSource)
                         InspectorTest.expectEqual(resource.responseSource, responseSource, `responseSource should be ${String(responseSource)}`);
+                    return resource.requestContentFromBackend();
+                }).then((responseContent) => {
+                    InspectorTest.expectTrue(responseContent.body.length, "Response `body` should not be empty.");
+                    InspectorTest.expectTrue(responseContent.base64Encoded, "Response should be base64 encoded.");
                 }).then(resolve, reject);
             }
         });

Modified: branches/safari-613-branch/LayoutTests/http/tests/inspector/network/resource-response-source-memory-cache-expected.txt (294296 => 294297)


--- branches/safari-613-branch/LayoutTests/http/tests/inspector/network/resource-response-source-memory-cache-expected.txt	2022-05-17 06:10:38 UTC (rev 294296)
+++ branches/safari-613-branch/LayoutTests/http/tests/inspector/network/resource-response-source-memory-cache-expected.txt	2022-05-17 06:10:43 UTC (rev 294297)
@@ -6,4 +6,6 @@
 PASS: Resource should exist.
 PASS: statusCode should be 200
 PASS: responseSource should be Symbol(memory-cache)
+PASS: Response `body` should not be empty.
+PASS: Response should not be base64 encoded.
 

Modified: branches/safari-613-branch/LayoutTests/http/tests/inspector/network/resource-response-source-memory-cache.html (294296 => 294297)


--- branches/safari-613-branch/LayoutTests/http/tests/inspector/network/resource-response-source-memory-cache.html	2022-05-17 06:10:38 UTC (rev 294296)
+++ branches/safari-613-branch/LayoutTests/http/tests/inspector/network/resource-response-source-memory-cache.html	2022-05-17 06:10:43 UTC (rev 294297)
@@ -32,6 +32,10 @@
                     InspectorTest.expectThat(resource instanceof WI.Resource, "Resource should exist.");
                     InspectorTest.expectEqual(resource.statusCode, statusCode, `statusCode should be ${statusCode}`);
                     InspectorTest.expectEqual(resource.responseSource, responseSource, `responseSource should be ${String(responseSource)}`);
+                    return resource.requestContentFromBackend();
+                }).then((responseContent) => {
+                    InspectorTest.expectTrue(responseContent.body.length, "Response `body` should not be empty.");
+                    InspectorTest.expectFalse(responseContent.base64Encoded, "Response should not be base64 encoded.");
                 }).then(resolve, reject);
             }
         });

Modified: branches/safari-613-branch/Source/WebCore/ChangeLog (294296 => 294297)


--- branches/safari-613-branch/Source/WebCore/ChangeLog	2022-05-17 06:10:38 UTC (rev 294296)
+++ branches/safari-613-branch/Source/WebCore/ChangeLog	2022-05-17 06:10:43 UTC (rev 294297)
@@ -1,5 +1,83 @@
 2022-05-16  Alan Coon  <alanc...@apple.com>
 
+        Cherry-pick r293264. rdar://problem/92130849
+
+    Web Inspector: Regression(r287684) Resources from the memory cache show empty content in Network, Sources, and Search tabs
+    https://bugs.webkit.org/show_bug.cgi?id=239667
+    
+    Reviewed by Devin Rousso.
+    
+    Source/WebCore:
+    
+    Updated tests:
+    - http/tests/inspector/network/resource-response-source-disk-cache.html
+    - http/tests/inspector/network/resource-response-source-memory-cache.html
+    
+    r287684 introduced a subtle bug when calling InspectorInstrumentation::didReceiveData. We rely
+    on there being a difference between real, but empty, data buffer and not having a data buffer,
+    but after r287684 an empty SharedBuffer would be passed in the later case. Instead, we should
+    continue to pass nullptr if there is no buffer so that InspectorNetworkAgent::didReceiveData
+    can distiguish between the two.
+    
+    The bug is the result of having a non-nullptr `data` in `InspectorNetworkAgent::didReceiveData`,
+    which causes us to call `maybeAddResourceData`, which means by the time
+    `InspectorNetworkAgent::getResponseBody` is called, the ResourceData for the request will have
+    an empty, not non-existant, `content()`, which means we will return the empty content instead,
+    since we believe the response had actual content.
+    
+    * inspector/InspectorInstrumentation.cpp:
+    (WebCore::InspectorInstrumentation::didReceiveDataImpl):
+    * inspector/InspectorInstrumentation.h:
+    (WebCore::InspectorInstrumentation::didReceiveData):
+    * loader/ResourceLoadNotifier.cpp:
+    (WebCore::ResourceLoadNotifier::dispatchDidReceiveData):
+    
+    LayoutTests:
+    
+    Add test steps to ensure that the resource has content, and that the base64Encoded value matches our
+    expectations. While only the memory cache was affected by this regression, add the test steps to both
+    the memory and disk caches to defend this functionality.
+    
+    * http/tests/inspector/network/resource-response-source-memory-cache-expected.txt:
+    * http/tests/inspector/network/resource-response-source-memory-cache.html:
+    * http/tests/inspector/network/resource-response-source-disk-cache-expected.txt:
+    * http/tests/inspector/network/resource-response-source-disk-cache.html:
+    
+    Canonical link: https://commits.webkit.org/249905@main
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@293264 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2022-04-22  Patrick Angle  <pan...@apple.com>
+
+            Web Inspector: Regression(r287684) Resources from the memory cache show empty content in Network, Sources, and Search tabs
+            https://bugs.webkit.org/show_bug.cgi?id=239667
+
+            Reviewed by Devin Rousso.
+
+            Updated tests:
+            - http/tests/inspector/network/resource-response-source-disk-cache.html
+            - http/tests/inspector/network/resource-response-source-memory-cache.html
+
+            r287684 introduced a subtle bug when calling InspectorInstrumentation::didReceiveData. We rely
+            on there being a difference between real, but empty, data buffer and not having a data buffer,
+            but after r287684 an empty SharedBuffer would be passed in the later case. Instead, we should
+            continue to pass nullptr if there is no buffer so that InspectorNetworkAgent::didReceiveData
+            can distiguish between the two.
+
+            The bug is the result of having a non-nullptr `data` in `InspectorNetworkAgent::didReceiveData`,
+            which causes us to call `maybeAddResourceData`, which means by the time
+            `InspectorNetworkAgent::getResponseBody` is called, the ResourceData for the request will have
+            an empty, not non-existant, `content()`, which means we will return the empty content instead,
+            since we believe the response had actual content.
+
+            * inspector/InspectorInstrumentation.cpp:
+            (WebCore::InspectorInstrumentation::didReceiveDataImpl):
+            * inspector/InspectorInstrumentation.h:
+            (WebCore::InspectorInstrumentation::didReceiveData):
+            * loader/ResourceLoadNotifier.cpp:
+            (WebCore::ResourceLoadNotifier::dispatchDidReceiveData):
+
+2022-05-16  Alan Coon  <alanc...@apple.com>
+
         Cherry-pick r293220. rdar://problem/91924480
 
     Apply purifyNaN in more places.

Modified: branches/safari-613-branch/Source/WebCore/inspector/InspectorInstrumentation.cpp (294296 => 294297)


--- branches/safari-613-branch/Source/WebCore/inspector/InspectorInstrumentation.cpp	2022-05-17 06:10:38 UTC (rev 294296)
+++ branches/safari-613-branch/Source/WebCore/inspector/InspectorInstrumentation.cpp	2022-05-17 06:10:43 UTC (rev 294297)
@@ -616,10 +616,10 @@
         networkAgent->didReceiveThreadableLoaderResponse(identifier, documentThreadableLoader);
 }
 
-void InspectorInstrumentation::didReceiveDataImpl(InstrumentingAgents& instrumentingAgents, ResourceLoaderIdentifier identifier, const SharedBuffer& buffer, int encodedDataLength)
+void InspectorInstrumentation::didReceiveDataImpl(InstrumentingAgents& instrumentingAgents, ResourceLoaderIdentifier identifier, const SharedBuffer* buffer, int encodedDataLength)
 {
     if (auto* networkAgent = instrumentingAgents.enabledNetworkAgent())
-        networkAgent->didReceiveData(identifier, &buffer, buffer.size(), encodedDataLength);
+        networkAgent->didReceiveData(identifier, buffer, buffer ? buffer->size() : 0, encodedDataLength);
 }
 
 void InspectorInstrumentation::didFinishLoadingImpl(InstrumentingAgents& instrumentingAgents, ResourceLoaderIdentifier identifier, DocumentLoader* loader, const NetworkLoadMetrics& networkLoadMetrics, ResourceLoader* resourceLoader)

Modified: branches/safari-613-branch/Source/WebCore/inspector/InspectorInstrumentation.h (294296 => 294297)


--- branches/safari-613-branch/Source/WebCore/inspector/InspectorInstrumentation.h	2022-05-17 06:10:38 UTC (rev 294296)
+++ branches/safari-613-branch/Source/WebCore/inspector/InspectorInstrumentation.h	2022-05-17 06:10:43 UTC (rev 294297)
@@ -193,7 +193,7 @@
     static void didLoadResourceFromMemoryCache(Page&, DocumentLoader*, CachedResource*);
     static void didReceiveResourceResponse(Frame&, ResourceLoaderIdentifier, DocumentLoader*, const ResourceResponse&, ResourceLoader*);
     static void didReceiveThreadableLoaderResponse(DocumentThreadableLoader&, ResourceLoaderIdentifier);
-    static void didReceiveData(Frame*, ResourceLoaderIdentifier, const SharedBuffer&, int encodedDataLength);
+    static void didReceiveData(Frame*, ResourceLoaderIdentifier, const SharedBuffer*, int encodedDataLength);
     static void didFinishLoading(Frame*, DocumentLoader*, ResourceLoaderIdentifier, const NetworkLoadMetrics&, ResourceLoader*);
     static void didFailLoading(Frame*, DocumentLoader*, ResourceLoaderIdentifier, const ResourceError&);
 
@@ -414,7 +414,7 @@
     static void didLoadResourceFromMemoryCacheImpl(InstrumentingAgents&, DocumentLoader*, CachedResource*);
     static void didReceiveResourceResponseImpl(InstrumentingAgents&, ResourceLoaderIdentifier, DocumentLoader*, const ResourceResponse&, ResourceLoader*);
     static void didReceiveThreadableLoaderResponseImpl(InstrumentingAgents&, DocumentThreadableLoader&, ResourceLoaderIdentifier);
-    static void didReceiveDataImpl(InstrumentingAgents&, ResourceLoaderIdentifier, const SharedBuffer&, int encodedDataLength);
+    static void didReceiveDataImpl(InstrumentingAgents&, ResourceLoaderIdentifier, const SharedBuffer*, int encodedDataLength);
     static void didFinishLoadingImpl(InstrumentingAgents&, ResourceLoaderIdentifier, DocumentLoader*, const NetworkLoadMetrics&, ResourceLoader*);
     static void didFailLoadingImpl(InstrumentingAgents&, ResourceLoaderIdentifier, DocumentLoader*, const ResourceError&);
     static void willLoadXHRSynchronouslyImpl(InstrumentingAgents&);
@@ -1082,7 +1082,7 @@
         didReceiveThreadableLoaderResponseImpl(*agents, documentThreadableLoader, identifier);
 }
     
-inline void InspectorInstrumentation::didReceiveData(Frame* frame, ResourceLoaderIdentifier identifier, const SharedBuffer& buffer, int encodedDataLength)
+inline void InspectorInstrumentation::didReceiveData(Frame* frame, ResourceLoaderIdentifier identifier, const SharedBuffer* buffer, int encodedDataLength)
 {
     FAST_RETURN_IF_NO_FRONTENDS(void());
     if (auto* agents = instrumentingAgents(frame))
@@ -1092,7 +1092,7 @@
 inline void InspectorInstrumentation::didReceiveData(WorkerOrWorkletGlobalScope& globalScope, ResourceLoaderIdentifier identifier, const SharedBuffer& buffer)
 {
     FAST_RETURN_IF_NO_FRONTENDS(void());
-    didReceiveDataImpl(instrumentingAgents(globalScope), identifier, buffer, buffer.size());
+    didReceiveDataImpl(instrumentingAgents(globalScope), identifier, &buffer, buffer.size());
 }
 
 inline void InspectorInstrumentation::didFinishLoading(Frame* frame, DocumentLoader* loader, ResourceLoaderIdentifier identifier, const NetworkLoadMetrics& networkLoadMetrics, ResourceLoader* resourceLoader)

Modified: branches/safari-613-branch/Source/WebCore/loader/ResourceLoadNotifier.cpp (294296 => 294297)


--- branches/safari-613-branch/Source/WebCore/loader/ResourceLoadNotifier.cpp	2022-05-17 06:10:38 UTC (rev 294296)
+++ branches/safari-613-branch/Source/WebCore/loader/ResourceLoadNotifier.cpp	2022-05-17 06:10:43 UTC (rev 294297)
@@ -160,7 +160,7 @@
     Ref<Frame> protect(m_frame);
     m_frame.loader().client().dispatchDidReceiveContentLength(loader, identifier, expectedDataLength);
 
-    InspectorInstrumentation::didReceiveData(&m_frame, identifier, buffer ? *buffer : SharedBuffer::create(), encodedDataLength);
+    InspectorInstrumentation::didReceiveData(&m_frame, identifier, buffer, encodedDataLength);
 }
 
 void ResourceLoadNotifier::dispatchDidFinishLoading(DocumentLoader* loader, ResourceLoaderIdentifier identifier, const NetworkLoadMetrics& networkLoadMetrics, ResourceLoader* resourceLoader)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to