Page 1 of 1

Re: [Done] PB V4.70B1 - No luck with the WebGadget()

Posted: Wed Mar 13, 2013 9:46 pm
by Shardik
Guimauve wrote:With the new librairy, the WebGadget() finally work but I get a [WARNING] DEBUG: NP_Initialize succeeded
Fred wrote:It's a warning which comes from the lib, sounds more like a debug message than a warning anyway.
This WebKit warning is displayed if the embedding of scripting lanuages is enabled which is the WebKit default setting. By disabling the embedding of scripts the above warning will disappear:

Code: Select all

#G_TYPE_INT = 6 << 2

ImportC "-lwebkitgtk-1.0"
  webkit_web_settings_new()
  webkit_web_view_set_settings(*WebkitWebView, *WebkitSettings)
EndImport

Define Value.GValue

OpenWindow(0, 200, 100, 600, 300, "WebGadget")
WebGadget(0, 10, 10, 580, 280, "http://www.purebasic.com")

; ----- Get current webkit settings
WebkitSettings = webkit_web_settings_new()

; ----- Disable embedding of scripting languages
Value\g_type = #G_TYPE_INT
g_value_set_int_(Value, 0)
g_object_set_property_(WebkitSettings, "enable-scripts", @Value)

; ----- Store changed settings
webkit_web_view_set_settings(GadgetID(0), WebkitSettings)

Repeat 
Until WaitWindowEvent() = #PB_Event_CloseWindow

Re: [Done] PB V4.70B1 - No luck with the WebGadget()

Posted: Sun Jun 12, 2016 8:22 am
by Frarth
Shardik wrote:
Guimauve wrote:With the new librairy, the WebGadget() finally work but I get a [WARNING] DEBUG: NP_Initialize succeeded
Fred wrote:It's a warning which comes from the lib, sounds more like a debug message than a warning anyway.
This WebKit warning is displayed if the embedding of scripting lanuages is enabled which is the WebKit default setting. By disabling the embedding of scripts the above warning will disappear:

Code: Select all

#G_TYPE_INT = 6 << 2

ImportC "-lwebkitgtk-1.0"
  webkit_web_settings_new()
  webkit_web_view_set_settings(*WebkitWebView, *WebkitSettings)
EndImport

Define Value.GValue

OpenWindow(0, 200, 100, 600, 300, "WebGadget")
WebGadget(0, 10, 10, 580, 280, "http://www.purebasic.com")

; ----- Get current webkit settings
WebkitSettings = webkit_web_settings_new()

; ----- Disable embedding of scripting languages
Value\g_type = #G_TYPE_INT
g_value_set_int_(Value, 0)
g_object_set_property_(WebkitSettings, "enable-scripts", @Value)

; ----- Store changed settings
webkit_web_view_set_settings(GadgetID(0), WebkitSettings)

Repeat 
Until WaitWindowEvent() = #PB_Event_CloseWindow
How would that be for gtk3? when I use this code the debugger crashes with a message that mixing gtk2 and gtk3 symbols is not allowed.

Re: [Done] PB V4.70B1 - No luck with the WebGadget()

Posted: Sun Jun 12, 2016 11:34 am
by Frarth
OK found it, "-lwebkitgtk-3.0" should be used.

It may have been mentioned already, but to simply load a html string into the WebGadget on Linux a workaround is needed, like:

Code: Select all

ImportC "-lwebkitgtk-3.0" ; should be 3, not 1
  webkit_web_settings_new()
  webkit_web_view_load_string(*WebView, Content.P-UTF8, *MIMEType, *Encoding, *BaseURI)
  webkit_web_view_set_settings(*WebkitWebView, *WebkitSettings)
EndImport

Procedure WebGadgetText(gadget.l, html.s)
  ; replaces SetGadgetText for the WebGadget in Linux to set/change text
  webkit_web_view_load_string(GadgetID(gadget), html, 0, 0, 0)
  WebkitSettings = webkit_web_settings_new()
  webkit_web_view_set_settings(GadgetID(gadget), WebkitSettings)
EndProcedure
I pulled this from the net and adjusted it a little. Seems to work fine. But I suppress debug warnings. There's no harm, but they are annoying.