Title: [189102] trunk/Source
Revision
189102
Author
timothy_hor...@apple.com
Date
2015-08-28 10:35:07 -0700 (Fri, 28 Aug 2015)

Log Message

[Mac] Right-clicking on GIFs spins the UI process for a while
https://bugs.webkit.org/show_bug.cgi?id=148566
<rdar://problem/22460854>

Reviewed by Brady Eidson.

* platform/ContextMenuItem.h:
Properly mark this as Mac-only. It's only implemented in ContextMenuItemMac.

* platform/mac/ContextMenuItemMac.mm:
(WebCore::ContextMenuItem::shareMenuItem):
Take a NSImage directly, so we don't have to round-trip through BitmapImage,
which can be lossy and expensive.

* WebCoreSupport/WebContextMenuClient.mm:
(WebContextMenuClient::shareMenuItem):
Make an NSImage directly from the hit image if possible.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::internalShowContextMenu):
(WebKit::WebPageProxy::platformInitializeShareMenuItem):
* UIProcess/WebPageProxy.h:
* UIProcess/mac/WebPageProxyMac.mm:
(WebKit::WebPageProxy::platformInitializeShareMenuItem):
Move all of the code to make a Share menuitem into platformInitializeShareMenuItem.
Make an NSImage directly from the image data if possible.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (189101 => 189102)


--- trunk/Source/WebCore/ChangeLog	2015-08-28 17:14:11 UTC (rev 189101)
+++ trunk/Source/WebCore/ChangeLog	2015-08-28 17:35:07 UTC (rev 189102)
@@ -1,3 +1,19 @@
+2015-08-28  Timothy Horton  <timothy_hor...@apple.com>
+
+        [Mac] Right-clicking on GIFs spins the UI process for a while
+        https://bugs.webkit.org/show_bug.cgi?id=148566
+        <rdar://problem/22460854>
+
+        Reviewed by Brady Eidson.
+
+        * platform/ContextMenuItem.h:
+        Properly mark this as Mac-only. It's only implemented in ContextMenuItemMac.
+
+        * platform/mac/ContextMenuItemMac.mm:
+        (WebCore::ContextMenuItem::shareMenuItem):
+        Take a NSImage directly, so we don't have to round-trip through BitmapImage,
+        which can be lossy and expensive.
+
 2015-08-28  Brady Eidson  <beid...@apple.com>
 
         Use new CFNetwork cookie jar SPI only on El Capitan.

Modified: trunk/Source/WebCore/platform/ContextMenuItem.cpp (189101 => 189102)


--- trunk/Source/WebCore/platform/ContextMenuItem.cpp	2015-08-28 17:14:11 UTC (rev 189101)
+++ trunk/Source/WebCore/platform/ContextMenuItem.cpp	2015-08-28 17:35:07 UTC (rev 189102)
@@ -131,11 +131,6 @@
     return m_enabled;
 }
 
-ContextMenuItem ContextMenuItem::shareMenuItem(const URL&, const URL&, Image*, const String&)
-{
-    return ContextMenuItem(SubmenuType, ContextMenuItemTagShareMenu, emptyString());
-}
-
 } // namespace WebCore
 
 #endif // ENABLE(CONTEXT_MENUS) && USE(CROSS_PLATFORM_CONTEXT_MENUS)

Modified: trunk/Source/WebCore/platform/ContextMenuItem.h (189101 => 189102)


--- trunk/Source/WebCore/platform/ContextMenuItem.h	2015-08-28 17:14:11 UTC (rev 189101)
+++ trunk/Source/WebCore/platform/ContextMenuItem.h	2015-08-28 17:35:07 UTC (rev 189102)
@@ -34,6 +34,7 @@
 
 #if PLATFORM(COCOA)
 #include <wtf/RetainPtr.h>
+OBJC_CLASS NSImage;
 OBJC_CLASS NSMenuItem;
 #elif PLATFORM(GTK)
 typedef struct _GtkMenuItem GtkMenuItem;
