[Libreoffice-commits] online.git: gtk/main.cpp
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Tue Oct 16 22:04:34 UTC 2018
gtk/main.cpp | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
New commits:
commit 8ceb8950e8d635ca95d2862c2dbb7d316cdf8199
Author: Tor Lillqvist <tml at collabora.com>
AuthorDate: Wed Oct 17 01:04:05 2018 +0300
Commit: Tor Lillqvist <tml at collabora.com>
CommitDate: Wed Oct 17 01:04:05 2018 +0300
Add handlers for messages from JS
Change-Id: Ifa3acfd09e10dbee4ecf43bec5735263e3655790
diff --git a/gtk/main.cpp b/gtk/main.cpp
index e7dc9f4d6..cdc711adc 100644
--- a/gtk/main.cpp
+++ b/gtk/main.cpp
@@ -42,6 +42,39 @@ static gboolean closeWebViewCb(WebKitWebView* webView, GtkWidget* window);
int loolwsd_server_socket_fd;
+static void handle_debug_message(WebKitUserContentManager *manager,
+ WebKitJavascriptResult *js_result,
+ gpointer user_data)
+{
+ JSCValue *value = webkit_javascript_result_get_js_value(js_result);
+ if (jsc_value_is_string(value))
+ std::cout << "From JS: debug: " << jsc_value_to_string(value) << std::endl;
+ else
+ std::cout << "From JS: debug: some object" << std::endl;
+}
+
+static void handle_lool_message(WebKitUserContentManager *manager,
+ WebKitJavascriptResult *js_result,
+ gpointer user_data)
+{
+ JSCValue *value = webkit_javascript_result_get_js_value(js_result);
+ if (jsc_value_is_string(value))
+ std::cout << "From JS: lool: " << jsc_value_to_string(value) << std::endl;
+ else
+ std::cout << "From JS: lool: some object" << std::endl;
+}
+
+static void handle_error_message(WebKitUserContentManager *manager,
+ WebKitJavascriptResult *js_result,
+ gpointer user_data)
+{
+ JSCValue *value = webkit_javascript_result_get_js_value(js_result);
+ if (jsc_value_is_string(value))
+ std::cout << "From JS: error: " << jsc_value_to_string(value) << std::endl;
+ else
+ std::cout << "From JS: error: some object" << std::endl;
+}
+
int main(int argc, char* argv[])
{
Log::initialize("Mobile", "trace", false, false, {});
@@ -61,6 +94,14 @@ int main(int argc, char* argv[])
// Create a "user content manager"
WebKitUserContentManager *userContentManager = WEBKIT_USER_CONTENT_MANAGER(webkit_user_content_manager_new());
+ g_signal_connect(userContentManager, "script-message-received::debug", G_CALLBACK(handle_debug_message), NULL);
+ g_signal_connect(userContentManager, "script-message-received::lool", G_CALLBACK(handle_lool_message), NULL);
+ g_signal_connect(userContentManager, "script-message-received::error", G_CALLBACK(handle_error_message), NULL);
+
+ webkit_user_content_manager_register_script_message_handler(userContentManager, "debug");
+ webkit_user_content_manager_register_script_message_handler(userContentManager, "lool");
+ webkit_user_content_manager_register_script_message_handler(userContentManager, "error");
+
// Create a browser instance
WebKitWebView *webView = WEBKIT_WEB_VIEW(webkit_web_view_new_with_user_content_manager(userContentManager));
More information about the Libreoffice-commits
mailing list