Clean up context menu code
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 2 Jan 2018 17:17:19 +0000 (17:17 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 2 Jan 2018 17:17:19 +0000 (17:17 +0000)
https://bugs.webkit.org/show_bug.cgi?id=181074

Reviewed by Brent Fulgham.

Use Ref instead of RefPtr where possible.
Use move semantics instead of copying from const references when possible.
Remove dead iOS code.  Reduce allocations.  Add stub for WPE.

* UIProcess/API/APIContextMenuClient.h:
(API::ContextMenuClient::getContextMenuFromProposedMenu):
(API::ContextMenuClient::getContextMenuFromProposedMenuAsync):
(API::ContextMenuClient::showContextMenu):
* UIProcess/API/C/WKPage.cpp:
(WKPageSetPageContextMenuClient):
* UIProcess/API/gtk/PageClientImpl.cpp:
(WebKit::PageClientImpl::createContextMenuProxy):
* UIProcess/API/gtk/PageClientImpl.h:
* UIProcess/PageClient.h:
* UIProcess/WebContextMenuListenerProxy.cpp:
(WebKit::WebContextMenuListenerProxy::useContextMenuItems):
* UIProcess/WebContextMenuProxy.cpp:
(WebKit::WebContextMenuProxy::WebContextMenuProxy):
* UIProcess/WebContextMenuProxy.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::showContextMenu):
(WebKit::WebPageProxy::internalShowContextMenu): Deleted.
* UIProcess/WebPageProxy.h:
* UIProcess/gtk/WebContextMenuProxyGtk.cpp:
(WebKit::WebContextMenuProxyGtk::showContextMenuWithItems):
(WebKit::WebContextMenuProxyGtk::WebContextMenuProxyGtk):
* UIProcess/gtk/WebContextMenuProxyGtk.h:
(WebKit::WebContextMenuProxyGtk::create):
* UIProcess/ios/PageClientImplIOS.h:
* UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::createContextMenuProxy): Deleted.
* UIProcess/mac/PageClientImplMac.h:
* UIProcess/mac/PageClientImplMac.mm:
(WebKit::PageClientImpl::createContextMenuProxy):
* UIProcess/mac/WebContextMenuProxyMac.h:
(WebKit::WebContextMenuProxyMac::create):
* UIProcess/mac/WebContextMenuProxyMac.mm:
(WebKit::WebContextMenuProxyMac::WebContextMenuProxyMac):
(WebKit::WebContextMenuProxyMac::showContextMenuWithItems):
(WebKit::WebContextMenuProxyMac::showContextMenu):

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

24 files changed:
Source/WebKit/ChangeLog
Source/WebKit/PlatformWPE.cmake
Source/WebKit/UIProcess/API/APIContextMenuClient.h
Source/WebKit/UIProcess/API/C/WKPage.cpp
Source/WebKit/UIProcess/API/glib/WebKitContextMenuClient.cpp
Source/WebKit/UIProcess/API/gtk/PageClientImpl.cpp
Source/WebKit/UIProcess/API/gtk/PageClientImpl.h
Source/WebKit/UIProcess/API/wpe/PageClientImpl.cpp
Source/WebKit/UIProcess/API/wpe/PageClientImpl.h
Source/WebKit/UIProcess/PageClient.h
Source/WebKit/UIProcess/WebContextMenuListenerProxy.cpp
Source/WebKit/UIProcess/WebContextMenuProxy.cpp
Source/WebKit/UIProcess/WebContextMenuProxy.h
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/UIProcess/gtk/WebContextMenuProxyGtk.cpp
Source/WebKit/UIProcess/gtk/WebContextMenuProxyGtk.h
Source/WebKit/UIProcess/ios/PageClientImplIOS.h
Source/WebKit/UIProcess/ios/PageClientImplIOS.mm
Source/WebKit/UIProcess/mac/PageClientImplMac.h
Source/WebKit/UIProcess/mac/PageClientImplMac.mm
Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.h
Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm
Source/WebKit/UIProcess/wpe/WebContextMenuProxyWPE.h [new file with mode: 0644]

