Browse Source

Show theme recovery modal when we detect an uncaught javascript exception.

sisyphus
Dustin Falgout 8 years ago
parent
commit
2629e092e2
  1. 107
      src/greeter.c
  2. 45
      src/webkit2-extension.c

107
src/greeter.c

@ -122,6 +122,66 @@ lock_hint_enabled_handler(void) {
}
static void
show_theme_recovery_modal() {
GtkWidget
*dialog,
*label,
*content_area,
*button,
*button_box;
dialog = gtk_dialog_new_with_buttons(
_("Greeter Theme Error Detected"),
GTK_WINDOW(window),
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
_("Load _Default Theme"),
GTK_RESPONSE_ACCEPT,
_("Load _Fallback Theme"),
GTK_RESPONSE_OK,
_("_Cancel"),
GTK_RESPONSE_REJECT,
NULL
);
content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
button = gtk_dialog_get_widget_for_response(GTK_DIALOG(dialog), GTK_RESPONSE_REJECT);
button_box = gtk_widget_get_parent(button);
label = gtk_label_new(
_("An error was detected in the current theme that could interfere with the system login process.")
);
gtk_button_box_set_layout(GTK_BUTTON_BOX(button_box), GTK_BUTTONBOX_EXPAND);
gtk_container_add(GTK_CONTAINER(content_area), label);
gtk_widget_show_all(content_area);
gint response = gtk_dialog_run(GTK_DIALOG(dialog));
if (GTK_RESPONSE_REJECT == response) {
gtk_widget_destroy(dialog);
return;
}
gchar *log_msg = "[ERROR] :: A problem was detected with the current theme. Falling back to default theme...";
gchar *fallback_theme;
if (GTK_RESPONSE_ACCEPT == response) {
fallback_theme = "antergos";
} else {
fallback_theme = "simple";
}
g_warning(log_msg);
gtk_widget_destroy(dialog);
webkit_web_view_load_uri(
WEBKIT_WEB_VIEW(web_view),
g_strdup_printf("file://%s/%s/index.html", THEME_DIR, fallback_theme)
);
}
/**
* Message received callback.
*
@ -157,7 +217,10 @@ message_received_cb(WebKitUserContentManager *manager,
printf("Error running javascript: unexpected return value");
}
if (strcmp(message_str, "LockHint") == 0) {
if (0 == g_strcmp0(message_str, "JavaScriptException")) {
show_theme_recovery_modal();
} else if (0 == g_strcmp0(message_str, "LockHint")) {
lock_hint_enabled_handler();
} else {
@ -245,42 +308,7 @@ theme_function_exists_cb(GObject *object,
}
if (FALSE == result_as_bool) {
GtkWidget *dialog, *label, *content_area, *button, *button_box;
dialog = gtk_dialog_new_with_buttons(
_("Greeter Theme Error Detected"),
GTK_WINDOW(window),
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
_("_Load Default Theme"),
GTK_RESPONSE_ACCEPT,
_("_Load Fallback Theme"),
GTK_RESPONSE_OK,
_("_Cancel"),
GTK_RESPONSE_REJECT,
NULL
);
content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
button = gtk_dialog_get_widget_for_response(GTK_DIALOG(dialog), GTK_RESPONSE_REJECT);
button_box = gtk_widget_get_parent(button);
label = gtk_label_new(_("An error was detected in the current theme that could interfere with the system login process."));
gtk_button_box_set_layout(GTK_BUTTON_BOX(button_box), GTK_BUTTONBOX_EXPAND);
gtk_container_add(GTK_CONTAINER(content_area), label);
gtk_widget_show_all(content_area);
gint response = gtk_dialog_run(GTK_DIALOG(dialog));
gchar *log_msg = "[ERROR] :: A problem was detected with the current theme. Falling back to simple theme...";
if (GTK_RESPONSE_ACCEPT == response) {
g_warning(log_msg);
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(web_view), g_strdup_printf("file://%s/antergos/index.html", THEME_DIR));
} else if (GTK_RESPONSE_OK == response) {
g_warning(log_msg);
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(web_view), g_strdup_printf("file://%s/simple/index.html", THEME_DIR));
}
gtk_widget_destroy(dialog);
show_theme_recovery_modal();
}
webkit_javascript_result_unref(js_result);
@ -419,9 +447,8 @@ main(int argc, char **argv) {
* so webkit can find our extension.
*/
context = webkit_web_context_get_default();
g_signal_connect(WEBKIT_WEB_CONTEXT(context),
"initialize-web-extensions",
G_CALLBACK(initialize_web_extensions_cb), NULL);
g_signal_connect(context, "initialize-web-extensions", G_CALLBACK(initialize_web_extensions_cb), NULL);
webkit_web_context_set_cache_model(context, WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
/* Set cookie policy */
cookie_manager = webkit_web_context_get_cookie_manager(context);

45
src/webkit2-extension.c

@ -1911,6 +1911,50 @@ web_page_send_request_cb(WebKitWebPage *web_page,
}
void
web_page_console_message_sent_cb(WebKitWebPage *web_page,
WebKitConsoleMessage *console_message,
gpointer user_data) {
WebKitConsoleMessageLevel msg_level;
WebKitConsoleMessageSource msg_source;
WebKitDOMDOMWindow *dom_window;
WebKitDOMDocument *dom_document;
const gchar *msg_text;
gboolean is_error, is_from_javascript, is_uncaught_exception;
msg_level = webkit_console_message_get_level(console_message);
is_error = WEBKIT_CONSOLE_MESSAGE_LEVEL_ERROR == msg_level;
if (! is_error) {
return;
}
msg_source = webkit_console_message_get_source(console_message);
is_from_javascript = WEBKIT_CONSOLE_MESSAGE_SOURCE_JAVASCRIPT == msg_source;
if (! is_from_javascript) {
return;
}
msg_text = webkit_console_message_get_text(console_message);
is_uncaught_exception = NULL != strstr(msg_text, "Uncaught");
if (! is_uncaught_exception) {
return;
}
/* This is an Uncaught JS Exception. Notify the UI process so it can show recovery dialog */
dom_document = webkit_web_page_get_dom_document(web_page);
dom_window = webkit_dom_document_get_default_view(dom_document);
if (dom_window) {
webkit_dom_dom_window_webkit_message_handlers_post_message(
dom_window, "GreeterBridge", "JavaScriptException"
);
}
}
void
page_created_cb(WebKitWebExtension *extension,
WebKitWebPage *web_page,
@ -1933,6 +1977,7 @@ page_created_cb(WebKitWebExtension *extension,
}
g_signal_connect(web_page, "send-request", G_CALLBACK(web_page_send_request_cb), NULL);
g_signal_connect(web_page, "console-message-sent", G_CALLBACK(web_page_console_message_sent_cb), NULL);
}

Loading…
Cancel
Save