@@ -207,7 +208,9 @@
 
         void setSubMenu(ContextMenu*);
 
-        WEBCORE_EXPORT static ContextMenuItem shareMenuItem(const URL& absoluteLinkURL, const URL& downloadableMediaURL, Image*, const String& selectedText);
+#if PLATFORM(MAC)
+        WEBCORE_EXPORT static ContextMenuItem shareMenuItem(const URL& absoluteLinkURL, const URL& downloadableMediaURL, NSImage *, const String& selectedText);
+#endif
 
 #if PLATFORM(GTK)
         GtkAction* gtkAction() const;

Modified: trunk/Source/WebCore/platform/gtk/ContextMenuItemGtk.cpp (189101 => 189102)


--- trunk/Source/WebCore/platform/gtk/ContextMenuItemGtk.cpp	2015-08-28 17:14:11 UTC (rev 189101)
+++ trunk/Source/WebCore/platform/gtk/ContextMenuItemGtk.cpp	2015-08-28 17:35:07 UTC (rev 189102)
@@ -288,11 +288,6 @@
     return gtk_activatable_get_related_action(GTK_ACTIVATABLE(m_platformDescription));
 }
 
-ContextMenuItem ContextMenuItem::shareMenuItem(const URL&, const URL&, Image*, const String&)
-{
-    return ContextMenuItem();
 }
 
-}
-
 #endif // ENABLE(CONTEXT_MENUS)

Modified: trunk/Source/WebCore/platform/mac/ContextMenuItemMac.mm (189101 => 189102)


--- trunk/Source/WebCore/platform/mac/ContextMenuItemMac.mm	2015-08-28 17:14:11 UTC (rev 189101)
+++ trunk/Source/WebCore/platform/mac/ContextMenuItemMac.mm	2015-08-28 17:35:07 UTC (rev 189102)
@@ -196,7 +196,7 @@
     return [m_platformDescription.get() state] == NSOnState;
 }
 
-ContextMenuItem ContextMenuItem::shareMenuItem(const URL& absoluteLinkURL, const URL& downloadableMediaURL, Image* image, const String& selectedText)
+ContextMenuItem ContextMenuItem::shareMenuItem(const URL& absoluteLinkURL, const URL& downloadableMediaURL, NSImage *image, const String& selectedText)
 {
     if (![[NSMenuItem class] respondsToSelector:@selector(standardShareMenuItemWithItems:)])
         return ContextMenuItem();
@@ -209,11 +209,8 @@
     if (!downloadableMediaURL.isEmpty())
         [items addObject:(NSURL *)downloadableMediaURL];
 
-    if (image) {
-        NSImage *nsImage = image->getNSImage();
-        if (nsImage)
-            [items addObject:nsImage];
-    }
+    if (image)
+        [items addObject:image];
 
     if (!selectedText.isEmpty())
         [items addObject:(NSString *)selectedText];

Modified: trunk/Source/WebKit/mac/ChangeLog (189101 => 189102)


--- trunk/Source/WebKit/mac/ChangeLog	2015-08-28 17:14:11 UTC (rev 189101)
+++ trunk/Source/WebKit/mac/ChangeLog	2015-08-28 17:35:07 UTC (rev 189102)
@@ -1,3 +1,15 @@
+2015-08-28  Timothy Horton  <timothy_hor...@apple.com>
+
+        [Mac] Right-clicking on GIFs spins the UI process for a while
+        https://bugs.webkit.org/show_bug.cgi?id=148566
+        <rdar://problem/22460854>
+
+        Reviewed by Brady Eidson.
+
+        * WebCoreSupport/WebContextMenuClient.mm:
+        (WebContextMenuClient::shareMenuItem):
+        Make an NSImage directly from the hit image if possible.
+
 2015-08-27  Timothy Horton  <timothy_hor...@apple.com>
 
         Factor out Lookup invocation

Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebContextMenuClient.mm (189101 => 189102)


--- trunk/Source/WebKit/mac/WebCoreSupport/WebContextMenuClient.mm	2015-08-28 17:14:11 UTC (rev 189101)
+++ trunk/Source/WebKit/mac/WebCoreSupport/WebContextMenuClient.mm	2015-08-28 17:35:07 UTC (rev 189102)
@@ -387,7 +387,13 @@
     if (!hitTestResult.absoluteMediaURL().isEmpty() && hitTestResult.isDownloadableMedia())
         downloadableMediaURL = hitTestResult.absoluteMediaURL();
 
-    return ContextMenuItem::shareMenuItem(hitTestResult.absoluteLinkURL(), downloadableMediaURL, hitTestResult.image(), hitTestResult.selectedText());
+    RetainPtr<NSImage> nsImage;
+    if (Image* image = hitTestResult.image()) {
+        if (RefPtr<SharedBuffer> buffer = image->data())
+            nsImage = adoptNS([[NSImage alloc] initWithData:[NSData dataWithBytes:buffer->data() length:buffer->size()]]);
+    }
+
+    return ContextMenuItem::shareMenuItem(hitTestResult.absoluteLinkURL(), downloadableMediaURL, nsImage.get(), hitTestResult.selectedText());
 }
 
 bool WebContextMenuClient::clientFloatRectForNode(Node& node, FloatRect& rect) const

