4

I need to embed a very simple browser ( can parse HTML, and JS Ext ) in a Gtk Widget hopefully in gtkmm. I looked into gtkmozembed, but the c++ wrapper is very out dated, so I tried to just write it in C, but I'm already committed to Gtk+ 3.0, and gtkmozembed doesn't work with Gtk+ 3.0. Is there a way to just extend Gtk::Widget and put a gecko parser in it? Can't really find any gecko documentation, I keep getting redirected to gtkmozembed.

Any ideas/suggestions would be greatly appreciated.

Edit: @Mark After I tried using Webkitgtk, I get the following output and the application crashes.

** (ttocui_gtk:16360): DEBUG: NP_Initialize
** (ttocui_gtk:16360): DEBUG: NP_Initialize succeeded
** (ttocui_gtk:16360): DEBUG: NP_Initialize
** (ttocui_gtk:16360): DEBUG: NP_Initialize succeeded
** (ttocui_gtk:16360): DEBUG: NP_Initialize
** (ttocui_gtk:16360): DEBUG: NP_Initialize succeeded
** (ttocui_gtk:16360): DEBUG: NP_Initialize
** (ttocui_gtk:16360): DEBUG: NP_Initialize succeeded
** (ttocui_gtk:16360): DEBUG: NP_Initialize
** (ttocui_gtk:16360): DEBUG: NP_Initialize succeeded
** (ttocui_gtk:16360): DEBUG: NP_Initialize
** (ttocui_gtk:16360): DEBUG: NP_Initialize succeeded
** (ttocui_gtk:16360): DEBUG: NP_Initialize
** (ttocui_gtk:16360): DEBUG: NP_Initialize succeeded
** (ttocui_gtk:16360): DEBUG: NP_Initialize
** (ttocui_gtk:16360): DEBUG: NP_Initialize succeeded

(ttocui_gtk:16360): GLib-CRITICAL **: g_hash_table_foreach: assertion `hash_table != NULL' failed

(ttocui_gtk:16360): GLib-CRITICAL **: g_hash_table_insert_internal: assertion `hash_table != NULL' failed

(ttocui_gtk:16360): GLib-CRITICAL **: g_hash_table_lookup: assertion `hash_table != NULL' failed
*** NSPlugin Wrapper *** ERROR: no valid NPP -> PluginInstance mapping found

(ttocui_gtk:16360): GLib-CRITICAL **: g_hash_table_lookup: assertion `hash_table != NULL' failed
*** NSPlugin Wrapper *** ERROR: no valid NPP -> PluginInstance mapping found

(ttocui_gtk:16360): GLib-CRITICAL **: g_hash_table_lookup: assertion `hash_table != NULL' failed

(ttocui_gtk:16360): GLib-CRITICAL **: g_hash_table_insert_internal: assertion `hash_table != NULL' failed

(ttocui_gtk:16360): GLib-CRITICAL **: g_hash_table_insert_internal: assertion `hash_table != NULL' failed

(ttocui_gtk:16360): GLib-CRITICAL **: g_hash_table_find: assertion `hash_table != NULL' failed

(ttocui_gtk:16360): GLib-CRITICAL **: g_hash_table_insert_internal: assertion `hash_table != NULL' failed

(ttocui_gtk:16360): GLib-CRITICAL **: g_hash_table_lookup: assertion `hash_table != NULL' failed
*** NSPlugin Wrapper *** ERROR: no valid NPP -> PluginInstance mapping found

(ttocui_gtk:16360): GLib-CRITICAL **: g_hash_table_lookup: assertion `hash_table != NULL' failed
ttocui_gtk: /build/buildd/nspluginwrapper-1.2.2/src/npw-rpc.c:1225: do_recv_NPObject: Assertion `npobj != ((void *)0)' failed.
*** NSPlugin Viewer  *** ERROR: NPN_GetProperty() wait for reply: Connection reset by peer
*** NSPlugin Viewer  *** WARNING:(/build/buildd/nspluginwrapper-1.2.2/src/npw-viewer.c:898):invoke_NPN_GetValue: assertion failed: (rpc_method_invoke_possible(g_rpc_connection))
Aborted
*** NSPlugin Viewer  *** WARNING: unhandled variable 18 (<unknown variable>) in NPN_GetValue()
*** NSPlugin Viewer  *** WARNING:(/build/buildd/nspluginwrapper-1.2.2/src/npw-viewer.c:898):invoke_NPN_GetValue: assertion failed: (rpc_method_invoke_possible(g_rpc_connection))

The .js file is included in the head tag of my html pages...

<link rel="stylesheet" type="text/css" href="/ext3.2.1/resources/css/ext-all.css">
<link rel="stylesheet" type="text/css" href="/ext3.2.1/resources/css/xtheme-access.css"/>

