Bug 223160 - [GTK] Clicking on a custom context menu item doesn't activate action (WebExtension)
Summary: [GTK] Clicking on a custom context menu item doesn't activate action (WebExte...
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKitGTK (show other bugs)
Version: Other
Hardware: PC Linux
: P3 Normal
Assignee: Nobody
URL:
Keywords: Gtk
Depends on:
Blocks:
 
Reported: 2021-03-14 06:33 PDT by samuel.dudik
Modified: 2021-03-16 12:34 PDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description samuel.dudik 2021-03-14 06:33:53 PDT
Clicking on a custom 'right-click' context menu item created with webkit_context_menu_item_new_from_gaction doesn't activate the specified action (no errors or warnings). This behavior only appears when using the "context-menu" signal from a WebKitWebPage (which is the only way when connecting from a WebExtension). Using it from WebKitWebView works fine.

static void web_page_created_callback(WebKitWebExtension *extension, WebKitWebPage *web_page, gpointer user_data)
{
	g_signal_connect(web_page, "context-menu", G_CALLBACK(context_menu_opened_callback), NULL);
}

static void open_adblock_settings(GSimpleAction *action, GVariant *parameter, gpointer user_data)
{
	g_print("Opened settings\n");
}

static gboolean context_menu_opened_callback(WebKitWebPage *web_page, WebKitContextMenu *context_menu, WebKitWebHitTestResult *hit_test_result, gpointer user_data)
{
	g_print("Context menu opened\n");

	webkit_context_menu_append(context_menu, webkit_context_menu_item_new_separator());

	GSimpleAction *action = g_simple_action_new("open-settings", NULL);
	g_signal_connect(action, "activate", G_CALLBACK(open_adblock_settings), NULL);

	WebKitContextMenuItem *item = webkit_context_menu_item_new_from_gaction(G_ACTION(action), "Settings", NULL);
	webkit_context_menu_append(context_menu, item);

	return TRUE;
}

After clicking on the "Settings" menu item:
Expected Results: "Opened settings" gets printed.
Actual Results: "Opened settings" doesn't get printed.

Encountered on Void Linux, WebKitGTK 2.30.5.