Пример #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);
    }
}
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);
	}
}
Пример #3
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
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);
	}
}