index 19f9536..d178cf6 100644 (file)
@@ -1 +1,49 @@
+2018-01-02  Alex Christensen  <achristensen@webkit.org>
+
+        Clean up context menu code
+        https://bugs.webkit.org/show_bug.cgi?id=181074
+
+        Reviewed by Brent Fulgham.
+
+        Use Ref instead of RefPtr where possible.
+        Use move semantics instead of copying from const references when possible.
+        Remove dead iOS code.  Reduce allocations.  Add stub for WPE.
+
+        * UIProcess/API/APIContextMenuClient.h:
+        (API::ContextMenuClient::getContextMenuFromProposedMenu):
+        (API::ContextMenuClient::getContextMenuFromProposedMenuAsync):
+        (API::ContextMenuClient::showContextMenu):
+        * UIProcess/API/C/WKPage.cpp:
+        (WKPageSetPageContextMenuClient):
+        * UIProcess/API/gtk/PageClientImpl.cpp:
+        (WebKit::PageClientImpl::createContextMenuProxy):
+        * UIProcess/API/gtk/PageClientImpl.h:
+        * UIProcess/PageClient.h:
+        * UIProcess/WebContextMenuListenerProxy.cpp:
+        (WebKit::WebContextMenuListenerProxy::useContextMenuItems):
+        * UIProcess/WebContextMenuProxy.cpp:
+        (WebKit::WebContextMenuProxy::WebContextMenuProxy):
+        * UIProcess/WebContextMenuProxy.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::showContextMenu):
+        (WebKit::WebPageProxy::internalShowContextMenu): Deleted.
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/gtk/WebContextMenuProxyGtk.cpp:
+        (WebKit::WebContextMenuProxyGtk::showContextMenuWithItems):
+        (WebKit::WebContextMenuProxyGtk::WebContextMenuProxyGtk):
+        * UIProcess/gtk/WebContextMenuProxyGtk.h:
+        (WebKit::WebContextMenuProxyGtk::create):
+        * UIProcess/ios/PageClientImplIOS.h:
+        * UIProcess/ios/PageClientImplIOS.mm:
+        (WebKit::PageClientImpl::createContextMenuProxy): Deleted.
+        * UIProcess/mac/PageClientImplMac.h:
+        * UIProcess/mac/PageClientImplMac.mm:
+        (WebKit::PageClientImpl::createContextMenuProxy):
+        * UIProcess/mac/WebContextMenuProxyMac.h:
+        (WebKit::WebContextMenuProxyMac::create):
+        * UIProcess/mac/WebContextMenuProxyMac.mm:
+        (WebKit::WebContextMenuProxyMac::WebContextMenuProxyMac):
+        (WebKit::WebContextMenuProxyMac::showContextMenuWithItems):
+        (WebKit::WebContextMenuProxyMac::showContextMenu):
+
 == Rolled over to ChangeLog-2018-01-01 ==
