WebContextMenuProxy doesn't have to be ref-counted
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Oct 2015 21:26:41 +0000 (21:26 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Oct 2015 21:26:41 +0000 (21:26 +0000)
https://bugs.webkit.org/show_bug.cgi?id=150415

Reviewed by Tim Horton.

Change WebContextMenuProxy to not inherit from RefCounted. Instead of using RefPtr, use std::unique_ptr.
Get rid of cancelTracking and hideContextMenu and dismiss the menu whenever the menu proxy is destroyed.
Also, rename showContextMenu to show.

* UIProcess/PageClient.h:
* UIProcess/WebContextMenuProxy.h:
(WebKit::WebContextMenuProxy::cancelTracking): Deleted.
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::close):
(WebKit::WebPageProxy::internalShowContextMenu):
* UIProcess/WebPageProxy.h:
* UIProcess/ios/PageClientImplIOS.h:
* UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::createContextMenuProxy):
* UIProcess/mac/PageClientImpl.h:
* UIProcess/mac/PageClientImpl.mm:
(WebKit::PageClientImpl::createContextMenuProxy):
* UIProcess/mac/WebContextMenuProxyMac.h:
(WebKit::WebContextMenuProxyMac::create): Deleted.
* UIProcess/mac/WebContextMenuProxyMac.mm:
(WebKit::WebContextMenuProxyMac::~WebContextMenuProxyMac):
(WebKit::WebContextMenuProxyMac::show):
(WebKit::WebContextMenuProxyMac::showContextMenu): Deleted.
(WebKit::WebContextMenuProxyMac::hideContextMenu): Deleted.
(WebKit::WebContextMenuProxyMac::cancelTracking): Deleted.

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/PageClient.h
Source/WebKit2/UIProcess/WebContextMenuProxy.h
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/ios/PageClientImplIOS.h
Source/WebKit2/UIProcess/ios/PageClientImplIOS.mm
Source/WebKit2/UIProcess/mac/PageClientImpl.h
Source/WebKit2/UIProcess/mac/PageClientImpl.mm
Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.h
Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.mm

index 0708c35..f61a507 100644 (file)
@@ -1,5 +1,38 @@
 2015-10-21  Anders Carlsson  <andersca@apple.com>
 
+        WebContextMenuProxy doesn't have to be ref-counted
+        https://bugs.webkit.org/show_bug.cgi?id=150415
+
+        Reviewed by Tim Horton.
+
+        Change WebContextMenuProxy to not inherit from RefCounted. Instead of using RefPtr, use std::unique_ptr.
+        Get rid of cancelTracking and hideContextMenu and dismiss the menu whenever the menu proxy is destroyed.
+        Also, rename showContextMenu to show.
+
+        * UIProcess/PageClient.h:
+        * UIProcess/WebContextMenuProxy.h:
+        (WebKit::WebContextMenuProxy::cancelTracking): Deleted.
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::close):
+        (WebKit::WebPageProxy::internalShowContextMenu):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/ios/PageClientImplIOS.h:
+        * UIProcess/ios/PageClientImplIOS.mm:
+        (WebKit::PageClientImpl::createContextMenuProxy):
+        * UIProcess/mac/PageClientImpl.h:
+        * UIProcess/mac/PageClientImpl.mm:
+        (WebKit::PageClientImpl::createContextMenuProxy):
+        * UIProcess/mac/WebContextMenuProxyMac.h:
+        (WebKit::WebContextMenuProxyMac::create): Deleted.
+        * UIProcess/mac/WebContextMenuProxyMac.mm:
+        (WebKit::WebContextMenuProxyMac::~WebContextMenuProxyMac):
+        (WebKit::WebContextMenuProxyMac::show):
+        (WebKit::WebContextMenuProxyMac::showContextMenu): Deleted.
+        (WebKit::WebContextMenuProxyMac::hideContextMenu): Deleted.
+        (WebKit::WebContextMenuProxyMac::cancelTracking): Deleted.
+
+2015-10-21  Anders Carlsson  <andersca@apple.com>
+
         Stop using a popup menu button cell(!) for context menus
         https://bugs.webkit.org/show_bug.cgi?id=150413
 
index e5567ad..8f39e1e 100644 (file)
@@ -224,7 +224,7 @@ public:
 
     virtual RefPtr<WebPopupMenuProxy> createPopupMenuProxy(WebPageProxy&) = 0;
 #if ENABLE(CONTEXT_MENUS)
-    virtual RefPtr<WebContextMenuProxy> createContextMenuProxy(WebPageProxy&, const ContextMenuContextData&, const UserData&) = 0;
+    virtual std::unique_ptr<WebContextMenuProxy> createContextMenuProxy(WebPageProxy&, const ContextMenuContextData&, const UserData&) = 0;
 #endif
 
 #if ENABLE(INPUT_TYPE_COLOR)
index 1d196d0..0a849ad 100644 (file)
@@ -36,13 +36,11 @@ namespace WebKit {
 
 class WebContextMenuItem;
 
-class WebContextMenuProxy : public RefCounted<WebContextMenuProxy> {
+class WebContextMenuProxy {
 public:
     virtual ~WebContextMenuProxy();
 
-    virtual void showContextMenu() = 0;
-    virtual void hideContextMenu() = 0;
-    virtual void cancelTracking() { }
+    virtual void show() = 0;
 
 protected:
     WebContextMenuProxy(const ContextMenuContextData&, const UserData&);
index 5eacb36..82af476 100644 (file)
@@ -817,8 +817,7 @@ void WebPageProxy::close()
         m_activePopupMenu->cancelTracking();
 
 #if ENABLE(CONTEXT_MENUS)
-    if (m_activeContextMenu)
-        m_activeContextMenu->cancelTracking();
+    m_activeContextMenu = nullptr;
 #endif
 
     m_backForwardList->pageClosed();
@@ -4197,11 +4196,6 @@ void WebPageProxy::internalShowContextMenu(const ContextMenuContextData& context
 {
     m_activeContextMenuContextData = contextMenuContextData;
 
-    if (!m_contextMenuClient->hideContextMenu(*this) && m_activeContextMenu) {
-        m_activeContextMenu->hideContextMenu();
-        m_activeContextMenu = nullptr;
-    }
-
     m_activeContextMenu = m_pageClient.createContextMenuProxy(*this, contextMenuContextData, userData);
     if (!m_activeContextMenu)
         return;
@@ -4209,7 +4203,7 @@ void WebPageProxy::internalShowContextMenu(const ContextMenuContextData& context
     // Since showContextMenu() can spin a nested run loop we need to turn off the responsiveness timer.
     m_process->responsivenessTimer()->stop();
 
-    m_activeContextMenu->showContextMenu();
+    m_activeContextMenu->show();
 }
 
 void WebPageProxy::contextMenuItemSelected(const WebContextMenuItemData& item)
index 76acf8d..75dbd0c 100644 (file)
@@ -1546,7 +1546,7 @@ private:
 
     RefPtr<WebPopupMenuProxy> m_activePopupMenu;
 #if ENABLE(CONTEXT_MENUS)
-    RefPtr<WebContextMenuProxy> m_activeContextMenu;
+    std::unique_ptr<WebContextMenuProxy> m_activeContextMenu;
     ContextMenuContextData m_activeContextMenuContextData;
 #endif
     RefPtr<API::HitTestResult> m_lastMouseMoveHitTestResult;
index f0e564e..6ec47b6 100644 (file)
@@ -97,7 +97,7 @@ private:
 #endif
     virtual RefPtr<WebPopupMenuProxy> createPopupMenuProxy(WebPageProxy&) override;
 #if ENABLE(CONTEXT_MENUS)
-    virtual RefPtr<WebContextMenuProxy> createContextMenuProxy(WebPageProxy&, const ContextMenuContextData&, const UserData&) override;
+    virtual std::unique_ptr<WebContextMenuProxy> createContextMenuProxy(WebPageProxy&, const ContextMenuContextData&, const UserData&) override;
 #endif
     virtual void setTextIndicator(Ref<WebCore::TextIndicator>, WebCore::TextIndicatorWindowLifetime) override;
     virtual void clearTextIndicator(WebCore::TextIndicatorWindowDismissalAnimation) override;
index 1541d8b..55ec2ae 100644 (file)
@@ -444,7 +444,7 @@ RefPtr<WebPopupMenuProxy> PageClientImpl::createPopupMenuProxy(WebPageProxy&)
 }
 
 #if ENABLE(CONTEXT_MENUS)
-RefPtr<WebContextMenuProxy> PageClientImpl::createContextMenuProxy(WebPageProxy&, const UserData&)
+std::unique_ptr<WebContextMenuProxy> PageClientImpl::createContextMenuProxy(WebPageProxy&, const UserData&)
 {
     return nullptr;
 }
index d302f11..46aa520 100644 (file)
@@ -127,7 +127,7 @@ private:
 
     virtual RefPtr<WebPopupMenuProxy> createPopupMenuProxy(WebPageProxy&) override;
 #if ENABLE(CONTEXT_MENUS)
-    virtual RefPtr<WebContextMenuProxy> createContextMenuProxy(WebPageProxy&, const ContextMenuContextData&, const UserData&) override;
+    virtual std::unique_ptr<WebContextMenuProxy> createContextMenuProxy(WebPageProxy&, const ContextMenuContextData&, const UserData&) override;
 #endif
 
 #if ENABLE(INPUT_TYPE_COLOR)
index d27971d..4c3d606 100644 (file)
@@ -500,9 +500,9 @@ RefPtr<WebPopupMenuProxy> PageClientImpl::createPopupMenuProxy(WebPageProxy& pag
 }
 
 #if ENABLE(CONTEXT_MENUS)
-RefPtr<WebContextMenuProxy> PageClientImpl::createContextMenuProxy(WebPageProxy& page, const ContextMenuContextData& context, const UserData& userData)
+std::unique_ptr<WebContextMenuProxy> PageClientImpl::createContextMenuProxy(WebPageProxy& page, const ContextMenuContextData& context, const UserData& userData)
 {
-    return WebContextMenuProxyMac::create(m_wkView, page, context, userData);
+    return std::make_unique<WebContextMenuProxyMac>(m_wkView, page, context, userData);
 }
 #endif
 
index 3d1df1b..9a71af3 100644 (file)
@@ -44,17 +44,9 @@ class WebPageProxy;
 
 class WebContextMenuProxyMac : public WebContextMenuProxy {
 public:
-    static Ref<WebContextMenuProxyMac> create(WKView* webView, WebPageProxy& page, const ContextMenuContextData& context, const UserData& userData)
-    {
-        return adoptRef(*new WebContextMenuProxyMac(webView, page, context, userData));
-    }
+    WebContextMenuProxyMac(WKView*, WebPageProxy&, const ContextMenuContextData&, const UserData&);
     ~WebContextMenuProxyMac();
 
-    virtual void showContextMenu() override;
-
-    virtual void hideContextMenu() override;
-    virtual void cancelTracking() override;
-    
     void contextMenuItemSelected(const WebContextMenuItemData&);
 
 #if ENABLE(SERVICE_CONTROLS)
@@ -65,7 +57,7 @@ public:
     NSWindow *window() const;
 
 private:
-    WebContextMenuProxyMac(WKView*, WebPageProxy&, const ContextMenuContextData&, const UserData&);
+    virtual void show() override;
 
     void populate(const Vector<RefPtr<WebContextMenuItem>>&);
 
index 8dc291a..7eef34d 100644 (file)
@@ -160,6 +160,7 @@ WebContextMenuProxyMac::WebContextMenuProxyMac(WKView* webView, WebPageProxy& pa
 
 WebContextMenuProxyMac::~WebContextMenuProxyMac()
 {
+    [m_menu cancelTracking];
 }
 
 void WebContextMenuProxyMac::contextMenuItemSelected(const WebContextMenuItemData& item)
@@ -374,7 +375,7 @@ void WebContextMenuProxyMac::populate(const Vector<RefPtr<WebContextMenuItem>>&
     populateNSMenu(m_menu.get(), nsMenuItemVector(items));
 }
 
-void WebContextMenuProxyMac::showContextMenu()
+void WebContextMenuProxyMac::show()
 {
     // Unless this is an image control, give the PageContextMenuClient one last swipe at changing the menu.
     bool askClientToChangeMenu = true;
@@ -422,21 +423,9 @@ void WebContextMenuProxyMac::showContextMenu()
         [[WKSharingServicePickerDelegate sharedSharingServicePickerDelegate] setMenuProxy:this];
 #endif
 
-    Ref<WebContextMenuProxyMac> protect(*this);
+    Ref<WebPageProxy> protect(m_page);
 
     [m_menu popUpMenuPositioningItem:nil atLocation:m_context.menuLocation() inView:m_webView];
-
-    hideContextMenu();
-}
-
-void WebContextMenuProxyMac::hideContextMenu()
-{
-    [m_menu cancelTracking];
-}
-
-void WebContextMenuProxyMac::cancelTracking()
-{
-    [m_menu cancelTracking];
 }
 
 NSWindow *WebContextMenuProxyMac::window() const