Mercurial > dwindows
comparison gtk3/dw.c @ 2990:9220cbf90ed3
GTK3: Fix deprecation warnings in WebKit2GTK 2.40 by switching to new
functions. Also fix a deadlock in the html message callback.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 04 Apr 2023 08:13:03 +0000 |
parents | fed8a986d565 |
children | 8450b87e960c |
comparison
equal
deleted
inserted
replaced
2989:fed8a986d565 | 2990:9220cbf90ed3 |
---|---|
1226 | 1226 |
1227 static void _dw_html_result_event(GObject *object, GAsyncResult *result, gpointer script_data) | 1227 static void _dw_html_result_event(GObject *object, GAsyncResult *result, gpointer script_data) |
1228 { | 1228 { |
1229 #if USE_WEBKIT2 | 1229 #if USE_WEBKIT2 |
1230 pthread_t saved_thread = _dw_thread; | 1230 pthread_t saved_thread = _dw_thread; |
1231 #if !WEBKIT_CHECK_VERSION(2, 40, 0) | |
1231 WebKitJavascriptResult *js_result; | 1232 WebKitJavascriptResult *js_result; |
1233 #endif | |
1232 #if WEBKIT_CHECK_VERSION(2, 22, 0) | 1234 #if WEBKIT_CHECK_VERSION(2, 22, 0) |
1233 JSCValue *value; | 1235 JSCValue *value; |
1234 #else | 1236 #else |
1235 JSValueRef value; | 1237 JSValueRef value; |
1236 JSGlobalContextRef context; | 1238 JSGlobalContextRef context; |
1253 htmlresultfunc = work.func; | 1255 htmlresultfunc = work.func; |
1254 user_data = work.data; | 1256 user_data = work.data; |
1255 } | 1257 } |
1256 } | 1258 } |
1257 | 1259 |
1260 #if WEBKIT_CHECK_VERSION(2, 40, 0) | |
1261 if(!(value = webkit_web_view_evaluate_javascript_finish(WEBKIT_WEB_VIEW(object), result, &error))) | |
1262 #else | |
1258 if(!(js_result = webkit_web_view_run_javascript_finish(WEBKIT_WEB_VIEW(object), result, &error))) | 1263 if(!(js_result = webkit_web_view_run_javascript_finish(WEBKIT_WEB_VIEW(object), result, &error))) |
1264 #endif | |
1259 { | 1265 { |
1260 if(htmlresultfunc) | 1266 if(htmlresultfunc) |
1261 htmlresultfunc((HWND)object, DW_ERROR_UNKNOWN, error->message, script_data, user_data); | 1267 htmlresultfunc((HWND)object, DW_ERROR_UNKNOWN, error->message, script_data, user_data); |
1262 g_error_free (error); | 1268 g_error_free(error); |
1263 _dw_thread = saved_thread; | 1269 _dw_thread = saved_thread; |
1264 return; | 1270 return; |
1265 } | 1271 } |
1266 | 1272 |
1267 #if WEBKIT_CHECK_VERSION(2, 22, 0) | 1273 #if WEBKIT_CHECK_VERSION(2, 22, 0) |
1274 #if !WEBKIT_CHECK_VERSION(2, 40, 0) | |
1268 value = webkit_javascript_result_get_js_value(js_result); | 1275 value = webkit_javascript_result_get_js_value(js_result); |
1276 #endif | |
1269 if(jsc_value_is_string(value)) | 1277 if(jsc_value_is_string(value)) |
1270 { | 1278 { |
1271 gchar *str_value = jsc_value_to_string(value); | 1279 gchar *str_value = jsc_value_to_string(value); |
1272 JSCException *exception = jsc_context_get_exception(jsc_value_get_context(value)); | 1280 JSCException *exception = jsc_context_get_exception(jsc_value_get_context(value)); |
1273 #else | 1281 #else |
1297 } | 1305 } |
1298 g_free (str_value); | 1306 g_free (str_value); |
1299 } | 1307 } |
1300 else if(htmlresultfunc) | 1308 else if(htmlresultfunc) |
1301 htmlresultfunc((HWND)object, DW_ERROR_UNKNOWN, NULL, script_data, user_data); | 1309 htmlresultfunc((HWND)object, DW_ERROR_UNKNOWN, NULL, script_data, user_data); |
1310 #if !WEBKIT_CHECK_VERSION(2, 40, 0) | |
1302 webkit_javascript_result_unref (js_result); | 1311 webkit_javascript_result_unref (js_result); |
1312 #endif | |
1303 _dw_thread = saved_thread; | 1313 _dw_thread = saved_thread; |
1304 #endif | 1314 #endif |
1305 } | 1315 } |
1306 | 1316 |
1307 #ifdef USE_WEBKIT2 | 1317 #ifdef USE_WEBKIT2 |
1308 static void _dw_html_message_event(WebKitUserContentManager *manager, WebKitJavascriptResult *js_result, gpointer *data) | 1318 static void _dw_html_message_event(WebKitUserContentManager *manager, WebKitJavascriptResult *js_result, gpointer *data) |
1309 { | 1319 { |
1320 pthread_t saved_thread = _dw_thread; | |
1310 HWND window = (HWND)data[0]; | 1321 HWND window = (HWND)data[0]; |
1311 int (*htmlmessagefunc)(HWND, char *, char *, void *) = NULL; | 1322 int (*htmlmessagefunc)(HWND, char *, char *, void *) = NULL; |
1312 void *user_data = NULL; | 1323 void *user_data = NULL; |
1313 gchar *name = (gchar *)data[1]; | 1324 gchar *name = (gchar *)data[1]; |
1314 gint handlerdata; | 1325 gint handlerdata; |
1317 #else | 1328 #else |
1318 JSValueRef value; | 1329 JSValueRef value; |
1319 JSGlobalContextRef context; | 1330 JSGlobalContextRef context; |
1320 #endif | 1331 #endif |
1321 | 1332 |
1333 _dw_thread = (pthread_t)-1; | |
1322 if(window && (handlerdata = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(window), "_dw_html_message_id")))) | 1334 if(window && (handlerdata = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(window), "_dw_html_message_id")))) |
1323 { | 1335 { |
1324 void *params[3] = { GINT_TO_POINTER(handlerdata-1), 0, window }; | 1336 void *params[3] = { GINT_TO_POINTER(handlerdata-1), 0, window }; |
1325 DWSignalHandler work = _dw_get_signal_handler(params); | 1337 DWSignalHandler work = _dw_get_signal_handler(params); |
1326 | 1338 |
1358 htmlmessagefunc(window, name, str_value, user_data); | 1370 htmlmessagefunc(window, name, str_value, user_data); |
1359 | 1371 |
1360 g_free(str_value); | 1372 g_free(str_value); |
1361 | 1373 |
1362 if(!exception) | 1374 if(!exception) |
1363 return; | 1375 { |
1376 _dw_thread = saved_thread; | |
1377 return; | |
1378 } | |
1364 } | 1379 } |
1380 | |
1365 if(htmlmessagefunc) | 1381 if(htmlmessagefunc) |
1366 htmlmessagefunc(window, name, NULL, user_data); | 1382 htmlmessagefunc(window, name, NULL, user_data); |
1383 _dw_thread = saved_thread; | |
1367 } | 1384 } |
1368 #endif | 1385 #endif |
1369 | 1386 |
1370 #ifdef USE_WEBKIT | 1387 #ifdef USE_WEBKIT |
1371 #ifdef USE_WEBKIT2 | 1388 #ifdef USE_WEBKIT2 |
11951 #ifdef USE_WEBKIT | 11968 #ifdef USE_WEBKIT |
11952 int _dw_locked_by_me = FALSE; | 11969 int _dw_locked_by_me = FALSE; |
11953 WebKitWebView *web_view; | 11970 WebKitWebView *web_view; |
11954 | 11971 |
11955 DW_MUTEX_LOCK; | 11972 DW_MUTEX_LOCK; |
11956 if((web_view = _dw_html_web_view(handle))) | 11973 if(script && (web_view = _dw_html_web_view(handle))) |
11957 #ifdef USE_WEBKIT2 | 11974 #ifdef USE_WEBKIT2 |
11975 #if WEBKIT_CHECK_VERSION(2, 40, 0) | |
11976 webkit_web_view_evaluate_javascript(web_view, script, strlen(script), NULL, NULL, NULL, _dw_html_result_event, scriptdata); | |
11977 #else | |
11958 webkit_web_view_run_javascript(web_view, script, NULL, _dw_html_result_event, scriptdata); | 11978 webkit_web_view_run_javascript(web_view, script, NULL, _dw_html_result_event, scriptdata); |
11979 #endif | |
11959 #else | 11980 #else |
11960 webkit_web_view_execute_script(web_view, script); | 11981 webkit_web_view_execute_script(web_view, script); |
11961 #endif | 11982 #endif |
11962 DW_MUTEX_UNLOCK; | 11983 DW_MUTEX_UNLOCK; |
11963 return DW_ERROR_NONE; | 11984 return DW_ERROR_NONE; |