Bug 237245

Summary: Trigger PDF download in captive portal mode instead of using PDF viewer
Product: WebKit Reporter: Tim Nguyen (:ntim) <ntim>
Component: PDFAssignee: pascoe <pascoe>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, cdumez, pascoe, thorton, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch for landing none

Description Tim Nguyen (:ntim) 2022-02-27 03:02:50 PST
I think that was the decision taken since PDF.js is not in a good enough state atm.
Comment 1 Radar WebKit Bug Importer 2022-02-27 03:03:54 PST
<rdar://problem/89525531>
Comment 2 Tim Nguyen (:ntim) 2022-03-14 07:04:26 PDT
Created attachment 454590 [details]
Patch
Comment 3 pascoe@apple.com 2022-03-17 09:50:11 PDT
Created attachment 454982 [details]
Patch
Comment 4 Alex Christensen 2022-03-17 10:36:00 PDT
Comment on attachment 454982 [details]
Patch

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

> Source/WebKit/UIProcess/WebPageProxy.cpp:3466
> +        auto mimeType = MIMETypeRegistry::mimeTypeForPath(navigation->currentRequest().url().path().toString());

This seems a little light weight.  Don't we even want to look at the mime type of the response?
Comment 5 Tim Nguyen (:ntim) 2022-03-17 12:32:10 PDT
Comment on attachment 454982 [details]
Patch

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

>> Source/WebKit/UIProcess/WebPageProxy.cpp:3466
>> +        auto mimeType = MIMETypeRegistry::mimeTypeForPath(navigation->currentRequest().url().path().toString());
> 
> This seems a little light weight.  Don't we even want to look at the mime type of the response?

There's no access to the response at this point. Do you have a suggestion of a good place to put this where there is access to the response?
Comment 6 Chris Dumez 2022-03-17 12:36:31 PDT
Comment on attachment 454982 [details]
Patch

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

>>> Source/WebKit/UIProcess/WebPageProxy.cpp:3466
>>> +        auto mimeType = MIMETypeRegistry::mimeTypeForPath(navigation->currentRequest().url().path().toString());
>> 
>> This seems a little light weight.  Don't we even want to look at the mime type of the response?
> 
> There's no access to the response at this point. Do you have a suggestion of a good place to put this where there is access to the response?

WebPageProxy::receivedPolicyDecision or WebPageProxy::decidePolicyForResponseShared. This is always frequently where we trigger downloads.
Comment 7 Chris Dumez 2022-03-17 12:38:10 PDT
(In reply to Tim Nguyen (:ntim) from comment #5)
> Comment on attachment 454982 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=454982&action=review
> 
> >> Source/WebKit/UIProcess/WebPageProxy.cpp:3466
> >> +        auto mimeType = MIMETypeRegistry::mimeTypeForPath(navigation->currentRequest().url().path().toString());
> > 
> > This seems a little light weight.  Don't we even want to look at the mime type of the response?
> 
> There's no access to the response at this point. Do you have a suggestion of
> a good place to put this where there is access to the response?

Purely relying on the URL ending with .pdf is weak and will miss plenty of cases where we're actually loading a PDF. Like Alex says, we need to check the content type in the resource response.
Comment 8 pascoe@apple.com 2022-03-17 13:48:59 PDT
Created attachment 455019 [details]
Patch
Comment 9 Tim Nguyen (:ntim) 2022-03-17 14:43:31 PDT
Comment on attachment 455019 [details]
Patch

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

> Source/WebKit/UIProcess/WebPageProxy.cpp:5735
> +        auto captivePortalMode = (policies ? policies->captivePortalModeEnabled() : shouldEnableCaptivePortalMode()) ? WebProcessProxy::CaptivePortalMode::Enabled : WebProcessProxy::CaptivePortalMode::Disabled;
> +        if (captivePortalMode == WebProcessProxy::CaptivePortalMode::Enabled && MIMETypeRegistry::isPDFOrPostScriptMIMEType(navigationResponse->response().mimeType()))

I'm not sure if this works, but I think you can do:

```
if (process->captivePortalMode() == WebProcessProxy::CaptivePortalMode::Enabled)
```

directly, instead of checking through policies. Though I might be wrong :)
Comment 10 Chris Dumez 2022-03-18 07:18:20 PDT
Comment on attachment 455019 [details]
Patch

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

r=me with Tim's proposed change.

>> Source/WebKit/UIProcess/WebPageProxy.cpp:5735
>> +        if (captivePortalMode == WebProcessProxy::CaptivePortalMode::Enabled && MIMETypeRegistry::isPDFOrPostScriptMIMEType(navigationResponse->response().mimeType()))
> 
> I'm not sure if this works, but I think you can do:
> 
> ```
> if (process->captivePortalMode() == WebProcessProxy::CaptivePortalMode::Enabled)
> ```
> 
> directly, instead of checking through policies. Though I might be wrong :)

I agree with Tim here. His proposal is simpler and I believe it would work since we would have already switched to a captive-portal-mode process earlier (during navigation policy decision).
Comment 11 pascoe@apple.com 2022-03-18 08:36:44 PDT
Created attachment 455095 [details]
Patch
Comment 12 Tim Nguyen (:ntim) 2022-03-18 08:41:25 PDT
Comment on attachment 455095 [details]
Patch

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

> Source/WebKit/UIProcess/WebPageProxy.cpp:5726
> +        process, navigationResponse] (PolicyAction policyAction, API::WebsitePolicies* policies, ProcessSwapRequestedByClient processSwapRequestedByClient, RefPtr<SafeBrowsingWarning>&& safeBrowsingWarning, std::optional<NavigatingToAppBoundDomain> isNavigatingToAppBoundDomain) mutable {

nit: please undo this change, which should no longer be necessary
Comment 13 pascoe@apple.com 2022-03-18 08:44:31 PDT
Created attachment 455096 [details]
Patch for landing
Comment 14 pascoe@apple.com 2022-03-18 08:45:30 PDT
Thank you Tim, Chris, and Alex for the comments and review!
Comment 15 EWS 2022-03-18 12:12:22 PDT
Committed r291491 (248603@main): <https://commits.webkit.org/248603@main>

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