Bug 177801

Summary: Use blob URL when pasting RTFD instead of overriding DocumentLoader
Product: WebKit Reporter: Ryosuke Niwa <rniwa>
Component: HTML EditingAssignee: Ryosuke Niwa <rniwa>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, wenson_hsieh
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 124391    
Attachments:
Description Flags
Fixes the bug
none
Fixed builds
none
Fixed GTK+ builds
none
Patch for landing none

Description Ryosuke Niwa 2017-10-03 01:01:40 PDT
Right now, the pasted content’s subresources are loaded by overriding document loader.
This is extremely hacky way of making paste work, and websites can’t access those sub resources.
Use blob URL instead.
Comment 1 Ryosuke Niwa 2017-10-03 01:02:03 PDT
<rdar://problem/34542270>
Comment 2 Ryosuke Niwa 2017-10-03 01:26:54 PDT
Created attachment 322500 [details]
Fixes the bug
Comment 3 Ryosuke Niwa 2017-10-03 11:45:18 PDT
Created attachment 322554 [details]
Fixed builds
Comment 4 Ryosuke Niwa 2017-10-03 11:49:04 PDT
Created attachment 322555 [details]
Fixed GTK+ builds
Comment 5 Wenson Hsieh 2017-10-04 00:39:07 PDT
Comment on attachment 322555 [details]
Fixed GTK+ builds

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

The general approach looks reasonable to me, but I'm not familiar with loading code at all. Perhaps Chris would have some additional input here?

> Source/WebCore/ChangeLog:10
> +        into the document using WebKit fake URL, and DocumentLoader was overridden to return the appropraite

appropraite => appropriate

> Source/WebCore/editing/markup.cpp:128
> +            if (element.attributeContainsURL(attribute) && !attribute.value().isEmpty()) {

How would this handle data: URLs, or app: URLs?

> Source/WebCore/editing/markup.cpp:131
> +                    changes.append(AttributeChange(&element, attribute.name(), replacement));

Nit - { } initialization here?

> Tools/TestWebKitAPI/Tests/WebKitCocoa/PasteRTFD.mm:46
> +    [[NSPasteboard generalPasteboard] declareTypes:[NSArray arrayWithObject:NSRTFDPboardType] owner:nil];

Nit - this would probably be more succinct using @[] instead of +[NSArray arrayWithObject]

> Tools/TestWebKitAPI/Tests/WebKitCocoa/PasteRTFD.mm:61
> +    [[UIPasteboard generalPasteboard] setItems:@[[NSDictionary dictionaryWithObject:data forKey:(NSString *)kUTTypeFlatRTFD]]];

Nit - this would probably be more succinct using @{} instead of +[NSDictionary dictionaryWithObject]

> Tools/TestWebKitAPI/Tests/WebKitCocoa/PasteRTFD.mm:72
> +    [webView paste:nil];

Did you mean to check that the editable root is empty after this?
Comment 6 Ryosuke Niwa 2017-10-04 02:04:50 PDT
Comment on attachment 322555 [details]
Fixed GTK+ builds

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

>> Source/WebCore/editing/markup.cpp:128
>> +            if (element.attributeContainsURL(attribute) && !attribute.value().isEmpty()) {
> 
> How would this handle data: URLs, or app: URLs?

They won't be in replacement map since those URLs shouldn't be appearing as sub resources in attributed attributes we just parsed.

>> Source/WebCore/editing/markup.cpp:131
>> +                    changes.append(AttributeChange(&element, attribute.name(), replacement));
> 
> Nit - { } initialization here?

Sure.

>> Tools/TestWebKitAPI/Tests/WebKitCocoa/PasteRTFD.mm:46
>> +    [[NSPasteboard generalPasteboard] declareTypes:[NSArray arrayWithObject:NSRTFDPboardType] owner:nil];
> 
> Nit - this would probably be more succinct using @[] instead of +[NSArray arrayWithObject]

Fixed.

>> Tools/TestWebKitAPI/Tests/WebKitCocoa/PasteRTFD.mm:61
>> +    [[UIPasteboard generalPasteboard] setItems:@[[NSDictionary dictionaryWithObject:data forKey:(NSString *)kUTTypeFlatRTFD]]];
> 
> Nit - this would probably be more succinct using @{} instead of +[NSDictionary dictionaryWithObject]

Fixed.

>> Tools/TestWebKitAPI/Tests/WebKitCocoa/PasteRTFD.mm:72
>> +    [webView paste:nil];
> 
> Did you mean to check that the editable root is empty after this?

No. This test is simply here to make sure WebKit doesn't hit a debug assertion / crash when sharedBuffer is empty in getPasteboardBufferForType.
Comment 7 Ryosuke Niwa 2017-10-04 02:05:44 PDT
Created attachment 322638 [details]
Patch for landing
Comment 8 Ryosuke Niwa 2017-10-04 02:06:14 PDT
Comment on attachment 322638 [details]
Patch for landing

Wait for EWS.
Comment 9 WebKit Commit Bot 2017-10-04 04:06:18 PDT
Comment on attachment 322638 [details]
Patch for landing

Clearing flags on attachment: 322638

Committed r222839: <http://trac.webkit.org/changeset/222839>
Comment 10 WebKit Commit Bot 2017-10-04 04:06:20 PDT
All reviewed patches have been landed.  Closing bug.