Modified: trunk/Source/WebKit2/ChangeLog (189101 => 189102)


--- trunk/Source/WebKit2/ChangeLog	2015-08-28 17:14:11 UTC (rev 189101)
+++ trunk/Source/WebKit2/ChangeLog	2015-08-28 17:35:07 UTC (rev 189102)
@@ -1,3 +1,20 @@
+2015-08-28  Timothy Horton  <timothy_hor...@apple.com>
+
+        [Mac] Right-clicking on GIFs spins the UI process for a while
+        https://bugs.webkit.org/show_bug.cgi?id=148566
+        <rdar://problem/22460854>
+
+        Reviewed by Brady Eidson.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::internalShowContextMenu):
+        (WebKit::WebPageProxy::platformInitializeShareMenuItem):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/mac/WebPageProxyMac.mm:
+        (WebKit::WebPageProxy::platformInitializeShareMenuItem):
+        Move all of the code to make a Share menuitem into platformInitializeShareMenuItem.
+        Make an NSImage directly from the image data if possible.
+
 2015-08-28  Michael Catanzaro  <mcatanz...@igalia.com>
 
         [CMake] LIBSECCOMP_INCLUDE_DIRS should be added to WebKit2_SYSTEM_INCLUDE_DIRECTORIES

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (189101 => 189102)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2015-08-28 17:14:11 UTC (rev 189101)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2015-08-28 17:35:07 UTC (rev 189102)
@@ -4259,27 +4259,9 @@
             continue;
         }
 
-        // Create the real Share menu item
-        URL absoluteLinkURL;
-        if (!contextMenuContextData.webHitTestResultData().absoluteLinkURL.isEmpty())
-            absoluteLinkURL = URL(ParsedURLString, contextMenuContextData.webHitTestResultData().absoluteLinkURL);
-
-        URL downloadableMediaURL;
-        if (!contextMenuContextData.webHitTestResultData().absoluteMediaURL.isEmpty() && contextMenuContextData.webHitTestResultData().isDownloadableMedia)
-            downloadableMediaURL = URL(ParsedURLString, contextMenuContextData.webHitTestResultData().absoluteMediaURL);
-
-        RefPtr<Image> image;
-        if (contextMenuContextData.webHitTestResultData().imageSharedMemory && contextMenuContextData.webHitTestResultData().imageSize) {
-            image = BitmapImage::create();
-            RefPtr<SharedBuffer> imageData = SharedBuffer::create((unsigned char*)contextMenuContextData.webHitTestResultData().imageSharedMemory->data(), contextMenuContextData.webHitTestResultData().imageSize);
-            image->setData(imageData.release(), true);
-        }
-
-        ContextMenuItem coreItem = ContextMenuItem::shareMenuItem(absoluteLinkURL, downloadableMediaURL, image.get(), contextMenuContextData.selectedText());
-        if (!coreItem.isNull()) {
-            platformInitializeShareMenuItem(coreItem);
+        ContextMenuItem coreItem = platformInitializeShareMenuItem(contextMenuContextData);
+        if (!coreItem.isNull())
             proposedAPIItems.append(WebContextMenuItem::create(coreItem));
-        }
     }
 
     Vector<RefPtr<WebContextMenuItem>> clientItems;
