From 286db5ef6e2e56b22227b69f3f974c0e491131a6 Mon Sep 17 00:00:00 2001 From: Scott Balneaves Date: Mon, 4 Jan 2016 14:51:45 -0600 Subject: [PATCH 01/18] Functional changes; provide_secret to response, added in_authentication and autologin-timer-expired callbacks, changes to prompt and message callbacks --- themes/simple/Makefile.am | 9 ++ themes/simple/index.html | 165 +++++++++++++++++++++++++++++++++ themes/simple/index.theme | 6 ++ themes/simple/power_button.png | Bin 0 -> 1296 bytes 4 files changed, 180 insertions(+) create mode 100644 themes/simple/Makefile.am create mode 100644 themes/simple/index.html create mode 100644 themes/simple/index.theme create mode 100644 themes/simple/power_button.png diff --git a/themes/simple/Makefile.am b/themes/simple/Makefile.am new file mode 100644 index 0000000..870e64b --- /dev/null +++ b/themes/simple/Makefile.am @@ -0,0 +1,9 @@ +themedir = $(THEME_DIR)/simple +theme_DATA = index.html index.theme power_button.png + +EXTRA_DIST = $(theme_DATA) + +DISTCLEANFILES = \ + Makefile.in + + diff --git a/themes/simple/index.html b/themes/simple/index.html new file mode 100644 index 0000000..810cc87 --- /dev/null +++ b/themes/simple/index.html @@ -0,0 +1,165 @@ + + + + + + + + + + +
+
+ + + + + +
+
+
+ + + + diff --git a/themes/simple/index.theme b/themes/simple/index.theme new file mode 100644 index 0000000..9d27a8a --- /dev/null +++ b/themes/simple/index.theme @@ -0,0 +1,6 @@ +[theme] +name=Simple +description=Simple Theme +engine=lightdm-webkit-greeter +url=index.html +session=gnome diff --git a/themes/simple/power_button.png b/themes/simple/power_button.png new file mode 100644 index 0000000000000000000000000000000000000000..3e0378a50e69bc13d79ae7a0d80da5be82b5e80c GIT binary patch literal 1296 zcmV+r1@HQaP)Y;~nw7!+8?Hb{&cK|tJG z8iQ^|%oek->4uV+%&%loGh_)$WHBK#;fK-5526bT$(*{)9|mUpjKZcR44EA+TWq29 zwmts1_indk-SqU&={e7H&U@bTycft}2Ta~UL)@_F?c1-z|FuAqE(QYWZ&q#2g<*3g zme+^|0EnBW?EiuMHCh1xTktIaFiKn`U;qICEFQ&$yOEEg0Y1Ha{>UM0j|N$)OP%OESfKs;?jm#_Q~{7meLFWL>kF2%-(_tfbd`!FW1yX>kd!zJ3%YRi)hEkythYKRL-~NX#k-T%Y=MU z>9xlP`968dOfmpGk5{zrK{hR+3(xPivQyh*ekp1BA$a_f*qu|b{kXhb+iRJU{>7>< zKLp1|41qwJl>Y@abY*7%AXFUT($d`JC)s!%Ny~`1$A7{7Y!XGMg&R_tTLCt)O5W~t z`Amfh#@yC6ql(s`{15Gn- z9ME>Q@N*%dO_ZLlpHRoOL`h|Sjh@qtS&gRZ+rk_QYzLJP-R>Y3agJpsoGBx7~mZPY9wc(NWfN zj!Of8sGAG<_{n=x$55-A4<$4Jz@;o-pmBq7R#x`SV2c4`IjMgGsM@8C%J2G0(>fgE zT|hXI@9VgqX(2hB)kNmeZAuw zrA_|qBb7Y>FvfacRUSG^MU%m{Q$i_P@CF9Zi*7W-f+5|eUDh8JsvuVO+>nI#COR#v zMwD+9$Z*RsT+`N4azYCLZ)uxL13R3j^#3S%mYl-}&F?D0ZG_!@;e%@rD{5mP#D%aB zPR$e8lH>!+WujIYgoA5*V`p;ilRGn2<4L!BginF){o}>5;k~PEnRhaaDjc$SUN+6L zIf*QpXM8Un%nPYitaRTELPNFdeN&iAX3`kaB+b9O`?pmB9a)>WZAak)agBaYcj?^| zAYyqSP+@g!AX8{%a&2L5AZBlJAXiXBY-w;|a&#;pP<3K#X=5NnZ*5^|ZZysMssI20 zC3HntbYx+4WjbSWWnpw>05UK!H7zkPEipJ$GBG+bG&(XjEig4YFfglF=?VY<03~!q zSaf7zbY(hiZ)9m^c>ppnF*PkQFfB1SR5CF-GBi3dIV~_XIxsK Date: Mon, 4 Jan 2016 14:55:14 -0600 Subject: [PATCH 02/18] Functional changes --- configure.ac | 11 +---- src/lightdm-webkit2-greeter-ext.c | 76 ++++++++++++++++++++++++++----- themes/Makefile.am | 2 +- themes/antergos | 1 - 4 files changed, 67 insertions(+), 23 deletions(-) delete mode 160000 themes/antergos diff --git a/configure.ac b/configure.ac index 777a178..6fe8b31 100644 --- a/configure.ac +++ b/configure.ac @@ -111,16 +111,7 @@ data/Makefile src/Makefile po/Makefile.in themes/Makefile -themes/antergos/Makefile -themes/antergos/js/Makefile -themes/antergos/img/Makefile -themes/antergos/img/thumbs/Makefile -themes/antergos/font-awesome/Makefile -themes/antergos/font-awesome/fonts/Makefile -themes/antergos/font-awesome/css/Makefile -themes/antergos/css/Makefile -themes/antergos/css/lib/Makefile -themes/antergos/css/bootstrap/Makefile +themes/simple/Makefile ]) dnl ########################################################################### diff --git a/src/lightdm-webkit2-greeter-ext.c b/src/lightdm-webkit2-greeter-ext.c index 6d0a6cf..e9fcc7e 100644 --- a/src/lightdm-webkit2-greeter-ext.c +++ b/src/lightdm-webkit2-greeter-ext.c @@ -568,32 +568,35 @@ start_authentication_cb(JSContextRef context, JSStringGetUTF8CString(name_arg, name, 1024); JSStringRelease(name_arg); - lightdm_greeter_authenticate(greeter, name); + if (*name == '\0') + lightdm_greeter_authenticate(greeter, NULL); + else + lightdm_greeter_authenticate(greeter, name); return JSValueMakeNull(context); } static JSValueRef -provide_secret_cb(JSContextRef context, +respond_cb(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { LightDMGreeter *greeter = JSObjectGetPrivate(thisObject); - JSStringRef secret_arg; - char secret[1024]; + JSStringRef response_arg; + char response[1024]; // FIXME: Throw exception if (!( argumentCount == 1 && JSValueGetType(context, arguments[0]) == kJSTypeString )) { return JSValueMakeNull(context); } - secret_arg = JSValueToStringCopy(context, arguments[0], NULL); - JSStringGetUTF8CString(secret_arg, secret, 1024); - JSStringRelease(secret_arg); + response_arg = JSValueToStringCopy(context, arguments[0], NULL); + JSStringGetUTF8CString(response_arg, response, 1024); + JSStringRelease(response_arg); - lightdm_greeter_respond(greeter, secret); + lightdm_greeter_respond(greeter, response); return JSValueMakeNull(context); } @@ -637,6 +640,14 @@ get_is_authenticated_cb(JSContextRef context, return JSValueMakeBoolean(context, lightdm_greeter_get_is_authenticated(greeter)); } +static JSValueRef +get_in_authentication_cb(JSContextRef context, + JSObjectRef thisObject, + JSStringRef propertyName, + JSValueRef *exception) { + LightDMGreeter *greeter = JSObjectGetPrivate(thisObject); + return JSValueMakeBoolean(context, lightdm_greeter_get_in_authentication(greeter)); +} static JSValueRef get_can_suspend_cb(JSContextRef context, @@ -895,6 +906,7 @@ static const JSStaticValue lightdm_greeter_values[] = { {"timed_login_user", get_timed_login_user_cb, NULL, kJSPropertyAttributeReadOnly}, {"timed_login_delay", get_timed_login_delay_cb, NULL, kJSPropertyAttributeReadOnly}, {"authentication_user", get_authentication_user_cb, NULL, kJSPropertyAttributeReadOnly}, + {"in_authentication", get_in_authentication_cb, NULL, kJSPropertyAttributeReadOnly}, {"is_authenticated", get_is_authenticated_cb, NULL, kJSPropertyAttributeReadOnly}, {"can_suspend", get_can_suspend_cb, NULL, kJSPropertyAttributeReadOnly}, {"can_hibernate", get_can_hibernate_cb, NULL, kJSPropertyAttributeReadOnly}, @@ -906,7 +918,7 @@ static const JSStaticValue lightdm_greeter_values[] = { static const JSStaticFunction lightdm_greeter_functions[] = { {"cancel_timed_login", cancel_timed_login_cb, kJSPropertyAttributeReadOnly}, {"start_authentication", start_authentication_cb, kJSPropertyAttributeReadOnly}, - {"provide_secret", provide_secret_cb, kJSPropertyAttributeReadOnly}, + {"respond", respond_cb, kJSPropertyAttributeReadOnly}, {"cancel_authentication", cancel_authentication_cb, kJSPropertyAttributeReadOnly}, {"suspend", suspend_cb, kJSPropertyAttributeReadOnly}, {"hibernate", hibernate_cb, kJSPropertyAttributeReadOnly}, @@ -1047,6 +1059,7 @@ show_prompt_cb(LightDMGreeter *greeter, JSGlobalContextRef jsContext; JSStringRef command; gchar *string; + const gchar *ct = ""; g_debug("Show prompt %s", text); @@ -1057,7 +1070,16 @@ show_prompt_cb(LightDMGreeter *greeter, jsContext = webkit_frame_get_javascript_global_context(web_frame); - string = g_strdup_printf("show_prompt('%s')", text); + switch (type) { + case LIGHTDM_PROMPT_TYPE_QUESTION: + ct = "text"; + break; + case LIGHTDM_PROMPT_TYPE_SECRET: + ct = "password"; + break; + } + + string = g_strdup_printf ("show_prompt('%s', '%s')", text, ct); command = JSStringCreateWithUTF8CString(string); JSEvaluateScript(jsContext, command, NULL, NULL, 0, NULL); @@ -1078,6 +1100,7 @@ show_message_cb(LightDMGreeter *greeter, JSGlobalContextRef jsContext; JSStringRef command; gchar *string; + const gchar *mt = ""; web_page = webkit_web_extension_get_page(extension, page_id); if (web_page != NULL) { @@ -1085,7 +1108,16 @@ show_message_cb(LightDMGreeter *greeter, jsContext = webkit_frame_get_javascript_global_context(web_frame); - string = g_strdup_printf("show_message('%s')", text); + switch (type) { + case LIGHTDM_MESSAGE_TYPE_ERROR: + mt = "error"; + break; + case LIGHTDM_MESSAGE_TYPE_INFO: + mt = "info"; + break; + } + + string = g_strdup_printf ("show_prompt('%s', '%s')", text, mt); command = JSStringCreateWithUTF8CString(string); JSEvaluateScript(jsContext, command, NULL, NULL, 0, NULL); @@ -1116,6 +1148,27 @@ authentication_complete_cb(LightDMGreeter *greeter, WebKitWebExtension *extensio } } +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); + } +} + G_MODULE_EXPORT void webkit_web_extension_initialize(WebKitWebExtension *extension) { @@ -1124,6 +1177,7 @@ webkit_web_extension_initialize(WebKitWebExtension *extension) { g_signal_connect(G_OBJECT(greeter), "authentication-complete", G_CALLBACK(authentication_complete_cb), extension); g_signal_connect(G_OBJECT(greeter), "show-prompt", G_CALLBACK(show_prompt_cb), extension); g_signal_connect(G_OBJECT(greeter), "show-message", G_CALLBACK(show_message_cb), extension); + g_signal_connect(G_OBJECT(greeter), "autologin-timer-expired", G_CALLBACK(autologin_timer_expired_cb), extension); g_signal_connect(webkit_script_world_get_default(), "window-object-cleared", diff --git a/themes/Makefile.am b/themes/Makefile.am index 64583bc..5f9a897 100644 --- a/themes/Makefile.am +++ b/themes/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = antergos +SUBDIRS = simple DISTCLEANFILES = \ Makefile.in diff --git a/themes/antergos b/themes/antergos deleted file mode 160000 index bc0b3fe..0000000 --- a/themes/antergos +++ /dev/null @@ -1 +0,0 @@ -Subproject commit bc0b3fe18f73d81c1fdf4043701c8706af88f6a9 From ac961e5fb02129422c9921a3780f6ebb6728744a Mon Sep 17 00:00:00 2001 From: Scott Balneaves Date: Mon, 4 Jan 2016 15:08:00 -0600 Subject: [PATCH 03/18] Escape text --- src/lightdm-webkit2-greeter-ext.c | 41 +++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/src/lightdm-webkit2-greeter-ext.c b/src/lightdm-webkit2-greeter-ext.c index e9fcc7e..dad4801 100644 --- a/src/lightdm-webkit2-greeter-ext.c +++ b/src/lightdm-webkit2-greeter-ext.c @@ -52,6 +52,37 @@ static JSClassRef lightdm_layout_class, lightdm_session_class; +static char * +escape (const gchar *text) +{ + size_t len; + size_t i, j; + int count = 0; + gchar *escaped; + + len = strlen (text); + + for (i = 0; i < len; i++) + if (text[i] == '\'') + count++; + + if (count == 0) + return g_strdup (text); + + escaped = g_malloc (len + count + 1); + + j = 0; + for (i = 0; i <= len; i++) { + if (text[i] == '\'') { + escaped[j] = '\\'; + j++; + } + escaped[j] = text[i]; + j++; + } + + return escaped; +} static JSValueRef get_user_name_cb(JSContextRef context, @@ -1059,6 +1090,7 @@ show_prompt_cb(LightDMGreeter *greeter, JSGlobalContextRef jsContext; JSStringRef command; gchar *string; + gchar *etext; const gchar *ct = ""; g_debug("Show prompt %s", text); @@ -1079,12 +1111,14 @@ show_prompt_cb(LightDMGreeter *greeter, break; } - string = g_strdup_printf ("show_prompt('%s', '%s')", text, ct); + 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); } } @@ -1099,6 +1133,7 @@ show_message_cb(LightDMGreeter *greeter, WebKitFrame *web_frame; JSGlobalContextRef jsContext; JSStringRef command; + gchar *etext; gchar *string; const gchar *mt = ""; @@ -1117,12 +1152,14 @@ show_message_cb(LightDMGreeter *greeter, break; } - string = g_strdup_printf ("show_prompt('%s', '%s')", text, mt); + 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); } } From 4cd3457a275f4431a59260f8462d7d6d49579d3b Mon Sep 17 00:00:00 2001 From: Scott Balneaves Date: Mon, 4 Jan 2016 15:32:22 -0600 Subject: [PATCH 04/18] Eliminated static char arrays, replaced with JSString*Size calls and g_malloc --- src/lightdm-webkit2-greeter-ext.c | 67 +++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 17 deletions(-) diff --git a/src/lightdm-webkit2-greeter-ext.c b/src/lightdm-webkit2-greeter-ext.c index dad4801..81924ee 100644 --- a/src/lightdm-webkit2-greeter-ext.c +++ b/src/lightdm-webkit2-greeter-ext.c @@ -466,7 +466,8 @@ set_layout_cb(JSContextRef context, JSValueRef value, JSValueRef *exception) { JSStringRef layout_arg; - char layout[1024]; + size_t layout_size; + gchar *layout; // FIXME: Throw exception if (JSValueGetType(context, value) != kJSTypeString) { @@ -474,11 +475,14 @@ set_layout_cb(JSContextRef context, } layout_arg = JSValueToStringCopy(context, value, NULL); - JSStringGetUTF8CString(layout_arg, layout, 1024); + layout_size = JSStringGetMaximumUTF8CStringSize(layout_arg); + layout = g_malloc (layout_size); + JSStringGetUTF8CString(layout_arg, layout, layout_size); JSStringRelease(layout_arg); //lightdm_set_layout (layout); + g_free (layout); return true; } @@ -588,7 +592,8 @@ start_authentication_cb(JSContextRef context, JSValueRef *exception) { LightDMGreeter *greeter = JSObjectGetPrivate(thisObject); JSStringRef name_arg; - char name[1024]; + size_t name_size; + gchar *name; // FIXME: Throw exception if (!( argumentCount == 1 && JSValueGetType(context, arguments[0]) == kJSTypeString )) { @@ -596,13 +601,17 @@ start_authentication_cb(JSContextRef context, } name_arg = JSValueToStringCopy(context, arguments[0], NULL); - JSStringGetUTF8CString(name_arg, name, 1024); + name_size = JSStringGetMaximumUTF8CStringSize(name_arg); + name = g_malloc (name_size); + JSStringGetUTF8CString(name_arg, name, name_size); JSStringRelease(name_arg); if (*name == '\0') lightdm_greeter_authenticate(greeter, NULL); else lightdm_greeter_authenticate(greeter, name); + + g_free (name); return JSValueMakeNull(context); } @@ -616,7 +625,8 @@ respond_cb(JSContextRef context, JSValueRef *exception) { LightDMGreeter *greeter = JSObjectGetPrivate(thisObject); JSStringRef response_arg; - char response[1024]; + size_t response_size; + gchar *response; // FIXME: Throw exception if (!( argumentCount == 1 && JSValueGetType(context, arguments[0]) == kJSTypeString )) { @@ -624,11 +634,14 @@ respond_cb(JSContextRef context, } response_arg = JSValueToStringCopy(context, arguments[0], NULL); - JSStringGetUTF8CString(response_arg, response, 1024); + response_size = JSStringGetMaximumUTF8CStringSize(response_arg); + response = g_malloc (response_size); + JSStringGetUTF8CString(response_arg, response, response_size); JSStringRelease(response_arg); lightdm_greeter_respond(greeter, response); + g_free (response); return JSValueMakeNull(context); } @@ -793,23 +806,28 @@ login_cb(JSContextRef context, JSValueRef *exception) { LightDMGreeter *greeter = JSObjectGetPrivate(thisObject); JSStringRef arg; - char username[1024], *session = NULL; + size_t username_size, session_size; + gchar *username, *session = NULL; // FIXME: Throw exception arg = JSValueToStringCopy(context, arguments[0], NULL); - JSStringGetUTF8CString(arg, username, 1024); + username_size = JSStringGetMaximumUTF8CStringSize(arg); + username = g_malloc (username_size); + JSStringGetUTF8CString(arg, username, username_size); JSStringRelease(arg); if (argumentCount > 1) { arg = JSValueToStringCopy(context, arguments[1], NULL); - session = g_malloc(sizeof(char) * 1024); - JSStringGetUTF8CString(arg, session, 1024); + session_size = JSStringGetMaximumUTF8CStringSize(arg); + session = g_malloc (session_size); + JSStringGetUTF8CString(arg, session, session_size); JSStringRelease(arg); } lightdm_greeter_start_session_sync(greeter, session, NULL); + g_free(username); g_free(session); return JSValueMakeNull(context); @@ -825,16 +843,20 @@ set_language_cb(JSContextRef context, JSValueRef *exception) { LightDMGreeter *greeter = JSObjectGetPrivate(thisObject); JSStringRef arg; - char language[1024]; + size_t language_size; + gchar *language; // FIXME: Throw exception arg = JSValueToStringCopy(context, arguments[0], NULL); - JSStringGetUTF8CString(arg, language, 1024); + language_size = JSStringGetMaximumUTF8CStringSize(arg); + language = g_malloc (language_size); + JSStringGetUTF8CString(arg, language, language_size); JSStringRelease(arg); lightdm_greeter_set_language(greeter, language); + g_free (language); return JSValueMakeNull(context); } @@ -847,7 +869,8 @@ gettext_cb(JSContextRef context, const JSValueRef arguments[], JSValueRef *exception) { JSStringRef string_arg, result; - char string[1024]; + size_t string_size; + gchar *string; // FIXME: Throw exception if (argumentCount != 1) { @@ -855,10 +878,13 @@ gettext_cb(JSContextRef context, } string_arg = JSValueToStringCopy(context, arguments[0], NULL); - JSStringGetUTF8CString(string_arg, string, 1024); + string_size = JSStringGetMaximumUTF8CStringSize(string_arg); + string = g_malloc (string_size); + JSStringGetUTF8CString(string_arg, string, string_size); JSStringRelease(string_arg); result = JSStringCreateWithUTF8CString(gettext(string)); + g_free (string); return JSValueMakeString(context, result); } @@ -871,7 +897,8 @@ ngettext_cb(JSContextRef context, const JSValueRef arguments[], JSValueRef *exception) { JSStringRef string_arg, plural_string_arg, result; - char string[1024], plural_string[1024]; + size_t string_size, plural_string_size; + gchar *string, *plural_string; unsigned int n; // FIXME: Throw exception @@ -880,16 +907,22 @@ ngettext_cb(JSContextRef context, } string_arg = JSValueToStringCopy(context, arguments[0], NULL); - JSStringGetUTF8CString(string_arg, string, 1024); + string_size = JSStringGetMaximumUTF8CStringSize(string_arg); + string = g_malloc (string_size); + JSStringGetUTF8CString(string_arg, string, string_size); JSStringRelease(string_arg); plural_string_arg = JSValueToStringCopy(context, arguments[1], NULL); - JSStringGetUTF8CString(plural_string_arg, string, 1024); + plural_string_size = JSStringGetMaximumUTF8CStringSize(plural_string_arg); + plural_string = g_malloc (plural_string_size); + JSStringGetUTF8CString(plural_string_arg, string, plural_string_size); JSStringRelease(plural_string_arg); n = JSValueToNumber(context, arguments[2], NULL); result = JSStringCreateWithUTF8CString(ngettext(string, plural_string, n)); + g_free (string); + g_free (plural_string); return JSValueMakeString(context, result); } From 9edd7bfba9e8d18d50d22675b01abe4c597f8a0f Mon Sep 17 00:00:00 2001 From: Scott Balneaves Date: Mon, 4 Jan 2016 16:23:50 -0600 Subject: [PATCH 05/18] Add in exception handling --- src/lightdm-webkit2-greeter-ext.c | 76 ++++++++++++++++++++++++------- 1 file changed, 60 insertions(+), 16 deletions(-) diff --git a/src/lightdm-webkit2-greeter-ext.c b/src/lightdm-webkit2-greeter-ext.c index 81924ee..5e74771 100644 --- a/src/lightdm-webkit2-greeter-ext.c +++ b/src/lightdm-webkit2-greeter-ext.c @@ -469,8 +469,11 @@ set_layout_cb(JSContextRef context, size_t layout_size; gchar *layout; - // FIXME: Throw exception if (JSValueGetType(context, value) != kJSTypeString) { + JSStringRef string = JSStringCreateWithUTF8CString("Expected a string"); + JSValueRef exceptionString = JSValueMakeString(context, string); + JSStringRelease(string); + *exception = JSValueToObject(context, exceptionString, NULL); return false; } @@ -573,8 +576,11 @@ cancel_timed_login_cb(JSContextRef context, JSValueRef *exception) { LightDMGreeter *greeter = JSObjectGetPrivate(thisObject); - // FIXME: Throw exception if (argumentCount != 0) { + JSStringRef string = JSStringCreateWithUTF8CString("Argument count not zero"); + JSValueRef exceptionString = JSValueMakeString(context, string); + JSStringRelease(string); + *exception = JSValueToObject(context, exceptionString, NULL); return JSValueMakeNull(context); } @@ -595,8 +601,11 @@ start_authentication_cb(JSContextRef context, size_t name_size; gchar *name; - // FIXME: Throw exception if (!( argumentCount == 1 && JSValueGetType(context, arguments[0]) == kJSTypeString )) { + JSStringRef string = JSStringCreateWithUTF8CString("Username argument not supplied"); + JSValueRef exceptionString = JSValueMakeString(context, string); + JSStringRelease(string); + *exception = JSValueToObject(context, exceptionString, NULL); return JSValueMakeNull(context); } @@ -628,8 +637,11 @@ respond_cb(JSContextRef context, size_t response_size; gchar *response; - // FIXME: Throw exception if (!( argumentCount == 1 && JSValueGetType(context, arguments[0]) == kJSTypeString )) { + JSStringRef string = JSStringCreateWithUTF8CString("Response not supplied"); + JSValueRef exceptionString = JSValueMakeString(context, string); + JSStringRelease(string); + *exception = JSValueToObject(context, exceptionString, NULL); return JSValueMakeNull(context); } @@ -655,8 +667,11 @@ cancel_authentication_cb(JSContextRef context, JSValueRef *exception) { LightDMGreeter *greeter = JSObjectGetPrivate(thisObject); - // FIXME: Throw exception if (argumentCount != 0) { + JSStringRef string = JSStringCreateWithUTF8CString("Argument count not zero"); + JSValueRef exceptionString = JSValueMakeString(context, string); + JSStringRelease(string); + *exception = JSValueToObject(context, exceptionString, NULL); return JSValueMakeNull(context); } @@ -709,8 +724,11 @@ suspend_cb(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { - // FIXME: Throw exception if (argumentCount != 0) { + JSStringRef string = JSStringCreateWithUTF8CString("Argument count not zero"); + JSValueRef exceptionString = JSValueMakeString(context, string); + JSStringRelease(string); + *exception = JSValueToObject(context, exceptionString, NULL); return JSValueMakeNull(context); } @@ -735,8 +753,11 @@ hibernate_cb(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { - // FIXME: Throw exception if (argumentCount != 0) { + JSStringRef string = JSStringCreateWithUTF8CString("Argument count not zero"); + JSValueRef exceptionString = JSValueMakeString(context, string); + JSStringRelease(string); + *exception = JSValueToObject(context, exceptionString, NULL); return JSValueMakeNull(context); } @@ -761,8 +782,11 @@ restart_cb(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { - // FIXME: Throw exception if (argumentCount != 0) { + JSStringRef string = JSStringCreateWithUTF8CString("Argument count not zero"); + JSValueRef exceptionString = JSValueMakeString(context, string); + JSStringRelease(string); + *exception = JSValueToObject(context, exceptionString, NULL); return JSValueMakeNull(context); } @@ -787,8 +811,11 @@ shutdown_cb(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { - // FIXME: Throw exception if (argumentCount != 0) { + JSStringRef string = JSStringCreateWithUTF8CString("Argument count not zero"); + JSValueRef exceptionString = JSValueMakeString(context, string); + JSStringRelease(string); + *exception = JSValueToObject(context, exceptionString, NULL); return JSValueMakeNull(context); } @@ -809,7 +836,14 @@ login_cb(JSContextRef context, size_t username_size, session_size; gchar *username, *session = NULL; - // FIXME: Throw exception + if (!((argumentCount == 1 && JSValueGetType (context, arguments[0]) == kJSTypeString) || + (argumentCount == 2 && JSValueGetType (context, arguments[0]) == kJSTypeString && JSValueGetType (context, arguments[1]) == kJSTypeString))) { + JSStringRef string = JSStringCreateWithUTF8CString("Username or Session incorrect"); + JSValueRef exceptionString = JSValueMakeString(context, string); + JSStringRelease(string); + *exception = JSValueToObject(context, exceptionString, NULL); + return JSValueMakeNull (context); + } arg = JSValueToStringCopy(context, arguments[0], NULL); username_size = JSStringGetMaximumUTF8CStringSize(arg); @@ -846,7 +880,13 @@ set_language_cb(JSContextRef context, size_t language_size; gchar *language; - // FIXME: Throw exception + if (!(argumentCount == 1 && JSValueGetType (context, arguments[0]) == kJSTypeString)) { + JSStringRef string = JSStringCreateWithUTF8CString("Language not supplied"); + JSValueRef exceptionString = JSValueMakeString(context, string); + JSStringRelease(string); + *exception = JSValueToObject(context, exceptionString, NULL); + return false; + } arg = JSValueToStringCopy(context, arguments[0], NULL); language_size = JSStringGetMaximumUTF8CStringSize(arg); @@ -872,8 +912,11 @@ gettext_cb(JSContextRef context, size_t string_size; gchar *string; - // FIXME: Throw exception - if (argumentCount != 1) { + if (!(argumentCount == 1 && JSValueGetType (context, arguments[0]) == kJSTypeString)) { + JSStringRef string = JSStringCreateWithUTF8CString("Argument not supplied"); + JSValueRef exceptionString = JSValueMakeString(context, string); + JSStringRelease(string); + *exception = JSValueToObject(context, exceptionString, NULL); return JSValueMakeNull(context); } @@ -901,8 +944,11 @@ ngettext_cb(JSContextRef context, gchar *string, *plural_string; unsigned int n; - // FIXME: Throw exception if (argumentCount != 3) { + JSStringRef string = JSStringCreateWithUTF8CString("Needs 3 arguments"); + JSValueRef exceptionString = JSValueMakeString(context, string); + JSStringRelease(string); + *exception = JSValueToObject(context, exceptionString, NULL); return JSValueMakeNull(context); } @@ -1126,8 +1172,6 @@ show_prompt_cb(LightDMGreeter *greeter, gchar *etext; const gchar *ct = ""; - g_debug("Show prompt %s", text); - web_page = webkit_web_extension_get_page(extension, page_id); if (web_page != NULL) { From 1f97b4034f29222c59dbfec06e798f2b60a30d08 Mon Sep 17 00:00:00 2001 From: Scott Balneaves Date: Mon, 4 Jan 2016 16:40:18 -0600 Subject: [PATCH 06/18] Added man page --- Makefile.am | 2 +- configure.ac | 1 + man/Makefile.am | 1 + man/lightdm-webkit2-greeter.1 | 110 ++++++++++++++++++++++++++++++++++ 4 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 man/Makefile.am create mode 100644 man/lightdm-webkit2-greeter.1 diff --git a/Makefile.am b/Makefile.am index 90cce03..b9f0de0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = data po src themes +SUBDIRS = data man po src themes DISTCLEANFILES = \ Makefile.in \ diff --git a/configure.ac b/configure.ac index 6fe8b31..6c255a1 100644 --- a/configure.ac +++ b/configure.ac @@ -108,6 +108,7 @@ dnl ########################################################################### AC_OUTPUT([ Makefile data/Makefile +man/Makefile src/Makefile po/Makefile.in themes/Makefile diff --git a/man/Makefile.am b/man/Makefile.am new file mode 100644 index 0000000..20005a7 --- /dev/null +++ b/man/Makefile.am @@ -0,0 +1 @@ +dist_man_MANS = lightdm-webkit2-greeter.1 diff --git a/man/lightdm-webkit2-greeter.1 b/man/lightdm-webkit2-greeter.1 new file mode 100644 index 0000000..f545ee6 --- /dev/null +++ b/man/lightdm-webkit2-greeter.1 @@ -0,0 +1,110 @@ +.TH "LIGHTDM" "1" "2015/11/14" +.nh +.ad l +.SH "NAME" +lightdm-webkit2-greeter \- Themeable greeter for LightDM which uses webkit2. +.SH "SYNOPSIS" +.HP \w'\fBlightdm-webkit2-greeter\fR\ 'u +\fBlightdm-webkit2-greeter\fR +.SH "DESCRIPTION" +.PP +lightdm-webkit2-greeter is a LightDM greeter that uses webkit2 as the theming +engine. Greeters can be written in a combination of HTML and Javascript\&. +.PP +.SH "API" +.PP +The following functions must be provided by the custom greeter, which LightDM +will call in the process of authenticating the user\&. +.PP +\fBshow_prompt(text, type)\fR +.RS 4 +This will be called when LightDM needs to prompt the user for some reason, such +as asking for a password\&. The "text" parameter will be the text of the +prompt, and the "type" parameter will either be "text" for a visible prompt, or +"password" for a prompt that the input should be hidden\&. +.RE +.PP +\fBshow_message(text, type)\fR +.RS 4 +This will be called when LightDM needs to display some info for the user\&. +The "text" parameter will be the text of the +message, and the "type" parameter will either be "info" for an information +message, or "error" for an error message that LightDM has encountered\&. +.RE +.PP +\fBauthentication_complete()\fR +.RS 4 +This function is called by LightDM when authentication has completed\&. +.RE +.PP +\fBautologin_timer_expired()\fR +.RS 4 +This function is called by LightDM when an autologin user's login timer has +expired. The greeter should reset the authentication process\&. +.RE +.PP +The following functions are available for the greeter to call to execute +actions within LightDM\&. +.PP +\fBlightdm.start_authentication(name)\fR +.RS 4 +Specifies the name of the user we'd like to start authenticating as\&. Note that +if you pass an empty string (""), LightDM (via PAM) will issue a show_prompt() +call to ask for the username\&. +.RE +.PP +\fBlightdm.respond(text)\fR +.RS 4 +When LightDM has prompted for input, provide the response to the input\&. +.RE +.PP +\fBlightdm.login(user, session)\fR +.RS 4 +Once LightDM has successfully authenticated the user, start the user's session +by calling this function\&. "user" is the authenticated user, and "session" is +the user's session\&. +.RE +.PP +Variables available within the greeter are: +.PP +\fBlightdm.authentication_user\fR +.RS 4 +The authenticated user\&. +.RE +.PP +\fBlightdm.default_session\fR +.RS 4 +The default session for the system\&. +.RE +.PP +\fBlightdm.is_authenticated\fR +.RS 4 +Indicates if the user has successfully authenticated\&. +.RE +.PP +Please see the LightDM API documentation for the complete list of calls +available. The lightdm-webkit2-greeter implements all of the LightDM API. +.PP +.SH "CONFIGURATION" +.PP +\fB/etc/lightdm/lightdm-webkit2-greeter.conf\fR +.RS 4 +Keyfile that contains one key: webkit-theme\&. This should point to which +theme the greeter should use. +.RE +.SH "FILES" +.PP +\fB/usr/share/lightdm-webkit/themes\fR +.RS 4 +Directory where themes should be stored\&. +.RE +.SH "EXAMPLES" +.PP +Please see the "simple" theme that is shipped with +lightdm-webkit2-greeter\&. +.SH "SEE ALSO" +.PP +http://people.ubuntu.com/~robert-ancell/lightdm/reference/core.html +.SH "AUTHOR" +.PP +lightdm-webkit-greeter was written by Robert Ancell \&. From 40b86cb688eeb5b9cce5d79f563bb3cddcca1066 Mon Sep 17 00:00:00 2001 From: Scott Balneaves Date: Mon, 4 Jan 2016 18:32:15 -0600 Subject: [PATCH 07/18] Implement the set_layout_cb function --- src/lightdm-webkit2-greeter-ext.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/lightdm-webkit2-greeter-ext.c b/src/lightdm-webkit2-greeter-ext.c index 5e74771..5c5d44f 100644 --- a/src/lightdm-webkit2-greeter-ext.c +++ b/src/lightdm-webkit2-greeter-ext.c @@ -468,6 +468,7 @@ set_layout_cb(JSContextRef context, JSStringRef layout_arg; size_t layout_size; gchar *layout; + const GList *layouts, *link; if (JSValueGetType(context, value) != kJSTypeString) { JSStringRef string = JSStringCreateWithUTF8CString("Expected a string"); @@ -483,7 +484,16 @@ set_layout_cb(JSContextRef context, JSStringGetUTF8CString(layout_arg, layout, layout_size); JSStringRelease(layout_arg); - //lightdm_set_layout (layout); + layouts = lightdm_get_layouts (); + for (link = layouts; link; link = link->next) + { + LightDMLayout *currlayout = link->data; + if (!(g_strcmp0(lightdm_layout_get_name(currlayout), layout))) { + g_object_ref (currlayout); + lightdm_set_layout (currlayout); + break; + } + } g_free (layout); return true; @@ -1009,7 +1019,7 @@ static const JSStaticValue lightdm_greeter_values[] = { {"languages", get_languages_cb, NULL, kJSPropertyAttributeReadOnly}, {"default_layout", get_default_layout_cb, NULL, kJSPropertyAttributeReadOnly}, {"layouts", get_layouts_cb, NULL, kJSPropertyAttributeReadOnly}, - {"layout", get_layout_cb, set_layout_cb, kJSPropertyAttributeReadOnly}, + {"layout", get_layout_cb, set_layout_cb, kJSPropertyAttributeNone}, {"sessions", get_sessions_cb, NULL, kJSPropertyAttributeReadOnly}, {"num_users", get_num_users_cb, NULL, kJSPropertyAttributeReadOnly}, {"default_session", get_default_session_cb, NULL, kJSPropertyAttributeNone}, From 5c32caa4ff52ac214c35eb66ced454719ddd633e Mon Sep 17 00:00:00 2001 From: Scott Balneaves Date: Mon, 4 Jan 2016 18:35:11 -0600 Subject: [PATCH 08/18] Update manpage --- man/lightdm-webkit2-greeter.1 | 1 + 1 file changed, 1 insertion(+) diff --git a/man/lightdm-webkit2-greeter.1 b/man/lightdm-webkit2-greeter.1 index f545ee6..bbdff2d 100644 --- a/man/lightdm-webkit2-greeter.1 +++ b/man/lightdm-webkit2-greeter.1 @@ -108,3 +108,4 @@ http://people.ubuntu.com/~robert-ancell/lightdm/reference/core.html .SH "AUTHOR" .PP lightdm-webkit-greeter was written by Robert Ancell \&. +lightdm-webkit2-greeter was ported to webkit2 by Dustin Falgout \&. From a0b7aac6b7f39876d444b71a495ebed695f79eff Mon Sep 17 00:00:00 2001 From: Scott Balneaves Date: Mon, 4 Jan 2016 18:48:56 -0600 Subject: [PATCH 09/18] Add test for exo-csource binary, needed for compile --- configure.ac | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/configure.ac b/configure.ac index 6c255a1..835056e 100644 --- a/configure.ac +++ b/configure.ac @@ -34,6 +34,13 @@ PKG_CHECK_MODULES([WEB_EXTENSION], [webkit2gtk-web-extension-4.0 >= 2.8.0]) AC_SUBST([WEB_EXTENSION_CFLAGS]) AC_SUBST([WEB_EXTENSION_LIBS]) +# Check for exo-csource +AC_DEFUN([AC_PROG_EXOCSOURCE], [AC_CHECK_PROG(EXOCSOURCE,exo-csource,yes)]) +AC_PROG_EXOCSOURCE +if test x"${EXOCSOURCE}" != x"yes" ; then + AC_MSG_ERROR([Please install the package containing the exo-csource binary.]) +fi + dnl ########################################################################### dnl Configurable values dnl ########################################################################### From 044fa942c1474a6f89dfebed9edff42f5b1e5daf Mon Sep 17 00:00:00 2001 From: Scott Balneaves Date: Tue, 5 Jan 2016 09:46:57 -0600 Subject: [PATCH 10/18] Don't hardcode the config dir, instead, use the config.h supplied value. --- src/lightdm-webkit2-greeter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lightdm-webkit2-greeter.c b/src/lightdm-webkit2-greeter.c index 2437503..eac9f62 100644 --- a/src/lightdm-webkit2-greeter.c +++ b/src/lightdm-webkit2-greeter.c @@ -190,7 +190,7 @@ main(int argc, char **argv) { // Apply greeter settings from conf file keyfile = g_key_file_new(); - g_key_file_load_from_file(keyfile, "/etc/lightdm/lightdm-webkit2-greeter.conf", G_KEY_FILE_NONE, NULL); + g_key_file_load_from_file(keyfile, CONFIG_DIR "/lightdm-webkit2-greeter.conf", G_KEY_FILE_NONE, NULL); theme = g_key_file_get_string(keyfile, "greeter", "webkit-theme", NULL); config_timeout = g_key_file_get_integer(keyfile, "greeter", "screensaver-timeout", NULL); From 8089f50e2265c089a4a0d958b660ae12c1f2d4c9 Mon Sep 17 00:00:00 2001 From: Scott Balneaves Date: Wed, 6 Jan 2016 10:29:39 -0600 Subject: [PATCH 11/18] added back in antergos theme as a submodule --- .gitmodules | 3 +++ configure.ac | 10 ++++++++++ themes/Makefile.am | 2 +- themes/antergos | 1 + 4 files changed, 15 insertions(+), 1 deletion(-) create mode 160000 themes/antergos diff --git a/.gitmodules b/.gitmodules index e9e813c..2fe7a07 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "themes/antergos"] path = themes/antergos url = http://github.com/antergos/lightdm-webkit-theme-antergos.git +[submodule "themes/lightdm-webkit-theme-antergos"] + path = themes/lightdm-webkit-theme-antergos + url = http://github.com/antergos/lightdm-webkit-theme-antergos.git diff --git a/configure.ac b/configure.ac index 835056e..2ea5f74 100644 --- a/configure.ac +++ b/configure.ac @@ -119,6 +119,16 @@ man/Makefile src/Makefile po/Makefile.in themes/Makefile +themes/antergos/css/vendor/Makefile +themes/antergos/css/Makefile +themes/antergos/Makefile +themes/antergos/fonts/Makefile +themes/antergos/fonts/font-awesome/Makefile +themes/antergos/fonts/TTF/Makefile +themes/antergos/js/vendor/Makefile +themes/antergos/js/Makefile +themes/antergos/img/Makefile +themes/antergos/img/thumbs/Makefile themes/simple/Makefile ]) diff --git a/themes/Makefile.am b/themes/Makefile.am index 5f9a897..4693388 100644 --- a/themes/Makefile.am +++ b/themes/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = simple +SUBDIRS = antergos simple DISTCLEANFILES = \ Makefile.in diff --git a/themes/antergos b/themes/antergos new file mode 160000 index 0000000..80fbe54 --- /dev/null +++ b/themes/antergos @@ -0,0 +1 @@ +Subproject commit 80fbe54f4b04fa3e6e8511db3d93ddc921045c9b From 9dea4c3af15387b14a60df119828360dfc7e0cf9 Mon Sep 17 00:00:00 2001 From: Scott Balneaves Date: Wed, 6 Jan 2016 20:55:43 -0600 Subject: [PATCH 12/18] Provide backwards compatibility for provide_secret callback --- src/lightdm-webkit2-greeter-ext.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lightdm-webkit2-greeter-ext.c b/src/lightdm-webkit2-greeter-ext.c index 5c5d44f..96d5348 100644 --- a/src/lightdm-webkit2-greeter-ext.c +++ b/src/lightdm-webkit2-greeter-ext.c @@ -1039,6 +1039,7 @@ static const JSStaticFunction lightdm_greeter_functions[] = { {"cancel_timed_login", cancel_timed_login_cb, kJSPropertyAttributeReadOnly}, {"start_authentication", start_authentication_cb, kJSPropertyAttributeReadOnly}, {"respond", respond_cb, kJSPropertyAttributeReadOnly}, + {"provide_secret", respond_cb, kJSPropertyAttributeReadOnly}, /* Deprecated */ {"cancel_authentication", cancel_authentication_cb, kJSPropertyAttributeReadOnly}, {"suspend", suspend_cb, kJSPropertyAttributeReadOnly}, {"hibernate", hibernate_cb, kJSPropertyAttributeReadOnly}, From 17ff86f2da14ad6408a143ae6294cfabea17640d Mon Sep 17 00:00:00 2001 From: Scott Balneaves Date: Thu, 7 Jan 2016 09:21:16 -0600 Subject: [PATCH 13/18] Since default_session has no settor, only a gettor, no reason it shouldn't be marked ReadOnly --- src/lightdm-webkit2-greeter-ext.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lightdm-webkit2-greeter-ext.c b/src/lightdm-webkit2-greeter-ext.c index 96d5348..7dcae64 100644 --- a/src/lightdm-webkit2-greeter-ext.c +++ b/src/lightdm-webkit2-greeter-ext.c @@ -1022,7 +1022,7 @@ static const JSStaticValue lightdm_greeter_values[] = { {"layout", get_layout_cb, set_layout_cb, kJSPropertyAttributeNone}, {"sessions", get_sessions_cb, NULL, kJSPropertyAttributeReadOnly}, {"num_users", get_num_users_cb, NULL, kJSPropertyAttributeReadOnly}, - {"default_session", get_default_session_cb, NULL, kJSPropertyAttributeNone}, + {"default_session", get_default_session_cb, NULL, kJSPropertyAttributeReadOnly}, {"timed_login_user", get_timed_login_user_cb, NULL, kJSPropertyAttributeReadOnly}, {"timed_login_delay", get_timed_login_delay_cb, NULL, kJSPropertyAttributeReadOnly}, {"authentication_user", get_authentication_user_cb, NULL, kJSPropertyAttributeReadOnly}, From 9917b44d63bfb0f11fcba6afbb7d52b52987aa88 Mon Sep 17 00:00:00 2001 From: Scott Balneaves Date: Thu, 7 Jan 2016 10:13:48 -0600 Subject: [PATCH 14/18] Improve manpage significantly --- man/lightdm-webkit2-greeter.1 | 163 +++++++++++++++++++++++++++++----- 1 file changed, 139 insertions(+), 24 deletions(-) diff --git a/man/lightdm-webkit2-greeter.1 b/man/lightdm-webkit2-greeter.1 index bbdff2d..5d0c837 100644 --- a/man/lightdm-webkit2-greeter.1 +++ b/man/lightdm-webkit2-greeter.1 @@ -2,18 +2,18 @@ .nh .ad l .SH "NAME" -lightdm-webkit2-greeter \- Themeable greeter for LightDM which uses webkit2. +lightdm-webkit2-greeter \- Themeable greeter for LightDM which uses webkit2\&. .SH "SYNOPSIS" .HP \w'\fBlightdm-webkit2-greeter\fR\ 'u \fBlightdm-webkit2-greeter\fR .SH "DESCRIPTION" .PP lightdm-webkit2-greeter is a LightDM greeter that uses webkit2 as the theming -engine. Greeters can be written in a combination of HTML and Javascript\&. +engine\&. Greeters can be written in a combination of HTML and Javascript\&. .PP .SH "API" .PP -The following functions must be provided by the custom greeter, which LightDM +The following functions \fBmust\fR be provided by the custom greeter, which LightDM will call in the process of authenticating the user\&. .PP \fBshow_prompt(text, type)\fR @@ -40,72 +40,187 @@ This function is called by LightDM when authentication has completed\&. \fBautologin_timer_expired()\fR .RS 4 This function is called by LightDM when an autologin user's login timer has -expired. The greeter should reset the authentication process\&. +expired\&. The greeter should reset the authentication process\&. .RE .PP The following functions are available for the greeter to call to execute actions within LightDM\&. .PP -\fBlightdm.start_authentication(name)\fR +\fBlightdm\&.cancel_authentication()\fR .RS 4 -Specifies the name of the user we'd like to start authenticating as\&. Note that -if you pass an empty string (""), LightDM (via PAM) will issue a show_prompt() -call to ask for the username\&. +Cancels the authentication of any user currently in the process of +authenticating\&. .RE .PP -\fBlightdm.respond(text)\fR +\fBlightdm\&.cancel_timed_login()\fR .RS 4 -When LightDM has prompted for input, provide the response to the input\&. +Cancels the authentication of the timed login user\&. .RE .PP -\fBlightdm.login(user, session)\fR +\fBlightdm\&.hibernate()\fR +.RS 4 +Hibernates the system, if the greeter has the authority to do so\&. +.RE +.PP +\fBlightdm\&.login(user, session)\fR .RS 4 Once LightDM has successfully authenticated the user, start the user's session by calling this function\&. "user" is the authenticated user, and "session" is the user's session\&. .RE .PP +\fBlightdm\&.respond(text)\fR +.RS 4 +When LightDM has prompted for input, provide the response to LightDM\&. +The deprecated function was "provide_secret"\&. This is still available for +backwards compatibility, but authors of greeters should move to using +lightdm.respond()\&. +.RE +.PP +\fBlightdm\&.restart()\fR +.RS 4 +Restarts the system, if the greeter has the authority to do so\&. +.RE +.PP +\fBlightdm\&.set_language(lang)\fR +.RS 4 +Will set the language for the current LightDM session\&. +.RE +.PP +\fBlightdm\&.shutdown()\fR +.RS 4 +Shuts down the system, if the greeter has the authority to do so\&. +.RE +.PP +\fBlightdm\&.start_authentication(name)\fR +.RS 4 +Specifies the name of the user we'd like to start authenticating as\&. Note that +if you pass an empty string (""), LightDM (via PAM) will issue a show_prompt() +call to ask for the username\&. +.RE +.PP Variables available within the greeter are: .PP -\fBlightdm.authentication_user\fR +\fBlightdm\&.authentication_user\fR +.RS 4 +String\&. The username of the authentication user being authenticated or null if no +authentication is in progress\&. +.RE +.PP +\fBlightdm\&.can_hibernate\fR +.RS 4 +Boolean\&. Whether or not the system can be made to hibernate by the greeter\&. +.RE +.PP +\fBlightdm\&.can_restart\fR +.RS 4 +Boolean\&. Whether or not the system can be restarted by the greeter\&. +.RE +.PP +\fBlightdm\&.can_shutdown\fR +.RS 4 +Boolean\&. Whether or not the system can be shutdown by the greeter\&. +.RE +.PP +\fBlightdm\&.can_suspend\fR +.RS 4 +Boolean\&. Whether or not the system can be suspended by the greeter\&. +.RE +.PP +\fBlightdm\&.default_language\fR +.RS 4 +String\&. The current language (system-wide)\&. +.RE +.PP +\fBlightdm\&.default_layout\fR +.RS 4 +String\&. The current keyboard layout (system-wide)\&. +.RE +.PP +\fBlightdm\&.default_session\fR +.RS 4 +String\&. The name of the default session (as configured in lightdm.conf)\&. +.RE +.PP +\fBlightdm\&.hostname\fR +.RS 4 +String\&. The hostname of the system\&. +.RE +.PP +\fBlightdm\&.is_authenticated\fR +.RS 4 +Boolean\&. Indicates if the user has successfully authenticated\&. +.RE +.PP +\fBlightdm\&.in_authentication\fR +.RS 4 +Boolean\&. Indicates if lightdm is currently in the authentication phase\&. +.RE +.PP +\fBlightdm\&.layout\fR +.RS 4 +String\&. The name of the currently active keyboard layout\&. To change the +layout, assign a valid layout name to this variable\&. +.RE +.PP +\fBlightdm\&.layouts\fR +.RS 4 +Array\&. The keyboard layouts that are available on the system\&. Returns an Array +of LightDMLayout objects\&. +.RE +.PP +\fBlightdm\&.num_users\fR +.RS 4 +Number\&. The number of users able to log in\&. +.RE +.PP +\fBlightdm\&.sessions\fR +.RS 4 +Array\&. The sessions that are available on the system\&. Returns an Array of +LightDMSession objects\&. +.RE +.PP +\fBlightdm\&.timed_login_delay\fR .RS 4 -The authenticated user\&. +Number\&. The number of seconds to wait before automatically logging in\&. .RE .PP -\fBlightdm.default_session\fR +\fBlightdm\&.timed_login_user\fR .RS 4 -The default session for the system\&. +String\&. The name of the user account that should be logged into +automatically after timed login delay has passed\&. .RE .PP -\fBlightdm.is_authenticated\fR +\fBlightdm\&.users\fR .RS 4 -Indicates if the user has successfully authenticated\&. +Array\&. The users that are able to log in\&. Returns an Array of LightDMUser +objects\&. .RE .PP Please see the LightDM API documentation for the complete list of calls -available. The lightdm-webkit2-greeter implements all of the LightDM API. +available\&. The lightdm-webkit2-greeter implements all of the LightDM API\&. .PP .SH "CONFIGURATION" .PP -\fB/etc/lightdm/lightdm-webkit2-greeter.conf\fR +\fB/etc/lightdm/lightdm-webkit2-greeter\&.conf\fR .RS 4 Keyfile that contains one key: webkit-theme\&. This should point to which -theme the greeter should use. +theme the greeter should use\&. .RE .SH "FILES" .PP -\fB/usr/share/lightdm-webkit/themes\fR +\fB/usr/share/lightdm-webkit-themes\fR .RS 4 Directory where themes should be stored\&. .RE .SH "EXAMPLES" .PP -Please see the "simple" theme that is shipped with +Please see the "antergos" and "simple" themes that are shipped with lightdm-webkit2-greeter\&. .SH "SEE ALSO" .PP -http://people.ubuntu.com/~robert-ancell/lightdm/reference/core.html +http://people\&.ubuntu\&.com/~robert-ancell/lightdm/reference/core\&.html .SH "AUTHOR" .PP -lightdm-webkit-greeter was written by Robert Ancell \&. +lightdm-webkit-greeter was written by Robert Ancell \&. lightdm-webkit2-greeter was ported to webkit2 by Dustin Falgout \&. From d644eea63a920fe8177dd1741b2192783ff51226 Mon Sep 17 00:00:00 2001 From: Scott Balneaves Date: Thu, 7 Jan 2016 15:12:17 -0600 Subject: [PATCH 15/18] API upgrade; complete API including the guest functions, bring API completely in line with LightDM API --- src/lightdm-webkit2-greeter-ext.c | 296 ++++++++++++++++++------------ themes/simple/index.html | 4 +- 2 files changed, 177 insertions(+), 123 deletions(-) diff --git a/src/lightdm-webkit2-greeter-ext.c b/src/lightdm-webkit2-greeter-ext.c index 7dcae64..74b3b34 100644 --- a/src/lightdm-webkit2-greeter-ext.c +++ b/src/lightdm-webkit2-greeter-ext.c @@ -90,10 +90,8 @@ get_user_name_cb(JSContextRef context, JSStringRef propertyName, JSValueRef *exception) { LightDMUser *user = JSObjectGetPrivate(thisObject); - JSStringRef string; - string = JSStringCreateWithUTF8CString(lightdm_user_get_name(user)); - return JSValueMakeString(context, string); + return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_user_get_name(user))); } @@ -103,10 +101,8 @@ get_user_real_name_cb(JSContextRef context, JSStringRef propertyName, JSValueRef *exception) { LightDMUser *user = JSObjectGetPrivate(thisObject); - JSStringRef string; - string = JSStringCreateWithUTF8CString(lightdm_user_get_real_name(user)); - return JSValueMakeString(context, string); + return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_user_get_real_name(user))); } @@ -116,23 +112,29 @@ get_user_display_name_cb(JSContextRef context, JSStringRef propertyName, JSValueRef *exception) { LightDMUser *user = JSObjectGetPrivate(thisObject); - JSStringRef string; - string = JSStringCreateWithUTF8CString(lightdm_user_get_display_name(user)); - return JSValueMakeString(context, string); + return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_user_get_display_name(user))); } +static JSValueRef +get_user_home_directory_cb(JSContextRef context, + JSObjectRef thisObject, + JSStringRef propertyName, + JSValueRef *exception) { + LightDMUser *user = JSObjectGetPrivate(thisObject); + + return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_user_get_home_directory(user))); +} + static JSValueRef get_user_image_cb(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef *exception) { LightDMUser *user = JSObjectGetPrivate(thisObject); - JSStringRef string; - string = JSStringCreateWithUTF8CString(lightdm_user_get_image(user)); - return JSValueMakeString(context, string); + return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_user_get_image(user))); } @@ -143,14 +145,12 @@ get_user_language_cb(JSContextRef context, JSValueRef *exception) { LightDMUser *user = JSObjectGetPrivate(thisObject); const gchar *language = lightdm_user_get_language(user); - JSStringRef string; if (!language) { return JSValueMakeNull(context); } - string = JSStringCreateWithUTF8CString(language); - return JSValueMakeString(context, string); + return JSValueMakeString(context, JSStringCreateWithUTF8CString(language)); } @@ -161,14 +161,12 @@ get_user_layout_cb(JSContextRef context, JSValueRef *exception) { LightDMUser *user = JSObjectGetPrivate(thisObject); const gchar *layout = lightdm_user_get_layout(user); - JSStringRef string; if (!layout) { return JSValueMakeNull(context); } - string = JSStringCreateWithUTF8CString(layout); - return JSValueMakeString(context, string); + return JSValueMakeString(context, JSStringCreateWithUTF8CString(layout)); } @@ -179,14 +177,12 @@ get_user_session_cb(JSContextRef context, JSValueRef *exception) { LightDMUser *user = JSObjectGetPrivate(thisObject); const gchar *session = lightdm_user_get_session(user); - JSStringRef string; if (!session) { return JSValueMakeNull(context); } - string = JSStringCreateWithUTF8CString(session); - return JSValueMakeString(context, string); + return JSValueMakeString(context, JSStringCreateWithUTF8CString(session)); } @@ -206,10 +202,8 @@ get_language_code_cb(JSContextRef context, JSStringRef propertyName, JSValueRef *exception) { LightDMLanguage *language = JSObjectGetPrivate(thisObject); - JSStringRef string; - string = JSStringCreateWithUTF8CString(lightdm_language_get_code(language)); - return JSValueMakeString(context, string); + return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_language_get_code(language))); } @@ -219,10 +213,8 @@ get_language_name_cb(JSContextRef context, JSStringRef propertyName, JSValueRef *exception) { LightDMLanguage *language = JSObjectGetPrivate(thisObject); - JSStringRef string; - string = JSStringCreateWithUTF8CString(lightdm_language_get_name(language)); - return JSValueMakeString(context, string); + return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_language_get_name(language))); } @@ -232,10 +224,8 @@ get_language_territory_cb(JSContextRef context, JSStringRef propertyName, JSValueRef *exception) { LightDMLanguage *language = JSObjectGetPrivate(thisObject); - JSStringRef string; - string = JSStringCreateWithUTF8CString(lightdm_language_get_territory(language)); - return JSValueMakeString(context, string); + return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_language_get_territory(language))); } @@ -245,10 +235,8 @@ get_layout_name_cb(JSContextRef context, JSStringRef propertyName, JSValueRef *exception) { LightDMLayout *layout = JSObjectGetPrivate(thisObject); - JSStringRef string; - string = JSStringCreateWithUTF8CString(lightdm_layout_get_name(layout)); - return JSValueMakeString(context, string); + return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_layout_get_name(layout))); } @@ -258,10 +246,8 @@ get_layout_short_description_cb(JSContextRef context, JSStringRef propertyName, JSValueRef *exception) { LightDMLayout *layout = JSObjectGetPrivate(thisObject); - JSStringRef string; - string = JSStringCreateWithUTF8CString(lightdm_layout_get_short_description(layout)); - return JSValueMakeString(context, string); + return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_layout_get_short_description(layout))); } @@ -271,10 +257,8 @@ get_layout_description_cb(JSContextRef context, JSStringRef propertyName, JSValueRef *exception) { LightDMLayout *layout = JSObjectGetPrivate(thisObject); - JSStringRef string; - string = JSStringCreateWithUTF8CString(lightdm_layout_get_description(layout)); - return JSValueMakeString(context, string); + return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_layout_get_description(layout))); } @@ -284,11 +268,8 @@ get_session_key_cb(JSContextRef context, JSStringRef propertyName, JSValueRef *exception) { LightDMSession *session = JSObjectGetPrivate(thisObject); - JSStringRef string; - - string = JSStringCreateWithUTF8CString(lightdm_session_get_key(session)); - return JSValueMakeString(context, string); + return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_session_get_key(session))); } @@ -298,10 +279,8 @@ get_session_name_cb(JSContextRef context, JSStringRef propertyName, JSValueRef *exception) { LightDMSession *session = JSObjectGetPrivate(thisObject); - JSStringRef string; - string = JSStringCreateWithUTF8CString(lightdm_session_get_name(session)); - return JSValueMakeString(context, string); + return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_session_get_name(session))); } @@ -311,10 +290,8 @@ get_session_comment_cb(JSContextRef context, JSStringRef propertyName, JSValueRef *exception) { LightDMSession *session = JSObjectGetPrivate(thisObject); - JSStringRef string; - string = JSStringCreateWithUTF8CString(lightdm_session_get_comment(session)); - return JSValueMakeString(context, string); + return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_session_get_comment(session))); } @@ -323,11 +300,7 @@ get_hostname_cb(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef *exception) { - JSStringRef string; - - string = JSStringCreateWithUTF8CString(lightdm_get_hostname()); - - return JSValueMakeString(context, string); + return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_get_hostname())); } @@ -394,31 +367,13 @@ get_languages_cb(JSContextRef context, static JSValueRef -get_default_language_cb(JSContextRef context, +get_language_cb(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef *exception) { - JSStringRef string; - - string = JSStringCreateWithUTF8CString(lightdm_language_get_name((LightDMLanguage *) lightdm_get_language())); - - return JSValueMakeString(context, string); + return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_language_get_name((LightDMLanguage *) lightdm_get_language()))); } - -static JSValueRef -get_default_layout_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - JSStringRef string; - - string = JSStringCreateWithUTF8CString(lightdm_layout_get_name(lightdm_get_layout())); - - return JSValueMakeString(context, string); -} - - static JSValueRef get_layouts_cb(JSContextRef context, JSObjectRef thisObject, @@ -450,12 +405,7 @@ get_layout_cb(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef *exception) { - - JSStringRef string; - - string = JSStringCreateWithUTF8CString(lightdm_layout_get_name(lightdm_get_layout())); - - return JSValueMakeString(context, string); + return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_layout_get_name(lightdm_get_layout()))); } @@ -531,25 +481,8 @@ get_default_session_cb(JSContextRef context, JSStringRef propertyName, JSValueRef *exception) { LightDMGreeter *greeter = JSObjectGetPrivate(thisObject); - JSStringRef string; - string = JSStringCreateWithUTF8CString(lightdm_greeter_get_default_session_hint(greeter)); - - return JSValueMakeString(context, string); -} - - -static JSValueRef -get_timed_login_user_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - LightDMGreeter *greeter = JSObjectGetPrivate(thisObject); - JSStringRef string; - - string = JSStringCreateWithUTF8CString(lightdm_greeter_get_autologin_user_hint(greeter)); - - return JSValueMakeString(context, string); + return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_greeter_get_default_session_hint(greeter))); } @@ -565,20 +498,18 @@ get_lock_hint_cb(JSContextRef context, static JSValueRef -get_timed_login_delay_cb(JSContextRef context, +get_autologin_timeout_cb(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef *exception) { LightDMGreeter *greeter = JSObjectGetPrivate(thisObject); - gint delay; - delay = lightdm_greeter_get_autologin_timeout_hint(greeter); - return JSValueMakeNumber(context, delay); + return JSValueMakeNumber(context, lightdm_greeter_get_autologin_timeout_hint(greeter)); } static JSValueRef -cancel_timed_login_cb(JSContextRef context, +cancel_autologin_cb(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, @@ -600,7 +531,7 @@ cancel_timed_login_cb(JSContextRef context, static JSValueRef -start_authentication_cb(JSContextRef context, +authenticate_cb(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, @@ -634,6 +565,62 @@ start_authentication_cb(JSContextRef context, return JSValueMakeNull(context); } +static JSValueRef +authenticate_as_guest_cb (JSContextRef context, + JSObjectRef function, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef * exception) { + LightDMGreeter *greeter = JSObjectGetPrivate (thisObject); + + if (argumentCount != 0) { + JSStringRef string = JSStringCreateWithUTF8CString ("Argument count not zero"); + JSValueRef exceptionString = JSValueMakeString (context, string); + JSStringRelease (string); + *exception = JSValueToObject (context, exceptionString, NULL); + return JSValueMakeNull (context); + } + + lightdm_greeter_authenticate_as_guest (greeter); + + return JSValueMakeNull (context); +} + +static JSValueRef +get_hint_cb (JSContextRef context, + JSObjectRef function, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef * exception) { + LightDMGreeter *greeter = JSObjectGetPrivate (thisObject); + JSStringRef hint_arg; + size_t hint_size; + gchar *hint_name; + JSStringRef hint; + + if (!(argumentCount == 1 && JSValueGetType (context, arguments[0]) == kJSTypeString)) { + JSStringRef string = JSStringCreateWithUTF8CString ("Hint argument not supplied"); + JSValueRef exceptionString = JSValueMakeString (context, string); + JSStringRelease (string); + *exception = JSValueToObject (context, exceptionString, NULL); + return JSValueMakeNull (context); + } + + hint_arg = JSValueToStringCopy (context, arguments[0], NULL); + hint_size = JSStringGetMaximumUTF8CStringSize (hint_arg); + hint_name = g_malloc (hint_size); + JSStringGetUTF8CString (hint_arg, hint_name, hint_size); + JSStringRelease (hint_arg); + + hint = JSStringCreateWithUTF8CString (lightdm_greeter_get_hint (greeter, hint_name)); + + g_free (hint_name); + + return JSValueMakeString (context, hint); +} + static JSValueRef respond_cb(JSContextRef context, @@ -699,6 +686,59 @@ get_authentication_user_cb(JSContextRef context, return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_greeter_get_authentication_user(greeter))); } +static JSValueRef +get_has_guest_account_cb (JSContextRef context, + JSObjectRef thisObject, + JSStringRef propertyName, + JSValueRef * exception) { + LightDMGreeter *greeter = JSObjectGetPrivate (thisObject); + return JSValueMakeBoolean (context, lightdm_greeter_get_has_guest_account_hint (greeter)); +} + +static JSValueRef +get_hide_users_cb (JSContextRef context, + JSObjectRef thisObject, + JSStringRef propertyName, + JSValueRef * exception) { + LightDMGreeter *greeter = JSObjectGetPrivate (thisObject); + return JSValueMakeBoolean (context, lightdm_greeter_get_hide_users_hint (greeter)); +} + +static JSValueRef +get_select_user_cb (JSContextRef context, + JSObjectRef thisObject, + JSStringRef propertyName, + JSValueRef * exception) { + LightDMGreeter *greeter = JSObjectGetPrivate (thisObject); + return JSValueMakeString (context, JSStringCreateWithUTF8CString (lightdm_greeter_get_select_user_hint (greeter))); +} + +static JSValueRef +get_select_guest_cb (JSContextRef context, + JSObjectRef thisObject, + JSStringRef propertyName, + JSValueRef * exception) { + LightDMGreeter *greeter = JSObjectGetPrivate (thisObject); + return JSValueMakeBoolean (context, lightdm_greeter_get_select_guest_hint (greeter)); +} + +static JSValueRef +get_autologin_user_cb (JSContextRef context, + JSObjectRef thisObject, + JSStringRef propertyName, + JSValueRef * exception) { + LightDMGreeter *greeter = JSObjectGetPrivate (thisObject); + return JSValueMakeString (context, JSStringCreateWithUTF8CString (lightdm_greeter_get_autologin_user_hint (greeter))); +} + +static JSValueRef +get_autologin_guest_cb (JSContextRef context, + JSObjectRef thisObject, + JSStringRef propertyName, + JSValueRef * exception) { + LightDMGreeter *greeter = JSObjectGetPrivate (thisObject); + return JSValueMakeBoolean (context, lightdm_greeter_get_autologin_guest_hint (greeter)); +} static JSValueRef get_is_authenticated_cb(JSContextRef context, @@ -835,7 +875,7 @@ shutdown_cb(JSContextRef context, static JSValueRef -login_cb(JSContextRef context, +start_session_sync_cb(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, @@ -984,15 +1024,16 @@ ngettext_cb(JSContextRef context, static const JSStaticValue lightdm_user_values[] = { - {"name", get_user_name_cb, NULL, kJSPropertyAttributeReadOnly}, - {"real_name", get_user_real_name_cb, NULL, kJSPropertyAttributeReadOnly}, - {"display_name", get_user_display_name_cb, NULL, kJSPropertyAttributeReadOnly}, - {"image", get_user_image_cb, NULL, kJSPropertyAttributeReadOnly}, - {"language", get_user_language_cb, NULL, kJSPropertyAttributeReadOnly}, - {"layout", get_user_layout_cb, NULL, kJSPropertyAttributeReadOnly}, - {"session", get_user_session_cb, NULL, kJSPropertyAttributeReadOnly}, - {"logged_in", get_user_logged_in_cb, NULL, kJSPropertyAttributeReadOnly}, - {NULL, NULL, NULL, 0}}; + {"name", get_user_name_cb, NULL, kJSPropertyAttributeReadOnly}, + {"real_name", get_user_real_name_cb, NULL, kJSPropertyAttributeReadOnly}, + {"display_name", get_user_display_name_cb, NULL, kJSPropertyAttributeReadOnly}, + {"home_directory", get_user_home_directory_cb, NULL, kJSPropertyAttributeReadOnly}, + {"image", get_user_image_cb, NULL, kJSPropertyAttributeReadOnly}, + {"language", get_user_language_cb, NULL, kJSPropertyAttributeReadOnly}, + {"layout", get_user_layout_cb, NULL, kJSPropertyAttributeReadOnly}, + {"session", get_user_session_cb, NULL, kJSPropertyAttributeReadOnly}, + {"logged_in", get_user_logged_in_cb, NULL, kJSPropertyAttributeReadOnly}, + {NULL, NULL, NULL, 0}}; static const JSStaticValue lightdm_language_values[] = { {"code", get_language_code_cb, NULL, kJSPropertyAttributeReadOnly}, @@ -1015,16 +1056,17 @@ static const JSStaticValue lightdm_session_values[] = { static const JSStaticValue lightdm_greeter_values[] = { {"hostname", get_hostname_cb, NULL, kJSPropertyAttributeReadOnly}, {"users", get_users_cb, NULL, kJSPropertyAttributeReadOnly}, - {"default_language", get_default_language_cb, NULL, kJSPropertyAttributeReadOnly}, + {"default_language", get_language_cb, NULL, kJSPropertyAttributeReadOnly}, /* Deprecated */ + {"language", get_language_cb, NULL, kJSPropertyAttributeReadOnly}, {"languages", get_languages_cb, NULL, kJSPropertyAttributeReadOnly}, - {"default_layout", get_default_layout_cb, NULL, kJSPropertyAttributeReadOnly}, + {"default_layout", get_layout_cb, NULL, kJSPropertyAttributeReadOnly}, /* Deprecated */ {"layouts", get_layouts_cb, NULL, kJSPropertyAttributeReadOnly}, {"layout", get_layout_cb, set_layout_cb, kJSPropertyAttributeNone}, {"sessions", get_sessions_cb, NULL, kJSPropertyAttributeReadOnly}, {"num_users", get_num_users_cb, NULL, kJSPropertyAttributeReadOnly}, {"default_session", get_default_session_cb, NULL, kJSPropertyAttributeReadOnly}, - {"timed_login_user", get_timed_login_user_cb, NULL, kJSPropertyAttributeReadOnly}, - {"timed_login_delay", get_timed_login_delay_cb, NULL, kJSPropertyAttributeReadOnly}, + {"timed_login_user", get_autologin_user_cb, NULL, kJSPropertyAttributeReadOnly}, /* Deprecated */ + {"timed_login_delay", get_autologin_timeout_cb, NULL, kJSPropertyAttributeReadOnly}, /* Deprecated */ {"authentication_user", get_authentication_user_cb, NULL, kJSPropertyAttributeReadOnly}, {"in_authentication", get_in_authentication_cb, NULL, kJSPropertyAttributeReadOnly}, {"is_authenticated", get_is_authenticated_cb, NULL, kJSPropertyAttributeReadOnly}, @@ -1033,11 +1075,21 @@ static const JSStaticValue lightdm_greeter_values[] = { {"can_restart", get_can_restart_cb, NULL, kJSPropertyAttributeReadOnly}, {"can_shutdown", get_can_shutdown_cb, NULL, kJSPropertyAttributeReadOnly}, {"lock_hint", get_lock_hint_cb, NULL, kJSPropertyAttributeReadOnly}, + {"has_guest_account", get_has_guest_account_cb, NULL, kJSPropertyAttributeReadOnly}, + {"hide_users", get_hide_users_cb, NULL, kJSPropertyAttributeReadOnly}, + {"select_user", get_select_user_cb, NULL, kJSPropertyAttributeReadOnly}, + {"select_guest", get_select_guest_cb, NULL, kJSPropertyAttributeReadOnly}, + {"autologin_user", get_autologin_user_cb, NULL, kJSPropertyAttributeReadOnly}, + {"autologin_guest", get_autologin_guest_cb, NULL, kJSPropertyAttributeReadOnly}, + {"autologin_timeout", get_autologin_timeout_cb, NULL, kJSPropertyAttributeReadOnly}, {NULL, NULL, NULL, 0}}; static const JSStaticFunction lightdm_greeter_functions[] = { - {"cancel_timed_login", cancel_timed_login_cb, kJSPropertyAttributeReadOnly}, - {"start_authentication", start_authentication_cb, kJSPropertyAttributeReadOnly}, + {"cancel_timed_login", cancel_autologin_cb, kJSPropertyAttributeReadOnly}, /* Deprecated */ + {"cancel_autologin", cancel_autologin_cb, kJSPropertyAttributeReadOnly}, + {"start_authentication", authenticate_cb, kJSPropertyAttributeReadOnly}, /* Deprecated */ + {"authenticate", authenticate_cb, kJSPropertyAttributeReadOnly}, + {"authenticate_as_guest", authenticate_as_guest_cb, kJSPropertyAttributeReadOnly}, {"respond", respond_cb, kJSPropertyAttributeReadOnly}, {"provide_secret", respond_cb, kJSPropertyAttributeReadOnly}, /* Deprecated */ {"cancel_authentication", cancel_authentication_cb, kJSPropertyAttributeReadOnly}, @@ -1046,7 +1098,9 @@ static const JSStaticFunction lightdm_greeter_functions[] = { {"restart", restart_cb, kJSPropertyAttributeReadOnly}, {"shutdown", shutdown_cb, kJSPropertyAttributeReadOnly}, {"set_language", set_language_cb, kJSPropertyAttributeReadOnly}, - {"login", login_cb, kJSPropertyAttributeReadOnly}, + {"login", start_session_sync_cb, kJSPropertyAttributeReadOnly}, /* Deprecated */ + {"start_session_sync", start_session_sync_cb, kJSPropertyAttributeReadOnly}, + {"get_hint", get_hint_cb, kJSPropertyAttributeReadOnly}, {NULL, NULL, 0}}; static const JSStaticFunction gettext_functions[] = { diff --git a/themes/simple/index.html b/themes/simple/index.html index 810cc87..b0b7515 100644 --- a/themes/simple/index.html +++ b/themes/simple/index.html @@ -92,7 +92,7 @@ function authentication_complete() { if (lightdm.is_authenticated) { - lightdm.login (lightdm.authentication_user, lightdm.default_session); + lightdm.start_session_sync (lightdm.authentication_user, lightdm.default_session); } else { show_message ("Authentication Failed", "error"); setTimeout (start_authentication, 3000); @@ -130,7 +130,7 @@ function start_authentication() { clear_messages(); - lightdm.start_authentication(""); // start with null userid, have pam prompt for userid. + lightdm.authenticate(""); // start with null userid, have pam prompt for userid. } /* From b4db8c0ae48f10c1f4c89bfc6acedd65ade9a053 Mon Sep 17 00:00:00 2001 From: Scott Balneaves Date: Thu, 7 Jan 2016 15:23:50 -0600 Subject: [PATCH 16/18] Update the manual --- man/lightdm-webkit2-greeter.1 | 95 +++++++++++++++++++++++++---------- 1 file changed, 68 insertions(+), 27 deletions(-) diff --git a/man/lightdm-webkit2-greeter.1 b/man/lightdm-webkit2-greeter.1 index 5d0c837..30d9719 100644 --- a/man/lightdm-webkit2-greeter.1 +++ b/man/lightdm-webkit2-greeter.1 @@ -12,6 +12,10 @@ lightdm-webkit2-greeter is a LightDM greeter that uses webkit2 as the theming engine\&. Greeters can be written in a combination of HTML and Javascript\&. .PP .SH "API" +Please note that all functions or variables marked "deprecated" are still +available for backwards compatibility, but may disappear in a future version of +lightdm-webkit2-greeter\&. Authors of themes should use the new functions and +variables, which more closely match the LightDM API\&. .PP The following functions \fBmust\fR be provided by the custom greeter, which LightDM will call in the process of authenticating the user\&. @@ -46,15 +50,34 @@ expired\&. The greeter should reset the authentication process\&. The following functions are available for the greeter to call to execute actions within LightDM\&. .PP +\fBlightdm\&.authenticate(name)\fR +.RS 4 +Specifies the name of the user we'd like to start authenticating as\&. Note that +if you pass an empty string (""), LightDM (via PAM) will issue a show_prompt() +call to ask for the username\&. The older function +lightdm\&.start_authentication() has been deprecated\&. +.RE +.PP +\fBlightdm\&.authenticate_as_guest()\fR +.RS 4 +Authenticates as the guest user\&. +.RE +.PP \fBlightdm\&.cancel_authentication()\fR .RS 4 Cancels the authentication of any user currently in the process of authenticating\&. .RE .PP -\fBlightdm\&.cancel_timed_login()\fR +\fBlightdm\&.cancel_autologin()\fR +.RS 4 +Cancels the authentication of the autologin user\&. The older function +lightdm\&.cancel_timed_login() has been deprecated. +.RE +.PP +\fBlightdm\&.get_hint(hint_name)\fR .RS 4 -Cancels the authentication of the timed login user\&. +Returns the value of a named hint provided by LightDM\&. .RE .PP \fBlightdm\&.hibernate()\fR @@ -62,11 +85,12 @@ Cancels the authentication of the timed login user\&. Hibernates the system, if the greeter has the authority to do so\&. .RE .PP -\fBlightdm\&.login(user, session)\fR +\fBlightdm\&.start_session_sync(user, session)\fR .RS 4 Once LightDM has successfully authenticated the user, start the user's session by calling this function\&. "user" is the authenticated user, and "session" is -the user's session\&. +the user's session\&. The older function lightdm\&.login() has been +deprecated\&. .RE .PP \fBlightdm\&.respond(text)\fR @@ -92,13 +116,6 @@ Will set the language for the current LightDM session\&. Shuts down the system, if the greeter has the authority to do so\&. .RE .PP -\fBlightdm\&.start_authentication(name)\fR -.RS 4 -Specifies the name of the user we'd like to start authenticating as\&. Note that -if you pass an empty string (""), LightDM (via PAM) will issue a show_prompt() -call to ask for the username\&. -.RE -.PP Variables available within the greeter are: .PP \fBlightdm\&.authentication_user\fR @@ -107,6 +124,24 @@ String\&. The username of the authentication user being authenticated or null if authentication is in progress\&. .RE .PP +\fBlightdm\&.autologin_guest\fR +.RS 4 +Boolean\&. Indicates the guest user should be used for autologin\&. +.RE +.PP +\fBlightdm\&.autologin_timeout\fR +.RS 4 +Number\&. The number of seconds to wait before automatically logging in\&. The +older variable lightdm\&.timed_user_delay has been deprecated\&. +.RE +.PP +\fBlightdm\&.autologin_user\fR +.RS 4 +String\&. The name of the user account that should be logged into +automatically after timed login delay has passed\&. The older variable +lightdm\&.timed_login_user has been deprecated\&. +.RE +.PP \fBlightdm\&.can_hibernate\fR .RS 4 Boolean\&. Whether or not the system can be made to hibernate by the greeter\&. @@ -127,19 +162,19 @@ Boolean\&. Whether or not the system can be shutdown by the greeter\&. Boolean\&. Whether or not the system can be suspended by the greeter\&. .RE .PP -\fBlightdm\&.default_language\fR +\fBlightdm\&.default_session\fR .RS 4 -String\&. The current language (system-wide)\&. +String\&. The name of the default session (as configured in lightdm.conf)\&. .RE .PP -\fBlightdm\&.default_layout\fR +\fBlightdm\&.has_guest_account\fR .RS 4 -String\&. The current keyboard layout (system-wide)\&. +Boolean\&. A guest account is available for login\&. .RE .PP -\fBlightdm\&.default_session\fR +\fBlightdm\&.hide_users\fR .RS 4 -String\&. The name of the default session (as configured in lightdm.conf)\&. +Boolean\&. The whole list of users should not be displayed\&. .RE .PP \fBlightdm\&.hostname\fR @@ -157,10 +192,17 @@ Boolean\&. Indicates if the user has successfully authenticated\&. Boolean\&. Indicates if lightdm is currently in the authentication phase\&. .RE .PP +\fBlightdm\&.language\fR +.RS 4 +String\&. The currently selected language\&. The older variable name +lightdm\&.default_language is deprecated\&. +.RE +.PP \fBlightdm\&.layout\fR .RS 4 String\&. The name of the currently active keyboard layout\&. To change the -layout, assign a valid layout name to this variable\&. +layout, assign a valid layout name to this variable\&. The older variable name +lightdm\&.default_layout is deprecated\&. .RE .PP \fBlightdm\&.layouts\fR @@ -174,21 +216,20 @@ of LightDMLayout objects\&. Number\&. The number of users able to log in\&. .RE .PP -\fBlightdm\&.sessions\fR +\fBlightdm\&.select_guest\fR .RS 4 -Array\&. The sessions that are available on the system\&. Returns an Array of -LightDMSession objects\&. +Boolean\&. The guest user should be selected by default for login\&. .RE .PP -\fBlightdm\&.timed_login_delay\fR +\fBlightdm\&.select_user\fR .RS 4 -Number\&. The number of seconds to wait before automatically logging in\&. +String\&. The username that should be selected by default for login\&. .RE .PP -\fBlightdm\&.timed_login_user\fR +\fBlightdm\&.sessions\fR .RS 4 -String\&. The name of the user account that should be logged into -automatically after timed login delay has passed\&. +Array\&. The sessions that are available on the system\&. Returns an Array of +LightDMSession objects\&. .RE .PP \fBlightdm\&.users\fR @@ -223,4 +264,4 @@ http://people\&.ubuntu\&.com/~robert-ancell/lightdm/reference/core\&.html .SH "AUTHOR" .PP lightdm-webkit-greeter was written by Robert Ancell \&. -lightdm-webkit2-greeter was ported to webkit2 by Dustin Falgout \&. +lightdm-webkit2-greeter was ported to webkit2 by the Antergos Developers From 9b5a8dc67ca18e618dc8f2953a20011801a0c27c Mon Sep 17 00:00:00 2001 From: Scott Balneaves Date: Thu, 7 Jan 2016 18:20:37 -0600 Subject: [PATCH 17/18] Ensure when we return a string, we also return a null correctly. Free strings we create --- src/lightdm-webkit2-greeter-ext.c | 103 ++++++++++++------------------ 1 file changed, 40 insertions(+), 63 deletions(-) diff --git a/src/lightdm-webkit2-greeter-ext.c b/src/lightdm-webkit2-greeter-ext.c index 74b3b34..33e3d7a 100644 --- a/src/lightdm-webkit2-greeter-ext.c +++ b/src/lightdm-webkit2-greeter-ext.c @@ -52,6 +52,21 @@ static JSClassRef lightdm_layout_class, lightdm_session_class; +static JSValueRef +string_or_null(JSContextRef context, const gchar *str) { + JSValueRef result; + JSStringRef string; + + if (str == NULL) + return JSValueMakeNull (context); + + string = JSStringCreateWithUTF8CString (str); + result = JSValueMakeString (context, string); + JSStringRelease (string); + + return result; +} + static char * escape (const gchar *text) { @@ -90,8 +105,7 @@ get_user_name_cb(JSContextRef context, JSStringRef propertyName, JSValueRef *exception) { LightDMUser *user = JSObjectGetPrivate(thisObject); - - return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_user_get_name(user))); + return string_or_null(context, lightdm_user_get_name(user)); } @@ -101,8 +115,7 @@ get_user_real_name_cb(JSContextRef context, JSStringRef propertyName, JSValueRef *exception) { LightDMUser *user = JSObjectGetPrivate(thisObject); - - return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_user_get_real_name(user))); + return string_or_null(context, lightdm_user_get_real_name(user)); } @@ -112,8 +125,7 @@ get_user_display_name_cb(JSContextRef context, JSStringRef propertyName, JSValueRef *exception) { LightDMUser *user = JSObjectGetPrivate(thisObject); - - return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_user_get_display_name(user))); + return string_or_null(context, lightdm_user_get_display_name(user)); } @@ -123,8 +135,7 @@ get_user_home_directory_cb(JSContextRef context, JSStringRef propertyName, JSValueRef *exception) { LightDMUser *user = JSObjectGetPrivate(thisObject); - - return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_user_get_home_directory(user))); + return string_or_null(context, lightdm_user_get_home_directory(user)); } static JSValueRef @@ -133,8 +144,7 @@ get_user_image_cb(JSContextRef context, JSStringRef propertyName, JSValueRef *exception) { LightDMUser *user = JSObjectGetPrivate(thisObject); - - return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_user_get_image(user))); + return string_or_null(context, lightdm_user_get_image(user)); } @@ -144,13 +154,7 @@ get_user_language_cb(JSContextRef context, JSStringRef propertyName, JSValueRef *exception) { LightDMUser *user = JSObjectGetPrivate(thisObject); - const gchar *language = lightdm_user_get_language(user); - - if (!language) { - return JSValueMakeNull(context); - } - - return JSValueMakeString(context, JSStringCreateWithUTF8CString(language)); + return string_or_null(context, lightdm_user_get_language(user)); } @@ -160,13 +164,7 @@ get_user_layout_cb(JSContextRef context, JSStringRef propertyName, JSValueRef *exception) { LightDMUser *user = JSObjectGetPrivate(thisObject); - const gchar *layout = lightdm_user_get_layout(user); - - if (!layout) { - return JSValueMakeNull(context); - } - - return JSValueMakeString(context, JSStringCreateWithUTF8CString(layout)); + return string_or_null(context, lightdm_user_get_layout(user)); } @@ -176,13 +174,7 @@ get_user_session_cb(JSContextRef context, JSStringRef propertyName, JSValueRef *exception) { LightDMUser *user = JSObjectGetPrivate(thisObject); - const gchar *session = lightdm_user_get_session(user); - - if (!session) { - return JSValueMakeNull(context); - } - - return JSValueMakeString(context, JSStringCreateWithUTF8CString(session)); + return string_or_null(context, lightdm_user_get_session(user)); } @@ -202,8 +194,7 @@ get_language_code_cb(JSContextRef context, JSStringRef propertyName, JSValueRef *exception) { LightDMLanguage *language = JSObjectGetPrivate(thisObject); - - return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_language_get_code(language))); + return string_or_null(context, lightdm_language_get_code(language)); } @@ -213,8 +204,7 @@ get_language_name_cb(JSContextRef context, JSStringRef propertyName, JSValueRef *exception) { LightDMLanguage *language = JSObjectGetPrivate(thisObject); - - return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_language_get_name(language))); + return string_or_null(context, lightdm_language_get_name(language)); } @@ -224,8 +214,7 @@ get_language_territory_cb(JSContextRef context, JSStringRef propertyName, JSValueRef *exception) { LightDMLanguage *language = JSObjectGetPrivate(thisObject); - - return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_language_get_territory(language))); + return string_or_null(context, lightdm_language_get_territory(language)); } @@ -235,8 +224,7 @@ get_layout_name_cb(JSContextRef context, JSStringRef propertyName, JSValueRef *exception) { LightDMLayout *layout = JSObjectGetPrivate(thisObject); - - return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_layout_get_name(layout))); + return string_or_null(context, lightdm_layout_get_name(layout)); } @@ -246,8 +234,7 @@ get_layout_short_description_cb(JSContextRef context, JSStringRef propertyName, JSValueRef *exception) { LightDMLayout *layout = JSObjectGetPrivate(thisObject); - - return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_layout_get_short_description(layout))); + return string_or_null(context, lightdm_layout_get_short_description(layout)); } @@ -257,8 +244,7 @@ get_layout_description_cb(JSContextRef context, JSStringRef propertyName, JSValueRef *exception) { LightDMLayout *layout = JSObjectGetPrivate(thisObject); - - return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_layout_get_description(layout))); + return string_or_null(context, lightdm_layout_get_description(layout)); } @@ -268,8 +254,7 @@ get_session_key_cb(JSContextRef context, JSStringRef propertyName, JSValueRef *exception) { LightDMSession *session = JSObjectGetPrivate(thisObject); - - return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_session_get_key(session))); + return string_or_null(context, lightdm_session_get_key(session)); } @@ -279,8 +264,7 @@ get_session_name_cb(JSContextRef context, JSStringRef propertyName, JSValueRef *exception) { LightDMSession *session = JSObjectGetPrivate(thisObject); - - return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_session_get_name(session))); + return string_or_null(context, lightdm_session_get_name(session)); } @@ -290,8 +274,7 @@ get_session_comment_cb(JSContextRef context, JSStringRef propertyName, JSValueRef *exception) { LightDMSession *session = JSObjectGetPrivate(thisObject); - - return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_session_get_comment(session))); + return string_or_null(context, lightdm_session_get_comment(session)); } @@ -300,7 +283,7 @@ get_hostname_cb(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef *exception) { - return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_get_hostname())); + return string_or_null(context, lightdm_get_hostname()); } @@ -309,10 +292,7 @@ get_num_users_cb(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef *exception) { - gint num_users; - - num_users = g_list_length(lightdm_user_list_get_users(lightdm_user_list_get_instance())); - return JSValueMakeNumber(context, num_users); + return JSValueMakeNumber(context, g_list_length(lightdm_user_list_get_users(lightdm_user_list_get_instance()))); } @@ -371,7 +351,7 @@ get_language_cb(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef *exception) { - return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_language_get_name((LightDMLanguage *) lightdm_get_language()))); + return string_or_null(context, lightdm_language_get_name((LightDMLanguage *) lightdm_get_language())); } static JSValueRef @@ -405,7 +385,7 @@ get_layout_cb(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef *exception) { - return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_layout_get_name(lightdm_get_layout()))); + return string_or_null(context, lightdm_layout_get_name(lightdm_get_layout())); } @@ -481,8 +461,7 @@ get_default_session_cb(JSContextRef context, JSStringRef propertyName, JSValueRef *exception) { LightDMGreeter *greeter = JSObjectGetPrivate(thisObject); - - return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_greeter_get_default_session_hint(greeter))); + return string_or_null(context, lightdm_greeter_get_default_session_hint(greeter)); } @@ -492,7 +471,6 @@ get_lock_hint_cb(JSContextRef context, JSStringRef propertyName, JSValueRef *exception) { LightDMGreeter *greeter = JSObjectGetPrivate(thisObject); - return JSValueMakeBoolean(context, lightdm_greeter_get_lock_hint(greeter)); } @@ -503,7 +481,6 @@ get_autologin_timeout_cb(JSContextRef context, JSStringRef propertyName, JSValueRef *exception) { LightDMGreeter *greeter = JSObjectGetPrivate(thisObject); - return JSValueMakeNumber(context, lightdm_greeter_get_autologin_timeout_hint(greeter)); } @@ -683,7 +660,7 @@ get_authentication_user_cb(JSContextRef context, JSStringRef propertyName, JSValueRef *exception) { LightDMGreeter *greeter = JSObjectGetPrivate(thisObject); - return JSValueMakeString(context, JSStringCreateWithUTF8CString(lightdm_greeter_get_authentication_user(greeter))); + return string_or_null(context, lightdm_greeter_get_authentication_user(greeter)); } static JSValueRef @@ -710,7 +687,7 @@ get_select_user_cb (JSContextRef context, JSStringRef propertyName, JSValueRef * exception) { LightDMGreeter *greeter = JSObjectGetPrivate (thisObject); - return JSValueMakeString (context, JSStringCreateWithUTF8CString (lightdm_greeter_get_select_user_hint (greeter))); + return string_or_null (context, lightdm_greeter_get_select_user_hint (greeter)); } static JSValueRef @@ -728,7 +705,7 @@ get_autologin_user_cb (JSContextRef context, JSStringRef propertyName, JSValueRef * exception) { LightDMGreeter *greeter = JSObjectGetPrivate (thisObject); - return JSValueMakeString (context, JSStringCreateWithUTF8CString (lightdm_greeter_get_autologin_user_hint (greeter))); + return string_or_null (context, lightdm_greeter_get_autologin_user_hint (greeter)); } static JSValueRef From d7c863e36b314f4b4af0043561957e59d0862278 Mon Sep 17 00:00:00 2001 From: Scott Balneaves Date: Thu, 7 Jan 2016 22:10:15 -0600 Subject: [PATCH 18/18] Plug remaining string leaks --- src/lightdm-webkit2-greeter-ext.c | 162 +++++++++++------------------- 1 file changed, 56 insertions(+), 106 deletions(-) diff --git a/src/lightdm-webkit2-greeter-ext.c b/src/lightdm-webkit2-greeter-ext.c index 33e3d7a..e0c524b 100644 --- a/src/lightdm-webkit2-greeter-ext.c +++ b/src/lightdm-webkit2-greeter-ext.c @@ -67,6 +67,16 @@ string_or_null(JSContextRef context, const gchar *str) { return result; } +static JSValueRef +mkexception (JSContextRef context, JSValueRef * exception, const gchar * str) +{ + JSStringRef string = JSStringCreateWithUTF8CString (str); + JSValueRef exceptionString = JSValueMakeString (context, string); + JSStringRelease (string); + *exception = JSValueToObject (context, exceptionString, NULL); + return JSValueMakeNull (context); +} + static char * escape (const gchar *text) { @@ -494,13 +504,8 @@ cancel_autologin_cb(JSContextRef context, JSValueRef *exception) { LightDMGreeter *greeter = JSObjectGetPrivate(thisObject); - if (argumentCount != 0) { - JSStringRef string = JSStringCreateWithUTF8CString("Argument count not zero"); - JSValueRef exceptionString = JSValueMakeString(context, string); - JSStringRelease(string); - *exception = JSValueToObject(context, exceptionString, NULL); - return JSValueMakeNull(context); - } + if (argumentCount != 0) + return mkexception (context, exception, "Argument count not zero"); lightdm_greeter_cancel_autologin(greeter); return JSValueMakeNull(context); @@ -519,13 +524,8 @@ authenticate_cb(JSContextRef context, size_t name_size; gchar *name; - if (!( argumentCount == 1 && JSValueGetType(context, arguments[0]) == kJSTypeString )) { - JSStringRef string = JSStringCreateWithUTF8CString("Username argument not supplied"); - JSValueRef exceptionString = JSValueMakeString(context, string); - JSStringRelease(string); - *exception = JSValueToObject(context, exceptionString, NULL); - return JSValueMakeNull(context); - } + if (!( argumentCount == 1 && JSValueGetType(context, arguments[0]) == kJSTypeString )) + return mkexception (context, exception, "Username argument not supplied"); name_arg = JSValueToStringCopy(context, arguments[0], NULL); name_size = JSStringGetMaximumUTF8CStringSize(name_arg); @@ -551,13 +551,8 @@ authenticate_as_guest_cb (JSContextRef context, JSValueRef * exception) { LightDMGreeter *greeter = JSObjectGetPrivate (thisObject); - if (argumentCount != 0) { - JSStringRef string = JSStringCreateWithUTF8CString ("Argument count not zero"); - JSValueRef exceptionString = JSValueMakeString (context, string); - JSStringRelease (string); - *exception = JSValueToObject (context, exceptionString, NULL); - return JSValueMakeNull (context); - } + if (argumentCount != 0) + return mkexception (context, exception, "Argument count not zero"); lightdm_greeter_authenticate_as_guest (greeter); @@ -576,14 +571,10 @@ get_hint_cb (JSContextRef context, size_t hint_size; gchar *hint_name; JSStringRef hint; + JSValueRef result; - if (!(argumentCount == 1 && JSValueGetType (context, arguments[0]) == kJSTypeString)) { - JSStringRef string = JSStringCreateWithUTF8CString ("Hint argument not supplied"); - JSValueRef exceptionString = JSValueMakeString (context, string); - JSStringRelease (string); - *exception = JSValueToObject (context, exceptionString, NULL); - return JSValueMakeNull (context); - } + if (!(argumentCount == 1 && JSValueGetType (context, arguments[0]) == kJSTypeString)) + return mkexception (context, exception, "Hint argument not supplied"); hint_arg = JSValueToStringCopy (context, arguments[0], NULL); hint_size = JSStringGetMaximumUTF8CStringSize (hint_arg); @@ -592,10 +583,11 @@ get_hint_cb (JSContextRef context, JSStringRelease (hint_arg); hint = JSStringCreateWithUTF8CString (lightdm_greeter_get_hint (greeter, hint_name)); - g_free (hint_name); + result = JSValueMakeString (context, hint); + JSStringRelease (hint); - return JSValueMakeString (context, hint); + return result; } @@ -611,13 +603,8 @@ respond_cb(JSContextRef context, size_t response_size; gchar *response; - if (!( argumentCount == 1 && JSValueGetType(context, arguments[0]) == kJSTypeString )) { - JSStringRef string = JSStringCreateWithUTF8CString("Response not supplied"); - JSValueRef exceptionString = JSValueMakeString(context, string); - JSStringRelease(string); - *exception = JSValueToObject(context, exceptionString, NULL); - return JSValueMakeNull(context); - } + if (!( argumentCount == 1 && JSValueGetType(context, arguments[0]) == kJSTypeString )) + return mkexception (context, exception, "Response not supplied"); response_arg = JSValueToStringCopy(context, arguments[0], NULL); response_size = JSStringGetMaximumUTF8CStringSize(response_arg); @@ -641,13 +628,8 @@ cancel_authentication_cb(JSContextRef context, JSValueRef *exception) { LightDMGreeter *greeter = JSObjectGetPrivate(thisObject); - if (argumentCount != 0) { - JSStringRef string = JSStringCreateWithUTF8CString("Argument count not zero"); - JSValueRef exceptionString = JSValueMakeString(context, string); - JSStringRelease(string); - *exception = JSValueToObject(context, exceptionString, NULL); - return JSValueMakeNull(context); - } + if (argumentCount != 0) + return mkexception (context, exception, "Argument count not zero"); lightdm_greeter_cancel_authentication(greeter); return JSValueMakeNull(context); @@ -751,13 +733,8 @@ suspend_cb(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { - if (argumentCount != 0) { - JSStringRef string = JSStringCreateWithUTF8CString("Argument count not zero"); - JSValueRef exceptionString = JSValueMakeString(context, string); - JSStringRelease(string); - *exception = JSValueToObject(context, exceptionString, NULL); - return JSValueMakeNull(context); - } + if (argumentCount != 0) + return mkexception (context, exception, "Argument count not zero"); lightdm_suspend(NULL); return JSValueMakeNull(context); @@ -780,13 +757,8 @@ hibernate_cb(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { - if (argumentCount != 0) { - JSStringRef string = JSStringCreateWithUTF8CString("Argument count not zero"); - JSValueRef exceptionString = JSValueMakeString(context, string); - JSStringRelease(string); - *exception = JSValueToObject(context, exceptionString, NULL); - return JSValueMakeNull(context); - } + if (argumentCount != 0) + return mkexception (context, exception, "Argument count not zero"); lightdm_hibernate(NULL); return JSValueMakeNull(context); @@ -809,13 +781,8 @@ restart_cb(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { - if (argumentCount != 0) { - JSStringRef string = JSStringCreateWithUTF8CString("Argument count not zero"); - JSValueRef exceptionString = JSValueMakeString(context, string); - JSStringRelease(string); - *exception = JSValueToObject(context, exceptionString, NULL); - return JSValueMakeNull(context); - } + if (argumentCount != 0) + return mkexception (context, exception, "Argument count not zero"); lightdm_restart(NULL); return JSValueMakeNull(context); @@ -838,13 +805,8 @@ shutdown_cb(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { - if (argumentCount != 0) { - JSStringRef string = JSStringCreateWithUTF8CString("Argument count not zero"); - JSValueRef exceptionString = JSValueMakeString(context, string); - JSStringRelease(string); - *exception = JSValueToObject(context, exceptionString, NULL); - return JSValueMakeNull(context); - } + if (argumentCount != 0) + return mkexception (context, exception, "Argument count not zero"); lightdm_shutdown(NULL); return JSValueMakeNull(context); @@ -864,13 +826,8 @@ start_session_sync_cb(JSContextRef context, gchar *username, *session = NULL; if (!((argumentCount == 1 && JSValueGetType (context, arguments[0]) == kJSTypeString) || - (argumentCount == 2 && JSValueGetType (context, arguments[0]) == kJSTypeString && JSValueGetType (context, arguments[1]) == kJSTypeString))) { - JSStringRef string = JSStringCreateWithUTF8CString("Username or Session incorrect"); - JSValueRef exceptionString = JSValueMakeString(context, string); - JSStringRelease(string); - *exception = JSValueToObject(context, exceptionString, NULL); - return JSValueMakeNull (context); - } + (argumentCount == 2 && JSValueGetType (context, arguments[0]) == kJSTypeString && JSValueGetType (context, arguments[1]) == kJSTypeString))) + return mkexception (context, exception, "Username or Session incorrect"); arg = JSValueToStringCopy(context, arguments[0], NULL); username_size = JSStringGetMaximumUTF8CStringSize(arg); @@ -907,13 +864,8 @@ set_language_cb(JSContextRef context, size_t language_size; gchar *language; - if (!(argumentCount == 1 && JSValueGetType (context, arguments[0]) == kJSTypeString)) { - JSStringRef string = JSStringCreateWithUTF8CString("Language not supplied"); - JSValueRef exceptionString = JSValueMakeString(context, string); - JSStringRelease(string); - *exception = JSValueToObject(context, exceptionString, NULL); - return false; - } + if (!(argumentCount == 1 && JSValueGetType (context, arguments[0]) == kJSTypeString)) + return mkexception (context, exception, "Language not supplied"); arg = JSValueToStringCopy(context, arguments[0], NULL); language_size = JSStringGetMaximumUTF8CStringSize(arg); @@ -935,17 +887,13 @@ gettext_cb(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { - JSStringRef string_arg, result; + JSStringRef string_arg, text; size_t string_size; gchar *string; + JSValueRef result; - if (!(argumentCount == 1 && JSValueGetType (context, arguments[0]) == kJSTypeString)) { - JSStringRef string = JSStringCreateWithUTF8CString("Argument not supplied"); - JSValueRef exceptionString = JSValueMakeString(context, string); - JSStringRelease(string); - *exception = JSValueToObject(context, exceptionString, NULL); - return JSValueMakeNull(context); - } + if (!(argumentCount == 1 && JSValueGetType (context, arguments[0]) == kJSTypeString)) + return mkexception (context, exception, "Argument not supplied"); string_arg = JSValueToStringCopy(context, arguments[0], NULL); string_size = JSStringGetMaximumUTF8CStringSize(string_arg); @@ -953,9 +901,12 @@ gettext_cb(JSContextRef context, JSStringGetUTF8CString(string_arg, string, string_size); JSStringRelease(string_arg); - result = JSStringCreateWithUTF8CString(gettext(string)); + text = JSStringCreateWithUTF8CString(gettext(string)); g_free (string); - return JSValueMakeString(context, result); + result = JSValueMakeString(context, text); + JSStringRelease (text); + + return result; } @@ -966,18 +917,14 @@ ngettext_cb(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { - JSStringRef string_arg, plural_string_arg, result; + JSStringRef string_arg, plural_string_arg, text; size_t string_size, plural_string_size; gchar *string, *plural_string; unsigned int n; + JSValueRef result; - if (argumentCount != 3) { - JSStringRef string = JSStringCreateWithUTF8CString("Needs 3 arguments"); - JSValueRef exceptionString = JSValueMakeString(context, string); - JSStringRelease(string); - *exception = JSValueToObject(context, exceptionString, NULL); - return JSValueMakeNull(context); - } + if (argumentCount != 3) + return mkexception (context, exception, "Needs 3 arguments"); string_arg = JSValueToStringCopy(context, arguments[0], NULL); string_size = JSStringGetMaximumUTF8CStringSize(string_arg); @@ -993,10 +940,13 @@ ngettext_cb(JSContextRef context, n = JSValueToNumber(context, arguments[2], NULL); - result = JSStringCreateWithUTF8CString(ngettext(string, plural_string, n)); + text = JSStringCreateWithUTF8CString(ngettext(string, plural_string, n)); g_free (string); g_free (plural_string); - return JSValueMakeString(context, result); + result = JSValueMakeString(context, text); + JSStringRelease (text); + + return result; }