Bug 190530

Summary: [Cocoa] Attachment dropped from one web view to another is missing its file wrapper
Product: WebKit Reporter: mitz
Component: HTML EditingAssignee: Wenson Hsieh <wenson_hsieh>
Status: RESOLVED FIXED    
Severity: Normal CC: bdakin, commit-queue, mitz, thorton, webkit-bug-importer, wenson_hsieh
Priority: P2 Keywords: InRadar
Version: Other   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Try to fix macOS builds
none
Try to fix the Windows build
none
Try to fix the Windows build (2)
none
Try to fix the Windows build (3)
none
Try to fix the Windows build (4)
none
Try to fix the Windows build (4.1)
none
Try to fix the Windows build (5) none

Description mitz 2018-10-12 11:32:06 PDT
To reproduce this bug:

1. Create two editable, attachment-enabled web views
2. Drop a file into the first web view, thus creating an attachment
3. Drag the attachment from the first web view to the other one

Notice that the _WKAttachment instance passed to -_webView:didInsertAttachment:withSource: has a nil info.fileWrapper.
Comment 1 mitz 2018-10-12 11:38:26 PDT
<rdar://problem/45232149>
Comment 2 mitz 2018-10-12 12:41:32 PDT
Seems to also happen with copy and paste!
Comment 3 Wenson Hsieh 2018-10-30 14:45:53 PDT
Created attachment 353411 [details]
Patch
Comment 4 Wenson Hsieh 2018-10-30 15:28:30 PDT
Created attachment 353417 [details]
Try to fix macOS builds
Comment 5 Wenson Hsieh 2018-10-30 16:45:57 PDT
Created attachment 353435 [details]
Try to fix the Windows build
Comment 6 Tim Horton 2018-10-30 16:56:09 PDT
Comment on attachment 353435 [details]
Try to fix the Windows build

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

> Source/WebCore/html/HTMLAttachmentElement.cpp:91
> +    return URLParser(makeString("applewebdata://attachment/"_s, identifier)).result();

It feels weird/scary to build a URL by concatenating strings. But it seems like we don't have a mutable URL? What happens if identifier (which comes from where?) has non-path-safe characters?
Comment 7 Wenson Hsieh 2018-10-30 17:42:51 PDT
Comment on attachment 353435 [details]
Try to fix the Windows build

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

>> Source/WebCore/html/HTMLAttachmentElement.cpp:91
>> +    return URLParser(makeString("applewebdata://attachment/"_s, identifier)).result();
> 
> It feels weird/scary to build a URL by concatenating strings. But it seems like we don't have a mutable URL? What happens if identifier (which comes from where?) has non-path-safe characters?

Good point — the identifier _normally_ comes from within WebKit (createCanonicalUUIDString()) and it's only exposed as a readonly attribute to internal clients. That being said, we do have a mechanism for temporarily saving the identifier as an attribute on the attachment element (see "webkitattachmentid"). Using this, it should be possible to influence the identifier of a pasted/dropped attachment element by writing a webarchive to the pasteboard with an attachment element that contains this attribute...

I've changed this to use URL::setPath() to set the path of the URL, and verified that non-path-safe characters (e.g. space) are URL-encoded.
Comment 8 Wenson Hsieh 2018-10-30 19:10:00 PDT
Created attachment 353456 [details]
Try to fix the Windows build (2)
Comment 9 Wenson Hsieh 2018-10-30 19:52:26 PDT
Created attachment 353458 [details]
Try to fix the Windows build (3)
Comment 10 Wenson Hsieh 2018-10-30 20:11:31 PDT
Created attachment 353459 [details]
Try to fix the Windows build (4)
Comment 11 Wenson Hsieh 2018-10-30 20:23:42 PDT
Created attachment 353460 [details]
Try to fix the Windows build (4.1)
Comment 12 Wenson Hsieh 2018-10-30 20:34:16 PDT
Created attachment 353461 [details]
Try to fix the Windows build (5)
Comment 13 WebKit Commit Bot 2018-10-30 22:29:26 PDT
Comment on attachment 353461 [details]
Try to fix the Windows build (5)

Clearing flags on attachment: 353461

Committed r237624: <https://trac.webkit.org/changeset/237624>
Comment 14 WebKit Commit Bot 2018-10-30 22:29:28 PDT
All reviewed patches have been landed.  Closing bug.
Comment 15 mitz 2019-04-06 19:34:18 PDT
*** Bug 188904 has been marked as a duplicate of this bug. ***