@@ -4295,9 +4277,10 @@
     m_contextMenuClient->contextMenuDismissed(*this);
 }
 
-#if !PLATFORM(MAC)
-void WebPageProxy::platformInitializeShareMenuItem(ContextMenuItem&)
+#if !ENABLE(SERVICE_CONTROLS)
+ContextMenuItem WebPageProxy::platformInitializeShareMenuItem(const ContextMenuContextData&)
 {
+    return ContextMenuItem();
 }
 #endif
 

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (189101 => 189102)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2015-08-28 17:14:11 UTC (rev 189101)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2015-08-28 17:35:07 UTC (rev 189102)
@@ -1265,8 +1265,7 @@
     };
     void showContextMenu(const WebCore::IntPoint& menuLocation, const ContextMenuContextData&, const Vector<WebContextMenuItemData>&, const UserData&);
     void internalShowContextMenu(const WebCore::IntPoint& menuLocation, const ContextMenuContextData&, const Vector<WebContextMenuItemData>&, ContextMenuClientEligibility, const UserData&);
-
-    void platformInitializeShareMenuItem(WebCore::ContextMenuItem&);
+    WebCore::ContextMenuItem platformInitializeShareMenuItem(const ContextMenuContextData&);
 #endif
 
 #if ENABLE(TELEPHONE_NUMBER_DETECTION)

Modified: trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm (189101 => 189102)


--- trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm	2015-08-28 17:14:11 UTC (rev 189101)
+++ trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm	2015-08-28 17:35:07 UTC (rev 189102)
@@ -748,9 +748,25 @@
 #endif
 }
 
-void WebPageProxy::platformInitializeShareMenuItem(ContextMenuItem& item)
+#if ENABLE(SERVICE_CONTROLS)
+ContextMenuItem WebPageProxy::platformInitializeShareMenuItem(const ContextMenuContextData& contextMenuContextData)
 {
-#if ENABLE(SERVICE_CONTROLS)
+    const WebHitTestResult::Data& hitTestData = contextMenuContextData.webHitTestResultData();
+
+    URL absoluteLinkURL;
+    if (!hitTestData.absoluteLinkURL.isEmpty())
+        absoluteLinkURL = URL(ParsedURLString, hitTestData.absoluteLinkURL);
+
+    URL downloadableMediaURL;
+    if (!hitTestData.absoluteMediaURL.isEmpty() && hitTestData.isDownloadableMedia)
+        downloadableMediaURL = URL(ParsedURLString, hitTestData.absoluteMediaURL);
+
+    RetainPtr<NSImage> image;
+    if (hitTestData.imageSharedMemory && hitTestData.imageSize)
+        image = adoptNS([[NSImage alloc] initWithData:[NSData dataWithBytes:(unsigned char*)hitTestData.imageSharedMemory->data() length:hitTestData.imageSize]]);
+
+    ContextMenuItem item = ContextMenuItem::shareMenuItem(absoluteLinkURL, downloadableMediaURL, image.get(), contextMenuContextData.selectedText());
+
     NSMenuItem *nsItem = item.platformDescription();
 
     NSSharingServicePicker *sharingServicePicker = [nsItem representedObject];
@@ -762,9 +778,11 @@
 
     // Setting the picker lets the delegate retain it to keep it alive, but this picker is kept alive by the menu item.
     [[WKSharingServicePickerDelegate sharedSharingServicePickerDelegate] setPicker:nil];
+
+    return item;
+}
 #endif
-}
-    
+
 } // namespace WebKit
 
 #endif // PLATFORM(MAC)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to