Changeset 211852 in webkit


Ignore:
Timestamp:
Feb 7, 2017 5:47:31 PM (7 years ago)
Author:
Wenson Hsieh
Message:

WebItemProviderPasteboard should use -registerLoadHandlersToItemProvider: when creating a new UIItemProvider
https://bugs.webkit.org/show_bug.cgi?id=167918
<rdar://problem/30382347>

Reviewed by Tim Horton.

Adopts SPI in WebItemProviderPasteboard for object types that the platform knows how to serialize. Since we use
-createObjectOfClass: to initialize data when reading off of the pasteboard, we need to match the format that
objects conforming to UIItemProviderReading will expect. Thus, for all given objects that conform to
UIItemProviderWriting, we have them register themselves to the item provider.

We register other UTI types due to the fact that PlatformPasteboardIOS does not care about the specific
pasteboard used. This should not be necessary, however, since data written to the WebItemProviderPasteboard
should never need to be read by an actual UIPasteboard. This will be refactored in a future patch to add a
special type of WebItemProviderPasteboard-aware PlatformPasteboard.

Also fixes some reference counting issues in WebItemProviderPasteboard by changing the array of _itemProviders
to be a RetainPtr.

  • platform/ios/WebItemProviderPasteboard.mm:

(-[WebItemProviderPasteboard init]):
(-[WebItemProviderPasteboard pasteboardTypes]):
(-[WebItemProviderPasteboard itemProviders]):
(-[WebItemProviderPasteboard setItemProviders:]):
(-[WebItemProviderPasteboard numberOfItems]):
(-[WebItemProviderPasteboard setItems:]):
(-[WebItemProviderPasteboard valuesForPasteboardType:inItemSet:]):
(-[WebItemProviderPasteboard itemProviderAtIndex:]):
(-[WebItemProviderPasteboard dealloc]): Deleted.

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r211845 r211852  
     12017-02-07  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        WebItemProviderPasteboard should use -registerLoadHandlersToItemProvider: when creating a new UIItemProvider
     4        https://bugs.webkit.org/show_bug.cgi?id=167918
     5        <rdar://problem/30382347>
     6
     7        Reviewed by Tim Horton.
     8
     9        Adopts SPI in WebItemProviderPasteboard for object types that the platform knows how to serialize. Since we use
     10        -createObjectOfClass: to initialize data when reading off of the pasteboard, we need to match the format that
     11        objects conforming to UIItemProviderReading will expect. Thus, for all given objects that conform to
     12        UIItemProviderWriting, we have them register themselves to the item provider.
     13
     14        We register other UTI types due to the fact that PlatformPasteboardIOS does not care about the specific
     15        pasteboard used. This should not be necessary, however, since data written to the WebItemProviderPasteboard
     16        should never need to be read by an actual UIPasteboard. This will be refactored in a future patch to add a
     17        special type of WebItemProviderPasteboard-aware PlatformPasteboard.
     18
     19        Also fixes some reference counting issues in WebItemProviderPasteboard by changing the array of _itemProviders
     20        to be a RetainPtr.
     21
     22        * platform/ios/WebItemProviderPasteboard.mm:
     23        (-[WebItemProviderPasteboard init]):
     24        (-[WebItemProviderPasteboard pasteboardTypes]):
     25        (-[WebItemProviderPasteboard itemProviders]):
     26        (-[WebItemProviderPasteboard setItemProviders:]):
     27        (-[WebItemProviderPasteboard numberOfItems]):
     28        (-[WebItemProviderPasteboard setItems:]):
     29        (-[WebItemProviderPasteboard valuesForPasteboardType:inItemSet:]):
     30        (-[WebItemProviderPasteboard itemProviderAtIndex:]):
     31        (-[WebItemProviderPasteboard dealloc]): Deleted.
     32
    1332017-02-06  Ryosuke Niwa  <rniwa@webkit.org>
    234
  • trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.mm

    r211716 r211852  
    3535#import <UIKit/UIColor.h>
    3636#import <UIKit/UIImage.h>
     37#import <UIKit/UIItemProviderWriting.h>
     38#import <wtf/RetainPtr.h>
    3739
    3840SOFT_LINK_FRAMEWORK(UIKit)
     
    7779@end
    7880
    79 @implementation WebItemProviderPasteboard
     81@implementation WebItemProviderPasteboard {
     82    RetainPtr<NSArray> _itemProviders;
     83}
    8084
    8185+ (instancetype)sharedInstance
     
    9296{
    9397    if (self = [super init]) {
    94         _itemProviders = [[NSArray alloc] init];
     98        _itemProviders = adoptNS([[NSArray alloc] init]);
    9599        _changeCount = 0;
    96100        _pendingOperationCount = 0;
     
    99103}
    100104
    101 - (void)dealloc
    102 {
    103     [super dealloc];
    104     [_itemProviders release];
    105 }
    106 
    107105- (NSArray<NSString *> *)pasteboardTypes
    108106{
    109107    NSMutableSet<NSString *> *allTypes = [NSMutableSet set];
    110     for (UIItemProvider *provider in _itemProviders)
     108    for (UIItemProvider *provider in _itemProviders.get())
    111109        [allTypes addObjectsFromArray:provider.registeredTypeIdentifiers];
    112110    return allTypes.allObjects;
     111}
     112
     113- (NSArray<UIItemProvider *> *)itemProviders
     114{
     115    return _itemProviders.get();
    113116}
    114117
     
    118121    if (_itemProviders == itemProviders || [_itemProviders isEqualToArray:itemProviders])
    119122        return;
    120     _itemProviders = [itemProviders copy];
     123
     124    _itemProviders = itemProviders;
    121125    _changeCount++;
    122126}
     
    124128- (NSInteger)numberOfItems
    125129{
    126     return _itemProviders.count;
     130    return [_itemProviders count];
    127131}
    128132
    129133- (void)setItems:(NSArray *)items
    130134{
    131     NSMutableArray *providers = [[NSMutableArray alloc] init];
     135    NSMutableArray *providers = [NSMutableArray array];
    132136    for (NSDictionary *item in items) {
    133137        if (!item.count)
    134138            continue;
    135         UIItemProvider *itemProvider = [[getUIItemProviderClass() alloc] init];
    136         for (NSString *typeIdentifier in item) {
     139        RetainPtr<UIItemProvider> itemProvider = adoptNS([[getUIItemProviderClass() alloc] init]);
     140        RetainPtr<NSMutableDictionary> itemRepresentationsCopy = adoptNS([item mutableCopy]);
     141        // First, let the platform write all the default object types it can recognize, such as NSString and NSURL.
     142        for (NSString *typeIdentifier in [itemRepresentationsCopy allKeys]) {
     143            id representingObject = [itemRepresentationsCopy objectForKey:typeIdentifier];
     144            if (![representingObject conformsToProtocol:@protocol(UIItemProviderWriting)])
     145                continue;
     146
     147            id <UIItemProviderWriting> objectToWrite = (id <UIItemProviderWriting>)representingObject;
     148            if (![objectToWrite.writableTypeIdentifiersForItemProvider containsObject:typeIdentifier])
     149                continue;
     150
     151            [itemRepresentationsCopy removeObjectForKey:typeIdentifier];
     152            [objectToWrite registerLoadHandlersToItemProvider:itemProvider.get()];
     153        }
     154
     155        // Secondly, WebKit uses some custom type representations and/or type identifiers, so we need to write these as well.
     156        for (NSString *typeIdentifier in itemRepresentationsCopy.get()) {
    137157            [itemProvider registerDataRepresentationForTypeIdentifier:typeIdentifier options:nil loadHandler:^NSProgress *(UIItemProviderDataLoadCompletionBlock completionBlock)
    138158            {
    139                 completionBlock(item[typeIdentifier], nil);
     159                completionBlock([itemRepresentationsCopy objectForKey:typeIdentifier], nil);
    140160                return [NSProgress discreteProgressWithTotalUnitCount:100];
    141161            }];
    142162        }
    143         [providers addObject:itemProvider];
     163        [providers addObject:itemProvider.get()];
    144164    }
    145165    _changeCount++;
     
    175195            return;
    176196
    177         if (isImageType(pasteboardType) && [self _tryToCreateAndAppendObjectOfClass:[NSString class] toArray:values usingProvider:provider])
     197        if (isImageType(pasteboardType) && [self _tryToCreateAndAppendObjectOfClass:[getUIImageClass() class] toArray:values usingProvider:provider])
    178198            return;
    179199
     
    211231- (UIItemProvider *)itemProviderAtIndex:(NSInteger)index
    212232{
    213     return 0 <= index && index < (NSInteger)_itemProviders.count ? _itemProviders[index] : nil;
     233    return 0 <= index && index < (NSInteger)[_itemProviders count] ? [_itemProviders objectAtIndex:index] : nil;
    214234}
    215235
Note: See TracChangeset for help on using the changeset viewer.