Bug 209686 - [iOS] Delay process suspension for a while after loading an app link
Summary: [iOS] Delay process suspension for a while after loading an app link
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-03-27 15:34 PDT by Chris Dumez
Modified: 2020-03-29 02:09 PDT (History)
6 users (show)

See Also:


Attachments
Patch (5.56 KB, patch)
2020-03-27 15:38 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (5.73 KB, patch)
2020-03-27 16:10 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Follow-up (1.78 KB, patch)
2020-03-27 19:34 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2020-03-27 15:34:04 PDT
Delay process suspension for a while after loading an app link. This will allow the page's script to pass information more reliably to the native app handling the navigation.
Comment 1 Chris Dumez 2020-03-27 15:34:36 PDT
<rdar://problem/60888891>
Comment 2 Chris Dumez 2020-03-27 15:38:24 PDT
Created attachment 394765 [details]
Patch
Comment 3 Darin Adler 2020-03-27 15:49:42 PDT
Comment on attachment 394765 [details]
Patch

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

> Source/WebKit/ChangeLog:13
> +        This patch adds a [WKWebView _willOpenAppLink] SPI that the client needs to call before opening the
> +        app link.

Why SPI instead of API?

> Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm:1550
> +    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(25 * NSEC_PER_SEC)), dispatch_get_main_queue(), [weakThis = makeWeakPtr(*this)] {

Seems like typecasting 25 seconds to int64_t *after* doing the multiplication is too late to avoid overflow. I understand know why a typecast is needed at all, but if one is needed, I’d think we’d need to cast before doing the math.

The comment should explain where the 25 second duration comes from, its rationale, so someone doesn’t just change it randomly later without understanding how we chose 25 seconds.
Comment 4 Chris Dumez 2020-03-27 15:52:39 PDT
(In reply to Darin Adler from comment #3)
> Comment on attachment 394765 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=394765&action=review
> 
> > Source/WebKit/ChangeLog:13
> > +        This patch adds a [WKWebView _willOpenAppLink] SPI that the client needs to call before opening the
> > +        app link.
> 
> Why SPI instead of API?

For now, I am merely trying to address the issue in MobileSafari and SVC so an SPI is sufficient. I am not aware of this being requested by app developers. If it ever does, we can think about it harder and provide some kind of SPI.

> 
> > Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm:1550
> > +    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(25 * NSEC_PER_SEC)), dispatch_get_main_queue(), [weakThis = makeWeakPtr(*this)] {
> 
> Seems like typecasting 25 seconds to int64_t *after* doing the
> multiplication is too late to avoid overflow. I understand know why a
> typecast is needed at all, but if one is needed, I’d think we’d need to cast
> before doing the math.
> 
> The comment should explain where the 25 second duration comes from, its
> rationale, so someone doesn’t just change it randomly later without
> understanding how we chose 25 seconds.

I will check. I copy / pasted from existing code :)
Comment 5 Chris Dumez 2020-03-27 16:10:50 PDT
Created attachment 394768 [details]
Patch
Comment 6 EWS 2020-03-27 16:44:52 PDT
Committed r259146: <https://trac.webkit.org/changeset/259146>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 394768 [details].
Comment 7 Darin Adler 2020-03-27 16:58:01 PDT
Comment on attachment 394765 [details]
Patch

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

>>> Source/WebKit/ChangeLog:13
>>> +        app link.
>> 
>> Why SPI instead of API?
> 
> For now, I am merely trying to address the issue in MobileSafari and SVC so an SPI is sufficient. I am not aware of this being requested by app developers. If it ever does, we can think about it harder and provide some kind of SPI.

Not needed by other iOS browsers?
Comment 8 Chris Dumez 2020-03-27 18:43:01 PDT
(In reply to Darin Adler from comment #7)
> Comment on attachment 394765 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=394765&action=review
> 
> >>> Source/WebKit/ChangeLog:13
> >>> +        app link.
> >> 
> >> Why SPI instead of API?
> > 
> > For now, I am merely trying to address the issue in MobileSafari and SVC so an SPI is sufficient. I am not aware of this being requested by app developers. If it ever does, we can think about it harder and provide some kind of SPI.
> 
> Not needed by other iOS browsers?

Looks like in other apps than Safari, WebKit takes care of opening AppLinks in tryInterceptNavigation(), in NavigationState.mm. I will update that method in a follow-up.
Comment 9 Chris Dumez 2020-03-27 19:31:50 PDT
Reopening for follow-up.
Comment 10 Chris Dumez 2020-03-27 19:34:44 PDT
Created attachment 394783 [details]
Follow-up
Comment 11 EWS 2020-03-28 19:05:46 PDT
Committed r259166: <https://trac.webkit.org/changeset/259166>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 394783 [details].
Comment 12 Darin Adler 2020-03-28 22:55:33 PDT
Comment on attachment 394783 [details]
Follow-up

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

> Source/WebKit/UIProcess/Cocoa/NavigationState.mm:511
> +            if (success && weakPage)
> +                weakPage->willOpenAppLink();

This breaking the build on newer versions of Mac. Needs to be inside #if PLATFORM(IOS_FAMILY) because the code in WebPageProxy.h is inside that.
Comment 13 David Kilzer (:ddkilzer) 2020-03-29 02:09:44 PDT
Comment on attachment 394783 [details]
Follow-up

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

>> Source/WebKit/UIProcess/Cocoa/NavigationState.mm:511
>> +                weakPage->willOpenAppLink();
> 
> This breaking the build on newer versions of Mac. Needs to be inside #if PLATFORM(IOS_FAMILY) because the code in WebPageProxy.h is inside that.

Fixed in commit r259177:  <https://trac.webkit.org/changeset/259177/webkit>
Fixed my missing ChangeLog entry in r259178:  <https://trac.webkit.org/changeset/259178/webkit>