Bug 237120 - WebKit continues to render PDF images in Captive Portal mode
Summary: WebKit continues to render PDF images in Captive Portal mode
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: 2022-02-23 15:57 PST by Brent Fulgham
Modified: 2022-02-25 16:03 PST (History)
8 users (show)

See Also:


Attachments
Patch (9.87 KB, patch)
2022-02-23 16:29 PST, Brent Fulgham
no flags Details | Formatted Diff | Diff
Patch (71.29 KB, patch)
2022-02-24 16:47 PST, Brent Fulgham
no flags Details | Formatted Diff | Diff
Patch (66.92 KB, patch)
2022-02-25 13:06 PST, Brent Fulgham
no flags Details | Formatted Diff | Diff
Patch for landing (57.86 KB, patch)
2022-02-25 14:38 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 2022-02-23 15:57:38 PST
We should hand PDF off to PDF.js when CaptivePortal mode is enabled. However, images continue to be processed using native PDF decoding.
Comment 1 Radar WebKit Bug Importer 2022-02-23 16:07:25 PST
<rdar://problem/89384234>
Comment 2 Brent Fulgham 2022-02-23 16:09:06 PST
This should not work in CaptivePortal mode, but currently renders:

<img width="150px" height="100px" src="images/webkit-logo.pdf">
Comment 3 Brent Fulgham 2022-02-23 16:29:20 PST
Created attachment 453050 [details]
Patch
Comment 4 Brent Fulgham 2022-02-24 16:47:19 PST
Created attachment 453157 [details]
Patch
Comment 5 Chris Dumez 2022-02-24 17:02:21 PST
Comment on attachment 453157 [details]
Patch

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

> Source/WebCore/loader/cache/CachedResourceLoader.cpp:122
> +        return new CachedImage(WTFMove(request), sessionID, cookieJar, settings.captivePortalModeEnabled() ? Image::UseRestrictedDecoder::Yes : Image::UseRestrictedDecoder::No);

This is a bit weird since settings are per page but CachedImages can totally be shared between pages. The MemoryCache (which stores the CachedImages) is a singleton object inside the process.
As a matter of fact, cachePortalMode is process-global too. As a result, it seems we're passing flags around and adding a data member to CachedImage unnecessarily.

It makes it look like we could support one page have restricted decoder for one page but not for another in the same process, which is just not possible at the moment since they may share the same CachedImage if both pages were to display the same image.

As a result, my suggestion would be to not add a CaptivePortalModeEnabled setting on the page. Instead, it should be some kind of global flag.
Maybe a static variable on Image or a flag on RuntimeEnabledFeatures (which is a singleton), or somewhere else that is global.

Also note that until now, our flags were about specific features, WebCore was not aware of captive portal mode, which I thought was nice to keep at the WebKit/Process model layer.
So maybe the flag could be about PDF images?
Comment 6 Brent Fulgham 2022-02-25 13:06:14 PST
Created attachment 453248 [details]
Patch
Comment 7 Chris Dumez 2022-02-25 13:16:57 PST
Comment on attachment 453248 [details]
Patch

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

r=me with changes.

> Source/WebCore/page/RuntimeEnabledFeatures.h:204
> +    void setPDFImagesEnabled(bool isEnabled) { m_pdfImagesEnabled = isEnabled; }

Per WebKit coding style, Boolean variables need a prefix. Should be something like:
void setArePDFImagesEnabled(bool arePDFImagesEnabled) { m_arePDFImagesEnabled = arePDFImagesEnabled; }

> Source/WebCore/page/RuntimeEnabledFeatures.h:205
> +    bool pdfImagesEnabled() const { return m_pdfImagesEnabled; }

bool arePDFImagesEnabled() const { return m_arePDFImagesEnabled; }

> Source/WebCore/page/RuntimeEnabledFeatures.h:360
> +    bool m_pdfImagesEnabled { true };

ditto.

> Source/WebKit/WebProcess/WebPage/WebPage.cpp:4074
> +        RuntimeEnabledFeatures::sharedFeatures().setPDFImagesEnabled(false);

This has nothing to do with the page, it is process-wide.
As a result, I think this call should be in the WebProcess constructor, right after we initialize WebProcess::m_isCaptivePortalModeEnabled.

> Tools/ChangeLog:20
> +        * TestWebKitAPI/Tests/WebKitCocoa/missing.png: Added.

I think we can probably omit this one.

> Tools/TestWebKitAPI/Tests/WebKitCocoa/CaptivePortalPDF.html:3
> +        <style>

Why the styling for an API test?

> Tools/TestWebKitAPI/Tests/WebKitCocoa/CaptivePortalPDF.html:20
> +        <h1>Captive Portal Mode - PDF Test</h1>

This is not a layout test and I don't think we need so much HTML code for an API test. I don't think these tests are expected to work when loading manually in the browser.
It's not like the window.webkit.messageHandlers.testHandler would exist in the browser anyway.

> Tools/TestWebKitAPI/Tests/WebKitCocoa/CaptivePortalPDF.html:30
> +                <td><img width="150px" height="100px" src="missing.png"></td>

What's the purpose on the second image in this test? Seems like we could just omit it, or am I missing something?
Comment 8 Brent Fulgham 2022-02-25 14:13:21 PST
Comment on attachment 453248 [details]
Patch

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

>> Source/WebCore/page/RuntimeEnabledFeatures.h:204
>> +    void setPDFImagesEnabled(bool isEnabled) { m_pdfImagesEnabled = isEnabled; }
> 
> Per WebKit coding style, Boolean variables need a prefix. Should be something like:
> void setArePDFImagesEnabled(bool arePDFImagesEnabled) { m_arePDFImagesEnabled = arePDFImagesEnabled; }

Will do!

>> Source/WebKit/WebProcess/WebPage/WebPage.cpp:4074
>> +        RuntimeEnabledFeatures::sharedFeatures().setPDFImagesEnabled(false);
> 
> This has nothing to do with the page, it is process-wide.
> As a result, I think this call should be in the WebProcess constructor, right after we initialize WebProcess::m_isCaptivePortalModeEnabled.

Ah! Good point -- will fix.

>> Tools/ChangeLog:20
>> +        * TestWebKitAPI/Tests/WebKitCocoa/missing.png: Added.
> 
> I think we can probably omit this one.

Will do.
Comment 9 Brent Fulgham 2022-02-25 14:38:42 PST
Created attachment 453265 [details]
Patch for landing
Comment 10 EWS 2022-02-25 16:03:36 PST
Committed r290534 (247813@main): <https://commits.webkit.org/247813@main>

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