static void test_dom_document_title(DomDocumentFixture* fixture, gconstpointer data) { g_assert(fixture); WebKitWebView* view = (WebKitWebView*)fixture->webView; g_assert(view); WebKitDOMDocument* document = webkit_web_view_get_dom_document(view); g_assert(document); gchar* title = webkit_dom_document_get_title(document); g_assert(title); g_assert_cmpstr(title, ==, "This is the title"); g_free(title); webkit_dom_document_set_title(document, "This is the second title"); title = webkit_dom_document_get_title(document); g_assert(title); g_assert_cmpstr(title, ==, "This is the second title"); g_free(title); }
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); WebKitWebPage* page = getWebPage(WEBKIT_WEB_EXTENSION(userData), pageID, invocation); if (!page) return; WebKitDOMDocument* document = webkit_web_page_get_dom_document(page); GUniquePtr<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, "RunJavaScriptInIsolatedWorld")) { uint64_t pageID; const char* script; g_variant_get(parameters, "(t&s)", &pageID, &script); WebKitWebPage* page = getWebPage(WEBKIT_WEB_EXTENSION(userData), pageID, invocation); if (!page) return; GRefPtr<WebKitScriptWorld> world = adoptGRef(webkit_script_world_new()); g_assert(webkit_script_world_get_default() != world.get()); WebKitFrame* frame = webkit_web_page_get_main_frame(page); JSGlobalContextRef jsContext = webkit_frame_get_javascript_context_for_script_world(frame, world.get()); JSRetainPtr<JSStringRef> jsScript(Adopt, JSStringCreateWithUTF8CString(script)); JSEvaluateScript(jsContext, jsScript.get(), 0, 0, 0, 0); g_dbus_method_invocation_return_value(invocation, 0); } else if (!g_strcmp0(methodName, "AbortProcess")) { abort(); } else if (!g_strcmp0(methodName, "GetInitializationUserData")) { g_assert(initializationUserData); g_assert(g_variant_is_of_type(initializationUserData.get(), G_VARIANT_TYPE_STRING)); g_dbus_method_invocation_return_value(invocation, g_variant_new("(s)", g_variant_get_string(initializationUserData.get(), nullptr))); } else if (!g_strcmp0(methodName, "GetProcessIdentifier")) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(u)", static_cast<guint32>(getCurrentProcessID()))); } }
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")) {