Several WebGadget issues [5.24 LTS]

Post bugreports for the Linux version here
User avatar
Kukulkan
Addict
Addict
Posts: 1352
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Several WebGadget issues [5.24 LTS]

Post by Kukulkan »

Hello,

1) NavigationCallback does not work

I shortened the example from the documentation regarding NavigationCallback:

Code: Select all

Procedure NavigationCallback(Gadget, Url$)
  MessageRequester("WebGadget Callback!", Url$)
  ProcedureReturn #True
EndProcedure 

If OpenWindow(0, 0, 0, 600, 300, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
  WebGadget(0, 10, 10, 580, 280, "http://www.purebasic.com") 
  SetGadgetAttribute(0, #PB_Web_NavigationCallback, @NavigationCallback())
  Repeat 
  Until WaitWindowEvent() = #PB_Event_CloseWindow 
EndIf
On several Xubuntu and Kubuntu machines, compiled with PureBasic 5.24 LTS, it simply does not work. No matter which link I click, it ignores the callback.

2) GetGadgetItemText(WebGadgetID, #PB_Web_SelectedText) fails

Code: Select all

#menuCopy = 1

If OpenWindow(0, 0, 0, 600, 300, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
  WebGadget(0, 10, 10, 580, 280, "http://www.purebasic.com") 
  AddKeyboardShortcut(0, #PB_Shortcut_Control | #PB_Shortcut_C, #menuCopy)
  Repeat 
    ev = WaitWindowEvent()
    If ev = #PB_Event_Menu
      If EventMenu() = #menuCopy
        Text.s = GetGadgetItemText(0, #PB_Web_SelectedText)
        MessageRequester("Debug", "Detected CTRL+C. Text: [" + Text.s + "]")
      EndIf
    EndIf
    
  Until ev = #PB_Event_CloseWindow 
EndIf
Try to select something and press CTRL+C. On Linux, the result is always empty.

3) Inconsistent behaviour on different platforms

On Windows and MacOS, JavaScript is enabled by default. On Linux, it is disabled. The hack from here (http://forums.purebasic.fr/english/view ... 15&t=60875) makes the executable crash on more complex HTML pages. Please, can you enable JS by default on Linux, too?

Can you please fix? Maybe also for the 5.24 LTS version?

Kukulkan
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Several WebGadget issues [5.24 LTS]

Post by Shardik »

Kukulkan wrote:On several Xubuntu and Kubuntu machines, compiled with PureBasic 5.24 LTS, it simply does not work. No matter which link I click, it ignores the callback.
(1) and (2) don't work on Linux and MacOS X because these features are only implemented for Windows:
[color=#0040FF]Help for WebGadget[/color] wrote:- SetGadgetItemText(): With #PB_Web_HtmlCode as 'Item' html code can be streamed into the Gadget. (Windows only)
.
.
- SetGadgetAttribute(): Set the following attributes (Windows only):

#PB_Web_ScrollX : Set the horizontal scrolling position.
#PB_Web_ScrollY : Set the vertical scrolling position.
#PB_Web_BlockPopups : Block popup windows. #PB_EventType_PopupWindow is fired if this setting is enabled.
#PB_Web_BlockPopupMenu: Block standard the popup menu. #PB_EventType_PopupMenu is fired if this setting is enabled.
#PB_Web_NavigationCallback: Set a callback for monitoring (and disabling) navigation.
For the navigation callback I have already demonstrated how to do it for Linux and MacOS X and even posted a feature request in spring 2013... :wink:
http://www.purebasic.fr/english/viewtop ... 15&t=54049
http://www.purebasic.fr/english/viewtop ... =3&t=54007

How to load customized HTML code into the WebGadget, I have already demostrated on the German forum for Linux and MacOS X:
http://www.purebasic.fr/german/viewtopi ... 1&start=13
User avatar
Kukulkan
Addict
Addict
Posts: 1352
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: Several WebGadget issues [5.24 LTS]

Post by Kukulkan »

Hello Shardik,

thank you very much for that. Yes, you are right, there is "Windows only". I missed that :-( Unbelievable that Fred did not implement. Even if it is not that much work as we can see in your examples.

Now I have to create my own platform independent versions of that function. Sadly, on Linux, I have problems with several types of crashes if I include those functions. Small test files work fine, my very big project is crashing at WaitWindowEvent() with something like this:
*** longjmp causes uninitialized stack frame ***: ./purebasic_compilation2.out terminated
======= Backtrace: =========
/lib/i386-linux-gnu/libc.so.6(+0x696de)[0xb6b936de]
/lib/i386-linux-gnu/libc.so.6(__fortify_fail+0x6b)[0xb6c260eb]
/lib/i386-linux-gnu/libc.so.6(+0xfbf9a)[0xb6c25f9a]
/lib/i386-linux-gnu/libc.so.6(__longjmp_chk+0x42)[0xb6c25f02]
/usr/lib/i386-linux-gnu/libwebkitgtk-1.0.so.0(+0x270e4c)[0xb51b7e4c]
./purebasic_compilation2.out(jpeg_CreateDecompress+0x6b)[0x820266b]
/usr/lib/i386-linux-gnu/libwebkitgtk-1.0.so.0(+0x2718bd)[0xb51b88bd]
/usr/lib/i386-linux-gnu/libwebkitgtk-1.0.so.0(+0x271a28)[0xb51b8a28]
/usr/lib/i386-linux-gnu/libwebkitgtk-1.0.so.0(+0x2516b9)[0xb51986b9]
/usr/lib/i386-linux-gnu/libwebkitgtk-1.0.so.0(+0x226720)[0xb516d720]
/usr/lib/i386-linux-gnu/libwebkitgtk-1.0.so.0(+0x226860)[0xb516d860]
/usr/lib/i386-linux-gnu/libwebkitgtk-1.0.so.0(+0x250529)[0xb5197529]
/usr/lib/i386-linux-gnu/libwebkitgtk-1.0.so.0(+0x802a1d)[0xb5749a1d]
/usr/lib/i386-linux-gnu/libwebkitgtk-1.0.so.0(+0x802d54)[0xb5749d54]
/usr/lib/i386-linux-gnu/libwebkitgtk-1.0.so.0(+0x86ca94)[0xb57b3a94]
/usr/lib/i386-linux-gnu/libwebkitgtk-1.0.so.0(+0x86cc68)[0xb57b3c68]
/usr/lib/i386-linux-gnu/libwebkitgtk-1.0.so.0(+0x863162)[0xb57aa162]
/usr/lib/i386-linux-gnu/libwebkitgtk-1.0.so.0(+0x10426f7)[0xb5f896f7]
/usr/lib/i386-linux-gnu/libgio-2.0.so.0(+0x553bb)[0xb4d6e3bb]
/usr/lib/i386-linux-gnu/libgio-2.0.so.0(+0x7dd71)[0xb4d96d71]
/usr/lib/i386-linux-gnu/libgio-2.0.so.0(+0x7ddab)[0xb4d96dab]
/lib/i386-linux-gnu/libglib-2.0.so.0(+0x43c50)[0xb6e6dc50]
/lib/i386-linux-gnu/libglib-2.0.so.0(g_main_context_dispatch+0x137)[0xb6e710a7]
/lib/i386-linux-gnu/libglib-2.0.so.0(+0x47468)[0xb6e71468]
/lib/i386-linux-gnu/libglib-2.0.so.0(g_main_context_iteration+0x38)[0xb6e71528]
/usr/lib/i386-linux-gnu/libgtk-x11-2.0.so.0(gtk_main_iteration_do+0x31)[0xb7304711]
./purebasic_compilation2.out[0x81020fc]
./purebasic_compilation2.out[0x806cad4]
======= Memory map: ========
08048000-082a2000 r-xp 00000000 08:01 1100885...
Just trying to find out the reason...

Any idea for some replacement of GetGadgetItemText(WebGadgetID, #PB_Web_SelectedText)?

Kukulkan
User avatar
Kukulkan
Addict
Addict
Posts: 1352
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: Several WebGadget issues [5.24 LTS]

Post by Kukulkan »

Hi,

this was a hard one, but I found the problem to reproduce easily. It seems that, if UseJPEGImageDecoder() is used, there is a problem with webkitgtk-1.0. Somehow a conflict? Not close enough to system programming to get it :-(

Run this code:

Code: Select all

EnableExplicit

Define path.s = "http://www.yahoo.com"

UseJPEGImageDecoder(); <=== COMMENT THIS TO MAKE IT WORK

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

Procedure EnableJSforWebGadget(WebgadgetID.i)
  Protected WebkitSettings.i
  ; ----- Get Webkit's default setting (with scripting languages enabled by default)
  WebkitSettings = webkit_web_settings_new()
  ; ----- Store Webkit's default settings in WebGadget
  webkit_web_view_set_settings(GadgetID(WebgadgetID.i), WebkitSettings)
EndProcedure

OpenWindow(0, 100, 100, 800, 600, "WebGadget", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
WebGadget(0, 10, 10, 780, 580, path.s)

EnableJSforWebGadget(0)

Repeat 
  Define Event.i     = WaitWindowEvent(200); <=== CRASH
  Define EventType.i = EventType()   
  Delay(1)
Until Event.i = #PB_Event_CloseWindow
For me this crashes at WaitWindowEvent(). Sadly, I need UseJPEGImageDecoder() as my program loads a lot of JPG images.

Is it also crashing for you?

[EDIT]Found that it also crashes with websites like yahoo. So the repro got smaller.[/EDIT]
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Several WebGadget issues [5.24 LTS]

Post by Shardik »

Kukulkan wrote:Is it also crashing for you?
Yes, your example is also crashing on my Kubuntu 14.04 x64 with PB 5.24 x64 and 5.31 x64.

I was even able to further track it down:
The combination of UseJPEGImageDecoder() together with webkit_web_view_get_settings() (or alternatively webkit_web_settings_new() or webkit_web_view_set_settings()) produces a crash with the following error message:
PureBasic Debugger wrote:The debugged executable quit unexpectedly.
When either commenting out

Code: Select all

UseJPEGImageDecoder()
or

Code: Select all

WebKitSettings = webkit_web_view_get_settings(GadgetID(0))
no crash will occur anymore... :oops:

Code: Select all

ImportC "-lwebkitgtk-1.0"
  webkit_web_view_get_settings (*WebKitWebView)
EndImport

UseJPEGImageDecoder() ; <= Comment this to make it work!

OpenWindow(0, 100, 100, 800, 600, "WebGadget crash demo")
WebGadget(0, 10, 10, 780, 580, "http://yahoo.com")

WebKitSettings = webkit_web_view_get_settings(GadgetID(0)) ; <= Or comment this to make it work!

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Several WebGadget issues [5.24 LTS]

Post by Shardik »

Kukulkan wrote:Any idea for some replacement of GetGadgetItemText(WebGadgetID, #PB_Web_SelectedText)?
Try this example which demonstrates how to implement the equivalent code for the following functions which are only available in Windows:
- GetGadgetItemText(WebGadgetID, #PB_Web_HtmlCode)
- GetGadgetItemText(WebGadgetID, #PB_Web_SelectedText)

Code: Select all

ImportC "-lwebkitgtk-1.0"
  webkit_web_view_can_copy_clipboard(*WebView)
  webkit_web_view_copy_clipboard(*WebView)
  webkit_web_view_has_selection(*WebView)
  webkit_web_view_load_string(*WebView, Content.P-UTF8, *MIMEType, *Encoding,
    *BaseURI)
EndImport

OpenWindow(0, 100, 100, 270, 110, "WebGadget demo")
WebGadget(0, 5, 5, 260, 60, "")
ButtonGadget(1, 70, 75, 120, 25, "Get selected text")

HTML.S = "<html>" +
  "<body>" +
  "The quick brown fox jumps over the lazy dog." +
  "</body>" +
  "</html>"
; ----- Load HTML into WebGadget
webkit_web_view_load_string(GadgetID(0), HTML, 0, 0, 0)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      If webkit_web_view_has_selection(GadgetID(0)) = #False
        MessageRequester("Error", "No text is selected!")
      Else
        If webkit_web_view_can_copy_clipboard(GadgetID(0)) = #False
          MessageRequester("Error",
            "The copying of selected text to the clipboard failed!")
        Else
          ; ----- Copy selected text to clipboard
          webkit_web_view_copy_clipboard(GadgetID(0))
          ; ----- Display clipboard contents
          MessageRequester("Info", "Selected text: " + #DQUOTE$ +
            GetClipboardText() + #DQUOTE$)
        EndIf
      EndIf  
  EndSelect
ForEver
User avatar
Kukulkan
Addict
Addict
Posts: 1352
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: Several WebGadget issues [5.24 LTS]

Post by Kukulkan »

Thank you Shardik! Will give it a try...
vwidmer
Enthusiast
Enthusiast
Posts: 282
Joined: Mon Jan 20, 2014 6:32 pm

Re: Several WebGadget issues [5.24 LTS]

Post by vwidmer »

I tried this code and while I was able to load more then I was before it just crashes now.

Any one have any improvements or fixes on this?
WARNING: I dont know what I am doing! I just put stuff here and there and sometimes like magic it works. So please improve on my code and post your changes so I can learn more. TIA
Post Reply