Bug 196893 - [Cocoa] WKCustomProtocolLoader should store a WeakPtr to its LegacyCustomProtocolManagerProxy
Summary: [Cocoa] WKCustomProtocolLoader should store a WeakPtr to its LegacyCustomProt...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Andy Estes
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-04-12 20:20 PDT by Andy Estes
Modified: 2019-04-14 09:08 PDT (History)
9 users (show)

See Also:


Attachments
Patch (7.67 KB, patch)
2019-04-12 20:27 PDT, Andy Estes
no flags Details | Formatted Diff | Diff
Patch (7.60 KB, patch)
2019-04-12 21:05 PDT, Andy Estes
no flags Details | Formatted Diff | Diff
Patch (7.92 KB, patch)
2019-04-13 14:10 PDT, Andy Estes
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andy Estes 2019-04-12 20:20:21 PDT
[Cocoa] WKCustomProtocolLoader should store a WeakPtr to its LegacyCustomProtocolManagerProxy
Comment 1 Andy Estes 2019-04-12 20:26:00 PDT
rdar://problem/48318983
Comment 2 Andy Estes 2019-04-12 20:27:06 PDT Comment hidden (obsolete)
Comment 3 Andy Estes 2019-04-12 21:05:24 PDT
Created attachment 367377 [details]
Patch
Comment 4 Anders Carlsson 2019-04-13 07:57:58 PDT
Comment on attachment 367377 [details]
Patch

Assuming there are no thread safety issues and that LegacyCustomProtocolManagerProxy is always called from the same (main?) thread, r=me.
Comment 5 Darin Adler 2019-04-13 07:58:50 PDT
Comment on attachment 367377 [details]
Patch

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

Kinda wish we still canceled the load when the weak pointer became null.

> Source/WebKit/UIProcess/Cocoa/LegacyCustomProtocolManagerClient.mm:-77
> -    ASSERT(_customProtocolManagerProxy);

I think this assertion might still be good. The WeakPtr can protect us from mistakes, but we should always be canceling before destroying the proxy, for efficiency reasons if no other reasons.

> Source/WebKit/UIProcess/Cocoa/LegacyCustomProtocolManagerClient.mm:-78
> -    _customProtocolManagerProxy = nullptr;

Still might be good to null this out. Not sure.

> Source/WebKit/UIProcess/Cocoa/LegacyCustomProtocolManagerClient.mm:119
> -    if (redirectResponse) {
> +    if (_customProtocolManagerProxy && redirectResponse) {
>          _customProtocolManagerProxy->wasRedirectedToRequest(_customProtocolID, request, redirectResponse);
>          return nil;
>      }

Seems to me that if _customProtocolManagerProxy is null we should return nil, not request.
Comment 6 Andy Estes 2019-04-13 13:51:51 PDT
(In reply to Anders Carlsson from comment #4)
> Comment on attachment 367377 [details]
> Patch
> 
> Assuming there are no thread safety issues and that
> LegacyCustomProtocolManagerProxy is always called from the same (main?)
> thread, r=me.

LegacyCustomProtocolManagerProxy is always called from the main thread. Thanks for reviewing!
Comment 7 Andy Estes 2019-04-13 13:53:24 PDT
(In reply to Darin Adler from comment #5)
> Comment on attachment 367377 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=367377&action=review
> 
> Kinda wish we still canceled the load when the weak pointer became null.

We should still cancel, because LegacyCustomProtocolManagerClient::invalidate() will still be called when the LegacyCustomProtocolManagerProxy is destroyed.

> 
> > Source/WebKit/UIProcess/Cocoa/LegacyCustomProtocolManagerClient.mm:-77
> > -    ASSERT(_customProtocolManagerProxy);
> 
> I think this assertion might still be good. The WeakPtr can protect us from
> mistakes, but we should always be canceling before destroying the proxy, for
> efficiency reasons if no other reasons.
> 
> > Source/WebKit/UIProcess/Cocoa/LegacyCustomProtocolManagerClient.mm:-78
> > -    _customProtocolManagerProxy = nullptr;
> 
> Still might be good to null this out. Not sure.

I restored the assertion and the nulling.

> 
> > Source/WebKit/UIProcess/Cocoa/LegacyCustomProtocolManagerClient.mm:119
> > -    if (redirectResponse) {
> > +    if (_customProtocolManagerProxy && redirectResponse) {
> >          _customProtocolManagerProxy->wasRedirectedToRequest(_customProtocolID, request, redirectResponse);
> >          return nil;
> >      }
> 
> Seems to me that if _customProtocolManagerProxy is null we should return
> nil, not request.

Yes, that makes more sense.

Thanks for your comments!
Comment 8 Andy Estes 2019-04-13 14:10:52 PDT
Created attachment 367391 [details]
Patch
Comment 9 Andy Estes 2019-04-14 08:40:41 PDT
The api-mac failure is due to a flaky API test. I filed <https://bugs.webkit.org/show_bug.cgi?id=196905>.
Comment 10 WebKit Commit Bot 2019-04-14 09:08:29 PDT
Comment on attachment 367391 [details]
Patch

Clearing flags on attachment: 367391

Committed r244246: <https://trac.webkit.org/changeset/244246>
Comment 11 WebKit Commit Bot 2019-04-14 09:08:30 PDT
All reviewed patches have been landed.  Closing bug.