Bug 214329

Summary: REGRESSION (r264101): Sharing a link attaches an image instead of the URL
Product: WebKit Reporter: Wenson Hsieh <wenson_hsieh>
Component: WebKit2Assignee: Wenson Hsieh <wenson_hsieh>
Status: RESOLVED FIXED    
Severity: Normal CC: bdakin, dino, graouts, hi, megan_gardner, thorton, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
thorton: review+
Patch for landing none

Description Wenson Hsieh 2020-07-14 16:08:15 PDT
<rdar://problem/65513607>
Comment 1 Wenson Hsieh 2020-07-14 16:23:53 PDT
Created attachment 404301 [details]
Patch
Comment 2 Tim Horton 2020-07-14 16:35:17 PDT
Might be even better to use some WTF thing, but this is fine as a quick fix
Comment 3 Wenson Hsieh 2020-07-14 16:37:59 PDT Comment hidden (obsolete)
Comment 4 Wenson Hsieh 2020-07-14 16:38:39 PDT
(In reply to Tim Horton from comment #2)
> Might be even better to use some WTF thing, but this is fine as a quick fix

That’s true! I could make this something like

URL(element.imageURL).protocolIsData();
Comment 5 Devin Rousso 2020-07-14 16:39:56 PDT
Comment on attachment 404301 [details]
Patch

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

r=me

> Source/WebKit/ChangeLog:10
> +        r264101 added logic that attempts to share an activated (i.e. long-pressed) element as an image, if the image
> +        URL for the element is equal to "data" (ignoring case sensitivity). However, in the case where the image URL is

NIT: it's really comparing the URL's scheme, not the entire URL itself

> Source/WebKit/UIProcess/ios/WKActionSheetAssistant.mm:831
> -        if ([element.imageURL.scheme caseInsensitiveCompare:@"data"] == NSOrderedSame && element.image && [delegate respondsToSelector:@selector(actionSheetAssistant:shareElementWithImage:rect:)])
> +        if ([@"data" caseInsensitiveCompare:element.imageURL.scheme] == NSOrderedSame && element.image && [delegate respondsToSelector:@selector(actionSheetAssistant:shareElementWithImage:rect:)])

Is it worth explicitly checking that `element.imageURL` is truthy so that it's explicit/obvious that this codepath expects it to be non-`nil` (i.e. have `element.image && element.imageURL` at the beginning)?

> Tools/TestWebKitAPI/Tests/ios/ShareSheetTests.mm:114
> +        EXPECT_WK_STREQ("https://www.apple.com/", [[activityItems objectAtIndex:0] absoluteString]);

So how would this fail if the above code changed in the future?  Would `absoluteString` be `nil` (and some other "form" would be set instead) or would it be the dataURL?
Comment 6 Wenson Hsieh 2020-07-14 16:44:21 PDT
Thanks for the reviews!

(In reply to Devin Rousso from comment #5)
> Comment on attachment 404301 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=404301&action=review
> 
> r=me
> 
> > Source/WebKit/ChangeLog:10
> > +        r264101 added logic that attempts to share an activated (i.e. long-pressed) element as an image, if the image
> > +        URL for the element is equal to "data" (ignoring case sensitivity). However, in the case where the image URL is
> 
> NIT: it's really comparing the URL's scheme, not the entire URL itself

Yep, I missed a word here ("scheme").

> 
> > Source/WebKit/UIProcess/ios/WKActionSheetAssistant.mm:831
> > -        if ([element.imageURL.scheme caseInsensitiveCompare:@"data"] == NSOrderedSame && element.image && [delegate respondsToSelector:@selector(actionSheetAssistant:shareElementWithImage:rect:)])
> > +        if ([@"data" caseInsensitiveCompare:element.imageURL.scheme] == NSOrderedSame && element.image && [delegate respondsToSelector:@selector(actionSheetAssistant:shareElementWithImage:rect:)])
> 
> Is it worth explicitly checking that `element.imageURL` is truthy so that
> it's explicit/obvious that this codepath expects it to be non-`nil` (i.e.
> have `element.image && element.imageURL` at the beginning)?

I don’t think there’s much benefit to doing so, but I’m changing this to URL(element.imageURL).protocolIsData() anyways.

> 
> > Tools/TestWebKitAPI/Tests/ios/ShareSheetTests.mm:114
> > +        EXPECT_WK_STREQ("https://www.apple.com/", [[activityItems objectAtIndex:0] absoluteString]);
> 
> So how would this fail if the above code changed in the future?  Would
> `absoluteString` be `nil` (and some other "form" would be set instead) or
> would it be the dataURL?

Depending on the nature of the failure, any of the above!
Comment 7 Wenson Hsieh 2020-07-14 16:55:25 PDT
Created attachment 404308 [details]
Patch for landing
Comment 8 EWS 2020-07-14 17:20:25 PDT
Committed r264383: <https://trac.webkit.org/changeset/264383>

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