Browse Source

fix message_received_cb function

sisyphus
Dustin Falgout 9 years ago
parent
commit
026bad4e07
  1. 69
      src/lightdm-webkit2-greeter.c

69
src/lightdm-webkit2-greeter.c

@ -128,22 +128,6 @@ context_menu_cb(WebKitWebView *view,
} }
/**
* Callback for Theme Heartbeat. Themes start the heartbeat by sending a post message
* via JavaScript. Once started, the heartbeat will schedule a check to ensure that the
* theme has sent a subsequent heartbeat message. If heartbeat message was not received,
* we assume that there has been an error in the web process and fallback to the simple theme.
*/
static void
theme_heartbeat_cb(void) {
if (! heartbeat) {
/* Setup g_timeout callback for theme heartbeat check */
g_timeout_add_seconds(G_PRIORITY_DEFAULT, 8, (GSourceFunc) check_theme_heartbeat_cb, NULL);
heartbeat = TRUE;
}
}
static gboolean static gboolean
check_theme_heartbeat_cb(void) { check_theme_heartbeat_cb(void) {
if (! heartbeat) { if (! heartbeat) {
@ -151,10 +135,7 @@ check_theme_heartbeat_cb(void) {
* which broke script execution. We will fallback to the simple theme * which broke script execution. We will fallback to the simple theme
* so the user won't be stuck with a broken login screen. * so the user won't be stuck with a broken login screen.
*/ */
g_print('%s%s', g_warning("[ERROR] :: A problem was detected with the current theme. Falling back to simple theme...");
'[ERROR] :: A problem was detected with the current theme. ',
'Falling back to simple theme...'
);
webkit_web_view_load_uri( webkit_web_view_load_uri(
WEBKIT_WEB_VIEW(web_view), WEBKIT_WEB_VIEW(web_view),
g_strdup_printf("file://%s/simple/index.html", THEME_DIR) g_strdup_printf("file://%s/simple/index.html", THEME_DIR)
@ -167,6 +148,22 @@ check_theme_heartbeat_cb(void) {
} }
/**
* Callback for Theme Heartbeat. Themes start the heartbeat by sending a post message
* via JavaScript. Once started, the heartbeat will schedule a check to ensure that the
* theme has sent a subsequent heartbeat message. If heartbeat message was not received,
* we assume that there has been an error in the web process and fallback to the simple theme.
*/
static void
theme_heartbeat_cb(void) {
if (! heartbeat) {
/* Setup g_timeout callback for theme heartbeat check */
g_timeout_add_seconds(8, (GSourceFunc) check_theme_heartbeat_cb, NULL);
heartbeat = TRUE;
}
}
/** /**
* Lock Hint enabled handler. * Lock Hint enabled handler.
* *
@ -199,19 +196,33 @@ message_received_cb(WebKitUserContentManager *manager,
gpointer user_data) { gpointer user_data) {
gchar *message_str, *lock_hint_str, *heartbeat_str; gchar *message_str, *lock_hint_str, *heartbeat_str;
JSGlobalContextRef context;
JSValueRef message_val;
JSStringRef js_str_val;
gsize message_str_length;
context = webkit_javascript_result_get_global_context(message);
message_val = webkit_javascript_result_get_value(message);
if (JSValueIsString(context, message_val)) {
js_str_val = JSValueToStringCopy(context, message_val, NULL);
message_str_length = JSStringGetMaximumUTF8CStringSize(js_str_val);
message_str = (gchar *)g_malloc (message_str_length);
JSStringGetUTF8CString(js_str_val, message_str, message_str_length);
JSStringRelease(js_str_val);
} else {
message_str = "";
g_warning("Error running javascript: unexpected return value");
}
message_str = get_js_result_as_string(message);
lock_hint_str = "LockHint"; lock_hint_str = "LockHint";
heartbeat_str = "Heartbeat"; heartbeat_str = "Heartbeat";
switch(message_str) { if (message_str == lock_hint_str) {
case lock_hint_str : lock_hint_enabled_handler();
lock_hint_enabled_handler(); } else if (message_str == heartbeat_str) {
break; theme_heartbeat_cb();
case heartbeat_str :
theme_heartbeat_cb();
break;
} }
g_free(message_str); g_free(lock_hint_str); g_free(heartbeat_str); g_free(message_str); g_free(lock_hint_str); g_free(heartbeat_str);

Loading…
Cancel
Save