175
175
176
176
static NSString *webIOSPastePboardType = @" iOS rich content paste pasteboard type" ;
177
177
178
- #if __IPHONE_OS_VERSION_MAX_ALLOWED < 110000
178
+ #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000
179
+
180
+ static void registerItemToPasteboard (WebItemProviderRegistrationInfoList *representationsToRegister, id <AbstractPasteboard> pasteboard)
181
+ {
182
+ UIItemProvider *itemProvider = [representationsToRegister itemProvider ];
183
+ if (!itemProvider) {
184
+ [pasteboard setItemProviders: @[ ]];
185
+ return ;
186
+ }
187
+
188
+ [pasteboard setItemProviders: @[ itemProvider ]];
189
+ if ([pasteboard respondsToSelector: @selector (setRegistrationInfoLists: )])
190
+ [pasteboard setRegistrationInfoLists: @[ representationsToRegister ]];
191
+ }
192
+
193
+ #else
179
194
180
195
static RetainPtr<NSDictionary > richTextRepresentationsForPasteboardWebContent (const PasteboardWebContent& content)
181
196
{
199
214
return representations;
200
215
}
201
216
202
- #else
203
-
204
- static void registerItemToPasteboard (WebItemProviderRegistrationInfoList *representationsToRegister, id <AbstractPasteboard> pasteboard)
205
- {
206
- UIItemProvider *itemProvider = [representationsToRegister itemProvider ];
207
- if (!itemProvider) {
208
- [pasteboard setItemProviders: @[ ]];
209
- return ;
210
- }
211
-
212
- [pasteboard setItemProviders: @[ itemProvider ]];
213
- if ([pasteboard respondsToSelector: @selector (setRegistrationInfoLists: )])
214
- [pasteboard setRegistrationInfoLists: @[ representationsToRegister ]];
215
- }
216
-
217
217
#endif
218
218
219
219
#if ENABLE(DATA_INTERACTION)
@@ -252,21 +252,7 @@ static void addRepresentationsForPlainText(WebItemProviderRegistrationInfoList *
252
252
253
253
void PlatformPasteboard::write (const PasteboardWebContent& content)
254
254
{
255
- #if __IPHONE_OS_VERSION_MAX_ALLOWED < 110000
256
- RetainPtr<NSMutableDictionary > representations = adoptNS ([[NSMutableDictionary alloc ] init ]);
257
- [representations addEntriesFromDictionary: richTextRepresentationsForPasteboardWebContent (content).autorelease ()];
258
-
259
- NSString *textAsString = content.dataInStringFormat ;
260
- [representations setValue: [textAsString dataUsingEncoding: NSUTF8StringEncoding] forKey: (NSString *)kUTTypeUTF8PlainText ];
261
- [representations setValue: [textAsString dataUsingEncoding: NSUTF16StringEncoding] forKey: (NSString *)kUTTypeUTF16PlainText ];
262
- // FIXME: We vend "public.text" here for backwards compatibility with pre-iOS 11 apps. In the future, we should stop vending this UTI,
263
- // and instead set data for concrete plain text types. See <https://bugs.webkit.org/show_bug.cgi?id=173317>.
264
- [representations setValue: textAsString forKey: (NSString *)kUTTypeText ];
265
-
266
- // Explicitly cast m_pasteboard to UIPasteboard * to work around rdar://problem/33383354.
267
- ASSERT ([m_pasteboard isKindOfClass: getUIPasteboardClass ()]);
268
- [(UIPasteboard *)m_pasteboard setItems: @[representations.get ()]];
269
- #else
255
+ #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000
270
256
auto representationsToRegister = adoptNS ([[WebItemProviderRegistrationInfoList alloc ] init ]);
271
257
272
258
[representationsToRegister addData: [webIOSPastePboardType dataUsingEncoding: NSUTF8StringEncoding] forType: webIOSPastePboardType];
@@ -294,23 +280,26 @@ static void addRepresentationsForPlainText(WebItemProviderRegistrationInfoList *
294
280
addRepresentationsForPlainText (representationsToRegister.get (), content.dataInStringFormat );
295
281
296
282
registerItemToPasteboard (representationsToRegister.get (), m_pasteboard.get ());
297
- #endif
298
- }
299
-
300
- void PlatformPasteboard::write (const PasteboardImage& pasteboardImage)
301
- {
302
- #if __IPHONE_OS_VERSION_MAX_ALLOWED < 110000
283
+ #else
303
284
RetainPtr<NSMutableDictionary > representations = adoptNS ([[NSMutableDictionary alloc ] init ]);
304
- if (!pasteboardImage.resourceMIMEType .isNull ()) {
305
- [representations setObject: pasteboardImage.resourceData->createNSData ().get () forKey: pasteboardImage.resourceMIMEType];
306
- if (!pasteboardImage.url .url .isNull ())
307
- [representations setObject: (NSURL *)pasteboardImage.url.url forKey: (NSString *)kUTTypeURL ];
308
- }
285
+ [representations addEntriesFromDictionary: richTextRepresentationsForPasteboardWebContent (content).autorelease ()];
286
+
287
+ NSString *textAsString = content.dataInStringFormat ;
288
+ [representations setValue: [textAsString dataUsingEncoding: NSUTF8StringEncoding] forKey: (NSString *)kUTTypeUTF8PlainText ];
289
+ [representations setValue: [textAsString dataUsingEncoding: NSUTF16StringEncoding] forKey: (NSString *)kUTTypeUTF16PlainText ];
290
+ // FIXME: We vend "public.text" here for backwards compatibility with pre-iOS 11 apps. In the future, we should stop vending this UTI,
291
+ // and instead set data for concrete plain text types. See <https://bugs.webkit.org/show_bug.cgi?id=173317>.
292
+ [representations setValue: textAsString forKey: (NSString *)kUTTypeText ];
309
293
310
294
// Explicitly cast m_pasteboard to UIPasteboard * to work around rdar://problem/33383354.
311
295
ASSERT ([m_pasteboard isKindOfClass: getUIPasteboardClass ()]);
312
296
[(UIPasteboard *)m_pasteboard setItems: @[representations.get ()]];
313
- #else
297
+ #endif
298
+ }
299
+
300
+ void PlatformPasteboard::write (const PasteboardImage& pasteboardImage)
301
+ {
302
+ #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000
314
303
auto representationsToRegister = adoptNS ([[WebItemProviderRegistrationInfoList alloc ] init ]);
315
304
316
305
auto & types = pasteboardImage.clientTypes ;
@@ -339,12 +328,36 @@ static void addRepresentationsForPlainText(WebItemProviderRegistrationInfoList *
339
328
}
340
329
341
330
registerItemToPasteboard (representationsToRegister.get (), m_pasteboard.get ());
331
+ #else
332
+ RetainPtr<NSMutableDictionary > representations = adoptNS ([[NSMutableDictionary alloc ] init ]);
333
+ if (!pasteboardImage.resourceMIMEType .isNull ()) {
334
+ [representations setObject: pasteboardImage.resourceData->createNSData ().get () forKey: pasteboardImage.resourceMIMEType];
335
+ if (!pasteboardImage.url .url .isNull ())
336
+ [representations setObject: (NSURL *)pasteboardImage.url.url forKey: (NSString *)kUTTypeURL ];
337
+ }
338
+
339
+ // Explicitly cast m_pasteboard to UIPasteboard * to work around rdar://problem/33383354.
340
+ ASSERT ([m_pasteboard isKindOfClass: getUIPasteboardClass ()]);
341
+ [(UIPasteboard *)m_pasteboard setItems: @[representations.get ()]];
342
342
#endif
343
343
}
344
344
345
345
void PlatformPasteboard::write (const String& pasteboardType, const String& text)
346
346
{
347
- #if __IPHONE_OS_VERSION_MAX_ALLOWED < 110000
347
+ #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000
348
+ auto representationsToRegister = adoptNS ([[WebItemProviderRegistrationInfoList alloc ] init ]);
349
+
350
+ NSString *pasteboardTypeAsNSString = pasteboardType;
351
+ if (!text.isEmpty () && pasteboardTypeAsNSString.length ) {
352
+ auto pasteboardTypeAsCFString = (CFStringRef )pasteboardTypeAsNSString;
353
+ if (UTTypeConformsTo (pasteboardTypeAsCFString, kUTTypeURL ) || UTTypeConformsTo (pasteboardTypeAsCFString, kUTTypeText ))
354
+ addRepresentationsForPlainText (representationsToRegister.get (), text);
355
+ else
356
+ [representationsToRegister addData: [pasteboardTypeAsNSString dataUsingEncoding: NSUTF8StringEncoding] forType: pasteboardType];
357
+ }
358
+
359
+ registerItemToPasteboard (representationsToRegister.get (), m_pasteboard.get ());
360
+ #else
348
361
RetainPtr<NSDictionary > representations = adoptNS ([[NSMutableDictionary alloc ] init ]);
349
362
350
363
NSString *textAsString = text;
@@ -363,27 +376,12 @@ static void addRepresentationsForPlainText(WebItemProviderRegistrationInfoList *
363
376
// Explicitly cast m_pasteboard to UIPasteboard * to work around rdar://problem/33383354.
364
377
ASSERT ([m_pasteboard isKindOfClass: getUIPasteboardClass ()]);
365
378
[(UIPasteboard *)m_pasteboard setItems: @[representations.get ()]];
366
- #else
367
- auto representationsToRegister = adoptNS ([[WebItemProviderRegistrationInfoList alloc ] init ]);
368
-
369
- NSString *pasteboardTypeAsNSString = pasteboardType;
370
- if (!text.isEmpty () && pasteboardTypeAsNSString.length ) {
371
- auto pasteboardTypeAsCFString = (CFStringRef )pasteboardTypeAsNSString;
372
- if (UTTypeConformsTo (pasteboardTypeAsCFString, kUTTypeURL ) || UTTypeConformsTo (pasteboardTypeAsCFString, kUTTypeText ))
373
- addRepresentationsForPlainText (representationsToRegister.get (), text);
374
- else
375
- [representationsToRegister addData: [pasteboardTypeAsNSString dataUsingEncoding: NSUTF8StringEncoding] forType: pasteboardType];
376
- }
377
-
378
- registerItemToPasteboard (representationsToRegister.get (), m_pasteboard.get ());
379
379
#endif
380
380
}
381
381
382
382
void PlatformPasteboard::write (const PasteboardURL& url)
383
383
{
384
- #if __IPHONE_OS_VERSION_MAX_ALLOWED < 110000
385
- write (kUTTypeURL , url.url .string ());
386
- #else
384
+ #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000
387
385
auto representationsToRegister = adoptNS ([[WebItemProviderRegistrationInfoList alloc ] init ]);
388
386
389
387
if (NSURL *nsURL = url.url ) {
@@ -393,6 +391,8 @@ static void addRepresentationsForPlainText(WebItemProviderRegistrationInfoList *
393
391
}
394
392
395
393
registerItemToPasteboard (representationsToRegister.get (), m_pasteboard.get ());
394
+ #else
395
+ write (kUTTypeURL , url.url .string ());
396
396
#endif
397
397
}
398
398
0 commit comments