webkitgtk-3.0 causes critical error with webgadget

Linux specific forum
User avatar
Frarth
Enthusiast
Enthusiast
Posts: 241
Joined: Tue Jul 21, 2009 11:11 am
Location: On the planet
Contact:

webkitgtk-3.0 causes critical error with webgadget

Post by Frarth »

There is the problem in Linux that html text for the WebGadget cannot be changed with SetGadgetText().

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
Last edited by Frarth on Sat Jun 18, 2016 7:36 am, edited 1 time in total.
PureBasic 5.41 LTS | Xubuntu 16.04 (x32) | Windows 7 (x64)
User avatar
Frarth
Enthusiast
Enthusiast
Posts: 241
Joined: Tue Jul 21, 2009 11:11 am
Location: On the planet
Contact:

Re: webkitgtk-3.0 causes critical error with webgadget

Post by Frarth »

Going back to Debian Wheezy 7 it turns out that the above code compiles just fine, without critical warnings. Apparently a few things have changed in GTK3 with the release of Debian 8. Good old Deb7 :)
PureBasic 5.41 LTS | Xubuntu 16.04 (x32) | Windows 7 (x64)
User avatar
Frarth
Enthusiast
Enthusiast
Posts: 241
Joined: Tue Jul 21, 2009 11:11 am
Location: On the planet
Contact:

Re: webkitgtk-3.0 causes critical error with webgadget

Post by Frarth »

Out of curiosity I tried to find out if the webgadget workaround would work on Xubuntu 16.04. So I installed this new OS. Because of the bug in the help window of PB 5.42 I went back to 5.41. So keep in mind that this is the compiler I used.

First I installed libwebkitgtk-1.0 and tried to compile the code. I got the same error as on Debian 7 and LinuxMint 17 about mixing gtk2 and gtk3 symbols not being allowed in the same process.

Then I installed libwebkitgtk-3.0 and tried to compile the code. Et voilá! No errors!

Here is the code I used to load / change html strings into the webgadget. It contains snippets I found here on the forum.

Code: Select all

;HTML include file

EnableExplicit

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

DeclareC WebGadgetCallback(*WebView, *Frame, *Request, *NavigationAction, *PolicyDecision, UserData)
Declare WebGadgetText(gadget.l, html.s)
Declare WebGadgetURLS(gadget.l)

Code: Select all

; HTML

XIncludeFile "html.pbi"

ProcedureC WebGadgetCallback(*WebView, *Frame, *Request, *NavigationAction, *PolicyDecision, UserData)
  Protected URL.s
  
  URL = PeekS(webkit_web_navigation_action_get_original_uri(*NavigationAction), -1, #PB_UTF8)
  RunProgram("xdg-open", URL, "") ; does not work with Seamonkey on MATE 1.8
  
EndProcedure

Procedure WebGadgetText(gadget.l, html.s)
  ; replaces SetGadgetText for the WebGadget in Linux to set/change html text
    
  webkit_web_view_load_string(GadgetID(gadget), html, 0, 0, 0)
  
EndProcedure

Procedure WebGadgetURLS(gadget.l)
  
  g_signal_connect_data(GadgetID(gadget), "new-window-policy-decision-requested", @WebGadgetCallback(), 0, 0, 0)
  
EndProcedure
I have the above code in html.pbi and html.pb

After setting up a window with a webgadget, this loads/changes html-content. (I have not tried any script, only pure html):

Code: Select all

WebGadgetText(0, html)
I hope this helps for those who still have trouble with the webgadget on Linux.
PureBasic 5.41 LTS | Xubuntu 16.04 (x32) | Windows 7 (x64)
Post Reply