Changeset 211852 in webkit
- Timestamp:
- Feb 7, 2017 5:47:31 PM (7 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r211845 r211852 1 2017-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 1 33 2017-02-06 Ryosuke Niwa <rniwa@webkit.org> 2 34 -
trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.mm
r211716 r211852 35 35 #import <UIKit/UIColor.h> 36 36 #import <UIKit/UIImage.h> 37 #import <UIKit/UIItemProviderWriting.h> 38 #import <wtf/RetainPtr.h> 37 39 38 40 SOFT_LINK_FRAMEWORK(UIKit) … … 77 79 @end 78 80 79 @implementation WebItemProviderPasteboard 81 @implementation WebItemProviderPasteboard { 82 RetainPtr<NSArray> _itemProviders; 83 } 80 84 81 85 + (instancetype)sharedInstance … … 92 96 { 93 97 if (self = [super init]) { 94 _itemProviders = [[NSArray alloc] init];98 _itemProviders = adoptNS([[NSArray alloc] init]); 95 99 _changeCount = 0; 96 100 _pendingOperationCount = 0; … … 99 103 } 100 104 101 - (void)dealloc102 {103 [super dealloc];104 [_itemProviders release];105 }106 107 105 - (NSArray<NSString *> *)pasteboardTypes 108 106 { 109 107 NSMutableSet<NSString *> *allTypes = [NSMutableSet set]; 110 for (UIItemProvider *provider in _itemProviders )108 for (UIItemProvider *provider in _itemProviders.get()) 111 109 [allTypes addObjectsFromArray:provider.registeredTypeIdentifiers]; 112 110 return allTypes.allObjects; 111 } 112 113 - (NSArray<UIItemProvider *> *)itemProviders 114 { 115 return _itemProviders.get(); 113 116 } 114 117 … … 118 121 if (_itemProviders == itemProviders || [_itemProviders isEqualToArray:itemProviders]) 119 122 return; 120 _itemProviders = [itemProviders copy]; 123 124 _itemProviders = itemProviders; 121 125 _changeCount++; 122 126 } … … 124 128 - (NSInteger)numberOfItems 125 129 { 126 return _itemProviders.count;130 return [_itemProviders count]; 127 131 } 128 132 129 133 - (void)setItems:(NSArray *)items 130 134 { 131 NSMutableArray *providers = [ [NSMutableArray alloc] init];135 NSMutableArray *providers = [NSMutableArray array]; 132 136 for (NSDictionary *item in items) { 133 137 if (!item.count) 134 138 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()) { 137 157 [itemProvider registerDataRepresentationForTypeIdentifier:typeIdentifier options:nil loadHandler:^NSProgress *(UIItemProviderDataLoadCompletionBlock completionBlock) 138 158 { 139 completionBlock( item[typeIdentifier], nil);159 completionBlock([itemRepresentationsCopy objectForKey:typeIdentifier], nil); 140 160 return [NSProgress discreteProgressWithTotalUnitCount:100]; 141 161 }]; 142 162 } 143 [providers addObject:itemProvider ];163 [providers addObject:itemProvider.get()]; 144 164 } 145 165 _changeCount++; … … 175 195 return; 176 196 177 if (isImageType(pasteboardType) && [self _tryToCreateAndAppendObjectOfClass:[ NSStringclass] toArray:values usingProvider:provider])197 if (isImageType(pasteboardType) && [self _tryToCreateAndAppendObjectOfClass:[getUIImageClass() class] toArray:values usingProvider:provider]) 178 198 return; 179 199 … … 211 231 - (UIItemProvider *)itemProviderAtIndex:(NSInteger)index 212 232 { 213 return 0 <= index && index < (NSInteger) _itemProviders.count ? _itemProviders[index] : nil;233 return 0 <= index && index < (NSInteger)[_itemProviders count] ? [_itemProviders objectAtIndex:index] : nil; 214 234 } 215 235
Note: See TracChangeset
for help on using the changeset viewer.