Browse Source

wait until "page loaded" callback to schedule the callback for the "theme loaded" check.

sisyphus
Dustin Falgout 8 years ago
parent
commit
48023e0bbc
  1. 105
      src/greeter.c
  2. 13
      src/webkit2-extension.c

105
src/greeter.c

@ -182,6 +182,54 @@ show_theme_recovery_modal() {
}
static void
theme_function_exists_cb(GObject *object,
GAsyncResult *result,
gpointer user_data) {
WebKitJavascriptResult *js_result;
GError *error = NULL;
JSValueRef value;
JSGlobalContextRef context;
gboolean result_as_bool;
js_result = webkit_web_view_run_javascript_finish(WEBKIT_WEB_VIEW(object), result, &error);
if (NULL != error) {
g_warning ("Error running javascript: %s", error->message);
g_error_free(error);
return;
} else {
context = webkit_javascript_result_get_global_context(js_result);
value = webkit_javascript_result_get_value(js_result);
result_as_bool = JSValueToBoolean(context, value);
}
if (FALSE == result_as_bool) {
show_theme_recovery_modal();
}
webkit_javascript_result_unref(js_result);
}
gboolean
maybe_show_theme_fallback_dialog(void) {
/* Check for existence of a function that themes must add to window object */
webkit_web_view_run_javascript(
WEBKIT_WEB_VIEW(web_view),
"(() => 'authentication_complete' in window)()",
NULL,
(GAsyncReadyCallback) theme_function_exists_cb,
NULL
);
return FALSE;
}
/**
* Message received callback.
*
@ -217,7 +265,11 @@ message_received_cb(WebKitUserContentManager *manager,
printf("Error running javascript: unexpected return value");
}
if (0 == g_strcmp0(message_str, "JavaScriptException")) {
if (0 == g_strcmp0(message_str, "PageLoaded")) {
/* Register callback to check if theme loaded successfully */
g_timeout_add_seconds(8, (GSourceFunc) maybe_show_theme_fallback_dialog, NULL);
} else if (0 == g_strcmp0(message_str, "JavaScriptException")) {
show_theme_recovery_modal();
} else if (0 == g_strcmp0(message_str, "LockHint")) {
@ -282,54 +334,6 @@ javascript_bundle_injection_setup() {
}
static void
theme_function_exists_cb(GObject *object,
GAsyncResult *result,
gpointer user_data) {
WebKitJavascriptResult *js_result;
GError *error = NULL;
JSValueRef value;
JSGlobalContextRef context;
gboolean result_as_bool;
js_result = webkit_web_view_run_javascript_finish(WEBKIT_WEB_VIEW(object), result, &error);
if (NULL != error) {
g_warning ("Error running javascript: %s", error->message);
g_error_free(error);
return;
} else {
context = webkit_javascript_result_get_global_context(js_result);
value = webkit_javascript_result_get_value(js_result);
result_as_bool = JSValueToBoolean(context, value);
}
if (FALSE == result_as_bool) {
show_theme_recovery_modal();
}
webkit_javascript_result_unref(js_result);
}
gboolean
maybe_show_theme_fallback_dialog(void) {
/* Check for existence of a function that themes must add to window object */
webkit_web_view_run_javascript(
WEBKIT_WEB_VIEW(web_view),
"(() => 'authentication_complete' in window)()",
NULL,
(GAsyncReadyCallback) theme_function_exists_cb,
NULL
);
return FALSE;
}
int
main(int argc, char **argv) {
GdkScreen *screen;
@ -477,9 +481,6 @@ main(int argc, char **argv) {
/* Maybe disable the context (right-click) menu. */
g_signal_connect(WEBKIT_WEB_VIEW(web_view), "context-menu", G_CALLBACK(context_menu_cb), NULL);
/* Register callback to check if theme loaded successfully */
g_timeout_add_seconds(10, (GSourceFunc) maybe_show_theme_fallback_dialog, NULL);
/* There's no turning back now, let's go! */
gtk_container_add(GTK_CONTAINER(window), web_view);
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(web_view),

13
src/webkit2-extension.c

@ -1950,6 +1950,9 @@ page_created_cb(WebKitWebExtension *extension,
WebKitWebPage *web_page,
gpointer user_data) {
WebKitDOMDOMWindow *dom_window;
WebKitDOMDocument *dom_document;
// save the page_id (global variable)
page_id = webkit_web_page_get_id(web_page);
@ -1958,6 +1961,16 @@ page_created_cb(WebKitWebExtension *extension,
if (TRUE == detect_theme_errors) {
g_signal_connect(web_page, "console-message-sent", G_CALLBACK(web_page_console_message_sent_cb), NULL);
}
// Notify UI process that the page is loaded.
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", "PageLoaded"
);
}
}

Loading…
Cancel
Save