comparison gtk3/dw.c @ 2028:fb292c267f52

GTK3: Fixes for building on older webkit2gtk versions.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 12 Nov 2019 00:19:09 +0000
parents ed9217a95924
children 2cbbbc850b8d
comparison
equal deleted inserted replaced
2027:ed9217a95924 2028:fb292c267f52
33 #include <gdk/gdkkeysyms.h> 33 #include <gdk/gdkkeysyms.h>
34 34
35 35
36 #ifdef USE_WEBKIT2 36 #ifdef USE_WEBKIT2
37 #include <webkit2/webkit2.h> 37 #include <webkit2/webkit2.h>
38 #if !WEBKIT_CHECK_VERSION(2, 22, 0)
39 #include <JavaScriptCore/JavaScript.h>
40 #endif
38 #else 41 #else
39 #include <webkit/webkit.h> 42 #include <webkit/webkit.h>
40 #endif 43 #endif
41 44
42 #include <gdk-pixbuf/gdk-pixbuf.h> 45 #include <gdk-pixbuf/gdk-pixbuf.h>
1196 1199
1197 static void _html_result_event(GObject *object, GAsyncResult *result, gpointer script_data) 1200 static void _html_result_event(GObject *object, GAsyncResult *result, gpointer script_data)
1198 { 1201 {
1199 #if USE_WEBKIT2 1202 #if USE_WEBKIT2
1200 WebKitJavascriptResult *js_result; 1203 WebKitJavascriptResult *js_result;
1204 #if WEBKIT_CHECK_VERSION(2, 22, 0)
1201 JSCValue *value; 1205 JSCValue *value;
1206 #else
1207 JSValueRef value;
1208 JSGlobalContextRef context;
1209 #endif
1202 GError *error = NULL; 1210 GError *error = NULL;
1203 int (*htmlresultfunc)(HWND, int, char *, void *, void *) = NULL; 1211 int (*htmlresultfunc)(HWND, int, char *, void *, void *) = NULL;
1204 gint handlerdata = GPOINTER_TO_INT(g_object_get_data(object, "_dw_html_result_id")); 1212 gint handlerdata = GPOINTER_TO_INT(g_object_get_data(object, "_dw_html_result_id"));
1205 void *user_data = NULL; 1213 void *user_data = NULL;
1206 1214
1224 htmlresultfunc((HWND)object, DW_ERROR_UNKNOWN, error->message, user_data, script_data); 1232 htmlresultfunc((HWND)object, DW_ERROR_UNKNOWN, error->message, user_data, script_data);
1225 g_error_free (error); 1233 g_error_free (error);
1226 return; 1234 return;
1227 } 1235 }
1228 1236
1237 #if WEBKIT_CHECK_VERSION(2, 22, 0)
1229 value = webkit_javascript_result_get_js_value(js_result); 1238 value = webkit_javascript_result_get_js_value(js_result);
1230 if(jsc_value_is_string(value)) 1239 if(jsc_value_is_string(value))
1231 { 1240 {
1232 gchar *str_value = jsc_value_to_string(value); 1241 gchar *str_value = jsc_value_to_string(value);
1233 JSCException *exception = jsc_context_get_exception(jsc_value_get_context(value)); 1242 JSCException *exception = jsc_context_get_exception(jsc_value_get_context(value));
1234 1243 #else
1244 context = webkit_javascript_result_get_global_context(js_result);
1245 value = webkit_javascript_result_get_value(js_result);
1246 if (JSValueIsString(context, value))
1247 {
1248 JSStringRef js_str_value;
1249 gchar *str_value;
1250 gsize str_length;
1251
1252 js_str_value = JSValueToStringCopy(context, value, NULL);
1253 str_length = JSStringGetMaximumUTF8CStringSize(js_str_value);
1254 str_value = (gchar *)g_malloc (str_length);
1255 JSStringGetUTF8CString(js_str_value, str_value, str_length);
1256 JSStringRelease(js_str_value);
1257 #endif
1258
1235 if(htmlresultfunc) 1259 if(htmlresultfunc)
1236 { 1260 {
1261 #if WEBKIT_CHECK_VERSION(2, 22, 0)
1237 if(exception) 1262 if(exception)
1238 htmlresultfunc((HWND)object, DW_ERROR_UNKNOWN, (char *)jsc_exception_get_message(exception), user_data, script_data); 1263 htmlresultfunc((HWND)object, DW_ERROR_UNKNOWN, (char *)jsc_exception_get_message(exception), user_data, script_data);
1239 else 1264 else
1265 #endif
1240 htmlresultfunc((HWND)object, DW_ERROR_NONE, str_value, user_data, script_data); 1266 htmlresultfunc((HWND)object, DW_ERROR_NONE, str_value, user_data, script_data);
1241 } 1267 }
1242 g_free (str_value); 1268 g_free (str_value);
1243 } 1269 }
1244 else if(htmlresultfunc) 1270 else if(htmlresultfunc)
2249 else if(flags & (DW_MB_YESNO | DW_MB_YESNOCANCEL)) 2275 else if(flags & (DW_MB_YESNO | DW_MB_YESNOCANCEL))
2250 gtkbuttons = GTK_BUTTONS_YES_NO; 2276 gtkbuttons = GTK_BUTTONS_YES_NO;
2251 2277
2252 DW_MUTEX_LOCK; 2278 DW_MUTEX_LOCK;
2253 dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL | GTK_DIALOG_USE_HEADER_BAR, gtkicon, gtkbuttons, "%s", title); 2279 dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL | GTK_DIALOG_USE_HEADER_BAR, gtkicon, gtkbuttons, "%s", title);
2254 gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), outbuf); 2280 gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), "%s", outbuf);
2255 if(flags & DW_MB_YESNOCANCEL) 2281 if(flags & DW_MB_YESNOCANCEL)
2256 gtk_dialog_add_button(GTK_DIALOG(dialog), "Cancel", GTK_RESPONSE_CANCEL); 2282 gtk_dialog_add_button(GTK_DIALOG(dialog), "Cancel", GTK_RESPONSE_CANCEL);
2257 response = gtk_dialog_run(GTK_DIALOG(dialog)); 2283 response = gtk_dialog_run(GTK_DIALOG(dialog));
2258 gtk_widget_destroy(dialog); 2284 gtk_widget_destroy(dialog);
2259 DW_MUTEX_UNLOCK; 2285 DW_MUTEX_UNLOCK;