Bug 220981

Summary: Load data URLs in the web process also for synchronous loads
Product: WebKit Reporter: Carlos Garcia Campos <cgarcia>
Component: WebKit2Assignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, annulen, aperez, cdumez, ews-watchlist, gyuyoung.kim, japhet, lmoura, ryuan.choi, sergio, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=220509
Bug Depends on:    
Bug Blocks: 220764    
Attachments:
Description Flags
Patch
ews-feeder: commit-queue-
Patch
ews-feeder: commit-queue-
Patch
none
Patch
aperez: review+, achristensen: commit-queue-
Patch for landing none

Description Carlos Garcia Campos 2021-01-26 07:32:52 PST
In r271879 I removed the support for data URLs in the network process for soup, assuming data URLs were always loaded from the web process, but that's not the case for synchronous loads. We don't need to go to the network process for sync loads.
Comment 1 Carlos Garcia Campos 2021-01-26 07:41:12 PST
Created attachment 418418 [details]
Patch
Comment 2 Carlos Garcia Campos 2021-01-26 07:49:46 PST
It seems it's failing to find <WebCore/DataURLDecoder.h>. Aren't forwarding headers automatic in mac? I added the header to Source/WebCore/Headers.cmake
Comment 3 Carlos Garcia Campos 2021-01-27 00:40:08 PST
*** Bug 221023 has been marked as a duplicate of this bug. ***
Comment 4 Carlos Garcia Campos 2021-01-27 03:55:18 PST
Created attachment 418525 [details]
Patch
Comment 5 Carlos Garcia Campos 2021-01-27 04:03:23 PST
Created attachment 418526 [details]
Patch
Comment 6 Carlos Garcia Campos 2021-01-27 04:10:30 PST
Created attachment 418528 [details]
Patch
Comment 7 Alex Christensen 2021-01-27 15:01:22 PST
Comment on attachment 418528 [details]
Patch

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

> Source/WebCore/platform/network/DataURLDecoder.cpp:221
> +    bool success = task->process();

I don't think we need a local variable here.  I think the function logic would look simpler like this:

if (!task->process())
    return WTF::nullopt;
if (task->isBase64) {
    if (!decodeBase64(*task, mode))
        return WTF::nullopt;
} else
    decodeEscaped(*task);
return WTFMove(task->result);

Also, this whole thing is duplicate code.  I think this function should be called decodeSynchronously and decode should call it.

> Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp:547
> +    result.response.setHTTPStatusCode(200);

This is adding duplicate code with ResourceLoader::loadDataURL.  Could we make them share code?

> Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp:601
> +        auto syncLoadResult = loadDataURLSynchronously(request);

WebLoaderStrategy::loadResourceSynchronously should return a SyncLoadResult instead of taking error, response, and data as out params.
Comment 8 Carlos Garcia Campos 2021-01-28 03:00:55 PST
Comment on attachment 418528 [details]
Patch

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

>> Source/WebCore/platform/network/DataURLDecoder.cpp:221
>> +    bool success = task->process();
> 
> I don't think we need a local variable here.  I think the function logic would look simpler like this:
> 
> if (!task->process())
>     return WTF::nullopt;
> if (task->isBase64) {
>     if (!decodeBase64(*task, mode))
>         return WTF::nullopt;
> } else
>     decodeEscaped(*task);
> return WTFMove(task->result);
> 
> Also, this whole thing is duplicate code.  I think this function should be called decodeSynchronously and decode should call it.

Ok, I'll moved the common parts, the whole function can't be used from the async function because the task creation is different.

>> Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp:547
>> +    result.response.setHTTPStatusCode(200);
> 
> This is adding duplicate code with ResourceLoader::loadDataURL.  Could we make them share code?

Yes.

>> Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp:601
>> +        auto syncLoadResult = loadDataURLSynchronously(request);
> 
> WebLoaderStrategy::loadResourceSynchronously should return a SyncLoadResult instead of taking error, response, and data as out params.

SyncLoadResult is private. We could make it public and update all the callers, but I think that refactoring is out of scope of this bug.
Comment 9 Carlos Garcia Campos 2021-01-28 03:08:25 PST
Created attachment 418633 [details]
Patch for landing
Comment 10 Carlos Garcia Campos 2021-01-28 04:40:54 PST
Committed r272009: <https://trac.webkit.org/changeset/272009>
Comment 11 Radar WebKit Bug Importer 2021-01-28 04:41:15 PST
<rdar://problem/73704517>