NavigationCallback for WebGadget

Linux specific forum
User avatar
Shardik
Addict
Addict
Posts: 2060
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: NavigationCallback for WebGadget

Post by Shardik »

Since PB 5.40 the default GTK version is no longer GTK2 but GTK3 although it's possible in PB 5.4x to use GTK2 as a subsystem (select "Compiler > Compiler Options..." in the menu bar of the IDE, select the tab "Compiler Options" and behind "Library Subsystem:" enter "gtk2").

In order to use the WebGadget you have to utilize WebKitGTK which requires one of these 2 libraries (you only have to install one of them if you don't need both):
- libwebkitgtk-1.0-0 (for GTK2)
- libwebkitgtk-3.0-0 (for GTK3)

By the way: WebKitGTK is deprecated. The current version WebKitGTK2 is not supported by PureBasic because the WebGadget is still compiled with the old WebKitGTK...

Depending on your distribution one or both of these libraries might be installed already.

I have modified my code example from above to now work equally well with both GTK2 and GTK3 in both PB 5.3x and PB 5.4x and in x86 and x64 distributions. For the following distributions I had to install the following libraries with the appropriate console commands (of course you may also use Synaptic or Aptitude on Debian/Ubuntu derived distributions):

Kubuntu 16.04 x86 with KDE, Ubuntu 16.04 x86 with Unity and Xubuntu 16.04 x86 with Xfce
I found out that installing libwebkitgtk-1.0/libwebkitgtk-3.0 would require a whopping 1.669 MB of additional disk space because the dev and debug versions would also be installed. I therefore decided to install libwebkitgtk-1.0-0/libwebkitgtk-3.0-0 which only required about 40 MB. The drawback is that you have to always specify the complete path in your ImportC statement. When installing the dev version a simple

Code: Select all

ImportC "-lwebkitgtk-1.0"
would be sufficient...

These are the console commands to install the libraries on Debian/Ubuntu derived distributions (it's only necessary to install one of these if you don't need both GTK2 and GTK3):

Code: Select all

sudo apt-get install libwebkitgtk-1.0-0
sudo apt-get install libwebkitgtk-3.0-0
In order to compile GTK2 programs you also have to install the GTK2 dev libs:

Code: Select all

sudo apt-get install libgtk2.0-dev
Lubuntu 14.04 x86 with LXDE (necessary only for GTK2)

Code: Select all

sudo apt-get install libwebkitgtk-1.0-0
Ubuntu MATE 14.04 x86 with MATE (necessary only for GTK2)

Code: Select all

sudo apt-get install libwebkitgtk-1.0-0
Linux Mint 17.3 x64 "Rosa" with Cinnamon
Nothing had to be done. All libraries for GTK2 and GTK3 were already preinstalled.


The distributions above are all derived from Debian/Ubuntu and utilize the Debian package management. Therefore I also tried a distribution with RPM packages derived from Red Hat (unfortunately the package names differ):

Fedora 23 x86 with Gnome 3
For GTK2:

Code: Select all

sudo dnf install webkitgtk
webkitgtk2 is already installed by default!

And finally this is my modified example (for Fedora you have to put the ImportC block in comments and uncomment the Fedora ImportC line):

Code: Select all

EnableExplicit

ImportC "-lgobject-2.0"
  g_signal_connect_data(*Instance, Signal.P-UTF8, *Callback, *UserData, *ClosureNotify, ConnectFlags.I)
EndImport

CompilerIf (#PB_Compiler_Version < 540 And Subsystem("gtk3") = #False) Or
  (#PB_Compiler_Version >= 540 And Subsystem("gtk2") = #True)
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
    ImportC "/usr/lib/i386-linux-gnu/libwebkitgtk-1.0.so.0"   ; Ubuntu/Kubuntu/Xubuntu x86 with GTK2
  CompilerElse
    ImportC "/usr/lib/x86_64-linux-gnu/libwebkitgtk-1.0.so.0" ; Ubuntu/Kubuntu/Xubuntu x64 with GTK2
  CompilerEndIf
;   ImportC "/usr/lib/libwebkitgtk-1.0.so.0"                  ; Fedora 23 with GTK2
CompilerElse
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
    ImportC "/usr/lib/i386-linux-gnu/libwebkitgtk-3.0.so.0"   ; Ubuntu/Kubuntu/Xubuntu x86 with GTK3
  CompilerElse
    ImportC "/usr/lib/x86_64-linux-gnu/libwebkitgtk-3.0.so.0" ; Ubuntu/Kubuntu/Xubuntu x64 with GTK3
  CompilerEndIf
;   ImportC "/usr/lib/libwebkitgtk-3.0.so.0"                  ; Fedora 23 x86 with GTK3
CompilerEndIf
    webkit_web_navigation_action_get_original_uri(*NavigationAction)
    webkit_web_policy_decision_ignore(*PolicyDecision)
    webkit_web_policy_decision_use(*PolicyDecision)
EndImport

Enumeration
  #WEBKIT_NAVIGATION_RESPONSE_ACCEPT
  #WEBKIT_NAVIGATION_RESPONSE_IGNORE
EndEnumeration

ProcedureC WebGadgetCallback(*WebView, *Frame, *Request, *NavigationAction, *PolicyDecision, UserData)
  If PeekS(webkit_web_navigation_action_get_original_uri(*NavigationAction), -1, #PB_UTF8) = "http://www.purebasic.com/news.php"
    MessageRequester("", "No news today!")
    webkit_web_policy_decision_ignore(*PolicyDecision)
  Else
    webkit_web_policy_decision_use(*PolicyDecision)
  EndIf
EndProcedure

If OpenWindow(0, 200, 100, 600, 300, "WebGadget")
  WebGadget(0, 10, 10, 580, 280, "http://www.purebasic.com")
 
  g_signal_connect_data(GadgetID(0), "navigation-policy-decision-requested", @WebGadgetCallback(), 0, 0, 0)
 
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
At last these were the warnings I did encounter (only with GTK3):

Fedora 23 x86 with Gnome 3, Ubuntu 16.04 x86 with Unity, Xubuntu 16.04 x86 with Xfce
[WARNING] Gtk(MESSAGE): GtkDialog mapped without a transient parent. This is discouraged.
This warning has already been posted several times in the Linux bugs subforum. Fred's response:
Fred wrote:even gedit shipped with Ubuntu has some gtk error here when launched from CLI, so I don't think it's worth the time investigating.
Linux Mint 17.3 x64 "Rosa" with Cinnamon, Lubuntu 14.04 x86 with LXDE, Ubuntu MATE 14.04 x86 with LXDE
[WARNING] GLib-GObject (CRITICAL): g_object_ref: assertion 'object->ref_count > 0' failed

Fedora 23 x86 with Gnome 3
[WARNING] Gnome Shell Browser Plugin (DEBUG): plugin loaded

The only distributions without warnings were Kubuntu 14.04 x86 and Kubuntu 16.04 x86 both with KDE.
Last edited by Shardik on Tue Sep 06, 2016 8:23 am, edited 1 time in total.
User avatar
Frarth
Enthusiast
Enthusiast
Posts: 241
Joined: Tue Jul 21, 2009 11:11 am
Location: On the planet
Contact:

Re: NavigationCallback for WebGadget

Post by Frarth »

What PB version 5.4x did you use? With my example shown in this thread (http://www.purebasic.fr/english/viewtop ... 15&t=65951) I did not have any error message using PB 5.41 on Xubuntu 16.04.
PureBasic 5.41 LTS | Xubuntu 16.04 (x32) | Windows 7 (x64)
User avatar
Shardik
Addict
Addict
Posts: 2060
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: NavigationCallback for WebGadget

Post by Shardik »

I tested with PB 5.42 (and in some cases also with PB 5.31). And what I posted are warnings (not errors that terminate the compilation) from the debugger's error log (IDE's menu: Debugger > Error Log > Show Error Log). If you have disabled "Show Error Log", you won't see them.
User avatar
Frarth
Enthusiast
Enthusiast
Posts: 241
Joined: Tue Jul 21, 2009 11:11 am
Location: On the planet
Contact:

Re: NavigationCallback for WebGadget

Post by Frarth »

Show Error Log is enabled here. I was not talking about fatal compilation errors but [CRITICAL] warnings like:

Code: Select all

GLib-GObject (CRITICAL): g_object_ref: assertion 'object->ref_count > 0' failed
I have not found the time yet to try your code, but I'll try to do that this weekend.
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: NavigationCallback for WebGadget

Post by Frarth »

@Shardik: I tested your code and had no warning or error messages. I checked again and debug error messages are turned on. I use the Integrated IDE Debugger with warning level set to Display Warnings.

Code: Select all

[18:04:26] Waiting for executable to start...
[18:04:27] Executable type: Linux - x86  (32bit, Unicode, Thread, Purifier)
[18:04:27] Executable started.
[18:04:34] The Program execution has finished.
As I said earlier, I use Xubuntu 16.04 with PB 5.41

These are the webkit related libraries installed:

- gir1.2-javascriptcoregtk-3.0
- gir1.2-javascriptcoregtk-4.0
- gir1.2-webkit2-3.0
- libjavascriptcoregtk-1.0-0
- libjavascriptcoregtk-1.0-dev
- libjavascriptcoregtk-3.0-0
- libjavascriptcoregtk-3.0-dev
- libjavascriptcoregtk-4.0-18
- libwebkit2gtk-3.0-25 (API layer)
- libwebkit2gtk-3.0-dev
- libwebkit2gtk-4.0-37
- libwebkit2gtk-4.0-37-gtk2
- libwebkitgtk-1.0-0
- libwebkitgtk-1.0-common
- libwebkitgtk-3.0-0
- libwebkitgtk-3.0-common
- libwebkitgtk-3.0-dev
- libwebkitgtk-common-dev
- libwebkitgtk-dev

EDIT: BTW, I never had this warning message you mentioned: "[WARNING] Gtk(MESSAGE): GtkDialog mapped without a transient parent. This is discouraged." The post you referred to mentioned the MessageRequester, but the warning has not shown up so far with PB 5.41.
PureBasic 5.41 LTS | Xubuntu 16.04 (x32) | Windows 7 (x64)
Post Reply