Skip to content

Commit

Permalink
[iOS] Write web archive data using the com.apple.webarchive UTI whe…
Browse files Browse the repository at this point in the history
…n copying/dragging

https://bugs.webkit.org/show_bug.cgi?id=267131
rdar://120545471

Reviewed by Aditya Keerthi.

Publish `com.apple.webarchive` alongside the legacy `Apple Web Archive pasteboard type` when writing
web archive data to the pasteboard when copying or dragging, so that the system can automatically
coerce from web archive data (which may include attachments) to `NSAttributedString`, RTF, or flat
RTFD if needed.

Note that landing this change no longer requires rdar://46830277 to be fixed after the (more recent)
UIKit changes in rdar://116051491, because writing `com.apple.webarchive` data now additionally
registers "derived" types for `public.rtf` and `com.apple.flat-rtfd`. This ensures that Messages
won't prefer pasting text copied in Safari as a `.webarchive` file over plain text in the entry
view.

* Source/WebCore/platform/ios/PlatformPasteboardIOS.mm:
(WebCore::PlatformPasteboard::write):
* Tools/TestWebKitAPI/Tests/ios/DragAndDropTestsIOS.mm:

Additionally rebaseline an API test, to reflect the fact that we should now register
`com.apple.webarchive` when dragging.

Canonical link: https://commits.webkit.org/272697@main
  • Loading branch information
whsieh committed Jan 5, 2024
1 parent 82682c1 commit cb14ef5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
12 changes: 4 additions & 8 deletions Source/WebCore/platform/ios/PlatformPasteboardIOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#import <UIKit/UIColor.h>
#import <UIKit/UIImage.h>
#import <UIKit/UIPasteboard.h>
#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>
#import <pal/spi/ios/UIKitSPI.h>
#import <wtf/ListHashSet.h>
#import <wtf/URL.h>
Expand Down Expand Up @@ -468,15 +469,10 @@ static void addRepresentationsForPlainText(WebItemProviderRegistrationInfoList *

if (content.dataInWebArchiveFormat) {
auto webArchiveData = content.dataInWebArchiveFormat->createNSData();
#if PLATFORM(MACCATALYST)
ALLOW_DEPRECATED_DECLARATIONS_BEGIN
NSString *webArchiveType = (__bridge NSString *)kUTTypeWebArchive;
ALLOW_DEPRECATED_DECLARATIONS_END
#else
// FIXME: We should additionally register "com.apple.webarchive" once <rdar://problem/46830277> is fixed.
NSString *webArchiveType = WebArchivePboardType;
#if !PLATFORM(MACCATALYST)
[representationsToRegister addData:webArchiveData.get() forType:WebArchivePboardType];
#endif
[representationsToRegister addData:webArchiveData.get() forType:webArchiveType];
[representationsToRegister addData:webArchiveData.get() forType:UTTypeWebArchive.identifier];
}

if (content.dataInAttributedStringFormat) {
Expand Down
4 changes: 1 addition & 3 deletions Tools/TestWebKitAPI/Tests/ios/DragAndDropTestsIOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,7 @@ static void runTestWithTemporaryFolder(void(^runTest)(NSURL *folderURL))
checkCGRectIsEqualToCGRectWithLogging(CGRectMake(960, 205, 2, 223), [simulator finalSelectionStartRect]);
checkRichTextTypePrecedesPlainTextType(simulator.get());
EXPECT_TRUE([simulator lastKnownDropProposal].precise);

// FIXME: Once <rdar://problem/46830277> is fixed, we should add "com.apple.webarchive" as a registered pasteboard type and rebaseline this expectation.
EXPECT_FALSE([[[simulator sourceItemProviders].firstObject registeredTypeIdentifiers] containsObject:(__bridge NSString *)kUTTypeWebArchive]);
EXPECT_TRUE([[[simulator sourceItemProviders].firstObject registeredTypeIdentifiers] containsObject:UTTypeWebArchive.identifier]);
}

TEST(DragAndDropTests, ContentEditableToTextarea)
Expand Down

0 comments on commit cb14ef5

Please sign in to comment.