static WebKitWebPage *get_web_page_or_return_dbus_error(GDBusMethodInvocation *invocation, WebKitWebExtension *extension, guint64 pageid) { WebKitWebPage *page = webkit_web_extension_get_page(extension, pageid); if (!page) { g_warning("invalid page id %lu", pageid); g_dbus_method_invocation_return_error(invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "Invalid page ID: %"G_GUINT64_FORMAT, pageid); } return page; }
static WebKitWebPage* getWebPage(WebKitWebExtension* extension, uint64_t pageID, GDBusMethodInvocation* invocation) { WebKitWebPage* page = webkit_web_extension_get_page(extension, pageID); if (!page) { g_dbus_method_invocation_return_error( invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "Invalid page ID: %" G_GUINT64_FORMAT, pageID); return 0; } g_assert_cmpuint(webkit_web_page_get_id(page), ==, pageID); return page; }
static void autologin_timer_expired_cb(LightDMGreeter *greeter, WebKitWebExtension *extension) { WebKitWebPage *web_page; WebKitFrame *web_frame; JSGlobalContextRef jsContext; JSStringRef command; web_page = webkit_web_extension_get_page(extension, page_id); if (web_page != NULL) { web_frame = webkit_web_page_get_main_frame(web_page); jsContext = webkit_frame_get_javascript_global_context(web_frame); command = JSStringCreateWithUTF8CString("autologin_timer_expired()"); JSEvaluateScript(jsContext, command, NULL, NULL, 0, NULL); } }
static void show_message_cb(LightDMGreeter *greeter, const gchar *text, LightDMMessageType type, WebKitWebExtension *extension) { WebKitWebPage *web_page; WebKitFrame *web_frame; JSGlobalContextRef jsContext; JSStringRef command; gchar *etext; gchar *string; const gchar *mt = ""; web_page = webkit_web_extension_get_page(extension, page_id); if (web_page != NULL) { web_frame = webkit_web_page_get_main_frame(web_page); jsContext = webkit_frame_get_javascript_global_context(web_frame); switch (type) { case LIGHTDM_MESSAGE_TYPE_ERROR: mt = "error"; break; case LIGHTDM_MESSAGE_TYPE_INFO: mt = "info"; break; } etext = escape(text); string = g_strdup_printf("show_prompt('%s', '%s')", etext, mt); command = JSStringCreateWithUTF8CString(string); JSEvaluateScript(jsContext, command, NULL, NULL, 0, NULL); g_free(string); g_free(etext); } }
static void show_prompt_cb(LightDMGreeter *greeter, const gchar *text, LightDMPromptType type, WebKitWebExtension *extension) { WebKitWebPage *web_page; WebKitFrame *web_frame; JSGlobalContextRef jsContext; JSStringRef command; gchar *string; gchar *etext; const gchar *ct = ""; web_page = webkit_web_extension_get_page(extension, page_id); if (web_page != NULL) { web_frame = webkit_web_page_get_main_frame(web_page); jsContext = webkit_frame_get_javascript_global_context(web_frame); switch (type) { case LIGHTDM_PROMPT_TYPE_QUESTION: ct = "text"; break; case LIGHTDM_PROMPT_TYPE_SECRET: ct = "password"; break; } etext = escape(text); string = g_strdup_printf("show_prompt('%s', '%s')", etext, ct); command = JSStringCreateWithUTF8CString(string); JSEvaluateScript(jsContext, command, NULL, NULL, 0, NULL); g_free(string); g_free(etext); } }
static void methodCallCallback(GDBusConnection* connection, const char* sender, const char* objectPath, const char* interfaceName, const char* methodName, GVariant* parameters, GDBusMethodInvocation* invocation, gpointer userData) { if (g_strcmp0(interfaceName, "org.webkit.gtk.WebExtensionTest")) return; if (!g_strcmp0(methodName, "GetTitle")) { uint64_t pageID; g_variant_get(parameters, "(t)", &pageID); WebKitWebExtension* extension = WEBKIT_WEB_EXTENSION(userData); WebKitWebPage* page = webkit_web_extension_get_page(extension, pageID); if (!page) { g_dbus_method_invocation_return_error( invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "Invalid page ID: %" G_GUINT64_FORMAT, pageID); return; } g_assert_cmpuint(webkit_web_page_get_id(page), ==, pageID); WebKitDOMDocument* document = webkit_web_page_get_dom_document(page); GOwnPtr<char> title(webkit_dom_document_get_title(document)); g_dbus_method_invocation_return_value(invocation, g_variant_new("(s)", title.get())); } else if (!g_strcmp0(methodName, "AbortProcess")) {