如何嵌入Gecko引擎

由于工作需要,研究了一下gecko的引擎嵌入的问题,花了三天多的时间,总算成功让gecko在Gtk控件下正确显示网页了。其实并不复杂,如果能找对正确的做法。基本思路是:
  • 下载mozilla的cvs代码。参考moziila官方的说明。这里重要的是要选择checkout xulrunner。我在多次尝试后,发现只有xulrunner能够正常的运行自己写的demo和embedding的demo,当然官方提供的TestGtkEmbed在browser下跑时也会有问题,如果不想走弯路,xulrunner是正确的选择。.mozconfig参考如下:
    ff_topsrc =/ mnt / sda2 / devel / mozilla
    .   $ {ff_topsrc} / xulrunner / config / mozconfig
    mk_add_options MOZ_OBJDIR
    =$ {ff_topsrc} / xulrunner-build
    ac_add_options --enable-application
    = xulrunner
    ac_add_options --enable-optimize
    ac_add_options --enable-default-toolkit
    = cairo-gtk2
    ac_add_options --enable-xft
    ac_add_options --enable-shared
    ac_add_options --disable-static
    ac_add_options --enable-
    debug
    ac_add_options --enable-libxul
    ac_add_options --disable-tests
  • 编译xulrunner。编译的.mozconfig文件中记得按照xulrunner编写,必须enable libxul。
编译完成后,你可以在编译目录(MOZ_OBJDIR)下找到所有需要的嵌入依赖的库和头文件,官方的称呼大概是GRE。以下是一个最简单的demo参考,可以正确编译和运行。我在embeding/config目录下make showbuild得到makefile的框架,然后根据需要做了一下修改。估计不需要这么麻烦,现在也懒得管了。
Makefile如下:
MOZ_ROOT =/ mnt / sda2 / devel / mozilla / xulrunner-build
LDFLAGS
= -lpthread  -Wl , -rpath -Wl ,$ {MOZ_ROOT} / dist / bin /  -Wl , -rpath -Wl ,$ {MOZ_ROOT} / dist / lib 
-L
$ {MOZ_ROOT} / dist / lib /  -lxpcom -lnspr4
CXXFLAGS
=  -ggdb -fno-rtti -fno-exceptions -Wall -Wconversion -Wpointer-arith -Wcast-align
-Woverloaded-virtual -Wsynth -Wno-ctor-dtor-privacy -Wno-non-virtual-dtor -Wno-long-long -pedantic
-fshort-wchar -pthread -pipe  -DNDEBUG -DTRIMMED -O -I
/ usr / include / gtk- 2.0  -I / usr / lib / gtk- 2.0 / include
-I
/ usr / include / atk- 1.0  -I / usr / include / cairo -I / usr / include / pango- 1.0  -I / usr / include / glib- 2.0
-I
/ usr / lib / glib- 2.0 / include -I / usr / include / freetype2 -I / usr / include / libpng12
COMPILE_CFLAGS
=  -I  $ {MOZ_ROOT} / dist / include / system_wrappers
-include 
/ mnt / sda2 / devel / mozilla / config / gcc_hidden . h -DMOZILLA_STRICT_API
-DOSTYPE
= " Linux2.6.22 "  -DOSARCH = Linux  -I  $ {MOZ_ROOT} / dist / include / xpcom
-I
$ {MOZ_ROOT} / dist / include / intl -I $ {MOZ_ROOT} / dist / include / embedcomponents
-I
$ {MOZ_ROOT} / dist / include   -I $ {MOZ_ROOT} / dist / include / embed_base
-I
$ {MOZ_ROOT} / dist / include / nspr -I $ {MOZ_ROOT} / dist / include / gtkembedmoz
-DMOZ_PNG_READ -DMOZ_PNG_WRITE   -I
$ {MOZ_ROOT} / dist / sdk / include
-Wall -W -Wno-unused -Wpointer-arith -Wcast-align -Wno-long-long -pedantic
-pthread -pipe  -DNDEBUG -DTRIMMED -O   -include 
$ {MOZ_ROOT} / mozilla-config . h
-DMOZILLA_CLIENT

all: test

test: test
. o
    g
++  -o test  $( LDFLAGS )  `pkg-config --libs gtk + - 2.0 ` test . o $ {MOZ_ROOT} / embedding / base / libembed_base_s . $ {MOZ_ROOT} / xpcom / glue / standalone / libxpcomglue . a

$ {MOZ_ROOT} / embedding / base / libembed_base_s . a

test
. o: test . cpp
        g
++  -c  $( CXXFLAGS )   $( COMPILE_CFLAGS )  `pkg-config --cflags gtk + - 2.0 ` test . cpp

clean:
        rm *
. o test


test.cpp如下:
#include  " nsXPCOM.h "
#include 
" nscore.h "
#include 
" nsEmbedAPI.h "
#include 
" nsWeakReference.h "
#include 
" nsIWebBrowserChrome.h "
#include 
" nsIEmbeddingSiteWindow.h "
#include 
" nsCOMPtr.h "
#include 
" nsIInterfaceRequestor.h "
#include 
" nsEmbedString.h "
#include 
" nsIWebBrowser.h "
#include 
" widget/nsIBaseWindow.h "
#include 
" nsEmbedCID.h "
#include 
" nsComponentManagerUtils.h "
#include 
" nsIWebProgressListener.h "
#include 
" docshell/nsIWebNavigation.h "
#include 
" docshell/nsIDocShellTreeItem.h "
#include 
< iostream >
#include 
< gtk / gtk.h >

using   namespace  std;

class  SillyBrowser:  public  nsIWebBrowserChrome,
                                        
p
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值