<script type="text/javascript" src="/ext3.2.1/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="/ext3.2.1/ext-all-debug.js"></script>
paullj1
  • 127
  • 2
  • 12

3 Answers3

8

Neither does gtkmozembed work with new versions of Gecko, if my memory serves me. What you are looking for is WebkitGTK, at least if you're not specifically tied to Gecko.

ptomato
  • 56,175
  • 13
  • 112
  • 165
  • Mozilla/Firefox is not embeddable anymore since 4.0 – Lothar Aug 19 '11 at 16:29
  • I'm definitely not tied to any concept/implementation at this point. Thanks for the input! – paullj1 Aug 19 '11 at 16:38
  • @ptomato any chance you know why WebkitGTK doesn't like POST data [(SO Question)](http://stackoverflow.com/questions/7771942/webkitgtk-wont-cant-find-post-data)? I'm still looking for an alternative to gtkmozembed. – paullj1 Apr 04 '12 at 19:45
5

As an addendum to @ptomato's answer. WebKitGTK is the way to go. I do not know of a gtkmm/C++ wrapper for it, but I am currently using it from a gtkmm project quite successfully (luckily, gtkmm/C++ allows you to mix in the C gtk quite easily):

WebKitWebView* pWebKitView = WEBKIT_WEB_VIEW (webkit_web_view_new ());
gtk_container_add (GTK_CONTAINER (pSomeContainer->gobj()), GTK_WIDGET (pWebKitView));

And off you go...

Mark
  • 106,305
  • 20
  • 172
  • 230
  • I don't know how mature these c++ bindings are, but [this](http://trac.webkit.org/wiki/ApplicationsGtk#Cgtkmmbindings) is from the Webkit wiki. – ptomato Aug 18 '11 at 06:57
  • But going cross platform with WebKitGTK is something that is not easy. You will see when you try to get it compiled on windows. – Lothar Aug 19 '11 at 16:30
  • Thanks @Mark! I will definitely give this a shot, but @Lothar makes a good point. I need this to compile in windows which is why I was going to go with Gecko, or something lightweight and portable. I don't need security or really rich web features, I just need to parse HTML, and Javascript ( Ext JS Framework ). – paullj1 Aug 19 '11 at 16:43
  • @ptomato, that project looks kind of old. I couldn't even get it to build when I was researching this the other day. – paullj1 Aug 19 '11 at 16:46
  • @Mark, Okay, after fighting with the 'gstreamer' dependencies I finally got around to giving this a shot, and it works really well, except that it won't parse the JavaScript EXT libraries. Any other suggestions? – paullj1 Aug 25 '11 at 17:07
  • @paullj1, what do you mean by "won't parse"? Does it return an error? How are you sourcing in the .js script files? I've never used it with ext.js but I have with jQuery without problems. – Mark Aug 26 '11 at 14:53
  • @paullj1: clarifications (such as error messages) should go in your question, not other people's answers. SO is a Q&A site, not a forum. Better still, post as a new question, since that's what you have. – outis Aug 28 '11 at 07:17
  • @Mark, I've posted a new question, and added the output of the application to this one. Any thoughts? http://stackoverflow.com/q/7221567/875375 – paullj1 Aug 29 '11 at 12:14
  • @paullj, sorry I am on the east coast of the US and currently without electricity. My internet time is limited. From what I see of your error though, they are from nspluginwrapper, are you embedding flash or something? – Mark Aug 29 '11 at 18:59
  • @Mark, Sorry it's been so long, and thank you for your help in the past. I solved the 'crash' problem, it turns out it was an OS / outdated library issue. Now I'm trying to figure out why webkit won't do a POST method. GET works fine, but for obvious security reasons, I need to do a POST method. It's probably not even a webkit problem, but do you have any ideas? – paullj1 Oct 14 '11 at 14:36
  • @paullj, could you show some sample code? Perhaps open a new question with the details. – Mark Oct 14 '11 at 15:58
  • @Mark Thanks for the quick response, I really appreciate it. Here's a link to the question I just posted with the code I'm using: [link](http://stackoverflow.com/questions/7771942/webkitgtk-wont-cant-find-post-information) Thanks again. – paullj1 Oct 14 '11 at 18:29
3

Just thought I'd come back and let anyone who cares know that our solution was to use Gtkmozembed. Only problem with it is that Gtkmozembed only runs using gtk+ 2 and I'm using gtk+ 3. The two can not exist in the same process, and I'm not migrating either project. So I'm running gtkmozembed in a child process that I use pipes to communicate with, and a GtkPlug that renders the widget in my project.

This solution is a little hokey, but it gets the job done, and the browser is embedded.

paullj1
  • 127
  • 2
  • 12