There are various examples on the forum to get this done by importing webkitgtk-1.0 routines. On LinuxMint 17 however this causes a "mixing gtk2 and gtk3 symbols" error.
When using the webkitgtk3.0 library the error is gone. However, when running examples, a critical error "GLib-GObject (CRITICAL): g_object_ref: assertion 'object->ref_count > 0' failed" occurs on the WaitWindowEvent() procedure. This is next to the usual "DEBUG: NP_Initialize" warnings.
Here is the log:
[21:10:11] Waiting for executable to start...
[21:10:11] Executable type: Linux - x86 (32bit, Unicode, Thread, Purifier)
[21:10:12] Executable started.
[21:10:12] [WARNING] webgadget5.pb (Line: 34)
[21:10:12] [WARNING] DEBUG: NP_Initialize
[21:10:12] [WARNING] webgadget5.pb (Line: 34)
[21:10:12] [WARNING] DEBUG: NP_Initialize succeeded
[21:10:12] [WARNING] webgadget5.pb (Line: 34)
[21:10:12] [WARNING] DEBUG: NP_Initialize
[21:10:12] [WARNING] webgadget5.pb (Line: 34)
[21:10:12] [WARNING] DEBUG: NP_Initialize succeeded
[21:10:12] [WARNING] webgadget5.pb (Line: 34)
[21:10:12] [WARNING] DEBUG: NP_Initialize
[21:10:12] [WARNING] webgadget5.pb (Line: 34)
[21:10:12] [WARNING] DEBUG: NP_Initialize succeeded
[21:10:12] [WARNING] webgadget5.pb (Line: 34)
[21:10:12] [WARNING] DEBUG: NP_Initialize
[21:10:12] [WARNING] webgadget5.pb (Line: 34)
[21:10:12] [WARNING] DEBUG: NP_Initialize succeeded
[21:10:12] [WARNING] webgadget5.pb (Line: 40)
[21:10:12] [WARNING] GLib-GObject (CRITICAL): g_object_ref: assertion 'object->ref_count > 0' failed
[21:10:12] [WARNING] webgadget5.pb (Line: 40)
[21:10:12] [WARNING] GLib-GObject (CRITICAL): g_object_unref: assertion 'object->ref_count > 0' failed
[21:10:14] [WARNING] webgadget5.pb (Line: 40)
[21:10:14] [WARNING] GLib-GObject (CRITICAL): g_object_ref: assertion 'object->ref_count > 0' failed
[21:10:14] [WARNING] webgadget5.pb (Line: 40)
[21:10:14] [WARNING] GLib-GObject (CRITICAL): g_object_unref: assertion 'object->ref_count > 0' failed
[21:10:17] The Program execution has finished.
This is the code causing it:
Code: Select all
EnableExplicit
#HTML = "<!doctype html>" +
"<html lang='en'>" +
" <head>" +
" <meta http-equiv='content-type' content='text/html; charset=UTF-8'>" +
" </head>" +
" <body>" +
" <a href='http://www.purebasic.com' target='_self'>Open here</a><br>" +
" <a href='http://www.purebasic.com' target='_blank'>Open new window</a>" +
" </body>" +
"</html>"
ImportC "-lgobject-2.0"
g_signal_connect_data(*Instance, Signal.P-UTF8, *Callback, *UserData,
*ClosureNotify, ConnectFlags.I)
EndImport
ImportC "-lwebkitgtk-3.0"
webkit_web_navigation_action_get_original_uri(*NavigationAction)
webkit_web_view_load_string(*WebView, Content.P-UTF8, *MIMEType, *Encoding,
*BaseURI)
EndImport
ProcedureC WebGadgetCallback(*WebView, *Frame, *Request, *NavigationAction,
*PolicyDecision, UserData)
Protected URL.S = PeekS(webkit_web_navigation_action_get_original_uri(*NavigationAction),
-1, #PB_UTF8)
; ----- Open URL in new window of default browser
RunProgram("xdg-open", URL, GetCurrentDirectory())
EndProcedure
OpenWindow(0, 100, 100, 640, 480, "WebGadget demo")
WebGadget(0, 5, 5, 630, 470, "")
webkit_web_view_load_string(GadgetID(0), #HTML, 0, 0, 0)
g_signal_connect_data(GadgetID(0), "new-window-policy-decision-requested",
@WebGadgetCallback(), 0, 0, 0)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow