Stop using ContextMenuItem::shareMenuItem in the UI process
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 28 Oct 2015 21:16:22 +0000 (21:16 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 28 Oct 2015 21:16:22 +0000 (21:16 +0000)
https://bugs.webkit.org/show_bug.cgi?id=150578

Reviewed by Tim Horton.

* UIProcess/mac/WebContextMenuProxyMac.h:
* UIProcess/mac/WebContextMenuProxyMac.mm:
(WebKit::WebContextMenuProxyMac::createShareMenuItem):
(WebKit::WebContextMenuProxyMac::createContextMenuItem):
(WebKit::WebContextMenuProxyMac::shareMenuItem): Deleted.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@191691 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.h
Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.mm

index 75dd003..ef901a2 100644 (file)
@@ -1,3 +1,16 @@
+2015-10-28  Anders Carlsson  <andersca@apple.com>
+
+        Stop using ContextMenuItem::shareMenuItem in the UI process
+        https://bugs.webkit.org/show_bug.cgi?id=150578
+
+        Reviewed by Tim Horton.
+
+        * UIProcess/mac/WebContextMenuProxyMac.h:
+        * UIProcess/mac/WebContextMenuProxyMac.mm:
+        (WebKit::WebContextMenuProxyMac::createShareMenuItem):
+        (WebKit::WebContextMenuProxyMac::createContextMenuItem):
+        (WebKit::WebContextMenuProxyMac::shareMenuItem): Deleted.
+
 2015-10-28  Tim Horton  <timothy_horton@apple.com>
 
         WKView being inside WKWebView leads to weird API issues
index c4ea154..1b2b076 100644 (file)
@@ -64,9 +64,9 @@ private:
     void showContextMenu();
 
 #if ENABLE(SERVICE_CONTROLS)
+    RetainPtr<NSMenuItem> createShareMenuItem();
     void showServicesMenu();
     void setupServicesMenu();
-    WebCore::ContextMenuItem shareMenuItem();
 #endif
 
     RetainPtr<NSMenu> m_menu;
index 448c0bd..9587d67 100644 (file)
@@ -42,6 +42,7 @@
 #import "WebProcessProxy.h"
 #import <WebCore/GraphicsContext.h>
 #import <WebCore/IntRect.h>
+#import <WebCore/NSMenuSPI.h>
 #import <WebCore/NSSharingServicePickerSPI.h>
 #import <WebCore/NSSharingServiceSPI.h>
 #import <WebKitSystemInterface.h>
@@ -257,29 +258,35 @@ void WebContextMenuProxyMac::clearServicesMenu()
     m_menu = nullptr;
 }
 
-ContextMenuItem WebContextMenuProxyMac::shareMenuItem()
+RetainPtr<NSMenuItem> WebContextMenuProxyMac::createShareMenuItem()
 {
+    if (![[NSMenuItem class] respondsToSelector:@selector(standardShareMenuItemWithItems:)])
+        return nil;
+
     const WebHitTestResultData& hitTestData = m_context.webHitTestResultData();
 
-    URL absoluteLinkURL;
-    if (!hitTestData.absoluteLinkURL.isEmpty())
-        absoluteLinkURL = URL(ParsedURLString, hitTestData.absoluteLinkURL);
+    auto items = adoptNS([[NSMutableArray alloc] init]);
 
-    URL downloadableMediaURL;
-    if (!hitTestData.absoluteMediaURL.isEmpty() && hitTestData.isDownloadableMedia)
-        downloadableMediaURL = URL(ParsedURLString, hitTestData.absoluteMediaURL);
+    if (!hitTestData.absoluteLinkURL.isEmpty()) {
+        NSURL *absoluteLinkURL = [NSURL URLWithString:hitTestData.absoluteLinkURL];
+        [items addObject:absoluteLinkURL];
+    }
 
-    RetainPtr<NSImage> image;
-    if (hitTestData.imageSharedMemory && hitTestData.imageSize)
-        image = adoptNS([[NSImage alloc] initWithData:[NSData dataWithBytes:(unsigned char*)hitTestData.imageSharedMemory->data() length:hitTestData.imageSize]]);
+    if (hitTestData.isDownloadableMedia && !hitTestData.absoluteMediaURL.isEmpty()) {
+        NSURL *downloadableMediaURL = [NSURL URLWithString:hitTestData.absoluteMediaURL];
+        [items addObject:downloadableMediaURL];
+    }
 
-    ContextMenuItem item = ContextMenuItem::shareMenuItem(absoluteLinkURL, downloadableMediaURL, image.get(), m_context.selectedText());
-    if (item.isNull())
-        return item;
+    if (hitTestData.imageSharedMemory && hitTestData.imageSize) {
+        auto image = adoptNS([[NSImage alloc] initWithData:[NSData dataWithBytes:(unsigned char*)hitTestData.imageSharedMemory->data() length:hitTestData.imageSize]]);
+        [items addObject:image.get()];
+    }
 
-    NSMenuItem *nsItem = item.platformDescription();
+    RetainPtr<NSMenuItem> item = [NSMenuItem standardShareMenuItemWithItems:items.get()];
+    if (!item)
+        return nil;
 
-    NSSharingServicePicker *sharingServicePicker = [nsItem representedObject];
+    NSSharingServicePicker *sharingServicePicker = [item representedObject];
     sharingServicePicker.delegate = [WKSharingServicePickerDelegate sharedSharingServicePickerDelegate];
 
     [[WKSharingServicePickerDelegate sharedSharingServicePickerDelegate] setFiltersEditingServices:NO];
@@ -324,7 +331,7 @@ RetainPtr<NSMenuItem> WebContextMenuProxyMac::createContextMenuItem(const WebCon
 {
 #if ENABLE(SERVICE_CONTROLS)
     if (item.action() == ContextMenuItemTagShareMenu)
-        return shareMenuItem().platformDescription();
+        return createShareMenuItem();
 #endif
 
     switch (item.type()) {