Bug 234015 - Propagate app-initiated state to new ResourceRequests
Summary: Propagate app-initiated state to new ResourceRequests
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Brent Fulgham
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-12-08 10:12 PST by Brent Fulgham
Modified: 2021-12-21 22:37 PST (History)
7 users (show)

See Also:


Attachments
WIP Patch (16.41 KB, patch)
2021-12-08 10:17 PST, Brent Fulgham
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (17.85 KB, patch)
2021-12-08 11:18 PST, Brent Fulgham
no flags Details | Formatted Diff | Diff
WIP Patch (33.63 KB, patch)
2021-12-20 17:55 PST, Brent Fulgham
no flags Details | Formatted Diff | Diff
Patch (33.63 KB, patch)
2021-12-21 10:28 PST, Brent Fulgham
no flags Details | Formatted Diff | Diff
Patch (36.70 KB, patch)
2021-12-21 12:31 PST, Brent Fulgham
no flags Details | Formatted Diff | Diff
Patch (31.98 KB, patch)
2021-12-21 16:22 PST, Brent Fulgham
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brent Fulgham 2021-12-08 10:12:38 PST
While reviewing logging we have found that some ResourceRequest objects are missing the correct state for app-initiated loads. Typically, these are cases where a new ResourceRequest is created from a URL string, losing the context that came with the original load (or the context of the page triggering the load).

This patch corrects a number of such cases.
Comment 1 Brent Fulgham 2021-12-08 10:14:55 PST
<rdar://problem/86128638>
Comment 2 Brent Fulgham 2021-12-08 10:17:39 PST
Created attachment 446382 [details]
WIP Patch
Comment 3 Kate Cheney 2021-12-08 10:48:35 PST
Comment on attachment 446382 [details]
WIP Patch

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

Thanks for covering these cases. r=me with gtk/wpe/wincairo/win fixes.

> Source/WebCore/Modules/websockets/WebSocketChannel.cpp:97
> +    if (auto* documentLoader = m_document->loader())

Seems like you may need to #include DocumentLoader.h here for GTK and WPE.

> Source/WebCore/loader/FrameLoader.cpp:3058
> +    workingResourceRequest.setIsAppInitiated(inRequest.isAppInitiated());

We set this in updateRequestAndAddExtraFields which is called below, so no need to do it here.
Comment 4 Brent Fulgham 2021-12-08 11:17:29 PST
Comment on attachment 446382 [details]
WIP Patch

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

>> Source/WebCore/Modules/websockets/WebSocketChannel.cpp:97
>> +    if (auto* documentLoader = m_document->loader())
> 
> Seems like you may need to #include DocumentLoader.h here for GTK and WPE.

Will do!

>> Source/WebCore/loader/FrameLoader.cpp:3058
>> +    workingResourceRequest.setIsAppInitiated(inRequest.isAppInitiated());
> 
> We set this in updateRequestAndAddExtraFields which is called below, so no need to do it here.

Ah! Good catch. Will remove.
Comment 5 Brent Fulgham 2021-12-08 11:18:19 PST
Created attachment 446391 [details]
Patch
Comment 6 Brent Fulgham 2021-12-20 17:55:52 PST
Created attachment 447671 [details]
WIP Patch
Comment 7 Brent Fulgham 2021-12-20 17:56:35 PST
Comment on attachment 447671 [details]
WIP Patch

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

> Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp:239
> +            WTFReportBacktraceWithPrefix("WebLoaderStrategy");

This debugging code should not be landed.
Comment 8 Brent Fulgham 2021-12-21 10:28:52 PST
Created attachment 447731 [details]
Patch
Comment 9 Kate Cheney 2021-12-21 10:45:01 PST
Comment on attachment 447731 [details]
Patch

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

One thing to note is only the main frame's document loader holds the correct value, so there may be some places where we need to check that value instead of the current document's loader.

> Source/WebCore/loader/FrameLoader.cpp:978
> +        frameLoadRequest.resourceRequest().setIsAppInitiated(*appInitiated);

I think this one is unnecessary because loadURL() called below will call updateRequestAndAddExtraFields which will set the value.

> Source/WebKit/NetworkProcess/cache/NetworkCacheSubresourcesEntry.cpp:50
> +    encoder << m_isAppInitiated;

Good catch.
Comment 10 Kate Cheney 2021-12-21 11:05:06 PST
Comment on attachment 447731 [details]
Patch

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

> Source/WebCore/loader/NavigationScheduler.cpp:198
> +            resourceRequest.setIsAppInitiated(documentLoader->lastNavigationWasAppInitiated());

I think this will also always end up in a frame loader function that calls updateRequestAndAddExtraFields, so it is not needed.

> Source/WebCore/loader/NavigationScheduler.cpp:232
> +            resourceRequest.setIsAppInitiated(documentLoader->lastNavigationWasAppInitiated());

Ditto

> Source/WebCore/loader/NavigationScheduler.cpp:261
> +            resourceRequest.setIsAppInitiated(documentLoader->lastNavigationWasAppInitiated());

Ditto.

> Source/WebCore/loader/NavigationScheduler.cpp:378
> +            resourceRequest.setIsAppInitiated(documentLoader->lastNavigationWasAppInitiated());

Ditto.

> Source/WebCore/loader/NavigationScheduler.cpp:482
> +            resourceRequest.setIsAppInitiated(documentLoader->lastNavigationWasAppInitiated());

Ditto.

> Source/WebCore/page/DOMWindow.cpp:2545
> +            resourceRequest.setIsAppInitiated(documentLoader->lastNavigationWasAppInitiated());

Ditto here. changeLocation calls loadFrameRequest which calls loadURL or loadPostRequest which will both eventually call updateRequestAndAddExtraFields.

> Source/WebCore/page/DragController.cpp:300
> +        resourceRequest.setIsAppInitiated(documentLoader->lastNavigationWasAppInitiated());

Here too.
Comment 11 Brent Fulgham 2021-12-21 12:31:13 PST
Created attachment 447742 [details]
Patch
Comment 12 Brent Fulgham 2021-12-21 16:22:58 PST
Created attachment 447763 [details]
Patch
Comment 13 EWS 2021-12-21 22:37:27 PST
Committed r287348 (245490@main): <https://commits.webkit.org/245490@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 447763 [details].