Bug 213283

Summary: Web Inspector: request / response interception trims resource type
Product: WebKit Reporter: Pavel Feldman <pfeldman>
Component: Web InspectorAssignee: Pavel Feldman <pfeldman>
Status: NEW ---    
Severity: Normal CC: bburg, cdumez, ews-watchlist, hi, inspector-bugzilla-changes, japhet, joepeck
Priority: P2    
Version: WebKit Nightly Build   
Hardware: All   
OS: All   
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch none

Description Pavel Feldman 2020-06-16 22:10:34 PDT
Will add failing test shortly.
Comment 1 Pavel Feldman 2020-06-16 22:12:32 PDT
Created attachment 402079 [details]
Patch
Comment 2 Pavel Feldman 2020-06-18 13:29:45 PDT
Created attachment 402232 [details]
Patch
Comment 3 Pavel Feldman 2020-06-18 13:50:38 PDT
Created attachment 402234 [details]
Patch
Comment 4 Pavel Feldman 2020-06-18 16:22:29 PDT
Created attachment 402247 [details]
Patch
Comment 5 Pavel Feldman 2020-06-18 20:32:41 PDT
Created attachment 402265 [details]
Patch
Comment 6 Pavel Feldman 2020-06-19 15:44:22 PDT
Created attachment 402340 [details]
Patch
Comment 7 Pavel Feldman 2020-06-19 17:31:58 PDT
Created attachment 402359 [details]
Patch
Comment 8 Devin Rousso 2020-06-22 18:43:16 PDT
Comment on attachment 402359 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=402359&action=review

What type is shown for cases like `<script src="https://example.org/definitely-not-a-script.html">`?  I would expect it to still have the requester type (e.g. script), which also matches the current functionality AFAICT.

Have you audited all of the places where a `ResourceRequest` is created to see if it should set a `ResourceRequest::Requester`?  Perhaps we should also add a `ResourceRequest::Requester` as a constructor parameter so that future manually created requests have to think about that too.

> Source/WebCore/inspector/NetworkResourcesData.h:71
> +        ResourceRequest::Requester requester() const { return m_requester; }

we should add `#include "ResourceRequest.h"`

> Source/WebCore/inspector/agents/InspectorNetworkAgent.cpp:-448
> -        else if (loader && equalIgnoringFragmentIdentifier(request.url(), loader->url()) && !loader->isCommitted())
> -            type = InspectorPageAgent::DocumentResource;
> -        else if (loader) {
> -            for (auto& linkIcon : loader->linkIcons()) {
> -                if (equalIgnoringFragmentIdentifier(request.url(), linkIcon.url)) {
> -                    type = InspectorPageAgent::ImageResource;
> -                    break;
> -                }
> -            }
> -        }

Are these paths also covered by the new logic?

> Source/WebCore/inspector/agents/InspectorPageAgent.cpp:216
> +Inspector::Protocol::Page::ResourceType InspectorPageAgent::resourceTypeJSON(ResourceRequest::Requester requester)

We should rename this to something more explicit/understandable, like `InspectorPageAgent::protocolResourceTypeForResourceRequester`.

> Source/WebCore/loader/PingLoader.cpp:211
> +        InspectorInstrumentation::willSendRequest(&frame, identifier, frame.loader().activeDocumentLoader(), request, ResourceResponse());

It seems like not all paths to this function have set a `ResourceRequest::Requester::Ping`.  Are we sure that those cases will still be covered after removing this code?

> Source/WebCore/loader/cache/CachedResource.cpp:311
> +        InspectorInstrumentation::willSendRequest(&frame, identifier, frameLoader.activeDocumentLoader(), request, ResourceResponse());

Do we know with certainty that `ResourceRequest::Requester::Beacon` has been set by this point?

> Source/WebCore/loader/cache/CachedResourceRequest.cpp:203
> +    default:
> +        // Only cherry-pick the ones below, leave the rest unspecified.
> +        return;

NIT: personally, I'd rather not use a `default` and instead list the remaining `CachedResource::Type` values so that future changes must also considered for this codepath

> LayoutTests/http/tests/inspector/network/interception-preserves-type.html:31
> +        name: "Network.requestIntercepted.resourceType baseline",

NIT: we usually don't use spaces in test case names, preferring camel casing and periods.

> LayoutTests/http/tests/inspector/network/interception-preserves-type.html:37
> +                RuntimeAgent.evaluate("loadSubresource('resources/stylesheet.css?baseline')"),

NIT: `InspectorTest.evaluateInPage`?

> LayoutTests/http/tests/inspector/network/interception-preserves-type.html:51
> +                RuntimeAgent.evaluate("loadSubresource('resources/stylesheet.css?request')"),

Ditto (:37)

> LayoutTests/http/tests/inspector/network/interception-preserves-type.html:55
> +        }

NIT: I don't think it matters, but should we continue the interception so that it's not just left hanging?

> LayoutTests/http/tests/inspector/network/interception-preserves-type.html:59
> +        name: "Network.responseIntercepted.resourceType",

NIT: we usually prefix the test case name with the suite name (though I get what you're trying to go for here, so perhaps just change the suite name to be more general instead of specific to "request" such as "Network.InterceptionPreservesType")

> LayoutTests/http/tests/inspector/network/interception-preserves-type.html:65
> +                RuntimeAgent.evaluate("loadSubresource('resources/stylesheet.css?response')"),

Ditto (:37)

> LayoutTests/http/tests/inspector/network/interception-preserves-type.html:69
> +        }

Ditto (:55)
Comment 9 BJ Burg 2020-09-09 11:48:08 PDT
Comment on attachment 402359 [details]
Patch

Clearing r? as there is unaddressed review feedback and the patch is now stale.