index 4ff69e5..fdf729d 100644 (file)
@@ -425,6 +425,7 @@ list(APPEND WebKit_INCLUDE_DIRECTORIES
     "${WEBKIT_DIR}/UIProcess/gstreamer"
     "${WEBKIT_DIR}/UIProcess/linux"
     "${WEBKIT_DIR}/UIProcess/soup"
+    "${WEBKIT_DIR}/UIProcess/wpe"
     "${WEBKIT_DIR}/WebProcess/InjectedBundle/API/glib"
     "${WEBKIT_DIR}/WebProcess/InjectedBundle/API/wpe"
     "${WEBKIT_DIR}/WebProcess/soup"
index 73646bb..ba1e36b 100644 (file)
@@ -23,8 +23,7 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef APIContextMenuClient_h
-#define APIContextMenuClient_h
+#pragma once
 
 #if ENABLE(CONTEXT_MENUS)
 
@@ -52,10 +51,10 @@ class ContextMenuClient {
 public:
     virtual ~ContextMenuClient() { }
 
-    virtual bool getContextMenuFromProposedMenu(WebKit::WebPageProxy&, const Vector<RefPtr<WebKit::WebContextMenuItem>>& /* proposedMenu */, Vector<RefPtr<WebKit::WebContextMenuItem>>& /* customMenu */, const WebKit::WebHitTestResultData&, API::Object* /* userData */) { return false; }
-    virtual bool getContextMenuFromProposedMenuAsync(WebKit::WebPageProxy&, const Vector<RefPtr<WebKit::WebContextMenuItem>>& /* proposedMenu */, WebKit::WebContextMenuListenerProxy*, const WebKit::WebHitTestResultData&, API::Object* /* userData */) { return false; }
+    virtual bool getContextMenuFromProposedMenu(WebKit::WebPageProxy&, const Vector<Ref<WebKit::WebContextMenuItem>>& /* proposedMenu */, Vector<Ref<WebKit::WebContextMenuItem>>& /* customMenu */, const WebKit::WebHitTestResultData&, API::Object* /* userData */) { return false; }
+    virtual bool getContextMenuFromProposedMenuAsync(WebKit::WebPageProxy&, const Vector<Ref<WebKit::WebContextMenuItem>>& /* proposedMenu */, WebKit::WebContextMenuListenerProxy*, const WebKit::WebHitTestResultData&, API::Object* /* userData */) { return false; }
     virtual void customContextMenuItemSelected(WebKit::WebPageProxy&, const WebKit::WebContextMenuItemData&) { }
-    virtual bool showContextMenu(WebKit::WebPageProxy&, const WebCore::IntPoint&, const Vector<RefPtr<WebKit::WebContextMenuItem>>&) { return false; }
+    virtual bool showContextMenu(WebKit::WebPageProxy&, const WebCore::IntPoint&, const Vector<Ref<WebKit::WebContextMenuItem>>&) { return false; }
     virtual bool hideContextMenu(WebKit::WebPageProxy&) { return false; }
 
 #if PLATFORM(MAC)
@@ -66,4 +65,3 @@ public:
 } // namespace API
 
 #endif // ENABLE(CONTEXT_MENUS)
-#endif // APIContextMenuClient_h
index 8dcf57a..7b479bb 100644 (file)
@@ -818,7 +818,7 @@ void WKPageSetPageContextMenuClient(WKPageRef pageRef, const WKPageContextMenuCl
         }
 
     private:
-        bool getContextMenuFromProposedMenu(WebPageProxy& page, const Vector<RefPtr<WebKit::WebContextMenuItem>>& proposedMenuVector, Vector<RefPtr<WebKit::WebContextMenuItem>>& customMenu, const WebHitTestResultData& hitTestResultData, API::Object* userData) override
+        bool getContextMenuFromProposedMenu(WebPageProxy& page, const Vector<Ref<WebKit::WebContextMenuItem>>& proposedMenuVector, Vector<Ref<WebKit::WebContextMenuItem>>& customMenu, const WebHitTestResultData& hitTestResultData, API::Object* userData) override
         {
             if (!m_client.getContextMenuFromProposedMenu && !m_client.getContextMenuFromProposedMenu_deprecatedForUseWithV0)
                 return false;
@@ -830,12 +830,12 @@ void WKPageSetPageContextMenuClient(WKPageRef pageRef, const WKPageContextMenuCl
             proposedMenuItems.reserveInitialCapacity(proposedMenuVector.size());
 
             for (const auto& menuItem : proposedMenuVector)
-                proposedMenuItems.uncheckedAppend(menuItem);
+                proposedMenuItems.uncheckedAppend(menuItem.ptr());
 
             WKArrayRef newMenu = nullptr;
             if (m_client.base.version >= 2) {
-                RefPtr<API::HitTestResult> webHitTestResult = API::HitTestResult::create(hitTestResultData);
-                m_client.getContextMenuFromProposedMenu(toAPI(&page), toAPI(API::Array::create(WTFMove(proposedMenuItems)).ptr()), &newMenu, toAPI(webHitTestResult.get()), toAPI(userData), m_client.base.clientInfo);
+                auto webHitTestResult = API::HitTestResult::create(hitTestResultData);
+                m_client.getContextMenuFromProposedMenu(toAPI(&page), toAPI(API::Array::create(WTFMove(proposedMenuItems)).ptr()), &newMenu, toAPI(webHitTestResult.ptr()), toAPI(userData), m_client.base.clientInfo);
             } else
                 m_client.getContextMenuFromProposedMenu_deprecatedForUseWithV0(toAPI(&page), toAPI(API::Array::create(WTFMove(proposedMenuItems)).ptr()), &newMenu, toAPI(userData), m_client.base.clientInfo);
 
@@ -851,13 +851,13 @@ void WKPageSetPageContextMenuClient(WKPageRef pageRef, const WKPageContextMenuCl
                     continue;
                 }
 
-                customMenu.append(item);
+                customMenu.append(*item);
             }
 
             return true;
         }
 
-        bool getContextMenuFromProposedMenuAsync(WebPageProxy& page, const Vector<RefPtr<WebKit::WebContextMenuItem>>& proposedMenuVector, WebKit::WebContextMenuListenerProxy* contextMenuListener, const WebHitTestResultData& hitTestResultData, API::Object* userData) override
+        bool getContextMenuFromProposedMenuAsync(WebPageProxy& page, const Vector<Ref<WebKit::WebContextMenuItem>>& proposedMenuVector, WebKit::WebContextMenuListenerProxy* contextMenuListener, const WebHitTestResultData& hitTestResultData, API::Object* userData) override
         {
             if (m_client.base.version < 4 || !m_client.getContextMenuFromProposedMenuAsync)
                 return false;
@@ -866,7 +866,7 @@ void WKPageSetPageContextMenuClient(WKPageRef pageRef, const WKPageContextMenuCl
             proposedMenuItems.reserveInitialCapacity(proposedMenuVector.size());
 
             for (const auto& menuItem : proposedMenuVector)
-                proposedMenuItems.uncheckedAppend(menuItem);
+                proposedMenuItems.uncheckedAppend(menuItem.ptr());
 
             RefPtr<API::HitTestResult> webHitTestResult = API::HitTestResult::create(hitTestResultData);
             m_client.getContextMenuFromProposedMenuAsync(toAPI(&page), toAPI(API::Array::create(WTFMove(proposedMenuItems)).ptr()), toAPI(contextMenuListener), toAPI(webHitTestResult.get()), toAPI(userData), m_client.base.clientInfo);
@@ -882,7 +882,7 @@ void WKPageSetPageContextMenuClient(WKPageRef pageRef, const WKPageContextMenuCl
             m_client.customContextMenuItemSelected(toAPI(&page), toAPI(WebContextMenuItem::create(itemData).ptr()), m_client.base.clientInfo);
         }
 
-        bool showContextMenu(WebPageProxy& page, const WebCore::IntPoint& menuLocation, const Vector<RefPtr<WebContextMenuItem>>& menuItemsVector) override
+        bool showContextMenu(WebPageProxy& page, const WebCore::IntPoint& menuLocation, const Vector<Ref<WebContextMenuItem>>& menuItemsVector) override
         {
             if (!m_client.showContextMenu)
                 return false;
@@ -891,7 +891,7 @@ void WKPageSetPageContextMenuClient(WKPageRef pageRef, const WKPageContextMenuCl
             menuItems.reserveInitialCapacity(menuItemsVector.size());
 
             for (const auto& menuItem : menuItemsVector)
-                menuItems.uncheckedAppend(menuItem);
+                menuItems.uncheckedAppend(menuItem.ptr());
 
             m_client.showContextMenu(toAPI(&page), toAPI(menuLocation), toAPI(API::Array::create(WTFMove(menuItems)).ptr()), m_client.base.clientInfo);
 
index 81092a3..bfea5f9 100644 (file)
@@ -34,7 +34,7 @@ public:
     }
 
 private:
-    bool getContextMenuFromProposedMenu(WebPageProxy&, const Vector<RefPtr<WebContextMenuItem>>& proposedMenu, Vector<RefPtr<WebContextMenuItem>>&, const WebHitTestResultData& hitTestResultData, API::Object* userData) override
+    bool getContextMenuFromProposedMenu(WebPageProxy&, const Vector<Ref<WebContextMenuItem>>& proposedMenu, Vector<Ref<WebContextMenuItem>>&, const WebHitTestResultData& hitTestResultData, API::Object* userData) override
     {
         GRefPtr<GVariant> variant;
         if (userData) {
index 1886d81..ed8a910 100644 (file)
@@ -211,9 +211,9 @@ RefPtr<WebPopupMenuProxy> PageClientImpl::createPopupMenuProxy(WebPageProxy& pag
     return WebPopupMenuProxyGtk::create(m_viewWidget, page);
 }
 
-RefPtr<WebContextMenuProxy> PageClientImpl::createContextMenuProxy(WebPageProxy& page, const ContextMenuContextData& context, const UserData& userData)
+Ref<WebContextMenuProxy> PageClientImpl::createContextMenuProxy(WebPageProxy& page, ContextMenuContextData&& context, const UserData& userData)
 {
-    return WebContextMenuProxyGtk::create(m_viewWidget, page, context, userData);
+    return WebContextMenuProxyGtk::create(m_viewWidget, page, WTFMove(context), userData);
 }
 
 RefPtr<WebColorPicker> PageClientImpl::createColorPicker(WebPageProxy* page, const WebCore::Color& color, const WebCore::IntRect& rect)
index ea2c10a..3e8984d 100644 (file)
@@ -80,7 +80,7 @@ private:
     WebCore::IntRect rootViewToScreen(const WebCore::IntRect&) override;
     void doneWithKeyEvent(const NativeWebKeyboardEvent&, bool wasEventHandled) override;
     RefPtr<WebPopupMenuProxy> createPopupMenuProxy(WebPageProxy&) override;
-    RefPtr<WebContextMenuProxy> createContextMenuProxy(WebPageProxy&, const ContextMenuContextData&, const UserData&) override;
+    Ref<WebContextMenuProxy> createContextMenuProxy(WebPageProxy&, ContextMenuContextData&&, const UserData&) override;
 #if ENABLE(INPUT_TYPE_COLOR)
     RefPtr<WebColorPicker> createColorPicker(WebPageProxy*, const WebCore::Color& intialColor, const WebCore::IntRect&) override;
 #endif
index e9b6b47..d50ee82 100644 (file)
@@ -32,6 +32,7 @@
 #include "ScrollGestureController.h"
 #include "WPEView.h"
 #include "WebContextMenuProxy.h"
+#include "WebContextMenuProxyWPE.h"
 #include <WebCore/ActivityState.h>
 #include <WebCore/NotImplemented.h>
 
@@ -230,9 +231,9 @@ RefPtr<WebPopupMenuProxy> PageClientImpl::createPopupMenuProxy(WebPageProxy&)
 }
 
 #if ENABLE(CONTEXT_MENUS)
-RefPtr<WebContextMenuProxy> PageClientImpl::createContextMenuProxy(WebPageProxy&, const ContextMenuContextData&, const UserData&)
+Ref<WebContextMenuProxy> PageClientImpl::createContextMenuProxy(WebPageProxy&, ContextMenuContextData&& context, const UserData& userData)
 {
-    return nullptr;
+    return WebContextMenuProxyWPE::create(WTFMove(context), userData);
 }
 #endif
 
index 4e0a664..780c884 100644 (file)
@@ -83,7 +83,7 @@ private:
 
     RefPtr<WebPopupMenuProxy> createPopupMenuProxy(WebPageProxy&) override;
 #if ENABLE(CONTEXT_MENUS)
-    RefPtr<WebContextMenuProxy> createContextMenuProxy(WebPageProxy&, const ContextMenuContextData&, const UserData&) override;
+    Ref<WebContextMenuProxy> createContextMenuProxy(WebPageProxy&, ContextMenuContextData&&, const UserData&) override;
 #endif
 
     void enterAcceleratedCompositingMode(const LayerTreeContext&) override;
index 0c509da..c2ec872 100644 (file)
@@ -214,7 +214,7 @@ public:
 
     virtual RefPtr<WebPopupMenuProxy> createPopupMenuProxy(WebPageProxy&) = 0;
 #if ENABLE(CONTEXT_MENUS)
-    virtual RefPtr<WebContextMenuProxy> createContextMenuProxy(WebPageProxy&, const ContextMenuContextData&, const UserData&) = 0;
+    virtual Ref<WebContextMenuProxy> createContextMenuProxy(WebPageProxy&, ContextMenuContextData&&, const UserData&) = 0;
 #endif
 
 #if ENABLE(INPUT_TYPE_COLOR)
index 5505d52..03eacb7 100644 (file)
@@ -53,18 +53,18 @@ void WebContextMenuListenerProxy::useContextMenuItems(WKArrayRef items)
         return;
 
     RefPtr<API::Array> array = toImpl(items);
-    Vector<WebContextMenuItemData> dataItems;
-
     size_t newSize = array ? array->size() : 0;
+    Vector<WebContextMenuItemData> dataItems;
+    dataItems.reserveInitialCapacity(newSize);
     for (size_t i = 0; i < newSize; ++i) {
         WebContextMenuItem* item = array->at<WebContextMenuItem>(i);
         if (!item)
             continue;
 
-        dataItems.append(item->data());
+        dataItems.uncheckedAppend(item->data());
     }
 
-    m_contextMenuMac->showContextMenuWithItems(dataItems);
+    m_contextMenuMac->showContextMenuWithItems(WTFMove(dataItems));
 }
 
 void WebContextMenuListenerProxy::invalidate()
index 1764c46..7fb2c52 100644 (file)
@@ -30,8 +30,8 @@
 
 namespace WebKit {
 
-WebContextMenuProxy::WebContextMenuProxy(const ContextMenuContextData& context, const UserData& userData)
-    : m_context(context)
+WebContextMenuProxy::WebContextMenuProxy(ContextMenuContextData&& context, const UserData& userData)
+    : m_context(WTFMove(context))
     , m_userData(userData)
 {
 }
index 2415db1..0c76297 100644 (file)
@@ -41,10 +41,10 @@ public:
 
     virtual void show() = 0;
 
-    virtual void showContextMenuWithItems(const Vector<WebContextMenuItemData>& items) = 0;
+    virtual void showContextMenuWithItems(Vector<WebContextMenuItemData>&&) = 0;
 
 protected:
-    WebContextMenuProxy(const ContextMenuContextData&, const UserData&);
+    WebContextMenuProxy(ContextMenuContextData&&, const UserData&);
 
     const ContextMenuContextData m_context;
     const UserData m_userData;
index db3f31a..49d256c 100644 (file)
@@ -4722,24 +4722,14 @@ void WebPageProxy::hidePopupMenu()
 }
 
 #if ENABLE(CONTEXT_MENUS)
-void WebPageProxy::showContextMenu(const ContextMenuContextData& contextMenuContextData, const UserData& userData)
+void WebPageProxy::showContextMenu(ContextMenuContextData&& contextMenuContextData, const UserData& userData)
 {
     // Showing a context menu runs a nested runloop, which can handle messages that cause |this| to get closed.
     Ref<WebPageProxy> protect(*this);
 
-    internalShowContextMenu(contextMenuContextData, userData);
-    
-    // No matter the result of internalShowContextMenu, always notify the WebProcess that the menu is hidden so it starts handling mouse events again.
-    m_process->send(Messages::WebPage::ContextMenuHidden(), m_pageID);
-}
-
-void WebPageProxy::internalShowContextMenu(const ContextMenuContextData& contextMenuContextData, const UserData& userData)
-{
     m_activeContextMenuContextData = contextMenuContextData;
 
-    m_activeContextMenu = m_pageClient.createContextMenuProxy(*this, contextMenuContextData, userData);
-    if (!m_activeContextMenu)
-        return;
+    m_activeContextMenu = m_pageClient.createContextMenuProxy(*this, WTFMove(contextMenuContextData), userData);
 
     // Since showContextMenu() can spin a nested run loop we need to turn off the responsiveness timer.
     m_process->responsivenessTimer().stop();
@@ -4747,6 +4737,9 @@ void WebPageProxy::internalShowContextMenu(const ContextMenuContextData& context
     // m_activeContextMenu might get cleared if WebPageProxy code is re-entered from the menu runloop or delegates.
     Ref<WebContextMenuProxy> protector(*m_activeContextMenu);
     m_activeContextMenu->show();
+
+    // No matter the result of internalShowContextMenu, always notify the WebProcess that the menu is hidden so it starts handling mouse events again.
+    m_process->send(Messages::WebPage::ContextMenuHidden(), m_pageID);
 }
 
 void WebPageProxy::contextMenuItemSelected(const WebContextMenuItemData& item)
index 9e6400b..d99ce79 100644 (file)
@@ -1461,8 +1461,7 @@ private:
     void hidePopupMenu();
 
 #if ENABLE(CONTEXT_MENUS)
-    void showContextMenu(const ContextMenuContextData&, const UserData&);
-    void internalShowContextMenu(const ContextMenuContextData&, const UserData&);
+    void showContextMenu(ContextMenuContextData&&, const UserData&);
 #endif
 
 #if ENABLE(TELEPHONE_NUMBER_DETECTION)
index 6afffe6..c9a1051 100644 (file)
@@ -124,7 +124,7 @@ void WebContextMenuProxyGtk::populate(const Vector<WebContextMenuItemGlib>& item
     gtk_menu_shell_bind_model(GTK_MENU_SHELL(m_menu), G_MENU_MODEL(menu.get()), nullptr, TRUE);
 }
 
-void WebContextMenuProxyGtk::populate(const Vector<RefPtr<WebContextMenuItem>>& items)
+void WebContextMenuProxyGtk::populate(const Vector<Ref<WebContextMenuItem>>& items)
 {
     GRefPtr<GMenu> menu = adoptGRef(g_menu_new());
     GMenu* sectionMenu = menu.get();
@@ -143,19 +143,19 @@ void WebContextMenuProxyGtk::populate(const Vector<RefPtr<WebContextMenuItem>>&
 
 void WebContextMenuProxyGtk::show()
 {
-    Vector<RefPtr<WebContextMenuItem>> proposedAPIItems;
+    Vector<Ref<WebContextMenuItem>> proposedAPIItems;
     for (auto& item : m_context.menuItems()) {
         if (item.action() != ContextMenuItemTagShareMenu)
             proposedAPIItems.append(WebContextMenuItem::create(item));
     }
 
-    Vector<RefPtr<WebContextMenuItem>> clientItems;
+    Vector<Ref<WebContextMenuItem>> clientItems;
     bool useProposedItems = true;
 
     if (m_page->contextMenuClient().getContextMenuFromProposedMenu(*m_page, proposedAPIItems, clientItems, m_context.webHitTestResultData(), m_page->process().transformHandlesToObjects(m_userData.object()).get()))
         useProposedItems = false;
 
-    const Vector<RefPtr<WebContextMenuItem>>& items = useProposedItems ? proposedAPIItems : clientItems;
+    const Vector<Ref<WebContextMenuItem>>& items = useProposedItems ? proposedAPIItems : clientItems;
 
     if (!items.isEmpty())
         populate(items);
@@ -175,12 +175,12 @@ void WebContextMenuProxyGtk::show()
                    event ? event->button.button : 3, event ? event->button.time : GDK_CURRENT_TIME);
 }
 
-void WebContextMenuProxyGtk::showContextMenuWithItems(const Vector<WebContextMenuItemData>& items)
+void WebContextMenuProxyGtk::showContextMenuWithItems(Vector<WebContextMenuItemData>&&)
 {
 }
 
-WebContextMenuProxyGtk::WebContextMenuProxyGtk(GtkWidget* webView, WebPageProxy& page, const ContextMenuContextData& context, const UserData& userData)
-    : WebContextMenuProxy(context, userData)
+WebContextMenuProxyGtk::WebContextMenuProxyGtk(GtkWidget* webView, WebPageProxy& page, ContextMenuContextData&& context, const UserData& userData)
+    : WebContextMenuProxy(WTFMove(context), userData)
     , m_webView(webView)
     , m_page(&page)
     , m_menu(GTK_MENU(gtk_menu_new()))
index 3a4f34d..aa6c740 100644 (file)
@@ -23,8 +23,7 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef WebContextMenuProxyGtk_h
-#define WebContextMenuProxyGtk_h
+#pragma once
 
 #if ENABLE(CONTEXT_MENUS)
 
@@ -44,9 +43,9 @@ class WebPageProxy;
 
 class WebContextMenuProxyGtk : public WebContextMenuProxy {
 public:
-    static auto create(GtkWidget* widget, WebPageProxy& page, const ContextMenuContextData& context, const UserData& userData)
+    static auto create(GtkWidget* widget, WebPageProxy& page, ContextMenuContextData&& context, const UserData& userData)
     {
-        return adoptRef(*new WebContextMenuProxyGtk(widget, page, context, userData));
+        return adoptRef(*new WebContextMenuProxyGtk(widget, page, WTFMove(context), userData));
     }
     ~WebContextMenuProxyGtk();
 
@@ -54,12 +53,12 @@ public:
     GtkMenu* gtkMenu() const { return m_menu; }
 
 private:
-    WebContextMenuProxyGtk(GtkWidget*, WebPageProxy&, const ContextMenuContextData&, const UserData&);
+    WebContextMenuProxyGtk(GtkWidget*, WebPageProxy&, ContextMenuContextData&&, const UserData&);
     void show() override;
-    void showContextMenuWithItems(const Vector<WebContextMenuItemData>&) override;
+    void showContextMenuWithItems(Vector<WebContextMenuItemData>&&) override;
     void append(GMenu*, const WebContextMenuItemGlib&);
     GRefPtr<GMenu> buildMenu(const Vector<WebContextMenuItemGlib>&);
-    void populate(const Vector<RefPtr<WebContextMenuItem>>&);
+    void populate(const Vector<Ref<WebContextMenuItem>>&);
     static void menuPositionFunction(GtkMenu*, gint*, gint*, gboolean*, WebContextMenuProxyGtk*);
 
     GtkWidget* m_webView;
@@ -73,4 +72,3 @@ private:
 } // namespace WebKit
 
 #endif // ENABLE(CONTEXT_MENUS)
-#endif // WebContextMenuProxyGtk_h
index 5de2786..c1a137a 100644 (file)
@@ -94,9 +94,6 @@ private:
     void doneWithTouchEvent(const NativeWebTouchEvent&, bool wasEventHandled) override;
 #endif
     RefPtr<WebPopupMenuProxy> createPopupMenuProxy(WebPageProxy&) override;
-#if ENABLE(CONTEXT_MENUS)
-    RefPtr<WebContextMenuProxy> createContextMenuProxy(WebPageProxy&, const ContextMenuContextData&, const UserData&) override;
-#endif
     Ref<WebCore::ValidationBubble> createValidationBubble(const String& message, const WebCore::ValidationBubble::Settings&) final;
 
     void setTextIndicator(Ref<WebCore::TextIndicator>, WebCore::TextIndicatorWindowLifetime) override;
index 29ee783..15b24d3 100644 (file)
@@ -448,13 +448,6 @@ RefPtr<WebPopupMenuProxy> PageClientImpl::createPopupMenuProxy(WebPageProxy&)
     return nullptr;
 }
 
-#if ENABLE(CONTEXT_MENUS)
-RefPtr<WebContextMenuProxy> PageClientImpl::createContextMenuProxy(WebPageProxy&, const UserData&)
-{
-    return nullptr;
-}
-#endif
-
 void PageClientImpl::setTextIndicator(Ref<TextIndicator> textIndicator, TextIndicatorWindowLifetime)
 {
 }
index 5568357..ae83640 100644 (file)
@@ -123,7 +123,7 @@ private:
 
     RefPtr<WebPopupMenuProxy> createPopupMenuProxy(WebPageProxy&) override;
 #if ENABLE(CONTEXT_MENUS)
-    RefPtr<WebContextMenuProxy> createContextMenuProxy(WebPageProxy&, const ContextMenuContextData&, const UserData&) override;
+    Ref<WebContextMenuProxy> createContextMenuProxy(WebPageProxy&, ContextMenuContextData&&, const UserData&) override;
 #endif
 
 #if ENABLE(INPUT_TYPE_COLOR)
index 7f7773d..addff70 100644 (file)
@@ -441,9 +441,9 @@ RefPtr<WebPopupMenuProxy> PageClientImpl::createPopupMenuProxy(WebPageProxy& pag
 }
 
 #if ENABLE(CONTEXT_MENUS)
-RefPtr<WebContextMenuProxy> PageClientImpl::createContextMenuProxy(WebPageProxy& page, const ContextMenuContextData& context, const UserData& userData)
+Ref<WebContextMenuProxy> PageClientImpl::createContextMenuProxy(WebPageProxy& page, ContextMenuContextData&& context, const UserData& userData)
 {
-    return WebContextMenuProxyMac::create(m_view, page, context, userData);
+    return WebContextMenuProxyMac::create(m_view, page, WTFMove(context), userData);
 }
 #endif
 
index 77b4f56..62a277b 100644 (file)
@@ -47,14 +47,14 @@ class WebPageProxy;
 
 class WebContextMenuProxyMac : public WebContextMenuProxy {
 public:
-    static auto create(NSView* view, WebPageProxy& page, const ContextMenuContextData& context, const UserData& userData)
+    static auto create(NSView* view, WebPageProxy& page, ContextMenuContextData&& context, const UserData& userData)
     {
-        return adoptRef(*new WebContextMenuProxyMac(view, page, context, userData));
+        return adoptRef(*new WebContextMenuProxyMac(view, page, WTFMove(context), userData));
     }
     ~WebContextMenuProxyMac();
 
     void contextMenuItemSelected(const WebContextMenuItemData&);
-    void showContextMenuWithItems(const Vector<WebContextMenuItemData>&) override;
+    void showContextMenuWithItems(Vector<WebContextMenuItemData>&&) override;
 
 #if ENABLE(SERVICE_CONTROLS)
     void clearServicesMenu();
@@ -64,7 +64,7 @@ public:
     NSWindow *window() const;
 
 private:
-    WebContextMenuProxyMac(NSView*, WebPageProxy&, const ContextMenuContextData&, const UserData&);
+    WebContextMenuProxyMac(NSView*, WebPageProxy&, ContextMenuContextData&&, const UserData&);
     void show() override;
 
     RefPtr<WebContextMenuListenerProxy> m_contextMenuListener;
index 2393ccc..94dfbe9 100644 (file)
@@ -152,8 +152,8 @@ using namespace WebCore;
 
 namespace WebKit {
 
-WebContextMenuProxyMac::WebContextMenuProxyMac(NSView* webView, WebPageProxy& page, const ContextMenuContextData& context, const UserData& userData)
-    : WebContextMenuProxy(context, userData)
+WebContextMenuProxyMac::WebContextMenuProxyMac(NSView* webView, WebPageProxy& page, ContextMenuContextData&& context, const UserData& userData)
+    : WebContextMenuProxy(WTFMove(context), userData)
     , m_webView(webView)
     , m_page(page)
 {
@@ -451,7 +451,7 @@ RetainPtr<NSMenuItem> WebContextMenuProxyMac::createContextMenuItem(const WebCon
     }
 }
 
-void WebContextMenuProxyMac::showContextMenuWithItems(const Vector<WebContextMenuItemData>& items)
+void WebContextMenuProxyMac::showContextMenuWithItems(Vector<WebContextMenuItemData>&& items)
 {
     auto menu = createContextMenuFromItems(items);
     [[WKMenuTarget sharedMenuTarget] setMenuProxy:this];
@@ -469,11 +469,11 @@ void WebContextMenuProxyMac::showContextMenuWithItems(const Vector<WebContextMen
 
 void WebContextMenuProxyMac::showContextMenu()
 {
-    Vector<RefPtr<WebContextMenuItem>> proposedAPIItems;
+    Vector<Ref<WebContextMenuItem>> proposedAPIItems;
     for (auto& item : m_context.menuItems())
         proposedAPIItems.append(WebContextMenuItem::create(item));
 
-    Vector<RefPtr<WebContextMenuItem>> clientItems;
+    Vector<Ref<WebContextMenuItem>> clientItems;
     bool useProposedItems = true;
 
     if (m_contextMenuListener) {
@@ -500,7 +500,7 @@ void WebContextMenuProxyMac::showContextMenu()
     if (items.isEmpty())
         return;
 
-    showContextMenuWithItems(items);
+    showContextMenuWithItems(WTFMove(items));
 }
 
 NSWindow *WebContextMenuProxyMac::window() const
diff --git a/Source/WebKit/UIProcess/wpe/WebContextMenuProxyWPE.h b/Source/WebKit/UIProcess/wpe/WebContextMenuProxyWPE.h
new file mode 100644 (file)
index 0000000..27e4fba
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "WebContextMenuProxy.h"
+
+namespace WebKit {
+
+class WebContextMenuProxyWPE : public WebContextMenuProxy {
+public:
+    static auto create(ContextMenuContextData&& context, const UserData& userData)
+    {
+        return adoptRef(*new WebContextMenuProxyWPE(WTFMove(context), userData));
+    }
+
+    void showContextMenuWithItems(Vector<WebContextMenuItemData>&&) final { }
+    void show() final { };
+
+private:
+    WebContextMenuProxyWPE(ContextMenuContextData&& context, const UserData& userData)
+        : WebContextMenuProxy(WTFMove(context), userData)
+    { }
+};
+
+} // namespace WebKit