Example #1
0
/**
 * Handle dbus method calls.
 */
static void dbus_handle_method_call(GDBusConnection *conn, const char *sender,
        const char *object_path, const char *interface_name, const char *method,
        GVariant *parameters, GDBusMethodInvocation *invocation, gpointer extension)
{
    char *value;
    guint64 pageid;
    WebKitWebPage *page;

    if (g_str_has_prefix(method, "EvalJs")) {
        char *result       = NULL;
        gboolean success;
        gboolean no_result;
        JSValueRef ref     = NULL;
        JSGlobalContextRef jsContext;

        g_variant_get(parameters, "(ts)", &pageid, &value);
        page = get_web_page_or_return_dbus_error(invocation, WEBKIT_WEB_EXTENSION(extension), pageid);
        if (!page) {
            return;
        }

        no_result = !g_strcmp0(method, "EvalJsNoResult");
        jsContext = webkit_frame_get_javascript_context_for_script_world(
            webkit_web_page_get_main_frame(page),
            webkit_script_world_get_default()
        );

        success = ext_util_js_eval(jsContext, value, &ref);

        if (no_result) {
            g_dbus_method_invocation_return_value(invocation, NULL);
        } else {
            result = ext_util_js_ref_to_string(jsContext, ref);
            g_dbus_method_invocation_return_value(invocation, g_variant_new("(bs)", success, result));
            g_free(result);
        }
    } else if (!g_strcmp0(method, "FocusInput")) {
        g_variant_get(parameters, "(t)", &pageid);
        page = get_web_page_or_return_dbus_error(invocation, WEBKIT_WEB_EXTENSION(extension), pageid);
        if (!page) {
            return;
        }
        ext_dom_focus_input(webkit_web_page_get_dom_document(page));
        g_dbus_method_invocation_return_value(invocation, NULL);
    } else if (!g_strcmp0(method, "SetHeaderSetting")) {
        g_variant_get(parameters, "(s)", &value);

        if (ext.headers) {
            soup_header_free_param_list(ext.headers);
            ext.headers = NULL;
        }
        ext.headers = soup_header_parse_param_list(value);
        g_dbus_method_invocation_return_value(invocation, NULL);
    }
}
Example #2
0
/**
 * Callback for web pages document-loaded signal.
 */
