From d3292153f3f18cc6510403100999f22ce59c11f3 Mon Sep 17 00:00:00 2001 From: Dustin Falgout Date: Mon, 3 Oct 2016 08:46:03 -0500 Subject: [PATCH] remove debugging messages. code cleanup --- src/config.h | 1 + src/greeter.c | 21 +++++++--- src/webkit2-extension.c | 79 +++++++++++++++++++++++------------ themes/antergos/js/greeter.js | 5 +-- 4 files changed, 71 insertions(+), 35 deletions(-) create mode 120000 src/config.h diff --git a/src/config.h b/src/config.h new file mode 120000 index 0000000..64de3f2 --- /dev/null +++ b/src/config.h @@ -0,0 +1 @@ +../build/src/config.h \ No newline at end of file diff --git a/src/greeter.c b/src/greeter.c index ab6cdd6..36d28cf 100644 --- a/src/greeter.c +++ b/src/greeter.c @@ -33,20 +33,24 @@ */ #include +#include #include #include -#include #include #include -#include #include #include #include #include -#include +#include "config.h" #include "gresource/greeter-resources.h" +/* CLion bugs */ +#ifndef gsize +typedef unsigned long gsize; +#endif + static GtkWidget *web_view; static GtkWidget *window; static WebKitSettings *webkit_settings; @@ -54,11 +58,18 @@ static GdkDisplay *default_display; static GResource *greeter_resources; /* Screensaver values */ -static int timeout, interval, prefer_blanking, allow_exposures; +static int + timeout, + interval, + prefer_blanking, + allow_exposures; static gint config_timeout; -static gboolean debug_mode, heartbeat, heartbeat_exit; +static gboolean + debug_mode, + heartbeat, + heartbeat_exit; static GdkFilterReturn diff --git a/src/webkit2-extension.c b/src/webkit2-extension.c index 8aae6d7..ffd47fb 100644 --- a/src/webkit2-extension.c +++ b/src/webkit2-extension.c @@ -31,37 +31,56 @@ * along with lightdm-webkit2-greeter; If not, see . */ +/* WebKitWebExtension + * This extension runs inside the web process allowing us to interact directly with + * the web page including the DOM and JavaScriptWorld. + */ + #define _GNU_SOURCE #include +#include #include #include -#include #include -#include #include +#include #include - #include -#include +#include "config.h" -G_MODULE_EXPORT void webkit_web_extension_initialize(WebKitWebExtension *extension); -guint64 page_id = -1; -GKeyFile *keyfile; +/* CLion bugs */ +#ifndef guint64 +typedef unsigned long guint64; +#endif + +/* Convenience macros for use in functions that can be called from JavaScript + * running in the web process. They are used to confirm that calls were made by one of + * the classes that we injected into the web page. + */ #define USER ((LightDMUser *) JSObjectGetPrivate (thisObject)) #define LAYOUT ((LightDMLayout *) JSObjectGetPrivate (thisObject)) #define SESSION ((LightDMSession *) JSObjectGetPrivate (thisObject)) #define GREETER ((LightDMGreeter *) JSObjectGetPrivate (thisObject)) #define LANGUAGE ((LightDMLanguage *) JSObjectGetPrivate (thisObject)) + /* - * Put all our translatable strings up top + * Translatable strings */ #define EXPECTSTRING _("Expected a string") #define ARGNOTSUPPLIED _("Argument(s) not supplied") + +G_MODULE_EXPORT void webkit_web_extension_initialize(WebKitWebExtension *extension); + + +guint64 page_id; +GKeyFile *keyfile; + + static JSClassRef lightdm_greeter_class, gettext_class, @@ -477,8 +496,7 @@ get_language_cb(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef *exception) { - return string_or_null(context, - lightdm_language_get_name((LightDMLanguage *) lightdm_get_language())); + return string_or_null(context, lightdm_language_get_name(lightdm_get_language())); } @@ -1302,7 +1320,7 @@ txt2html_cb(JSContextRef context, static gchar * -remove_query_string(gchar *str) { +remove_query_and_hash(gchar *str) { gchar *ptr = NULL; ptr = strchr(str, '?'); @@ -1311,6 +1329,12 @@ remove_query_string(gchar *str) { *ptr = '\0'; } + ptr = strchr(str, '#'); + + if (NULL != ptr) { + *ptr = '\0'; + } + return g_strstrip(str); } @@ -1720,12 +1744,12 @@ get_config_option(const gchar *section, const gchar *key) { static gboolean -is_requested_file_path_allowed(const char *file_path) { +should_block_request(const char *file_path) { gchar *background_images_dir; gchar *user_image; gchar *logo; - gboolean result = FALSE; - char *normalized_path; + gboolean result = TRUE; + char *canonical_path; if (NULL == file_path) { return result; @@ -1744,20 +1768,20 @@ is_requested_file_path_allowed(const char *file_path) { logo = get_config_option("branding", "logo"); paths = g_slist_prepend(paths, logo); - normalized_path = canonicalize_file_name(file_path); + canonical_path = canonicalize_file_name(file_path); - if (NULL != normalized_path) { + if (NULL != canonical_path) { for (iter = paths; iter; iter = iter->next) { - if (strcmp(normalized_path, iter->data) == 0 || g_str_has_prefix(normalized_path, iter->data)) { - /* Requested path is allowed */ - result = TRUE; + if (strcmp(canonical_path, iter->data) == 0 || g_str_has_prefix(canonical_path, iter->data)) { + /* Requested path is allowed (don't block request). */ + result = FALSE; break; } } } g_slist_free(paths); - g_free(normalized_path); + g_free(canonical_path); g_free(background_images_dir); g_free(user_image); g_free(logo); @@ -1805,13 +1829,11 @@ web_page_send_request_cb(WebKitWebPage *web_page, request_file_path = g_filename_from_uri(request_uri, NULL, NULL); request_file_path_without_query = g_strdup(request_file_path); - request_file_path_without_query = remove_query_string(request_file_path_without_query); - - g_message(request_file_path_without_query); + request_file_path_without_query = remove_query_and_hash(request_file_path_without_query); g_free(request_scheme); - return (FALSE == is_requested_file_path_allowed(request_file_path_without_query)); + return should_block_request(request_file_path_without_query); } @@ -1887,9 +1909,12 @@ webkit_web_extension_initialize(WebKitWebExtension *extension) { /* load greeter settings from config file */ keyfile = g_key_file_new(); - g_key_file_load_from_file(keyfile, - CONFIG_DIR "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 + ); } /* vim: set ts=4 sw=4 tw=0 noet : */ diff --git a/themes/antergos/js/greeter.js b/themes/antergos/js/greeter.js index 11a626e..e8e2dad 100644 --- a/themes/antergos/js/greeter.js +++ b/themes/antergos/js/greeter.js @@ -99,7 +99,8 @@ class AntergosThemeUtils { if ('' === this.cache_backend) { this.cache_backend = 'Cookies'; } - console.log(`AntergosThemeUtils.cache_backend is: ${this.cache_backend}`); + + this.log(`AntergosThemeUtils.cache_backend is: ${this.cache_backend}`); } @@ -730,8 +731,6 @@ class AntergosTheme { _self.selected_user = null; _self.auth_pending = false; - console.log($(event.target)); - if ( $(event.target).hasClass('alert') ) { /* We were triggered by the authentication failed message being dismissed. * Keep the same account selected so user can retry without re-selecting an account.