|
Lines 109-114
static bool shouldTreatAtLeastOneTypeAsFile(NSArray<NSString *> *platformTypes)
a/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm_sec1
|
| 109 |
static const char *safeTypeForDOMToReadAndWriteForPlatformType(const String& platformType, PlatformPasteboard::IncludeImageTypes includeImageTypes) |
109 |
static const char *safeTypeForDOMToReadAndWriteForPlatformType(const String& platformType, PlatformPasteboard::IncludeImageTypes includeImageTypes) |
| 110 |
{ |
110 |
{ |
| 111 |
auto cfType = platformType.createCFString(); |
111 |
auto cfType = platformType.createCFString(); |
|
|
112 |
ALLOW_DEPRECATED_DECLARATIONS_BEGIN |
| 112 |
if (UTTypeConformsTo(cfType.get(), kUTTypePlainText)) |
113 |
if (UTTypeConformsTo(cfType.get(), kUTTypePlainText)) |
| 113 |
return "text/plain"_s; |
114 |
return "text/plain"_s; |
| 114 |
|
115 |
|
|
Lines 121-126
static const char *safeTypeForDOMToReadAndWriteForPlatformType(const String& pla
a/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm_sec2
|
| 121 |
|
122 |
|
| 122 |
if (includeImageTypes == PlatformPasteboard::IncludeImageTypes::Yes && UTTypeConformsTo(cfType.get(), kUTTypePNG)) |
123 |
if (includeImageTypes == PlatformPasteboard::IncludeImageTypes::Yes && UTTypeConformsTo(cfType.get(), kUTTypePNG)) |
| 123 |
return "image/png"_s; |
124 |
return "image/png"_s; |
|
|
125 |
ALLOW_DEPRECATED_DECLARATIONS_END |
| 124 |
|
126 |
|
| 125 |
return nullptr; |
127 |
return nullptr; |
| 126 |
} |
128 |
} |
|
Lines 139-146
static Vector<String> webSafeTypes(NSArray<NSString *> *platformTypes, PlatformP
a/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm_sec3
|
| 139 |
|
141 |
|
| 140 |
if (auto* coercedType = safeTypeForDOMToReadAndWriteForPlatformType(type, includeImageTypes)) { |
142 |
if (auto* coercedType = safeTypeForDOMToReadAndWriteForPlatformType(type, includeImageTypes)) { |
| 141 |
auto domTypeAsString = String::fromUTF8(coercedType); |
143 |
auto domTypeAsString = String::fromUTF8(coercedType); |
|
|
144 |
ALLOW_DEPRECATED_DECLARATIONS_BEGIN |
| 142 |
if (domTypeAsString == "text/uri-list"_s && ([platformTypes containsObject:(__bridge NSString *)kUTTypeFileURL] || shouldAvoidExposingURLType())) |
145 |
if (domTypeAsString == "text/uri-list"_s && ([platformTypes containsObject:(__bridge NSString *)kUTTypeFileURL] || shouldAvoidExposingURLType())) |
| 143 |
continue; |
146 |
continue; |
|
|
147 |
ALLOW_DEPRECATED_DECLARATIONS_END |
| 144 |
|
148 |
|
| 145 |
domPasteboardTypes.add(WTFMove(domTypeAsString)); |
149 |
domPasteboardTypes.add(WTFMove(domTypeAsString)); |
| 146 |
} |
150 |
} |
|
Lines 218-223
Optional<PasteboardItemInfo> PlatformPasteboard::informationForItemAtIndex(size_
a/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm_sec4
|
| 218 |
for (NSString *typeIdentifier in registeredTypeIdentifiers) { |
222 |
for (NSString *typeIdentifier in registeredTypeIdentifiers) { |
| 219 |
info.platformTypesByFidelity.uncheckedAppend(typeIdentifier); |
223 |
info.platformTypesByFidelity.uncheckedAppend(typeIdentifier); |
| 220 |
CFStringRef cfTypeIdentifier = (CFStringRef)typeIdentifier; |
224 |
CFStringRef cfTypeIdentifier = (CFStringRef)typeIdentifier; |
|
|
225 |
ALLOW_DEPRECATED_DECLARATIONS_BEGIN |
| 221 |
if (!UTTypeIsDeclared(cfTypeIdentifier)) |
226 |
if (!UTTypeIsDeclared(cfTypeIdentifier)) |
| 222 |
continue; |
227 |
continue; |
| 223 |
|
228 |
|
|
Lines 232-243
Optional<PasteboardItemInfo> PlatformPasteboard::informationForItemAtIndex(size_
a/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm_sec5
|
| 232 |
|
237 |
|
| 233 |
if (UTTypeConformsTo(cfTypeIdentifier, kUTTypeFlatRTFD)) |
238 |
if (UTTypeConformsTo(cfTypeIdentifier, kUTTypeFlatRTFD)) |
| 234 |
continue; |
239 |
continue; |
|
|
240 |
ALLOW_DEPRECATED_DECLARATIONS_END |
| 235 |
|
241 |
|
| 236 |
info.isNonTextType = true; |
242 |
info.isNonTextType = true; |
| 237 |
} |
243 |
} |
| 238 |
|
244 |
|
| 239 |
info.webSafeTypesByFidelity = webSafeTypes(registeredTypeIdentifiers, IncludeImageTypes::Yes, [&] { |
245 |
info.webSafeTypesByFidelity = webSafeTypes(registeredTypeIdentifiers, IncludeImageTypes::Yes, [&] { |
|
|
246 |
ALLOW_DEPRECATED_DECLARATIONS_BEGIN |
| 240 |
return shouldTreatAtLeastOneTypeAsFile(registeredTypeIdentifiers) && !Pasteboard::canExposeURLToDOMWhenPasteboardContainsFiles(readString(index, kUTTypeURL)); |
247 |
return shouldTreatAtLeastOneTypeAsFile(registeredTypeIdentifiers) && !Pasteboard::canExposeURLToDOMWhenPasteboardContainsFiles(readString(index, kUTTypeURL)); |
|
|
248 |
ALLOW_DEPRECATED_DECLARATIONS_END |
| 241 |
}); |
249 |
}); |
| 242 |
|
250 |
|
| 243 |
return info; |
251 |
return info; |
|
Lines 265-274
String PlatformPasteboard::stringForType(const String& type) const
a/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm_sec6
|
| 265 |
{ |
273 |
{ |
| 266 |
auto result = readString(0, type); |
274 |
auto result = readString(0, type); |
| 267 |
|
275 |
|
|
|
276 |
ALLOW_DEPRECATED_DECLARATIONS_BEGIN |
| 268 |
if (pasteboardMayContainFilePaths(m_pasteboard.get()) && type == String { kUTTypeURL }) { |
277 |
if (pasteboardMayContainFilePaths(m_pasteboard.get()) && type == String { kUTTypeURL }) { |
| 269 |
if (!Pasteboard::canExposeURLToDOMWhenPasteboardContainsFiles(result)) |
278 |
if (!Pasteboard::canExposeURLToDOMWhenPasteboardContainsFiles(result)) |
| 270 |
result = { }; |
279 |
result = { }; |
| 271 |
} |
280 |
} |
|
|
281 |
ALLOW_DEPRECATED_DECLARATIONS_END |
| 272 |
|
282 |
|
| 273 |
return result; |
283 |
return result; |
| 274 |
} |
284 |
} |
|
Lines 322-327
int64_t PlatformPasteboard::changeCount() const
a/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm_sec7
|
| 322 |
|
332 |
|
| 323 |
String PlatformPasteboard::platformPasteboardTypeForSafeTypeForDOMToReadAndWrite(const String& domType, IncludeImageTypes includeImageTypes) |
333 |
String PlatformPasteboard::platformPasteboardTypeForSafeTypeForDOMToReadAndWrite(const String& domType, IncludeImageTypes includeImageTypes) |
| 324 |
{ |
334 |
{ |
|
|
335 |
ALLOW_DEPRECATED_DECLARATIONS_BEGIN |
| 325 |
if (domType == "text/plain") |
336 |
if (domType == "text/plain") |
| 326 |
return kUTTypePlainText; |
337 |
return kUTTypePlainText; |
| 327 |
|
338 |
|
|
Lines 333-338
String PlatformPasteboard::platformPasteboardTypeForSafeTypeForDOMToReadAndWrite
a/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm_sec8
|
| 333 |
|
344 |
|
| 334 |
if (includeImageTypes == IncludeImageTypes::Yes && domType == "image/png") |
345 |
if (includeImageTypes == IncludeImageTypes::Yes && domType == "image/png") |
| 335 |
return kUTTypePNG; |
346 |
return kUTTypePNG; |
|
|
347 |
ALLOW_DEPRECATED_DECLARATIONS_END |
| 336 |
|
348 |
|
| 337 |
return { }; |
349 |
return { }; |
| 338 |
} |
350 |
} |
|
Lines 396-410
static void addRepresentationsForPlainText(WebItemProviderRegistrationInfoList *
a/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm_sec9
|
| 396 |
if (URL(platformURL).isValid()) |
408 |
if (URL(platformURL).isValid()) |
| 397 |
[itemsToRegister addRepresentingObject:platformURL]; |
409 |
[itemsToRegister addRepresentingObject:platformURL]; |
| 398 |
|
410 |
|
|
|
411 |
ALLOW_DEPRECATED_DECLARATIONS_BEGIN |
| 399 |
[itemsToRegister addData:[(NSString *)plainText dataUsingEncoding:NSUTF8StringEncoding] forType:(NSString *)kUTTypeUTF8PlainText]; |
412 |
[itemsToRegister addData:[(NSString *)plainText dataUsingEncoding:NSUTF8StringEncoding] forType:(NSString *)kUTTypeUTF8PlainText]; |
|
|
413 |
ALLOW_DEPRECATED_DECLARATIONS_END |
| 400 |
} |
414 |
} |
| 401 |
|
415 |
|
| 402 |
bool PlatformPasteboard::allowReadingURLAtIndex(const URL& url, int index) const |
416 |
bool PlatformPasteboard::allowReadingURLAtIndex(const URL& url, int index) const |
| 403 |
{ |
417 |
{ |
| 404 |
NSItemProvider *itemProvider = (NSUInteger)index < [m_pasteboard itemProviders].count ? [[m_pasteboard itemProviders] objectAtIndex:index] : nil; |
418 |
NSItemProvider *itemProvider = (NSUInteger)index < [m_pasteboard itemProviders].count ? [[m_pasteboard itemProviders] objectAtIndex:index] : nil; |
| 405 |
for (NSString *type in itemProvider.registeredTypeIdentifiers) { |
419 |
for (NSString *type in itemProvider.registeredTypeIdentifiers) { |
|
|
420 |
ALLOW_DEPRECATED_DECLARATIONS_BEGIN |
| 406 |
if (UTTypeConformsTo((CFStringRef)type, kUTTypeURL)) |
421 |
if (UTTypeConformsTo((CFStringRef)type, kUTTypeURL)) |
| 407 |
return true; |
422 |
return true; |
|
|
423 |
ALLOW_DEPRECATED_DECLARATIONS_END |
| 408 |
} |
424 |
} |
| 409 |
|
425 |
|
| 410 |
return url.isValid(); |
426 |
return url.isValid(); |
|
Lines 425-431
void PlatformPasteboard::write(const PasteboardWebContent& content)
a/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm_sec10
|
| 425 |
if (content.dataInWebArchiveFormat) { |
441 |
if (content.dataInWebArchiveFormat) { |
| 426 |
auto webArchiveData = content.dataInWebArchiveFormat->createNSData(); |
442 |
auto webArchiveData = content.dataInWebArchiveFormat->createNSData(); |
| 427 |
#if PLATFORM(MACCATALYST) |
443 |
#if PLATFORM(MACCATALYST) |
|
|
444 |
ALLOW_DEPRECATED_DECLARATIONS_BEGIN |
| 428 |
NSString *webArchiveType = (__bridge NSString *)kUTTypeWebArchive; |
445 |
NSString *webArchiveType = (__bridge NSString *)kUTTypeWebArchive; |
|
|
446 |
ALLOW_DEPRECATED_DECLARATIONS_END |
| 429 |
#else |
447 |
#else |
| 430 |
// FIXME: We should additionally register "com.apple.webarchive" once <rdar://problem/46830277> is fixed. |
448 |
// FIXME: We should additionally register "com.apple.webarchive" once <rdar://problem/46830277> is fixed. |
| 431 |
NSString *webArchiveType = WebArchivePboardType; |
449 |
NSString *webArchiveType = WebArchivePboardType; |
|
Lines 438-443
void PlatformPasteboard::write(const PasteboardWebContent& content)
a/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm_sec11
|
| 438 |
[representationsToRegister addRepresentingObject:attributedString]; |
456 |
[representationsToRegister addRepresentingObject:attributedString]; |
| 439 |
} |
457 |
} |
| 440 |
|
458 |
|
|
|
459 |
ALLOW_DEPRECATED_DECLARATIONS_BEGIN |
| 441 |
if (content.dataInRTFDFormat) |
460 |
if (content.dataInRTFDFormat) |
| 442 |
[representationsToRegister addData:content.dataInRTFDFormat->createNSData().get() forType:(NSString *)kUTTypeFlatRTFD]; |
461 |
[representationsToRegister addData:content.dataInRTFDFormat->createNSData().get() forType:(NSString *)kUTTypeFlatRTFD]; |
| 443 |
|
462 |
|
|
Lines 448-453
void PlatformPasteboard::write(const PasteboardWebContent& content)
a/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm_sec12
|
| 448 |
NSData *htmlAsData = [(NSString *)content.dataInHTMLFormat dataUsingEncoding:NSUTF8StringEncoding]; |
467 |
NSData *htmlAsData = [(NSString *)content.dataInHTMLFormat dataUsingEncoding:NSUTF8StringEncoding]; |
| 449 |
[representationsToRegister addData:htmlAsData forType:(NSString *)kUTTypeHTML]; |
468 |
[representationsToRegister addData:htmlAsData forType:(NSString *)kUTTypeHTML]; |
| 450 |
} |
469 |
} |
|
|
470 |
ALLOW_DEPRECATED_DECLARATIONS_END |
| 451 |
|
471 |
|
| 452 |
if (!content.dataInStringFormat.isEmpty()) |
472 |
if (!content.dataInStringFormat.isEmpty()) |
| 453 |
addRepresentationsForPlainText(representationsToRegister.get(), content.dataInStringFormat); |
473 |
addRepresentationsForPlainText(representationsToRegister.get(), content.dataInStringFormat); |
|
Lines 502-511
void PlatformPasteboard::write(const String& pasteboardType, const String& text)
a/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm_sec13
|
| 502 |
NSString *pasteboardTypeAsNSString = pasteboardType; |
522 |
NSString *pasteboardTypeAsNSString = pasteboardType; |
| 503 |
if (!text.isEmpty() && pasteboardTypeAsNSString.length) { |
523 |
if (!text.isEmpty() && pasteboardTypeAsNSString.length) { |
| 504 |
auto pasteboardTypeAsCFString = (CFStringRef)pasteboardTypeAsNSString; |
524 |
auto pasteboardTypeAsCFString = (CFStringRef)pasteboardTypeAsNSString; |
|
|
525 |
ALLOW_DEPRECATED_DECLARATIONS_BEGIN |
| 505 |
if (UTTypeConformsTo(pasteboardTypeAsCFString, kUTTypeURL) || UTTypeConformsTo(pasteboardTypeAsCFString, kUTTypeText)) |
526 |
if (UTTypeConformsTo(pasteboardTypeAsCFString, kUTTypeURL) || UTTypeConformsTo(pasteboardTypeAsCFString, kUTTypeText)) |
| 506 |
addRepresentationsForPlainText(representationsToRegister.get(), text); |
527 |
addRepresentationsForPlainText(representationsToRegister.get(), text); |
| 507 |
else |
528 |
else |
| 508 |
[representationsToRegister addData:[pasteboardTypeAsNSString dataUsingEncoding:NSUTF8StringEncoding] forType:pasteboardType]; |
529 |
[representationsToRegister addData:[pasteboardTypeAsNSString dataUsingEncoding:NSUTF8StringEncoding] forType:pasteboardType]; |
|
|
530 |
ALLOW_DEPRECATED_DECLARATIONS_END |
| 509 |
} |
531 |
} |
| 510 |
|
532 |
|
| 511 |
registerItemToPasteboard(representationsToRegister.get(), m_pasteboard.get()); |
533 |
registerItemToPasteboard(representationsToRegister.get(), m_pasteboard.get()); |
|
Lines 569-575
Vector<String> PlatformPasteboard::typesSafeForDOMToReadAndWrite(const String& o
a/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm_sec14
|
| 569 |
|
591 |
|
| 570 |
auto webSafePasteboardTypes = webSafeTypes([m_pasteboard pasteboardTypes], IncludeImageTypes::No, [&] { |
592 |
auto webSafePasteboardTypes = webSafeTypes([m_pasteboard pasteboardTypes], IncludeImageTypes::No, [&] { |
| 571 |
BOOL ableToDetermineProtocolOfPasteboardURL = ![m_pasteboard isKindOfClass:[WebItemProviderPasteboard class]]; |
593 |
BOOL ableToDetermineProtocolOfPasteboardURL = ![m_pasteboard isKindOfClass:[WebItemProviderPasteboard class]]; |
|
|
594 |
ALLOW_DEPRECATED_DECLARATIONS_BEGIN |
| 572 |
return ableToDetermineProtocolOfPasteboardURL && stringForType(kUTTypeURL).isEmpty(); |
595 |
return ableToDetermineProtocolOfPasteboardURL && stringForType(kUTTypeURL).isEmpty(); |
|
|
596 |
ALLOW_DEPRECATED_DECLARATIONS_END |
| 573 |
}); |
597 |
}); |
| 574 |
|
598 |
|
| 575 |
for (auto& type : webSafePasteboardTypes) |
599 |
for (auto& type : webSafePasteboardTypes) |
|
Lines 610-621
static RetainPtr<WebItemProviderRegistrationInfoList> createItemProviderRegistra
a/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm_sec15
|
| 610 |
|
634 |
|
| 611 |
NSString *nsStringValue = WTF::get<String>(value); |
635 |
NSString *nsStringValue = WTF::get<String>(value); |
| 612 |
auto cfType = cocoaType.createCFString(); |
636 |
auto cfType = cocoaType.createCFString(); |
|
|
637 |
ALLOW_DEPRECATED_DECLARATIONS_BEGIN |
| 613 |
if (UTTypeConformsTo(cfType.get(), kUTTypeURL)) |
638 |
if (UTTypeConformsTo(cfType.get(), kUTTypeURL)) |
| 614 |
[representationsToRegister addRepresentingObject:[NSURL URLWithString:nsStringValue]]; |
639 |
[representationsToRegister addRepresentingObject:[NSURL URLWithString:nsStringValue]]; |
| 615 |
else if (UTTypeConformsTo(cfType.get(), kUTTypePlainText)) |
640 |
else if (UTTypeConformsTo(cfType.get(), kUTTypePlainText)) |
| 616 |
[representationsToRegister addRepresentingObject:nsStringValue]; |
641 |
[representationsToRegister addRepresentingObject:nsStringValue]; |
| 617 |
else |
642 |
else |
| 618 |
[representationsToRegister addData:[nsStringValue dataUsingEncoding:NSUTF8StringEncoding] forType:(NSString *)cocoaType]; |
643 |
[representationsToRegister addData:[nsStringValue dataUsingEncoding:NSUTF8StringEncoding] forType:(NSString *)cocoaType]; |
|
|
644 |
ALLOW_DEPRECATED_DECLARATIONS_END |
| 619 |
return; |
645 |
return; |
| 620 |
} |
646 |
} |
| 621 |
|
647 |
|
|
Lines 709-714
RefPtr<SharedBuffer> PlatformPasteboard::readBuffer(size_t index, const String&
a/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm_sec16
|
| 709 |
|
735 |
|
| 710 |
String PlatformPasteboard::readString(size_t index, const String& type) const |
736 |
String PlatformPasteboard::readString(size_t index, const String& type) const |
| 711 |
{ |
737 |
{ |
|
|
738 |
ALLOW_DEPRECATED_DECLARATIONS_BEGIN |
| 712 |
if (type == String(kUTTypeURL)) { |
739 |
if (type == String(kUTTypeURL)) { |
| 713 |
String title; |
740 |
String title; |
| 714 |
return [(NSURL *)readURL(index, title) absoluteString]; |
741 |
return [(NSURL *)readURL(index, title) absoluteString]; |
|
Lines 736-741
String PlatformPasteboard::readString(size_t index, const String& type) const
a/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm_sec17
|
| 736 |
if ([value isKindOfClass:[NSAttributedString class]]) |
763 |
if ([value isKindOfClass:[NSAttributedString class]]) |
| 737 |
return [(NSAttributedString *)value string]; |
764 |
return [(NSAttributedString *)value string]; |
| 738 |
} |
765 |
} |
|
|
766 |
ALLOW_DEPRECATED_DECLARATIONS_END |
| 739 |
|
767 |
|
| 740 |
return String(); |
768 |
return String(); |
| 741 |
} |
769 |
} |
|
Lines 745-751
URL PlatformPasteboard::readURL(size_t index, String& title) const
a/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm_sec18
|
| 745 |
if ((NSInteger)index < 0 || (NSInteger)index >= [m_pasteboard numberOfItems]) |
773 |
if ((NSInteger)index < 0 || (NSInteger)index >= [m_pasteboard numberOfItems]) |
| 746 |
return { }; |
774 |
return { }; |
| 747 |
|
775 |
|
|
|
776 |
ALLOW_DEPRECATED_DECLARATIONS_BEGIN |
| 748 |
id value = [m_pasteboard valuesForPasteboardType:(__bridge NSString *)kUTTypeURL inItemSet:[NSIndexSet indexSetWithIndex:index]].firstObject; |
777 |
id value = [m_pasteboard valuesForPasteboardType:(__bridge NSString *)kUTTypeURL inItemSet:[NSIndexSet indexSetWithIndex:index]].firstObject; |
|
|
778 |
ALLOW_DEPRECATED_DECLARATIONS_END |
| 749 |
if (!value) |
779 |
if (!value) |
| 750 |
return { }; |
780 |
return { }; |
| 751 |
|
781 |
|
|
Lines 783-792
bool PlatformPasteboard::containsURLStringSuitableForLoading()
a/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm_sec19
|
| 783 |
{ |
813 |
{ |
| 784 |
Vector<String> types; |
814 |
Vector<String> types; |
| 785 |
getTypes(types); |
815 |
getTypes(types); |
|
|
816 |
ALLOW_DEPRECATED_DECLARATIONS_BEGIN |
| 786 |
if (!types.contains(String(kUTTypeURL))) |
817 |
if (!types.contains(String(kUTTypeURL))) |
| 787 |
return false; |
818 |
return false; |
| 788 |
|
819 |
|
| 789 |
auto urlString = stringForType(kUTTypeURL); |
820 |
auto urlString = stringForType(kUTTypeURL); |
|
|
821 |
ALLOW_DEPRECATED_DECLARATIONS_END |
| 790 |
if (urlString.isEmpty()) { |
822 |
if (urlString.isEmpty()) { |
| 791 |
// On iOS, we don't get access to the contents of NSItemProviders until we perform the drag operation. |
823 |
// On iOS, we don't get access to the contents of NSItemProviders until we perform the drag operation. |
| 792 |
// Thus, we consider DragData to contain an URL if it contains the `public.url` UTI type. Later down the |
824 |
// Thus, we consider DragData to contain an URL if it contains the `public.url` UTI type. Later down the |