static void on_web_page_document_loaded(WebKitWebPage *webpage, gpointer extension)
{
    /* If there is a hashtable of known document - detroy this and create a
     * new hashtable. */
    if (ext.documents) {
        g_hash_table_unref(ext.documents);
    }
    ext.documents = g_hash_table_new(g_direct_hash, g_direct_equal);

    add_onload_event_observers(webkit_web_page_get_dom_document(webpage), webpage);
}
Example #3
0
static void documentLoadedCallback(WebKitWebPage* webPage, WebKitWebExtension* extension)
{
    // FIXME: Too much code just to send a message, we need convenient custom API for this.
    WebKitDOMDocument* document = webkit_web_page_get_dom_document(webPage);
    GRefPtr<WebKitDOMDOMWindow> window = adoptGRef(webkit_dom_document_get_default_view(document));
    if (WebKitDOMWebKitNamespace* webkit = webkit_dom_dom_window_get_webkit_namespace(window.get())) {
        WebKitDOMUserMessageHandlersNamespace* messageHandlers = webkit_dom_webkit_namespace_get_message_handlers(webkit);
        if (WebKitDOMUserMessageHandler* handler = webkit_dom_user_message_handlers_namespace_get_handler(messageHandlers, "dom"))
            webkit_dom_user_message_handler_post_message(handler, "DocumentLoaded", nullptr);
    }

    webkit_dom_dom_window_webkit_message_handlers_post_message(window.get(), "dom-convenience", "DocumentLoaded");

    gpointer data = g_object_get_data(G_OBJECT(extension), "dbus-connection");
    if (data)
        emitDocumentLoaded(G_DBUS_CONNECTION(data));
    else
        delayedSignalsQueue.append(DelayedSignal(DocumentLoadedSignal));
}
Example #4
0
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")) {
Example #6
0
// document_loaded_cb is called when a document is loaded, and updates
// internal bookkeeping and attaches to signals from the document.
static void
document_loaded_cb(WebKitWebPage *page,
                   gpointer       user_data)
{
    Exten *exten = user_data;
    if(exten->registered_documents) {
        g_hash_table_unref(exten->registered_documents);
    }
    exten->registered_documents = g_hash_table_new(NULL, NULL);
    exten->document = webkit_web_page_get_dom_document(page);
    frame_document_loaded(exten->document, exten);
    active_element_change_cb(
            WEBKIT_DOM_EVENT_TARGET(exten->document),
            NULL,
            exten);
    // listen for scroll changes.
    webkit_dom_event_target_add_event_listener(
            WEBKIT_DOM_EVENT_TARGET(exten->document),
            "scroll",
            G_CALLBACK(document_scroll_cb),
            false,
            exten);
}
static void
window_object_cleared_callback(WebKitScriptWorld *world,
							   WebKitWebPage *web_page,
							   WebKitFrame *frame,
							   LightDMGreeter *greeter) {

	JSObjectRef gettext_object, lightdm_greeter_object, config_file_object, greeter_util_object;
	JSGlobalContextRef jsContext;
	JSObjectRef globalObject;
	WebKitDOMDocument *dom_document;
	WebKitDOMDOMWindow *dom_window;
	gchar *message = "LockHint";

	page_id = webkit_web_page_get_id(web_page);

	jsContext = webkit_frame_get_javascript_context_for_script_world(frame, world);
	globalObject = JSContextGetGlobalObject(jsContext);

	gettext_class = JSClassCreate(&gettext_definition);
	lightdm_greeter_class = JSClassCreate(&lightdm_greeter_definition);
	lightdm_user_class = JSClassCreate(&lightdm_user_definition);
	lightdm_language_class = JSClassCreate(&lightdm_language_definition);
	lightdm_layout_class = JSClassCreate(&lightdm_layout_definition);
	lightdm_session_class = JSClassCreate(&lightdm_session_definition);
	config_file_class = JSClassCreate(&config_file_definition);
	greeter_util_class = JSClassCreate(&greeter_util_definition);

	gettext_object = JSObjectMake(jsContext, gettext_class, NULL);

	JSObjectSetProperty(jsContext,
						globalObject,
						JSStringCreateWithUTF8CString("gettext"),
						gettext_object,
						kJSPropertyAttributeNone,
						NULL);

	lightdm_greeter_object = JSObjectMake(jsContext, lightdm_greeter_class, greeter);

	JSObjectSetProperty(jsContext,
						globalObject,
						JSStringCreateWithUTF8CString("lightdm"),
						lightdm_greeter_object,
						kJSPropertyAttributeNone,
						NULL);

	config_file_object = JSObjectMake(jsContext, config_file_class, greeter);

	JSObjectSetProperty(jsContext,
						globalObject,
						JSStringCreateWithUTF8CString("config"),
						config_file_object,
						kJSPropertyAttributeNone,
						NULL);

	greeter_util_object = JSObjectMake(jsContext, greeter_util_class, NULL);

	JSObjectSetProperty(jsContext,
						globalObject,
						JSStringCreateWithUTF8CString("greeterutil"),
						greeter_util_object,
						kJSPropertyAttributeNone,
						NULL);



	/* If the greeter was started as a lock-screen, send message to our UI process. */
	if (lightdm_greeter_get_lock_hint(greeter)) {
		dom_document = webkit_web_page_get_dom_document(web_page);
		dom_window = webkit_dom_document_get_default_view(dom_document);

		if (dom_window) {
			webkit_dom_dom_window_webkit_message_handlers_post_message(dom_window,
																	   "GreeterBridge", message);
		}
	}

}