开发者

Embed a web browser in a cross platform Gtk application

I need to embed a very simple browser ( can parse 开发者_JS百科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>


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.


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...


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