Title: [168145] trunk/Source/WebKit/mac
- Revision
- 168145
- Author
- beid...@apple.com
- Date
- 2014-05-01 20:31:43 -0700 (Thu, 01 May 2014)
Log Message
Update service picker API usage.
<rdar://problem/16772674> and https://bugs.webkit.org/show_bug.cgi?id=132452
Reviewed by Tim Horton.
* Misc/WebSharingServicePickerController.h:
* Misc/WebSharingServicePickerController.mm:
(-[WebSharingServicePickerController didShareImageData:confirmDataIsValidTIFFData:]):
Factor out a common "didShare" handler that optionally validates whether the data represents an image.
(-[WebSharingServicePickerController sharingService:didShareItems:]): Update API usage, including marshalling
on off-main thread call back to the main thread.
* WebCoreSupport/WebContextMenuClient.mm:
(WebContextMenuClient::contextMenuForEvent): Update API usage.
Modified Paths
Diff
Modified: trunk/Source/WebKit/mac/ChangeLog (168144 => 168145)
--- trunk/Source/WebKit/mac/ChangeLog 2014-05-02 02:28:49 UTC (rev 168144)
+++ trunk/Source/WebKit/mac/ChangeLog 2014-05-02 03:31:43 UTC (rev 168145)
@@ -1,3 +1,20 @@
+2014-05-01 Brady Eidson <beid...@apple.com>
+
+ Update service picker API usage.
+ <rdar://problem/16772674> and https://bugs.webkit.org/show_bug.cgi?id=132452
+
+ Reviewed by Tim Horton.
+
+ * Misc/WebSharingServicePickerController.h:
+ * Misc/WebSharingServicePickerController.mm:
+ (-[WebSharingServicePickerController didShareImageData:confirmDataIsValidTIFFData:]):
+ Factor out a common "didShare" handler that optionally validates whether the data represents an image.
+ (-[WebSharingServicePickerController sharingService:didShareItems:]): Update API usage, including marshalling
+ on off-main thread call back to the main thread.
+
+ * WebCoreSupport/WebContextMenuClient.mm:
+ (WebContextMenuClient::contextMenuForEvent): Update API usage.
+
2014-05-01 Anders Carlsson <ander...@apple.com>
Support OS-version-specific install paths for WebKit.framework
Modified: trunk/Source/WebKit/mac/Misc/WebSharingServicePickerController.h (168144 => 168145)
--- trunk/Source/WebKit/mac/Misc/WebSharingServicePickerController.h 2014-05-02 02:28:49 UTC (rev 168144)
+++ trunk/Source/WebKit/mac/Misc/WebSharingServicePickerController.h 2014-05-02 03:31:43 UTC (rev 168145)
@@ -39,8 +39,9 @@
BOOL _includeEditorServices;
}
-- (instancetype)initWithImage:(NSImage *)image includeEditorServices:(BOOL)includeEditorServices menuClient:(WebContextMenuClient*)menuClient;
+- (instancetype)initWithData:(NSData *)data includeEditorServices:(BOOL)includeEditorServices menuClient:(WebContextMenuClient*)menuClient;
- (NSMenu *)menu;
+- (void)didShareImageData:(NSData *)data confirmDataIsValidTIFFData:(BOOL)confirmData;
@end
Modified: trunk/Source/WebKit/mac/Misc/WebSharingServicePickerController.mm (168144 => 168145)
--- trunk/Source/WebKit/mac/Misc/WebSharingServicePickerController.mm 2014-05-02 02:28:49 UTC (rev 168144)
+++ trunk/Source/WebKit/mac/Misc/WebSharingServicePickerController.mm 2014-05-02 03:31:43 UTC (rev 168145)
@@ -49,7 +49,16 @@
@property NSSharingServicePickerStyle style;
- (NSMenu *)menu;
@end
+#endif
+#if __has_include(<AppKit/NSItemProvider.h>)
+#import <AppKit/NSItemProvider.h>
+#else
+@interface NSItemProvider : NSObject
+@property (copy, readonly) NSArray *registeredTypeIdentifiers;
+- (instancetype)initWithItem:(id <NSSecureCoding>)item typeIdentifier:(NSString *)typeIdentifier;
+- (void)loadItemForTypeIdentifier:(NSString *)typeIdentifier options:(NSDictionary *)options completionHandler:(void (^)(id <NSSecureCoding> item, NSError *error))completionHandler;
+@end
#endif
static NSString *serviceControlsPasteboardName = @"WebKitServiceControlsPasteboard";
@@ -58,12 +67,14 @@
@implementation WebSharingServicePickerController
-- (instancetype)initWithImage:(NSImage *)image includeEditorServices:(BOOL)includeEditorServices menuClient:(WebContextMenuClient*)menuClient
+- (instancetype)initWithData:(NSData *)data includeEditorServices:(BOOL)includeEditorServices menuClient:(WebContextMenuClient*)menuClient
{
if (!(self = [super init]))
return nil;
- _picker = adoptNS([[NSSharingServicePicker alloc] initWithItems:@[ image ]]);
+ RetainPtr<NSItemProvider> itemProvider = adoptNS([[NSItemProvider alloc] initWithItem:data typeIdentifier:@"public.data"]);
+
+ _picker = adoptNS([[NSSharingServicePicker alloc] initWithItems:@[ itemProvider.get() ]]);
[_picker setStyle:NSSharingServicePickerStyleRollover];
[_picker setDelegate:self];
@@ -86,9 +97,35 @@
return [_picker menu];
}
+- (void)didShareImageData:(NSData *)data confirmDataIsValidTIFFData:(BOOL)confirmData
+{
+ Page* page = [_menuClient->webView() page];
+ if (!page)
+ return;
+
+ if (confirmData) {
+ RetainPtr<NSImage> nsImage = adoptNS([[NSImage alloc] initWithData:data]);
+ if (!nsImage) {
+ LOG_ERROR("Shared image data cannot create a valid NSImage");
+ return;
+ }
+
+ data = "" TIFFRepresentation];
+ }
+
+ NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName:serviceControlsPasteboardName];
+ [pasteboard declareTypes:@[ NSPasteboardTypeTIFF ] owner:nil];
+ [pasteboard setData:data forType:NSPasteboardTypeTIFF];
+
+ Frame& frame = page->focusController().focusedOrMainFrame();
+ if (!frame.selection().isNone())
+ frame.editor().readSelectionFromPasteboard(serviceControlsPasteboardName);
+
+ [self clear];
+}
+
#pragma mark NSSharingServicePickerDelegate methods
-
- (NSArray *)sharingServicePicker:(NSSharingServicePicker *)sharingServicePicker sharingServicesForItems:(NSArray *)items mask:(NSSharingServiceMask)mask proposedSharingServices:(NSArray *)proposedServices
{
if (_includeEditorServices)
@@ -123,25 +160,32 @@
if ([items count] != 1)
return;
- RetainPtr<CGImageSourceRef> source = adoptCF(CGImageSourceCreateWithData((CFDataRef)[items objectAtIndex:0], NULL));
- RetainPtr<CGImageRef> cgImage = adoptCF(CGImageSourceCreateImageAtIndex(source.get(), 0, NULL));
+ id item = [items objectAtIndex:0];
- if (!cgImage)
- return;
+ if ([item isKindOfClass:[NSImage class]])
+ [self didShareImageData:[item TIFFRepresentation] confirmDataIsValidTIFFData:NO];
+ else if ([item isKindOfClass:[NSItemProvider class]]) {
+ NSItemProvider *itemProvider = (NSItemProvider *)item;
+ NSString *itemUTI = itemProvider.registeredTypeIdentifiers.firstObject;
+
+ [itemProvider loadItemForTypeIdentifier:itemUTI options:nil completionHandler:^(id receivedData, NSError *dataError) {
+ if (!receivedData) {
+ LOG_ERROR("Did not receive data from NSItemProvider");
+ return;
+ }
- Page* page = [_menuClient->webView() page];
- if (!page)
- return;
+ if (![receivedData isKindOfClass:[NSData class]]) {
+ LOG_ERROR("Data received from NSItemProvider is not of type NSData");
+ return;
+ }
- NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName:serviceControlsPasteboardName];
- [pasteboard declareTypes:@[ NSPasteboardTypeTIFF ] owner:nil];
- [pasteboard setData:[items objectAtIndex:0] forType:NSPasteboardTypeTIFF];
+ [[NSOperationQueue mainQueue] addOperationWithBlock:^{
+ [self didShareImageData:receivedData confirmDataIsValidTIFFData:YES];
+ }];
- Frame& frame = page->focusController().focusedOrMainFrame();
- if (!frame.selection().isNone())
- frame.editor().readSelectionFromPasteboard(serviceControlsPasteboardName);
-
- [self clear];
+ }];
+ } else
+ LOG_ERROR("sharingService:didShareItems: - Unknown item type returned");
}
- (void)sharingService:(NSSharingService *)sharingService didFailToShareItems:(NSArray *)items error:(NSError *)error
Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebContextMenuClient.mm (168144 => 168145)
--- trunk/Source/WebKit/mac/WebCoreSupport/WebContextMenuClient.mm 2014-05-02 02:28:49 UTC (rev 168144)
+++ trunk/Source/WebKit/mac/WebCoreSupport/WebContextMenuClient.mm 2014-05-02 03:31:43 UTC (rev 168145)
@@ -50,6 +50,7 @@
#import <WebCore/URL.h>
#import <WebCore/LocalizedStrings.h>
#import <WebCore/Page.h>
+#import <WebCore/SharedBuffer.h>
#import <WebCore/Frame.h>
#import <WebCore/FrameView.h>
#import <WebCore/RuntimeApplicationChecks.h>
@@ -363,8 +364,13 @@
#if ENABLE(SERVICE_CONTROLS)
if (Image* image = page->contextMenuController().context().controlledImage()) {
ASSERT(page->contextMenuController().context().hitTestResult().innerNode());
+
+ RefPtr<SharedBuffer> data = ""
+ ASSERT(data);
+ RetainPtr<CFDataRef> cfData = data->createCFData();
+
bool isContentEditable = page->contextMenuController().context().hitTestResult().innerNode()->isContentEditable();
- m_sharingServicePickerController = adoptNS([[WebSharingServicePickerController alloc] initWithImage:image->getNSImage() includeEditorServices:isContentEditable menuClient:this]);
+ m_sharingServicePickerController = adoptNS([[WebSharingServicePickerController alloc] initWithData:(NSData *)cfData.get() includeEditorServices:isContentEditable menuClient:this]);
return [m_sharingServicePickerController menu];
}
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes