- Revision
- 271206
- Author
- [email protected]
- Date
- 2021-01-06 11:31:01 -0800 (Wed, 06 Jan 2021)
Log Message
Modernize WebContextMenu
https://bugs.webkit.org/show_bug.cgi?id=219969
Patch by Alex Christensen <[email protected]> on 2021-01-06
Reviewed by Tim Horton.
This is old code, complete with a raw pointer.
Use references instead of pointers where possible,
and WeakPtr instead of a raw pointer.
* WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:
(WKBundlePageClickMenuItem):
(WKBundlePageCopyContextMenuItems):
* WebProcess/WebCoreSupport/WebContextMenuClient.cpp:
(WebKit::WebContextMenuClient::showContextMenu):
* WebProcess/WebPage/WebContextMenu.cpp:
(WebKit::WebContextMenu::WebContextMenu):
* WebProcess/WebPage/WebContextMenu.h:
(WebKit::WebContextMenu::create):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::contextMenu):
(WebKit::WebPage::contextMenuAtPointInWindow):
(WebKit::handleContextMenuEvent):
(WebKit::WebPage::contextMenuForKeyEvent):
Modified Paths
Diff
Modified: trunk/Source/WebKit/ChangeLog (271205 => 271206)
--- trunk/Source/WebKit/ChangeLog 2021-01-06 19:22:03 UTC (rev 271205)
+++ trunk/Source/WebKit/ChangeLog 2021-01-06 19:31:01 UTC (rev 271206)
@@ -1,3 +1,29 @@
+2021-01-06 Alex Christensen <[email protected]>
+
+ Modernize WebContextMenu
+ https://bugs.webkit.org/show_bug.cgi?id=219969
+
+ Reviewed by Tim Horton.
+
+ This is old code, complete with a raw pointer.
+ Use references instead of pointers where possible,
+ and WeakPtr instead of a raw pointer.
+
+ * WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:
+ (WKBundlePageClickMenuItem):
+ (WKBundlePageCopyContextMenuItems):
+ * WebProcess/WebCoreSupport/WebContextMenuClient.cpp:
+ (WebKit::WebContextMenuClient::showContextMenu):
+ * WebProcess/WebPage/WebContextMenu.cpp:
+ (WebKit::WebContextMenu::WebContextMenu):
+ * WebProcess/WebPage/WebContextMenu.h:
+ (WebKit::WebContextMenu::create):
+ * WebProcess/WebPage/WebPage.cpp:
+ (WebKit::WebPage::contextMenu):
+ (WebKit::WebPage::contextMenuAtPointInWindow):
+ (WebKit::handleContextMenuEvent):
+ (WebKit::WebPage::contextMenuForKeyEvent):
+
2021-01-06 Sihui Liu <[email protected]>
Stop speech recognition if page becomes invisible
Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp (271205 => 271206)
--- trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp 2021-01-06 19:22:03 UTC (rev 271205)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp 2021-01-06 19:31:01 UTC (rev 271206)
@@ -181,7 +181,7 @@
void WKBundlePageClickMenuItem(WKBundlePageRef pageRef, WKContextMenuItemRef item)
{
#if ENABLE(CONTEXT_MENUS)
- WebKit::toImpl(pageRef)->contextMenu()->itemSelected(WebKit::toImpl(item)->data());
+ WebKit::toImpl(pageRef)->contextMenu().itemSelected(WebKit::toImpl(item)->data());
#else
UNUSED_PARAM(pageRef);
UNUSED_PARAM(item);
@@ -206,9 +206,9 @@
WKArrayRef WKBundlePageCopyContextMenuItems(WKBundlePageRef pageRef)
{
#if ENABLE(CONTEXT_MENUS)
- WebKit::WebContextMenu* contextMenu = WebKit::toImpl(pageRef)->contextMenu();
+ auto& contextMenu = WebKit::toImpl(pageRef)->contextMenu();
- return WebKit::toAPI(&contextMenuItems(*contextMenu).leakRef());
+ return WebKit::toAPI(&contextMenuItems(contextMenu).leakRef());
#else
UNUSED_PARAM(pageRef);
return nullptr;
Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebContextMenuClient.cpp (271205 => 271206)
--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebContextMenuClient.cpp 2021-01-06 19:22:03 UTC (rev 271205)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebContextMenuClient.cpp 2021-01-06 19:31:01 UTC (rev 271206)
@@ -95,7 +95,7 @@
void WebContextMenuClient::showContextMenu()
{
- m_page->contextMenu()->show();
+ m_page->contextMenu().show();
}
#endif
Modified: trunk/Source/WebKit/WebProcess/WebPage/WebContextMenu.cpp (271205 => 271206)
--- trunk/Source/WebKit/WebProcess/WebPage/WebContextMenu.cpp 2021-01-06 19:22:03 UTC (rev 271205)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebContextMenu.cpp 2021-01-06 19:31:01 UTC (rev 271206)
@@ -40,8 +40,8 @@
namespace WebKit {
using namespace WebCore;
-WebContextMenu::WebContextMenu(WebPage* page)
- : m_page(page)
+WebContextMenu::WebContextMenu(WebPage& page)
+ : m_page(makeWeakPtr(page))
{
}
Modified: trunk/Source/WebKit/WebProcess/WebPage/WebContextMenu.h (271205 => 271206)
--- trunk/Source/WebKit/WebProcess/WebPage/WebContextMenu.h 2021-01-06 19:22:03 UTC (rev 271205)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebContextMenu.h 2021-01-06 19:31:01 UTC (rev 271206)
@@ -18,8 +18,7 @@
*
*/
-#ifndef WebContextMenu_h
-#define WebContextMenu_h
+#pragma once
#if ENABLE(CONTEXT_MENUS)
@@ -27,6 +26,7 @@
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
+#include <wtf/WeakPtr.h>
namespace WebCore {
class Image;
@@ -39,7 +39,7 @@
class WebContextMenu : public RefCounted<WebContextMenu> {
public:
- static Ref<WebContextMenu> create(WebPage* page)
+ static Ref<WebContextMenu> create(WebPage& page)
{
return adoptRef(*new WebContextMenu(page));
}
@@ -51,13 +51,12 @@
Vector<WebContextMenuItemData> items() const;
private:
- WebContextMenu(WebPage*);
+ WebContextMenu(WebPage&);
void menuItemsWithUserData(Vector<WebContextMenuItemData>&, RefPtr<API::Object>&) const;
- WebPage* m_page;
+ WeakPtr<WebPage> m_page;
};
} // namespace WebKit
#endif // ENABLE(CONTEXT_MENUS)
-#endif // WebPopupMenu_h
Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (271205 => 271206)
--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp 2021-01-06 19:22:03 UTC (rev 271205)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp 2021-01-06 19:31:01 UTC (rev 271206)
@@ -2587,11 +2587,11 @@
}
#if ENABLE(CONTEXT_MENUS)
-WebContextMenu* WebPage::contextMenu()
+WebContextMenu& WebPage::contextMenu()
{
if (!m_contextMenu)
- m_contextMenu = WebContextMenu::create(this);
- return m_contextMenu.get();
+ m_contextMenu = WebContextMenu::create(*this);
+ return *m_contextMenu;
}
WebContextMenu* WebPage::contextMenuAtPointInWindow(const IntPoint& point)
@@ -2602,7 +2602,7 @@
PlatformMouseEvent mousePressEvent(point, point, RightButton, PlatformEvent::MousePressed, 1, false, false, false, false, WallTime::now(), WebCore::ForceAtClick, WebCore::NoTap);
corePage()->userInputBridge().handleMousePressEvent(mousePressEvent);
bool handled = corePage()->userInputBridge().handleContextMenuEvent(mousePressEvent, corePage()->mainFrame());
- auto* menu = handled ? contextMenu() : nullptr;
+ auto* menu = handled ? &contextMenu() : nullptr;
PlatformMouseEvent mouseReleaseEvent(point, point, RightButton, PlatformEvent::MouseReleased, 1, false, false, false, false, WallTime::now(), WebCore::ForceAtClick, WebCore::NoTap);
corePage()->userInputBridge().handleMouseReleaseEvent(mouseReleaseEvent);
@@ -2750,7 +2750,7 @@
bool handled = page->corePage()->userInputBridge().handleContextMenuEvent(platformMouseEvent, *frame);
#if ENABLE(CONTEXT_MENUS)
if (handled)
- page->contextMenu()->show();
+ page->contextMenu().show();
#endif
return handled;
}
@@ -2765,7 +2765,7 @@
bool handled = frame.eventHandler().sendContextMenuEventForKey();
#if ENABLE(CONTEXT_MENUS)
if (handled)
- contextMenu()->show();
+ contextMenu().show();
#else
UNUSED_PARAM(handled);
#endif
Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (271205 => 271206)
--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h 2021-01-06 19:22:03 UTC (rev 271205)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h 2021-01-06 19:31:01 UTC (rev 271206)
@@ -819,7 +819,7 @@
void pageDidScroll();
#if ENABLE(CONTEXT_MENUS)
- WebContextMenu* contextMenu();
+ WebContextMenu& contextMenu();
WebContextMenu* contextMenuAtPointInWindow(const WebCore::IntPoint&);
#endif